11file (GLOB GENERAL_OPS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR } " "*_op.cc" )
22string (REPLACE ".cc" "" GENERAL_OPS "${GENERAL_OPS} " )
3+ set (pybind_file ${PADDLE_SOURCE_DIR } /paddle/pybind/pybind.h)
4+ file (WRITE ${pybind_file} "// Generated by the paddle/operator/CMakeLists.txt. DO NOT EDIT!\n\n " )
35function (op_library TARGET )
46 # op_library is a function to create op library. The interface is same as
57 # cc_library. But it handle split GPU/CPU code and link some common library
@@ -11,6 +13,7 @@ function(op_library TARGET)
1113 set (options "" )
1214 set (oneValueArgs "" )
1315 set (multiValueArgs SRCS DEPS)
16+ set (pybind_flag 0)
1417 cmake_parse_arguments (op_library "${options} " "${oneValueArgs} "
1518 "${multiValueArgs} " ${ARGN} )
1619
@@ -46,15 +49,40 @@ function(op_library TARGET)
4649 cc_library (${TARGET} SRCS ${cc_srcs} DEPS ${op_library_DEPS}
4750 ${op_common_deps} )
4851 endif ()
52+
53+ # net_op doesn't need pybind
54+ if ("${TARGET} " STREQUAL "net_op" )
55+ set (pybind_flag 1)
56+ endif ()
57+
58+ # pybind USE_NO_KERNEL_OP
59+ file (READ ${TARGET} .cc TARGET_CONTENT )
60+ string (REGEX MATCH "OperatorWithKernel" regex_result "${TARGET_CONTENT} " )
61+ string (REPLACE "_op" "" TARGET "${TARGET} " )
62+ if (${pybind_flag} EQUAL 0 AND regex_result STREQUAL "" )
63+ file (APPEND ${pybind_file} "USE_NO_KERNEL_OP(${TARGET} );\n " )
64+ set (pybind_flag 1)
65+ endif ()
66+
67+ # pybind USE_CPU_ONLY_OP
68+ list (LENGTH cu_srcs cu_srcs_len)
69+ if (${pybind_flag} EQUAL 0 AND ${cu_srcs_len} EQUAL 0)
70+ file (APPEND ${pybind_file} "USE_CPU_ONLY_OP(${TARGET} );\n " )
71+ set (pybind_flag 1)
72+ endif ()
73+
74+ # pybind USE_OP
75+ if (${pybind_flag} EQUAL 0)
76+ file (APPEND ${pybind_file} "USE_OP(${TARGET} );\n " )
77+ endif ()
4978endfunction ()
5079
5180add_subdirectory (math )
5281
5382set (DEPS_OPS
5483 recurrent_op)
55-
5684op_library (recurrent_op SRCS recurrent_op.cc rnn/recurrent_op_utils.cc
57- DEPS framework_proto tensor operator net_op )
85+ DEPS framework_proto tensor net_op )
5886
5987list (REMOVE_ITEM GENERAL_OPS ${DEPS_OPS} )
6088foreach (src ${GENERAL_OPS} )
0 commit comments