@@ -61,106 +61,28 @@ function(op_library TARGET)
61
61
${op_common_deps} )
62
62
endif ()
63
63
64
- # net_op doesn't need pybind
65
- if ("${TARGET} " STREQUAL "net_op" )
66
- set (pybind_flag 1)
67
- endif ()
68
-
69
- if ("${TARGET} " STREQUAL "compare_op" )
70
- set (pybind_flag 1)
71
- file (APPEND ${pybind_file} "USE_OP(less_than);\n USE_OP(equal);\n " )
72
- endif ()
73
-
74
- # conv_op contains several operators
75
- if ("${TARGET} " STREQUAL "conv_op" )
76
- set (pybind_flag 1)
77
- # It's enough to just adding one operator to pybind
78
- file (APPEND ${pybind_file} "USE_OP(conv2d);\n " )
79
- endif ()
80
-
81
- # conv_cudnn_op contains several operators
82
- if ("${TARGET} " STREQUAL "conv_cudnn_op" )
83
- set (pybind_flag 1)
84
- # It's enough to just adding one operator to pybind
85
- file (APPEND ${pybind_file} "USE_OP(conv2d_cudnn);\n " )
86
- endif ()
87
-
88
- # pool_op contains several operators
89
- if ("${TARGET} " STREQUAL "pool_op" )
90
- set (pybind_flag 1)
91
- # It's enough to just adding one operator to pybind
92
- file (APPEND ${pybind_file} "USE_OP(pool2d);\n " )
93
- endif ()
94
-
95
- # pool_cudnn_op contains several operators
96
- if ("${TARGET} " STREQUAL "pool_cudnn_op" )
97
- set (pybind_flag 1)
98
- # It's enough to just adding one operator to pybind
99
- file (APPEND ${pybind_file} "USE_OP(pool2d_cudnn);\n " )
100
- endif ()
101
-
102
- if ("${TARGET} " STREQUAL "logical_op" )
103
- set (pybind_flag 1)
104
- file (APPEND ${pybind_file} "USE_OP(logical_and);\n " )
105
- endif ()
106
-
107
- # pool_with_index_op contains several operators
108
- if ("${TARGET} " STREQUAL "pool_with_index_op" )
109
- set (pybind_flag 1)
110
- # It's enough to just adding one operator to pybind
111
- file (APPEND ${pybind_file} "USE_OP(max_pool2d_with_index);\n " )
112
- endif ()
113
-
114
- # conv_transpose_op contains several operators
115
- if ("${TARGET} " STREQUAL "conv_transpose_op" )
116
- set (pybind_flag 1)
117
- # It's enough to just adding one operator to pybind
118
- file (APPEND ${pybind_file} "USE_OP(conv2d_transpose);\n " )
119
- endif ()
120
-
121
- # conv_transpose_cudnn_op contains two operators
122
- if ("${TARGET} " STREQUAL "conv_transpose_cudnn_op" )
123
- set (pybind_flag 1)
124
- # It's enough to just adding one operator to pybind
125
- file (APPEND ${pybind_file} "USE_OP(conv2d_transpose_cudnn);\n " )
126
- endif ()
127
-
128
- # save_restore_op contains several operators
129
- if ("${TARGET} " STREQUAL "save_restore_op" )
130
- set (pybind_flag 1)
131
- # It's enough to just adding one operator to pybind
132
- file (APPEND ${pybind_file} "USE_NO_KERNEL_OP(save);\n " )
133
- endif ()
134
-
135
- # activation_op contains several operators
136
- if ("${TARGET} " STREQUAL "activation_op" )
137
- set (pybind_flag 1)
138
- # It's enough to just adding one operator to pybind
139
- file (APPEND ${pybind_file} "USE_OP(sigmoid);\n " )
140
- endif ()
141
-
142
- # nccl_op contains several operators
143
- if ("${TARGET} " STREQUAL "nccl_op" )
144
- set (pybind_flag 1)
145
- # It's enough to just adding one operator to pybind
146
- file (APPEND ${pybind_file} "USE_CUDA_ONLY_OP(ncclAllReduce);\n " )
147
- endif ()
148
-
149
- # reduce_op contains several operators
150
- if ("${TARGET} " STREQUAL "reduce_op" )
151
- set (pybind_flag 1)
152
- # It's enough to just adding one operator to pybind
153
- file (APPEND ${pybind_file} "USE_OP(reduce_sum);\n " )
154
- endif ()
64
+ # Define operators that don't need pybind here.
65
+ foreach (manual_pybind_op "net_op" "compare_op" "logical_op" "nccl_op" "tensor_array_read_write_op" )
66
+ if ("${TARGET} " STREQUAL "${manual_pybind_op} " )
67
+ set (pybind_flag 1)
68
+ endif ()
69
+ endforeach ()
155
70
156
- if ("${TARGET} " STREQUAL "tensor_array_read_write_op" )
157
- set (pybind_flag 1)
158
- file (APPEND ${pybind_file} "USE_NO_KERNEL_OP(read_from_array);\n USE_NO_KERNEL_OP(write_to_array);\n " )
71
+ # The registration of USE_OP, please refer to paddle/framework/op_registry.h.
72
+ # Note that it's enough to just adding one operator to pybind in a *_op.cc file.
73
+ # And for detail pybind information, please see generated paddle/pybind/pybind.h.
74
+ file (READ ${TARGET} .cc TARGET_CONTENT)
75
+ string (REGEX MATCH "REGISTER_OP\\ (.*REGISTER_OP\\ (" multi_register "${TARGET_CONTENT} " )
76
+ string (REGEX MATCH "REGISTER_OP\\ ([a-z0-9_]*," one_register "${multi_register} " )
77
+ if (one_register STREQUAL "" )
78
+ string (REPLACE "_op" "" TARGET "${TARGET} " )
79
+ else ()
80
+ string (REPLACE "REGISTER_OP(" "" TARGET "${one_register} " )
81
+ string (REPLACE "," "" TARGET "${TARGET} " )
159
82
endif ()
160
83
161
84
# pybind USE_NO_KERNEL_OP
162
85
# HACK: if REGISTER_OP_CPU_KERNEL presents the operator must have kernel
163
- file (READ ${TARGET} .cc TARGET_CONTENT)
164
86
string (REGEX MATCH "REGISTER_OP_CPU_KERNEL" regex_result "${TARGET_CONTENT} " )
165
87
string (REPLACE "_op" "" TARGET "${TARGET} " )
166
88
if (${pybind_flag} EQUAL 0 AND regex_result STREQUAL "" )
@@ -171,7 +93,6 @@ function(op_library TARGET)
171
93
# pybind USE_CPU_ONLY_OP
172
94
list (LENGTH cu_srcs cu_srcs_len)
173
95
list (LENGTH cu_cc_srcs cu_cc_srcs_len)
174
-
175
96
if (${pybind_flag} EQUAL 0 AND ${cu_srcs_len} EQUAL 0 AND ${cu_cc_srcs_len} EQUAL 0)
176
97
file (APPEND ${pybind_file} "USE_CPU_ONLY_OP(${TARGET} );\n " )
177
98
set (pybind_flag 1)
@@ -188,6 +109,7 @@ add_subdirectory(nccl)
188
109
189
110
if (WITH_GPU)
190
111
op_library(nccl_op DEPS nccl_common)
112
+ file (APPEND ${pybind_file} "USE_CUDA_ONLY_OP(ncclAllReduce);\n " )
191
113
else ()
192
114
set (DEPS_OPS ${DEPS_OPS} nccl_op)
193
115
endif ()
@@ -238,6 +160,8 @@ list(REMOVE_ITEM GENERAL_OPS ${DEPS_OPS})
238
160
foreach (src ${GENERAL_OPS} )
239
161
op_library(${src} )
240
162
endforeach ()
163
+ file (APPEND ${pybind_file} "USE_OP(less_than);\n USE_OP(logical_and);\n USE_NO_KERNEL_OP(read_from_array);\n " )
164
+
241
165
242
166
set (GLOB_OP_LIB ${OP_LIBRARY} CACHE INTERNAL "Global OP library" )
243
167
0 commit comments