From 594d42670b3e2e1a70e9db2939fdf0dc1078b855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mirza=20Halil=C4=8Devi=C4=87?= <109971222+mirza-halilcevic@users.noreply.github.com> Date: Thu, 28 Dec 2023 14:04:09 +0100 Subject: [PATCH] EXSWHTEC-381 - Implement tests for Surface Object device functions #453 Change-Id: I750ac29781637187d59ad0a2291a1d400f97cd83 [ROCm/hip-tests commit: e0c3f64e78641d002773f0b9abe74299ee92bbf3] --- .../catch/unit/surface/CMakeLists.txt | 15 +- .../surface/{hipSurfaceObj1D.cc => surf1D.cc} | 214 +++++------ .../catch/unit/surface/surf1DLayered.cc | 294 +++++++++++++++ .../surface/{hipSurfaceObj2D.cc => surf2D.cc} | 273 +++++++------- .../catch/unit/surface/surf2DLayered.cc | 338 +++++++++++++++++ .../surface/{hipSurfaceObj3D.cc => surf3D.cc} | 248 ++++++------- .../catch/unit/surface/surfCubemap.cc | 338 +++++++++++++++++ .../catch/unit/surface/surfCubemapLayered.cc | 340 ++++++++++++++++++ 8 files changed, 1654 insertions(+), 406 deletions(-) rename projects/hip-tests/catch/unit/surface/{hipSurfaceObj1D.cc => surf1D.cc} (60%) create mode 100644 projects/hip-tests/catch/unit/surface/surf1DLayered.cc rename projects/hip-tests/catch/unit/surface/{hipSurfaceObj2D.cc => surf2D.cc} (55%) create mode 100644 projects/hip-tests/catch/unit/surface/surf2DLayered.cc rename projects/hip-tests/catch/unit/surface/{hipSurfaceObj3D.cc => surf3D.cc} (64%) create mode 100644 projects/hip-tests/catch/unit/surface/surfCubemap.cc create mode 100644 projects/hip-tests/catch/unit/surface/surfCubemapLayered.cc diff --git a/projects/hip-tests/catch/unit/surface/CMakeLists.txt b/projects/hip-tests/catch/unit/surface/CMakeLists.txt index d2afb5c702..43c7eee343 100644 --- a/projects/hip-tests/catch/unit/surface/CMakeLists.txt +++ b/projects/hip-tests/catch/unit/surface/CMakeLists.txt @@ -20,13 +20,22 @@ # Common Tests - Test independent of all platforms set(TEST_SRC - hipSurfaceObj1D.cc - hipSurfaceObj2D.cc - hipSurfaceObj3D.cc hipCreateSurfaceObject.cc hipDestroySurfaceObject.cc + surf1D.cc + surf1DLayered.cc + surf2D.cc + surf2DLayered.cc + surf3D.cc + surfCubemap.cc ) +if(HIP_PLATFORM MATCHES "nvidia") # Disabled on AMD due to defect EXSWHTEC-377 +set(TEST_SRC + ${TEST_SRC} + surfCubemapLayered.cc) +endif() + hip_add_exe_to_target(NAME SurfaceTest TEST_SRC ${TEST_SRC} TEST_TARGET_NAME build_tests) \ No newline at end of file diff --git a/projects/hip-tests/catch/unit/surface/hipSurfaceObj1D.cc b/projects/hip-tests/catch/unit/surface/surf1D.cc similarity index 60% rename from projects/hip-tests/catch/unit/surface/hipSurfaceObj1D.cc rename to projects/hip-tests/catch/unit/surface/surf1D.cc index 701a99666d..20286ef483 100644 --- a/projects/hip-tests/catch/unit/surface/hipSurfaceObj1D.cc +++ b/projects/hip-tests/catch/unit/surface/surf1D.cc @@ -1,13 +1,16 @@ /* Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved. + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -16,18 +19,22 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include + +/** + * @addtogroup surf1D surf1D + * @{ + * @ingroup SurfaceTest + */ + #include +#include #include #pragma clang diagnostic ignored "-Wunused-variable" #pragma clang diagnostic ignored "-Wunused-parameter" template -__global__ void -surf1DKernelR(hipSurfaceObject_t surfaceObject, - T* outputData, int width) -{ +__global__ void surf1DKernelR(hipSurfaceObject_t surfaceObject, T* outputData, int width) { #if !defined(__HIP_NO_IMAGE_SUPPORT) || !__HIP_NO_IMAGE_SUPPORT int x = blockIdx.x * blockDim.x + threadIdx.x; if (x < width) { @@ -37,10 +44,7 @@ surf1DKernelR(hipSurfaceObject_t surfaceObject, } template -__global__ void -surf1DKernelW(hipSurfaceObject_t surfaceObject, - T* inputData, int width) -{ +__global__ void surf1DKernelW(hipSurfaceObject_t surfaceObject, T* inputData, int width) { #if !defined(__HIP_NO_IMAGE_SUPPORT) || !__HIP_NO_IMAGE_SUPPORT int x = blockIdx.x * blockDim.x + threadIdx.x; if (x < width) { @@ -50,10 +54,8 @@ surf1DKernelW(hipSurfaceObject_t surfaceObject, } template -__global__ void -surf1DKernelRW(hipSurfaceObject_t surfaceObject, - hipSurfaceObject_t outputSurfObj, int width) -{ +__global__ void surf1DKernelRW(hipSurfaceObject_t surfaceObject, hipSurfaceObject_t outputSurfObj, + int width) { #if !defined(__HIP_NO_IMAGE_SUPPORT) || !__HIP_NO_IMAGE_SUPPORT int x = blockIdx.x * blockDim.x + threadIdx.x; if (x < width) { @@ -64,14 +66,11 @@ surf1DKernelRW(hipSurfaceObject_t surfaceObject, #endif } -template -static void runTestR(const int width) -{ +template static void runTestR(const int width) { unsigned int size = width * sizeof(T); - T *hData = (T*) malloc (size); + T* hData = (T*)malloc(size); memset(hData, 0, size); - for (int j = 0; j < width; j++) - { + for (int j = 0; j < width; j++) { initVal(hData[j]); } @@ -91,12 +90,12 @@ static void runTestR(const int width) hipSurfaceObject_t surfaceObject = 0; HIP_CHECK(hipCreateSurfaceObject(&surfaceObject, &resDesc)); - T *hOutputData = nullptr; + T* hOutputData = nullptr; HIP_CHECK(hipHostMalloc((void**)&hOutputData, size)); memset(hOutputData, 0, size); - dim3 dimBlock (16, 1, 1); - dim3 dimGrid ((width + dimBlock.x - 1) / dimBlock.x, 1, 1); + dim3 dimBlock(16, 1, 1); + dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x, 1, 1); surf1DKernelR<<>>(surfaceObject, hOutputData, width); @@ -105,8 +104,8 @@ static void runTestR(const int width) for (int j = 0; j < width; j++) { if (!isEqual(hData[j], hOutputData[j])) { - printf("Difference [ %d ]:%s ----%s\n", j, - getString(hData[j]).c_str(), getString(hOutputData[j]).c_str()); + printf("Difference [ %d ]:%s ----%s\n", j, getString(hData[j]).c_str(), + getString(hOutputData[j]).c_str()); REQUIRE(false); } } @@ -115,14 +114,11 @@ static void runTestR(const int width) HIP_CHECK(hipFreeArray(hipArray)); free(hData); HIP_CHECK(hipHostFree(hOutputData)); - REQUIRE(true); } -template -static void runTestW(const int width) -{ +template static void runTestW(const int width) { unsigned int size = width * sizeof(T); - T *hData = nullptr; + T* hData = nullptr; HIP_CHECK(hipHostMalloc((void**)&hData, size)); memset(hData, 0, size); @@ -142,27 +138,26 @@ static void runTestW(const int width) hipSurfaceObject_t surfaceObject = 0; HIP_CHECK(hipCreateSurfaceObject(&surfaceObject, &resDesc)); - for (int j = 0; j < width; j++) - { + for (int j = 0; j < width; j++) { initVal(hData[j]); } - dim3 dimBlock (16, 1, 1); - dim3 dimGrid ((width + dimBlock.x - 1) / dimBlock.x, 1, 1); + dim3 dimBlock(16, 1, 1); + dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x, 1, 1); surf1DKernelW<<>>(surfaceObject, hData, width); HIP_CHECK(hipGetLastError()); HIP_CHECK(hipDeviceSynchronize()); - T *hOutputData = (T*) malloc (size); + T* hOutputData = (T*)malloc(size); memset(hOutputData, 0, size); HIP_CHECK(hipMemcpyFromArray(hOutputData, hipArray, 0, 0, size, hipMemcpyDeviceToHost)); for (int j = 0; j < width; j++) { if (!isEqual(hData[j], hOutputData[j])) { - printf("Difference [ %d ]:%s ----%s\n", j, - getString(hData[j]).c_str(), getString(hOutputData[j]).c_str()); + printf("Difference [ %d ]:%s ----%s\n", j, getString(hData[j]).c_str(), + getString(hOutputData[j]).c_str()); REQUIRE(false); } } @@ -171,18 +166,13 @@ static void runTestW(const int width) HIP_CHECK(hipFreeArray(hipArray)); HIP_CHECK(hipHostFree(hData)); free(hOutputData); - REQUIRE(true); } - -template -static void runTestRW(const int width) -{ +template static void runTestRW(const int width) { unsigned int size = width * sizeof(T); - T *hData = (T*) malloc (size); + T* hData = (T*)malloc(size); memset(hData, 0, size); - for (int j = 0; j < width; j++) - { + for (int j = 0; j < width; j++) { initVal(hData[j]); } @@ -210,24 +200,24 @@ static void runTestRW(const int width) resOutDesc.res.array.array = hipOutArray; hipSurfaceObject_t outSurfaceObject = 0; - HIP_CHECK(hipCreateSurfaceObject (&outSurfaceObject, &resOutDesc)); + HIP_CHECK(hipCreateSurfaceObject(&outSurfaceObject, &resOutDesc)); - dim3 dimBlock (16, 1, 1); - dim3 dimGrid ((width + dimBlock.x - 1) / dimBlock.x, 1, 1); + dim3 dimBlock(16, 1, 1); + dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x, 1, 1); surf1DKernelRW<<>>(surfaceObject, outSurfaceObject, width); HIP_CHECK(hipGetLastError()); HIP_CHECK(hipDeviceSynchronize()); - T *hOutputData = (T*) malloc (size); + T* hOutputData = (T*)malloc(size); memset(hOutputData, 0, size); HIP_CHECK(hipMemcpyFromArray(hOutputData, hipOutArray, 0, 0, size, hipMemcpyDeviceToHost)); for (int j = 0; j < width; j++) { if (!isEqual(hData[j], hOutputData[j])) { - printf("Difference [ %d ]:%s ----%s\n", j, - getString(hData[j]).c_str(), getString(hOutputData[j]).c_str()); + printf("Difference [ %d ]:%s ----%s\n", j, getString(hData[j]).c_str(), + getString(hOutputData[j]).c_str()); REQUIRE(false); } } @@ -238,83 +228,67 @@ static void runTestRW(const int width) HIP_CHECK(hipFreeArray(hipOutArray)); free(hData); free(hOutputData); - REQUIRE(true); } -TEMPLATE_TEST_CASE("Unit_hipSurfaceObj1D_type_R", "", - char, uchar, 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 - auto err = hipGetLastError(); // reset last err due to previous negative tests +/** + * Test Description + * ------------------------ + * - Basic test for `surf1Dread` with different types and dimensions. + * Test source + * ------------------------ + * - unit/surface/surf1D.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.7 + */ +TEMPLATE_TEST_CASE("Unit_surf1Dread_Positive_Basic", "", char, uchar, 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; - SECTION("Unit_hipSurfaceObj1D_type_R - 31") { - runTestR(31); - } - - SECTION("Unit_hipSurfaceObj1D_type_R - 67") { - runTestR(67); - } - - SECTION("Unit_hipSurfaceObj1D_type_R - 131") { - runTestR(131); - } - - SECTION("Unit_hipSurfaceObj1D_type_R - 263") { - runTestR(263); - } + const int width = GENERATE(31, 67, 131, 263); + runTestR(width); } -TEMPLATE_TEST_CASE("Unit_hipSurfaceObj1D_type_W", "", - char, uchar, 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 - auto err = hipGetLastError(); // reset last err due to previous negative tests +/** + * Test Description + * ------------------------ + * - Basic test for `surf1Dwrite` with different types and dimensions. + * Test source + * ------------------------ + * - unit/surface/surf1D.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.7 + */ +TEMPLATE_TEST_CASE("Unit_surf1Dwrite_Positive_Basic", "", char, uchar, 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; - SECTION("Unit_hipSurfaceObj1D_type_W - 31") { - runTestW(31); - } - - SECTION("Unit_hipSurfaceObj1D_type_W - 63") { - runTestW(63); - } - - SECTION("Unit_hipSurfaceObj1D_type_W - 131") { - runTestW(131); - } - - SECTION("Unit_hipSurfaceObj1D_type_W - 263") { - runTestW(263); - } + const int width = GENERATE(31, 67, 131, 263); + runTestW(width); } -TEMPLATE_TEST_CASE("Unit_hipSurfaceObj1D_type_RW", "", - char, uchar, 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 - auto err = hipGetLastError(); // reset last err due to previous negative tests +/** + * Test Description + * ------------------------ + * - Basic test for `surf1Dread` and `surf1Dwrite` together, with different types and dimensions. + * Test source + * ------------------------ + * - unit/surface/surf1D.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.7 + */ +TEMPLATE_TEST_CASE("Unit_surf1D_Positive_ReadWrite", "", char, uchar, 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; - SECTION("Unit_hipSurfaceObj1D_type_RW - 23") { - runTestRW(23); - } - - SECTION("Unit_hipSurfaceObj1D_type_RW - 67") { - runTestRW(67); - } - - SECTION("Unit_hipSurfaceObj1D_type_RW - 131") { - runTestRW(131); - } - - SECTION("Unit_hipSurfaceObj1D_type_RW - 263") { - runTestRW(263); - } + const int width = GENERATE(31, 67, 131, 263); + runTestRW(width); } diff --git a/projects/hip-tests/catch/unit/surface/surf1DLayered.cc b/projects/hip-tests/catch/unit/surface/surf1DLayered.cc new file mode 100644 index 0000000000..3432524527 --- /dev/null +++ b/projects/hip-tests/catch/unit/surface/surf1DLayered.cc @@ -0,0 +1,294 @@ +/* +Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +/** + * @addtogroup surf1DLayered surf1DLayered + * @{ + * @ingroup SurfaceTest + */ + +#include +#include +#include + +#pragma clang diagnostic ignored "-Wunused-variable" +#pragma clang diagnostic ignored "-Wunused-parameter" + +template +__global__ void surf1DLayeredKernelR(hipSurfaceObject_t surfaceObject, T* outputData, int width) { +#if !defined(__HIP_NO_IMAGE_SUPPORT) || !__HIP_NO_IMAGE_SUPPORT + int x = blockIdx.x * blockDim.x + threadIdx.x; + if (x < width) { + surf1DLayeredread(outputData + x, surfaceObject, x * sizeof(T), 0); + } +#endif +} + +template +__global__ void surf1DLayeredKernelW(hipSurfaceObject_t surfaceObject, T* inputData, int width) { +#if !defined(__HIP_NO_IMAGE_SUPPORT) || !__HIP_NO_IMAGE_SUPPORT + int x = blockIdx.x * blockDim.x + threadIdx.x; + if (x < width) { + surf1DLayeredwrite(inputData[x], surfaceObject, x * sizeof(T), 0); + } +#endif +} + +template +__global__ void surf1DLayeredKernelRW(hipSurfaceObject_t surfaceObject, + hipSurfaceObject_t outputSurfObj, int width) { +#if !defined(__HIP_NO_IMAGE_SUPPORT) || !__HIP_NO_IMAGE_SUPPORT + int x = blockIdx.x * blockDim.x + threadIdx.x; + if (x < width) { + T data; + surf1DLayeredread(&data, surfaceObject, x * sizeof(T), 0); + surf1DLayeredwrite(data, outputSurfObj, x * sizeof(T), 0); + } +#endif +} + +template static void runTestR(const int width) { + unsigned int size = width * sizeof(T); + T* hData = (T*)malloc(size); + memset(hData, 0, size); + for (int j = 0; j < width; j++) { + initVal(hData[j]); + } + + hipChannelFormatDesc channelDesc = hipCreateChannelDesc(); + + hipArray_t hipArray = nullptr; + HIP_CHECK(hipMallocArray(&hipArray, &channelDesc, width, 0, hipArraySurfaceLoadStore)); + + HIP_CHECK(hipMemcpyToArray(hipArray, 0, 0, hData, size, hipMemcpyHostToDevice)); + + hipResourceDesc resDesc; + memset(&resDesc, 0, sizeof(resDesc)); + resDesc.resType = hipResourceTypeArray; + resDesc.res.array.array = hipArray; + + // Create surface object + hipSurfaceObject_t surfaceObject = 0; + HIP_CHECK(hipCreateSurfaceObject(&surfaceObject, &resDesc)); + + T* hOutputData = nullptr; + HIP_CHECK(hipHostMalloc((void**)&hOutputData, size)); + memset(hOutputData, 0, size); + + dim3 dimBlock(16, 1, 1); + dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x, 1, 1); + + surf1DLayeredKernelR<<>>(surfaceObject, hOutputData, width); + + HIP_CHECK(hipGetLastError()); + HIP_CHECK(hipDeviceSynchronize()); + + for (int j = 0; j < width; j++) { + if (!isEqual(hData[j], hOutputData[j])) { + printf("Difference [ %d ]:%s ----%s\n", j, getString(hData[j]).c_str(), + getString(hOutputData[j]).c_str()); + REQUIRE(false); + } + } + + HIP_CHECK(hipDestroySurfaceObject(surfaceObject)); + HIP_CHECK(hipFreeArray(hipArray)); + free(hData); + HIP_CHECK(hipHostFree(hOutputData)); +} + +template static void runTestW(const int width) { + unsigned int size = width * sizeof(T); + T* hData = nullptr; + HIP_CHECK(hipHostMalloc((void**)&hData, size)); + memset(hData, 0, size); + + hipChannelFormatDesc channelDesc = hipCreateChannelDesc(); + + hipArray_t hipArray = nullptr; + HIP_CHECK(hipMallocArray(&hipArray, &channelDesc, width, 0, hipArraySurfaceLoadStore)); + + HIP_CHECK(hipMemcpyToArray(hipArray, 0, 0, hData, size, hipMemcpyHostToDevice)); + + hipResourceDesc resDesc; + memset(&resDesc, 0, sizeof(resDesc)); + resDesc.resType = hipResourceTypeArray; + resDesc.res.array.array = hipArray; + + // Create surface object + hipSurfaceObject_t surfaceObject = 0; + HIP_CHECK(hipCreateSurfaceObject(&surfaceObject, &resDesc)); + + for (int j = 0; j < width; j++) { + initVal(hData[j]); + } + + dim3 dimBlock(16, 1, 1); + dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x, 1, 1); + + surf1DLayeredKernelW<<>>(surfaceObject, hData, width); + + HIP_CHECK(hipGetLastError()); + HIP_CHECK(hipDeviceSynchronize()); + + T* hOutputData = (T*)malloc(size); + memset(hOutputData, 0, size); + HIP_CHECK(hipMemcpyFromArray(hOutputData, hipArray, 0, 0, size, hipMemcpyDeviceToHost)); + + for (int j = 0; j < width; j++) { + if (!isEqual(hData[j], hOutputData[j])) { + printf("Difference [ %d ]:%s ----%s\n", j, getString(hData[j]).c_str(), + getString(hOutputData[j]).c_str()); + REQUIRE(false); + } + } + + HIP_CHECK(hipDestroySurfaceObject(surfaceObject)); + HIP_CHECK(hipFreeArray(hipArray)); + HIP_CHECK(hipHostFree(hData)); + free(hOutputData); +} + +template static void runTestRW(const int width) { + unsigned int size = width * sizeof(T); + T* hData = (T*)malloc(size); + memset(hData, 0, size); + for (int j = 0; j < width; j++) { + initVal(hData[j]); + } + + hipChannelFormatDesc channelDesc = hipCreateChannelDesc(); + + hipArray_t hipArray = nullptr, hipOutArray = nullptr; + HIP_CHECK(hipMallocArray(&hipArray, &channelDesc, width, 0, hipArraySurfaceLoadStore)); + + HIP_CHECK(hipMemcpyToArray(hipArray, 0, 0, hData, size, hipMemcpyHostToDevice)); + + hipResourceDesc resDesc; + memset(&resDesc, 0, sizeof(resDesc)); + resDesc.resType = hipResourceTypeArray; + resDesc.res.array.array = hipArray; + + // Create surface object + hipSurfaceObject_t surfaceObject = 0; + HIP_CHECK(hipCreateSurfaceObject(&surfaceObject, &resDesc)); + + HIP_CHECK(hipMallocArray(&hipOutArray, &channelDesc, width, 0, hipArraySurfaceLoadStore)); + + hipResourceDesc resOutDesc; + memset(&resOutDesc, 0, sizeof(resOutDesc)); + resOutDesc.resType = hipResourceTypeArray; + resOutDesc.res.array.array = hipOutArray; + + hipSurfaceObject_t outSurfaceObject = 0; + HIP_CHECK(hipCreateSurfaceObject(&outSurfaceObject, &resOutDesc)); + + dim3 dimBlock(16, 1, 1); + dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x, 1, 1); + + surf1DLayeredKernelRW<<>>(surfaceObject, outSurfaceObject, width); + + HIP_CHECK(hipGetLastError()); + HIP_CHECK(hipDeviceSynchronize()); + + T* hOutputData = (T*)malloc(size); + memset(hOutputData, 0, size); + HIP_CHECK(hipMemcpyFromArray(hOutputData, hipOutArray, 0, 0, size, hipMemcpyDeviceToHost)); + + for (int j = 0; j < width; j++) { + if (!isEqual(hData[j], hOutputData[j])) { + printf("Difference [ %d ]:%s ----%s\n", j, getString(hData[j]).c_str(), + getString(hOutputData[j]).c_str()); + REQUIRE(false); + } + } + + HIP_CHECK(hipDestroySurfaceObject(surfaceObject)); + HIP_CHECK(hipDestroySurfaceObject(outSurfaceObject)); + HIP_CHECK(hipFreeArray(hipArray)); + HIP_CHECK(hipFreeArray(hipOutArray)); + free(hData); + free(hOutputData); +} + +/** + * Test Description + * ------------------------ + * - Basic test for `surf1DLayeredread` with different types and dimensions. + * Test source + * ------------------------ + * - unit/surface/surf1DLayered.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.7 + */ +TEMPLATE_TEST_CASE("Unit_surf1DLayeredread_Positive_Basic", "", char, uchar, 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; + + const int width = GENERATE(31, 67, 131, 263); + runTestR(width); +} + +/** + * Test Description + * ------------------------ + * - Basic test for `surf1DLayeredwrite` with different types and dimensions. + * Test source + * ------------------------ + * - unit/surface/surf1DLayered.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.7 + */ +TEMPLATE_TEST_CASE("Unit_surf1DLayeredwrite_Positive_Basic", "", char, uchar, 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; + + const int width = GENERATE(31, 67, 131, 263); + runTestW(width); +} + +/** + * Test Description + * ------------------------ + * - Basic test for `surf1DLayeredread` and `surf1DLayeredwrite` together, with different types + * and dimensions. Test source + * ------------------------ + * - unit/surface/surf1DLayered.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.7 + */ +TEMPLATE_TEST_CASE("Unit_surf1DLayered_Positive_ReadWrite", "", char, uchar, 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; + + const int width = GENERATE(31, 67, 131, 263); + runTestRW(width); +} diff --git a/projects/hip-tests/catch/unit/surface/hipSurfaceObj2D.cc b/projects/hip-tests/catch/unit/surface/surf2D.cc similarity index 55% rename from projects/hip-tests/catch/unit/surface/hipSurfaceObj2D.cc rename to projects/hip-tests/catch/unit/surface/surf2D.cc index 1fdc0eee9e..ca504b178b 100644 --- a/projects/hip-tests/catch/unit/surface/hipSurfaceObj2D.cc +++ b/projects/hip-tests/catch/unit/surface/surf2D.cc @@ -1,13 +1,16 @@ /* Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved. + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -16,8 +19,15 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include + +/** + * @addtogroup surf2D surf2D + * @{ + * @ingroup SurfaceTest + */ + #include +#include #include #pragma clang diagnostic ignored "-Wunused-variable" @@ -26,10 +36,8 @@ THE SOFTWARE. #define LOG_DATA 0 template -__global__ void -surf2DKernelR(hipSurfaceObject_t surfaceObject, - T* outputData, int width, int height) -{ +__global__ void surf2DKernelR(hipSurfaceObject_t surfaceObject, T* outputData, int width, + int height) { #if !defined(__HIP_NO_IMAGE_SUPPORT) || !__HIP_NO_IMAGE_SUPPORT int x = blockIdx.x * blockDim.x + threadIdx.x; int y = blockIdx.y * blockDim.y + threadIdx.y; @@ -40,10 +48,8 @@ surf2DKernelR(hipSurfaceObject_t surfaceObject, } template -__global__ void -surf2DKernelW(hipSurfaceObject_t surfaceObject, - T* inputData, int width, int height) -{ +__global__ void surf2DKernelW(hipSurfaceObject_t surfaceObject, T* inputData, int width, + int height) { #if !defined(__HIP_NO_IMAGE_SUPPORT) || !__HIP_NO_IMAGE_SUPPORT int x = blockIdx.x * blockDim.x + threadIdx.x; int y = blockIdx.y * blockDim.y + threadIdx.y; @@ -54,10 +60,8 @@ surf2DKernelW(hipSurfaceObject_t surfaceObject, } template -__global__ void -surf2DKernelRW(hipSurfaceObject_t surfaceObject, - hipSurfaceObject_t outputSurfObj, int width, int height) -{ +__global__ void surf2DKernelRW(hipSurfaceObject_t surfaceObject, hipSurfaceObject_t outputSurfObj, + int width, int height) { #if !defined(__HIP_NO_IMAGE_SUPPORT) || !__HIP_NO_IMAGE_SUPPORT int x = blockIdx.x * blockDim.x + threadIdx.x; int y = blockIdx.y * blockDim.y + threadIdx.y; @@ -69,29 +73,24 @@ surf2DKernelRW(hipSurfaceObject_t surfaceObject, #endif } -template -static void runTestR(const int width, const int height) -{ +template static void runTestR(const int width, const int height) { unsigned int size = width * height * sizeof(T); - T* hData = (T*) malloc(size); + T* hData = (T*)malloc(size); memset(hData, 0, size); - for (int i = 0; i < height; i++) - { - for (int j = 0; j < width; j++) - { + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { initVal(hData[i * width + j]); } } hipChannelFormatDesc channelDesc = hipCreateChannelDesc(); hipArray_t hipArray = nullptr; - HIP_CHECK(hipMallocArray (&hipArray, &channelDesc, width, height, - hipArraySurfaceLoadStore)); + HIP_CHECK(hipMallocArray(&hipArray, &channelDesc, width, height, hipArraySurfaceLoadStore)); // Need set source pitch, but we don't have any padding here const size_t spitch = width * sizeof(T); - HIP_CHECK(hipMemcpy2DToArray(hipArray, 0, 0, hData, spitch, spitch, height, - hipMemcpyHostToDevice)); + HIP_CHECK( + hipMemcpy2DToArray(hipArray, 0, 0, hData, spitch, spitch, height, hipMemcpyHostToDevice)); hipResourceDesc resDesc; memset(&resDesc, 0, sizeof(resDesc)); @@ -106,8 +105,8 @@ static void runTestR(const int width, const int height) HIP_CHECK(hipHostMalloc((void**)&hOutputData, size)); memset(hOutputData, 0, size); - dim3 dimBlock (16, 16, 1); - dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x, (height + dimBlock.y -1)/ dimBlock.y, 1); + dim3 dimBlock(16, 16, 1); + dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x, (height + dimBlock.y - 1) / dimBlock.y, 1); surf2DKernelR<<>>(surfaceObject, hOutputData, width, height); HIP_CHECK(hipGetLastError()); HIP_CHECK(hipDeviceSynchronize()); @@ -116,8 +115,8 @@ static void runTestR(const int width, const int height) for (int j = 0; j < width; j++) { int index = i * width + j; if (!isEqual(hData[index], hOutputData[index])) { - printf("Difference [ %d %d ]:%s ----%s\n", i, j, - getString(hData[index]).c_str(), getString(hOutputData[index]).c_str()); + printf("Difference [ %d %d ]:%s ----%s\n", i, j, getString(hData[index]).c_str(), + getString(hOutputData[index]).c_str()); REQUIRE(false); } } @@ -127,12 +126,9 @@ static void runTestR(const int width, const int height) HIP_CHECK(hipFreeArray(hipArray)); free(hData); HIP_CHECK(hipHostFree(hOutputData)); - REQUIRE(true); } -template -static void runTestW(const int width, const int height) -{ +template static void runTestW(const int width, const int height) { unsigned int size = width * height * sizeof(T); T* hData = nullptr; HIP_CHECK(hipHostMalloc((void**)&hData, size)); @@ -140,13 +136,12 @@ static void runTestW(const int width, const int height) hipChannelFormatDesc channelDesc = hipCreateChannelDesc(); hipArray_t hipArray = nullptr; - HIP_CHECK(hipMallocArray (&hipArray, &channelDesc, width, height, - hipArraySurfaceLoadStore)); + HIP_CHECK(hipMallocArray(&hipArray, &channelDesc, width, height, hipArraySurfaceLoadStore)); // Need set source pitch, but we don't have any padding here const size_t spitch = width * sizeof(T); - HIP_CHECK(hipMemcpy2DToArray(hipArray, 0, 0, hData, spitch, spitch, height, - hipMemcpyHostToDevice)); + HIP_CHECK( + hipMemcpy2DToArray(hipArray, 0, 0, hData, spitch, spitch, height, hipMemcpyHostToDevice)); hipResourceDesc resDesc; memset(&resDesc, 0, sizeof(resDesc)); @@ -157,32 +152,30 @@ static void runTestW(const int width, const int height) hipSurfaceObject_t surfaceObject = 0; HIP_CHECK(hipCreateSurfaceObject(&surfaceObject, &resDesc)); - for (int i = 0; i < height; i++) - { - for (int j = 0; j < width; j++) - { + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { initVal(hData[i * width + j]); } } - dim3 dimBlock (16, 16, 1); - dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x, (height + dimBlock.y -1)/ dimBlock.y, 1); + dim3 dimBlock(16, 16, 1); + dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x, (height + dimBlock.y - 1) / dimBlock.y, 1); surf2DKernelW<<>>(surfaceObject, hData, width, height); HIP_CHECK(hipGetLastError()); HIP_CHECK(hipDeviceSynchronize()); - T* hOutputData = (T*) malloc(size); + T* hOutputData = (T*)malloc(size); memset(hOutputData, 0, size); - HIP_CHECK(hipMemcpy2DFromArray(hOutputData, spitch, hipArray, 0, 0, spitch, - height, hipMemcpyDeviceToHost)); + HIP_CHECK(hipMemcpy2DFromArray(hOutputData, spitch, hipArray, 0, 0, spitch, height, + hipMemcpyDeviceToHost)); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { int index = i * width + j; if (!isEqual(hData[index], hOutputData[index])) { - printf("Difference [ %d %d ]:%s ----%s\n", i, j, - getString(hData[index]).c_str(), getString(hOutputData[index]).c_str()); + printf("Difference [ %d %d ]:%s ----%s\n", i, j, getString(hData[index]).c_str(), + getString(hOutputData[index]).c_str()); REQUIRE(false); } } @@ -192,40 +185,33 @@ static void runTestW(const int width, const int height) HIP_CHECK(hipFreeArray(hipArray)); HIP_CHECK(hipHostFree(hData)); free(hOutputData); - REQUIRE(true); } -template -static void runTestRW(const int width, const int height) -{ +template static void runTestRW(const int width, const int height) { unsigned int size = width * height * sizeof(T); - T* hData = (T*) malloc(size); + T* hData = (T*)malloc(size); memset(hData, 0, size); - for (int i = 0; i < height; i++) - { - for (int j = 0; j < width; j++) - { + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { initVal(hData[i * width + j]); } } #if LOG_DATA - printf ("hData: "); - for (int i = 0; i < 32; i++) - { - printf ("%s ", getString(hData[i]).c_str()); + printf("hData: "); + for (int i = 0; i < 32; i++) { + printf("%s ", getString(hData[i]).c_str()); } - printf ("\n"); + printf("\n"); #endif hipChannelFormatDesc channelDesc = hipCreateChannelDesc(); hipArray_t hipArray = nullptr, hipOutArray = nullptr; - HIP_CHECK(hipMallocArray (&hipArray, &channelDesc, width, height, - hipArraySurfaceLoadStore)); + HIP_CHECK(hipMallocArray(&hipArray, &channelDesc, width, height, hipArraySurfaceLoadStore)); // Need set source pitch, but we don't have any padding here const size_t spitch = width * sizeof(T); - HIP_CHECK(hipMemcpy2DToArray(hipArray, 0, 0, hData, spitch, spitch, height, - hipMemcpyHostToDevice)); + HIP_CHECK( + hipMemcpy2DToArray(hipArray, 0, 0, hData, spitch, spitch, height, hipMemcpyHostToDevice)); hipResourceDesc resDesc; memset(&resDesc, 0, sizeof(resDesc)); @@ -236,8 +222,7 @@ static void runTestRW(const int width, const int height) hipSurfaceObject_t surfaceObject = 0; HIP_CHECK(hipCreateSurfaceObject(&surfaceObject, &resDesc)); - HIP_CHECK(hipMallocArray(&hipOutArray, &channelDesc, width, height, - hipArraySurfaceLoadStore)); + HIP_CHECK(hipMallocArray(&hipOutArray, &channelDesc, width, height, hipArraySurfaceLoadStore)); hipResourceDesc resOutDesc; memset(&resOutDesc, 0, sizeof(resOutDesc)); @@ -245,35 +230,34 @@ static void runTestRW(const int width, const int height) resOutDesc.res.array.array = hipOutArray; hipSurfaceObject_t outSurfaceObject = 0; - HIP_CHECK(hipCreateSurfaceObject (&outSurfaceObject, &resOutDesc)); + HIP_CHECK(hipCreateSurfaceObject(&outSurfaceObject, &resOutDesc)); - dim3 dimBlock (16, 16, 1); - dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x, (height + dimBlock.y -1)/ dimBlock.y, 1); + dim3 dimBlock(16, 16, 1); + dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x, (height + dimBlock.y - 1) / dimBlock.y, 1); surf2DKernelRW<<>>(surfaceObject, outSurfaceObject, width, height); HIP_CHECK(hipGetLastError()); HIP_CHECK(hipDeviceSynchronize()); - T* hOutputData = (T*) malloc(size); + T* hOutputData = (T*)malloc(size); memset(hOutputData, 0, size); - HIP_CHECK(hipMemcpy2DFromArray(hOutputData, spitch, hipOutArray, 0, 0, spitch, - height, hipMemcpyDeviceToHost)); + HIP_CHECK(hipMemcpy2DFromArray(hOutputData, spitch, hipOutArray, 0, 0, spitch, height, + hipMemcpyDeviceToHost)); #if LOG_DATA - printf ("dData: "); - for (int i = 0; i < 32; i++) - { - printf ("%s ", getString(hOutputData[i]).c_str()); + printf("dData: "); + for (int i = 0; i < 32; i++) { + printf("%s ", getString(hOutputData[i]).c_str()); } - printf ("\n"); + printf("\n"); #endif for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { int index = i * width + j; if (!isEqual(hData[index], hOutputData[index])) { - printf("Difference [ %d %d ]:%s ----%s\n", i, j, - getString(hData[index]).c_str(), getString(hOutputData[index]).c_str()); + printf("Difference [ %d %d ]:%s ----%s\n", i, j, getString(hData[index]).c_str(), + getString(hOutputData[index]).c_str()); REQUIRE(false); } } @@ -285,83 +269,70 @@ static void runTestRW(const int width, const int height) HIP_CHECK(hipFreeArray(hipOutArray)); free(hData); free(hOutputData); - REQUIRE(true); } -TEMPLATE_TEST_CASE("Unit_hipSurfaceObj2D_type_R", "", - char, uchar, 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 - auto err = hipGetLastError(); // reset last err due to previous negative tests +/** + * Test Description + * ------------------------ + * - Basic test for `surf2Dread` with different types and dimensions. + * Test source + * ------------------------ + * - unit/surface/surf2D.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.7 + */ +TEMPLATE_TEST_CASE("Unit_surf2Dread_Positive_Basic", "", char, uchar, 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; - SECTION("Unit_hipSurfaceObj2D_type_R - 23, 67") { - runTestR(23, 67); - } - - SECTION("Unit_hipSurfaceObj2D_type_R - 67, 23") { - runTestR(67, 23); - } - - SECTION("Unit_hipSurfaceObj2D_type_R - 131, 67") { - runTestR(131, 67); - } - - SECTION("Unit_hipSurfaceObj2D_type_R - 263, 131") { - runTestR(263, 131); - } + const int width = GENERATE(31, 67); + const int height = GENERATE(131, 263); + runTestR(width, height); } -TEMPLATE_TEST_CASE("Unit_hipSurfaceObj2D_type_W", "", - char, uchar, 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 - auto err = hipGetLastError(); // reset last err due to previous negative tests +/** + * Test Description + * ------------------------ + * - Basic test for `surf2Dwrite` with different types and dimensions. + * Test source + * ------------------------ + * - unit/surface/surf2D.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.7 + */ +TEMPLATE_TEST_CASE("Unit_surf2Dwrite_Positive_Basic", "", char, uchar, 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; - SECTION("Unit_hipSurfaceObj2D_type_W - 23, 67") { - runTestW(23, 67); - } - - SECTION("Unit_hipSurfaceObj2D_type_W - 67, 23") { - runTestW(67, 23); - } - - SECTION("Unit_hipSurfaceObj2D_type_W - 131, 67") { - runTestW(131, 67); - } - - SECTION("Unit_hipSurfaceObj2D_type_W - 263, 23") { - runTestW(263, 23); - } + const int width = GENERATE(31, 67); + const int height = GENERATE(131, 263); + runTestW(width, height); } -TEMPLATE_TEST_CASE("Unit_hipSurfaceObj2D_type_RW", "", - char, uchar, 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 - auto err = hipGetLastError(); // reset last err due to previous negative tests +/** + * Test Description + * ------------------------ + * - Basic test for `surf2Dread` and `surf2Dwrite` together, with different types and dimensions. + * Test source + * ------------------------ + * - unit/surface/surf2D.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.7 + */ +TEMPLATE_TEST_CASE("Unit_surf2D_Positive_ReadWrite", "", char, uchar, 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; - SECTION("Unit_hipSurfaceObj2D_type_RW - 23, 67") { - runTestRW(23, 67); - } - - SECTION("Unit_hipSurfaceObj2D_type_RW - 67, 131") { - runTestRW(67, 131); - } - - SECTION("Unit_hipSurfaceObj2D_type_RW - 131, 263") { - runTestRW(131, 263); - } - - SECTION("Unit_hipSurfaceObj2D_type_RW - 263, 67") { - runTestRW(263, 67); - } + const int width = GENERATE(31, 67); + const int height = GENERATE(131, 263); + runTestRW(width, height); } diff --git a/projects/hip-tests/catch/unit/surface/surf2DLayered.cc b/projects/hip-tests/catch/unit/surface/surf2DLayered.cc new file mode 100644 index 0000000000..c8f06bdfc2 --- /dev/null +++ b/projects/hip-tests/catch/unit/surface/surf2DLayered.cc @@ -0,0 +1,338 @@ +/* +Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +/** + * @addtogroup surf2DLayered surf2DLayered + * @{ + * @ingroup SurfaceTest + */ + +#include +#include +#include + +#pragma clang diagnostic ignored "-Wunused-variable" +#pragma clang diagnostic ignored "-Wunused-parameter" + +#define LOG_DATA 0 + +template +__global__ void surf2DLayeredKernelR(hipSurfaceObject_t surfaceObject, T* outputData, int width, + int height) { +#if !defined(__HIP_NO_IMAGE_SUPPORT) || !__HIP_NO_IMAGE_SUPPORT + int x = blockIdx.x * blockDim.x + threadIdx.x; + int y = blockIdx.y * blockDim.y + threadIdx.y; + if (x < width && y < height) { + surf2DLayeredread(outputData + y * width + x, surfaceObject, x * sizeof(T), y, 0); + } +#endif +} + +template +__global__ void surf2DLayeredKernelW(hipSurfaceObject_t surfaceObject, T* inputData, int width, + int height) { +#if !defined(__HIP_NO_IMAGE_SUPPORT) || !__HIP_NO_IMAGE_SUPPORT + int x = blockIdx.x * blockDim.x + threadIdx.x; + int y = blockIdx.y * blockDim.y + threadIdx.y; + if (x < width && y < height) { + surf2DLayeredwrite(inputData[y * width + x], surfaceObject, x * sizeof(T), y, 0); + } +#endif +} + +template +__global__ void surf2DLayeredKernelRW(hipSurfaceObject_t surfaceObject, + hipSurfaceObject_t outputSurfObj, int width, int height) { +#if !defined(__HIP_NO_IMAGE_SUPPORT) || !__HIP_NO_IMAGE_SUPPORT + int x = blockIdx.x * blockDim.x + threadIdx.x; + int y = blockIdx.y * blockDim.y + threadIdx.y; + if (x < width && y < height) { + T data; + surf2DLayeredread(&data, surfaceObject, x * sizeof(T), y, 0); + surf2DLayeredwrite(data, outputSurfObj, x * sizeof(T), y, 0); + } +#endif +} + +template static void runTestR(const int width, const int height) { + unsigned int size = width * height * sizeof(T); + T* hData = (T*)malloc(size); + memset(hData, 0, size); + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + initVal(hData[i * width + j]); + } + } + + hipChannelFormatDesc channelDesc = hipCreateChannelDesc(); + hipArray_t hipArray = nullptr; + HIP_CHECK(hipMallocArray(&hipArray, &channelDesc, width, height, hipArraySurfaceLoadStore)); + + // Need set source pitch, but we don't have any padding here + const size_t spitch = width * sizeof(T); + HIP_CHECK( + hipMemcpy2DToArray(hipArray, 0, 0, hData, spitch, spitch, height, hipMemcpyHostToDevice)); + + hipResourceDesc resDesc; + memset(&resDesc, 0, sizeof(resDesc)); + resDesc.resType = hipResourceTypeArray; + resDesc.res.array.array = hipArray; + + // Create surface object + hipSurfaceObject_t surfaceObject = 0; + HIP_CHECK(hipCreateSurfaceObject(&surfaceObject, &resDesc)); + + T* hOutputData = nullptr; + HIP_CHECK(hipHostMalloc((void**)&hOutputData, size)); + memset(hOutputData, 0, size); + + dim3 dimBlock(16, 16, 1); + dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x, (height + dimBlock.y - 1) / dimBlock.y, 1); + surf2DLayeredKernelR<<>>(surfaceObject, hOutputData, width, height); + HIP_CHECK(hipGetLastError()); + HIP_CHECK(hipDeviceSynchronize()); + + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + int index = i * width + j; + if (!isEqual(hData[index], hOutputData[index])) { + printf("Difference [ %d %d ]:%s ----%s\n", i, j, getString(hData[index]).c_str(), + getString(hOutputData[index]).c_str()); + REQUIRE(false); + } + } + } + + HIP_CHECK(hipDestroySurfaceObject(surfaceObject)); + HIP_CHECK(hipFreeArray(hipArray)); + free(hData); + HIP_CHECK(hipHostFree(hOutputData)); +} + +template static void runTestW(const int width, const int height) { + unsigned int size = width * height * sizeof(T); + T* hData = nullptr; + HIP_CHECK(hipHostMalloc((void**)&hData, size)); + memset(hData, 0, size); + + hipChannelFormatDesc channelDesc = hipCreateChannelDesc(); + hipArray_t hipArray = nullptr; + HIP_CHECK(hipMallocArray(&hipArray, &channelDesc, width, height, hipArraySurfaceLoadStore)); + + // Need set source pitch, but we don't have any padding here + const size_t spitch = width * sizeof(T); + HIP_CHECK( + hipMemcpy2DToArray(hipArray, 0, 0, hData, spitch, spitch, height, hipMemcpyHostToDevice)); + + hipResourceDesc resDesc; + memset(&resDesc, 0, sizeof(resDesc)); + resDesc.resType = hipResourceTypeArray; + resDesc.res.array.array = hipArray; + + // Create surface object + hipSurfaceObject_t surfaceObject = 0; + HIP_CHECK(hipCreateSurfaceObject(&surfaceObject, &resDesc)); + + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + initVal(hData[i * width + j]); + } + } + + dim3 dimBlock(16, 16, 1); + dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x, (height + dimBlock.y - 1) / dimBlock.y, 1); + surf2DLayeredKernelW<<>>(surfaceObject, hData, width, height); + HIP_CHECK(hipGetLastError()); + HIP_CHECK(hipDeviceSynchronize()); + + T* hOutputData = (T*)malloc(size); + + memset(hOutputData, 0, size); + HIP_CHECK(hipMemcpy2DFromArray(hOutputData, spitch, hipArray, 0, 0, spitch, height, + hipMemcpyDeviceToHost)); + + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + int index = i * width + j; + if (!isEqual(hData[index], hOutputData[index])) { + printf("Difference [ %d %d ]:%s ----%s\n", i, j, getString(hData[index]).c_str(), + getString(hOutputData[index]).c_str()); + REQUIRE(false); + } + } + } + + HIP_CHECK(hipDestroySurfaceObject(surfaceObject)); + HIP_CHECK(hipFreeArray(hipArray)); + HIP_CHECK(hipHostFree(hData)); + free(hOutputData); +} + +template static void runTestRW(const int width, const int height) { + unsigned int size = width * height * sizeof(T); + T* hData = (T*)malloc(size); + memset(hData, 0, size); + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + initVal(hData[i * width + j]); + } + } +#if LOG_DATA + printf("hData: "); + for (int i = 0; i < 32; i++) { + printf("%s ", getString(hData[i]).c_str()); + } + printf("\n"); +#endif + + hipChannelFormatDesc channelDesc = hipCreateChannelDesc(); + hipArray_t hipArray = nullptr, hipOutArray = nullptr; + HIP_CHECK(hipMallocArray(&hipArray, &channelDesc, width, height, hipArraySurfaceLoadStore)); + + // Need set source pitch, but we don't have any padding here + const size_t spitch = width * sizeof(T); + HIP_CHECK( + hipMemcpy2DToArray(hipArray, 0, 0, hData, spitch, spitch, height, hipMemcpyHostToDevice)); + + hipResourceDesc resDesc; + memset(&resDesc, 0, sizeof(resDesc)); + resDesc.resType = hipResourceTypeArray; + resDesc.res.array.array = hipArray; + + // Create surface object + hipSurfaceObject_t surfaceObject = 0; + HIP_CHECK(hipCreateSurfaceObject(&surfaceObject, &resDesc)); + + HIP_CHECK(hipMallocArray(&hipOutArray, &channelDesc, width, height, hipArraySurfaceLoadStore)); + + hipResourceDesc resOutDesc; + memset(&resOutDesc, 0, sizeof(resOutDesc)); + resOutDesc.resType = hipResourceTypeArray; + resOutDesc.res.array.array = hipOutArray; + + hipSurfaceObject_t outSurfaceObject = 0; + HIP_CHECK(hipCreateSurfaceObject(&outSurfaceObject, &resOutDesc)); + + dim3 dimBlock(16, 16, 1); + dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x, (height + dimBlock.y - 1) / dimBlock.y, 1); + surf2DLayeredKernelRW<<>>(surfaceObject, outSurfaceObject, width, height); + HIP_CHECK(hipGetLastError()); + HIP_CHECK(hipDeviceSynchronize()); + + T* hOutputData = (T*)malloc(size); + + memset(hOutputData, 0, size); + HIP_CHECK(hipMemcpy2DFromArray(hOutputData, spitch, hipOutArray, 0, 0, spitch, height, + hipMemcpyDeviceToHost)); + +#if LOG_DATA + printf("dData: "); + for (int i = 0; i < 32; i++) { + printf("%s ", getString(hOutputData[i]).c_str()); + } + printf("\n"); +#endif + + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + int index = i * width + j; + if (!isEqual(hData[index], hOutputData[index])) { + printf("Difference [ %d %d ]:%s ----%s\n", i, j, getString(hData[index]).c_str(), + getString(hOutputData[index]).c_str()); + REQUIRE(false); + } + } + } + + HIP_CHECK(hipDestroySurfaceObject(surfaceObject)); + HIP_CHECK(hipDestroySurfaceObject(outSurfaceObject)); + HIP_CHECK(hipFreeArray(hipArray)); + HIP_CHECK(hipFreeArray(hipOutArray)); + free(hData); + free(hOutputData); +} + +/** + * Test Description + * ------------------------ + * - Basic test for `surf2DLayeredread` with different types and dimensions. + * Test source + * ------------------------ + * - unit/surface/surf2DLayered.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.7 + */ +TEMPLATE_TEST_CASE("Unit_surf2DLayeredread_Positive_Basic", "", char, uchar, 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; + + const int width = GENERATE(31, 67); + const int height = GENERATE(131, 263); + runTestR(width, height); +} + +/** + * Test Description + * ------------------------ + * - Basic test for `surf2DLayeredwrite` with different types and dimensions. + * Test source + * ------------------------ + * - unit/surface/surf2DLayered.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.7 + */ +TEMPLATE_TEST_CASE("Unit_surf2DLayeredwrite_Positive_Basic", "", char, uchar, 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; + + const int width = GENERATE(31, 67); + const int height = GENERATE(131, 263); + runTestW(width, height); +} + +/** + * Test Description + * ------------------------ + * - Basic test for `surf2DLayeredread` and `surf2DLayeredwrite` together, with different types + * and dimensions. Test source + * ------------------------ + * - unit/surface/surf2DLayered.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.7 + */ +TEMPLATE_TEST_CASE("Unit_surf2DLayered_Positive_ReadWrite", "", char, uchar, 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; + + const int width = GENERATE(31, 67); + const int height = GENERATE(131, 263); + runTestRW(width, height); +} diff --git a/projects/hip-tests/catch/unit/surface/hipSurfaceObj3D.cc b/projects/hip-tests/catch/unit/surface/surf3D.cc similarity index 64% rename from projects/hip-tests/catch/unit/surface/hipSurfaceObj3D.cc rename to projects/hip-tests/catch/unit/surface/surf3D.cc index 7cc3889e6f..d209f09115 100644 --- a/projects/hip-tests/catch/unit/surface/hipSurfaceObj3D.cc +++ b/projects/hip-tests/catch/unit/surface/surf3D.cc @@ -1,13 +1,16 @@ /* Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved. + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -16,50 +19,49 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include + +/** + * @addtogroup surf3D surf3D + * @{ + * @ingroup SurfaceTest + */ + #include +#include #include #pragma clang diagnostic ignored "-Wunused-variable" #pragma clang diagnostic ignored "-Wunused-parameter" template -__global__ void -surf3DKernelR(hipSurfaceObject_t surfaceObject, - T* outputData, int width, int height, int depth) -{ +__global__ void surf3DKernelR(hipSurfaceObject_t surfaceObject, T* outputData, int width, + int height, int depth) { #if !defined(__HIP_NO_IMAGE_SUPPORT) || !__HIP_NO_IMAGE_SUPPORT int x = blockIdx.x * blockDim.x + threadIdx.x; int y = blockIdx.y * blockDim.y + threadIdx.y; int z = blockIdx.z * blockDim.z + threadIdx.z; if (x < width && y < height && z < depth) { - surf3Dread(outputData + z * width * height + y * width + x, - surfaceObject, x * sizeof(T), y, z); + surf3Dread(outputData + z * width * height + y * width + x, surfaceObject, x * sizeof(T), y, z); } #endif } template -__global__ void -surf3DKernelW(hipSurfaceObject_t surfaceObject, - T* inputData, int width, int height, int depth) -{ +__global__ void surf3DKernelW(hipSurfaceObject_t surfaceObject, T* inputData, int width, int height, + int depth) { #if !defined(__HIP_NO_IMAGE_SUPPORT) || !__HIP_NO_IMAGE_SUPPORT int x = blockIdx.x * blockDim.x + threadIdx.x; int y = blockIdx.y * blockDim.y + threadIdx.y; int z = blockIdx.z * blockDim.z + threadIdx.z; if (x < width && y < height && z < depth) { - surf3Dwrite(inputData[z * width * height + y * width + x], - surfaceObject, x * sizeof(T), y, z); + surf3Dwrite(inputData[z * width * height + y * width + x], surfaceObject, x * sizeof(T), y, z); } #endif } template -__global__ void -surf3DKernelRW(hipSurfaceObject_t surfaceObject, - hipSurfaceObject_t outputSurfObj, int width, int height, int depth) -{ +__global__ void surf3DKernelRW(hipSurfaceObject_t surfaceObject, hipSurfaceObject_t outputSurfObj, + int width, int height, int depth) { #if !defined(__HIP_NO_IMAGE_SUPPORT) || !__HIP_NO_IMAGE_SUPPORT int x = blockIdx.x * blockDim.x + threadIdx.x; int y = blockIdx.y * blockDim.y + threadIdx.y; @@ -72,11 +74,9 @@ surf3DKernelRW(hipSurfaceObject_t surfaceObject, #endif } -template -static void runTestR(const int width, const int height, const int depth) -{ +template static void runTestR(const int width, const int height, const int depth) { unsigned int size = width * height * depth * sizeof(T); - T *hData = (T*) malloc(size); + T* hData = (T*)malloc(size); memset(hData, 0, size); for (int i = 0; i < depth; i++) { for (int j = 0; j < height; j++) { @@ -94,8 +94,8 @@ static void runTestR(const int width, const int height, const int depth) hipMemcpy3DParms myparms; memset(&myparms, 0, sizeof(myparms)); - myparms.srcPos = make_hipPos(0,0,0); - myparms.dstPos = make_hipPos(0,0,0); + myparms.srcPos = make_hipPos(0, 0, 0); + myparms.dstPos = make_hipPos(0, 0, 0); myparms.srcPtr = make_hipPitchedPtr(hData, width * sizeof(T), width, height); myparms.dstArray = hipArray; myparms.extent = make_hipExtent(width, height, depth); @@ -112,12 +112,12 @@ static void runTestR(const int width, const int height, const int depth) hipSurfaceObject_t surfaceObject = 0; HIP_CHECK(hipCreateSurfaceObject(&surfaceObject, &resDesc)); - T *hOutputData = nullptr; + T* hOutputData = nullptr; HIP_CHECK(hipHostMalloc((void**)&hOutputData, size)); memset(hOutputData, 0, size); - dim3 dimBlock(8, 8, 8); // 512 threads - dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x, (height + dimBlock.y -1)/ dimBlock.y, + dim3 dimBlock(8, 8, 8); // 512 threads + dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x, (height + dimBlock.y - 1) / dimBlock.y, (depth + dimBlock.z - 1) / dimBlock.z); surf3DKernelR<<>>(surfaceObject, hOutputData, width, height, depth); @@ -130,26 +130,23 @@ static void runTestR(const int width, const int height, const int depth) for (int k = 0; k < width; k++) { int index = i * width * height + j * width + k; if (!isEqual(hData[index], hOutputData[index])) { - printf("Difference [ %d %d %d]:%s ----%s\n", i, j, k, - getString(hData[index]).c_str(), getString(hOutputData[index]).c_str()); + printf("Difference [ %d %d %d]:%s ----%s\n", i, j, k, getString(hData[index]).c_str(), + getString(hOutputData[index]).c_str()); REQUIRE(false); } } } } - HIP_CHECK(hipDestroySurfaceObject (surfaceObject)); + HIP_CHECK(hipDestroySurfaceObject(surfaceObject)); HIP_CHECK(hipFreeArray(hipArray)); free(hData); HIP_CHECK(hipHostFree(hOutputData)); - REQUIRE(true); } -template -static void runTestW(const int width, const int height, const int depth) -{ +template static void runTestW(const int width, const int height, const int depth) { unsigned int size = width * height * depth * sizeof(T); - T *hData = nullptr; + T* hData = nullptr; HIP_CHECK(hipHostMalloc((void**)&hData, size)); memset(hData, 0, size); @@ -161,8 +158,8 @@ static void runTestW(const int width, const int height, const int depth) hipMemcpy3DParms myparms; memset(&myparms, 0, sizeof(myparms)); - myparms.srcPos = make_hipPos(0,0,0); - myparms.dstPos = make_hipPos(0,0,0); + myparms.srcPos = make_hipPos(0, 0, 0); + myparms.dstPos = make_hipPos(0, 0, 0); myparms.srcPtr = make_hipPitchedPtr(hData, width * sizeof(T), width, height); myparms.dstArray = hipArray; myparms.extent = make_hipExtent(width, height, depth); @@ -187,8 +184,8 @@ static void runTestW(const int width, const int height, const int depth) } } - dim3 dimBlock(8, 8, 8); // 512 threads - dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x, (height + dimBlock.y -1)/ dimBlock.y, + dim3 dimBlock(8, 8, 8); // 512 threads + dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x, (height + dimBlock.y - 1) / dimBlock.y, (depth + dimBlock.z - 1) / dimBlock.z); surf3DKernelW<<>>(surfaceObject, hData, width, height, depth); @@ -196,13 +193,13 @@ static void runTestW(const int width, const int height, const int depth) HIP_CHECK(hipGetLastError()); HIP_CHECK(hipDeviceSynchronize()); - T *hOutputData = (T*) malloc (size); + T* hOutputData = (T*)malloc(size); memset(hOutputData, 0, size); memset(&myparms, 0, sizeof(myparms)); - myparms.srcPos = make_hipPos(0,0,0); - myparms.dstPos = make_hipPos(0,0,0); - myparms.srcArray= hipArray; + myparms.srcPos = make_hipPos(0, 0, 0); + myparms.dstPos = make_hipPos(0, 0, 0); + myparms.srcArray = hipArray; myparms.dstPtr = make_hipPitchedPtr(hOutputData, width * sizeof(T), width, height); myparms.extent = make_hipExtent(width, height, depth); myparms.kind = hipMemcpyDeviceToHost; @@ -214,26 +211,23 @@ static void runTestW(const int width, const int height, const int depth) for (int k = 0; k < width; k++) { int index = i * width * height + j * width + k; if (!isEqual(hData[index], hOutputData[index])) { - printf("Difference [ %d %d %d]:%s ----%s\n", i, j, k, - getString(hData[index]).c_str(), getString(hOutputData[index]).c_str()); + printf("Difference [ %d %d %d]:%s ----%s\n", i, j, k, getString(hData[index]).c_str(), + getString(hOutputData[index]).c_str()); REQUIRE(false); } } } } - HIP_CHECK(hipDestroySurfaceObject (surfaceObject)); + HIP_CHECK(hipDestroySurfaceObject(surfaceObject)); HIP_CHECK(hipFreeArray(hipArray)); HIP_CHECK(hipHostFree(hData)); free(hOutputData); - REQUIRE(true); } -template -static void runTestRW(const int width, const int height, const int depth) -{ +template static void runTestRW(const int width, const int height, const int depth) { unsigned int size = width * height * depth * sizeof(T); - T *hData = (T*) malloc(size); + T* hData = (T*)malloc(size); memset(hData, 0, size); for (int i = 0; i < depth; i++) { for (int j = 0; j < height; j++) { @@ -251,8 +245,8 @@ static void runTestRW(const int width, const int height, const int depth) hipMemcpy3DParms myparms; memset(&myparms, 0, sizeof(myparms)); - myparms.srcPos = make_hipPos(0,0,0); - myparms.dstPos = make_hipPos(0,0,0); + myparms.srcPos = make_hipPos(0, 0, 0); + myparms.dstPos = make_hipPos(0, 0, 0); myparms.srcPtr = make_hipPitchedPtr(hData, width * sizeof(T), width, height); myparms.dstArray = hipArray; myparms.extent = make_hipExtent(width, height, depth); @@ -280,8 +274,8 @@ static void runTestRW(const int width, const int height, const int depth) hipSurfaceObject_t outSurfaceObject = 0; HIP_CHECK(hipCreateSurfaceObject(&outSurfaceObject, &resOutDesc)); - dim3 dimBlock(8, 8, 8); // 512 threads - dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x, (height + dimBlock.y -1)/ dimBlock.y, + dim3 dimBlock(8, 8, 8); // 512 threads + dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x, (height + dimBlock.y - 1) / dimBlock.y, (depth + dimBlock.z - 1) / dimBlock.z); surf3DKernelRW<<>>(surfaceObject, outSurfaceObject, width, height, depth); @@ -289,13 +283,13 @@ static void runTestRW(const int width, const int height, const int depth) HIP_CHECK(hipGetLastError()); HIP_CHECK(hipDeviceSynchronize()); - T *hOutputData = (T*) malloc (size); + T* hOutputData = (T*)malloc(size); memset(hOutputData, 0, size); memset(&myparms, 0, sizeof(myparms)); - myparms.srcPos = make_hipPos(0,0,0); - myparms.dstPos = make_hipPos(0,0,0); - myparms.srcArray= hipOutArray; + myparms.srcPos = make_hipPos(0, 0, 0); + myparms.dstPos = make_hipPos(0, 0, 0); + myparms.srcArray = hipOutArray; myparms.dstPtr = make_hipPitchedPtr(hOutputData, width * sizeof(T), width, height); myparms.extent = make_hipExtent(width, height, depth); myparms.kind = hipMemcpyDeviceToHost; @@ -307,97 +301,87 @@ static void runTestRW(const int width, const int height, const int depth) for (int k = 0; k < width; k++) { int index = i * width * height + j * width + k; if (!isEqual(hData[index], hOutputData[index])) { - printf("Difference [ %d %d %d]:%s ----%s\n", i, j, k, - getString(hData[index]).c_str(), getString(hOutputData[index]).c_str()); + printf("Difference [ %d %d %d]:%s ----%s\n", i, j, k, getString(hData[index]).c_str(), + getString(hOutputData[index]).c_str()); REQUIRE(false); } } } } - HIP_CHECK(hipDestroySurfaceObject (surfaceObject)); - HIP_CHECK(hipDestroySurfaceObject (outSurfaceObject)); + HIP_CHECK(hipDestroySurfaceObject(surfaceObject)); + HIP_CHECK(hipDestroySurfaceObject(outSurfaceObject)); HIP_CHECK(hipFreeArray(hipArray)); HIP_CHECK(hipFreeArray(hipOutArray)); free(hData); free(hOutputData); - REQUIRE(true); } -TEMPLATE_TEST_CASE("Unit_hipSurfaceObj3D_type_R", "", - char, uchar, 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 - auto err = hipGetLastError(); // reset last err due to previous negative tests +/** + * Test Description + * ------------------------ + * - Basic test for `surf3Dread` with different types and dimensions. + * Test source + * ------------------------ + * - unit/surface/surf3D.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.7 + */ +TEMPLATE_TEST_CASE("Unit_surf3Dread_Positive_Basic", "", char, uchar, 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; - SECTION("Unit_hipSurfaceObj3D_type_R - 31, 67, 131") { - runTestR(31, 67, 131); - } - - SECTION("Unit_hipSurfaceObj3D_type_R - 67, 31, 263") { - runTestR(67, 31, 263); - } - - SECTION("Unit_hipSurfaceObj3D_type_R - 131, 131, 67") { - runTestR(131, 131, 67); - } - - SECTION("Unit_hipSurfaceObj3D_type_R - 263, 131, 263") { - runTestR(263, 131, 263); - } + const int width = GENERATE(31, 67); + const int height = GENERATE(131, 263); + const int depth = GENERATE(4, 11); + runTestR(width, height, depth); } -TEMPLATE_TEST_CASE("Unit_hipSurfaceObj3D_type_W", "", - char, uchar, 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 - auto err = hipGetLastError(); // reset last err due to previous negative tests +/** + * Test Description + * ------------------------ + * - Basic test for `surf3Dwrite` with different types and dimensions. + * Test source + * ------------------------ + * - unit/surface/surf3D.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.7 + */ +TEMPLATE_TEST_CASE("Unit_surf3Dwrite_Positive_Basic", "", char, uchar, 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; - SECTION("Unit_hipSurfaceObj3D_type_W - 31, 67, 131") { - runTestW(31, 67, 131); - } - - SECTION("Unit_hipSurfaceObj3D_type_W - 67, 67, 31") { - runTestW(67, 67, 31); - } - - SECTION("Unit_hipSurfaceObj3D_type_W - 131, 131, 67") { - runTestW(131, 131, 67); - } - - SECTION("Unit_hipSurfaceObj3D_type_W - 263, 131, 263") { - runTestW(263, 131, 263); - } + const int width = GENERATE(31, 67); + const int height = GENERATE(131, 263); + const int depth = GENERATE(4, 11); + runTestR(width, height, depth); } -TEMPLATE_TEST_CASE("Unit_hipSurfaceObj3D_type_RW", "", - char, uchar, 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 - auto err = hipGetLastError(); // reset last err due to previous negative tests +/** + * Test Description + * ------------------------ + * - Basic test for `surf3Dread` and `surf3Dwrite` together, with different types and dimensions. + * Test source + * ------------------------ + * - unit/surface/surf3D.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.7 + */ +TEMPLATE_TEST_CASE("Unit_surf3D_Positive_ReadWrite", "", char, uchar, 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; - SECTION("Unit_hipSurfaceObj3D_type_RW - 31, 31, 67") { - runTestRW(31, 31, 67); - } - - SECTION("Unit_hipSurfaceObj3D_type_RW - 67, 67, 31") { - runTestRW(67, 67, 31); - } - - SECTION("Unit_hipSurfaceObj3D_type_RW - 131, 67, 263") { - runTestRW(131, 67, 263); - } - - SECTION("Unit_hipSurfaceObj3D_type_RW - 263, 131, 263") { - runTestRW(263, 131, 263); - } + const int width = GENERATE(31, 67); + const int height = GENERATE(131, 263); + const int depth = GENERATE(4, 11); + runTestR(width, height, depth); } diff --git a/projects/hip-tests/catch/unit/surface/surfCubemap.cc b/projects/hip-tests/catch/unit/surface/surfCubemap.cc new file mode 100644 index 0000000000..c0fa488567 --- /dev/null +++ b/projects/hip-tests/catch/unit/surface/surfCubemap.cc @@ -0,0 +1,338 @@ +/* +Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +/** + * @addtogroup surfCubemap surfCubemap + * @{ + * @ingroup SurfaceTest + */ + +#include +#include +#include + +#pragma clang diagnostic ignored "-Wunused-variable" +#pragma clang diagnostic ignored "-Wunused-parameter" + +#define LOG_DATA 0 + +template +__global__ void surfCubemapKernelR(hipSurfaceObject_t surfaceObject, T* outputData, int width, + int height) { +#if !defined(__HIP_NO_IMAGE_SUPPORT) || !__HIP_NO_IMAGE_SUPPORT + int x = blockIdx.x * blockDim.x + threadIdx.x; + int y = blockIdx.y * blockDim.y + threadIdx.y; + if (x < width && y < height) { + surfCubemapread(outputData + y * width + x, surfaceObject, x * sizeof(T), y, 0); + } +#endif +} + +template +__global__ void surfCubemapKernelW(hipSurfaceObject_t surfaceObject, T* inputData, int width, + int height) { +#if !defined(__HIP_NO_IMAGE_SUPPORT) || !__HIP_NO_IMAGE_SUPPORT + int x = blockIdx.x * blockDim.x + threadIdx.x; + int y = blockIdx.y * blockDim.y + threadIdx.y; + if (x < width && y < height) { + surfCubemapwrite(inputData[y * width + x], surfaceObject, x * sizeof(T), y, 0); + } +#endif +} + +template +__global__ void surfCubemapKernelRW(hipSurfaceObject_t surfaceObject, + hipSurfaceObject_t outputSurfObj, int width, int height) { +#if !defined(__HIP_NO_IMAGE_SUPPORT) || !__HIP_NO_IMAGE_SUPPORT + int x = blockIdx.x * blockDim.x + threadIdx.x; + int y = blockIdx.y * blockDim.y + threadIdx.y; + if (x < width && y < height) { + T data; + surfCubemapread(&data, surfaceObject, x * sizeof(T), y, 0); + surfCubemapwrite(data, outputSurfObj, x * sizeof(T), y, 0); + } +#endif +} + +template static void runTestR(const int width, const int height) { + unsigned int size = width * height * sizeof(T); + T* hData = (T*)malloc(size); + memset(hData, 0, size); + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + initVal(hData[i * width + j]); + } + } + + hipChannelFormatDesc channelDesc = hipCreateChannelDesc(); + hipArray_t hipArray = nullptr; + HIP_CHECK(hipMallocArray(&hipArray, &channelDesc, width, height, hipArraySurfaceLoadStore)); + + // Need set source pitch, but we don't have any padding here + const size_t spitch = width * sizeof(T); + HIP_CHECK( + hipMemcpy2DToArray(hipArray, 0, 0, hData, spitch, spitch, height, hipMemcpyHostToDevice)); + + hipResourceDesc resDesc; + memset(&resDesc, 0, sizeof(resDesc)); + resDesc.resType = hipResourceTypeArray; + resDesc.res.array.array = hipArray; + + // Create surface object + hipSurfaceObject_t surfaceObject = 0; + HIP_CHECK(hipCreateSurfaceObject(&surfaceObject, &resDesc)); + + T* hOutputData = nullptr; + HIP_CHECK(hipHostMalloc((void**)&hOutputData, size)); + memset(hOutputData, 0, size); + + dim3 dimBlock(16, 16, 1); + dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x, (height + dimBlock.y - 1) / dimBlock.y, 1); + surfCubemapKernelR<<>>(surfaceObject, hOutputData, width, height); + HIP_CHECK(hipGetLastError()); + HIP_CHECK(hipDeviceSynchronize()); + + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + int index = i * width + j; + if (!isEqual(hData[index], hOutputData[index])) { + printf("Difference [ %d %d ]:%s ----%s\n", i, j, getString(hData[index]).c_str(), + getString(hOutputData[index]).c_str()); + REQUIRE(false); + } + } + } + + HIP_CHECK(hipDestroySurfaceObject(surfaceObject)); + HIP_CHECK(hipFreeArray(hipArray)); + free(hData); + HIP_CHECK(hipHostFree(hOutputData)); +} + +template static void runTestW(const int width, const int height) { + unsigned int size = width * height * sizeof(T); + T* hData = nullptr; + HIP_CHECK(hipHostMalloc((void**)&hData, size)); + memset(hData, 0, size); + + hipChannelFormatDesc channelDesc = hipCreateChannelDesc(); + hipArray_t hipArray = nullptr; + HIP_CHECK(hipMallocArray(&hipArray, &channelDesc, width, height, hipArraySurfaceLoadStore)); + + // Need set source pitch, but we don't have any padding here + const size_t spitch = width * sizeof(T); + HIP_CHECK( + hipMemcpy2DToArray(hipArray, 0, 0, hData, spitch, spitch, height, hipMemcpyHostToDevice)); + + hipResourceDesc resDesc; + memset(&resDesc, 0, sizeof(resDesc)); + resDesc.resType = hipResourceTypeArray; + resDesc.res.array.array = hipArray; + + // Create surface object + hipSurfaceObject_t surfaceObject = 0; + HIP_CHECK(hipCreateSurfaceObject(&surfaceObject, &resDesc)); + + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + initVal(hData[i * width + j]); + } + } + + dim3 dimBlock(16, 16, 1); + dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x, (height + dimBlock.y - 1) / dimBlock.y, 1); + surfCubemapKernelW<<>>(surfaceObject, hData, width, height); + HIP_CHECK(hipGetLastError()); + HIP_CHECK(hipDeviceSynchronize()); + + T* hOutputData = (T*)malloc(size); + + memset(hOutputData, 0, size); + HIP_CHECK(hipMemcpy2DFromArray(hOutputData, spitch, hipArray, 0, 0, spitch, height, + hipMemcpyDeviceToHost)); + + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + int index = i * width + j; + if (!isEqual(hData[index], hOutputData[index])) { + printf("Difference [ %d %d ]:%s ----%s\n", i, j, getString(hData[index]).c_str(), + getString(hOutputData[index]).c_str()); + REQUIRE(false); + } + } + } + + HIP_CHECK(hipDestroySurfaceObject(surfaceObject)); + HIP_CHECK(hipFreeArray(hipArray)); + HIP_CHECK(hipHostFree(hData)); + free(hOutputData); +} + +template static void runTestRW(const int width, const int height) { + unsigned int size = width * height * sizeof(T); + T* hData = (T*)malloc(size); + memset(hData, 0, size); + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + initVal(hData[i * width + j]); + } + } +#if LOG_DATA + printf("hData: "); + for (int i = 0; i < 32; i++) { + printf("%s ", getString(hData[i]).c_str()); + } + printf("\n"); +#endif + + hipChannelFormatDesc channelDesc = hipCreateChannelDesc(); + hipArray_t hipArray = nullptr, hipOutArray = nullptr; + HIP_CHECK(hipMallocArray(&hipArray, &channelDesc, width, height, hipArraySurfaceLoadStore)); + + // Need set source pitch, but we don't have any padding here + const size_t spitch = width * sizeof(T); + HIP_CHECK( + hipMemcpy2DToArray(hipArray, 0, 0, hData, spitch, spitch, height, hipMemcpyHostToDevice)); + + hipResourceDesc resDesc; + memset(&resDesc, 0, sizeof(resDesc)); + resDesc.resType = hipResourceTypeArray; + resDesc.res.array.array = hipArray; + + // Create surface object + hipSurfaceObject_t surfaceObject = 0; + HIP_CHECK(hipCreateSurfaceObject(&surfaceObject, &resDesc)); + + HIP_CHECK(hipMallocArray(&hipOutArray, &channelDesc, width, height, hipArraySurfaceLoadStore)); + + hipResourceDesc resOutDesc; + memset(&resOutDesc, 0, sizeof(resOutDesc)); + resOutDesc.resType = hipResourceTypeArray; + resOutDesc.res.array.array = hipOutArray; + + hipSurfaceObject_t outSurfaceObject = 0; + HIP_CHECK(hipCreateSurfaceObject(&outSurfaceObject, &resOutDesc)); + + dim3 dimBlock(16, 16, 1); + dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x, (height + dimBlock.y - 1) / dimBlock.y, 1); + surfCubemapKernelRW<<>>(surfaceObject, outSurfaceObject, width, height); + HIP_CHECK(hipGetLastError()); + HIP_CHECK(hipDeviceSynchronize()); + + T* hOutputData = (T*)malloc(size); + + memset(hOutputData, 0, size); + HIP_CHECK(hipMemcpy2DFromArray(hOutputData, spitch, hipOutArray, 0, 0, spitch, height, + hipMemcpyDeviceToHost)); + +#if LOG_DATA + printf("dData: "); + for (int i = 0; i < 32; i++) { + printf("%s ", getString(hOutputData[i]).c_str()); + } + printf("\n"); +#endif + + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + int index = i * width + j; + if (!isEqual(hData[index], hOutputData[index])) { + printf("Difference [ %d %d ]:%s ----%s\n", i, j, getString(hData[index]).c_str(), + getString(hOutputData[index]).c_str()); + REQUIRE(false); + } + } + } + + HIP_CHECK(hipDestroySurfaceObject(surfaceObject)); + HIP_CHECK(hipDestroySurfaceObject(outSurfaceObject)); + HIP_CHECK(hipFreeArray(hipArray)); + HIP_CHECK(hipFreeArray(hipOutArray)); + free(hData); + free(hOutputData); +} + +/** + * Test Description + * ------------------------ + * - Basic test for `surfCubemapread` with different types and dimensions. + * Test source + * ------------------------ + * - unit/surface/surfCubemap.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.7 + */ +TEMPLATE_TEST_CASE("Unit_surfCubemapread_Positive_Basic", "", char, uchar, 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; + + const int width = GENERATE(31, 67); + const int height = GENERATE(131, 263); + runTestR(width, height); +} + +/** + * Test Description + * ------------------------ + * - Basic test for `surfCubemapwrite` with different types and dimensions. + * Test source + * ------------------------ + * - unit/surface/surfCubemap.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.7 + */ +TEMPLATE_TEST_CASE("Unit_surfCubemapwrite_Positive_Basic", "", char, uchar, 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; + + const int width = GENERATE(31, 67); + const int height = GENERATE(131, 263); + runTestW(width, height); +} + +/** + * Test Description + * ------------------------ + * - Basic test for `surfCubemapread` and `surfCubemapwrite` together, with different types and + * dimensions. Test source + * ------------------------ + * - unit/surface/surfCubemap.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.7 + */ +TEMPLATE_TEST_CASE("Unit_surfCubemap_Positive_ReadWrite", "", char, uchar, 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; + + const int width = GENERATE(31, 67); + const int height = GENERATE(131, 263); + runTestRW(width, height); +} diff --git a/projects/hip-tests/catch/unit/surface/surfCubemapLayered.cc b/projects/hip-tests/catch/unit/surface/surfCubemapLayered.cc new file mode 100644 index 0000000000..89da56ed53 --- /dev/null +++ b/projects/hip-tests/catch/unit/surface/surfCubemapLayered.cc @@ -0,0 +1,340 @@ +/* +Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +/** + * @addtogroup surfCubemapLayered surfCubemapLayered + * @{ + * @ingroup SurfaceTest + */ + +#include +#include +#include + +#pragma clang diagnostic ignored "-Wunused-variable" +#pragma clang diagnostic ignored "-Wunused-parameter" + +#define LOG_DATA 0 + +template +__global__ void surfCubemapLayeredKernelR(hipSurfaceObject_t surfaceObject, T* outputData, + int width, int height) { +#if !defined(__HIP_NO_IMAGE_SUPPORT) || !__HIP_NO_IMAGE_SUPPORT + int x = blockIdx.x * blockDim.x + threadIdx.x; + int y = blockIdx.y * blockDim.y + threadIdx.y; + if (x < width && y < height) { + surfCubemapLayeredread(outputData + y * width + x, surfaceObject, x * sizeof(T), y, 0); + } +#endif +} + +template +__global__ void surfCubemapLayeredKernelW(hipSurfaceObject_t surfaceObject, T* inputData, int width, + int height) { +#if !defined(__HIP_NO_IMAGE_SUPPORT) || !__HIP_NO_IMAGE_SUPPORT + int x = blockIdx.x * blockDim.x + threadIdx.x; + int y = blockIdx.y * blockDim.y + threadIdx.y; + if (x < width && y < height) { + surfCubemapLayeredwrite(inputData[y * width + x], surfaceObject, x * sizeof(T), y, 0); + } +#endif +} + +template +__global__ void surfCubemapLayeredKernelRW(hipSurfaceObject_t surfaceObject, + hipSurfaceObject_t outputSurfObj, int width, + int height) { +#if !defined(__HIP_NO_IMAGE_SUPPORT) || !__HIP_NO_IMAGE_SUPPORT + int x = blockIdx.x * blockDim.x + threadIdx.x; + int y = blockIdx.y * blockDim.y + threadIdx.y; + if (x < width && y < height) { + T data; + surfCubemapLayeredread(&data, surfaceObject, x * sizeof(T), y, 0); + surfCubemapLayeredwrite(data, outputSurfObj, x * sizeof(T), y, 0); + } +#endif +} + +template static void runTestR(const int width, const int height) { + unsigned int size = width * height * sizeof(T); + T* hData = (T*)malloc(size); + memset(hData, 0, size); + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + initVal(hData[i * width + j]); + } + } + + hipChannelFormatDesc channelDesc = hipCreateChannelDesc(); + hipArray_t hipArray = nullptr; + HIP_CHECK(hipMallocArray(&hipArray, &channelDesc, width, height, hipArraySurfaceLoadStore)); + + // Need set source pitch, but we don't have any padding here + const size_t spitch = width * sizeof(T); + HIP_CHECK( + hipMemcpy2DToArray(hipArray, 0, 0, hData, spitch, spitch, height, hipMemcpyHostToDevice)); + + hipResourceDesc resDesc; + memset(&resDesc, 0, sizeof(resDesc)); + resDesc.resType = hipResourceTypeArray; + resDesc.res.array.array = hipArray; + + // Create surface object + hipSurfaceObject_t surfaceObject = 0; + HIP_CHECK(hipCreateSurfaceObject(&surfaceObject, &resDesc)); + + T* hOutputData = nullptr; + HIP_CHECK(hipHostMalloc((void**)&hOutputData, size)); + memset(hOutputData, 0, size); + + dim3 dimBlock(16, 16, 1); + dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x, (height + dimBlock.y - 1) / dimBlock.y, 1); + surfCubemapLayeredKernelR<<>>(surfaceObject, hOutputData, width, height); + HIP_CHECK(hipGetLastError()); + HIP_CHECK(hipDeviceSynchronize()); + + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + int index = i * width + j; + if (!isEqual(hData[index], hOutputData[index])) { + printf("Difference [ %d %d ]:%s ----%s\n", i, j, getString(hData[index]).c_str(), + getString(hOutputData[index]).c_str()); + REQUIRE(false); + } + } + } + + HIP_CHECK(hipDestroySurfaceObject(surfaceObject)); + HIP_CHECK(hipFreeArray(hipArray)); + free(hData); + HIP_CHECK(hipHostFree(hOutputData)); +} + +template static void runTestW(const int width, const int height) { + unsigned int size = width * height * sizeof(T); + T* hData = nullptr; + HIP_CHECK(hipHostMalloc((void**)&hData, size)); + memset(hData, 0, size); + + hipChannelFormatDesc channelDesc = hipCreateChannelDesc(); + hipArray_t hipArray = nullptr; + HIP_CHECK(hipMallocArray(&hipArray, &channelDesc, width, height, hipArraySurfaceLoadStore)); + + // Need set source pitch, but we don't have any padding here + const size_t spitch = width * sizeof(T); + HIP_CHECK( + hipMemcpy2DToArray(hipArray, 0, 0, hData, spitch, spitch, height, hipMemcpyHostToDevice)); + + hipResourceDesc resDesc; + memset(&resDesc, 0, sizeof(resDesc)); + resDesc.resType = hipResourceTypeArray; + resDesc.res.array.array = hipArray; + + // Create surface object + hipSurfaceObject_t surfaceObject = 0; + HIP_CHECK(hipCreateSurfaceObject(&surfaceObject, &resDesc)); + + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + initVal(hData[i * width + j]); + } + } + + dim3 dimBlock(16, 16, 1); + dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x, (height + dimBlock.y - 1) / dimBlock.y, 1); + surfCubemapLayeredKernelW<<>>(surfaceObject, hData, width, height); + HIP_CHECK(hipGetLastError()); + HIP_CHECK(hipDeviceSynchronize()); + + T* hOutputData = (T*)malloc(size); + + memset(hOutputData, 0, size); + HIP_CHECK(hipMemcpy2DFromArray(hOutputData, spitch, hipArray, 0, 0, spitch, height, + hipMemcpyDeviceToHost)); + + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + int index = i * width + j; + if (!isEqual(hData[index], hOutputData[index])) { + printf("Difference [ %d %d ]:%s ----%s\n", i, j, getString(hData[index]).c_str(), + getString(hOutputData[index]).c_str()); + REQUIRE(false); + } + } + } + + HIP_CHECK(hipDestroySurfaceObject(surfaceObject)); + HIP_CHECK(hipFreeArray(hipArray)); + HIP_CHECK(hipHostFree(hData)); + free(hOutputData); +} + +template static void runTestRW(const int width, const int height) { + unsigned int size = width * height * sizeof(T); + T* hData = (T*)malloc(size); + memset(hData, 0, size); + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + initVal(hData[i * width + j]); + } + } +#if LOG_DATA + printf("hData: "); + for (int i = 0; i < 32; i++) { + printf("%s ", getString(hData[i]).c_str()); + } + printf("\n"); +#endif + + hipChannelFormatDesc channelDesc = hipCreateChannelDesc(); + hipArray_t hipArray = nullptr, hipOutArray = nullptr; + HIP_CHECK(hipMallocArray(&hipArray, &channelDesc, width, height, hipArraySurfaceLoadStore)); + + // Need set source pitch, but we don't have any padding here + const size_t spitch = width * sizeof(T); + HIP_CHECK( + hipMemcpy2DToArray(hipArray, 0, 0, hData, spitch, spitch, height, hipMemcpyHostToDevice)); + + hipResourceDesc resDesc; + memset(&resDesc, 0, sizeof(resDesc)); + resDesc.resType = hipResourceTypeArray; + resDesc.res.array.array = hipArray; + + // Create surface object + hipSurfaceObject_t surfaceObject = 0; + HIP_CHECK(hipCreateSurfaceObject(&surfaceObject, &resDesc)); + + HIP_CHECK(hipMallocArray(&hipOutArray, &channelDesc, width, height, hipArraySurfaceLoadStore)); + + hipResourceDesc resOutDesc; + memset(&resOutDesc, 0, sizeof(resOutDesc)); + resOutDesc.resType = hipResourceTypeArray; + resOutDesc.res.array.array = hipOutArray; + + hipSurfaceObject_t outSurfaceObject = 0; + HIP_CHECK(hipCreateSurfaceObject(&outSurfaceObject, &resOutDesc)); + + dim3 dimBlock(16, 16, 1); + dim3 dimGrid((width + dimBlock.x - 1) / dimBlock.x, (height + dimBlock.y - 1) / dimBlock.y, 1); + surfCubemapLayeredKernelRW + <<>>(surfaceObject, outSurfaceObject, width, height); + HIP_CHECK(hipGetLastError()); + HIP_CHECK(hipDeviceSynchronize()); + + T* hOutputData = (T*)malloc(size); + + memset(hOutputData, 0, size); + HIP_CHECK(hipMemcpy2DFromArray(hOutputData, spitch, hipOutArray, 0, 0, spitch, height, + hipMemcpyDeviceToHost)); + +#if LOG_DATA + printf("dData: "); + for (int i = 0; i < 32; i++) { + printf("%s ", getString(hOutputData[i]).c_str()); + } + printf("\n"); +#endif + + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + int index = i * width + j; + if (!isEqual(hData[index], hOutputData[index])) { + printf("Difference [ %d %d ]:%s ----%s\n", i, j, getString(hData[index]).c_str(), + getString(hOutputData[index]).c_str()); + REQUIRE(false); + } + } + } + + HIP_CHECK(hipDestroySurfaceObject(surfaceObject)); + HIP_CHECK(hipDestroySurfaceObject(outSurfaceObject)); + HIP_CHECK(hipFreeArray(hipArray)); + HIP_CHECK(hipFreeArray(hipOutArray)); + free(hData); + free(hOutputData); +} + +/** + * Test Description + * ------------------------ + * - Basic test for `surfCubemapLayeredread` with different types and dimensions. + * Test source + * ------------------------ + * - unit/surface/surfCubemapLayered.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.7 + */ +TEMPLATE_TEST_CASE("Unit_surfCubemapLayeredread_Positive_Basic", "", char, uchar, 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; + + const int width = GENERATE(31, 67); + const int height = GENERATE(131, 263); + runTestR(width, height); +} + +/** + * Test Description + * ------------------------ + * - Basic test for `surfCubemapLayeredwrite` with different types and dimensions. + * Test source + * ------------------------ + * - unit/surface/surfCubemapLayered.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.7 + */ +TEMPLATE_TEST_CASE("Unit_surfCubemapLayeredwrite_Positive_Basic", "", char, uchar, 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; + + const int width = GENERATE(31, 67); + const int height = GENERATE(131, 263); + runTestW(width, height); +} + +/** + * Test Description + * ------------------------ + * - Basic test for `surfCubemapLayeredread` and `surfCubemapLayeredwrite` together, with + * different types and dimensions. Test source + * ------------------------ + * - unit/surface/surfCubemapLayered.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.7 + */ +TEMPLATE_TEST_CASE("Unit_surfCubemapLayered_Positive_ReadWrite", "", char, uchar, 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; + + const int width = GENERATE(31, 67); + const int height = GENERATE(131, 263); + runTestRW(width, height); +}