Skip to content

Commit 1e1974c

Browse files
authored
Merge pull request #12563 from luotao1/anakin_test
* make inference_anakin_test SERIAL * add anakin compiler from github source code * fix inference_lib_dist error * add comment * update anakin.cmake * fix anakin-NOTFOUND compiler error * modify the anakin_model download dir
2 parents a85bf42 + 2ea110c commit 1e1974c

File tree

4 files changed

+66
-54
lines changed

4 files changed

+66
-54
lines changed

cmake/configure.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ if(WITH_GPU)
9797
endif()
9898
include_directories(${TENSORRT_INCLUDE_DIR})
9999
endif()
100+
if(WITH_ANAKIN)
101+
if(${CUDA_VERSION_MAJOR} VERSION_LESS 8)
102+
message(FATAL_ERROR "Anakin needs CUDA >= 8.0 to compile")
103+
endif()
104+
if(${CUDNN_MAJOR_VERSION} VERSION_LESS 7)
105+
message(FATAL_ERROR "Anakin needs CUDNN >= 7.0 to compile")
106+
endif()
107+
endif()
100108
elseif(WITH_AMD_GPU)
101109
add_definitions(-DPADDLE_WITH_HIP)
102110
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__HIP_PLATFORM_HCC__")

cmake/external/anakin.cmake

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,22 @@ if (NOT WITH_ANAKIN)
22
return()
33
endif()
44

5-
set(ANAKIN_INSTALL_DIR "${THIRD_PARTY_PATH}/install/anakin" CACHE PATH
6-
"Anakin install path." FORCE)
7-
set(ANAKIN_INCLUDE "${ANAKIN_INSTALL_DIR}" CACHE STRING "root of Anakin header files")
8-
set(ANAKIN_LIBRARY "${ANAKIN_INSTALL_DIR}" CACHE STRING "path of Anakin library")
5+
INCLUDE(ExternalProject)
6+
set(ANAKIN_SOURCE_DIR ${THIRD_PARTY_PATH}/anakin)
7+
# the anakin install dir is only default one now
8+
set(ANAKIN_INSTALL_DIR ${THIRD_PARTY_PATH}/anakin/src/extern_anakin/output)
9+
set(ANAKIN_INCLUDE ${ANAKIN_INSTALL_DIR})
10+
set(ANAKIN_LIBRARY ${ANAKIN_INSTALL_DIR})
11+
set(ANAKIN_SHARED_LIB ${ANAKIN_LIBRARY}/libanakin.so)
12+
set(ANAKIN_SABER_LIB ${ANAKIN_LIBRARY}/libanakin_saber_common.so)
13+
14+
# TODO(luotao): ANAKIN_MODLE_URL will move to demo ci later.
15+
set(ANAKIN_MODLE_URL "http://paddle-inference-dist.bj.bcebos.com/mobilenet_v2.anakin.bin")
16+
execute_process(COMMAND bash -c "mkdir -p ${ANAKIN_SOURCE_DIR}")
17+
execute_process(COMMAND bash -c "cd ${ANAKIN_SOURCE_DIR}; wget -q --no-check-certificate ${ANAKIN_MODLE_URL}")
18+
19+
include_directories(${ANAKIN_INCLUDE})
20+
include_directories(${ANAKIN_INCLUDE}/saber/)
921

