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

312 lines
12 KiB
C++

/*
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
*
* SPDX-License-Identifier: MIT
*/
#pragma clang diagnostic ignored "-Wunused-parameter"
#include <hip_test_common.hh>
#include <hip_array_common.hh>
#include <hip_test_checkers.hh>
#include <hip_texture_helper.hh>
// #define DEBUG_DATA
template <typename TestType>
__global__ void simpleKernelLayered1DArray(hipTextureObject_t tex, TestType* outputData,
unsigned int width, unsigned int layer) {
#if !__HIP_NO_IMAGE_SUPPORT
unsigned int x = blockIdx.x * blockDim.x + threadIdx.x;
outputData[layer * width + x] = tex1DLayered<TestType>(tex, x, layer);
#endif
}
/**
* Test Description
* ------------------------
* - The suite will test host buffer copied to/from layered 1D array in following steps,
allocating a host buffer,
creating layered array,
copying host buffer to the layered array in two ways,
copying whole host buffer to the layered array,
copying host buffer layer by layer to the layered array and then
copying & verifying layer data,
creating a texture object on the layered array,
getting the data from the texture object in kernel,
verifing the data in host
* Test source
* ------------------------
* - catch\unit\texture\hipSimpleTexture1DLayered.cc
* Test requirements
* ------------------------
* - Host specific (WINDOWS and LINUX)
* - Layered 1D array supported on device
* - Textures supported on device
* - HIP_VERSION >= 6.0
*/
HIP_TEMPLATE_TEST_CASE(Unit_Layered1DTexture_Check_HostBufferToFromLayered1DArray, char,
unsigned char, short, ushort, int, uint, float, char1, uchar1, short1, ushort1,
int1, uint1, float1, char2, uchar2, short2, ushort2, int2, uint2, float2, char4,
uchar4, short4, ushort4, int4, uint4, float4) {
CHECK_IMAGE_SUPPORT
constexpr int SIZE = 512;
constexpr int num_layers = 5;
constexpr unsigned int width = SIZE;
constexpr unsigned int size = width * num_layers * sizeof(TestType);
TestType* hData = reinterpret_cast<TestType*>(malloc(size));
REQUIRE(hData != nullptr);
memset(hData, 0, size);
for (unsigned int layer = 0; layer < num_layers; layer++) {
for (unsigned int i = 0; i < width; i++) {
initVal(hData[layer * width + i]);
}
}
hipChannelFormatDesc channelDesc;
// Allocate array and copy image data
channelDesc = hipCreateChannelDesc<TestType>();
hipArray_t arr;
HIP_CHECK(
hipMalloc3DArray(&arr, &channelDesc, make_hipExtent(width, 0, num_layers), hipArrayLayered));
hipMemcpy3DParms myparms{};
SECTION("hipMemcpy3D whole layers") {
myparms.srcPos = make_hipPos(0, 0, 0);
myparms.dstPos = make_hipPos(0, 0, 0);
myparms.srcPtr = make_hipPitchedPtr(hData, width * sizeof(TestType), width, 1);
myparms.dstArray = arr;
myparms.extent = make_hipExtent(width, 1, num_layers);
myparms.kind = hipMemcpyHostToDevice;
HIP_CHECK(hipMemcpy3D(&myparms));
}
SECTION("hipMemcpy3D layer by layer") {
constexpr unsigned int layerSize = width * sizeof(TestType);
TestType* hLayerData = reinterpret_cast<TestType*>(malloc(layerSize));
REQUIRE(hLayerData != nullptr);
for (unsigned int layer = 0; layer < num_layers; layer++) {
// Copy buffer layer to image layer
memset(hLayerData, 0, layerSize);
memset(&myparms, 0, sizeof(myparms));
myparms.srcPos = make_hipPos(0, 0, layer);
myparms.dstPos = make_hipPos(0, 0, layer);
myparms.srcPtr = make_hipPitchedPtr(hData, width * sizeof(TestType), width, 1);
myparms.dstArray = arr;
myparms.extent = make_hipExtent(width, 1, 1);
myparms.kind = hipMemcpyHostToDevice;
HIP_CHECK(hipMemcpy3D(&myparms));
// Copy image layer to buffer layer
memset(&myparms, 0, sizeof(myparms));
myparms.srcPos = make_hipPos(0, 0, layer);
myparms.dstPos = make_hipPos(0, 0, 0);
myparms.srcArray = arr;
myparms.dstPtr = make_hipPitchedPtr(hLayerData, width * sizeof(TestType), width, 1);
myparms.extent = make_hipExtent(width, 1, 1);
myparms.kind = hipMemcpyDeviceToHost;
HIP_CHECK(hipMemcpy3D(&myparms));
// Compare layer
#ifdef DEBUG_DATA
for (unsigned int i = 0; i < width; i++) {
fprintf(stderr, "%4u: %u: %s -- %s\n", layer, i, getString(hData[layer * width + i]),
getString(hLayerData[i]));
}
#endif
REQUIRE(HipTest::checkArray(hData + layer * width, hLayerData, width, 1, 1));
}
free(hLayerData);
}
hipTextureObject_t tex;
hipResourceDesc texRes;
memset(&texRes, 0, sizeof(hipResourceDesc));
texRes.resType = hipResourceTypeArray;
texRes.res.array.array = arr;
hipTextureDesc texDescr;
memset(&texDescr, 0, sizeof(hipTextureDesc));
texDescr.normalizedCoords = 0;
texDescr.filterMode = hipFilterModePoint;
texDescr.addressMode[0] = hipAddressModeClamp;
texDescr.addressMode[1] = hipAddressModeClamp;
texDescr.addressMode[2] = hipAddressModeClamp;
texDescr.readMode = hipReadModeElementType;
HIP_CHECK(hipCreateTextureObject(&tex, &texRes, &texDescr, NULL));
// Allocate device memory for result
TestType* dData = nullptr;
HIP_CHECK(hipMalloc(&dData, size));
dim3 dimBlock(8);
dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x);
for (unsigned int layer = 0; layer < num_layers; layer++) {
hipLaunchKernelGGL(simpleKernelLayered1DArray<TestType>, dimGrid, dimBlock, 0, 0, tex, dData,
width, layer);
HIP_CHECK(hipGetLastError());
}
HIP_CHECK(hipDeviceSynchronize());
// Allocate mem for the result on host side
TestType* hOutputData = reinterpret_cast<TestType*>(malloc(size));
REQUIRE(hOutputData != nullptr);
// Copy result from device to host
HIP_CHECK(hipMemcpy(hOutputData, dData, size, hipMemcpyDeviceToHost));
REQUIRE(HipTest::checkArray(hData, hOutputData, width, 1, num_layers));
HIP_CHECK(hipFree(dData));
HIP_CHECK(hipFreeArray(arr));
free(hData);
free(hOutputData);
HIP_CHECK(hipDestroyTextureObject(tex));
}
/**
* Test Description
* ------------------------
* - The suite will test device buffer copied to/from layered 1D array in following steps,
allocating host buffer,
allocating device buffer,
copying host buffer to device buffer,
creating layered array,
copying device buffer to the layered array in two ways,
copying whole device buffer to the layered array,
copying device buffer layer by layer to the layered array and then
copying & verifying layer data,
creating a texture object on the layered array,
getting the data from the texture object in kernel,
verifing the data in host
* Test source
* ------------------------
* - catch\unit\texture\hipSimpleTexture1DLayered.cc
* Test requirements
* ------------------------
* - Host specific (WINDOWS and LINUX)
* - Layered 1D array supported on device
* - Textures supported on device
* - HIP_VERSION >= 6.0
*/
HIP_TEMPLATE_TEST_CASE(Unit_Layered1DTexture_Check_DeviceBufferToFromLayered1DArray, char,
unsigned char, short, ushort, int, uint, float, char1, uchar1, short1, ushort1,
int1, uint1, float1, char2, uchar2, short2, ushort2, int2, uint2, float2, char4,
uchar4, short4, ushort4, int4, uint4, float4) {
CHECK_IMAGE_SUPPORT
constexpr int SIZE = 512;
constexpr int num_layers = 5;
constexpr unsigned int width = SIZE;
constexpr unsigned int size = width * num_layers * sizeof(TestType);
TestType* hData = reinterpret_cast<TestType*>(malloc(size));
memset(hData, 0, size);
for (unsigned int layer = 0; layer < num_layers; layer++) {
for (unsigned int i = 0; i < width; i++) {
initVal(hData[layer * width + i]);
}
}
TestType* dData = nullptr;
HIP_CHECK(hipMalloc(&dData, size));
HIP_CHECK(hipMemcpy(dData, hData, size, hipMemcpyHostToDevice));
hipChannelFormatDesc channelDesc;
// Allocate array and copy image data
channelDesc = hipCreateChannelDesc<TestType>();
hipArray_t arr;
HIP_CHECK(
hipMalloc3DArray(&arr, &channelDesc, make_hipExtent(width, 0, num_layers), hipArrayLayered));
hipMemcpy3DParms myparms{};
SECTION("hipMemcpy3D whole layers") {
myparms.srcPos = make_hipPos(0, 0, 0);
myparms.dstPos = make_hipPos(0, 0, 0);
myparms.srcPtr = make_hipPitchedPtr(dData, width * sizeof(TestType), width, 1);
myparms.dstArray = arr;
myparms.extent = make_hipExtent(width, 1, num_layers);
myparms.kind = hipMemcpyDeviceToDevice;
HIP_CHECK(hipMemcpy3D(&myparms));
}
SECTION("hipMemcpy3D layer by layer") {
constexpr unsigned int layerSize = width * sizeof(TestType);
TestType* hLayerData = reinterpret_cast<TestType*>(malloc(layerSize));
REQUIRE(hLayerData != nullptr);
TestType* dData1 = nullptr;
HIP_CHECK(hipMalloc(&dData1, size));
HIP_CHECK(hipMemset(dData1, 0, size));
for (unsigned int layer = 0; layer < num_layers; layer++) {
// Copy buffer layer to image layer
memset(hLayerData, 0, layerSize);
memset(&myparms, 0, sizeof(myparms));
myparms.srcPos = make_hipPos(0, 0, layer);
myparms.dstPos = make_hipPos(0, 0, layer);
myparms.srcPtr = make_hipPitchedPtr(dData, width * sizeof(TestType), width, 1);
myparms.kind = hipMemcpyDeviceToDevice;
myparms.dstArray = arr;
myparms.extent = make_hipExtent(width, 1, 1);
HIP_CHECK(hipMemcpy3D(&myparms));
// Copy image layer to buffer layer
memset(&myparms, 0, sizeof(myparms));
myparms.srcPos = make_hipPos(0, 0, layer);
myparms.dstPos = make_hipPos(0, 0, layer);
myparms.srcArray = arr;
myparms.dstPtr = make_hipPitchedPtr(dData1, width * sizeof(TestType), width, 1);
myparms.extent = make_hipExtent(width, 1, 1);
myparms.kind = hipMemcpyDeviceToDevice;
HIP_CHECK(hipMemcpy3D(&myparms));
HIP_CHECK(hipMemcpy(hLayerData, dData1 + layer * width, layerSize, hipMemcpyDeviceToHost));
// Compare layer
#ifdef DEBUG_DATA
for (unsigned int i = 0; i < width; i++) {
fprintf(stderr, "%4u: %u: %s -- %s\n", layer, i,
getString(hData[layer * width + i]).c_str(), getString(hLayerData[i]).c_str());
}
#endif
REQUIRE(HipTest::checkArray(hData + layer * width, hLayerData, width, 1, 1));
}
free(hLayerData);
HIP_CHECK(hipFree(dData1));
}
hipTextureObject_t tex;
hipResourceDesc texRes;
memset(&texRes, 0, sizeof(hipResourceDesc));
texRes.resType = hipResourceTypeArray;
texRes.res.array.array = arr;
hipTextureDesc texDescr;
memset(&texDescr, 0, sizeof(hipTextureDesc));
texDescr.normalizedCoords = 0;
texDescr.filterMode = hipFilterModePoint;
texDescr.addressMode[0] = hipAddressModeClamp;
texDescr.addressMode[1] = hipAddressModeClamp;
texDescr.addressMode[2] = hipAddressModeClamp;
texDescr.readMode = hipReadModeElementType;
HIP_CHECK(hipCreateTextureObject(&tex, &texRes, &texDescr, NULL));
HIP_CHECK(hipMemset(dData, 0, size));
dim3 dimBlock(8);
dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x);
for (unsigned int layer = 0; layer < num_layers; layer++) {
hipLaunchKernelGGL(simpleKernelLayered1DArray<TestType>, dimGrid, dimBlock, 0, 0, tex, dData,
width, layer);
HIP_CHECK(hipGetLastError());
}
HIP_CHECK(hipDeviceSynchronize());
// Allocate mem for the result on host side
TestType* hOutputData = reinterpret_cast<TestType*>(malloc(size));
REQUIRE(hOutputData != nullptr);
// Copy result from device to host
HIP_CHECK(hipMemcpy(hOutputData, dData, size, hipMemcpyDeviceToHost));
REQUIRE(HipTest::checkArray(hData, hOutputData, width, 1, num_layers));
HIP_CHECK(hipFree(dData));
HIP_CHECK(hipFreeArray(arr));
free(hData);
free(hOutputData);
HIP_CHECK(hipDestroyTextureObject(tex));
}