Skip to content

Commit 1749d40

Browse files
authored
Merge pull request #8682 from luotao1/math_function
refine operators/math/CMakeLists.txt
2 parents c89664e + 49f3f1d commit 1749d40

File tree

3 files changed

+58
-49
lines changed

3 files changed

+58
-49
lines changed

paddle/fluid/operators/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,18 +190,18 @@ op_library(cos_sim_op DEPS cos_sim_functor)
190190
op_library(parallel_do_op DEPS executor)
191191

192192
if (WITH_GPU)
193-
op_library(conv_op DEPS vol2col depthwise_conv)
193+
op_library(conv_op DEPS vol2col depthwise_conv im2col)
194194
else()
195-
op_library(conv_op DEPS vol2col)
195+
op_library(conv_op DEPS vol2col im2col)
196196
endif()
197-
op_library(conv_transpose_op DEPS vol2col)
197+
op_library(conv_transpose_op DEPS vol2col im2col)
198198

199199
# FIXME(typhoonzero): save/load depends lodtensor serialization functions
200200
op_library(save_op DEPS lod_tensor)
201201
op_library(load_op DEPS lod_tensor)
202202
op_library(save_combine_op DEPS lod_tensor)
203203
op_library(load_combine_op DEPS lod_tensor)
204-
op_library(concat_op DEPS concat_functor)
204+
op_library(concat_op DEPS concat)
205205

206206
list(REMOVE_ITEM GENERAL_OPS ${DEPS_OPS})
207207
foreach(src ${GENERAL_OPS})
Lines changed: 54 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,59 @@
11
add_subdirectory(detail)
22

3-
if(WITH_GPU)
4-
nv_library(math_function SRCS math_function.cc math_function.cu im2col.cc im2col.cu DEPS cblas device_context framework_proto)
5-
nv_test(math_function_gpu_test SRCS math_function_test.cu DEPS math_function tensor)
6-
nv_library(selected_rows_functor SRCS selected_rows_functor.cc selected_rows_functor.cu DEPS selected_rows math_function)
7-
nv_test(selected_rows_functor_gpu_test SRCS selected_rows_functor_test.cu DEPS selected_rows_functor)
8-
nv_library(softmax SRCS softmax.cc softmax.cu DEPS device_context)
9-
nv_library(cross_entropy SRCS cross_entropy.cc cross_entropy.cu DEPS device_context)
10-
nv_library(pooling SRCS pooling.cc pooling.cu DEPS device_context)
11-
nv_library(depthwise_conv SRCS depthwise_conv.cu DEPS device_context)
12-
nv_library(sequence_pooling SRCS sequence_pooling.cc sequence_pooling.cu DEPS device_context math_function)
13-
nv_library(vol2col SRCS vol2col.cc vol2col.cu DEPS device_context tensor)
14-
nv_library(context_project SRCS context_project.cc context_project.cu DEPS device_context math_function)
15-
nv_library(sequence2batch SRCS sequence2batch.cc sequence2batch.cu DEPS device_context tensor math_function)
16-
nv_library(sequence_padding SRCS sequence_padding.cc sequence_padding.cu DEPS lod_tensor device_context)
17-
nv_library(sequence_scale SRCS sequence_scale.cc sequence_scale.cu DEPS lod_tensor device_context)
18-
nv_library(lstm_compute SRCS lstm_compute.cc lstm_compute.cu DEPS device_context activation_functions)
19-
nv_library(maxouting SRCS maxouting.cc maxouting.cu DEPS device_context)
20-
nv_library(unpooling SRCS unpooling.cc unpooling.cu DEPS device_context)
21-
nv_library(gru_compute SRCS gru_compute.cc gru_compute.cu DEPS device_context activation_functions math_function)
22-
nv_library(cos_sim_functor SRCS cos_sim_functor.cc cos_sim_functor.cu DEPS device_context)
23-
nv_library(concat_functor SRCS concat.cc concat.cu DEPS device_context tensor)
24-
else()
25-
cc_library(math_function SRCS math_function.cc im2col.cc DEPS cblas device_context framework_proto)
26-
cc_library(selected_rows_functor SRCS selected_rows_functor.cc DEPS selected_rows math_function)
27-
cc_library(softmax SRCS softmax.cc DEPS device_context)
28-
cc_library(cross_entropy SRCS cross_entropy.cc DEPS device_context)
29-
cc_library(pooling SRCS pooling.cc DEPS device_context)
30-
cc_library(sequence_pooling SRCS sequence_pooling.cc DEPS device_context math_function)
31-
cc_library(vol2col SRCS vol2col.cc DEPS device_context tensor)
32-
cc_library(context_project SRCS context_project.cc DEPS device_context math_function)
33-
cc_library(sequence2batch SRCS sequence2batch.cc DEPS device_context tensor math_function)
34-
cc_library(sequence_padding SRCS sequence_padding.cc DEPS lod_tensor device_context)
35-
cc_library(sequence_scale SRCS sequence_scale.cc DEPS lod_tensor device_context)
36-
cc_library(lstm_compute SRCS lstm_compute.cc DEPS device_context activation_functions)
37-
cc_library(maxouting SRCS maxouting.cc DEPS device_context)
38-
cc_library(unpooling SRCS unpooling.cc DEPS device_context)
39-
cc_library(gru_compute SRCS gru_compute.cc DEPS device_context activation_functions math_function)
40-
cc_library(cos_sim_functor SRCS cos_sim_functor.cc DEPS device_context)
41-
cc_library(concat_functor SRCS concat.cc DEPS device_context tensor)
42-
endif()
3+
function(math_library TARGET)
4+
# math_library is a function to create math library.
5+
# The interface is the same as cc_library.
6+
# But it handle split GPU/CPU code and link some common library.
7+
set(cc_srcs)
8+
set(cu_srcs)
9+
set(math_common_deps device_context framework_proto)
10+
set(multiValueArgs DEPS)
11+
cmake_parse_arguments(math_library "${options}" "${oneValueArgs}"
12+
"${multiValueArgs}" ${ARGN})
13+
14+
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${TARGET}.cc)
15+
list(APPEND cc_srcs ${TARGET}.cc)
16+
endif()
17+
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${TARGET}.cu)
18+
list(APPEND cu_srcs ${TARGET}.cu)
19+
endif()
20+
21+
list(LENGTH cc_srcs cc_srcs_len)
22+
if (WITH_GPU)
23+
nv_library(${TARGET} SRCS ${cc_srcs} ${cu_srcs} DEPS ${math_library_DEPS} ${math_common_deps})
24+
elseif(${cc_srcs_len} GREATER 0)
25+
cc_library(${TARGET} SRCS ${cc_srcs} DEPS ${math_library_DEPS} ${math_common_deps})
26+
endif()
27+
endfunction()
4328

