From f66d78680d9d52e9ea29796e5bcc1d9106772756 Mon Sep 17 00:00:00 2001 From: fengjiayi Date: Wed, 9 Aug 2017 14:48:19 -0700 Subject: [PATCH] Add macro USE_OP_GRADIENT() --- paddle/framework/op_registry.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/paddle/framework/op_registry.h b/paddle/framework/op_registry.h index 3633ddb9df2..a3fd93290a0 100644 --- a/paddle/framework/op_registry.h +++ b/paddle/framework/op_registry.h @@ -371,7 +371,7 @@ class OpKernelRegistrar : public Registrar { static ::paddle::framework::GradOpRegistrar \ __op_gradient_registrar_##op_type##_##grad_op_type##__(#op_type, \ #grad_op_type); \ - int TouchOpGradientRegister_##op_type() { \ + int TouchOpGradientRegistrar_##op_type() { \ __op_gradient_registrar_##op_type##_##grad_op_type##__.Touch(); \ return 0; \ } @@ -416,6 +416,14 @@ class OpKernelRegistrar : public Registrar { static int use_op_itself_##op_type##_ __attribute__((unused)) = \ TouchOpRegistrar_##op_type() +#define USE_OP_GRADIENT(op_type) \ + STATIC_ASSERT_GLOBAL_NAMESPACE( \ + __use_op_gradient_##op_type, \ + "USE_OP_GRADIENT must be called in global namespace"); \ + extern int TouchOpGradientRegistrar_##op_type(); \ + static int use_op_gradient_##op_type##_ __attribute__((unused)) = \ + TouchOpGradientRegistrar_##op_type() + #define USE_OP_KERNEL(op_type, DEVICE_TYPE) \ STATIC_ASSERT_GLOBAL_NAMESPACE( \ __use_op_kernel_##op_type##_##DEVICE_TYPE##__, \ @@ -425,9 +433,10 @@ class OpKernelRegistrar : public Registrar { __attribute__((unused)) = \ TouchOpKernelRegistrar_##op_type##_##DEVICE_TYPE() -#define USE_CPU_OP(op_type) \ - USE_OP_ITSELF(op_type); \ - USE_OP_KERNEL(op_type, CPU) +#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) -- GitLab