Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Radeon support by controlling wave size #1729

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ endif()

if(RAJA_ENABLE_HIP)
message(STATUS "HIP version: ${hip_VERSION}")
set(RAJA_DEFAULT_WAVESIZE "64" CACHE STRING "Default wave size for GPU architecture. E.g. MI200/MI300 this is 64.")
if("${hip_VERSION}" VERSION_LESS "3.5")
message(FATAL_ERROR "Trying to use HIP/ROCm version ${hip_VERSION}. RAJA requires HIP/ROCm version 3.5 or newer. ")
endif()
Expand Down
2 changes: 2 additions & 0 deletions include/RAJA/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ static_assert(RAJA_HAS_SOME_CXX14,
#cmakedefine RAJA_ENABLE_NV_TOOLS_EXT
#cmakedefine RAJA_ENABLE_ROCTX

#cmakedefine RAJA_DEFAULT_WAVESIZE @RAJA_DEFAULT_WAVESIZE@

/*!
******************************************************************************
*
Expand Down
9 changes: 1 addition & 8 deletions include/RAJA/pattern/kernel/InitLocalMem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,16 @@ struct StatementExecutor<statement::InitLocalMem<RAJA::cpu_tile_mem,camp::idx_se
using varType = typename camp::tuple_element_t<Pos, typename camp::decay<Data>::param_tuple_t>::value_type;

// Initialize memory
#ifdef RAJA_COMPILER_MSVC
// MSVC doesn't like taking a pointer to stack allocated data?!?!
varType *ptr = new varType[camp::get<Pos>(data.param_tuple).size()];
camp::get<Pos>(data.param_tuple).set_data(ptr);
#else
varType Array[camp::get<Pos>(data.param_tuple).size()];
camp::get<Pos>(data.param_tuple).set_data(&Array[0]);
#endif


// Initialize others and execute
exec_expanded<others...>(data);

// Cleanup and return
camp::get<Pos>(data.param_tuple).set_data(nullptr);
#ifdef RAJA_COMPILER_MSVC
delete[] ptr;
#endif
}


Expand Down
5 changes: 3 additions & 2 deletions include/RAJA/policy/hip/policy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,9 @@ struct DeviceConstants
// values for HIP warp size and max block size.
//
#if defined(__HIP_PLATFORM_AMD__)
constexpr DeviceConstants device_constants(64, 1024, 64); // MI300A
// constexpr DeviceConstants device_constants(64, 1024, 128); // MI250X
constexpr DeviceConstants device_constants(RAJA_DEFAULT_WAVESIZE, 1024, 64); // MI300A
// constexpr DeviceConstants device_constants(RAJA_DEFAULT_WAVESIZE, 1024, 128); // MI250X

#elif defined(__HIP_PLATFORM_NVIDIA__)
constexpr DeviceConstants device_constants(32, 1024, 32); // V100
#endif
Expand Down
9 changes: 5 additions & 4 deletions include/RAJA/policy/tensor/arch/hip/hip_wave.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace expt

public:

static constexpr int s_num_elem = 64;
static constexpr int s_num_elem = policy::hip::device_constants.WARP_SIZE;

/*!
* @brief Default constructor, zeros register contents
Expand Down Expand Up @@ -780,8 +780,8 @@ namespace expt

// Third: mask off everything but output_segment
// this is because all output segments are valid at this point
// (5-segbits), the 5 is since the warp-width is 32 == 1<<5
int our_output_segment = get_lane()>>(6-segbits);
const int log2_warp_size = 32-1-__builtin_clz(warpSize);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By using warpSize it appear that this is making a runtime value now instead of a compile time value, do we need to worry about the performance implications of this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will add a few instructions and possibly a sgpr load. It probably won't be noticeable, but we can move the log2_warp_size as a constexpr member of the DeviceConstants. Or just wrap these two places in ifdefs. If we keep it dynamic then it should work for Nvidia/other as well - I'm not sure how important that is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we're already relying on getting the right warpSize at configure time I think we should keep this compile time if possible. There is a constexpr RAJA::log2 that we can use instead of clz here to keep it constexpr.

int our_output_segment = get_lane()>>(log2_warp_size-segbits);
bool in_output_segment = our_output_segment == output_segment;
if(!in_output_segment){
result.get_raw_value() = 0;
Expand Down Expand Up @@ -828,8 +828,9 @@ namespace expt

// First: tree reduce values within each segment
element_type x = m_value;
const int log2_warp_size = 32-1-__builtin_clz(warpSize);
RAJA_UNROLL
for(int i = 0;i < 6-segbits; ++ i){
for(int i = 0;i < log2_warp_size-segbits; ++ i){

// tree shuffle
int delta = s_num_elem >> (i+1);
Expand Down
3 changes: 2 additions & 1 deletion include/RAJA/policy/tensor/arch/hip/traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ namespace expt {
struct RegisterTraits<RAJA::expt::hip_wave_register, T>{
using element_type = T;
using register_policy = RAJA::expt::hip_wave_register;
static constexpr camp::idx_t s_num_elem = 64;
static constexpr camp::idx_t s_num_elem = policy::hip::device_constants.WARP_SIZE;

static constexpr camp::idx_t s_num_bits = sizeof(T) * s_num_elem;
using int_element_type = int32_t;
};
Expand Down
4 changes: 3 additions & 1 deletion test/include/RAJA_test-tensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ struct TensorTestHelper<RAJA::expt::hip_wave_register>
void exec(BODY const &body){
hipDeviceSynchronize();

RAJA::forall<RAJA::hip_exec<64>>(RAJA::RangeSegment(0,64),
constexpr int warp_size = RAJA::policy::hip::device_constants.WARP_SIZE;

RAJA::forall<RAJA::hip_exec<warp_size>>(RAJA::RangeSegment(0,warp_size),
[=] RAJA_HOST_DEVICE (int ){
body();
});
Expand Down
Loading