Skip to content

Commit 6354af2

Browse files
onepickonepickonepick
authored
[DCU]Fix build error on rocm5.7 (PaddlePaddle#63738)
* [ROCM]Add patch for warprnnt/warpctc * add rocm_path to cmake_prefix_path * rm ambiguous apt because rocm has implemented Signed-off-by: jiajuku <[email protected]> * [ROCM] fix build error on rocm5.7 * change expression of Xcompiler since clang17 only support "-Xcompiler xxx" instead of "-Xcompiler=xxx" * clang17 check warning mre strictly Signed-off-by: jiajuku <[email protected]> * [ROCM] add dependent rocm lib Signed-off-by: jiajuku <[email protected]> * [ROCM]fix build warning rocm5 requires the include path: $ROCM_PATH/include Signed-off-by: jiajuku <[email protected]> * clean code style issue Signed-off-by: jiajuku <[email protected]> * Revert "[ROCM] fix build error on rocm5.7" This reverts commit 2b3bb69. * [ROCm]:support rocm 57 * change build option "-Xcompiler" expression, since clang17 reuqire "-Xcompiler xxx" instead of "-Xcompiler=xxx" * remove Werror from HIP_HCC_FLAGS since clang17 check more strictly. Signed-off-by: onepick <[email protected]> * Fix build error Xcompiler expression for clang17 Signed-off-by: onepick <[email protected]> * Fix build warning * sign-compare * bitwise-instead-of-logical * unknown-warning-option * unused-lambda-capture * unused-variable * unused-but-set-variable * reorder-ctor * deprecated-copy-with-user-provided-copy * unused-local-typedef * missing-braces * sometimes-uninitialized Signed-off-by: onepick <[email protected]> --------- Signed-off-by: jiajuku <[email protected]> Signed-off-by: onepick <[email protected]> Signed-off-by: onepick <[email protected]> Co-authored-by: onepick <[email protected]> Co-authored-by: onepick <[email protected]>
1 parent bedd212 commit 6354af2

File tree

17 files changed

+88
-18
lines changed

17 files changed

+88
-18
lines changed

cmake/external/warpctc.cmake

+11-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ if(NOT WIN32 AND WITH_GPU)
4949
endif()
5050
endif()
5151

52+
if(WITH_ROCM)
53+
set(WARPCTC_PATHCH_ROCM_COMMAND
54+
patch -p1 <
55+
${PADDLE_SOURCE_DIR}/patches/warpctc/CMakeLists.txt.rocm.patch && patch
56+
-p1 < ${PADDLE_SOURCE_DIR}/patches/warpctc/devicetypes.cuh.patch)
57+
endif()
58+
5259
set(WARPCTC_INCLUDE_DIR
5360
"${WARPCTC_INSTALL_DIR}/include"
5461
CACHE PATH "Warp-ctc Directory" FORCE)
@@ -100,7 +107,10 @@ ExternalProject_Add(
100107
SOURCE_DIR ${SOURCE_DIR}
101108
PREFIX ${WARPCTC_PREFIX_DIR}
102109
UPDATE_COMMAND ""
103-
PATCH_COMMAND ${WARPCTC_PATCH_COMMAND} ${WARPCTC_PATCH_CUDA_COMMAND}
110+
PATCH_COMMAND
111+
COMMAND ${WARPCTC_PATCH_COMMAND}
112+
COMMAND ${WARPCTC_PATCH_CUDA_COMMAND}
113+
COMMAND ${WARPCTC_PATHCH_ROCM_COMMAND}
104114
#BUILD_ALWAYS 1
105115
CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
106116
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}

cmake/external/warprnnt.cmake

+8-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ else()
3535
${SOURCE_DIR} <
3636
${PADDLE_SOURCE_DIR}/patches/warprnnt/CMakeLists.txt.cuda.patch)
3737
endif()
38-
38+
if(WITH_ROCM)
39+
set(WARPRNNT_PATCH_ROCM_COMMAND
40+
patch -p1 <
41+
${PADDLE_SOURCE_DIR}/patches/warprnnt/CMakeLists.txt.rocm.patch)
42+
endif()
3943
if(NOT WIN32 AND WITH_GPU)
4044
if(${CMAKE_CUDA_COMPILER_VERSION} LESS 12.0 AND ${CMAKE_CXX_COMPILER_VERSION}
4145
VERSION_GREATER 12.0)
@@ -99,7 +103,9 @@ ExternalProject_Add(
99103
SOURCE_DIR ${SOURCE_DIR}
100104
PREFIX ${WARPRNNT_PREFIX_DIR}
101105
UPDATE_COMMAND ""
102-
PATCH_COMMAND ${WARPCTC_PATCH_CUDA_COMMAND}
106+
PATCH_COMMAND
107+
COMMAND ${WARPCTC_PATCH_CUDA_COMMAND}
108+
COMMAND ${WARPRNNT_PATCH_ROCM_COMMAND}
103109
#BUILD_ALWAYS 1
104110
CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
105111
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}

