@@ -22,7 +22,6 @@ endif()
22
22
23
23
# Custom options for Paddle Inference backend
24
24
option (PADDLEINFERENCE_DIRECTORY "Directory of custom Paddle Inference library" OFF )
25
- option (PADDLEINFERENCE_WITH_ENCRYPT_AUTH "Whether the Paddle Inference is built with FD encryption and auth" OFF )
26
25
27
26
set (PADDLEINFERENCE_PROJECT "extern_paddle_inference" )
28
27
set (PADDLEINFERENCE_PREFIX_DIR ${THIRD_PARTY_PATH} /paddle_inference)
@@ -43,44 +42,15 @@ if(PADDLEINFERENCE_DIRECTORY)
43
42
endif ()
44
43
45
44
include_directories (${PADDLEINFERENCE_INC_DIR} )
46
- if (WIN32 )
47
- set (PADDLEINFERENCE_COMPILE_LIB
48
- "${PADDLEINFERENCE_INSTALL_DIR} /paddle/lib/paddle_inference.lib"
49
- CACHE FILEPATH "paddle_inference compile library." FORCE)
50
- set (DNNL_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/mkldnn/lib/mkldnn.lib" )
51
- set (OMP_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/mklml/lib/libiomp5md.lib" )
52
- set (P2O_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/paddle2onnx/lib/paddle2onnx.lib" )
53
- set (ORT_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/onnxruntime/lib/onnxruntime.lib" )
54
- elseif (APPLE )
55
- set (PADDLEINFERENCE_COMPILE_LIB
56
- "${PADDLEINFERENCE_INSTALL_DIR} /paddle/lib/libpaddle_inference.dylib"
57
- CACHE FILEPATH "paddle_inference compile library." FORCE)
58
- set (DNNL_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/mkldnn/lib/libdnnl.so.2" )
59
- set (OMP_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/mklml/lib/libiomp5.so" )
60
- set (P2O_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/paddle2onnx/lib/libpaddle2onnx.dylib" )
61
- set (ORT_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/onnxruntime/lib/libonnxruntime.dylib" )
62
- else ()
63
- set (PADDLEINFERENCE_COMPILE_LIB
64
- "${PADDLEINFERENCE_INSTALL_DIR} /paddle/lib/libpaddle_inference.so"
65
- CACHE FILEPATH "paddle_inference compile library." FORCE)
66
- set (DNNL_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/mkldnn/lib/libdnnl.so.2" )
67
- set (OMP_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/mklml/lib/libiomp5.so" )
68
- set (P2O_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/paddle2onnx/lib/libpaddle2onnx.so" )
69
- set (ORT_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/onnxruntime/lib/libonnxruntime.so" )
70
- if (PADDLEINFERENCE_WITH_ENCRYPT_AUTH)
71
- set (FDMODEL_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/fdmodel/lib/libfastdeploy_wenxin.so" )
72
- set (FDMODEL_AUTH_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/fdmodel/lib/libfastdeploy_auth.so" )
73
- set (FDMODEL_MODEL_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/fdmodel/lib/libfastdeploy_model.so.2.0.0" )
74
- set (LEVELDB_LIB_DIR "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/leveldb/lib" )
75
- endif ()
76
- endif (WIN32 )
77
45
78
46
if (PADDLEINFERENCE_DIRECTORY)
79
47
# Use custom Paddle Inference libs.
80
48
if (EXISTS "${THIRD_PARTY_PATH} /install/paddle_inference" )
81
49
file (REMOVE_RECURSE "${THIRD_PARTY_PATH} /install/paddle_inference" )
82
50
endif ()
83
- find_package (Python COMPONENTS Interpreter Development REQUIRED)
51
+ if (NOT Python_EXECUTABLE)
52
+ find_package (Python COMPONENTS Interpreter Development REQUIRED)
53
+ endif ()
84
54
message (STATUS "Copying ${PADDLEINFERENCE_DIRECTORY} to ${THIRD_PARTY_PATH} /install/paddle_inference ..." )
85
55
if (WIN32 )
86
56
execute_process (COMMAND mkdir -p ${THIRD_PARTY_PATH} /install )
@@ -166,6 +136,51 @@ else()
166
136
167
137
endif (PADDLEINFERENCE_DIRECTORY)
168
138
139
+ # check libs
140
+ set (PADDLEINFERENCE_WITH_AUTH OFF )
141
+ set (PADDLEINFERENCE_WITH_ENCRYPT OFF )
142
+ if (WIN32 )
143
+ set (PADDLEINFERENCE_COMPILE_LIB
144
+ "${PADDLEINFERENCE_INSTALL_DIR} /paddle/lib/paddle_inference.lib"
145
+ CACHE FILEPATH "paddle_inference compile library." FORCE)
146
+ set (DNNL_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/mkldnn/lib/mkldnn.lib" )
147
+ set (OMP_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/mklml/lib/libiomp5md.lib" )
148
+ set (P2O_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/paddle2onnx/lib/paddle2onnx.lib" )
149
+ set (ORT_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/onnxruntime/lib/onnxruntime.lib" )
150
+ elseif (APPLE )
151
+ set (PADDLEINFERENCE_COMPILE_LIB
152
+ "${PADDLEINFERENCE_INSTALL_DIR} /paddle/lib/libpaddle_inference.dylib"
153
+ CACHE FILEPATH "paddle_inference compile library." FORCE)
154
+ set (DNNL_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/mkldnn/lib/libdnnl.so.2" )
155
+ set (OMP_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/mklml/lib/libiomp5.so" )
156
+ set (P2O_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/paddle2onnx/lib/libpaddle2onnx.dylib" )
157
+ set (ORT_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/onnxruntime/lib/libonnxruntime.dylib" )
158
+ else ()
159
+ set (PADDLEINFERENCE_COMPILE_LIB
160
+ "${PADDLEINFERENCE_INSTALL_DIR} /paddle/lib/libpaddle_inference.so"
161
+ CACHE FILEPATH "paddle_inference compile library." FORCE)
162
+ set (DNNL_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/mkldnn/lib/libdnnl.so.2" )
163
+ set (OMP_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/mklml/lib/libiomp5.so" )
164
+ set (P2O_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/paddle2onnx/lib/libpaddle2onnx.so" )
165
+ set (ORT_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/onnxruntime/lib/libonnxruntime.so" )
166
+ # Check whether the encrypt and auth tools exists. only support PADDLEINFERENCE_DIRECTORY now.
167
+ if (PADDLEINFERENCE_DIRECTORY)
168
+ set (FDMODEL_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/fdmodel/lib/libfastdeploy_wenxin.so" )
169
+ set (FDMODEL_MODEL_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/fdmodel/lib/libfastdeploy_model.so.2.0.0" )
170
+ set (FDMODEL_AUTH_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/fdmodel/lib/libfastdeploy_auth.so" )
171
+ set (FDMODEL_LEVELDB_LIB_DIR "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/leveldb" )
172
+ set (FDMODEL_LEVELDB_LIB_LIB "${PADDLEINFERENCE_INSTALL_DIR} /third_party/install/leveldb/lib/libleveldb.a" )
173
+ if ((EXISTS ${FDMODEL_LIB} ) AND (EXISTS ${FDMODEL_MODEL_LIB} ))
174
+ set (PADDLEINFERENCE_WITH_ENCRYPT ON CACHE BOOL "" FORCE)
175
+ message (STATUS "Detected ${FDMODEL_LIB} and ${FDMODEL_MODEL_LIB} exists, fource PADDLEINFERENCE_WITH_ENCRYPT=${PADDLEINFERENCE_WITH_ENCRYPT} " )
176
+ endif ()
177
+ if ((EXISTS ${FDMODEL_LIB} ) AND (EXISTS ${FDMODEL_AUTH_LIB} ))
178
+ set (PADDLEINFERENCE_WITH_AUTH ON CACHE BOOL "" FORCE)
179
+ message (STATUS "Detected ${FDMODEL_LIB} and ${FDMODEL_AUTH_LIB} exists, fource PADDLEINFERENCE_WITH_AUTH=${PADDLEINFERENCE_WITH_AUTH} " )
180
+ endif ()
181
+ endif ()
182
+ endif (WIN32 )
183
+
169
184
# Path Paddle Inference ELF lib file
170
185
if (UNIX AND (NOT APPLE ) AND (NOT ANDROID))
171
186
add_custom_target (patchelf_paddle_inference ALL COMMAND bash -c "PATCHELF_EXE=${PATCHELF_EXE} python ${PROJECT_SOURCE_DIR} /scripts/patch_paddle_inference.py ${PADDLEINFERENCE_INSTALL_DIR} /paddle/lib/libpaddle_inference.so" DEPENDS ${LIBRARY_NAME} )
@@ -198,28 +213,37 @@ set_property(TARGET external_omp PROPERTY IMPORTED_LOCATION
198
213
add_dependencies (external_omp ${PADDLEINFERENCE_PROJECT} )
199
214
200
215
set (ENCRYPT_AUTH_LIBS )
201
- if (PADDLEINFERENCE_WITH_ENCRYPT_AUTH )
216
+ if (PADDLEINFERENCE_WITH_ENCRYPT )
202
217
add_library (external_fdmodel STATIC IMPORTED GLOBAL )
203
218
set_property (TARGET external_fdmodel PROPERTY IMPORTED_LOCATION
204
219
${FDMODEL_LIB} )
205
- add_library (external_fdmodel_auth STATIC IMPORTED GLOBAL )
206
- set_property (TARGET external_fdmodel_auth PROPERTY IMPORTED_LOCATION
207
- ${FDMODEL_AUTH_LIB} )
220
+
208
221
add_library (external_fdmodel_model STATIC IMPORTED GLOBAL )
209
222
set_property (TARGET external_fdmodel_model PROPERTY IMPORTED_LOCATION
210
223
${FDMODEL_MODEL_LIB} )
211
- add_dependencies (external_fdmodel ${PADDLEINFERENCE_PROJECT} )
212
- add_dependencies (external_fdmodel_auth ${PADDLEINFERENCE_PROJECT} )
213
- add_dependencies (external_fdmodel_model ${PADDLEINFERENCE_PROJECT} )
214
- list (APPEND ENCRYPT_AUTH_LIBS external_fdmodel external_fdmodel_auth external_fdmodel_model)
224
+ list (APPEND ENCRYPT_AUTH_LIBS external_fdmodel external_fdmodel_model)
225
+ endif ()
226
+
227
+ if (PADDLEINFERENCE_WITH_AUTH)
228
+ add_library (external_fdmodel_auth STATIC IMPORTED GLOBAL )
229
+ set_property (TARGET external_fdmodel_auth PROPERTY IMPORTED_LOCATION
230
+ ${FDMODEL_AUTH_LIB} )
231
+ list (APPEND ENCRYPT_AUTH_LIBS external_fdmodel_auth)
215
232
endif ()
216
233
217
- function (enable_paddle_encrypt_auth_link_policy LIBRARY_NAME)
218
- if (ENABLE_PADDLE_BACKEND AND PADDLEINFERENCE_WITH_ENCRYPT_AUTH)
219
- link_directories (${LEVELDB_LIB_DIR} )
220
- target_link_libraries (${LIBRARY_NAME} ${ENCRYPT_AUTH_LIBS} -lssl -lcrypto)
221
- target_link_libraries (${LIBRARY_NAME} ${LEVELDB_LIB_DIR} /libleveldb.a)
222
- set_target_properties (${LIBRARY_NAME} PROPERTIES LINK_FLAGS
223
- "-Wl,--whole-archive ${LEVELDB_LIB_DIR} /libleveldb.a -Wl,-no-whole-archive" )
234
+ function (set_paddle_encrypt_auth_link_policy LIBRARY_NAME)
235
+ if (ENABLE_PADDLE_BACKEND AND (PADDLEINFERENCE_WITH_ENCRYPT OR PADDLEINFERENCE_WITH_AUTH))
236
+ target_link_libraries (${LIBRARY_NAME} ${ENCRYPT_AUTH_LIBS} )
237
+ # Note(qiuyanjun): Currently, for XPU, we need to manually link the whole
238
+ # leveldb static lib into fastdeploy lib if PADDLEINFERENCE_WITH_ENCRYPT
239
+ # or PADDLEINFERENCE_WITH_AUTH is 'ON'. Will remove this policy while
240
+ # the bug of paddle inference lib with auth & encrypt fixed.
241
+ if ((EXISTS ${FDMODEL_LEVELDB_LIB_LIB} ) AND WITH_KUNLUNXIN)
242
+ target_link_libraries (${LIBRARY_NAME} -lssl -lcrypto)
243
+ link_directories (${FDMODEL_LEVELDB_LIB_DIR} )
244
+ target_link_libraries (${LIBRARY_NAME} ${FDMODEL_LEVELDB_LIB_LIB} )
245
+ set_target_properties (${LIBRARY_NAME} PROPERTIES LINK_FLAGS
246
+ "-Wl,--whole-archive ${FDMODEL_LEVELDB_LIB_LIB} -Wl,-no-whole-archive" )
247
+ endif ()
224
248
endif ()
225
249
endfunction ()
0 commit comments