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 broadcast and elementwise PEs (PaddlePaddle#168)
- Loading branch information
1 parent
f4cfb6d
commit 75dbf7d
Showing
25 changed files
with
731 additions
and
61 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
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
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
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
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
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
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
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,59 @@ | ||
#include "cinn/hlir/pe/elementwise.h" | ||
|
||
#include <vector> | ||
|
||
#include "cinn/ir/ir_operators.h" | ||
#include "cinn/lang/compute.h" | ||
|
||
namespace cinn { | ||
namespace hlir { | ||
namespace pe { | ||
|
||
using cinn::lang::Compute; | ||
using ir::Expr; | ||
using ir::Tensor; | ||
|
||
#define HLIR_IMP_UNARY_PE(name__) \ | ||
Tensor name__(const Tensor& A, const std::string& output_name) { \ | ||
return Compute( \ | ||
A->shape, [&](const std::vector<Expr>& indice) { return name__(A(indice)); }, output_name); \ | ||
} | ||
|
||
HLIR_IMP_UNARY_PE(Exp); | ||
HLIR_IMP_UNARY_PE(Erf); | ||
HLIR_IMP_UNARY_PE(Sqrt); | ||
HLIR_IMP_UNARY_PE(Log); | ||
HLIR_IMP_UNARY_PE(Log2); | ||
HLIR_IMP_UNARY_PE(Log10); | ||
HLIR_IMP_UNARY_PE(Floor); | ||
HLIR_IMP_UNARY_PE(Ceil); | ||
HLIR_IMP_UNARY_PE(Round); | ||
HLIR_IMP_UNARY_PE(Trunc); | ||
HLIR_IMP_UNARY_PE(Cos); | ||
HLIR_IMP_UNARY_PE(Cosh); | ||
HLIR_IMP_UNARY_PE(Tan); | ||
HLIR_IMP_UNARY_PE(Sin); | ||
HLIR_IMP_UNARY_PE(Sinh); | ||
HLIR_IMP_UNARY_PE(Acos); | ||
HLIR_IMP_UNARY_PE(Acosh); | ||
HLIR_IMP_UNARY_PE(Asin); | ||
HLIR_IMP_UNARY_PE(Asinh); | ||
HLIR_IMP_UNARY_PE(Atan); | ||
HLIR_IMP_UNARY_PE(Atanh); | ||
HLIR_IMP_UNARY_PE(Isnan); | ||
HLIR_IMP_UNARY_PE(Tanh); | ||
HLIR_IMP_UNARY_PE(Isfinite); | ||
HLIR_IMP_UNARY_PE(Isinf); | ||
|
||
HLIR_IMP_UNARY_PE(Negative); | ||
HLIR_IMP_UNARY_PE(Identity); | ||
HLIR_IMP_UNARY_PE(LogicalNot); | ||
HLIR_IMP_UNARY_PE(BitwiseNot); | ||
HLIR_IMP_UNARY_PE(Sigmoid); | ||
HLIR_IMP_UNARY_PE(Sign); | ||
HLIR_IMP_UNARY_PE(Abs); | ||
HLIR_IMP_UNARY_PE(Rsqrt); | ||
|
||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#pragma once | ||
|
||
#include "cinn/ir/ir.h" | ||
|
||
namespace cinn { | ||
namespace hlir { | ||
namespace pe { | ||
/** | ||
* @brief Unary primitive emitters | ||
* | ||
* @param A The input Tensor | ||
* @param output_name The name of the output Tensor | ||
* | ||
* @return The result Tensor. | ||
*/ | ||
#define HLIR_DCL_UNARY_PE(name__) \ | ||
ir::Tensor name__(const ir::Tensor& A, const std::string& output_name = "T_" #name__ "_out"); | ||
|
||
HLIR_DCL_UNARY_PE(Exp); | ||
HLIR_DCL_UNARY_PE(Erf); | ||
HLIR_DCL_UNARY_PE(Sqrt); | ||
HLIR_DCL_UNARY_PE(Log); | ||
HLIR_DCL_UNARY_PE(Log2); | ||
HLIR_DCL_UNARY_PE(Log10); | ||
HLIR_DCL_UNARY_PE(Floor); | ||
HLIR_DCL_UNARY_PE(Ceil); | ||
HLIR_DCL_UNARY_PE(Round); | ||
HLIR_DCL_UNARY_PE(Trunc); | ||
HLIR_DCL_UNARY_PE(Cos); | ||
HLIR_DCL_UNARY_PE(Cosh); | ||
HLIR_DCL_UNARY_PE(Tan); | ||
HLIR_DCL_UNARY_PE(Sin); | ||
HLIR_DCL_UNARY_PE(Sinh); | ||
HLIR_DCL_UNARY_PE(Acos); | ||
HLIR_DCL_UNARY_PE(Acosh); | ||
HLIR_DCL_UNARY_PE(Asin); | ||
HLIR_DCL_UNARY_PE(Asinh); | ||
HLIR_DCL_UNARY_PE(Atan); | ||
HLIR_DCL_UNARY_PE(Atanh); | ||
HLIR_DCL_UNARY_PE(Isnan); | ||
HLIR_DCL_UNARY_PE(Tanh); | ||
HLIR_DCL_UNARY_PE(Isfinite); | ||
HLIR_DCL_UNARY_PE(Isinf); | ||
|
||
HLIR_DCL_UNARY_PE(Negative); | ||
HLIR_DCL_UNARY_PE(Identity); | ||
HLIR_DCL_UNARY_PE(LogicalNot); | ||
HLIR_DCL_UNARY_PE(BitwiseNot); | ||
HLIR_DCL_UNARY_PE(Sigmoid); | ||
HLIR_DCL_UNARY_PE(Sign); | ||
HLIR_DCL_UNARY_PE(Abs); | ||
HLIR_DCL_UNARY_PE(Rsqrt); | ||
HLIR_DCL_UNARY_PE(Cast); | ||
HLIR_DCL_UNARY_PE(Clip); | ||
HLIR_DCL_UNARY_PE(Reinterpret); | ||
HLIR_DCL_UNARY_PE(ElementwiseSum); | ||
HLIR_DCL_UNARY_PE(Full); | ||
HLIR_DCL_UNARY_PE(FullLike); | ||
|
||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "cinn/hlir/pe/nn.h" | ||
|
||
#include "cinn/lang/compute.h" | ||
|
||
namespace cinn { | ||
namespace hlir { | ||
namespace pe { | ||
|
||
using cinn::lang::Compute; | ||
using ir::Expr; | ||
using ir::Tensor; | ||
|
||
template <typename T> | ||
Tensor Relu(const Tensor& A, T threshold, const std::string& output_name) { | ||
return Compute( | ||
A->shape, [&](const std::vector<Expr>& indice) { return Relu(A(indice), threshold); }, output_name); | ||
} | ||
Tensor LeakyRelu(const Tensor& A, double alpha, const std::string& output_name) { | ||
return Compute( | ||
A->shape, [&](const std::vector<Expr>& indice) { return LeakyRelu(A(indice), alpha); }, output_name); | ||
} | ||
|
||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
#include "cinn/ir/ir.h" | ||
|
||
namespace cinn { | ||
namespace hlir { | ||
namespace pe { | ||
|
||
template <typename T> | ||
ir::Tensor Relu(const ir::Tensor& A, T threshold = static_cast<T>(0), const std::string& output_name = "T_Relu_out"); | ||
|
||
ir::Tensor LeakyRelu(const ir::Tensor& A, double alpha = 0.1, const std::string& output_name = "T_LeakyRelu_out"); | ||
|
||
} // namespace pe | ||
} // namespace hlir | ||
} // namespace cinn |
Oops, something went wrong.