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
203 lines
8.1 KiB
C++
203 lines
8.1 KiB
C++
/*
|
|
Copyright (c) 2022 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.
|
|
*/
|
|
/*
|
|
AtomicAdd on FineGrainMemory
|
|
1. The following test scenario verifies
|
|
unsafeatomicAdd on fineGrain memory with different unsafe-atomics flags:
|
|
- with -mno-unsafe-fp-atomics flag
|
|
- without any atomics flag
|
|
- with -munsafe-fp-atomics flag
|
|
This testcase works only on gfx90a, gfx942, gfx950.
|
|
*/
|
|
|
|
#include <hip_test_checkers.hh>
|
|
#include <hip_test_common.hh>
|
|
#include <hip_test_features.hh>
|
|
#include <type_traits>
|
|
|
|
#define INC_VAL 10
|
|
#define INITIAL_VAL 5
|
|
|
|
template <typename T> static __global__ void AtomicCheck(T* Ad, T* result) {
|
|
T inc_val = 10;
|
|
*result = unsafeAtomicAdd(Ad, inc_val);
|
|
}
|
|
|
|
/*unsafeatomicAdd API for the fine grained memory variable with different flags
|
|
- with -mno-unsafe-fp-atomics flag
|
|
- without any atomics flag
|
|
- with -munsafe-fp-atomics flag
|
|
Input: Ad{5}, INC_VAL{10}
|
|
Output: unsafeatomicAdd API behavior depends on the flag used
|
|
Generate the assembly file and check whether
|
|
atomic add instruction is generated */
|
|
|
|
// Helper function for "with -mno-unsafe-fp-atomics flag" test
|
|
template <typename TestType>
|
|
static void runUnsafeAtomicAddCoherentNoUnsafeFlagTest(const std::string& gfxName) {
|
|
TestType *A_h{nullptr}, *result{nullptr};
|
|
TestType *A_d{nullptr}, *result_d{nullptr};
|
|
HIP_CHECK(
|
|
hipHostMalloc(reinterpret_cast<void**>(&A_h), sizeof(TestType), hipHostMallocCoherent));
|
|
A_h[0] = INITIAL_VAL;
|
|
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&result), sizeof(TestType),
|
|
hipHostMallocCoherent));
|
|
result[0] = INITIAL_VAL;
|
|
HIP_CHECK(hipHostGetDevicePointer(reinterpret_cast<void**>(&A_d), A_h, 0));
|
|
HIP_CHECK(hipHostGetDevicePointer(reinterpret_cast<void**>(&result_d), result, 0));
|
|
hipLaunchKernelGGL(AtomicCheck<TestType>, dim3(1), dim3(1), 0, 0, A_d, result_d);
|
|
HIP_CHECK(hipGetLastError());
|
|
HIP_CHECK(hipDeviceSynchronize());
|
|
bool testResult;
|
|
|
|
if ((std::is_same<TestType, float>::value)) {
|
|
testResult = HipTest::assemblyFile_Verification<TestType>(
|
|
"unsafeAtomicAdd_Coherent_withnounsafeflag-hip-amdgcn(.*)\\.s", "global_atomic_add_f32");
|
|
REQUIRE(testResult == true);
|
|
} else {
|
|
testResult = HipTest::assemblyFile_Verification<TestType>(
|
|
"unsafeAtomicAdd_Coherent_withnounsafeflag-hip-amdgcn(.*)\\.s", "global_atomic_add_f64");
|
|
REQUIRE(testResult == true);
|
|
}
|
|
|
|
if ((gfxName == "gfx90a" || gfxName.find("gfx90a:")) == 0) {
|
|
REQUIRE(A_h[0] == INITIAL_VAL);
|
|
REQUIRE(result[0] == 0);
|
|
} else {
|
|
REQUIRE(A_h[0] == INITIAL_VAL + INC_VAL);
|
|
REQUIRE(result[0] == INITIAL_VAL);
|
|
}
|
|
HIP_CHECK(hipHostFree(A_h));
|
|
HIP_CHECK(hipHostFree(result));
|
|
}
|
|
|
|
// Helper function for "without any flag" test
|
|
template <typename TestType>
|
|
static void runUnsafeAtomicAddCoherentWithoutFlagTest(const std::string& gfxName) {
|
|
TestType *A_h{nullptr}, *result{nullptr};
|
|
TestType *A_d{nullptr}, *result_d{nullptr};
|
|
HIP_CHECK(
|
|
hipHostMalloc(reinterpret_cast<void**>(&A_h), sizeof(TestType), hipHostMallocCoherent));
|
|
A_h[0] = INITIAL_VAL;
|
|
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&result), sizeof(TestType),
|
|
hipHostMallocCoherent));
|
|
result[0] = INITIAL_VAL;
|
|
HIP_CHECK(hipHostGetDevicePointer(reinterpret_cast<void**>(&A_d), A_h, 0));
|
|
HIP_CHECK(hipHostGetDevicePointer(reinterpret_cast<void**>(&result_d), result, 0));
|
|
hipLaunchKernelGGL(AtomicCheck<TestType>, dim3(1), dim3(1), 0, 0, A_d, result_d);
|
|
HIP_CHECK(hipGetLastError());
|
|
HIP_CHECK(hipDeviceSynchronize());
|
|
bool testResult;
|
|
|
|
if ((std::is_same<TestType, float>::value)) {
|
|
testResult = HipTest::assemblyFile_Verification<TestType>(
|
|
"unsafeAtomicAdd_Coherent_withoutflag-hip-amdgcn(.*)\\.s", "global_atomic_add_f32");
|
|
REQUIRE(testResult == true);
|
|
} else {
|
|
testResult = HipTest::assemblyFile_Verification<TestType>(
|
|
"unsafeAtomicAdd_Coherent_withoutflag-hip-amdgcn(.*)\\.s", "global_atomic_add_f64");
|
|
REQUIRE(testResult == true);
|
|
}
|
|
|
|
if ((gfxName == "gfx90a" || gfxName.find("gfx90a:")) == 0) {
|
|
REQUIRE(A_h[0] == INITIAL_VAL);
|
|
REQUIRE(result[0] == 0);
|
|
} else {
|
|
REQUIRE(A_h[0] == INITIAL_VAL + INC_VAL);
|
|
REQUIRE(result[0] == INITIAL_VAL);
|
|
}
|
|
HIP_CHECK(hipHostFree(A_h));
|
|
HIP_CHECK(hipHostFree(result));
|
|
}
|
|
|
|
// Helper function for "with -munsafe-fp-atomics flag" test
|
|
template <typename TestType>
|
|
static void runUnsafeAtomicAddCoherentUnsafeFlagTest(const std::string& gfxName) {
|
|
TestType *A_h{nullptr}, *result{nullptr};
|
|
TestType *A_d{nullptr}, *result_d{nullptr};
|
|
HIP_CHECK(
|
|
hipHostMalloc(reinterpret_cast<void**>(&A_h), sizeof(TestType), hipHostMallocCoherent));
|
|
A_h[0] = INITIAL_VAL;
|
|
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&result), sizeof(TestType),
|
|
hipHostMallocCoherent));
|
|
result[0] = INITIAL_VAL;
|
|
HIP_CHECK(hipHostGetDevicePointer(reinterpret_cast<void**>(&A_d), A_h, 0));
|
|
HIP_CHECK(hipHostGetDevicePointer(reinterpret_cast<void**>(&result_d), result, 0));
|
|
hipLaunchKernelGGL(AtomicCheck<TestType>, dim3(1), dim3(1), 0, 0, A_d, result_d);
|
|
HIP_CHECK(hipGetLastError());
|
|
HIP_CHECK(hipDeviceSynchronize());
|
|
bool testResult;
|
|
|
|
if ((std::is_same<TestType, float>::value)) {
|
|
testResult = HipTest::assemblyFile_Verification<TestType>(
|
|
"unsafeAtomicAdd_Coherent_withunsafeflag-hip-amdgcn(.*)\\.s", "global_atomic_add_f32");
|
|
REQUIRE(testResult == true);
|
|
} else {
|
|
testResult = HipTest::assemblyFile_Verification<TestType>(
|
|
"unsafeAtomicAdd_Coherent_withunsafeflag-hip-amdgcn(.*)\\.s", "global_atomic_add_f64");
|
|
REQUIRE(testResult == true);
|
|
}
|
|
|
|
if ((gfxName == "gfx90a" || gfxName.find("gfx90a:")) == 0) {
|
|
REQUIRE(A_h[0] == INITIAL_VAL);
|
|
REQUIRE(result[0] == 0);
|
|
} else {
|
|
REQUIRE(A_h[0] == INITIAL_VAL + INC_VAL);
|
|
REQUIRE(result[0] == INITIAL_VAL);
|
|
}
|
|
HIP_CHECK(hipHostFree(A_h));
|
|
HIP_CHECK(hipHostFree(result));
|
|
}
|
|
|
|
TEST_CASE(Unit_unsafeAtomicAdd_Coherent) {
|
|
hipDeviceProp_t prop;
|
|
int device;
|
|
HIP_CHECK(hipGetDevice(&device));
|
|
HIP_CHECK(hipGetDeviceProperties(&prop, device));
|
|
std::string gfxName(prop.gcnArchName);
|
|
|
|
if (CheckIfFeatSupported(CTFeatures::CT_FEATURE_FINEGRAIN_HWSUPPORT, gfxName)) {
|
|
if (prop.canMapHostMemory != 1) {
|
|
SUCCEED("Does not support HostPinned Memory");
|
|
} else {
|
|
SECTION("with -mno-unsafe-fp-atomics flag") {
|
|
SECTION("float") { runUnsafeAtomicAddCoherentNoUnsafeFlagTest<float>(gfxName); }
|
|
SECTION("double") { runUnsafeAtomicAddCoherentNoUnsafeFlagTest<double>(gfxName); }
|
|
}
|
|
|
|
SECTION("without any flag") {
|
|
SECTION("float") { runUnsafeAtomicAddCoherentWithoutFlagTest<float>(gfxName); }
|
|
SECTION("double") { runUnsafeAtomicAddCoherentWithoutFlagTest<double>(gfxName); }
|
|
}
|
|
|
|
SECTION("with -munsafe-fp-atomics flag") {
|
|
SECTION("float") { runUnsafeAtomicAddCoherentUnsafeFlagTest<float>(gfxName); }
|
|
SECTION("double") { runUnsafeAtomicAddCoherentUnsafeFlagTest<double>(gfxName); }
|
|
}
|
|
}
|
|
} else {
|
|
SUCCEED(
|
|
"Memory model feature is only supported for gfx90a, gfx942, gfx950,"
|
|
"Hence skipping the testcase for this GPU "
|
|
<< device);
|
|
}
|
|
}
|