Skip to content

Commit

Permalink
combination the WITH_XPU and WITH_XPU2
Browse files Browse the repository at this point in the history
  • Loading branch information
Liu-xiandong committed Nov 23, 2021
1 parent a49660e commit 9c0a1dd
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 52 deletions.
14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,13 @@ if (NOT WITH_GPU AND WITH_NCCL)
"Disable NCCL when compiling without GPU" FORCE)
endif()

# XPU XPU2 use BKCL
# if (NOT (WITH_XPU OR WITH_XPU2) AND WITH_XPU_BKCL)
# MESSAGE(WARNING
# "Disable BKCL when compiling without XPU. Force WITH_XPU_BKCL=OFF.")
# set(WITH_XPU_BKCL OFF CACHE STRING
# "Disable BKCL when compiling without XPU" FORCE)
# endif()
# force XPU on when WITH_XPU2
if (WITH_XPU2 AND NOT WITH_XPU)
MESSAGE(WARNING
"Enable XPU when compiling with XPU2. Force WITH_XPU=ON.")
set(WITH_XPU ON CACHE STRING
"Enable XPU when compiling with XPU2" FORCE)
endif()

#
if (NOT WITH_XPU AND WITH_XPU_BKCL)
Expand Down
6 changes: 3 additions & 3 deletions cmake/generic.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ function(cc_binary TARGET_NAME)
target_link_libraries(${TARGET_NAME} ${ROCM_HIPRTC_LIB})
endif()
if(WITH_XPU2)
target_link_libraries(${TARGET_NAME} ${XPU2_CLANG_API_LIB})
target_link_libraries(${TARGET_NAME} ${XPU2_CLANG_RT_LIB})
# target_link_libraries(${TARGET_NAME} ${XPU2_CLANG_API_LIB})
# target_link_libraries(${TARGET_NAME} ${XPU2_CLANG_RT_LIB})
endif()

check_coverage_opt(${TARGET_NAME} ${cc_binary_SRCS})
Expand Down Expand Up @@ -430,7 +430,7 @@ function(cc_test_build TARGET_NAME)
endif()
# added by lxd
if(WITH_XPU2)
target_link_libraries(${TARGET_NAME} ${XPU2_CLANGRTC_LIB})
#target_link_libraries(${TARGET_NAME} ${XPU2_CLANGRTC_LIB})
endif()
check_coverage_opt(${TARGET_NAME} ${cc_test_SRCS})
endif()
Expand Down
55 changes: 47 additions & 8 deletions cmake/operators.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,53 @@ function(op_library TARGET)
list(APPEND cu_cc_srcs ${src})
elseif(WITH_XPU AND ${src} MATCHES ".*_op_xpu.cc$")
list(APPEND xpu_cc_srcs ${src})
elseif(WITH_XPU2 AND ${src} MATCHES ".*_op_kps.cc$")
list(APPEND xpu2_cc_srcs ${src})
elseif(WITH_XPU2 AND ${src} MATCHES ".*\\.xpu$")
list(APPEND xpu2_cc_srcs ${src})
elseif(WITH_ASCEND_CL AND ${src} MATCHES ".*_op_npu.cc$")
list(APPEND npu_cc_srcs ${src})
elseif(${src} MATCHES ".*\\.cc$")
list(APPEND cc_srcs ${src})
else()
message(FATAL_ERROR "${TARGET} Source file ${src} should only be .cc or .cu")
message(FATAL_ERROR "${TARGET} Source file ${src} should only be .cc or .cu or .xpu")
endif()
endforeach()
endif()

list(LENGTH xpu_cc_srcs xpu_cc_srcs_len)
list(LENGTH xpu2_cc_srcs xpu2_cc_srcs_len)
if(WITH_XPU AND WITH_XPU2)
if(${xpu2_cc_srcs_len})
# message(STATUS "lxd_debug: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>delete duplicate op in xpu")
# message(STATUS " xpu ${xpu_cc_srcs} xpu2 ${xpu2_cc_srcs}")
endif()
endif()

