From ab732884fff6b5cbc7e9f86f6fe2ee71e5074ce3 Mon Sep 17 00:00:00 2001 From: Huihuang Zheng Date: Sat, 23 Oct 2021 08:03:23 +0800 Subject: [PATCH] New Paddle-CINN Compile PR (#36584) This PR added some changes to match the CINN change for compilation. It also tried to fix JiangCheng's Problem in PR: https://github.com/PaddlePaddle/Paddle/pull/36100 These changes include: 1. Set `CINN_GIT_TAG` to a newer tag 2. CINN now just `make cinnapi -j` 3. We have to add `-DPY_VERSION=${PY_VERSION} -DWITH_TESTING=ON` to CINN cmake args 4. For CINN's third party dependencies, we could just include headers without target_link_libraries 5. Moved `cinn.cmake` from `paddle/cmake` to `paddle/cmake/external` to match old style. External folder contains `lite`, which is the same level of `cinn` 6. CINN added `-DNAMESPACE=cinn_gflags` in `gflags.cmake` to have different gflag namespaces between CINN and Paddle. It solved re-define problem. 7. Change namespace of `::google::` in gflags to `::GFLAGS_NAMESPACE` --- CMakeLists.txt | 4 -- cmake/{ => external}/cinn.cmake | 44 +++---------------- cmake/third_party.cmake | 5 +++ paddle/fluid/framework/ir/cinn_lib_test.cc | 1 + .../inference/tests/infer_ut/test_LeViT.cc | 2 +- .../tests/infer_ut/test_det_mv3_db.cc | 2 +- .../tests/infer_ut/test_ernie_text_cls.cc | 2 +- .../tests/infer_ut/test_ernie_xnli_int8.cc | 3 +- .../tests/infer_ut/test_mobilnetv1.cc | 2 +- .../tests/infer_ut/test_ppyolo_mbv3.cc | 2 +- .../tests/infer_ut/test_ppyolov2_r50vd.cc | 2 +- .../inference/tests/infer_ut/test_resnet50.cc | 2 +- .../tests/infer_ut/test_resnet50_quant.cc | 2 +- .../inference/tests/infer_ut/test_yolov3.cc | 2 +- 14 files changed, 24 insertions(+), 51 deletions(-) rename cmake/{ => external}/cinn.cmake (64%) diff --git a/CMakeLists.txt b/CMakeLists.txt index d4a0eb067b4..334a6cfcd0e 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -300,10 +300,6 @@ if(WITH_GPU) endif() endif() -if(WITH_CINN) - include(cinn) -endif() - if(WITH_ROCM) include(hip) include(miopen) # set miopen libraries, must before configure diff --git a/cmake/cinn.cmake b/cmake/external/cinn.cmake similarity index 64% rename from cmake/cinn.cmake rename to cmake/external/cinn.cmake index dd5f809e958..ee5aea9f8b2 100644 --- a/cmake/cinn.cmake +++ b/cmake/external/cinn.cmake @@ -27,16 +27,15 @@ add_definitions(-w) include(ExternalProject) set(CINN_SOURCE_DIR ${THIRD_PARTY_PATH}/CINN) # TODO(zhhsplendid): Modify git tag after we have release tag -set(CINN_GIT_TAG 3f004bfa3ed273ecf1de8e7b946433038c79b84f) -set(CINN_OPTIONAL_ARGS -DWITH_CUDA=${WITH_GPU} -DWITH_CUDNN=${WITH_GPU} -DPUBLISH_LIBS=ON) -set(CINN_BUILD_COMMAND $(MAKE) cinncore -j && $(MAKE) cinnapi -j) +set(CINN_GIT_TAG e422c01b7875301996a2baf67a14ba61b0e6192a) +set(CINN_OPTIONAL_ARGS -DPY_VERSION=${PY_VERSION} -DWITH_CUDA=${WITH_GPU} -DWITH_CUDNN=${WITH_GPU} -DPUBLISH_LIBS=ON -DWITH_TESTING=ON) +set(CINN_BUILD_COMMAND $(MAKE) cinnapi -j) ExternalProject_Add( external_cinn ${EXTERNAL_PROJECT_LOG_ARGS} GIT_REPOSITORY "${GIT_URL}/PaddlePaddle/CINN.git" GIT_TAG ${CINN_GIT_TAG} PREFIX ${CINN_SOURCE_DIR} - UPDATE_COMMAND "" BUILD_COMMAND ${CINN_BUILD_COMMAND} INSTALL_COMMAND "" CMAKE_ARGS ${CINN_OPTIONAL_ARGS}) @@ -52,49 +51,20 @@ message(STATUS "CINN BINARY_DIR: ${CINN_BINARY_DIR}") message(STATUS "CINN SOURCE_DIR: ${CINN_SOURCE_DIR}") -######################### -# Add CINN's dependencies -######################### +###################################### +# Add CINN's dependencies header files +###################################### # Add absl -set(ABSL_LIB_NAMES - hash - wyhash - city - strings - throw_delegate - bad_any_cast_impl - bad_optional_access - bad_variant_access - raw_hash_set - ) -set(ABSL_LIB_DIR "${CINN_BINARY_DIR}/dist/third_party/absl/lib") set(ABSL_INCLUDE_DIR "${CINN_BINARY_DIR}/dist/third_party/absl/include") -add_library(absl STATIC IMPORTED GLOBAL) -set_target_properties(absl PROPERTIES IMPORTED_LOCATION ${ABSL_LIB_DIR}/libabsl_base.a) -foreach(lib_name ${ABSL_LIB_NAMES}) - target_link_libraries(absl INTERFACE ${ABSL_LIB_DIR}/libabsl_${lib_name}.a) -endforeach() include_directories(${ABSL_INCLUDE_DIR}) # Add isl -set(ISL_LIB_DIR "${CINN_BINARY_DIR}/dist/third_party/isl/lib") set(ISL_INCLUDE_DIR "${CINN_BINARY_DIR}/dist/third_party/isl/include") -add_library(isl STATIC IMPORTED GLOBAL) -set_target_properties(isl PROPERTIES IMPORTED_LOCATION ${ISL_LIB_DIR}/libisl.a) include_directories(${ISL_INCLUDE_DIR}) # Add LLVM -set(LLVM_LIB_NAMES - ExecutionEngine - ) -set(LLVM_LIB_DIR "${CINN_BINARY_DIR}/dist/third_party/llvm/lib") set(LLVM_INCLUDE_DIR "${CINN_BINARY_DIR}/dist/third_party/llvm/include") -add_library(llvm STATIC IMPORTED GLOBAL) -set_target_properties(llvm PROPERTIES IMPORTED_LOCATION ${LLVM_LIB_DIR}/libLLVMCore.a) -foreach(lib_name ${LLVM_LIB_NAMES}) - target_link_libraries(llvm INTERFACE ${LLVM_LIB_DIR}/libLLVM${lib_name}.a) -endforeach() include_directories(${LLVM_INCLUDE_DIR}) ###################################################### @@ -108,5 +78,5 @@ set(CINN_INCLUDE_DIR "${CINN_BINARY_DIR}/dist/cinn/include") add_library(cinn SHARED IMPORTED GLOBAL) set_target_properties(cinn PROPERTIES IMPORTED_LOCATION "${CINN_LIB_LOCATION}/${CINN_LIB_NAME}") include_directories(${CINN_INCLUDE_DIR}) -add_dependencies(cinn external_cinn absl isl llvm glog gflag) +add_dependencies(cinn external_cinn) diff --git a/cmake/third_party.cmake b/cmake/third_party.cmake index d45b5e07bb8..0049311a931 100644 --- a/cmake/third_party.cmake +++ b/cmake/third_party.cmake @@ -360,6 +360,11 @@ if (WITH_LITE) include(external/lite) endif (WITH_LITE) +if (WITH_CINN) + message(STATUS "Compile Paddle with CINN.") + include(external/cinn) +endif (WITH_CINN) + if (WITH_CRYPTO) include(external/cryptopp) # download, build, install cryptopp list(APPEND third_party_deps extern_cryptopp) diff --git a/paddle/fluid/framework/ir/cinn_lib_test.cc b/paddle/fluid/framework/ir/cinn_lib_test.cc index cdee45a06c7..23cb653fef2 100644 --- a/paddle/fluid/framework/ir/cinn_lib_test.cc +++ b/paddle/fluid/framework/ir/cinn_lib_test.cc @@ -24,6 +24,7 @@ limitations under the License. */ #include #endif +#include "cinn/cinn.h" #include "cinn/common/target.h" #include "cinn/frontend/net_builder.h" #include "cinn/frontend/syntax.h" diff --git a/paddle/fluid/inference/tests/infer_ut/test_LeViT.cc b/paddle/fluid/inference/tests/infer_ut/test_LeViT.cc index a7ff5af1bdc..2fe9b6c1444 100644 --- a/paddle/fluid/inference/tests/infer_ut/test_LeViT.cc +++ b/paddle/fluid/inference/tests/infer_ut/test_LeViT.cc @@ -174,6 +174,6 @@ TEST(tensorrt_tester_LeViT, multi_thread4_trt_fp32_bz2) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); - ::google::ParseCommandLineFlags(&argc, &argv, true); + ::GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true); return RUN_ALL_TESTS(); } diff --git a/paddle/fluid/inference/tests/infer_ut/test_det_mv3_db.cc b/paddle/fluid/inference/tests/infer_ut/test_det_mv3_db.cc index cf3398b49ee..eb31acbdf7c 100644 --- a/paddle/fluid/inference/tests/infer_ut/test_det_mv3_db.cc +++ b/paddle/fluid/inference/tests/infer_ut/test_det_mv3_db.cc @@ -164,6 +164,6 @@ TEST(mkldnn_tester_det_mv3_db, multi_thread2_mkl_fp32_bz2) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); - ::google::ParseCommandLineFlags(&argc, &argv, true); + ::GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true); return RUN_ALL_TESTS(); } diff --git a/paddle/fluid/inference/tests/infer_ut/test_ernie_text_cls.cc b/paddle/fluid/inference/tests/infer_ut/test_ernie_text_cls.cc index 6ef894cc3d1..3fa41b201c6 100644 --- a/paddle/fluid/inference/tests/infer_ut/test_ernie_text_cls.cc +++ b/paddle/fluid/inference/tests/infer_ut/test_ernie_text_cls.cc @@ -132,6 +132,6 @@ TEST(mkldnn_tester_ernie_text_cls, multi_thread4_mkl_fp32_bz2) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); - ::google::ParseCommandLineFlags(&argc, &argv, true); + ::GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true); return RUN_ALL_TESTS(); } diff --git a/paddle/fluid/inference/tests/infer_ut/test_ernie_xnli_int8.cc b/paddle/fluid/inference/tests/infer_ut/test_ernie_xnli_int8.cc index 9e835511265..4e924e31979 100644 --- a/paddle/fluid/inference/tests/infer_ut/test_ernie_xnli_int8.cc +++ b/paddle/fluid/inference/tests/infer_ut/test_ernie_xnli_int8.cc @@ -186,7 +186,8 @@ TEST(tensorrt_tester_ernie_xnli, oss_varlen_truth_data_int8) { int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); - ::google::ParseCommandLineFlags(&argc, &argv, true); + ::GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true); + #if IS_TRT_VERSION_GE(7200) return RUN_ALL_TESTS(); #endif diff --git a/paddle/fluid/inference/tests/infer_ut/test_mobilnetv1.cc b/paddle/fluid/inference/tests/infer_ut/test_mobilnetv1.cc index 21991d0da06..eaa7bac89ef 100644 --- a/paddle/fluid/inference/tests/infer_ut/test_mobilnetv1.cc +++ b/paddle/fluid/inference/tests/infer_ut/test_mobilnetv1.cc @@ -81,6 +81,6 @@ TEST(tensorrt_tester_mobilenetv1, tuned_dynamic_trt_fp32_bz2) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); - ::google::ParseCommandLineFlags(&argc, &argv, true); + ::GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true); return RUN_ALL_TESTS(); } diff --git a/paddle/fluid/inference/tests/infer_ut/test_ppyolo_mbv3.cc b/paddle/fluid/inference/tests/infer_ut/test_ppyolo_mbv3.cc index 2d69c933c2f..ff1647432a1 100644 --- a/paddle/fluid/inference/tests/infer_ut/test_ppyolo_mbv3.cc +++ b/paddle/fluid/inference/tests/infer_ut/test_ppyolo_mbv3.cc @@ -151,6 +151,6 @@ TEST(DISABLED_mkldnn_tester_ppyolo_mbv3, multi_thread4_mkl_bz2) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); - ::google::ParseCommandLineFlags(&argc, &argv, true); + ::GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true); return RUN_ALL_TESTS(); } diff --git a/paddle/fluid/inference/tests/infer_ut/test_ppyolov2_r50vd.cc b/paddle/fluid/inference/tests/infer_ut/test_ppyolov2_r50vd.cc index d74a3332324..9689ec20956 100644 --- a/paddle/fluid/inference/tests/infer_ut/test_ppyolov2_r50vd.cc +++ b/paddle/fluid/inference/tests/infer_ut/test_ppyolov2_r50vd.cc @@ -150,6 +150,6 @@ TEST(mkldnn_tester_ppyolov2_r50vd, multi_thread2_mkl_bz2) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); - ::google::ParseCommandLineFlags(&argc, &argv, true); + ::GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true); return RUN_ALL_TESTS(); } diff --git a/paddle/fluid/inference/tests/infer_ut/test_resnet50.cc b/paddle/fluid/inference/tests/infer_ut/test_resnet50.cc index 6157fdbdb10..01bec2916e9 100644 --- a/paddle/fluid/inference/tests/infer_ut/test_resnet50.cc +++ b/paddle/fluid/inference/tests/infer_ut/test_resnet50.cc @@ -236,6 +236,6 @@ TEST(DISABLED_tensorrt_tester_resnet50, profile_multi_thread_trt_fp32) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); - ::google::ParseCommandLineFlags(&argc, &argv, true); + ::GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true); return RUN_ALL_TESTS(); } diff --git a/paddle/fluid/inference/tests/infer_ut/test_resnet50_quant.cc b/paddle/fluid/inference/tests/infer_ut/test_resnet50_quant.cc index ed7ab7b5eee..380954f9e52 100644 --- a/paddle/fluid/inference/tests/infer_ut/test_resnet50_quant.cc +++ b/paddle/fluid/inference/tests/infer_ut/test_resnet50_quant.cc @@ -165,6 +165,6 @@ TEST(DISABLED_tensorrt_tester_resnet50_quant, multi_thread_multi_instance) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); - ::google::ParseCommandLineFlags(&argc, &argv, true); + ::GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true); return RUN_ALL_TESTS(); } diff --git a/paddle/fluid/inference/tests/infer_ut/test_yolov3.cc b/paddle/fluid/inference/tests/infer_ut/test_yolov3.cc index 845bcbc5c5b..69a9e8d6a90 100644 --- a/paddle/fluid/inference/tests/infer_ut/test_yolov3.cc +++ b/paddle/fluid/inference/tests/infer_ut/test_yolov3.cc @@ -150,6 +150,6 @@ TEST(test_yolov3, multi_thread4_mkl_bz2) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); - ::google::ParseCommandLineFlags(&argc, &argv, true); + ::GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true); return RUN_ALL_TESTS(); } -- GitLab