Files
TheRock/rocm-systems/projects/hip-tests/catch/unit/event/hipEventDestroy.cc
T
derek.holloway 7502bf64a4
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
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

151 lines
4.4 KiB
C++

/*
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
*
* SPDX-License-Identifier: MIT
*/
#include <chrono>
#include <hip_test_checkers.hh>
#include <hip_test_kernels.hh>
#include <hip_test_common.hh>
#include "hip/hip_runtime_api.h"
#include <utils.hh>
/**
* @addtogroup hipEventDestroy hipEventDestroy
* @{
* @ingroup EventTest
* `hipEventDestroy(hipEvent_t event)` -
* Destroy the specified event.
* ________________________
* Test cases from other modules:
* - @ref Unit_hipEventIpc
*/
static constexpr size_t vectorSize{1024};
/*
* 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<void**>(&A_d), A_h, 0));
HIP_CHECK(hipHostGetDevicePointer(reinterpret_cast<void**>(&B_d), B_h, 0));
HIP_CHECK(hipHostGetDevicePointer(reinterpret_cast<void**>(&C_d), C_h, 0));
LaunchDelayKernel(delay, stream);
HipTest::vectorADD<<<1, 1, 0, stream>>>(A_d, B_d, C_d, vectorSize);
}
/**
* Test Description
* ------------------------
* - Destroys the event before launched kernel has finished running.
* Test source
* ------------------------
* - unit/event/hipEventDestroy.cc
* Test requirements
* ------------------------
* - Platform specific (AMD)
* - HIP_VERSION >= 5.2
*/
HIP_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(isQuickLevel() ? 100 : 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);
}
/**
* Test Description
* ------------------------
* - Destroys the event that is enqueued into a stream.
* Test source
* ------------------------
* - unit/event/hipEventDestroy.cc
* Test requirements
* ------------------------
* - Platform specific (AMD)
* - HIP_VERSION >= 5.2
*/
HIP_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 Description
* ------------------------
* - Validates handling of invalid arguments:
* -# When output pointer to the event is `nullptr`
* - Expected output: return `hipErrorInvalidResourceHandle`
* -# When event is destroyed twice
* - Expected output: return `hipErrorContextIsDestroyed`
* Test source
* ------------------------
* - unit/event/hipEventDestroy.cc
* Test requirements
* ------------------------
* - Platform specific (AMD)
* - HIP_VERSION >= 5.2
*/
HIP_TEST_CASE(Unit_hipEventDestroy_Negative) {
SECTION("Invalid Event") {
hipEvent_t event{nullptr};
HIP_CHECK_ERROR(hipEventDestroy(event), hipErrorInvalidResourceHandle);
}
}
HIP_TEST_CASE(Unit_hipEventDestroy_Verify_Capture) {
hipEvent_t event;
HIP_CHECK(hipEventCreate(&event));
REQUIRE(event != nullptr);
hipStream_t stream;
HIP_CHECK(hipStreamCreate(&stream));
hipStreamCaptureMode mode = GENERATE(hipStreamCaptureModeGlobal, hipStreamCaptureModeThreadLocal,
hipStreamCaptureModeRelaxed);
HIP_CHECK(hipStreamBeginCapture(stream, mode));
HIP_CHECK(hipEventDestroy(event));
hipGraph_t graph;
HIP_CHECK(hipStreamEndCapture(stream, &graph));
HIP_CHECK(hipGraphDestroy(graph));
HIP_CHECK(hipStreamDestroy(stream));
}
/**
* End doxygen group EventTest.
* @}
*/