diff --git a/paddle/framework/op_registry.h b/paddle/framework/op_registry.h index a3fd93290a0bb95fc12bb091eec5e0168bd5f98e..9eeec37331f0ffb037fd6c7be5e20f2b503bf4d4 100644 --- a/paddle/framework/op_registry.h +++ b/paddle/framework/op_registry.h @@ -416,6 +416,12 @@ class OpKernelRegistrar : public Registrar { static int use_op_itself_##op_type##_ __attribute__((unused)) = \ TouchOpRegistrar_##op_type() +// TODO(jiayi): Most ops' gradient op have not been compeleted. So we use +// `NO_GRAD` to disable micro USE_OP_GRADIENT(op_type). Otherwise the code can't +// be compiled. `NO_GRAD` should be removed after all gradient ops are +// compeleted. +#define NO_GRAD +#ifndef NO_GRAD #define USE_OP_GRADIENT(op_type) \ STATIC_ASSERT_GLOBAL_NAMESPACE( \ __use_op_gradient_##op_type, \ @@ -423,28 +429,39 @@ class OpKernelRegistrar : public Registrar { extern int TouchOpGradientRegistrar_##op_type(); \ static int use_op_gradient_##op_type##_ __attribute__((unused)) = \ TouchOpGradientRegistrar_##op_type() +#else +#define USE_OP_GRADIENT(op_type) +#endif -#define USE_OP_KERNEL(op_type, DEVICE_TYPE) \ +#define USE_OP_DEVICE_KERNEL(op_type, DEVICE_TYPE) \ STATIC_ASSERT_GLOBAL_NAMESPACE( \ __use_op_kernel_##op_type##_##DEVICE_TYPE##__, \ - "USE_OP_KERNEL must be in global namespace"); \ + "USE_OP_DEVICE_KERNEL must be in global namespace"); \ extern int TouchOpKernelRegistrar_##op_type##_##DEVICE_TYPE(); \ static int use_op_kernel_##op_type##_##DEVICE_TYPE##_ \ __attribute__((unused)) = \ TouchOpKernelRegistrar_##op_type##_##DEVICE_TYPE() -#define USE_CPU_OP(op_type) \ - USE_OP_ITSELF(op_type); \ - USE_OP_KERNEL(op_type, CPU); \ - USE_OP_GRADIENT(op_type) - #ifdef PADDLE_ONLY_CPU -#define USE_OP(op_type) USE_CPU_OP(op_type) +#define USE_OP_KERNEL(op_type) USE_OP_DEVICE_KERNEL(op_type, CPU) #else -#define USE_OP(op_type) \ - USE_CPU_OP(op_type); \ - USE_OP_KERNEL(op_type, GPU) +#define USE_OP_KERNEL(op_type) \ + USE_OP_DEVICE_KERNEL(op_type, CPU); \ + USE_OP_DEVICE_KERNEL(op_type, GPU) #endif +#define USE_NO_GRAD_OP(op_type) \ + USE_OP_ITSELF(op_type); \ + USE_OP_KERNEL(op_type) + +#define USE_CPU_OP(op_type) \ + USE_OP_ITSELF(op_type); \ + USE_OP_DEVICE_KERNEL(op_type, CPU); \ + USE_OP_GRADIENT(op_type) + +#define USE_OP(op_type) \ + USE_NO_GRAD_OP(op_type); \ + USE_OP_GRADIENT(op_type) + } // namespace framework } // namespace paddle diff --git a/paddle/framework/pybind.cc b/paddle/framework/pybind.cc index a955191e982e10372de861aec2c0af7b747fe828..9c618ad90096476ae123c84574ecd20b14cd66ff 100644 --- a/paddle/framework/pybind.cc +++ b/paddle/framework/pybind.cc @@ -31,7 +31,7 @@ namespace py = pybind11; USE_OP(add_two); USE_CPU_OP(onehot_cross_entropy); USE_OP_ITSELF(fc); -USE_OP(sgd); +USE_NO_GRAD_OP(sgd); USE_OP(mul); USE_OP(mean); USE_OP(sigmoid); diff --git a/paddle/operators/sgd_op_test.cc b/paddle/operators/sgd_op_test.cc index 75137259f5e608b259b073101353e5818bb17c92..b2a5487f12c9e0287257ca5ac89bf46c19799adc 100644 --- a/paddle/operators/sgd_op_test.cc +++ b/paddle/operators/sgd_op_test.cc @@ -14,7 +14,7 @@ limitations under the License. */ #include #include -USE_OP(sgd); +USE_NO_GRAD_OP(sgd); TEST(SGDOp, GetOpProto) { auto& protos = paddle::framework::OpRegistry::protos(); auto it = protos.find("sgd");