From bc1459cefb292c4aff7a7cae43eeab175b40b722 Mon Sep 17 00:00:00 2001
From: fengjiayi <fengjiayi@baidu.com>
Date: Wed, 9 Aug 2017 15:50:04 -0700
Subject: [PATCH] Unable macro `USE_OP_GRADIENT` temporarily

---
 paddle/framework/op_registry.h  | 39 +++++++++++++++++++++++----------
 paddle/framework/pybind.cc      |  2 +-
 paddle/operators/sgd_op_test.cc |  2 +-
 3 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/paddle/framework/op_registry.h b/paddle/framework/op_registry.h
index a3fd93290a..9eeec37331 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 a955191e98..9c618ad900 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 75137259f5..b2a5487f12 100644
--- a/paddle/operators/sgd_op_test.cc
+++ b/paddle/operators/sgd_op_test.cc
@@ -14,7 +14,7 @@ limitations under the License. */
 
 #include <gtest/gtest.h>
 #include <paddle/framework/op_registry.h>
-USE_OP(sgd);
+USE_NO_GRAD_OP(sgd);
 TEST(SGDOp, GetOpProto) {
   auto& protos = paddle::framework::OpRegistry::protos();
   auto it = protos.find("sgd");
-- 
GitLab