提交 79b70c2d 编写于 作者: Y Yu Yang

Follow comments

* Convert `op` --> `operators`
* Remove AddType in OpProtoMaker, because type is part of registry.
* Rename CPU_OR_GPU --> DEVICE_TYPE in registry macro.
上级 a0aaafe9
...@@ -14,7 +14,7 @@ if(Boost_FOUND) ...@@ -14,7 +14,7 @@ if(Boost_FOUND)
add_subdirectory(memory) add_subdirectory(memory)
add_subdirectory(platform) add_subdirectory(platform)
add_subdirectory(framework) add_subdirectory(framework)
add_subdirectory(op) # because `operator` is a reserved word for CPP, so short to `op` add_subdirectory(operators)
add_subdirectory(pybind) add_subdirectory(pybind)
endif() endif()
......
...@@ -82,8 +82,6 @@ class OpProtoAndCheckerMaker { ...@@ -82,8 +82,6 @@ class OpProtoAndCheckerMaker {
return op_checker_->AddAttrChecker<T>(name); return op_checker_->AddAttrChecker<T>(name);
} }
void AddType(const std::string& op_type) { proto_->set_type(op_type); }
void AddComment(const std::string& comment) { void AddComment(const std::string& comment) {
*(proto_->mutable_comment()) = comment; *(proto_->mutable_comment()) = comment;
} }
...@@ -194,13 +192,14 @@ class OpRegisterHelper { ...@@ -194,13 +192,14 @@ class OpRegisterHelper {
static int __use_op_ptr_##op_type##_without_kernel__ \ static int __use_op_ptr_##op_type##_without_kernel__ \
__attribute__((unused)) = __op_register_##op_type##_handle__() __attribute__((unused)) = __op_register_##op_type##_handle__()
#define USE_OP_KERNEL(op_type, CPU_OR_GPU) \ #define USE_OP_KERNEL(op_type, DEVICE_TYPE) \
STATIC_ASSERT_GLOBAL_NAMESPACE(__use_op_kernel_##op_type##_##CPU_OR_GPU##__, \ STATIC_ASSERT_GLOBAL_NAMESPACE( \
"USE_OP_KERNEL must be in global namespace"); \ __use_op_kernel_##op_type##_##DEVICE_TYPE##__, \
extern int __op_kernel_register_##op_type##_handle_##CPU_OR_GPU##__(); \ "USE_OP_KERNEL must be in global namespace"); \
static int __use_op_ptr_##op_type##_##CPU_OR_GPU##_kernel__ \ extern int __op_kernel_register_##op_type##_handle_##DEVICE_TYPE##__(); \
__attribute__((unused)) = \ static int __use_op_ptr_##op_type##_##DEVICE_TYPE##_kernel__ \
__op_kernel_register_##op_type##_handle_##CPU_OR_GPU##__() __attribute__((unused)) = \
__op_kernel_register_##op_type##_handle_##DEVICE_TYPE##__()
#ifdef PADDLE_ONLY_CPU #ifdef PADDLE_ONLY_CPU
#define USE_OP(op_type) \ #define USE_OP(op_type) \
......
...@@ -19,7 +19,6 @@ class CosineOpProtoAndCheckerMaker : public OpProtoAndCheckerMaker { ...@@ -19,7 +19,6 @@ class CosineOpProtoAndCheckerMaker : public OpProtoAndCheckerMaker {
AddAttr<float>("scale", "scale of cosine op") AddAttr<float>("scale", "scale of cosine op")
.SetDefault(1.0) .SetDefault(1.0)
.LargerThan(0.0); .LargerThan(0.0);
AddType("cos");
AddComment("This is cos op"); AddComment("This is cos op");
} }
}; };
...@@ -44,7 +43,6 @@ class MyTestOpProtoAndCheckerMaker : public OpProtoAndCheckerMaker { ...@@ -44,7 +43,6 @@ class MyTestOpProtoAndCheckerMaker : public OpProtoAndCheckerMaker {
}; };
AddAttr<int>("test_attr", "a simple test attribute") AddAttr<int>("test_attr", "a simple test attribute")
.AddCustomChecker(my_checker); .AddCustomChecker(my_checker);
AddType("my_test_op");
AddComment("This is my_test op"); AddComment("This is my_test op");
} }
}; };
......
...@@ -36,20 +36,6 @@ class OperatorTest : public OperatorBase { ...@@ -36,20 +36,6 @@ class OperatorTest : public OperatorBase {
float x = 0; float x = 0;
}; };
class OperatorTestProtoAndCheckerMaker : public OpProtoAndCheckerMaker {
public:
OperatorTestProtoAndCheckerMaker(OpProto* proto, OpAttrChecker* op_checker)
: OpProtoAndCheckerMaker(proto, op_checker) {
AddInput("input", "input of test op");
AddOutput("output", "output of test op");
AddAttr<float>("scale", "scale of cosine op")
.SetDefault(1.0)
.LargerThan(0.0);
AddType("test_operator");
AddComment("This is test op");
}
};
class OpKernelTestProtoAndCheckerMaker : public OpProtoAndCheckerMaker { class OpKernelTestProtoAndCheckerMaker : public OpProtoAndCheckerMaker {
public: public:
OpKernelTestProtoAndCheckerMaker(OpProto* proto, OpAttrChecker* op_checker) OpKernelTestProtoAndCheckerMaker(OpProto* proto, OpAttrChecker* op_checker)
......
#include <paddle/framework/op_registry.h> #include <paddle/framework/op_registry.h>
#include <paddle/framework/tensor.h> #include <paddle/framework/tensor.h>
#include <paddle/op/add_op.h> #include <paddle/operators/add_op.h>
namespace paddle { namespace paddle {
namespace op { namespace operators {
class AddOp : public framework::OperatorWithKernel { class AddOp : public framework::OperatorWithKernel {
protected: protected:
...@@ -39,6 +39,6 @@ The equation is: Out = X + Y ...@@ -39,6 +39,6 @@ The equation is: Out = X + Y
} // namespace op } // namespace op
} // namespace paddle } // namespace paddle
REGISTER_OP(add_two, paddle::op::AddOp, paddle::op::AddOpMaker); REGISTER_OP(add_two, paddle::operators::AddOp, paddle::operators::AddOpMaker);
REGISTER_OP_CPU_KERNEL(add_two, REGISTER_OP_CPU_KERNEL(
::paddle::op::AddKernel<::paddle::platform::CPUPlace>); add_two, ::paddle::operators::AddKernel<::paddle::platform::CPUPlace>);
\ No newline at end of file \ No newline at end of file
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include <paddle/framework/operator.h> #include <paddle/framework/operator.h>
namespace paddle { namespace paddle {
namespace op { namespace operators {
template <typename Place> template <typename Place>
class AddKernel : public framework::OpKernel { class AddKernel : public framework::OpKernel {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册