CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
107 lines
3.0 KiB
C++
107 lines
3.0 KiB
C++
/*
|
|
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
#include <hip_test_common.hh>
|
|
#include <hip_test_kernels.hh>
|
|
#include <hip_test_checkers.hh>
|
|
|
|
// Test case to validate atomicInc and atomicDec functions.
|
|
// if TestToRun=1, then atomicInc function will be tested and validated
|
|
// if TestToRun=2, then atomicDec function will be tested and validated.
|
|
|
|
|
|
// kernel function for atomicInc
|
|
static __global__ void AtomicCheckInc(int* g_ptr) {
|
|
atomicInc(reinterpret_cast<unsigned int*>(&g_ptr[0]), 17);
|
|
}
|
|
|
|
// kernel function for atomicDec
|
|
static __global__ void AtomicCheckDec(int* g_ptr) {
|
|
atomicDec(reinterpret_cast<unsigned int*>(&g_ptr[0]), 25);
|
|
}
|
|
|
|
// verify results for atomicInc
|
|
static int verifyResultInc(int value) {
|
|
int limit = 17;
|
|
value = (value >= limit) ? 0 : value + 1;
|
|
return value;
|
|
}
|
|
|
|
// verify results for atomicDec
|
|
static int verifyResultDec(int value) {
|
|
int limit = 25;
|
|
value = ((value == 0) || (value > limit)) ? limit : value - 1;
|
|
return value;
|
|
}
|
|
|
|
// common fuction to launch atomic functions kernel.
|
|
static void launchAtomicFunction(int* Hptr, int val, int TestToRun) {
|
|
unsigned int memSize = sizeof(int) * 1;
|
|
int* dptr{nullptr};
|
|
// allocate device memory
|
|
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&dptr), memSize));
|
|
// copy host memory to device
|
|
HIP_CHECK(hipMemcpy(dptr, Hptr, memSize, hipMemcpyHostToDevice));
|
|
// launch kernel function
|
|
if (TestToRun == 1) {
|
|
AtomicCheckInc<<<1, 1>>>(dptr);
|
|
} else if (TestToRun == 2) {
|
|
AtomicCheckDec<<<1, 1>>>(dptr);
|
|
}
|
|
// copy back from device to host
|
|
HIP_CHECK(hipMemcpy(Hptr, dptr, memSize, hipMemcpyDeviceToHost));
|
|
// verify the results.
|
|
if (TestToRun == 1) {
|
|
int result = verifyResultInc(val);
|
|
REQUIRE(result == Hptr[0]);
|
|
} else if (TestToRun == 2) {
|
|
int result = verifyResultDec(val);
|
|
REQUIRE(result == Hptr[0]);
|
|
}
|
|
// Cleanup memory
|
|
HIP_CHECK(hipFree(dptr));
|
|
}
|
|
|
|
HIP_TEST_CASE(Unit_AtomicFunctions_Inc) {
|
|
int* Hptr{nullptr};
|
|
int val;
|
|
// Allocate Host memory
|
|
Hptr = reinterpret_cast<int*>(malloc(sizeof(int)));
|
|
SECTION("Test case when value is lesser than limit") {
|
|
val = Hptr[0] = 10;
|
|
launchAtomicFunction(Hptr, val, 1);
|
|
}
|
|
SECTION("Test case when value is greater than limit") {
|
|
val = Hptr[0] = 20;
|
|
launchAtomicFunction(Hptr, val, 1);
|
|
}
|
|
SECTION("Test case when value is equal to the limit") {
|
|
val = Hptr[0] = 17;
|
|
launchAtomicFunction(Hptr, val, 1);
|
|
}
|
|
free(Hptr);
|
|
}
|
|
|
|
HIP_TEST_CASE(Unit_AtomicFunctions_Dec) {
|
|
int* Hptr{nullptr};
|
|
int val;
|
|
// Allocate Host memory
|
|
Hptr = reinterpret_cast<int*>(malloc(sizeof(int)));
|
|
SECTION("Test case when value is less than limit") {
|
|
val = Hptr[0] = 4;
|
|
launchAtomicFunction(Hptr, val, 2);
|
|
}
|
|
SECTION("Test case when value is greater than limit") {
|
|
val = Hptr[0] = 31;
|
|
launchAtomicFunction(Hptr, val, 2);
|
|
}
|
|
SECTION("Test case when value is equal to the limit") {
|
|
val = Hptr[0] = 25;
|
|
launchAtomicFunction(Hptr, val, 2);
|
|
}
|
|
free(Hptr);
|
|
}
|