cmake/flags.cmake

+8-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,13 @@ macro(safe_set_nvflag flag_name)
9292
check_c_compiler_flag(${flag_name} C_COMPILER_SUPPORT_FLAG_${safe_name})
9393
set(safe_name C_COMPILER_SUPPORT_FLAG_${safe_name})
9494
if(${safe_name})
95-
set(SAFE_GPU_COMMON_FLAGS
96-
"${SAFE_GPU_COMMON_FLAGS} -Xcompiler=\"${flag_name}\"")
95+
if(WITH_ROCM)
96+
set(SAFE_GPU_COMMON_FLAGS
97+
"${SAFE_GPU_COMMON_FLAGS} -Xcompiler \"${flag_name}\"")
98+
else()
99+
set(SAFE_GPU_COMMON_FLAGS
100+
"${SAFE_GPU_COMMON_FLAGS} -Xcompiler=\"${flag_name}\"")
101+
endif()
97102
endif()
98103
endmacro()
99104

@@ -279,6 +284,7 @@ endif()
279284

280285
# Disable -Werror, otherwise the compile will fail for rocblas_gemm_ex
281286
if(WITH_ROCM)
287+
string(REPLACE "-Werror" "-Wno-error" HIP_HIPCC_FLAGS ${HIP_HIPCC_FLAGS})
282288
string(REPLACE "-Werror" "-Wno-error" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
283289
string(REPLACE "-Werror" "-Wno-error" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
284290
endif()

cmake/hip.cmake

+12
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ else()
2424
CACHE PATH "Path to which clang has been installed")
2525
endif()
2626
set(CMAKE_MODULE_PATH "${HIP_PATH}/cmake" ${CMAKE_MODULE_PATH})
27+
set(CMAKE_PREFIX_PATH "${ROCM_PATH}" ${CMAKE_PREFIX_PATH})
2728

2829
find_package(HIP REQUIRED)
2930
include_directories(${ROCM_PATH}/include)
@@ -123,6 +124,17 @@ list(APPEND HIP_CXX_FLAGS -Wno-switch)
123124
list(APPEND HIP_CXX_FLAGS -Wno-literal-conversion)
124125
list(APPEND HIP_CXX_FLAGS -Wno-constant-conversion)
125126
list(APPEND HIP_CXX_FLAGS -Wno-defaulted-function-deleted)
127+
list(APPEND HIP_CXX_FLAGS -Wno-sign-compare)
128+
list(APPEND HIP_CXX_FLAGS -Wno-bitwise-instead-of-logical)
129+
list(APPEND HIP_CXX_FLAGS -Wno-unknown-warning-option)
130+
list(APPEND HIP_CXX_FLAGS -Wno-unused-lambda-capture)
131+
list(APPEND HIP_CXX_FLAGS -Wno-unused-variable)
132+
list(APPEND HIP_CXX_FLAGS -Wno-unused-but-set-variable)
133+
list(APPEND HIP_CXX_FLAGS -Wno-reorder-ctor)
134+
list(APPEND HIP_CXX_FLAGS -Wno-deprecated-copy-with-user-provided-copy)
135+
list(APPEND HIP_CXX_FLAGS -Wno-unused-local-typedef)
136+
list(APPEND HIP_CXX_FLAGS -Wno-missing-braces)
137+
list(APPEND HIP_CXX_FLAGS -Wno-sometimes-uninitialized)
126138

127139
if(WITH_CINN)
128140
list(APPEND HIP_CXX_FLAGS -std=c++14)

paddle/fluid/framework/var_type_traits.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#ifdef PADDLE_WITH_HIP
3838
#include <miopen/miopen.h>
3939
#ifdef PADDLE_WITH_RCCL
40-
#include <rccl.h>
40+
#include <rccl/rccl.h>
4141
#endif
4242
#endif
4343

paddle/fluid/memory/allocation/CMakeLists.txt

+5-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ if(WITH_GPU OR WITH_ROCM)
3333
list(APPEND ALLOCATOR_DEPS cuda_device_guard gpu_info dynload_cuda)
3434
endif()
3535

36-
if(WITH_GPU)
37-
list(APPEND ALLOCATOR_DEPS phi common)
36+
if(WITH_ROCM)
37+
list(APPEND ALLOCATOR_DEPS ${ROCM_HIPRTC_LIB})
3838
endif()
3939

40+
if(WITH_GPU OR WITH_ROCM)
41+
list(APPEND ALLOCATOR_DEPS phi common)
42+
endif()
4043
if(CUDA_VERSION VERSION_GREATER_EQUAL 10.2)
4144
list(APPEND ALLOCATOR_SRCS cuda_virtual_mem_allocator.cc)
4245
endif()

paddle/fluid/platform/dynload/rccl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
1313
limitations under the License. */
1414
#pragma once
1515

16-
#include <rccl.h>
16+
#include <rccl/rccl.h>
1717

1818
#include <mutex> // NOLINT
1919

paddle/fluid/platform/dynload/rocblas.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ limitations under the License. */
1515
#pragma once
1616

1717
#include <hip/hip_runtime.h>
18-
#include <rocblas.h>
18+
#include <rocblas/rocblas.h>
1919

2020
#include <mutex> // NOLINT
2121
#include <type_traits>

paddle/fluid/platform/enforce.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ limitations under the License. */
3939
#endif // PADDLE_WITH_CUDA
4040

4141
#ifdef PADDLE_WITH_HIP
42-
#include <hiprand.h>
42+
#include <hiprand/hiprand.h>
4343
#include <miopen/miopen.h>
44-
#include <rocblas.h>
44+
#include <rocblas/rocblas.h>
4545
#include <thrust/system/hip/error.h>
4646
#include <thrust/system_error.h> // NOLINT
4747
#endif

paddle/phi/backends/dynload/hipfft.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
1313
limitations under the License. */
1414
#pragma once
1515
#ifdef PADDLE_WITH_HIP
16-
#include <hipfft.h>
16+
#include <hipfft/hipfft.h>
1717

1818
#include <mutex> // NOLINT
1919

paddle/phi/backends/dynload/hiprand.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
1313
limitations under the License. */
1414
#pragma once
1515

16-
#include <hiprand.h>
16+
#include <hiprand/hiprand.h>
1717

1818
#include <mutex> // NOLINT
1919

paddle/phi/backends/dynload/rccl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
1313
limitations under the License. */
1414
#pragma once
1515

16-
#include <rccl.h>
16+
#include <rccl/rccl.h>
1717

1818
#include <mutex> // NOLINT
1919

paddle/phi/backends/dynload/rocblas.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ limitations under the License. */
1515
#pragma once
1616

1717
#include <hip/hip_runtime.h>
18-
#include <rocblas.h>
18+
#include <rocblas/rocblas.h>
1919

2020
#include <mutex> // NOLINT
2121
#include <type_traits>

paddle/phi/core/enforce.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ limitations under the License. */
2424
#endif // PADDLE_WITH_CUDA
2525

2626
#ifdef PADDLE_WITH_HIP
27-
#include <hiprand.h>
27+
#include <hiprand/hiprand.h>
2828
#include <miopen/miopen.h>
29-
#include <rocblas.h>
29+
#include <rocblas/rocblas.h>
3030
#include <thrust/system/hip/error.h>
3131
#include <thrust/system_error.h> // NOLINT
3232
#endif
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--- a/CMakeLists.txt
2+
+++ b/CMakeLists.txt
3+
@@ -24,6 +24,7 @@ option(BUILD_SHARED "build warp-ctc shared library." ON)
4+
option(WITH_ROCM "Compile PaddlePaddle with ROCM platform" OFF)
5+
6+
if(WITH_ROCM)
7+
+ list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH})
8+
add_definitions(-DWARPCTC_WITH_HIP)
9+
include(hip)
10+
endif(WITH_ROCM)

