Files
TheRock/rocm-systems/projects/hip-tests/catch/unit/graph/hipThreadExchangeStreamCaptureMode.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

143 lines
4.4 KiB
C++

/*
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
*
* SPDX-License-Identifier: MIT
*/
#include <hip_test_checkers.hh>
#include <hip_test_common.hh>
#include <hip_test_kernels.hh>
#include "stream_capture_common.hh"
/**
* @addtogroup hipThreadExchangeStreamCaptureMode
* hipThreadExchangeStreamCaptureMode
* @{
* @ingroup GraphTest
* `hipThreadExchangeStreamCaptureMode(hipStreamCaptureMode *mode)` -
* swaps the stream capture mode of a thread
*/
/* Local Function for swaping stream capture mode of a thread
*/
static void hipGraphLaunchWithMode(hipStream_t stream, hipStreamCaptureMode mode) {
constexpr size_t N = 1024;
size_t Nbytes = N * sizeof(float);
constexpr float fill_value = 5.0f;
hipGraph_t graph{nullptr};
hipGraphExec_t graphExec{nullptr};
LinearAllocGuard<float> A_h(LinearAllocs::malloc, Nbytes);
LinearAllocGuard<float> B_h(LinearAllocs::malloc, Nbytes);
LinearAllocGuard<float> A_d(LinearAllocs::hipMalloc, Nbytes);
LinearAllocGuard<float> B_d(LinearAllocs::hipMalloc, Nbytes);
float* C_d;
HIP_CHECK(hipThreadExchangeStreamCaptureMode(&mode));
HIP_CHECK(hipStreamBeginCapture(stream, mode));
captureSequenceLinear(A_h.host_ptr(), A_d.ptr(), B_h.host_ptr(), B_d.ptr(), N, stream);
captureSequenceCompute(A_d.ptr(), B_h.host_ptr(), B_d.ptr(), N, stream);
if (mode == hipStreamCaptureModeRelaxed) {
HIP_CHECK(hipMalloc(&C_d, Nbytes));
}
HIP_CHECK(hipStreamEndCapture(stream, &graph));
// Validate end capture is successful
REQUIRE(graph != nullptr);
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
std::fill_n(A_h.host_ptr(), N, fill_value);
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
// Validate the computation
ArrayFindIfNot(B_h.host_ptr(), fill_value * fill_value, N);
if (mode == hipStreamCaptureModeRelaxed) {
HIP_CHECK(hipFree(C_d));
}
HIP_CHECK(hipGraphExecDestroy(graphExec));
HIP_CHECK(hipGraphDestroy(graph));
}
void threadFuncCaptureMode(hipStream_t stream, hipStreamCaptureMode mode) {
hipGraphLaunchWithMode(stream, mode);
}
/**
* Test Description
* ------------------------
* - Test to verify basic functionality for API that swaps the stream capture
* mode of a thread. All combinations for main and other thread capture modes
* are tested
* Test source
* ------------------------
* - catch\unit\graph\hipThreadExchangeStreamCaptureMode.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.3
*/
HIP_TEST_CASE(Unit_hipThreadExchangeStreamCaptureMode_Positive_Functional) {
StreamGuard stream_guard(Streams::created);
hipStream_t stream = stream_guard.stream();
const hipStreamCaptureMode captureModeMain = GENERATE(
hipStreamCaptureModeGlobal, hipStreamCaptureModeThreadLocal, hipStreamCaptureModeRelaxed);
const hipStreamCaptureMode captureModeThread = GENERATE(
hipStreamCaptureModeGlobal, hipStreamCaptureModeThreadLocal, hipStreamCaptureModeRelaxed);
hipGraphLaunchWithMode(stream, captureModeMain);
std::thread t(threadFuncCaptureMode, stream, captureModeThread);
t.join();
}
/**
* Test Description
* ------------------------
* - Test to verify API behavior with invalid arguments:
* -# Mode as nullptr
* -# Mode as -1
* -# Mode as INT_MAX
* -# Mode other than existing 3 modes (hipStreamCaptureModeRelaxed + 1)
* Test source
* ------------------------
* - catch\unit\graph\hipThreadExchangeStreamCaptureMode.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.3
*/
#if HT_AMD // getting error in Cuda Setup
HIP_TEST_CASE(Unit_hipThreadExchangeStreamCaptureMode_Negative_Parameters) {
hipStreamCaptureMode mode;
SECTION("Pass Mode as nullptr") {
HIP_CHECK_ERROR(hipThreadExchangeStreamCaptureMode(nullptr), hipErrorInvalidValue);
}
SECTION("Pass Mode as -1") {
mode = hipStreamCaptureMode(-1);
HIP_CHECK_ERROR(hipThreadExchangeStreamCaptureMode(&mode), hipErrorInvalidValue);
}
SECTION("Pass Mode as INT_MAX") {
mode = hipStreamCaptureMode(INT_MAX);
HIP_CHECK_ERROR(hipThreadExchangeStreamCaptureMode(&mode), hipErrorInvalidValue);
}
SECTION("Pass Mode as hipStreamCaptureModeRelaxed + 1") {
mode = hipStreamCaptureMode(hipStreamCaptureModeRelaxed + 1);
HIP_CHECK_ERROR(hipThreadExchangeStreamCaptureMode(&mode), hipErrorInvalidValue);
}
}
#endif
/**
* End doxygen group GraphTest.
* @}
*/