44-
cc_test(math_function_test SRCS math_function_test.cc DEPS math_function tensor)
29+
# please add new math_library in alphabetical order
30+
math_library(concat)
31+
math_library(context_project DEPS im2col math_function)
32+
math_library(cross_entropy)
33+
math_library(cos_sim_functor)
34+
math_library(depthwise_conv)
35+
math_library(gru_compute DEPS activation_functions math_function)
36+
math_library(im2col)
37+
math_library(lstm_compute DEPS activation_functions)
38+
math_library(math_function DEPS cblas)
39+
math_library(maxouting)
40+
math_library(pooling)
41+
math_library(selected_rows_functor DEPS selected_rows)
42+
math_library(sequence2batch)
43+
math_library(sequence_padding)
44+
math_library(sequence_pooling DEPS math_function)
45+
math_library(sequence_scale)
46+
math_library(softmax)
47+
math_library(unpooling)
48+
math_library(vol2col)
49+
50+
cc_test(math_function_test SRCS math_function_test.cc)
4551
cc_test(selected_rows_functor_test SRCS selected_rows_functor_test.cc DEPS selected_rows_functor)
46-
cc_test(im2col_test SRCS im2col_test.cc DEPS math_function tensor)
47-
cc_test(vol2col_test SRCS vol2col_test.cc DEPS vol2col tensor)
52+
cc_test(im2col_test SRCS im2col_test.cc DEPS im2col)
53+
cc_test(vol2col_test SRCS vol2col_test.cc DEPS vol2col)
4854
cc_test(sequence_padding_test SRCS sequence_padding_test.cc DEPS sequence_padding)
49-
cc_test(concat_test SRCS concat_test.cc DEPS concat_functor tensor)
55+
if(WITH_GPU)
56+
nv_test(math_function_gpu_test SRCS math_function_test.cu)
57+
nv_test(selected_rows_functor_gpu_test SRCS selected_rows_functor_test.cu DEPS selected_rows_functor)
58+
endif()
59+
cc_test(concat_test SRCS concat_test.cc DEPS concat)

paddle/fluid/operators/math/sequence2batch.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

1515
#include "paddle/fluid/operators/math/sequence2batch.h"
16-
#include "paddle/fluid/operators/math/math_function.h"
1716

1817
namespace paddle {
1918
namespace operators {

0 commit comments

Comments
 (0)