Skip to content

Commit ca2ed9b

Browse files
EXSWHTEC-2 - Implement additional tests for hipDeviceSynchronize (#2872)
- Test synchronization when no work is enqueued on streams - Test synchronization on default stream - Modify tests to run for all devices. - Remove unnecessary check in Unit_hipDeviceSynchronize_Positive_Empty_Streams test.
1 parent 84650ef commit ca2ed9b

File tree

1 file changed

+40
-7
lines changed

1 file changed

+40
-7
lines changed

tests/catch/unit/device/hipDeviceSynchronize.cc

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
/*
2-
Copyright (c) 2021 Advanced Micro Devices, Inc. All rights reserved.
2+
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
3+
34
Permission is hereby granted, free of charge, to any person obtaining a copy
45
of this software and associated documentation files (the "Software"), to deal
56
in the Software without restriction, including without limitation the rights
67
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
78
copies of the Software, and to permit persons to whom the Software is
89
furnished to do so, subject to the following conditions:
10+
911
The above copyright notice and this permission notice shall be included in
1012
all copies or substantial portions of the Software.
11-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
12-
IMPLIED, INNCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13-
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANNY CLAIM, DAMAGES OR OTHER
15-
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16-
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1720
THE SOFTWARE.
1821
*/
1922

@@ -41,6 +44,36 @@ static __global__ void Iter(int* Ad, int num) {
4144
}
4245
}
4346

47+
TEST_CASE("Unit_hipDeviceSynchronize_Positive_Empty_Streams") {
48+
const auto device = GENERATE(range(0, HipTest::getDeviceCount()));
49+
HIP_CHECK(hipSetDevice(device));
50+
INFO("Current device: " << device);
51+
52+
hipStream_t stream;
53+
HIP_CHECK(hipStreamCreate(&stream));
54+
HIP_CHECK(hipDeviceSynchronize());
55+
HIP_CHECK(hipStreamDestroy(stream));
56+
}
57+
58+
TEST_CASE("Unit_hipDeviceSynchronize_Positive_Nullstream") {
59+
const auto device = GENERATE(range(0, HipTest::getDeviceCount()));
60+
HIP_CHECK(hipSetDevice(device));
61+
INFO("Current device: " << device);
62+
63+
int *A_h = nullptr, *A_d = nullptr;
64+
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&A_h), _SIZE, hipHostMallocDefault));
65+
A_h[0] = 1;
66+
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&A_d), _SIZE));
67+
68+
HIP_CHECK(hipMemcpyAsync(A_d, A_h, _SIZE, hipMemcpyHostToDevice, NULL));
69+
hipLaunchKernelGGL(HIP_KERNEL_NAME(Iter), dim3(1), dim3(1), 0, NULL, A_d, 1 << 30);
70+
HIP_CHECK(hipMemcpyAsync(A_h, A_d, _SIZE, hipMemcpyDeviceToHost, NULL));
71+
72+
CHECK(1 << 30 != A_h[0] - 1);
73+
HIP_CHECK(hipDeviceSynchronize());
74+
CHECK(1 << 30 == A_h[0] - 1);
75+
}
76+
4477
TEST_CASE("Unit_hipDeviceSynchronize_Functional") {
4578
int* A[NUM_STREAMS];
4679
int* Ad[NUM_STREAMS];

0 commit comments

Comments
 (0)