Skip to content

Commit a4eaf2d

Browse files
authored
Merge pull request #2897 from reyoung/feature/op_library
CMake `op_library` function
2 parents 0ddbdbb + 38310f9 commit a4eaf2d

File tree

3 files changed

+67
-10
lines changed

3 files changed

+67
-10
lines changed

paddle/framework/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
# ddim lib
1+
cc_library(enforce SRCS enforce.cc DEPS glog)
2+
cc_test(enforce_test SRCS enforce_test.cc DEPS enforce)
23
cc_library(ddim SRCS ddim.cc)
34
cc_test(ddim_test SRCS ddim_test.cc DEPS ddim)
45
nv_test(dim_test SRCS dim_test.cu DEPS ddim)
5-
cc_test(tensor_test SRCS tensor_test.cc DEPS ddim glog gflags)
6+
cc_library(tensor SRCS tensor.cc DEPS ddim place enforce paddle_memory)
7+
cc_test(tensor_test SRCS tensor_test.cc DEPS tensor)
68
cc_test(variable_test SRCS variable_test.cc)
79
cc_test(scope_test SRCS scope_test.cc)
8-
cc_library(enforce SRCS enforce.cc DEPS glog gflags)
9-
cc_test(enforce_test SRCS enforce_test.cc DEPS enforce)
1010
proto_library(attr_type SRCS attr_type.proto)
1111
proto_library(op_proto SRCS op_proto.proto DEPS attr_type)
1212
cc_test(op_proto_test SRCS op_proto_test.cc DEPS op_proto protobuf)
1313
proto_library(op_desc SRCS op_desc.proto DEPS attr_type)
1414
cc_test(op_desc_test SRCS op_desc_test.cc DEPS op_desc protobuf)
1515

16-
cc_library(operator SRCS operator.cc DEPS op_desc device_context enforce)
16+
cc_library(operator SRCS operator.cc DEPS op_desc device_context tensor)
1717
cc_test(operator_test SRCS operator_test.cc DEPS operator op_registry)
1818

1919
cc_library(op_registry SRCS op_registry.cc DEPS op_proto op_desc enforce)

paddle/framework/tensor.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License. */
14+
15+
#include <paddle/framework/tensor.h>
16+
17+
namespace paddle {
18+
namespace framework {}
19+
} // namespace paddle

paddle/operators/CMakeLists.txt

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,44 @@
1-
if(WITH_GPU)
2-
nv_library(add_op SRCS add_op.cc add_op.cu DEPS operator op_registry glog ddim)
3-
else()
4-
cc_library(add_op SRCS add_op.cc DEPS operator op_registry glog ddim)
5-
endif()
1+
function(op_library TARGET)
2+
# op_library is a function to create op library. The interface is same as
3+
# cc_library. But it handle split GPU/CPU code and link some common library
4+
# for ops.
5+
set(cc_srcs)
6+
set(cu_srcs)
7+
set(op_common_deps operator op_registry)
8+
set(options "")
9+
set(oneValueArgs "")
10+
set(multiValueArgs SRCS DEPS)
11+
cmake_parse_arguments(op_library "${options}" "${oneValueArgs}"
12+
"${multiValueArgs}" ${ARGN})
13+
14+
foreach(src ${op_library_SRCS})
15+
if (${src} MATCHES ".*\\.cu$")
16+
list(APPEND cu_srcs ${src})
17+
elseif(${src} MATCHES ".*\\.cc$")
18+
list(APPEND cc_srcs ${src})
19+
else()
20+
message(FATAL_ERROR "${TARGET} Source file ${src} should only be .cc or .cu")
21+
endif()
22+
endforeach()
23+
24+
list(LENGTH cc_srcs cc_srcs_len)
25+
if (${cc_srcs_len} EQUAL 0)
26+
message(FATAL_ERROR "The op library ${TARGET} should contains at least one .cc file")
27+
endif()
28+
29+
list(LENGTH cu_srcs cu_srcs_len)
30+
if (${cu_srcs_len} EQUAL 0)
31+
message(WARNING "The op library ${TARGET} not support GPU!")
32+
endif()
33+
34+
if (WITH_GPU)
35+
nv_library(${TARGET} SRCS ${cc_srcs} ${cu_srcs} DEPS ${op_library_DEPS}
36+
${op_common_deps})
37+
else()
38+
cc_library(${TARGET} SRCS ${cc_srcs} DEPS ${op_library_DEPS}
39+
${op_common_deps})
40+
endif()
41+
endfunction()
42+
43+
op_library(add_op SRCS add_op.cc add_op.cu)
644
cc_test(add_op_test SRCS add_op_test.cc DEPS add_op)

0 commit comments

Comments
 (0)