Skip to content

Commit 61c5f13

Browse files
sabreshaoXreki
authored andcommitted
Fix cmake for AMDGPU platform (#13801)
* HIP cmake. Enable whole archieve build for pybind library. Disable two warning. Rollback to C++11. Link RCCL to WA gpu kernel loading issue. Update eigen to fix build failure. Add more include directories. Fix O3 build failure. Update eigen. fix tensor_util_test segment fault issue add more macro check in hip.cmake. we may consider refine hip.cmake to inherit all add_definitions() in parrent scope, in the future. Fix rocRAND load. Update eigen to fix gru_unit_op and reduce_op. Add HIP support to testing. Update eigen to support int16 and int8 in arg min and arg max. * add rocprim as cub library used by nv implementation * Reduce build time in rocprim. * Add rocprim introduction, remove useless cmake code. * Remove useless flags and format cmake file.
1 parent 7465546 commit 61c5f13

File tree

8 files changed

+94
-20
lines changed

8 files changed

+94
-20
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ include(external/eigen) # download eigen3
204204
include(external/pybind11) # download pybind11
205205
include(external/cares)
206206
include(external/cub)
207+
include(external/rocprim)
207208
include(external/xxhash) # download xxhash
208209
include(external/dlpack)
209210
include(external/snappy) # download snappy

cmake/external/eigen.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if(WITH_AMD_GPU)
1717
extern_eigen3
1818
${EXTERNAL_PROJECT_LOG_ARGS}
1919
GIT_REPOSITORY "https://github.com/sabreshao/hipeigen.git"
20-
GIT_TAG 0cba03ff9f8f9f70bbd92ac5857b031aa8fed6f9
20+
GIT_TAG 7cb2b6e5a4b4a1efe658abb215cd866c6fb2275e
2121
PREFIX ${EIGEN_SOURCE_DIR}
2222
UPDATE_COMMAND ""
2323
CONFIGURE_COMMAND ""

cmake/external/rocprim.cmake

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
if (NOT WITH_AMD_GPU)
2+
return()
3+
endif()
4+
5+
# rocprim is "ROCm Parallel Primitives" for short.
6+
# It is a header-only library providing HIP and HC parallel primitives
7+
# for developing performant GPU-accelerated code on AMD ROCm platform.
8+
9+
if("x${HCC_HOME}" STREQUAL "x")
10+
set(HCC_HOME "/opt/rocm/hcc")
11+
endif()
12+
13+
INCLUDE(ExternalProject)
14+
15+
SET(ROCPRIM_SOURCE_DIR ${THIRD_PARTY_PATH}/rocprim)
16+
SET(ROCPRIM_INSTALL_DIR ${THIRD_PARTY_PATH}/install/rocprim)
17+
SET(ROCPRIM_INCLUDE_DIR ${ROCPRIM_INSTALL_DIR}/include)
18+
19+
ExternalProject_Add(
20+
extern_rocprim
21+
GIT_REPOSITORY "https://github.com/ROCmSoftwarePlatform/rocPRIM.git"
22+
GIT_TAG 5bd41b96ab8d8343330fb2c3e1b96775bde3b3fc
23+
PREFIX ${ROCPRIM_SOURCE_DIR}
24+
UPDATE_COMMAND ""
25+
CMAKE_ARGS -DCMAKE_CXX_COMPILER=${HCC_HOME}/bin/hcc
26+
CMAKE_ARGS -DONLY_INSTALL=ON
27+
CMAKE_ARGS -DBUILD_TEST=OFF
28+
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${ROCPRIM_INSTALL_DIR}
29+
30+
INSTALL_DIR ${ROCPRIM_INSTALL_DIR}
31+
${EXTERNAL_PROJECT_LOG_ARGS}
32+
)
33+
34+
INCLUDE_DIRECTORIES(${ROCPRIM_INCLUDE_DIR})
35+
36+
if (${CMAKE_VERSION} VERSION_LESS "3.3.0")
37+
set(dummyfile ${CMAKE_CURRENT_BINARY_DIR}/rocprim_dummy.c)
38+
file(WRITE ${dummyfile} "const char *dummy_rocprim = \"${dummyfile}\";")
39+
add_library(rocprim STATIC ${dummyfile})
40+
else()
41+
add_library(rocprim INTERFACE)
42+
endif()
43+
44+
add_dependencies(rocprim extern_rocprim)

cmake/flags.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ set(COMMON_FLAGS
129129
-Wno-error=parentheses-equality # Warnings in pybind11
130130
-Wno-error=ignored-attributes # Warnings in Eigen, gcc 6.3
131131
-Wno-error=terminate # Warning in PADDLE_ENFORCE
132+
-Wno-error=int-in-bool-context # Warning in Eigen gcc 7.2
133+
-Wimplicit-fallthrough=0 # Warning in tinyformat.h
134+
-Wno-error=maybe-uninitialized # Warning in boost gcc 7.2
132135
)
133136

134137
set(GPU_COMMON_FLAGS

cmake/generic.cmake

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -454,25 +454,29 @@ function(hip_library TARGET_NAME)
454454
else()
455455
add_library(${TARGET_NAME} STATIC ${_cmake_options} ${_generated_files} ${_sources})
456456
set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX)
457-
target_link_libraries(${TARGET_NAME} /opt/rocm/hip/lib/libhip_hcc.so /opt/rocm/hip/lib/libhip_device.a)
458-
find_fluid_modules(${TARGET_NAME})
457+
target_link_libraries(${TARGET_NAME} /opt/rocm/hip/lib/libhip_hcc.so /opt/rocm/hip/lib/libhip_device.a /opt/rocm/rccl/lib/librccl.so /opt/rocm/hiprand/lib/libhiprand.so)
458+
find_fluid_modules(${TARGET_NAME})
459459
endif()
460-
if (hip_library_DEPS)
461-
add_dependencies(${TARGET_NAME} ${hip_library_DEPS})
462-
target_link_libraries(${TARGET_NAME} ${hip_library_DEPS})
460+
if("${hip_library_DEPS}" MATCHES "ARCHIVE_START")
461+
# Support linking flags: --whole-archive (Linux) / -force_load (MacOS).
462+
# WARNING: Please don't use ARCHIVE_START&ARCHIVE_END if TARGET_NAME will be linked by other libraries.
463+
target_circle_link_libraries(${TARGET_NAME} ${hip_library_DEPS})
464+
list(REMOVE_ITEM hip_library_DEPS ARCHIVE_START ARCHIVE_END)
465+
else()
466+
target_link_libraries(${TARGET_NAME} ${hip_library_DEPS})
463467
endif()
464468
# cpplint code style
465469
foreach(source_file ${hip_library_SRCS})
466-
string(REGEX REPLACE "\\.[^.]*$" "" source ${source_file})
467-
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${source}.h)
468-
list(APPEND hip_library_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/${source}.h)
469-
endif()
470+
string(REGEX REPLACE "\\.[^.]*$" "" source ${source_file})
471+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${source}.h)
472+
list(APPEND hip_library_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/${source}.h)
473+
endif()
470474
endforeach()
471475
else(hip_library_SRCS)
472476
if (hip_library_DEPS)
473-
merge_static_libs(${TARGET_NAME} ${hip_library_DEPS})
477+
merge_static_libs(${TARGET_NAME} ${hip_library_DEPS})
474478
else()
475-
message(FATAL "Please specify source file or library in nv_library.")
479+
message(FATAL "Please specify source file or library in nv_library.")
476480
endif()
477481
endif(hip_library_SRCS)
478482
endif()

