Skip to content

Commit e90e7ab

Browse files
authored
Remove the use of ARCHIVE_START/END (#9844)
* Add USE_OP of all operators and kernels and remove ARCHIVE_START/END in CMakeLists.txt of inference unittests. * Remove ARCHIVE_START/END when linking inference shared library. * Disable some fluid related cmake operations for cross-compiling.
1 parent ef169eb commit e90e7ab

File tree

11 files changed

+83
-48
lines changed

11 files changed

+83
-48
lines changed

cmake/cblas.cmake

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,29 +62,33 @@ endif()
6262

6363

6464
## Then find the reference-cblas. www.netlib.org/blas/
65-
66-
6765
set(REFERENCE_CBLAS_ROOT $ENV{REFERENCE_CBLAS_ROOT} CACHE PATH
6866
"Folder contains reference-cblas")
69-
set(REFERENCE_CBLAS_INCLUDE_SEARCH_PATHS
70-
${REFERENCE_CBLAS_ROOT}/include
71-
/usr/include
72-
/usr/include/cblas
73-
)
74-
75-
set(REFERENCE_CBLAS_LIB_SEARCH_PATHS
76-
${REFERENCE_CBLAS_ROOT}/lib
77-
/usr/lib
78-
/usr/lib/blas/reference/
79-
/usr/lib/reference/
80-
)
67+
if(NOT CMAKE_CROSSCOMPILING)
68+
set(REFERENCE_CBLAS_INCLUDE_SEARCH_PATHS
69+
${REFERENCE_CBLAS_ROOT}/include
70+
/usr/include
71+
/usr/include/cblas
72+
)
73+
74+
set(REFERENCE_CBLAS_LIB_SEARCH_PATHS
75+
${REFERENCE_CBLAS_ROOT}/lib
76+
/usr/lib
77+
/usr/lib/blas/reference/
78+
/usr/lib/reference/
79+
)
80+
else()
81+
# Diable the finding of reference cblas under host's system path
82+
set(REFERENCE_CBLAS_INCLUDE_SEARCH_PATHS ${REFERENCE_CBLAS_ROOT}/include)
83+
set(REFERENCE_CBLAS_LIB_SEARCH_PATHS ${REFERENCE_CBLAS_ROOT}/lib)
84+
endif()
8185

8286
find_path(REFERENCE_CBLAS_INCLUDE_DIR NAMES cblas.h PATHS
8387
${REFERENCE_CBLAS_INCLUDE_SEARCH_PATHS})
8488
find_library(REFERENCE_CBLAS_LIBRARY NAMES cblas PATHS
8589
${REFERENCE_CBLAS_LIB_SEARCH_PATHS})
8690

87-
if (REFERENCE_CBLAS_INCLUDE_DIR AND REFERENCE_CBLAS_LIBRARY)
91+
if(REFERENCE_CBLAS_INCLUDE_DIR AND REFERENCE_CBLAS_LIBRARY)
8892
set(CBLAS_FOUND ON)
8993
set(CBLAS_PROVIDER REFERENCE)
9094
set(CBLAS_INC_DIR ${REFERENCE_CBLAS_INCLUDE_DIR})

cmake/external/snappy.cmake

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
#
1514

16-
IF(MOBILE_INFERENCE)
15+
if(MOBILE_INFERENCE OR RPI)
1716
return()
18-
ENDIF()
17+
endif()
1918

2019
include (ExternalProject)
2120

2221
# NOTE: snappy is needed when linking with recordio
2322

24-
SET(SNAPPY_SOURCES_DIR ${THIRD_PARTY_PATH}/snappy)
25-
SET(SNAPPY_INSTALL_DIR ${THIRD_PARTY_PATH}/install/snappy)
26-
SET(SNAPPY_INCLUDE_DIR "${SNAPPY_INSTALL_DIR}/include/" CACHE PATH "snappy include directory." FORCE)
23+
set(SNAPPY_SOURCES_DIR ${THIRD_PARTY_PATH}/snappy)
24+
set(SNAPPY_INSTALL_DIR ${THIRD_PARTY_PATH}/install/snappy)
25+
set(SNAPPY_INCLUDE_DIR "${SNAPPY_INSTALL_DIR}/include" CACHE PATH "snappy include directory." FORCE)
26+
27+
set(SNAPPY_LIBRARIES "${SNAPPY_INSTALL_DIR}/lib/libsnappy.a")
2728

2829
ExternalProject_Add(
2930
extern_snappy
@@ -51,8 +52,7 @@ ExternalProject_Add(
5152
)
5253

5354
add_library(snappy STATIC IMPORTED GLOBAL)
54-
set_property(TARGET snappy PROPERTY IMPORTED_LOCATION
55-
"${SNAPPY_INSTALL_DIR}/lib/libsnappy.a")
55+
set_property(TARGET snappy PROPERTY IMPORTED_LOCATION ${SNAPPY_LIBRARIES})
5656

5757
include_directories(${SNAPPY_INCLUDE_DIR})
5858
add_dependencies(snappy extern_snappy)

cmake/external/snappystream.cmake

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
#
1514

16-
IF(MOBILE_INFERENCE)
15+
IF(MOBILE_INFERENCE OR RPI)
1716
return()
1817
ENDIF()
1918

2019
include (ExternalProject)
2120

2221
# NOTE: snappy is needed when linking with recordio
2322

24-
SET(SNAPPYSTREAM_SOURCES_DIR ${THIRD_PARTY_PATH}/snappy_stream)
25-
SET(SNAPPYSTREAM_INSTALL_DIR ${THIRD_PARTY_PATH}/install/snappy_stream)
26-
SET(SNAPPYSTREAM_INCLUDE_DIR "${SNAPPYSTREAM_INSTALL_DIR}/include/" CACHE PATH "snappy stream include directory." FORCE)
23+
set(SNAPPYSTREAM_SOURCES_DIR ${THIRD_PARTY_PATH}/snappy_stream)
24+
set(SNAPPYSTREAM_INSTALL_DIR ${THIRD_PARTY_PATH}/install/snappy_stream)
25+
set(SNAPPYSTREAM_INCLUDE_DIR "${SNAPPYSTREAM_INSTALL_DIR}/include" CACHE PATH "snappy stream include directory." FORCE)
26+
27+
set(SNAPPYSTREAM_LIBRARIES "${SNAPPYSTREAM_INSTALL_DIR}/lib/libsnappystream.a")
2728

2829
ExternalProject_Add(
2930
extern_snappystream
@@ -51,8 +52,7 @@ ExternalProject_Add(
5152
)
5253

5354
add_library(snappystream STATIC IMPORTED GLOBAL)
54-
set_property(TARGET snappystream PROPERTY IMPORTED_LOCATION
55-
"${SNAPPYSTREAM_INSTALL_DIR}/lib/libsnappystream.a")
55+
set_property(TARGET snappystream PROPERTY IMPORTED_LOCATION ${SNAPPYSTREAM_LIBRARIES})
5656

5757
include_directories(${SNAPPYSTREAM_INCLUDE_DIR}) # For snappysteam to include its own headers.
5858
include_directories(${THIRD_PARTY_PATH}/install) # For Paddle to include snappy stream headers.

cmake/generic.cmake

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,7 @@ function(cc_library TARGET_NAME)
195195
list(REMOVE_ITEM cc_library_DEPS warpctc)
196196
add_dependencies(${TARGET_NAME} warpctc)
197197
endif()
198-
if("${cc_library_DEPS}" MATCHES "ARCHIVE_START")
199-
# Support linking flags: --whole-archive (Linux) / -force_load (MacOS).
200-
# WARNING: Please don't use ARCHIVE_START&ARCHIVE_END if TARGET_NAME will be linked by other libraries.
201-
target_circle_link_libraries(${TARGET_NAME} ${cc_library_DEPS})
202-
list(REMOVE_ITEM cc_library_DEPS ARCHIVE_START ARCHIVE_END)
203-
else()
204-
target_link_libraries(${TARGET_NAME} ${cc_library_DEPS})
205-
endif()
198+
target_link_libraries(${TARGET_NAME} ${cc_library_DEPS})
206199
add_dependencies(${TARGET_NAME} ${cc_library_DEPS})
207200
endif()
208201

@@ -243,11 +236,7 @@ function(cc_test TARGET_NAME)
243236
set(multiValueArgs SRCS DEPS ARGS)
244237
cmake_parse_arguments(cc_test "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
245238
add_executable(${TARGET_NAME} ${cc_test_SRCS})
246-
# Support linking flags: --whole-archive (Linux) / -force_load (MacOS)
247-
target_circle_link_libraries(${TARGET_NAME} ${cc_test_DEPS} paddle_gtest_main memory gtest gflags glog)
248-
if("${cc_test_DEPS}" MATCHES "ARCHIVE_START")
249-
list(REMOVE_ITEM cc_test_DEPS ARCHIVE_START ARCHIVE_END)
250-
endif()
239+
target_link_libraries(${TARGET_NAME} ${cc_test_DEPS} paddle_gtest_main memory gtest gflags glog)
251240
add_dependencies(${TARGET_NAME} ${cc_test_DEPS} paddle_gtest_main memory gtest gflags glog)
252241
add_test(NAME ${TARGET_NAME}
253242
COMMAND ${TARGET_NAME} ${cc_test_ARGS}

cmake/inference_lib.cmake

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1+
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
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+
115
set_property(GLOBAL PROPERTY FLUID_MODULES "")
216
# find all fluid modules is used for paddle fluid static library
317
function(find_fluid_modules TARGET_NAME)
418
get_filename_component(__target_path ${TARGET_NAME} ABSOLUTE)
19+
string(REGEX REPLACE "^${PADDLE_SOURCE_DIR}/" "" __target_path ${__target_path})
520
string(FIND "${__target_path}" "fluid" pos)
621
if(pos GREATER 1)
722
get_property(fluid_modules GLOBAL PROPERTY FLUID_MODULES)
@@ -77,6 +92,23 @@ elseif (WITH_MKLML)
7792
)
7893
endif()
7994

95+
if(NOT MOBILE_INFERENCE AND NOT RPI)
96+
set(dst_dir "${CMAKE_INSTALL_PREFIX}/third_party/install/snappy")
97+
copy(snappy_lib
98+
SRCS ${SNAPPY_INCLUDE_DIR} ${SNAPPY_LIBRARIES}
99+
DSTS ${dst_dir} ${dst_dir}/lib)
100+
101+
set(dst_dir "${CMAKE_INSTALL_PREFIX}/third_party/install/snappystream")
102+
copy(snappystream_lib
103+
SRCS ${SNAPPYSTREAM_INCLUDE_DIR} ${SNAPPYSTREAM_LIBRARIES}
104+
DSTS ${dst_dir} ${dst_dir}/lib)
105+
106+
set(dst_dir "${CMAKE_INSTALL_PREFIX}/third_party/install/zlib")
107+
copy(zlib_lib
108+
SRCS ${ZLIB_INCLUDE_DIR} ${ZLIB_LIBRARIES}
109+
DSTS ${dst_dir} ${dst_dir}/lib)
110+
endif()
111+
80112
# paddle fluid module
81113
set(src_dir "${PADDLE_SOURCE_DIR}/paddle/fluid")
82114
set(dst_dir "${CMAKE_INSTALL_PREFIX}/paddle/fluid")

paddle/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ if(NOT WITH_FLUID_ONLY)
2424
endif()
2525

2626
add_subdirectory(testing)
27-
if(NOT MOBILE_INFERENCE AND NOT ANDROID AND NOT IOS)
27+
if(NOT MOBILE_INFERENCE AND NOT RPI)
2828
add_subdirectory(fluid)
2929
endif()

paddle/fluid/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ add_subdirectory(platform)
33
add_subdirectory(framework)
44
add_subdirectory(operators)
55
add_subdirectory(pybind)
6-
add_subdirectory(inference)
76
add_subdirectory(string)
87
add_subdirectory(recordio)
8+
# NOTE: please add subdirectory inference at last.
9+
add_subdirectory(inference)

paddle/fluid/inference/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
set(FLUID_CORE_MODULES proto_desc memory lod_tensor executor prune init)
1+
set(FLUID_CORE_MODULES proto_desc memory lod_tensor executor init)
22

33
cc_library(paddle_fluid_api
44
SRCS io.cc
@@ -11,7 +11,7 @@ cc_library(paddle_fluid DEPS ${fluid_modules})
1111
# Create shared library
1212
cc_library(paddle_fluid_shared SHARED
1313
SRCS io.cc
14-
DEPS ARCHIVE_START ${GLOB_OP_LIB} ${FLUID_CORE_MODULES} ARCHIVE_END)
14+
DEPS ${fluid_modules})
1515
set_target_properties(paddle_fluid_shared PROPERTIES OUTPUT_NAME paddle_fluid)
1616
if(NOT APPLE)
1717
# TODO(liuyiqun): Temporarily disable the link flag because it is not support on Mac.

paddle/fluid/inference/io.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ limitations under the License. */
1717
#include <fstream>
1818
#include "paddle/fluid/framework/block_desc.h"
1919
#include "paddle/fluid/framework/feed_fetch_type.h"
20+
#include "paddle/fluid/framework/op_registry.h"
21+
#include "paddle/fluid/pybind/pybind.h"
2022

2123
namespace paddle {
2224
namespace inference {
2325

26+
// Temporarilly add this function for exposing framework::InitDevices() when
27+
// linking the inference shared library.
28+
void Init(bool init_p2p) { framework::InitDevices(init_p2p); }
29+
2430
void ReadBinaryFile(const std::string& filename, std::string& contents) {
2531
std::ifstream fin(filename, std::ios::in | std::ios::binary);
2632
PADDLE_ENFORCE(static_cast<bool>(fin), "Cannot open file %s", filename);

paddle/fluid/inference/io.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ limitations under the License. */
1818
#include <string>
1919
#include <vector>
2020
#include "paddle/fluid/framework/executor.h"
21+
#include "paddle/fluid/framework/init.h"
2122
#include "paddle/fluid/framework/program_desc.h"
2223
#include "paddle/fluid/framework/scope.h"
2324

2425
namespace paddle {
2526
namespace inference {
2627

28+
void Init(bool init_p2p);
29+
2730
void LoadPersistables(framework::Executor& executor, framework::Scope& scope,
2831
const framework::ProgramDesc& main_program,
2932
const std::string& dirname,

0 commit comments

Comments
 (0)