Files
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

135 lines
4.4 KiB
C++

/*
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
*
* SPDX-License-Identifier: MIT
*/
// TODO Enable it after hipStreamAttachMemAsync is feature complete on HIP
#include <hip_test_common.hh>
#include <memory>
__device__ __managed__ int var = 0;
enum class StreamAttachTestType { NullStream = 0, StreamPerThread, CreatedStream };
HIP_TEST_CASE(Unit_hipStreamAttachMemAsync_Negative) {
CHECK_MANAGED_MEMORY_SUPPORT
hipStream_t stream{nullptr};
auto streamType =
GENERATE(StreamAttachTestType::NullStream, StreamAttachTestType::StreamPerThread,
StreamAttachTestType::CreatedStream);
if (streamType == StreamAttachTestType::StreamPerThread) {
stream = hipStreamPerThread;
} else if (streamType == StreamAttachTestType::CreatedStream) {
HIP_CHECK(hipStreamCreate(&stream));
REQUIRE(stream != nullptr);
}
SECTION("Invalid Resource Handle") {
int definitelyNotAManagedVariable = 0;
HIP_CHECK_ERROR(
hipStreamAttachMemAsync(stream, reinterpret_cast<hipDeviceptr_t*>(&definitelyNotAManagedVariable),
sizeof(int), hipMemAttachSingle),
hipErrorInvalidValue);
}
SECTION("Invalid devptr") {
HIP_CHECK_ERROR(hipStreamAttachMemAsync(stream, nullptr, sizeof(int), hipMemAttachSingle),
hipErrorInvalidValue);
}
SECTION("Invalid Resource Size") {
HIP_CHECK_ERROR(hipStreamAttachMemAsync(stream, reinterpret_cast<hipDeviceptr_t*>(&var), sizeof(int) - 1,
hipMemAttachSingle),
hipErrorInvalidValue);
}
SECTION("Invalid Flags") {
HIP_CHECK_ERROR(
hipStreamAttachMemAsync(stream, reinterpret_cast<hipDeviceptr_t*>(&var), sizeof(int) - 1,
hipMemAttachSingle | hipMemAttachHost | hipMemAttachGlobal),
hipErrorInvalidValue);
}
if (streamType == StreamAttachTestType::CreatedStream) {
HIP_CHECK(hipStreamDestroy(stream));
}
}
__global__ void kernel(int* ptr, size_t size) {
auto i = threadIdx.x;
if (i < size) {
ptr[i] = 1024;
}
}
constexpr size_t size = 1024;
__device__ __managed__ int m_memory[size];
HIP_TEST_CASE(Unit_hipStreamAttachMemAsync_UseCase) {
CHECK_MANAGED_MEMORY_SUPPORT
hipStream_t stream{nullptr};
auto streamType =
GENERATE(StreamAttachTestType::NullStream, StreamAttachTestType::StreamPerThread,
StreamAttachTestType::CreatedStream);
if (streamType == StreamAttachTestType::CreatedStream) {
HIP_CHECK(hipStreamCreate(&stream));
REQUIRE(stream != nullptr);
}
SECTION("Size zero is valid") {
int* d_memory{nullptr};
HIP_CHECK(hipMallocManaged(&d_memory, sizeof(int) * size, hipMemAttachHost));
HIP_CHECK(
hipStreamAttachMemAsync(stream, reinterpret_cast<hipDeviceptr_t*>(d_memory), 0, hipMemAttachHost));
HIP_CHECK(hipStreamSynchronize(stream)); // Wait for command to complete
HIP_CHECK(hipFree(d_memory));
}
SECTION("Access from device and host") {
int* d_memory{nullptr};
HIP_CHECK(hipMallocManaged(&d_memory, sizeof(int) * size, hipMemAttachHost));
HIP_CHECK(hipMemset(d_memory, 0, sizeof(int) * size));
HIP_CHECK(
hipStreamAttachMemAsync(stream, reinterpret_cast<hipDeviceptr_t*>(d_memory), 0, hipMemAttachHost));
HIP_CHECK(hipStreamSynchronize(stream)); // Wait for the command to complete
kernel<<<1, size, 0, stream>>>(d_memory, size);
HIP_CHECK(hipStreamSynchronize(stream)); // Wait for the kernel to complete
auto ptr = std::make_unique<int[]>(size);
std::copy(d_memory, d_memory + size, ptr.get());
HIP_CHECK(hipFree(d_memory));
REQUIRE(std::all_of(ptr.get(), ptr.get() + size, [](int n) { return n == size; }));
}
SECTION("Access ManagedMemory") {
HIP_CHECK(hipMemset(m_memory, 0, sizeof(int) * size));
HIP_CHECK(
hipStreamAttachMemAsync(stream, reinterpret_cast<hipDeviceptr_t*>(m_memory), 0, hipMemAttachHost));
HIP_CHECK(hipStreamSynchronize(stream)); // Wait for the command to complete
kernel<<<1, size, 0, stream>>>(m_memory, size);
HIP_CHECK(hipStreamSynchronize(stream)); // Wait for the kernel to complete
auto ptr = std::make_unique<int[]>(size);
std::copy(m_memory, m_memory + size, ptr.get());
REQUIRE(std::all_of(ptr.get(), ptr.get() + size, [](int n) { return n == size; }));
}
if (streamType == StreamAttachTestType::CreatedStream) {
HIP_CHECK(hipStreamDestroy(stream));
}
}