From e3c5126b72718751b60131b1ddfb75f9f886d937 Mon Sep 17 00:00:00 2001 From: agunashe <86270081+agunashe@users.noreply.github.com> Date: Mon, 17 Apr 2023 13:44:43 -0700 Subject: [PATCH 01/10] =?UTF-8?q?SWDEV-394199=20-=20disable=20Unit=5FhipSt?= =?UTF-8?q?reamCreateWithPriority=5FMulthreadNonb=E2=80=A6=20(#237)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * SWDEV-394199 - disable Unit_hipStreamCreateWithPriority_MulthreadNonblockingflag * SWDEV-394199 - disabling same test on linux Unit_hipStreamCreateWithPriority_MulthreadNonblockingflag on linux too --- catch/hipTestMain/config/config_amd_linux_common.json | 6 ++++-- catch/hipTestMain/config/config_amd_windows_common.json | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/catch/hipTestMain/config/config_amd_linux_common.json b/catch/hipTestMain/config/config_amd_linux_common.json index 4f6c294560..20efc199e5 100644 --- a/catch/hipTestMain/config/config_amd_linux_common.json +++ b/catch/hipTestMain/config/config_amd_linux_common.json @@ -55,9 +55,11 @@ "Unit_hipDeviceSetSharedMemConfig_Negative_Parameters", "Disabling tests tracked with SWDEV-394083", "Unit_hipDeviceSynchronize_Positive_Nullstream", - "Disabling tests tracked with SWDEV-393637", + "Disabling tests tracked with SWDEV-393637", "Unit_hipDeviceSynchronize_Functional", "Unit_hipMemset3DSync", - "Unit_hipStreamAddCallback_StrmSyncTiming" + "Unit_hipStreamAddCallback_StrmSyncTiming", + "Disabling test tracked SWDEV-394199", + "Unit_hipStreamCreateWithPriority_MulthreadNonblockingflag" ] } diff --git a/catch/hipTestMain/config/config_amd_windows_common.json b/catch/hipTestMain/config/config_amd_windows_common.json index 32c2aff890..486ca83568 100644 --- a/catch/hipTestMain/config/config_amd_windows_common.json +++ b/catch/hipTestMain/config/config_amd_windows_common.json @@ -147,6 +147,8 @@ "Unit_hipGraphMemsetNodeSetParams_Positive_Basic - uint8_t", "Unit_hipStreamWaitEvent_UninitializedStream_Negative", "Unit_hipDeviceSetSharedMemConfig_Negative_Parameters", - "Unit_hipDeviceGetUuid_Positive" + "Unit_hipDeviceGetUuid_Positive", + "Disabling test tracked SWDEV-394199", + "Unit_hipStreamCreateWithPriority_MulthreadNonblockingflag" ] } From 1cd686bed6a2907e754ee0203152d3dcf75933b3 Mon Sep 17 00:00:00 2001 From: agunashe <86270081+agunashe@users.noreply.github.com> Date: Wed, 19 Apr 2023 13:27:50 -0700 Subject: [PATCH 02/10] SWDEV-395683 - skipping Unit_hipStreamPerThread_MultiThread (#240) --- catch/hipTestMain/config/config_amd_linux_common.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/catch/hipTestMain/config/config_amd_linux_common.json b/catch/hipTestMain/config/config_amd_linux_common.json index 20efc199e5..88a91bf511 100644 --- a/catch/hipTestMain/config/config_amd_linux_common.json +++ b/catch/hipTestMain/config/config_amd_linux_common.json @@ -60,6 +60,8 @@ "Unit_hipMemset3DSync", "Unit_hipStreamAddCallback_StrmSyncTiming", "Disabling test tracked SWDEV-394199", - "Unit_hipStreamCreateWithPriority_MulthreadNonblockingflag" + "Unit_hipStreamCreateWithPriority_MulthreadNonblockingflag", + "Disabling test tracked SWDEV-395683", + "Unit_hipStreamPerThread_MultiThread" ] } From 61dce0f72a2ca26851413863f22b409be6af5aff Mon Sep 17 00:00:00 2001 From: Maneesh Gupta Date: Thu, 20 Apr 2023 04:49:58 +0530 Subject: [PATCH 03/10] Update jenkinsfile to build tests against clr (#239) * Update jenkinsfile to build tests against clr * Update jenkinsfile --- .jenkins/jenkinsfile | 55 ++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/.jenkins/jenkinsfile b/.jenkins/jenkinsfile index bed5be315e..96b1d74e78 100644 --- a/.jenkins/jenkinsfile +++ b/.jenkins/jenkinsfile @@ -2,53 +2,40 @@ def hipBuildTest(String backendLabel) { node(backendLabel) { stage("SYNC - ${backendLabel}") { - // Checkout hip repository with the PR patch + // Checkout hip-tests repository with the PR patch dir("${WORKSPACE}/hip-tests") { checkout scm env.HIP_TESTS_DIR = "${WORKSPACE}" + "/hip-tests" } - // Clone HIP repository + // Clone hip repository dir("${WORKSPACE}/hip") { git branch: 'develop', - url: 'https://github.com/ROCm-Developer-Tools/HIP' + url: 'https://github.com/ROCm-Developer-Tools/hip' env.HIP_DIR = "${WORKSPACE}" + "/hip" } - // Clone hipamd repository - dir("${WORKSPACE}/hipamd") { + // Clone clr repository + dir("${WORKSPACE}/clr") { git branch: 'develop', - url: 'https://github.com/ROCm-Developer-Tools/hipamd' - env.HIPAMD_DIR = "${WORKSPACE}" + "/hipamd" - } - - // Clone vdi and opencl for only amd backend server - if (backendLabel =~ /.*amd.*/) { - dir("${WORKSPACE}/ROCm-OpenCL-Runtime") { - git branch:'develop', - url: 'https://github.com/RadeonOpenCompute/ROCm-OpenCL-Runtime' - env.OPENCL_DIR = "${WORKSPACE}" + "/ROCm-OpenCL-Runtime" - } - dir("${WORKSPACE}/ROCclr") { - git branch:'develop', - url: 'https://github.com/ROCm-Developer-Tools/ROCclr' - env.ROCclr_DIR = "${WORKSPACE}" + "/ROCclr" - } + url: 'https://github.com/ROCm-Developer-Tools/clr' + env.CLR_DIR = "${WORKSPACE}" + "/clr" } } stage("BUILD HIP - ${backendLabel}") { - // Running the build on hipamd workspace - dir("${WORKSPACE}/hipamd") { + // Running the build on clr workspace + dir("${WORKSPACE}/clr") { sh """#!/usr/bin/env bash set -x + rm -rf build mkdir -p build cd build # Check if backend label contains string "amd" or backend host is a server with amd gpu if [[ $backendLabel =~ amd ]]; then - cmake -DHIP_PATH=\$PWD/install -DHIP_COMMON_DIR=\$HIP_DIR -DAMD_OPENCL_PATH=\$OPENCL_DIR -DROCCLR_PATH=\$ROCclr_DIR -DCMAKE_PREFIX_PATH="/opt/rocm/" -DCMAKE_INSTALL_PREFIX=\$PWD/install .. + cmake -DCLR_BUILD_HIP=ON -DHIP_PATH=\$PWD/install -DHIP_COMMON_DIR=\$HIP_DIR -DCMAKE_PREFIX_PATH="/opt/rocm/" -DCMAKE_INSTALL_PREFIX=\$PWD/install .. else - cmake -DHIP_PLATFORM=nvidia -DHIP_COMMON_DIR=\$HIP_DIR -DCMAKE_INSTALL_PREFIX=\$PWD/install .. + cmake -DCLR_BUILD_HIP=ON -DHIP_PLATFORM=nvidia -DHIP_COMMON_DIR=\$HIP_DIR -DCMAKE_INSTALL_PREFIX=\$PWD/install .. fi make -j\$(nproc) make install -j\$(nproc) @@ -59,7 +46,7 @@ def hipBuildTest(String backendLabel) { stage("BUILD HIP TESTS - ${backendLabel}") { // Running the build on HIP TESTS workspace dir("${WORKSPACE}/hip-tests") { - env.HIP_PATH = "${HIPAMD_DIR}" + "/build/install" + env.HIP_PATH = "${CLR_DIR}" + "/build/install" sh """#!/usr/bin/env bash set -x rm -rf build @@ -78,17 +65,19 @@ def hipBuildTest(String backendLabel) { } } - stage("TEST - ${backendLabel}") { - dir("${WORKSPACE}/hip-tests") { - sh """#!/usr/bin/env bash - set -x - cd build + timeout(time: 1, unit: 'HOURS') { + stage("TEST - ${backendLabel}") { + dir("${WORKSPACE}/hip-tests") { + sh """#!/usr/bin/env bash + set -x + cd build if [[ $backendLabel =~ amd ]]; then - ctest + ctest --overwrite BuildDirectory=. --output-junit hiptest_output_catch_amd.xml else - ctest -E 'Unit_hipMemcpyHtoD_Positive_Synchronization_Behavior|Unit_hipMemcpy_Positive_Synchronization_Behavior|Unit_hipFreeNegativeHost' + ctest --overwrite BuildDirectory=. --output-junit hiptest_output_catch_nvidia.xml -E 'Unit_hipMemcpyHtoD_Positive_Synchronization_Behavior|Unit_hipMemcpy_Positive_Synchronization_Behavior|Unit_hipFreeNegativeHost' fi """ + } } } } From 8f296fcc5886048eeae085e34b01d28b07aa360c Mon Sep 17 00:00:00 2001 From: ROCm CI Service Account <66695075+rocm-ci@users.noreply.github.com> Date: Fri, 21 Apr 2023 09:38:34 +0530 Subject: [PATCH 04/10] SWDEV-362365 - Correct error code. (#224) Change-Id: I329a3296ce56ae741118b4f66294001025d48443 --- catch/unit/device/hipDeviceSetGetSharedMemConfig.cc | 5 ----- 1 file changed, 5 deletions(-) diff --git a/catch/unit/device/hipDeviceSetGetSharedMemConfig.cc b/catch/unit/device/hipDeviceSetGetSharedMemConfig.cc index 045f40092a..83251172dc 100644 --- a/catch/unit/device/hipDeviceSetGetSharedMemConfig.cc +++ b/catch/unit/device/hipDeviceSetGetSharedMemConfig.cc @@ -43,13 +43,8 @@ TEST_CASE("Unit_hipDeviceSetSharedMemConfig_Positive_Basic") { } TEST_CASE("Unit_hipDeviceSetSharedMemConfig_Negative_Parameters") { -#if HT_AMD - HIP_CHECK_ERROR(hipDeviceSetSharedMemConfig(static_cast(-1)), - hipErrorNotSupported); -#elif HT_NVIDIA HIP_CHECK_ERROR(hipDeviceSetSharedMemConfig(static_cast(-1)), hipErrorInvalidValue); -#endif } TEST_CASE("Unit_hipDeviceGetSharedMemConfig_Positive_Default") { From 86ccc3e7d53c5db1a4e28944a73d4cc49e3bf27d Mon Sep 17 00:00:00 2001 From: arjun-raj-kuppala <60718144+arjun-raj-kuppala@users.noreply.github.com> Date: Fri, 21 Apr 2023 15:22:21 +0530 Subject: [PATCH 05/10] Use cred for private repo (#241) --- .jenkins/jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/.jenkins/jenkinsfile b/.jenkins/jenkinsfile index 96b1d74e78..813fdd6992 100644 --- a/.jenkins/jenkinsfile +++ b/.jenkins/jenkinsfile @@ -18,6 +18,7 @@ def hipBuildTest(String backendLabel) { // Clone clr repository dir("${WORKSPACE}/clr") { git branch: 'develop', + credentialsId: 'branch-credentials', url: 'https://github.com/ROCm-Developer-Tools/clr' env.CLR_DIR = "${WORKSPACE}" + "/clr" } From c062ab6c593f9bc4a2bfccb14c94495de9a01e96 Mon Sep 17 00:00:00 2001 From: ROCm CI Service Account <66695075+rocm-ci@users.noreply.github.com> Date: Fri, 21 Apr 2023 16:44:33 +0530 Subject: [PATCH 06/10] SWDEV-375580 - rework the test to be more stable, move it to correct folder and fix some multi threaded access patterns (#211) --- catch/unit/memory/CMakeLists.txt | 1 - .../unit/memory/hipMemsetAsyncMultiThread.cc | 243 ------------------ catch/unit/multiThread/CMakeLists.txt | 1 + .../multiThread/hipMemsetAsyncMultiThread.cc | 182 +++++++++++++ 4 files changed, 183 insertions(+), 244 deletions(-) delete mode 100644 catch/unit/memory/hipMemsetAsyncMultiThread.cc create mode 100644 catch/unit/multiThread/hipMemsetAsyncMultiThread.cc diff --git a/catch/unit/memory/CMakeLists.txt b/catch/unit/memory/CMakeLists.txt index 6c528fcc16..dfecc3471f 100644 --- a/catch/unit/memory/CMakeLists.txt +++ b/catch/unit/memory/CMakeLists.txt @@ -51,7 +51,6 @@ set(TEST_SRC hipMallocManaged_MultiScenario.cc hipMemsetNegative.cc hipMemset.cc - hipMemsetAsyncMultiThread.cc hipMemset3D.cc hipMemset2D.cc hipHostMallocTests.cc diff --git a/catch/unit/memory/hipMemsetAsyncMultiThread.cc b/catch/unit/memory/hipMemsetAsyncMultiThread.cc deleted file mode 100644 index 68deacda92..0000000000 --- a/catch/unit/memory/hipMemsetAsyncMultiThread.cc +++ /dev/null @@ -1,243 +0,0 @@ -/* - * Copyright (c) 2021 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 WARRANNTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNNESS 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 INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -/* - * Test that validates functionality of hipmemsetAsync apis over multi threads - */ - -#include -#include - - -#define NUM_THREADS 20 -#define ITER 10 -#define N (4*1024*1024) - - -template -class MemSetAsyncMthreadTest { - public: - T *A_h, *A_d, *B_h; - T memSetVal; - size_t Nbytes; - bool testResult = true; - int validateCount = 0; - hipStream_t stream; - - void memAllocate(T memSetValue) { - memSetVal = memSetValue; - Nbytes = N * sizeof(T); - - A_h = reinterpret_cast(malloc(Nbytes)); - HIP_ASSERT(A_h != nullptr); - - HIP_CHECK(hipMalloc(&A_d, Nbytes)); - B_h = reinterpret_cast(malloc(Nbytes)); - HIP_ASSERT(B_h != nullptr); - - HIP_CHECK(hipStreamCreate(&stream)); - } - - void threadCompleteStatus() { - for (int k = 0 ; k < N ; k++) { - if ((A_h[k] == memSetVal) && (B_h[k] == memSetVal)) { - validateCount+= 1; - } - } - } - - bool resultAfterAllIterations() { - memDeallocate(); - testResult = (validateCount == (ITER * N)) ? true: false; - return testResult; - } - - void memDeallocate() { - HIP_CHECK(hipFree(A_d)); - free(A_h); - free(B_h); - HIP_CHECK(hipStreamDestroy(stream)); - } -}; - -template -void queueJobsForhipMemsetAsync(T* A_d, T* A_h, T memSetVal, size_t Nbytes, - hipStream_t stream) { - HIPCHECK(hipMemsetAsync(A_d, memSetVal, N, stream)); - HIPCHECK(hipMemcpyAsync(A_h, A_d, Nbytes, hipMemcpyDeviceToHost, stream)); -} - -template -void queueJobsForhipMemsetD32Async(T* A_d, T* A_h, T memSetVal, size_t Nbytes, - hipStream_t stream) { - HIPCHECK(hipMemsetD32Async((hipDeviceptr_t)A_d, memSetVal, N, stream)); - HIPCHECK(hipMemcpyAsync(A_h, A_d, Nbytes, hipMemcpyDeviceToHost, stream)); -} - -template -void queueJobsForhipMemsetD16Async(T* A_d, T* A_h, T memSetVal, size_t Nbytes, - hipStream_t stream) { - HIPCHECK(hipMemsetD16Async((hipDeviceptr_t)A_d, memSetVal, N, stream)); - HIPCHECK(hipMemcpyAsync(A_h, A_d, Nbytes, hipMemcpyDeviceToHost, stream)); -} - -template -void queueJobsForhipMemsetD8Async(T* A_d, T* A_h, T memSetVal, size_t Nbytes, - hipStream_t stream) { - HIPCHECK(hipMemsetD8Async((hipDeviceptr_t)A_d, memSetVal, N, stream)); - HIPCHECK(hipMemcpyAsync(A_h, A_d, Nbytes, hipMemcpyDeviceToHost, stream)); -} - -/* Queue hipMemsetAsync jobs on multiple threads and verify they all - * finished on all threads successfully - */ -bool testhipMemsetAsyncWithMultiThread() { - MemSetAsyncMthreadTest obj; - constexpr char memsetval = 0x42; - obj.memAllocate(memsetval); - std::thread t[NUM_THREADS]; - - for (int i = 0 ; i < ITER ; i++) { - for (int k = 0 ; k < NUM_THREADS ; k++) { - if (k%2) { - t[k] = std::thread(queueJobsForhipMemsetAsync, obj.A_d, obj.A_h, - obj.memSetVal, obj.Nbytes, obj.stream); - } else { - t[k] = std::thread(queueJobsForhipMemsetAsync, obj.A_d, obj.B_h, - obj.memSetVal, obj.Nbytes, obj.stream); - } - } - - for (int j = 0 ; j < NUM_THREADS ; j++) { - t[j].join(); - } - - HIP_CHECK(hipStreamSynchronize(obj.stream)); - obj.threadCompleteStatus(); - } - return obj.resultAfterAllIterations(); -} - -bool testhipMemsetD32AsyncWithMultiThread() { - MemSetAsyncMthreadTest obj; - constexpr int memsetD32val = 0xDEADBEEF; - obj.memAllocate(memsetD32val); - std::thread t[NUM_THREADS]; - - for (int i = 0 ; i < ITER ; i++) { - for (int k = 0 ; k < NUM_THREADS ; k++) { - if (k%2) { - t[k] = std::thread(queueJobsForhipMemsetD32Async, obj.A_d, - obj.A_h, obj.memSetVal, obj.Nbytes, obj.stream); - } else { - t[k] = std::thread(queueJobsForhipMemsetD32Async, obj.A_d, - obj.B_h, obj.memSetVal, obj.Nbytes, obj.stream); - } - } - - for (int j = 0 ; j < NUM_THREADS ; j++) { - t[j].join(); - } - - HIP_CHECK(hipStreamSynchronize(obj.stream)); - obj.threadCompleteStatus(); - } - return obj.resultAfterAllIterations(); -} - -bool testhipMemsetD16AsyncWithMultiThread() { - MemSetAsyncMthreadTest obj; - constexpr int16_t memsetD16val = 0xDEAD; - obj.memAllocate(memsetD16val); - std::thread t[NUM_THREADS]; - - for (int i = 0 ; i < ITER ; i++) { - for (int k = 0 ; k < NUM_THREADS ; k++) { - if (k%2) { - t[k] = std::thread(queueJobsForhipMemsetD16Async, obj.A_d, - obj.A_h, obj.memSetVal, obj.Nbytes, obj.stream); - } else { - t[k] = std::thread(queueJobsForhipMemsetD16Async, obj.A_d, - obj.B_h, obj.memSetVal, obj.Nbytes, obj.stream); - } - } - - for (int j = 0 ; j < NUM_THREADS ; j++) { - t[j].join(); - } - - HIP_CHECK(hipStreamSynchronize(obj.stream)); - obj.threadCompleteStatus(); - } - return obj.resultAfterAllIterations(); -} - -bool testhipMemsetD8AsyncWithMultiThread() { - MemSetAsyncMthreadTest obj; - constexpr char memsetD8val = 0xDE; - obj.memAllocate(memsetD8val); - std::thread t[NUM_THREADS]; - - for (int i = 0 ; i < ITER ; i++) { - for (int k = 0 ; k < NUM_THREADS ; k++) { - if (k%2) { - t[k] = std::thread(queueJobsForhipMemsetD8Async, obj.A_d, - obj.A_h, obj.memSetVal, obj.Nbytes, obj.stream); - } else { - t[k] = std::thread(queueJobsForhipMemsetD8Async, obj.A_d, - obj.B_h, obj.memSetVal, obj.Nbytes, obj.stream); - } - } - for (int j = 0 ; j < NUM_THREADS ; j++) { - t[j].join(); - } - - HIP_CHECK(hipStreamSynchronize(obj.stream)); - obj.threadCompleteStatus(); - } - return obj.resultAfterAllIterations(); -} - - -/* - * Test that validates functionality of hipmemsetAsync apis over multi threads - */ -TEST_CASE("Unit_hipMemsetAsync_QueueJobsMultithreaded") { - bool ret; - - SECTION("hipMemsetAsync With MultiThread") { - ret = testhipMemsetAsyncWithMultiThread(); - REQUIRE(ret == true); - } - - SECTION("hipMemsetD32Async With MultiThread") { - ret = testhipMemsetD32AsyncWithMultiThread(); - REQUIRE(ret == true); - } - - SECTION("hipMemsetD16Async With MultiThread") { - ret = testhipMemsetD16AsyncWithMultiThread(); - REQUIRE(ret == true); - } - - SECTION("hipMemsetD8Async With MultiThread") { - ret = testhipMemsetD8AsyncWithMultiThread(); - REQUIRE(ret == true); - } -} diff --git a/catch/unit/multiThread/CMakeLists.txt b/catch/unit/multiThread/CMakeLists.txt index 32abf0f5f3..8c77831a71 100644 --- a/catch/unit/multiThread/CMakeLists.txt +++ b/catch/unit/multiThread/CMakeLists.txt @@ -1,5 +1,6 @@ # Common Tests - Test independent of all platforms set(TEST_SRC + hipMemsetAsyncMultiThread.cc hipMultiThreadDevice.cc hipMultiThreadStreams1.cc hipMultiThreadStreams2.cc diff --git a/catch/unit/multiThread/hipMemsetAsyncMultiThread.cc b/catch/unit/multiThread/hipMemsetAsyncMultiThread.cc new file mode 100644 index 0000000000..0826ad7535 --- /dev/null +++ b/catch/unit/multiThread/hipMemsetAsyncMultiThread.cc @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2023 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 WARRANNTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNNESS 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 INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +enum TestType { SameStream = 0, DifferentStreams }; + +// Func -> Memset/MemsetD[8/16/32], T - type of data to be worked on +// basically each thread memsets value present in input one by one on its +// allocated buffer +template +void threadCall(Func f, hipStream_t stream) { + // Should match hipMemsetAsync or hipMemsetD*Async arguments + static_assert( + (std::is_same:: + value || // hipMemsetAsync + std::is_same::value || // hipMemsetD32Async + std::is_same::value || // hipMemsetD16Async + std::is_same::value) && // hipMemsetD8Async + "Func f should be hipMemsetAsync or hipMemsetD*Async"); + + constexpr bool cast_2_void = + std::is_same::value; + + // Use the unsiged type, since memset concerns with set bit values over a mem + // address + typedef typename std::make_unsigned::type unsigned_t; + + unsigned_t min = 0; + unsigned_t max = std::numeric_limits::max(); + + std::mt19937_64 engine(std::random_device{}()); + auto distribution = std::uniform_int_distribution( + min, max); // this needs to be unsigned because windows does not treats + // char as numeric types + + T *ptr{nullptr}; + constexpr size_t size = 1024; + constexpr size_t iter = 1024; + HIP_CHECK_THREAD(hipMalloc(&ptr, sizeof(T) * size)); + hipEvent_t event{}; + HIP_CHECK_THREAD(hipEventCreate(&event)); + + union overlay_val_t { + T t_val; + unsigned_t u_val; + } overlay_val; + + std::vector dst(size, 0); + for (size_t i = 0; i < iter; i++) { + overlay_val.u_val = static_cast( + distribution(engine)); // generate an unsigned int number + if constexpr (cast_2_void) { + HIP_CHECK_THREAD(f((void *)ptr, overlay_val.t_val, size, stream)); + } else { + HIP_CHECK_THREAD( + f(*(hipDeviceptr_t *)&ptr, overlay_val.t_val, size, stream)); + } + HIP_CHECK_THREAD(hipMemcpyAsync(dst.data(), ptr, size * sizeof(T), + hipMemcpyDeviceToHost, stream)); + HIP_CHECK_THREAD(hipEventRecord(event, stream)); + HIP_CHECK_THREAD( + hipStreamWaitEvent(stream, event, 0)); // wait till memcpy is done + REQUIRE_THREAD(std::all_of(dst.begin(), dst.end(), [&](T v) { + // If this test ever fails, add prints here on mismatch + return v == overlay_val.t_val; + })); + } + + HIP_CHECK_THREAD(hipEventDestroy(event)); + HIP_CHECK_THREAD(hipFree(ptr)); +} + +// Func -> Memset/MemsetD[8/16/32], T - type of data to be worked on +template void launchThreads(Func f, TestType type) { + static_assert(!std::is_pointer::value && "Argument cant be a pointer"); + + // Should match hipMemsetAsync or hipMemsetD*Async arguments + static_assert( + (std::is_same:: + value || // hipMemsetAsync + std::is_same::value || // hipMemsetD32Async + std::is_same::value || // hipMemsetD16Async + std::is_same::value) && // hipMemsetD8Async + "Func f should be hipMemsetAsync or hipMemsetD*Async"); + + const size_t num_threads = + (std::thread::hardware_concurrency() > 8) + ? (((std::thread::hardware_concurrency() / 4) >= 127) + ? 127 + : (std::thread::hardware_concurrency() / 4)) + : 2; // thread count between 2 - 127 + + const size_t num_streams = (type == SameStream) ? 1 : num_threads; + std::vector streams(num_streams, nullptr); + + for (size_t i = 0; i < num_streams; i++) { + HIP_CHECK(hipStreamCreate(&streams[i])); + REQUIRE(streams[i] != nullptr); + } + + std::vector thread_pool; + thread_pool.reserve(num_threads); + auto thread_func = threadCall; + for (size_t i = 0; i < num_threads; i++) { + auto stream = (type == SameStream) ? streams[0] : streams[i]; + thread_pool.emplace_back(std::thread(thread_func, f, stream)); + } + + for (size_t i = 0; i < num_threads; i++) { + thread_pool[i].join(); + } + + HIP_CHECK_THREAD_FINALIZE(); // Make sure all thread have exited properly + + for (size_t i = 0; i < num_streams; i++) { + HIP_CHECK(hipStreamDestroy(streams[i])); + } +} + +TEST_CASE("Unit_hipMemsetAsync_QueueJobsMultithreaded") { + using hipMemsetAsync_t = + hipError_t (*)(void *, int, const size_t, hipStream_t); + using hipMemsetAsyncD8_t = + hipError_t (*)(hipDeviceptr_t, unsigned char, const size_t, hipStream_t); + using hipMemsetAsyncD16_t = + hipError_t (*)(hipDeviceptr_t, unsigned short, const size_t, hipStream_t); + using hipMemsetAsyncD32_t = + hipError_t (*)(hipDeviceptr_t, int, const size_t, hipStream_t); + + launchThreads(hipMemsetAsync, SameStream); + launchThreads(hipMemsetAsync, DifferentStreams); + + launchThreads(hipMemsetD8Async, + SameStream); + launchThreads(hipMemsetD8Async, + DifferentStreams); + launchThreads(hipMemsetD16Async, + SameStream); + launchThreads(hipMemsetD16Async, + DifferentStreams); + launchThreads(hipMemsetD32Async, SameStream); + launchThreads(hipMemsetD32Async, DifferentStreams); +} From 8c76b1848cd75eb5b84f9221af52b7542ff52c33 Mon Sep 17 00:00:00 2001 From: agunashe <86270081+agunashe@users.noreply.github.com> Date: Mon, 24 Apr 2023 16:03:48 -0700 Subject: [PATCH 07/10] SWDEV-1 - skip multiple tests on Windows (#242) Unit_hipEventElapsedTime_NotReady_Negative Unit_hipGraphExecMemcpyNodeSetParamsFromSymbol_Negative_Parameters Unit_hipMemVmm_Basic Unit_hipManagedKeyword_MultiGpu --- .../hipTestMain/config/config_amd_windows_common.json | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/catch/hipTestMain/config/config_amd_windows_common.json b/catch/hipTestMain/config/config_amd_windows_common.json index 486ca83568..0b898627e4 100644 --- a/catch/hipTestMain/config/config_amd_windows_common.json +++ b/catch/hipTestMain/config/config_amd_windows_common.json @@ -149,6 +149,14 @@ "Unit_hipDeviceSetSharedMemConfig_Negative_Parameters", "Unit_hipDeviceGetUuid_Positive", "Disabling test tracked SWDEV-394199", - "Unit_hipStreamCreateWithPriority_MulthreadNonblockingflag" + "Unit_hipStreamCreateWithPriority_MulthreadNonblockingflag", + "SWDEV-396618 hipEventElapsedTime returns sucess", + "Unit_hipEventElapsedTime_NotReady_Negative", + "SWDEV-396617 ExecMemcpyNodeSetParamsFromSymbol fails in direction", + "Unit_hipGraphExecMemcpyNodeSetParamsFromSymbol_Negative_Parameters", + "SWDEV-396616 hipMemMap returns invalid error", + "Unit_hipMemVmm_Basic", + "SWDEV-396615 mGPUs not considered correctly", + "Unit_hipManagedKeyword_MultiGpu" ] } From 6adef2989aad824394ee8f6cc39c8012ef627435 Mon Sep 17 00:00:00 2001 From: ROCm CI Service Account <66695075+rocm-ci@users.noreply.github.com> Date: Tue, 25 Apr 2023 10:55:21 +0530 Subject: [PATCH 08/10] SWDEV-385487 - [catch2][dtest] hipGraphInstantiateWithFlags API with hipGraphInstantiateFlagAutoFreeOnLaunch flag call (#213) Change-Id: Ib96f796416d4e3190315f81432500e63876e78c0 --- .../graph/hipGraphInstantiateWithFlags.cc | 52 +++++++++++++++++-- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/catch/unit/graph/hipGraphInstantiateWithFlags.cc b/catch/unit/graph/hipGraphInstantiateWithFlags.cc index 14302b84f9..54210442fb 100644 --- a/catch/unit/graph/hipGraphInstantiateWithFlags.cc +++ b/catch/unit/graph/hipGraphInstantiateWithFlags.cc @@ -1,5 +1,5 @@ /* -Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2023 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 @@ -20,20 +20,16 @@ THE SOFTWARE. /* hipGraphInstantiateWithFlags(hipGraphExec_t* pGraphExec, hipGraph_t graph, unsigned long long flags); Testcase Scenarios of hipGraphInstantiateWithFlags API: - Negative: 1) Pass nullptr to pGraphExec 2) Pass nullptr to graph 4) Pass invalid flag - Functional: - 1) Create dependencies graph and instantiate the graph 2) Create graph in one GPU device and instantiate, launch in peer GPU device 3) Create stream capture graph and instantite the graph 4) Create stream capture graph in one GPU device and instantite the graph launch in peer GPU device - Mapping is missing for NVIDIA platform hence skipping the testcases */ @@ -311,3 +307,49 @@ TEST_CASE("Unit_hipGraphInstantiateWithFlags_StreamCaptureDeviceContextChg") { SUCCEED("skipped the testcase as no of devices is less than 2"); } } + +/* Create graph and add memAlloc node, but no corresponding memFree node to it. + Instantiate graph with flag - hipGraphInstantiateFlagAutoFreeOnLaunch + Launch and check graph execution should work properly and + free memory allocated by memAlloc call manually using hipFree api. + +Note - This test case is just to check if hipGraphInstantiateFlagAutoFreeOnLaunch + is not resulting in compilation error or api failure. Real functional test + will be added once the feature is fully implemented. +*/ +TEST_CASE("Unit_hipGraphInstantiateWithFlags_FlagAutoFreeOnLaunch_check") { + constexpr size_t size = 512 * 1024 * 1024; + constexpr size_t Nbytes = size * sizeof(int); + + hipGraph_t graph; + hipGraphExec_t graphExec; + hipStream_t stream; + hipGraphNode_t allocNodeA; + hipMemAllocNodeParams allocParam; + + HIP_CHECK(hipGraphCreate(&graph, 0)); + HIP_CHECK(hipStreamCreate(&stream)); + + memset(&allocParam, 0, sizeof(allocParam)); + allocParam.bytesize = Nbytes; + allocParam.poolProps.allocType = hipMemAllocationTypePinned; + allocParam.poolProps.location.id = 0; + allocParam.poolProps.location.type = hipMemLocationTypeDevice; + + HIP_CHECK(hipGraphAddMemAllocNode(&allocNodeA, graph, nullptr, + 0, &allocParam)); + REQUIRE(allocParam.dptr != nullptr); + int *A_d = reinterpret_cast(allocParam.dptr); + + // Instantiate with Flag and launch the graph + HIP_CHECK(hipGraphInstantiateWithFlags(&graphExec, graph, + hipGraphInstantiateFlagAutoFreeOnLaunch)); + + HIP_CHECK(hipGraphLaunch(graphExec, stream)); + HIP_CHECK(hipStreamSynchronize(stream)); + + HIP_CHECK(hipFree(A_d)); // free allocMemory manually + HIP_CHECK(hipGraphDestroy(graph)); + HIP_CHECK(hipGraphExecDestroy(graphExec)); + HIP_CHECK(hipStreamDestroy(stream)); +} From b52e7868b0ec89e7af2168f37a8dd6892a547864 Mon Sep 17 00:00:00 2001 From: jtpatel Date: Thu, 27 Apr 2023 02:35:46 +0530 Subject: [PATCH 09/10] SWDEV-396088 - Disable Unit_hipMemcpy2DToArrayAsync_Positive_Synchronization_Behavior. (#251) --- catch/hipTestMain/config/config_amd_linux_common.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/catch/hipTestMain/config/config_amd_linux_common.json b/catch/hipTestMain/config/config_amd_linux_common.json index 88a91bf511..ec86f902cc 100644 --- a/catch/hipTestMain/config/config_amd_linux_common.json +++ b/catch/hipTestMain/config/config_amd_linux_common.json @@ -62,6 +62,8 @@ "Disabling test tracked SWDEV-394199", "Unit_hipStreamCreateWithPriority_MulthreadNonblockingflag", "Disabling test tracked SWDEV-395683", - "Unit_hipStreamPerThread_MultiThread" + "Unit_hipStreamPerThread_MultiThread", + "Disabling tests tracked with SWDEV-389647..", + "Unit_hipMemcpy2DToArrayAsync_Positive_Synchronization_Behavior" ] } From b5d2ea28e1c9832fd6bda7522123818033e9b440 Mon Sep 17 00:00:00 2001 From: shadidashmiz <94885391+shadidashmiz@users.noreply.github.com> Date: Mon, 1 May 2023 12:59:45 -0400 Subject: [PATCH 10/10] SWDEV-391555 - disable failing tests (#252) * SWDEV-391555 - disable failing tests Change-Id: I6ded26927720b77938022f37acf7513a7fc2575b * SWDEV-391555 - disable more failing tests --- catch/hipTestMain/config/config_amd_linux_common.json | 8 +++++++- catch/hipTestMain/config/config_amd_windows_common.json | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/catch/hipTestMain/config/config_amd_linux_common.json b/catch/hipTestMain/config/config_amd_linux_common.json index ec86f902cc..be62d80429 100644 --- a/catch/hipTestMain/config/config_amd_linux_common.json +++ b/catch/hipTestMain/config/config_amd_linux_common.json @@ -64,6 +64,12 @@ "Disabling test tracked SWDEV-395683", "Unit_hipStreamPerThread_MultiThread", "Disabling tests tracked with SWDEV-389647..", - "Unit_hipMemcpy2DToArrayAsync_Positive_Synchronization_Behavior" + "Unit_hipMemcpy2DToArrayAsync_Positive_Synchronization_Behavior", + "Disabling test tracked SWDEV-391555", + "Unit_hipMemcpyPeer_Positive_ZeroSize", + "Unit_hipMemcpyPeerAsync_Positive_ZeroSize", + "Disabling test tracked SWDEV-391718", + "Unit_hipMemRangeGetAttribute_TstCountParam" ] + } diff --git a/catch/hipTestMain/config/config_amd_windows_common.json b/catch/hipTestMain/config/config_amd_windows_common.json index 0b898627e4..f9be07bda6 100644 --- a/catch/hipTestMain/config/config_amd_windows_common.json +++ b/catch/hipTestMain/config/config_amd_windows_common.json @@ -157,6 +157,11 @@ "SWDEV-396616 hipMemMap returns invalid error", "Unit_hipMemVmm_Basic", "SWDEV-396615 mGPUs not considered correctly", - "Unit_hipManagedKeyword_MultiGpu" + "Unit_hipManagedKeyword_MultiGpu", + "Disabling test tracked SWDEV-391555", + "Unit_hipMemcpyPeer_Positive_ZeroSize", + "Unit_hipMemcpyPeerAsync_Positive_ZeroSize", + "Disabling test tracked SWDEV-391718", + "Unit_hipMemRangeGetAttribute_TstCountParam" ] }