2024-09-03 14:19:01 -07:00
|
|
|
/******************************************************************************
|
2025-04-15 15:37:53 -05:00
|
|
|
* Copyright (c) Advanced Micro Devices, Inc. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
2024-09-03 14:19:01 -07:00
|
|
|
*
|
|
|
|
|
* 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,
|
2025-04-15 15:37:53 -05:00
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
2024-09-03 14:19:01 -07:00
|
|
|
* 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.
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
2025-03-18 14:39:57 -05:00
|
|
|
#include "wavefront_primitives.hpp"
|
2024-09-03 14:19:01 -07:00
|
|
|
|
2024-11-25 14:12:15 -06:00
|
|
|
#include <rocshmem/rocshmem.hpp>
|
2024-09-03 14:19:01 -07:00
|
|
|
|
2024-10-14 23:49:40 +00:00
|
|
|
#include <numeric>
|
|
|
|
|
|
2024-09-03 14:19:01 -07:00
|
|
|
using namespace rocshmem;
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
2024-10-14 23:49:40 +00:00
|
|
|
* DEVICE TEST KERNEL
|
2024-09-03 14:19:01 -07:00
|
|
|
*****************************************************************************/
|
2025-03-18 14:39:57 -05:00
|
|
|
__global__ void WaveFrontPrimitiveTest(int loop, int skip,
|
2025-02-17 06:18:46 +00:00
|
|
|
long long int *start_time,
|
2025-03-18 14:39:57 -05:00
|
|
|
long long int *end_time, char *source,
|
2025-07-03 13:26:54 -05:00
|
|
|
char *dest, size_t size, TestType type,
|
2025-03-18 14:39:57 -05:00
|
|
|
ShmemContextType ctx_type,
|
|
|
|
|
int wf_size) {
|
2024-11-25 14:12:15 -06:00
|
|
|
__shared__ rocshmem_ctx_t ctx;
|
2025-02-17 06:18:46 +00:00
|
|
|
int wg_id = get_flat_grid_id();
|
|
|
|
|
|
2024-11-25 14:12:15 -06:00
|
|
|
rocshmem_wg_ctx_create(ctx_type, &ctx);
|
2024-09-03 14:19:01 -07:00
|
|
|
|
2025-03-18 14:39:57 -05:00
|
|
|
// Calculate start index for each wavefront
|
2024-09-07 16:06:36 -07:00
|
|
|
int wf_id = get_flat_block_id() / wf_size;
|
2025-03-18 14:39:57 -05:00
|
|
|
int wg_offset = wg_id * ((get_flat_block_size() - 1 ) / wf_size + 1);
|
|
|
|
|
int idx = wf_id + wg_offset;
|
2025-07-03 13:26:54 -05:00
|
|
|
size_t offset = size * idx;
|
2025-03-18 14:39:57 -05:00
|
|
|
source += offset;
|
|
|
|
|
dest += offset;
|
2024-09-03 14:19:01 -07:00
|
|
|
|
|
|
|
|
for (int i = 0; i < loop + skip; i++) {
|
2025-02-17 06:18:46 +00:00
|
|
|
if (i == skip) {
|
2025-03-18 14:39:57 -05:00
|
|
|
// Ensures all RMA calls from the skip loops are completed
|
2025-11-05 12:01:14 -05:00
|
|
|
rocshmem_ctx_quiet(ctx);
|
2025-03-18 14:39:57 -05:00
|
|
|
__syncthreads();
|
2025-11-05 12:01:14 -05:00
|
|
|
if (is_thread_zero_in_wave()) {
|
|
|
|
|
start_time[idx] = wall_clock64();
|
|
|
|
|
}
|
2025-02-17 06:18:46 +00:00
|
|
|
}
|
2024-09-03 14:19:01 -07:00
|
|
|
switch (type) {
|
|
|
|
|
case WAVEGetTestType:
|
2025-03-18 14:39:57 -05:00
|
|
|
rocshmem_ctx_getmem_wave(ctx, dest, source, size, 1);
|
2024-09-03 14:19:01 -07:00
|
|
|
break;
|
|
|
|
|
case WAVEGetNBITestType:
|
2025-03-18 14:39:57 -05:00
|
|
|
rocshmem_ctx_getmem_nbi_wave(ctx, dest, source, size, 1);
|
2024-09-03 14:19:01 -07:00
|
|
|
break;
|
|
|
|
|
case WAVEPutTestType:
|
2025-03-18 14:39:57 -05:00
|
|
|
rocshmem_ctx_putmem_wave(ctx, dest, source, size, 1);
|
2024-09-03 14:19:01 -07:00
|
|
|
break;
|
|
|
|
|
case WAVEPutNBITestType:
|
2025-03-18 14:39:57 -05:00
|
|
|
rocshmem_ctx_putmem_nbi_wave(ctx, dest, source, size, 1);
|
2024-09-03 14:19:01 -07:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-05 12:01:14 -05:00
|
|
|
rocshmem_ctx_quiet(ctx);
|
2025-03-18 14:39:57 -05:00
|
|
|
if (is_thread_zero_in_wave()) {
|
|
|
|
|
end_time[idx] = wall_clock64();
|
2024-09-03 14:19:01 -07:00
|
|
|
}
|
|
|
|
|
|
2024-11-25 14:12:15 -06:00
|
|
|
rocshmem_wg_ctx_destroy(&ctx);
|
2024-09-03 14:19:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
|
* HOST TESTER CLASS METHODS
|
|
|
|
|
*****************************************************************************/
|
2025-03-18 14:39:57 -05:00
|
|
|
WaveFrontPrimitiveTester::WaveFrontPrimitiveTester(TesterArguments args)
|
2024-09-03 14:19:01 -07:00
|
|
|
: Tester(args) {
|
2025-03-18 14:39:57 -05:00
|
|
|
size_t buff_size = args.max_msg_size * args.num_wgs * num_warps;
|
|
|
|
|
source = (char *)rocshmem_malloc(buff_size);
|
|
|
|
|
dest = (char *)rocshmem_malloc(buff_size);
|
|
|
|
|
|
|
|
|
|
if (source == nullptr || dest == nullptr) {
|
|
|
|
|
std::cerr << "Error allocating memory from symmetric heap" << std::endl;
|
|
|
|
|
std::cerr << "source: " << source << ", dest: " << dest << std::endl;
|
|
|
|
|
if (source) {
|
|
|
|
|
rocshmem_free(source);
|
|
|
|
|
}
|
|
|
|
|
if (dest) {
|
|
|
|
|
rocshmem_free(dest);
|
|
|
|
|
}
|
|
|
|
|
rocshmem_global_exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(size_t i = 0; i < buff_size; i++) {
|
|
|
|
|
source[i] = static_cast<char>('a' + i % 26);
|
|
|
|
|
}
|
2024-09-03 14:19:01 -07:00
|
|
|
}
|
|
|
|
|
|
2025-03-18 14:39:57 -05:00
|
|
|
WaveFrontPrimitiveTester::~WaveFrontPrimitiveTester() {
|
|
|
|
|
rocshmem_free(source);
|
|
|
|
|
rocshmem_free(dest);
|
2024-09-03 14:19:01 -07:00
|
|
|
}
|
|
|
|
|
|
2025-07-03 13:26:54 -05:00
|
|
|
void WaveFrontPrimitiveTester::resetBuffers(size_t size) {
|
2025-03-18 14:39:57 -05:00
|
|
|
size_t buff_size = size * args.num_wgs * num_warps;
|
|
|
|
|
memset(dest, '1', buff_size);
|
2024-09-03 14:19:01 -07:00
|
|
|
}
|
|
|
|
|
|
2025-03-18 14:39:57 -05:00
|
|
|
void WaveFrontPrimitiveTester::launchKernel(dim3 gridSize, dim3 blockSize,
|
2025-07-03 13:26:54 -05:00
|
|
|
int loop, size_t size) {
|
2024-09-03 14:19:01 -07:00
|
|
|
size_t shared_bytes = 0;
|
|
|
|
|
|
2025-03-18 14:39:57 -05:00
|
|
|
hipLaunchKernelGGL(WaveFrontPrimitiveTest, gridSize, blockSize, shared_bytes,
|
2025-02-17 06:18:46 +00:00
|
|
|
stream, loop, args.skip, start_time, end_time,
|
2025-03-18 14:39:57 -05:00
|
|
|
source, dest, size, _type, _shmem_context,
|
2025-02-17 06:18:46 +00:00
|
|
|
wf_size);
|
2024-09-03 14:19:01 -07:00
|
|
|
|
2024-10-14 23:49:40 +00:00
|
|
|
num_msgs = (loop + args.skip) * gridSize.x * num_warps;
|
|
|
|
|
num_timed_msgs = loop * gridSize.x * num_warps;
|
2024-09-03 14:19:01 -07:00
|
|
|
}
|
|
|
|
|
|
2025-07-03 13:26:54 -05:00
|
|
|
void WaveFrontPrimitiveTester::verifyResults(size_t size) {
|
2024-09-03 14:19:01 -07:00
|
|
|
int check_id = (_type == WAVEGetTestType || _type == WAVEGetNBITestType)
|
|
|
|
|
? 0
|
|
|
|
|
: 1;
|
|
|
|
|
|
|
|
|
|
if (args.myid == check_id) {
|
2025-03-18 14:39:57 -05:00
|
|
|
size_t buff_size = size * args.num_wgs * num_warps;
|
2025-04-28 16:06:05 -04:00
|
|
|
size_t verify_wg_size = std::min((size_t) 1024, buff_size);
|
|
|
|
|
size_t verify_num_wgs = buff_size / verify_wg_size;
|
|
|
|
|
|
|
|
|
|
hipLaunchKernelGGL(verify_results_kernel_char, verify_num_wgs, verify_wg_size, 0, stream,
|
|
|
|
|
source, dest, buff_size, verification_error);
|
|
|
|
|
CHECK_HIP(hipStreamSynchronize(stream));
|
|
|
|
|
|
|
|
|
|
if (*verification_error) {
|
|
|
|
|
for (size_t i = 0; i < buff_size; i++) {
|
|
|
|
|
if (dest[i] != source[i]) {
|
|
|
|
|
std::cerr << "Data validation error at idx " << i << std::endl;
|
|
|
|
|
std::cerr << " Got " << dest[i] << ", Expected "
|
|
|
|
|
<< source[i] << std::endl;
|
|
|
|
|
exit(-1);
|
|
|
|
|
}
|
2024-09-03 14:19:01 -07:00
|
|
|
}
|
2025-04-28 16:06:05 -04:00
|
|
|
*verification_error = false;
|
2024-09-03 14:19:01 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|