1022
set(ANAKIN_COMPILE_EXTRA_FLAGS
1123
-Wno-error=unused-but-set-variable -Wno-unused-but-set-variable
@@ -20,36 +32,33 @@ set(ANAKIN_COMPILE_EXTRA_FLAGS
2032
-Wno-reorder
2133
-Wno-error=cpp)
2234

23-
set(ANAKIN_LIBRARY_URL "https://github.com/pangge/Anakin/releases/download/Version0.1.0/anakin.tar.gz")
24-
25-
# A helper function used in Anakin, currently, to use it, one need to recursively include
26-
# nearly all the header files.
27-
function(fetch_include_recursively root_dir)
28-
if (IS_DIRECTORY ${root_dir})
29-
include_directories(${root_dir})
30-
endif()
31-
32-
file(GLOB ALL_SUB RELATIVE ${root_dir} ${root_dir}/*)
33-
foreach(sub ${ALL_SUB})
34-
if (IS_DIRECTORY ${root_dir}/${sub})
35-
fetch_include_recursively(${root_dir}/${sub})
36-
endif()
37-
endforeach()
38-
endfunction()
39-
40-
if (NOT EXISTS "${ANAKIN_INSTALL_DIR}")
41-
# download library
42-
message(STATUS "Download Anakin library from ${ANAKIN_LIBRARY_URL}")
43-
execute_process(COMMAND bash -c "mkdir -p ${ANAKIN_INSTALL_DIR}")
44-
execute_process(COMMAND bash -c "rm -rf ${ANAKIN_INSTALL_DIR}/*")
45-
execute_process(COMMAND bash -c "cd ${ANAKIN_INSTALL_DIR}; wget --no-check-certificate -q ${ANAKIN_LIBRARY_URL}")
46-
execute_process(COMMAND bash -c "mkdir -p ${ANAKIN_INSTALL_DIR}")
47-
execute_process(COMMAND bash -c "cd ${ANAKIN_INSTALL_DIR}; tar xzf anakin.tar.gz")
48-
endif()
35+
ExternalProject_Add(
36+
extern_anakin
37+
${EXTERNAL_PROJECT_LOG_ARGS}
38+
# TODO(luotao): use PaddlePaddle/Anakin later
39+
GIT_REPOSITORY "https://github.com/luotao1/Anakin"
40+
GIT_TAG "3957ae9263eaa0b1986758dac60a88852afb09be"
41+
PREFIX ${ANAKIN_SOURCE_DIR}
42+
UPDATE_COMMAND ""
43+
CMAKE_ARGS -DUSE_GPU_PLACE=YES
44+
-DUSE_X86_PLACE=YES
45+
-DBUILD_WITH_UNIT_TEST=NO
46+
-DPROTOBUF_ROOT=${THIRD_PARTY_PATH}/install/protobuf
47+
-DMKLML_ROOT=${THIRD_PARTY_PATH}/install/mklml
48+
-DCUDNN_ROOT=${CUDNN_ROOT}
49+
${EXTERNAL_OPTIONAL_ARGS}
50+
CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${ANAKIN_INSTALL_DIR}
51+
)
4952

50-
if (WITH_ANAKIN)
51-
message(STATUS "Anakin for inference is enabled")
52-
message(STATUS "Anakin is set INCLUDE:${ANAKIN_INCLUDE} LIBRARY:${ANAKIN_LIBRARY}")
53-
fetch_include_recursively(${ANAKIN_INCLUDE})
54-
link_directories(${ANAKIN_LIBRARY})
55-
endif()
53+
message(STATUS "Anakin for inference is enabled")
54+
message(STATUS "Anakin is set INCLUDE:${ANAKIN_INCLUDE} LIBRARY:${ANAKIN_LIBRARY}")
55+
56+
add_library(anakin_shared SHARED IMPORTED GLOBAL)
57+
set_property(TARGET anakin_shared PROPERTY IMPORTED_LOCATION ${ANAKIN_SHARED_LIB})
58+
add_dependencies(anakin_shared extern_anakin protobuf mklml)
59+
60+
add_library(anakin_saber SHARED IMPORTED GLOBAL)
61+
set_property(TARGET anakin_saber PROPERTY IMPORTED_LOCATION ${ANAKIN_SABER_LIB})
62+
add_dependencies(anakin_saber extern_anakin protobuf mklml)
63+
64+
list(APPEND external_project_dependencies anakin_shared anakin_saber)

cmake/inference_lib.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ if (WITH_ANAKIN AND WITH_GPU)
143143
copy(anakin_inference_lib DEPS paddle_inference_api inference_anakin_api
144144
SRCS
145145
${PADDLE_BINARY_DIR}/paddle/fluid/inference/api/libinference_anakin_api* # compiled anakin api
146-
${PADDLE_BINARY_DIR}/third_party/install/anakin/*.tar.gz # anakin release
146+
${ANAKIN_INSTALL_DIR} # anakin release
147147
DSTS ${dst_dir}/inference/anakin ${dst_dir}/inference/anakin)
148148
list(APPEND inference_deps anakin_inference_lib)
149149
endif()

paddle/fluid/inference/api/CMakeLists.txt

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ endfunction(inference_api_test)
4545

4646
cc_library(paddle_inference_api SRCS api.cc api_impl.cc DEPS lod_tensor)
4747

48-
4948
cc_test(test_paddle_inference_api
5049
SRCS api_tester.cc
5150
DEPS paddle_inference_api)
@@ -62,22 +61,18 @@ inference_api_test(test_api_tensorrt_subgraph_engine SRC api_tensorrt_subgraph_e
6261
endif()
6362

6463
if (WITH_ANAKIN) # only needed in CI
65-
# Due to Anakin do not have official library releases and the versions of protobuf and cuda do not match Paddle's,
66-
# so anakin library will not be merged to our official inference library. To use anakin prediction API, one need to
67-
# compile the libinference_anakin_api.a and compile with anakin.so.
68-
fetch_include_recursively(${ANAKIN_INCLUDE})
6964
# compile the libinference_anakin_api.a and anakin.so.
70-
nv_library(inference_anakin_api SRCS api.cc api_anakin_engine.cc)
71-
nv_library(inference_anakin_api_shared SHARED SRCS api.cc api_anakin_engine.cc)
72-
target_compile_options(inference_anakin_api BEFORE PUBLIC ${ANAKIN_COMPILE_EXTRA_FLAGS})
73-
target_compile_options(inference_anakin_api_shared BEFORE PUBLIC ${ANAKIN_COMPILE_EXTRA_FLAGS})
74-
target_link_libraries(inference_anakin_api anakin anakin_saber_common)
75-
target_link_libraries(inference_anakin_api_shared anakin anakin_saber_common)
65+
nv_library(inference_anakin_api SRCS api.cc api_anakin_engine.cc DEPS anakin_shared anakin_saber)
66+
#nv_library(inference_anakin_api_shared SHARED SRCS api.cc api_anakin_engine.cc DEPS anakin)
67+
function(anakin_target target_name)
68+
target_compile_options(${target_name} BEFORE PUBLIC ${ANAKIN_COMPILE_EXTRA_FLAGS})
69+
endfunction()
70+
anakin_target(inference_anakin_api)
71+
#anakin_target(inference_anakin_api_shared)
7672
if (WITH_TESTING)
77-
# this test is unstable, disable it first.
78-
#cc_test(inference_anakin_test SRCS api_anakin_engine_tester.cc
79-
#ARGS --model=${ANAKIN_INSTALL_DIR}/mobilenet_v2.anakin.bin
80-
#DEPS inference_anakin_api_shared)
81-
#target_compile_options(inference_anakin_test BEFORE PUBLIC ${ANAKIN_COMPILE_EXTRA_FLAGS})
82-
endif(WITH_TESTING)
73+
cc_test(inference_anakin_test SRCS api_anakin_engine_tester.cc
74+
ARGS --model=${ANAKIN_SOURCE_DIR}/mobilenet_v2.anakin.bin
75+
DEPS inference_anakin_api dynload_cuda SERIAL)
76+
target_compile_options(inference_anakin_test BEFORE PUBLIC ${ANAKIN_COMPILE_EXTRA_FLAGS})
77+
endif(WITH_TESTING)
8378
endif()

0 commit comments

Comments
 (0)