@@ -17,39 +17,56 @@ cmake_minimum_required(VERSION 3.10)
17
17
project (paddle-custom-gcu CXX C)
18
18
set (CUSTOM_GCU_NAME "paddle-custom-gcu" )
19
19
20
- set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR } /cmake" )
20
+ set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR } /cmake" )
21
21
message (STATUS "CMAKE_DEBUG CMAKE_MODULE_PATH is: ${CMAKE_MODULE_PATH} " )
22
+ option (VERSION_WITH_GIT "Use git hash to PACKAGE_VERSION" FALSE )
22
23
23
24
set (TOPS_RELEASE_VERSION 3.1.0)
24
25
if ((NOT DEFINED PACKAGE_VERSION )
25
26
OR ("${PACKAGE_VERSION} " STREQUAL "" )
26
27
OR ("${PACKAGE_VERSION} " STREQUAL "123.456" ))
27
- # get Paddle-custom git hash
28
- execute_process (
29
- COMMAND git log -1 --abbrev=7 --format=%h
30
- WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
31
- OUTPUT_VARIABLE GIT_HASH
32
- OUTPUT_STRIP_TRAILING_WHITESPACE)
33
- message (STATUS "git hash: ${GIT_HASH} " )
34
- set (GIT_HASH ".${GIT_HASH} " )
35
- else ()
36
- set (GIT_HASH "" )
37
- set (TOPS_RELEASE_VERSION ${PACKAGE_VERSION} )
28
+ if (VERSION_WITH_GIT)
29
+ # get Paddle-custom git hash
30
+ execute_process (
31
+ COMMAND git log -1 --abbrev=7 --format=%h
32
+ WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
33
+ OUTPUT_VARIABLE _tag
34
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
35
+ message (STATUS "git hash: ${_tag} " )
36
+ else ()
37
+ string (TIMESTAMP _tag "%Y%m%d" )
38
+ endif ()
39
+ set (PACKAGE_VERSION ${TOPS_RELEASE_VERSION} .${_tag} )
38
40
endif ()
39
- set (PACKAGE_VERSION ${GIT_HASH} -${TOPS_RELEASE_VERSION} )
40
41
41
- message (STATUS "tops release version: ${TOPS_RELEASE_VERSION} " )
42
42
message (STATUS "package version: ${PACKAGE_VERSION} " )
43
43
44
+ if (DEFINED PY_VERSION)
45
+ message (STATUS "User define PY_VERSION: ${PY_VERSION} " )
46
+ else ()
47
+ set (PY_VERSION "3.10" )
48
+ message (STATUS "Use default PY_VERSION: ${PY_VERSION} " )
49
+ endif ()
50
+ set (PYTHON_VERSION ${PY_VERSION} )
51
+ set (Python_EXECUTABLE "python${PY_VERSION} " )
52
+ message (STATUS "Python_EXECUTABLE: ${Python_EXECUTABLE} " )
53
+
54
+ if (NOT DEFINED ENV{PADDLE_VERSION})
55
+ set (ENV{PADDLE_VERSION} 3.0.0-beta1)
56
+ endif ()
57
+
44
58
include (paddle)
45
59
include (version )
46
60
include (generic)
47
61
include (external/gcu)
62
+ include (external/topscc)
48
63
49
- include_directories (${CMAKE_SOURCE_DIR } )
64
+ include_directories (${CMAKE_CURRENT_SOURCE_DIR } )
50
65
include_directories (/opt/tops/include )
51
66
52
- set (OUTPUT_PADDLE_PACKAGE_VERSION ${PADDLE_VERSION}${PACKAGE_VERSION} )
67
+ set (OUTPUT_PADDLE_PACKAGE_VERSION ${PADDLE_VERSION} +${PACKAGE_VERSION} )
68
+ string (REPLACE "-beta" "b" OUTPUT_PADDLE_PACKAGE_VERSION
69
+ "${OUTPUT_PADDLE_PACKAGE_VERSION} " )
53
70
option (WITH_KERNELS "compile with custom kernels" ON )
54
71
option (WITH_TESTING "compile with unit testing" OFF )
55
72
option (WITH_MKL "compile with mkl support" ON )
@@ -62,12 +79,6 @@ message(STATUS "C compiler: ${CMAKE_C_COMPILER}, version: "
62
79
"${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION} " )
63
80
message (STATUS "AR tools: ${CMAKE_AR} " )
64
81
65
- if (DEFINED PY_VERSION)
66
- message (STATUS "User define PY_VERSION: ${PY_VERSION} " )
67
- set (Python_EXECUTABLE "python${PY_VERSION} " )
68
- endif ()
69
- message (STATUS "Python_EXECUTABLE: ${Python_EXECUTABLE} " )
70
-
71
82
# custom runtime
72
83
set (CUSTOM_GCU_SRCS runtime/runtime.cc)
73
84
add_definitions (-DPADDLE_WITH_CUSTOM_DEVICE)
@@ -81,12 +92,12 @@ if(WITH_KERNELS)
81
92
add_compile_definitions (HLIR_BUILDER_ABI_COMPATIABLE)
82
93
file (
83
94
GLOB_RECURSE CUSTOM_KERNEL_SRCS
84
- RELATIVE ${CMAKE_SOURCE_DIR }
95
+ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR }
85
96
kernels/*.cc)
86
97
list (APPEND CUSTOM_GCU_SRCS ${CUSTOM_KERNEL_SRCS} )
87
98
file (
88
99
GLOB_RECURSE GCU_KERNEL_DEPENDS
89
- RELATIVE ${CMAKE_SOURCE_DIR }
100
+ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR }
90
101
backend/*.cc common/*.cc)
91
102
# build static library
92
103
set (GCU_DEPENDS_NAME "gcu-kernels-depend" )
@@ -99,7 +110,7 @@ if(WITH_KERNELS)
99
110
# custom op with kernel
100
111
file (
101
112
GLOB_RECURSE CUSTOM_CUSTOM_OP_SRCS
102
- RELATIVE ${CMAKE_SOURCE_DIR }
113
+ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR }
103
114
custom_op/*.cc)
104
115
list (APPEND CUSTOM_GCU_SRCS ${CUSTOM_CUSTOM_OP_SRCS} )
105
116
endif ()
@@ -108,22 +119,44 @@ if(ON_INFER)
108
119
link_directories (${PADDLE_INFERENCE_LIB_DIR} )
109
120
endif ()
110
121
122
+ # topscc kernels
123
+ file (GLOB_RECURSE TOPSCC_KERNEL_SRCS
124
+ ${CMAKE_CURRENT_SOURCE_DIR} /topscc_custom_kernels/*.cc
125
+ ${CMAKE_CURRENT_SOURCE_DIR} /topscc_custom_kernels/*.cpp)
126
+ list (LENGTH TOPSCC_KERNEL_SRCS TOPSCC_KERNEL_SRCS_LEN)
127
+ unset (TOPSCC_LIBS)
128
+ if (${TOPSCC_KERNEL_SRCS_LEN} GREATER 0)
129
+ topscc_compile(FALSE ${TOPSCC_KERNEL_SRCS} "-shared -fPIC -O3 " TOPSCC_LIBS)
130
+ message (STATUS "TOPSCC_LIBS: ${TOPSCC_LIBS} " )
131
+ endif ()
132
+
111
133
# build shared library
112
134
add_library (${CUSTOM_GCU_NAME} SHARED ${CUSTOM_GCU_SRCS} )
135
+
136
+ # for link topscc custom kernels
137
+ set_target_properties (
138
+ ${CUSTOM_GCU_NAME}
139
+ PROPERTIES
140
+ LINK_FLAGS
141
+ "-Wl,-rpath,/usr/local/lib/python${PY_VERSION} /dist-packages/paddle_custom_device/gcu/"
142
+ )
143
+
113
144
target_link_libraries (${CUSTOM_GCU_NAME} PRIVATE ${GCU_LIBS} )
114
145
if (WITH_KERNELS)
115
146
target_link_libraries (${CUSTOM_GCU_NAME} PRIVATE ${GCU_DEPENDS_NAME} )
116
- target_link_libraries (
117
- ${CUSTOM_GCU_NAME}
118
- PRIVATE -Wl,--whole-archive ${TOPSOP_LIB_DIR} /libtopsop.a
119
- -Wl,--no -whole-archive)
120
147
endif ()
121
148
if (TOPS_MODULE_SOURCE_DIR)
122
149
target_include_directories (${CUSTOM_GCU_NAME}
123
150
PRIVATE ${TOPS_MODULE_SOURCE_DIR} /usr/include )
124
151
target_include_directories (${CUSTOM_GCU_NAME}
125
152
PRIVATE ${TOPS_MODULE_SOURCE_DIR} /opt/tops/include )
126
153
endif ()
154
+ # link topscc kernel libs
155
+ add_custom_target (CUSTOM_TOPSCC_LIBS ALL DEPENDS ${TOPSCC_LIBS} )
156
+ if (${TOPSCC_KERNEL_SRCS_LEN} GREATER 0)
157
+ add_dependencies (${CUSTOM_GCU_NAME} CUSTOM_TOPSCC_LIBS)
158
+ target_link_libraries (${CUSTOM_GCU_NAME} PRIVATE ${TOPSCC_LIBS} )
159
+ endif ()
127
160
128
161
# link paddle shared library
129
162
include (${CMAKE_CURRENT_SOURCE_DIR} /cmake/third_party.cmake)
@@ -142,11 +175,12 @@ else()
142
175
endif ()
143
176
144
177
# export paddle_gcu interface with version map
145
- set_property (TARGET ${CUSTOM_GCU_NAME}
146
- PROPERTY LINK_DEPENDS ${CMAKE_SOURCE_DIR} /paddle_gcu_export.map)
178
+ set_property (
179
+ TARGET ${CUSTOM_GCU_NAME}
180
+ PROPERTY LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR} /paddle_gcu_export.map)
147
181
target_link_options (
148
182
${CUSTOM_GCU_NAME} PRIVATE
149
- -Wl,--version -script=${CMAKE_SOURCE_DIR } /paddle_gcu_export.map)
183
+ -Wl,--version -script=${CMAKE_CURRENT_SOURCE_DIR } /paddle_gcu_export.map)
150
184
151
185
# testing
152
186
if (WITH_TESTING)
@@ -155,7 +189,7 @@ if(WITH_TESTING)
155
189
add_subdirectory (tests)
156
190
add_custom_command (
157
191
OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /tests/.timestamp
158
- COMMAND cp -r ${CMAKE_SOURCE_DIR } /tests ${CMAKE_CURRENT_BINARY_DIR} )
192
+ COMMAND cp -r ${CMAKE_CURRENT_SOURCE_DIR } /tests ${CMAKE_CURRENT_BINARY_DIR} )
159
193
add_custom_target (python_tests ALL
160
194
DEPENDS ${CMAKE_CURRENT_BINARY_DIR} /tests/.timestamp)
161
195
endif ()
@@ -194,13 +228,35 @@ add_custom_target(
194
228
${CMAKE_CURRENT_BINARY_DIR} /python/paddle_custom_device/lib${CUSTOM_GCU_NAME} .so
195
229
)
196
230
231
+ set (topscc_kernel_lib_targets "" )
232
+ unset (topscc_kernel_lib_targets)
233
+ foreach (topscc_kernel_lib ${TOPSCC_LIBS} )
234
+ get_filename_component (topscc_kernel_lib_name ${topscc_kernel_lib} NAME_WLE)
235
+ get_filename_component (topscc_kernel_lib_target_name ${topscc_kernel_lib}
236
+ NAME_WE )
237
+ message (STATUS "topscc_kernel_lib_name: ${topscc_kernel_lib_name} " )
238
+ add_custom_command (
239
+ OUTPUT
240
+ ${CMAKE_CURRENT_BINARY_DIR} /python/paddle_custom_device/gcu/${topscc_kernel_lib_name}
241
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${topscc_kernel_lib}
242
+ ${CMAKE_CURRENT_BINARY_DIR} /python/paddle_custom_device/gcu
243
+ USES_TERMINAL
244
+ DEPENDS ${topscc_kernel_lib} )
245
+ list (
246
+ APPEND
247
+ topscc_kernel_lib_targets
248
+ ${CMAKE_CURRENT_BINARY_DIR} /python/paddle_custom_device/gcu/${topscc_kernel_lib_name}
249
+ )
250
+ endforeach ()
251
+ add_custom_target (topscc_targets ALL DEPENDS ${topscc_kernel_lib_targets} )
252
+
197
253
set (whl_file
198
- "${CMAKE_BINARY_DIR } /dist/paddle_custom_gcu-${OUTPUT_PADDLE_PACKAGE_VERSION} -cp${PY_VERSION_NO_DOT} -cp${PY_VERSION_NO_DOT} -linux_x86_64.whl"
254
+ "${CMAKE_CURRENT_BINARY_DIR } /dist/paddle_custom_gcu-${OUTPUT_PADDLE_PACKAGE_VERSION} -cp${PY_VERSION_NO_DOT} -cp${PY_VERSION_NO_DOT} -linux_x86_64.whl"
199
255
)
200
256
set (_passes_target_dir
201
257
"${CMAKE_CURRENT_BINARY_DIR} /python/paddle_custom_device/gcu/passes" )
202
258
file (MAKE_DIRECTORY ${_passes_target_dir} )
203
- file (GLOB passes_srcs "${CMAKE_SOURCE_DIR } /passes/*" )
259
+ file (GLOB passes_srcs "${CMAKE_CURRENT_SOURCE_DIR } /passes/*" )
204
260
foreach (passes_src IN LISTS passes_srcs)
205
261
get_filename_component (passes_file_name ${passes_src} NAME )
206
262
add_custom_command (
@@ -212,11 +268,11 @@ foreach(passes_src IN LISTS passes_srcs)
212
268
endforeach ()
213
269
add_custom_command (
214
270
OUTPUT ${whl_file}
215
- COMMAND ${Python_EXECUTABLE} ${CMAKE_BINARY_DIR } /setup.py bdist_wheel
271
+ COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR } /setup.py bdist_wheel
216
272
# COMMAND rename 's/_${TOPS_RELEASE_VERSION}/-${TOPS_RELEASE_VERSION}/g'
217
273
# ${CMAKE_CURRENT_BINARY_DIR}/dist/*.whl
218
- DEPENDS ${CUSTOM_GCU_NAME} CUSTOM_GCU_NAME_shared_lib_copy
219
- ${CMAKE_BINARY_DIR } /setup.py ${passes_bin_files_list}
274
+ DEPENDS ${CUSTOM_GCU_NAME} CUSTOM_GCU_NAME_shared_lib_copy topscc_targets
275
+ ${CMAKE_CURRENT_BINARY_DIR } /setup.py ${passes_bin_files_list}
220
276
COMMENT "Packing whl packages------>>>" )
221
277
222
278
add_custom_target (python_package ALL DEPENDS ${whl_file} )
0 commit comments