From 613beeb6702995b618fd0205b7279815b7beb47e Mon Sep 17 00:00:00 2001 From: hong19860320 <9973393+hong19860320@users.noreply.github.com> Date: Thu, 3 Aug 2023 14:10:46 +0800 Subject: [PATCH] [XPU] Fix compilation errors of XPU plugin on multiple versions of GCC (#55924) --- paddle/phi/kernels/xpu/plugin/CMakeLists.txt | 37 +++++++++---------- paddle/phi/kernels/xpu/plugin/build.sh | 8 ++-- .../kernels/xpu/plugin/example/CMakeLists.txt | 2 +- .../phi/kernels/xpu/plugin/example/build.sh | 4 +- paddle/phi/kernels/xpu/plugin/example/run.sh | 22 ++++++++--- 5 files changed, 41 insertions(+), 32 deletions(-) diff --git a/paddle/phi/kernels/xpu/plugin/CMakeLists.txt b/paddle/phi/kernels/xpu/plugin/CMakeLists.txt index ec82864da79..32f56343485 100644 --- a/paddle/phi/kernels/xpu/plugin/CMakeLists.txt +++ b/paddle/phi/kernels/xpu/plugin/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.16) +cmake_minimum_required(VERSION 3.10) project(xpuplugin LANGUAGES CXX) @@ -62,14 +62,13 @@ message(STATUS "Build with XPU_CLANG=" ${XPU_CLANG}) if(NOT DEFINED HOST_SYSROOT) set(HOST_SYSROOT $ENV{HOST_SYSROOT}) endif() -if(NOT HOST_SYSROOT) - set(HOST_SYSROOT /opt/compiler/gcc-8.2) -endif() -if(NOT IS_DIRECTORY ${HOST_SYSROOT}) - message( - FATAL_ERROR - "Directory ${HOST_SYSROOT} not found, please export HOST_SYSROOT=." - ) +if(HOST_SYSROOT) + if(NOT IS_DIRECTORY ${HOST_SYSROOT}) + message( + FATAL_ERROR + "Directory ${HOST_SYSROOT} not found, please export HOST_SYSROOT=." + ) + endif() endif() if(NOT DEFINED HOST_ARCH) @@ -89,13 +88,12 @@ endif() if(NOT DEFINED TOOLCHAIN_ARGS) set(TOOLCHAIN_ARGS $ENV{TOOLCHAIN_ARGS}) endif() -set(TOOLCHAIN_ARGS -isystem ${HOST_SYSROOT}/include/c++/8.2.0 -isystem - /usr/include/ -isystem /usr/include/x86_64-linux-gnu) if(HOST_ARCH MATCHES "x86_64") if(TARGET_ARCH MATCHES "x86_64") if(EXISTS ${HOST_SYSROOT}/bin/g++) set(HOST_CXX ${HOST_SYSROOT}/bin/g++) - if(NOT EXISTS ${HOST_SYSROOT}/bin/ar) + set(HOST_AR ${HOST_SYSROOT}/bin/ar) + if(NOT EXISTS ${HOST_AR}) # try gcc-ar set(HOST_AR ${HOST_SYSROOT}/bin/gcc-ar) endif() @@ -105,7 +103,7 @@ if(HOST_ARCH MATCHES "x86_64") endif() endif() if(TARGET_ARCH MATCHES "aarch64") - set(TOOLCHAIN_ARGS --gcc-toolchain=${HOST_SYSROOT}) + set(TOOLCHAIN_ARGS "${TOOLCHAIN_ARGS} --gcc-toolchain=${HOST_SYSROOT}") set(HOST_SYSROOT ${HOST_SYSROOT}/aarch64-linux-gnu/libc) set(HOST_CXX ${CMAKE_CXX_COMPILER}) set(HOST_AR ${CMAKE_AR}) @@ -130,6 +128,7 @@ message(STATUS "Build with HOST_SYSROOT=" ${HOST_SYSROOT}) message(STATUS "Build with HOST_CXX=" ${HOST_CXX}) message(STATUS "Build with HOST_AR=" ${HOST_AR}) +separate_arguments(TOOLCHAIN_ARGS) # compile xpu kernel macro function macro( compile_kernel @@ -303,9 +302,9 @@ foreach(xpu_wrapper IN LISTS xpu_wrappers) ${xpu_wrapper} -I${XDNN_INC_DIR} -I${XRE_INC_DIR} -I${CMAKE_CURRENT_SOURCE_DIR}/include -I${CMAKE_CURRENT_SOURCE_DIR}/src -I${CMAKE_CURRENT_SOURCE_DIR}/src/wrapper -D_GNU_SOURCE - -D__STDC_LIMIT_MACROS -DNDEBUG --sysroot=${HOST_SYSROOT} ${TOOLCHAIN_ARGS} - --target=${TARGET_ARCH} -fPIC -Werror -Wreorder -fvisibility=hidden - --xpu-host-only ${XPU_MF_FLAGS} + -D__STDC_LIMIT_MACROS -DNDEBUG ${TOOLCHAIN_ARGS} --target=${TARGET_ARCH} + -fPIC -Werror -Wreorder -fvisibility=hidden --xpu-host-only + ${XPU_MF_FLAGS} COMMAND ${CMAKE_COMMAND} -E cmake_depends "Unix Makefiles" ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR} @@ -325,9 +324,9 @@ foreach(xpu_wrapper IN LISTS xpu_wrappers) -I${XDNN_INC_DIR} -I${XRE_INC_DIR} -I${CMAKE_CURRENT_SOURCE_DIR}/include -I${CMAKE_CURRENT_SOURCE_DIR}/src -I${CMAKE_CURRENT_SOURCE_DIR}/src/wrapper -D_GNU_SOURCE - -D__STDC_LIMIT_MACROS -DNDEBUG --sysroot=${HOST_SYSROOT} ${TOOLCHAIN_ARGS} - --target=${TARGET_ARCH} -fPIC -Wunused-variable -Werror -Wreorder - -fvisibility=hidden --xpu-host-only ${HOST_XPU_FLAGS} + -D__STDC_LIMIT_MACROS -DNDEBUG ${TOOLCHAIN_ARGS} --target=${TARGET_ARCH} + -fPIC -Wunused-variable -Werror -Wreorder -fvisibility=hidden + --xpu-host-only ${HOST_XPU_FLAGS} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} DEPENDS wrapper_build/${wrapper_name}.wrapper.d COMMENT wrapper_build/${wrapper_name}.wrapper.o diff --git a/paddle/phi/kernels/xpu/plugin/build.sh b/paddle/phi/kernels/xpu/plugin/build.sh index 9e446436ab0..65228c101d3 100755 --- a/paddle/phi/kernels/xpu/plugin/build.sh +++ b/paddle/phi/kernels/xpu/plugin/build.sh @@ -16,10 +16,10 @@ set -e -export XDNN_PATH=/opt/xdnn # -export XRE_PATH=/opt/xre # -export CLANG_PATH=/opt/xtdk # -export HOST_SYSROOT=/opt/compiler/gcc-8.2 # +#export XDNN_PATH=/opt/xdnn # +#export XRE_PATH=/opt/xre # +#export CLANG_PATH=/opt/xtdk # +#export HOST_SYSROOT=/opt/compiler/gcc-8.2 # rm -rf build mkdir build diff --git a/paddle/phi/kernels/xpu/plugin/example/CMakeLists.txt b/paddle/phi/kernels/xpu/plugin/example/CMakeLists.txt index f9b714ade3a..eb4cc478171 100644 --- a/paddle/phi/kernels/xpu/plugin/example/CMakeLists.txt +++ b/paddle/phi/kernels/xpu/plugin/example/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.16) +cmake_minimum_required(VERSION 3.10) project(example LANGUAGES CXX) diff --git a/paddle/phi/kernels/xpu/plugin/example/build.sh b/paddle/phi/kernels/xpu/plugin/example/build.sh index e5d74dcafc8..d96636707d1 100755 --- a/paddle/phi/kernels/xpu/plugin/example/build.sh +++ b/paddle/phi/kernels/xpu/plugin/example/build.sh @@ -16,8 +16,8 @@ set -e -export XDNN_PATH=/opt/xdnn # -export XRE_PATH=/opt/xre # +#export XDNN_PATH=/opt/xdnn # +#export XRE_PATH=/opt/xre # export LINK_TYPE=static # shared/static rm -rf build diff --git a/paddle/phi/kernels/xpu/plugin/example/run.sh b/paddle/phi/kernels/xpu/plugin/example/run.sh index d3936a51a68..25b4a9dbd24 100755 --- a/paddle/phi/kernels/xpu/plugin/example/run.sh +++ b/paddle/phi/kernels/xpu/plugin/example/run.sh @@ -16,10 +16,20 @@ set -e -XDNN_PATH=/opt/xdnn # -XRE_PATH=/opt/xre # +#XDNN_PATH=/opt/xdnn # +#XRE_PATH=/opt/xre # -:<." + exit -1 +fi + +if [[ "$XRE_PATH" == "" ]] || [[ ! -d "$XRE_PATH" ]]; then + echo "XRE_PATH not set, or directory ${XRE_PATH} not found, please export XRE_PATH=." + exit -1 +fi + +#:<