-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathAtomicAdd_Coherent_withunsafeflag.cc
More file actions
101 lines (92 loc) · 4.07 KB
/
Copy pathAtomicAdd_Coherent_withunsafeflag.cc
File metadata and controls
101 lines (92 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
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
atomicAdd on fineGrain memory with -munsafe-fp-atomics flag
This testcase works only on gfx90a, gfx940, gfx941, gfx942.
*/
#include<hip_test_checkers.hh>
#include<hip_test_common.hh>
#include<hip_test_features.hh>
#define INC_VAL 10
#define INITIAL_VAL 5
template<typename T>
static __global__ void AtomicCheck(T* Ad, T* result) {
T inc_val = 10;
*result = atomicAdd(Ad, inc_val);
}
/*atomicAdd API for the fine grained memory variable
with -m-unsafe-atomics flag
Input: Ad{5}, INC_VAL{10}
Output: atomicAdd API would return 0 and the 0/P is 5
Generate the assembly file and check whether
global_atomic_cmpswap instruction is generated
or not */
TEMPLATE_TEST_CASE("Unit_AtomicAdd_CoherentwithUnsafeflag", "",
float, double) {
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 {
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>(
"AtomicAdd_Coherent_withunsafeflag-hip-amdgcn(.*)\\.s",
"global_atomic_add_f32");
REQUIRE(testResult == true);
} else {
testResult = HipTest::assemblyFile_Verification<TestType>(
"AtomicAdd_Coherent_withunsafeflag-hip-amdgcn(.*)\\.s",
"global_atomic_add_f64");
REQUIRE(testResult == true);
}
REQUIRE(A_h[0] == INITIAL_VAL);
REQUIRE(result[0] == 0);
HIP_CHECK(hipHostFree(A_h));
HIP_CHECK(hipHostFree(result));
}
} else {
SUCCEED("Memory model feature is only supported for gfx90a, gfx940, gfx941, gfx942, Hence"
"skipping the testcase for this GPU " << device);
}
}