cmake/hip.cmake

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ if(NOT WITH_AMD_GPU)
33
endif()
44

55
include_directories("/opt/rocm/include")
6+
include_directories("/opt/rocm/hip/include")
7+
include_directories("/opt/rocm/miopen/include")
68
include_directories("/opt/rocm/hipblas/include")
79
include_directories("/opt/rocm/hiprand/include")
810
include_directories("/opt/rocm/rocrand/include")
@@ -11,20 +13,40 @@ include_directories("/opt/rocm/thrust")
1113

1214
list(APPEND EXTERNAL_LIBS "-L/opt/rocm/lib/ -lhip_hcc")
1315

14-
set(HIP_HCC_FLAGS "${HIP_HCC_FLAGS} -fPIC -DPADDLE_WITH_HIP -std=c++14" )
16+
set(HIP_HCC_FLAGS "${HIP_HCC_FLAGS} -fPIC -DPADDLE_WITH_HIP -std=c++11" )
1517

1618
if(WITH_DSO)
1719
set(HIP_HCC_FLAGS "${HIP_HCC_FLAGS} -DPADDLE_USE_DSO")
1820
endif(WITH_DSO)
1921

20-
if(WITH_DOUBLE)
21-
set(HIP_HCC_FLAGS "${HIP_HCC_FLAGS} -DPADDLE_TYPE_DOUBLE")
22-
endif(WITH_DOUBLE)
23-
2422
if(WITH_TESTING)
2523
set(HIP_HCC_FLAGS "${HIP_HCC_FLAGS} -DPADDLE_WITH_TESTING")
2624
endif(WITH_TESTING)
2725

