From 2a1b2b993d379a710dc8b5ad8a788f34ebd6f74b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio?= Date: Fri, 5 Aug 2022 06:30:06 +0100 Subject: [PATCH] EXSWCPHIPT-105: Add testing for hipEventDestroy (#2727) --- catch/unit/event/CMakeLists.txt | 1 + catch/unit/event/hipEventDestroy.cc | 115 ++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 catch/unit/event/hipEventDestroy.cc diff --git a/catch/unit/event/CMakeLists.txt b/catch/unit/event/CMakeLists.txt index bbcc2c9fa4..30d5a4155b 100644 --- a/catch/unit/event/CMakeLists.txt +++ b/catch/unit/event/CMakeLists.txt @@ -5,6 +5,7 @@ set(TEST_SRC Unit_hipEventElapsedTime.cc Unit_hipEventRecord.cc Unit_hipEventIpc.cc + hipEventDestroy.cc ) # The test used wait mechanism and doesnt play well with all arch of nvidia diff --git a/catch/unit/event/hipEventDestroy.cc b/catch/unit/event/hipEventDestroy.cc new file mode 100644 index 0000000000..23cb17bed5 --- /dev/null +++ b/catch/unit/event/hipEventDestroy.cc @@ -0,0 +1,115 @@ +/* +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. +*/ + +#include +#include +#include +#include +#include "hip/hip_runtime_api.h" + +#if HT_AMD /* Disabled because frequency based wait is timing out on nvidia platforms */ + +static constexpr size_t vectorSize{1024}; + +/** + * @brief Launches vectorAdd kernel with a delay + */ +static inline void launchVectorAdd(float*& A_h, float*& B_h, float*& C_h, + std::chrono::milliseconds delay, hipStream_t stream = nullptr) { + float* A_d{nullptr}; + float* B_d{nullptr}; + float* C_d{nullptr}; + HipTest::initArraysForHost(&A_h, &B_h, &C_h, vectorSize, true); + HIP_CHECK(hipHostGetDevicePointer(reinterpret_cast(&A_d), A_h, 0)); + HIP_CHECK(hipHostGetDevicePointer(reinterpret_cast(&B_d), B_h, 0)); + HIP_CHECK(hipHostGetDevicePointer(reinterpret_cast(&C_d), C_h, 0)); + HipTest::runKernelForDuration(delay, stream); + HipTest::vectorADD<<<1, 1, 0, stream>>>(A_d, B_d, C_d, vectorSize); +} + + +/** + * @brief Check that destroying an event before the kernel has finished running causes no errors. + * + */ +TEST_CASE("Unit_hipEventDestroy_Unfinished") { + hipEvent_t event; + + HIP_CHECK(hipEventCreate(&event)); + + float *A_h, *B_h, *C_h; + launchVectorAdd(A_h, B_h, C_h, std::chrono::milliseconds(1000)); + + HIP_CHECK(hipEventRecord(event)); + HIP_CHECK_ERROR(hipEventQuery(event), hipErrorNotReady); + HIP_CHECK(hipEventDestroy(event)); + + HIP_CHECK(hipDeviceSynchronize()); + HipTest::checkVectorADD(A_h, B_h, C_h, vectorSize); + HipTest::freeArraysForHost(A_h, B_h, C_h, true); +} + +/** + * @brief Check that destroying an event enqueued to a stream causes no errors. + * + */ +TEST_CASE("Unit_hipEventDestroy_WithWaitingStream") { + hipEvent_t event; + HIP_CHECK(hipEventCreate(&event)); + + hipStream_t stream; + HIP_CHECK(hipStreamCreate(&stream)); + + float *A_h, *B_h, *C_h; + launchVectorAdd(A_h, B_h, C_h, std::chrono::milliseconds(1000), stream); + + HIP_CHECK(hipEventRecord(event, stream)); + HIP_CHECK_ERROR(hipEventQuery(event), hipErrorNotReady); + HIP_CHECK_ERROR(hipStreamQuery(stream), hipErrorNotReady); + HIP_CHECK(hipEventDestroy(event)); + HIP_CHECK_ERROR(hipStreamQuery(stream), hipErrorNotReady); + HIP_CHECK(hipStreamSynchronize(stream)); + HIP_CHECK(hipStreamDestroy(stream)); + + HipTest::checkVectorADD(A_h, B_h, C_h, vectorSize); + HipTest::freeArraysForHost(A_h, B_h, C_h, true); +} + +TEST_CASE("Unit_hipEventDestroy_Negative") { +#if HT_AMD + HipTest::HIP_SKIP_TEST("EXSWCPHIPT-103"); + return; +#endif + + SECTION("Invalid Event") { + hipEvent_t event{nullptr}; + HIP_CHECK_ERROR(hipEventDestroy(event), hipErrorInvalidResourceHandle); + } + + SECTION("Destroy twice") { + hipEvent_t event; + HIP_CHECK(hipEventCreate(&event)); + HIP_CHECK(hipEventDestroy(event)); + HIP_CHECK_ERROR(hipEventDestroy(event), hipErrorContextIsDestroyed); + } +} +#endif