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 PEs(matmul, all relus) and Ops(elementwise_add, relu6, mul) and C… (
PaddlePaddle#198) * add PEs(matmul, all relus) and Ops(elementwise_add, relu6, mul) and C++/python tests * modify codes * modify code styles Co-authored-by: Yan Chunwei <yanchunwei@outlook.com>
- Loading branch information
1 parent
00b99d4
commit 9b6e04c
Showing
33 changed files
with
998 additions
and
233 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
set(srcs | ||
nn.cc | ||
nn.cc | ||
broadcast.cc | ||
transform.cc | ||
) | ||
|
||
foreach(cpp ${srcs}) | ||
set(core_src | ||
"${core_src};cinn/hlir/op/${cpp}" | ||
CACHE INTERNAL "") | ||
endforeach() | ||
|
||
cc_test(test_op_broadcast SRCS op_broadcast_test.cc DEPS core) |
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,81 @@ | ||
#include "cinn/hlir/pe/broadcast.h" | ||
|
||
#include <iostream> | ||
#include "cinn/hlir/framework/node.h" | ||
#include "cinn/hlir/framework/op.h" | ||
#include "cinn/hlir/framework/op_strategy.h" | ||
|
||
namespace cinn { | ||
namespace hlir { | ||
namespace op { | ||
using common::_CINNValuePack_; | ||
using common::CINNValue; | ||
using common::CINNValuePack; | ||
using framework::OpStrategy; | ||
using framework::StrategyFunction; | ||
|
||
std::shared_ptr<OpStrategy> StrategyForElementwiseAdd(const framework::NodeAttr &attrs, | ||
const std::vector<ir::Tensor> &inputs, | ||
const std::vector<Type> &out_type, | ||
const Target &target) { | ||
framework::CINNCompute add_compute([&attrs](lang::Args args, lang::RetValue *ret) { | ||
CINNValuePack a = args[0]; | ||
ir::Expr A_expr = a[0]; | ||
ir::Expr B_expr = a[1]; | ||
CHECK(A_expr.as_tensor()); | ||
CHECK(B_expr.as_tensor()); | ||
ir::Tensor A = A_expr.as_tensor_ref(); | ||
ir::Tensor B = B_expr.as_tensor_ref(); | ||
auto attr_store = attrs.attr_store; | ||
auto iter = attr_store.find("axis"); | ||
ir::Expr axis; | ||
if (iter != attr_store.end()) { | ||
axis = ir::Expr(std::get<int>(iter->second)); | ||
} | ||
|
||
auto out = pe::Add(A, B, UniqName("C"), axis); | ||
|
||
auto stages = CreateStages({out}); | ||
*ret = CINNValuePack{{CINNValue(ir::Expr(out.get())), CINNValue(stages)}}; | ||
}); | ||
|
||
framework::CINNSchedule add_schedule([](lang::Args args, lang::RetValue *ret) { | ||
CINNValuePack arg_pack = args[0]; | ||
ir::Expr A [[maybe_unused]] = arg_pack[0]; | ||
CHECK_EQ(arg_pack.size(), 2UL); | ||
*ret = arg_pack; | ||
}); | ||
|
||
auto strategy = std::make_shared<framework::OpStrategy>(); | ||
strategy->AddImpl(add_compute, add_schedule, "strategy.elementwise_add.x86", 1); | ||
|
||
return strategy; | ||
} | ||
|
||
std::vector<std::vector<int>> InferShapeForElementwiseAdd(const std::vector<std::vector<int>> &inputs_shape, | ||
const framework::NodeAttr &attrs) { | ||
CHECK(!inputs_shape.empty() && !inputs_shape[0].empty()) << "The input's shape size is 0! Please check again."; | ||
std::vector<std::vector<int>> res{inputs_shape[0]}; | ||
return res; | ||
} | ||
|
||
std::vector<Type> InferDtypeForElementwiseAdd(const std::vector<Type> &inputs_type, const framework::NodeAttr &attrs) { | ||
CHECK(!inputs_type.empty()) << "The input's type size is 0! Please check again."; | ||
std::vector<Type> res{inputs_type[0]}; | ||
return res; | ||
} | ||
|
||
} // namespace op | ||
} // namespace hlir | ||
} // namespace cinn | ||
|
||
CINN_REGISTER_HELPER(broadcast_ops) { | ||
CINN_REGISTER_OP(elementwise_add) | ||
.describe("Add two tensors") | ||
.set_num_inputs(2) | ||
.set_num_outputs(1) | ||
.set_attr<cinn::hlir::framework::StrategyFunction>("CINNStrategy", cinn::hlir::op::StrategyForElementwiseAdd) | ||
.set_attr("infershape", std::function(cinn::hlir::op::InferShapeForElementwiseAdd)) | ||
.set_attr("inferdtype", std::function(cinn::hlir::op::InferDtypeForElementwiseAdd)) | ||
.set_support_level(4); | ||
} |
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
Oops, something went wrong.