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

132 lines
3.9 KiB
C++

/*
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
*
* SPDX-License-Identifier: MIT
*/
#include <hip_test_common.hh>
#include <hip_test_helper.hh>
#include <utils.hh>
static constexpr unsigned int N = 2 * 1024 * 1024;
static constexpr size_t NBYTES = N * sizeof(int);
/**
* Local Function to fill the array with given value
*/
static void fillArr(int* arr, unsigned int size, int value) {
for (int i = 0; i < size; i++) {
arr[i] = value;
}
}
/**
* Test Description
* ------------------------
* - This test, tests the following scenario with per thread compiler option:-
* - Do Memory copy Asynchronously H2D in Legacy stream
* - and do Memory copy Asynchronously D2H in Legacy stream.
* - The task 2 should wait till the execution of task 1.
* - Even it is compiled with stream per thread, since one stream for both
* - these should be in sync.
* Test source
* ------------------------
* - unit/stream/hipStreamLegacy_compiler_options.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 6.3
*/
HIP_TEST_CASE(Unit_hipStreamLegacy_WithSptCompilerOption) {
int* hostArrSrc = new int[N];
REQUIRE(hostArrSrc != nullptr);
fillArr(hostArrSrc, N, 1);
int* devArr = nullptr;
HIP_CHECK(hipMalloc(&devArr, NBYTES));
REQUIRE(devArr != nullptr);
int* hostArrDst = new int[N];
REQUIRE(hostArrDst != nullptr);
fillArr(hostArrDst, N, 3);
HIP_CHECK(hipMemcpyAsync(devArr, hostArrSrc, NBYTES, hipMemcpyHostToDevice, hipStreamLegacy));
HIP_CHECK(hipMemcpyAsync(hostArrDst, devArr, NBYTES, hipMemcpyDeviceToHost, hipStreamLegacy));
HIP_CHECK(hipStreamSynchronize(hipStreamLegacy));
for (int i = 0; i < N; i++) {
INFO("At index : " << i << " Got value : " << hostArrDst[i] << " Expected value : 1 \n");
REQUIRE(hostArrDst[i] == 1);
}
delete[] hostArrSrc;
delete[] hostArrDst;
HIP_CHECK(hipFree(devArr));
}
/*
* Local helper function to copy data from host to device
*/
static void copyHostToDevice(int* hostArr, int* devArr) {
HIP_CHECK(hipMemcpyAsync(devArr, hostArr, NBYTES, hipMemcpyHostToDevice, hipStreamLegacy));
}
/*
* Local helper function to copy data from device to host
*/
static void copyDeviceToHost(int* devArr, int* hostArr) {
HIP_CHECK(hipMemcpyAsync(hostArr, devArr, NBYTES, hipMemcpyDeviceToHost, hipStreamLegacy));
}
/**
* Test Description
* ------------------------
* - This test, tests the following scenario with per thread compiler option:-
* - Launch two threads,
* - In thread 1 : H -> D Copy
* - In thread 2 : D -> H Copy
* - These two threads should run successfully and update the data.
* - Note : Joined first thread before launching second thread to avoid,
* - the scenario of second thread can be launched before first
* - thread while scheduling.
* Test source
* ------------------------
* - unit/stream/hipStreamLegacy_compiler_options.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 6.3
*/
HIP_TEST_CASE(Unit_hipStreamLegacy_TwoThreadsDiffOperationWithSptCompOption) {
const unsigned int threadsSupported = std::thread::hardware_concurrency();
if (threadsSupported < 2) {
HIP_SKIP_TEST("Skipping due to machine doesn't support two concurrent threads");
}
int* hostArrSrc = new int[N];
REQUIRE(hostArrSrc != nullptr);
fillArr(hostArrSrc, N, 50);
int* devArr = nullptr;
HIP_CHECK(hipMalloc(&devArr, NBYTES));
REQUIRE(devArr != nullptr);
int* hostArrDst = new int[N];
REQUIRE(hostArrDst != nullptr);
fillArr(hostArrDst, N, 52);
std::thread H2D_Thread(copyHostToDevice, hostArrSrc, devArr);
H2D_Thread.join();
std::thread D2H_Thread(copyDeviceToHost, devArr, hostArrDst);
D2H_Thread.join();
HIP_CHECK(hipStreamSynchronize(hipStreamLegacy));
for (int i = 0; i < N; i++) {
INFO("At index : " << i << " Got value : " << hostArrDst[i] << " Expected value : 50 \n");
REQUIRE(hostArrDst[i] == 50);
}
delete[] hostArrSrc;
delete[] hostArrDst;
HIP_CHECK(hipFree(devArr));
}