#TODO(liuxiandong)
if(WITH_XPU2 AND ${xpu2_cc_srcs_len})
foreach(src ${xpu2_cc_srcs})
get_filename_component(op_name ${src} NAME_WE)
message(STATUS "lxd_debug op_name ${op_name}")
if(WITH_XPU)
#TODO
if(${xpu_cc_srcs} MATCHES "elementwise_add_op_xpu.cc")
# delete it from the xpu_cc_srcs
#list(REMOVE_ITEM ${xpu_cc_srcs} ${op_name}_xpu.cc)
list(REMOVE_ITEM xpu_cc_srcs "elementwise_add_op_xpu.cc")
endif()
endif()
endforeach()
endif()

if(WITH_XPU AND WITH_XPU2)
if(${xpu2_cc_srcs_len})
# message(STATUS "lxd_debug: <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<delete duplicate op in xpu")
# message(STATUS " xpu ${xpu_cc_srcs} xpu2 ${xpu2_cc_srcs}")
endif()
endif()
list(LENGTH xpu_cc_srcs xpu_cc_srcs_len)
list(LENGTH xpu2_cc_srcs xpu2_cc_srcs_len)
# message(STATUS "lxd_debug: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! xpu ${xpu_cc_srcs} xpu2 ${xpu2_cc_srcs}")