26+
if(WITH_DISTRIBUTE)
27+
set(HIP_HCC_FLAGS "${HIP_HCC_FLAGS} -DPADDLE_WITH_DISTRIBUTE")
28+
endif(WITH_DISTRIBUTE)
29+
30+
if(WITH_GRPC)
31+
set(HIP_HCC_FLAGS "${HIP_HCC_FLAGS} -DPADDLE_WITH_GRPC")
32+
endif(WITH_GRPC)
33+
34+
if(NOT WITH_GOLANG)
35+
set(HIP_HCC_FLAGS "${HIP_HCC_FLAGS} -DPADDLE_WITHOUT_GOLANG")
36+
endif(NOT WITH_GOLANG)
37+
38+
if(WITH_MKLDNN)
39+
set(HIP_HCC_FLAGS "${HIP_HCC_FLAGS} -DPADDLE_WITH_MKLDNN")
40+
endif(WITH_MKLDNN)
41+
42+
set(HIP_HCC_FLAGS "${HIP_HCC_FLAGS} -DANY_IMPL_ANY_CAST_MOVEABLE")
43+
44+
if(NOT WITH_RDMA)
45+
set(HIP_HCC_FLAGS "${HIP_HCC_FLAGS} -DPADDLE_DISABLE_RDMA")
46+
endif(NOT WITH_RDMA)
47+
48+
49+
2850
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
2951
list(APPEND HIP_HCC_FLAGS ${CMAKE_CXX_FLAGS_DEBUG})
3052
elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")

paddle/fluid/pybind/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ if(WITH_PYTHON)
55
if(WITH_AMD_GPU)
66
hip_library(paddle_pybind SHARED
77
SRCS ${PYBIND_SRCS}
8-
DEPS ${PYBIND_DEPS}
9-
${GLOB_OP_LIB} ${GLOB_OPERATOR_DEPS})
8+
DEPS ARCHIVE_START ${PYBIND_DEPS}
9+
${GLOB_OP_LIB} ${GLOB_OPERATOR_DEPS} ARCHIVE_END)
1010
else()
1111
cc_library(paddle_pybind SHARED
1212
SRCS ${PYBIND_SRCS}

paddle/testing/paddle_gtest_main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ int main(int argc, char** argv) {
2828
for (int i = 0; i < argc; ++i) {
2929
new_argv.push_back(argv[i]);
3030
}
31-
#ifdef PADDLE_WITH_CUDA
31+
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
3232
new_argv.push_back(
3333
strdup("--tryfromenv=fraction_of_gpu_memory_to_use,allocator_strategy"));
3434
#else

0 commit comments

Comments
 (0)