Files
rocm-systems/catch/unit/cooperativeGrps/cooperative_groups_common.hh
T
nives-vukovic 22f3d9034b EXSWHTEC-256 - Implement tests for grid_group APIs (#153)
- Migrate basic Cooperative Groups tests and integrate to catch
- Refactor basic Cooperative Groups tests
- Rename tiled partition related files and fix minor bug
- Add LaunchCooperativeKernal and LaunchCooperativeKernelMultiDevice tests
- Refactor hipCGThreadBlockTileType to use common function
- Fix updated file not added during merge
- Add coalesced_group type tests
- Add coalesced_group shuffle_up and shuffle_down tests
- Add coalesced_group shuffle tests - test fails
- Implement common code for cooperative group tests
- Fixed compilation errror in cooperative_groups_common.hh
- Implement busy wait device function
- Reimplement tests for grid_group APIs
- Add tests for grid_group member and non-member APIs
- Refactor existing test for grid_group sync testing
- Add thread and block dimensions generators
- Add check of grid and block dimensions
- Modify doxygen comments
- Move cpu_grid.h and supporting functions to catch/include
- Use warp_size from properties in grid/block dims generators
- Fix condition for warp size 32 on AMD
- Fix cpu_grid.h for warp function tests
- Add missing include into cpu_grid.h
- Code cleanup
- Fix doxygen comments
- Add missing include in utils header
2023-07-18 12:55:00 +05:30

71 lines
2.6 KiB
C++

/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#pragma once
#include <hip_test_common.hh>
#include <hip/hip_cooperative_groups.h>
namespace {
#if (!__GFX8__ && !__GFX9__) || HT_NVIDIA
constexpr size_t kWarpSize = 32;
#else
constexpr size_t kWarpSize = 64;
#endif
} // namespace
constexpr int MaxGPUs = 8;
__device__ inline unsigned int thread_rank_in_grid() {
const auto block_size = blockDim.x * blockDim.y * blockDim.z;
const auto block_rank_in_grid = (blockIdx.z * gridDim.y + blockIdx.y) * gridDim.x + blockIdx.x;
const auto thread_rank_in_block =
(threadIdx.z * blockDim.y + threadIdx.y) * blockDim.x + threadIdx.x;
return block_rank_in_grid * block_size + thread_rank_in_block;
}
static __device__ void busy_wait(unsigned long long wait_period) {
unsigned long long time_diff = 0;
unsigned long long last_clock = clock64();
while (time_diff < wait_period) {
unsigned long long cur_clock = clock64();
if (cur_clock > last_clock) {
time_diff += (cur_clock - last_clock);
}
last_clock = cur_clock;
}
}
template <class T> bool CheckDimensions(unsigned int device, T kernel, dim3 blocks, dim3 threads) {
hipDeviceProp_t props;
int max_blocks_per_sm = 0;
int num_sm = 0;
HIP_CHECK(hipSetDevice(device));
HIP_CHECK(hipOccupancyMaxActiveBlocksPerMultiprocessor(&max_blocks_per_sm, kernel,
threads.x * threads.y * threads.z, 0));
HIP_CHECK(hipGetDeviceProperties(&props, device));
num_sm = props.multiProcessorCount;
if ((blocks.x * blocks.y * blocks.z) > max_blocks_per_sm * num_sm) {
return false;
}
return true;
}