list(LENGTH cc_srcs cc_srcs_len)
if (${cc_srcs_len} EQUAL 0)
message(FATAL_ERROR "The op library ${TARGET} should contains at least one .cc file")
Expand Down Expand Up @@ -208,9 +241,12 @@ function(op_library TARGET)
list(REMOVE_ITEM hip_srcs "decode_jpeg_op.cu")
hip_library(${TARGET} SRCS ${cc_srcs} ${hip_cc_srcs} ${miopen_cu_cc_srcs} ${miopen_cu_srcs} ${mkldnn_cc_srcs} ${hip_srcs} DEPS ${op_library_DEPS}
${op_common_deps})
elseif (WITH_XPU2)
elseif (WITH_XPU2 AND ${xpu2_cc_srcs_len} GREATER 0)
xpu_library(${TARGET} SRCS ${cc_srcs} ${mkldnn_cc_srcs} ${xpu2_cc_srcs} DEPS ${op_library_DEPS} ${op_common_deps})
else()
# if(WITH_XPU2 AND ${xpu2_cc_srcs_len} GREATER 0)
# xpu_library(${TARGET} SRCS ${cc_srcs} ${mkldnn_cc_srcs} ${xpu2_cc_srcs} DEPS ${op_library_DEPS} ${op_common_deps})
# endif()
# Unity Build relies on global option `WITH_UNITY_BUILD` and local option `UNITY`.
if(WITH_UNITY_BUILD AND op_library_UNITY)
# Combine the cc source files.
Expand Down Expand Up @@ -277,8 +313,8 @@ function(op_library TARGET)
list(LENGTH cu_cc_srcs cu_cc_srcs_len)
list(LENGTH hip_cc_srcs hip_cc_srcs_len)
list(LENGTH mkldnn_cc_srcs mkldnn_cc_srcs_len)
list(LENGTH xpu_cc_srcs xpu_cc_srcs_len)
list(LENGTH xpu2_cc_srcs xpu2_cc_srcs_len)
#list(LENGTH xpu_cc_srcs xpu_cc_srcs_len)
#list(LENGTH xpu2_cc_srcs xpu2_cc_srcs_len)
list(LENGTH miopen_cu_cc_srcs miopen_cu_cc_srcs_len)
list(LENGTH npu_cc_srcs npu_cc_srcs_len)
if (${pybind_flag} EQUAL 0 AND ${mkldnn_cc_srcs_len} EQUAL 0 AND ${cu_srcs_len} EQUAL 0 AND ${cu_cc_srcs_len} EQUAL 0 AND
Expand Down Expand Up @@ -320,10 +356,13 @@ function(op_library TARGET)
file(APPEND ${pybind_file} "USE_OP_DEVICE_KERNEL(${TARGET}, CUDNN);\n")
endif()

if (WITH_XPU AND ${pybind_flag} EQUAL 0 AND ${xpu_cc_srcs_len} GREATER 0)
#file(APPEND ${pybind_file} "USE_OP_DEVICE_KERNEL(${TARGET}, XPU);\n")
if (WITH_XPU AND ${pybind_flag} EQUAL 0 AND ${xpu_cc_srcs_len} GREATER 0 AND ${xpu2_cc_srcs_len} EQUAL 0)
#message(STATUS "lxd_debug: ${TARGET} op in XPU1")
file(APPEND ${pybind_file} "USE_OP_DEVICE_KERNEL(${TARGET}, XPU);\n")
endif()

#message(STATUS "lxd_debug: cmake source dir is: ${CMAKE_SOURCE_DIR}")

if (WITH_XPU2 AND ${xpu2_cc_srcs_len} GREATER 0)
file(APPEND ${pybind_file} "USE_OP_DEVICE_KERNEL(${TARGET}, XPU);\n")
endif()
Expand Down
68 changes: 34 additions & 34 deletions cmake/xpu2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ macro(compile_kernel COMPILE_ARGS)
set(XTDK_DIR ${XPU_TOOLCHAIN})
set(CXX_DIR ${HOST_SYSROOT})
#-Wno-error=constant-conversion -Wno-error=c++11-narrowing -Wno-error=shift-count-overflow
set(XPU_CXX_INCLUDES -I/workspace/paddle/Paddle/build -I/workspace/paddle/Paddle/paddle/fluid/framework/io -I/workspace/paddle/Paddle/build/third_party/install/zlib/include -I/workspace/paddle/Paddle/build/third_party/install -I/workspace/paddle/Paddle/build/third_party/install/gflags/include -I/workspace/paddle/Paddle/build/third_party/install/glog/include -I/workspace/paddle/Paddle/build/third_party/boost/src/extern_boost -I/workspace/paddle/Paddle/build/third_party/eigen3/src/extern_eigen3 -I/workspace/paddle/Paddle/build/third_party/threadpool/src/extern_threadpool -I/workspace/paddle/Paddle/build/third_party/dlpack/src/extern_dlpack/include -I/workspace/paddle/Paddle/build/third_party/install/xxhash/include -I/workspace/paddle/Paddle/build/third_party/install/warpctc/include -I/workspace/paddle/Paddle/build/third_party/install/openblas/include -I/workspace/paddle/Paddle/build/third_party/install/protobuf/include -I/usr/include/python3.7m -I/usr/local/lib/python3.7/dist-packages/numpy/core/include -I/workspace/paddle/Paddle/build/third_party/pybind/src/extern_pybind/include -I/workspace/paddle/Paddle/build/third_party/install/gtest/include -I/workspace/paddle/Paddle/build/third_party/install/gloo/include -I/workspace/paddle/Paddle/build/third_party/install/xbyak/include -I/workspace/paddle/Paddle/build/third_party/install/xbyak/include/xbyak -I/workspace/paddle/Paddle/build/third_party/install/cryptopp/include -I/workspace/paddle/Paddle/build/third_party/pocketfft/src -I/workspace/paddle/Paddle)
set(XPU_CXX_INCLUDES -I${CMAKE_SOURCE_DIR}/build -I${CMAKE_SOURCE_DIR}/paddle/fluid/framework/io -I${CMAKE_SOURCE_DIR}/build/third_party/install/zlib/include -I${CMAKE_SOURCE_DIR}/build/third_party/install -I${CMAKE_SOURCE_DIR}/build/third_party/install/gflags/include -I${CMAKE_SOURCE_DIR}/build/third_party/install/glog/include -I${CMAKE_SOURCE_DIR}/build/third_party/boost/src/extern_boost -I${CMAKE_SOURCE_DIR}/build/third_party/eigen3/src/extern_eigen3 -I${CMAKE_SOURCE_DIR}/build/third_party/threadpool/src/extern_threadpool -I${CMAKE_SOURCE_DIR}/build/third_party/dlpack/src/extern_dlpack/include -I${CMAKE_SOURCE_DIR}/build/third_party/install/xxhash/include -I${CMAKE_SOURCE_DIR}/build/third_party/install/warpctc/include -I${CMAKE_SOURCE_DIR}/build/third_party/install/utf8proc/include -I${CMAKE_SOURCE_DIR}/build/third_party/install/openblas/include -I${CMAKE_SOURCE_DIR}/build/third_party/install/protobuf/include -I/usr/include/python3.7m -I/usr/local/lib/python3.7/dist-packages/numpy/core/include -I${CMAKE_SOURCE_DIR}/build/third_party/pybind/src/extern_pybind/include -I${CMAKE_SOURCE_DIR}/build/third_party/install/gtest/include -I${CMAKE_SOURCE_DIR}/build/third_party/install/xpu/include -I${CMAKE_SOURCE_DIR}/build/third_party/install/gloo/include -I${CMAKE_SOURCE_DIR}/build/third_party/install/xbyak/include -I${CMAKE_SOURCE_DIR}/build/third_party/install/xbyak/include/xbyak -I${CMAKE_SOURCE_DIR}/build/third_party/install/cryptopp/include -I${CMAKE_SOURCE_DIR}/build/third_party/pocketfft/src -I${CMAKE_SOURCE_DIR} -I${CMAKE_SOURCE_DIR}/paddle/fluid/platform)
#set(XPU_CXX_FLAGS -Wno-error=deprecated-declarations -Wno-deprecated-declarations -std=c++14 -m64 -fPIC -fno-omit-frame-pointer -Werror -Wall -Wextra -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wno-unused-parameter -Wno-unused-function -Wno-error=literal-suffix -Wno-error=unused-local-typedefs -Wno-error=ignored-attributes -Wno-error=terminate -Wno-error=int-in-bool-context -Wimplicit-fallthrough=0 -Wno-error=maybe-uninitialized -Wno-format-truncation -Wno-error=cast-function-type -Wno-error=parentheses -Wno-error=catch-value -Wno-error=nonnull-compare -Wno-error=address -Wno-ignored-qualifiers -Wno-ignored-attributes -Wno-parentheses -mavx -O3 -DNDEBUG )
set(XPU_CXX_FLAGS -Wno-error=pessimizing-move -Wno-error=constant-conversion -Wno-error=c++11-narrowing -Wno-error=shift-count-overflow -Wno-error=unused-local-typedef -Wno-error=deprecated-declarations -Wno-deprecated-declarations -std=c++14 -m64 -fPIC -fno-omit-frame-pointer -Wall -Wno-inconsistent-missing-override -Wextra -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wno-unused-parameter -Wno-unused-function -Wno-error=unused-local-typedefs -Wno-error=ignored-attributes -Wno-error=int-in-bool-context -Wno-error=parentheses -Wno-error=address -Wno-ignored-qualifiers -Wno-ignored-attributes -Wno-parentheses -O3 -DNDEBUG )
#set(XPU_CXX_FLAGS -Wno-error=deprecated-declarations -Wno-deprecated-declarations -std=c++14 -m64 -fPIC -fno-omit-frame-pointer -Werror -Wall -Wextra -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wno-unused-parameter -Wno-unused-function -Wno-error=literal-suffix -Wno-error=unused-local-typedefs -Wno-error=ignored-attributes -Wno-error=terminate -Wno-error=int-in-bool-context -Wimplicit-fallthrough=0 -Wno-error=maybe-uninitialized -Wno-format-truncation -Wno-error=cast-function-type -Wno-error=parentheses -Wno-error=catch-value -Wno-error=nonnull-compare -Wno-error=address -Wno-ignored-qualifiers -Wno-ignored-attributes -Wno-parentheses -O3 -DNDEBUG )
Expand All @@ -107,7 +107,7 @@ macro(compile_kernel COMPILE_ARGS)
COMMAND
# TODO(liuxiandong) xpu->kps -I${XTDK_DIR}/include -std=c++11
${XPU_CLANG} --sysroot=${CXX_DIR} -O2 -fno-builtin -g -mcpu=xpu2 -fPIC ${XPU_CXX_DEFINES} ${XPU_CXX_FLAGS} ${XPU_CXX_INCLUDES}
-I${XTDK_DIR}/include -I. -o kernel_build/${kernel_name}.bin.o.sec /workspace/paddle/Paddle/paddle/fluid/operators/elementwise/${kernel_name}.xpu
-I${XTDK_DIR}/include -I. -o kernel_build/${kernel_name}.bin.o.sec ${CMAKE_SOURCE_DIR}/paddle/fluid/operators/elementwise/${kernel_name}.xpu
--xpu-device-only -c -v
COMMAND
${XTDK_DIR}/bin/xpu2-elfconv kernel_build/${kernel_name}.bin.o.sec kernel_build/${kernel_name}.bin.o ${XPU_CLANG} --sysroot=${CXX_DIR}
Expand Down Expand Up @@ -135,7 +135,7 @@ macro(compile_kernel COMPILE_ARGS)
COMMAND
# TODO(liuxiandong) xpu->kps -I${XTDK_DIR}/include -std=c++11
${XPU_CLANG} --sysroot=${CXX_DIR} -O2 -fno-builtin -g -mcpu=xpu2 -fPIC ${XPU_CXX_DEFINES} ${XPU_CXX_FLAGS} ${XPU_CXX_INCLUDES}
-I${XTDK_DIR}/include -I. -o kernel_build/${kernel_name}.host.o /workspace/paddle/Paddle/paddle/fluid/operators/elementwise/${kernel_name}.xpu
-I${XTDK_DIR}/include -I. -o kernel_build/${kernel_name}.host.o ${CMAKE_SOURCE_DIR}/paddle/fluid/operators/elementwise/${kernel_name}.xpu
--xpu-host-only -c -v
# COMMAND
# ${CMAKE_COMMAND} -E cmake_depends "Unix Makefiles" ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
Expand Down Expand Up @@ -263,42 +263,42 @@ macro(xpu_add_library TARGET_NAME)
endmacro()

# XPU2 PATH
if(NOT DEFINED ENV{XPU2_PATH})
set(XPU2_PATH "/workspace/paddle/xpu-demo/XTDK" CACHE PATH "Path to which XPU2 has been installed")
set(XPU_CLANG_PATH ${XPU2_PATH}/bin/clang CACHE PATH "Path to which XPU2 CLANG has been installed")
else()
set(XPU2_PATH $ENV{XPU2_PATH} CACHE PATH "Path to which ROCm has been installed")
set(XPU_CLANG_PATH ${XPU2_PATH}/bin/clang CACHE PATH "Path to which XPU2 CLANG has been installed")
endif()
set(CMAKE_MODULE_PATH "${XPU2_CLANG_PATH}/cmake" ${CMAKE_MODULE_PATH})
# if(NOT DEFINED ENV{XPU2_PATH})
# set(XPU2_PATH "/workspace/paddle/xpu-demo/XTDK" CACHE PATH "Path to which XPU2 has been installed")
# set(XPU_CLANG_PATH ${XPU2_PATH}/bin/clang CACHE PATH "Path to which XPU2 CLANG has been installed")
# else()
# set(XPU2_PATH $ENV{XPU2_PATH} CACHE PATH "Path to which ROCm has been installed")
# set(XPU_CLANG_PATH ${XPU2_PATH}/bin/clang CACHE PATH "Path to which XPU2 CLANG has been installed")
# endif()
# set(CMAKE_MODULE_PATH "${XPU2_CLANG_PATH}/cmake" ${CMAKE_MODULE_PATH})

# define XPU_CXX_FLAGS
list(APPEND XPU_CFLAGS -fPIC)
list(APPEND XPU_CFLAGS --sysroot = /opt/compiler/gcc-8.2)
list(APPEND XPU_CFLAGS -std=c++11)
list(APPEND XPU_CFLAGS -O2)
list(APPEND XPU_CFLAGS -g)
list(APPEND XPU_CFLAGS -mcpu=xpu2)
list(APPEND XPU_CFLAGS --target=x86_64-linux-gnu)
list(APPEND XPU_CFLAGS -v)
list(APPEND XPU_CFLAGS --dyld-prefix=/opt/compiler/gcc-8.2)
list(APPEND XPU_CFLAGS -fno-builtin)
list(APPEND XPU_CFLAGS -Wno-dev)
# # define XPU_CXX_FLAGS
# list(APPEND XPU_CFLAGS -fPIC)
# list(APPEND XPU_CFLAGS --sysroot = /opt/compiler/gcc-8.2)
# list(APPEND XPU_CFLAGS -std=c++11)
# list(APPEND XPU_CFLAGS -O2)
# list(APPEND XPU_CFLAGS -g)
# list(APPEND XPU_CFLAGS -mcpu=xpu2)
# list(APPEND XPU_CFLAGS --target=x86_64-linux-gnu)
# list(APPEND XPU_CFLAGS -v)
# list(APPEND XPU_CFLAGS --dyld-prefix=/opt/compiler/gcc-8.2)
# list(APPEND XPU_CFLAGS -fno-builtin)
# list(APPEND XPU_CFLAGS -Wno-dev)

set(XPU_XPUCC_FLAGS ${XPU_CFLAGS})
# set(XPU_XPUCC_FLAGS ${XPU_CFLAGS})

# set HIP link libs
set(xpuapi_library_name xpuapi)
message(STATUS "XPU API library name: ${xpuapi_library_name}")
# link in the generic.cmake
find_library(XPU2_CLANG_API_LIB ${xpuapi_library_name} HINTS ${XPU2_PATH}/shlib)
message(STATUS "XPU2_CLANG_API_LIB: ${XPU2_CLANG_API_LIB}")
# set(xpuapi_library_name xpuapi)
# message(STATUS "XPU API library name: ${xpuapi_library_name}")
# # link in the generic.cmake
# find_library(XPU2_CLANG_API_LIB ${xpuapi_library_name} HINTS ${XPU2_PATH}/shlib)
# message(STATUS "XPU2_CLANG_API_LIB: ${XPU2_CLANG_API_LIB}")

set(xpurt_library_name xpurt)
message(STATUS "XPU RT library name: ${xpurt_library_name}")
# link in the generic.cmake
find_library(XPU2_CLANG_RT_LIB ${xpurt_library_name} HINTS ${XPU2_PATH}/runtime/shlib)
message(STATUS "XPU2_CLANG_RT_LIB: ${XPU2_CLANG_RT_LIB}")
# set(xpurt_library_name xpurt)
# message(STATUS "XPU RT library name: ${xpurt_library_name}")
# # link in the generic.cmake
# find_library(XPU2_CLANG_RT_LIB ${xpurt_library_name} HINTS ${XPU2_PATH}/runtime/shlib)
# message(STATUS "XPU2_CLANG_RT_LIB: ${XPU2_CLANG_RT_LIB}")

# # Ensure that xpu/api.h can be included without dependency errors.
# file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/.xpu_headers_dummy.cc CONTENT "")
Expand Down

0 comments on commit 9c0a1dd

Please sign in to comment.