Skip to content

Commit

Permalink
[DCU] fix dcu compile failure (#62573)
Browse files Browse the repository at this point in the history
  • Loading branch information
qili93 committed Mar 11, 2024
1 parent fbf852d commit d527fb5
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 10 deletions.
10 changes: 4 additions & 6 deletions cmake/generic.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -758,12 +758,6 @@ function(hip_library TARGET_NAME)
cmake_parse_arguments(hip_library "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN})
if(hip_library_SRCS)
# FindHIP.cmake defined hip_add_library, HIP_SOURCE_PROPERTY_FORMAT is requried if no .cu files found
if(NOT (${CMAKE_CURRENT_SOURCE_DIR} MATCHES ".*/operators"
OR ${CMAKE_CURRENT_SOURCE_DIR} MATCHES ".*/phi/kernels"))
set_source_files_properties(${hip_library_SRCS}
PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1)
endif()
if(hip_library_SHARED OR hip_library_shared) # build *.so
hip_add_library(${TARGET_NAME} SHARED ${hip_library_SRCS})
else()
Expand All @@ -777,6 +771,10 @@ function(hip_library TARGET_NAME)
endif()
# cpplint code style
foreach(source_file ${hip_library_SRCS})
if(NOT ${source_file} MATCHES "\\.cu$")
set_source_files_properties(${source_file}
PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1)
endif()
string(REGEX REPLACE "\\.[^.]*$" "" source ${source_file})
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${source}.h)
list(APPEND hip_library_HEADERS
Expand Down
7 changes: 5 additions & 2 deletions paddle/phi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,11 @@ if(WITH_GPU)
SRCS ${PHI_SRCS}
DEPS ${PHI_DEPS})
elseif(WITH_ROCM)
hip_add_library(phi ${PHI_BUILD_TYPE} ${PHI_SRCS})
target_link_libraries(phi ${PHI_DEPS})
hip_library(
phi ${PHI_BUILD_TYPE}
SRCS ${PHI_SRCS}
DEPS ${PHI_DEPS})

elseif(WITH_XPU_KP)
xpu_library(
phi ${PHI_BUILD_TYPE}
Expand Down
2 changes: 1 addition & 1 deletion paddle/phi/core/visit_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ namespace phi {
"`"); \
} \
}()
#if defined(PADDLE_WITH_XPU)
#if defined(PADDLE_WITH_XPU) || defined(PADDLE_WITH_HIP)
#define PD_VISIT_ALL_TYPES(TYPE, NAME, ...) \
[&] { \
const auto& __dtype__ = TYPE; \
Expand Down
26 changes: 26 additions & 0 deletions paddle/phi/kernels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,32 @@ if(NOT WITH_CUDNN_FRONTEND)
"fusion/gpu/fused_dconv_drelu_dbn_kernel.cu")
endif()

# Note(qili93): remove kernels not supported on DCU yet
if(WITH_ROCM)
list(
REMOVE_ITEM
kernel_cu
"gpu/affine_grid_grad_kernel.cu"
"gpu/apply_per_channel_scale_kernel.cu"
"gpu/cholesky_solve_kernel.cu"
"gpu/eigh_kernel.cu"
"gpu/eigvalsh_kernel.cu"
"gpu/lstsq_kernel.cu"
"gpu/lu_kernel.cu"
"gpu/matrix_rank_kernel.cu"
"gpu/matrix_rank_tol_kernel.cu"
"gpu/multiclass_nms3_kernel.cu"
"gpu/put_along_axis_grad_kernel.cu"
"gpu/put_along_axis_kernel.cu"
"gpu/qr_kernel.cu"
"gpu/svd_kernel.cu"
"gpudnn/mha_cudnn_frontend.cu"
"fusion/gpu/block_multi_head_attention_kernel.cu"
"fusion/gpu/fused_bn_add_activation_grad_kernel.cu"
"fusion/gpu/fused_bn_add_activation_kernel.cu"
"fusion/gpu/fusion_transpose_flatten_concat_kernel.cu")
endif()

set(cc_search_pattern
"*.cc"
"cpu/*.cc"
Expand Down
5 changes: 5 additions & 0 deletions paddle/phi/kernels/funcs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ if(WITH_GPU OR WITH_ROCM)
"*.cu")
endif()

# Note(qili93): remove kernels not supported on DCU yet
if(WITH_ROCM)
list(REMOVE_ITEM func_cu_srcs "weight_only_gemv.cu")
endif()

collect_srcs(kernels_srcs SRCS ${func_cc_srcs} ${func_cu_srcs})
2 changes: 1 addition & 1 deletion paddle/phi/kernels/gpu/top_p_sampling_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ __device__ __forceinline__ void BlockReduce(Pair<T> shared_max[],
if (*beam >= MaxLength) break;
} else {
#ifdef PADDLE_WITH_HIP
uint64 mask = 0;
unsigned mask = 0u;
mask = __ballot(true);
if (tid_max / WARP_SIZE == wid) {
if (__shfl_down(*beam, tid_max % WARP_SIZE, WARP_SIZE) == MaxLength)
Expand Down
5 changes: 5 additions & 0 deletions paddle/phi/kernels/gpu/unique_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@
#include <iostream>
#include <vector>

#ifdef PADDLE_WITH_CUDA
#include "cub/cub.cuh"
#else
#include <hipcub/hipcub.hpp>
namespace cub = hipcub;
#endif
#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/common/memory_utils.h"
#include "paddle/phi/core/kernel_registry.h"
Expand Down

0 comments on commit d527fb5

Please sign in to comment.