Skip to content

Commit bd2a537

Browse files
authored
feature/anakin ci (#11330)
1 parent 6fcdb24 commit bd2a537

File tree

7 files changed

+66
-50
lines changed

7 files changed

+66
-50
lines changed

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ option(EIGEN_USE_THREADS "Compile with multi-threaded Eigen" OFF)
6161
option(WITH_ARM_FP16 "Use half precision support on armv8.2-a cpu" OFF)
6262
option(WITH_FAST_BUNDLE_TEST "Bundle tests that can be run in a single process together to reduce launch overhead" OFF)
6363
option(WITH_CONTRIB "Compile the third-party contributation" OFF)
64+
option(WITH_ANAKIN "Compile with Anakin library" OFF)
6465
option(WITH_GRPC "Use grpc as the default rpc framework" ${WITH_DISTRIBUTE})
6566

6667
# CMAKE_BUILD_TYPE
@@ -193,7 +194,10 @@ set(EXTERNAL_LIBS
193194
if(WITH_GPU)
194195
include(cuda)
195196
include(tensorrt)
196-
endif(WITH_GPU)
197+
include(external/anakin)
198+
else()
199+
set(WITH_ANAKIN OFF CACHE STRING "Anakin is valid only when GPU is set." FORCE)
200+
endif()
197201

198202
if(WITH_AMD_GPU)
199203
find_package(HIP)

cmake/external/anakin.cmake

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
if (NOT WITH_ANAKIN)
2+
return()
3+
endif()
4+
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")
9+
10+
set(ANAKIN_COMPILE_EXTRA_FLAGS -Wno-error=unused-variable -Wno-error=format-extra-args -Wno-error=comment -Wno-error=format -Wno-error=switch -Wno-error=return-type -Wno-error=non-virtual-dtor -Wno-reorder -Wno-error=cpp)
11+
12+
set(ANAKIN_LIBRARY_URL "https://github.com/pangge/Anakin/releases/download/3.0/anakin_release_simple.tar.gz")
13+
14+
# A helper function used in Anakin, currently, to use it, one need to recursively include
15+
# nearly all the header files.
16+
function(fetch_include_recursively root_dir)
17+
if (IS_DIRECTORY ${root_dir})
18+
include_directories(${root_dir})
19+
endif()
20+
21+
file(GLOB ALL_SUB RELATIVE ${root_dir} ${root_dir}/*)
22+
foreach(sub ${ALL_SUB})
23+
if (IS_DIRECTORY ${root_dir}/${sub})
24+
fetch_include_recursively(${root_dir}/${sub})
25+
endif()
26+
endforeach()
27+
endfunction()
28+
29+
# download library
30+
message(STATUS "Download Anakin library from ${ANAKIN_LIBRARY_URL}")
31+
execute_process(COMMAND bash -c "mkdir -p ${ANAKIN_INSTALL_DIR}")
32+
execute_process(COMMAND bash -c "rm -rf ${ANAKIN_INSTALL_DIR}/*")
33+
execute_process(COMMAND bash -c "cd ${ANAKIN_INSTALL_DIR}; wget -q ${ANAKIN_LIBRARY_URL}")
34+
execute_process(COMMAND bash -c "mkdir -p ${ANAKIN_INSTALL_DIR}")
35+
execute_process(COMMAND bash -c "cd ${ANAKIN_INSTALL_DIR}; tar xzf anakin_release_simple.tar.gz")
36+
37+
if (WITH_ANAKIN)
38+
message(STATUS "Anakin for inference is enabled")
39+
message(STATUS "Anakin is set INCLUDE:${ANAKIN_INCLUDE} LIBRARY:${ANAKIN_LIBRARY}")
40+
fetch_include_recursively(${ANAKIN_INCLUDE})
41+
link_directories(${ANAKIN_LIBRARY})
42+
endif()

paddle/contrib/inference/CMakeLists.txt

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,48 +17,9 @@ if(APPLE)
1717
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=pessimizing-move")
1818
endif(APPLE)
1919

20-
set(ANAKIN_INCLUDE "" CACHE STRING "root of Anakin header files")
21-
set(ANAKIN_LIBRARY "" CACHE STRING "path of Anakin library")
22-
2320

2421
set(inference_deps paddle_inference_api paddle_fluid_api)
2522

26-
# if anakin is set enable anakin api implementation
27-
if(ANAKIN_INCLUDE AND ANAKIN_LIBRARY)
28-
set(ANAKIN_FOUND ON)
29-
else()
30-
set(ANAKIN_FOUND OFF)
31-
endif()
32-
33-
function(fetch_include_recursively root_dir)
34-
if (IS_DIRECTORY ${root_dir})
35-
include_directories(${root_dir})
36-
endif()
37-
38-
file(GLOB ALL_SUB RELATIVE ${root_dir} ${root_dir}/*)
39-
foreach(sub ${ALL_SUB})
40-
if (IS_DIRECTORY ${root_dir}/${sub})
41-
fetch_include_recursively(${root_dir}/${sub})
42-
endif()
43-
endforeach()
44-
endfunction()
45-
46-
if (ANAKIN_FOUND)
47-
# Anakin's code style doesn't follow google c style.
48-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=unused-variable -Wno-error=format-extra-args -Wno-error=comment -Wno-error=format -Wno-error=switch -Wno-error=return-type -Wno-error=non-virtual-dtor -Wno-reorder -Wno-error=cpp")
49-
50-
message(STATUS "Anakin for inference is enabled")
51-
message(STATUS "Anakin is set INCLUDE:${ANAKIN_INCLUDE} LIBRARY:${ANAKIN_LIBRARY}")
52-
fetch_include_recursively(${ANAKIN_INCLUDE})
53-
54-
link_directories(${ANAKIN_LIBRARY})
55-
56-
nv_library(inference_anakin_api SHARED SRCS paddle_inference_api.cc paddle_inference_api_anakin_engine.cc)
57-
target_link_libraries(inference_anakin_api anakin anakin_saber_common)
58-
list(APPEND inference_deps inference_anakin_api)
59-
endif()
60-
61-
6223
function(inference_api_test TARGET_NAME)
6324
if (WITH_TESTING)
6425
set(options "")
@@ -79,7 +40,7 @@ function(inference_api_test TARGET_NAME)
7940
endfunction(inference_api_test)
8041

8142
cc_library(paddle_inference_api
82-
SRCS paddle_inference_api.cc paddle_inference_api_impl.cc
43+
SRCS paddle_inference_api.cc paddle_inference_api_impl.cc
8344
DEPS ${FLUID_CORE_MODULES} ${GLOB_OP_LIB})
8445

8546
cc_test(test_paddle_inference_api
@@ -89,9 +50,17 @@ cc_test(test_paddle_inference_api
8950
inference_api_test(test_paddle_inference_api_impl
9051
ARGS test_word2vec test_image_classification)
9152

92-
if (ANAKIN_FOUND)
53+
if (WITH_ANAKIN)
54+
# Due to Anakin do not have official library releases and the versions of protobuf and cuda do not match Paddle's,
55+
# so anakin library will not be merged to our official inference library. To use anakin prediction API, one need to
56+
# compile the libinference_anakin_api.a and compile with anakin.so.
57+
nv_library(inference_anakin_api SHARED SRCS paddle_inference_api.cc paddle_inference_api_anakin_engine.cc)
58+
target_compile_options(inference_anakin_api BEFORE PUBLIC ${ANAKIN_COMPILE_EXTRA_FLAGS})
59+
target_link_libraries(inference_anakin_api anakin anakin_saber_common)
9360
cc_test(inference_anakin_test SRCS paddle_inference_api_anakin_engine_tester.cc
94-
DEPS ${inference_deps})
61+
ARGS --model=${ANAKIN_INSTALL_DIR}/mobilenet_v2.anakin.bin
62+
DEPS inference_anakin_api)
63+
target_compile_options(inference_anakin_test BEFORE PUBLIC ${ANAKIN_COMPILE_EXTRA_FLAGS})
9564
endif()
9665

9766
if(WITH_TESTING)

paddle/contrib/inference/paddle_inference_api_anakin_engine.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include <cuda.h>
16-
1715
#include "paddle/contrib/inference/paddle_inference_api_anakin_engine.h"
16+
#include <cuda.h>
1817

1918
namespace paddle {
2019

paddle/contrib/inference/paddle_inference_api_anakin_engine.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ limitations under the License. */
1919

2020
#pragma once
2121

22-
// NOTE This header file do not have namespace.
23-
//#include <test/framework/net/paddle_api.h>
2422
#include "paddle/contrib/inference/paddle_inference_api.h"
2523

24+
// from anakin
2625
#include "framework/core/net/net.h"
2726
#include "saber/saber_types.h"
2827

paddle/contrib/inference/paddle_inference_api_anakin_engine_tester.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@ 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. */
1414

15+
#include <gflags/gflags.h>
1516
#include <glog/logging.h>
1617
#include <gtest/gtest.h>
1718

18-
#include "gflags/gflags.h"
1919
#include "paddle/contrib/inference/paddle_inference_api.h"
2020

21+
DEFINE_string(model, "", "Directory of the inference model.");
22+
2123
namespace paddle {
2224

2325
AnakinConfig GetConfig() {
2426
AnakinConfig config;
25-
config.model_file = "./mobilenet_v2.anakin.bin";
27+
config.model_file = FLAGS_model;
2628
config.device = 0;
2729
config.max_batch_size = 1;
2830
return config;

paddle/scripts/paddle_build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ EOF
132132
-DCMAKE_MODULE_PATH=/opt/rocm/hip/cmake \
133133
-DWITH_FLUID_ONLY=${WITH_FLUID_ONLY:-OFF} \
134134
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
135-
-DWITH_CONTRIB=${WITH_CONTRIB:-ON}
135+
-DWITH_CONTRIB=${WITH_CONTRIB:-ON} \
136+
-DWITH_ANAKIN=ON
136137
}
137138

138139
function abort(){

0 commit comments

Comments
 (0)