patches/warpctc/devicetypes.cuh.patch

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--- a/include/contrib/moderngpu/include/device/devicetypes.cuh
2+
+++ b/include/contrib/moderngpu/include/device/devicetypes.cuh
3+
@@ -207,10 +207,6 @@ MGPU_HOST_DEVICE int2& operator+=(int2& a, int2 b) {
4+
MGPU_HOST_DEVICE int2 operator*(int2 a, int2 b) {
5+
return make_int2(a.x * b.x, a.y * b.y);
6+
}
7+
-MGPU_HOST_DEVICE int2& operator*=(int2& a, int2 b) {
8+
- a = a * b;
9+
- return a;
10+
-}
11+
12+
template<typename T>
13+
MGPU_HOST_DEVICE T max(T a, T b) {
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--- a/CMakeLists.txt
2+
+++ b/CMakeLists.txt
3+
@@ -39,6 +39,7 @@ option(BUILD_SHARED "build warp-rnnt shared library." ON)
4+
option(WITH_ROCM "Compile PaddlePaddle with ROCM platform" OFF)
5+
6+
if(WITH_ROCM)
7+
+ list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH})
8+
add_definitions(-DWARPRNNT_WITH_HIP)
9+
include(hip)
10+
endif(WITH_ROCM)

0 commit comments

Comments
 (0)