forked from PaddlePaddle/Paddle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add primitive layer. add function primitive::add (PaddlePaddle#118)
- Loading branch information
Showing
2 changed files
with
40 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
#include <string> | ||
#include <vector> | ||
#include "cinn/common/common.h" | ||
#include "cinn/ir/ir.h" | ||
#include "cinn/ir/node.h" | ||
#include "cinn/lang/compute.h" | ||
#include "cinn/lang/tensor.h" | ||
|
||
using cinn::ir::Expr; | ||
using cinn::ir::Tensor; | ||
using cinn::ir::Var; | ||
using cinn::lang::Compute; | ||
|
||
namespace cinn { | ||
namespace hlir { | ||
namespace pe { | ||
|
||
Tensor Add(const Tensor &A, const Tensor &B, const std::string output_name = "") { | ||
CHECK(A->SameShapeWith(B)) << "The 2 inputs have different shapes with each other. " | ||
"The Add fucntion needs two inputs to have identical shape."; | ||
const std::vector<Expr> output_shape = A->shape; | ||
CHECK_GE(output_shape.size(), 1) << "The input shape of pe::Add function is " << output_shape.size() | ||
<< " and it should be >= 1."; | ||
CHECK_LE(output_shape.size(), 4) << "The input shape of pe::Add function is " << output_shape.size() | ||
<< " and it should be <= 4."; | ||
|
||
Tensor output = Compute( | ||
output_shape, [&](const std::vector<Expr> &indice) { return A(indice) + B(indice); }, output_name); | ||
return output; | ||
} | ||
|
||
} // namespace pe | ||
} // namespace hlir | ||
} // namespace cinn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters