EXSWHTEC-381 - Implement tests for Surface Object device functions #453
Change-Id: I750ac29781637187d59ad0a2291a1d400f97cd83
[ROCm/hip-tests commit: e0c3f64e78]
Bu işleme şunda yer alıyor:
işlemeyi yapan:
Rakesh Roy
ebeveyn
74299ca09d
işleme
594d42670b
@@ -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)
|
||||
+94
-120
@@ -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 <hip_test_common.hh>
|
||||
|
||||
/**
|
||||
* @addtogroup surf1D surf1D
|
||||
* @{
|
||||
* @ingroup SurfaceTest
|
||||
*/
|
||||
|
||||
#include <hip_array_common.hh>
|
||||
#include <hip_test_common.hh>
|
||||
#include <hip_texture_helper.hh>
|
||||
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
#pragma clang diagnostic ignored "-Wunused-parameter"
|
||||
|
||||
template <typename T>
|
||||
__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 <typename T>
|
||||
__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 <typename T>
|
||||
__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 <typename T>
|
||||
static void runTestR(const int width)
|
||||
{
|
||||
template <typename T> 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<T><<<dimGrid, dimBlock>>>(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 <typename T>
|
||||
static void runTestW(const int width)
|
||||
{
|
||||
template <typename T> 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<T><<<dimGrid, dimBlock>>>(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 <typename T>
|
||||
static void runTestRW(const int width)
|
||||
{
|
||||
template <typename T> 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<T><<<dimGrid, dimBlock>>>(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<TestType>(31);
|
||||
}
|
||||
|
||||
SECTION("Unit_hipSurfaceObj1D_type_R - 67") {
|
||||
runTestR<TestType>(67);
|
||||
}
|
||||
|
||||
SECTION("Unit_hipSurfaceObj1D_type_R - 131") {
|
||||
runTestR<TestType>(131);
|
||||
}
|
||||
|
||||
SECTION("Unit_hipSurfaceObj1D_type_R - 263") {
|
||||
runTestR<TestType>(263);
|
||||
}
|
||||
const int width = GENERATE(31, 67, 131, 263);
|
||||
runTestR<TestType>(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<TestType>(31);
|
||||
}
|
||||
|
||||
SECTION("Unit_hipSurfaceObj1D_type_W - 63") {
|
||||
runTestW<TestType>(63);
|
||||
}
|
||||
|
||||
SECTION("Unit_hipSurfaceObj1D_type_W - 131") {
|
||||
runTestW<TestType>(131);
|
||||
}
|
||||
|
||||
SECTION("Unit_hipSurfaceObj1D_type_W - 263") {
|
||||
runTestW<TestType>(263);
|
||||
}
|
||||
const int width = GENERATE(31, 67, 131, 263);
|
||||
runTestW<TestType>(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<TestType>(23);
|
||||
}
|
||||
|
||||
SECTION("Unit_hipSurfaceObj1D_type_RW - 67") {
|
||||
runTestRW<TestType>(67);
|
||||
}
|
||||
|
||||
SECTION("Unit_hipSurfaceObj1D_type_RW - 131") {
|
||||
runTestRW<TestType>(131);
|
||||
}
|
||||
|
||||
SECTION("Unit_hipSurfaceObj1D_type_RW - 263") {
|
||||
runTestRW<TestType>(263);
|
||||
}
|
||||
const int width = GENERATE(31, 67, 131, 263);
|
||||
runTestRW<TestType>(width);
|
||||
}
|
||||
@@ -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 <hip_array_common.hh>
|
||||
#include <hip_test_common.hh>
|
||||
#include <hip_texture_helper.hh>
|
||||
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
#pragma clang diagnostic ignored "-Wunused-parameter"
|
||||
|
||||
template <typename T>
|
||||
__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 <typename T>
|
||||
__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 <typename T>
|
||||
__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 <typename T> 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<T>();
|
||||
|
||||
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<T><<<dimGrid, dimBlock>>>(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 <typename T> 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<T>();
|
||||
|
||||
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<T><<<dimGrid, dimBlock>>>(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 <typename T> 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<T>();
|
||||
|
||||
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<T><<<dimGrid, dimBlock>>>(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<TestType>(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<TestType>(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<TestType>(width);
|
||||
}
|
||||
+122
-151
@@ -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 <hip_test_common.hh>
|
||||
|
||||
/**
|
||||
* @addtogroup surf2D surf2D
|
||||
* @{
|
||||
* @ingroup SurfaceTest
|
||||
*/
|
||||
|
||||
#include <hip_array_common.hh>
|
||||
#include <hip_test_common.hh>
|
||||
#include <hip_texture_helper.hh>
|
||||
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
@@ -26,10 +36,8 @@ THE SOFTWARE.
|
||||
#define LOG_DATA 0
|
||||
|
||||
template <typename T>
|
||||
__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 <typename T>
|
||||
__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 <typename T>
|
||||
__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 <typename T>
|
||||
static void runTestR(const int width, const int height)
|
||||
{
|
||||
template <typename T> 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<T>();
|
||||
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<T><<<dimGrid, dimBlock>>>(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 <typename T>
|
||||
static void runTestW(const int width, const int height)
|
||||
{
|
||||
template <typename T> 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<T>();
|
||||
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<T><<<dimGrid, dimBlock>>>(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 <typename T>
|
||||
static void runTestRW(const int width, const int height)
|
||||
{
|
||||
template <typename T> 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<T>();
|
||||
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<T><<<dimGrid, dimBlock>>>(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<TestType>(23, 67);
|
||||
}
|
||||
|
||||
SECTION("Unit_hipSurfaceObj2D_type_R - 67, 23") {
|
||||
runTestR<TestType>(67, 23);
|
||||
}
|
||||
|
||||
SECTION("Unit_hipSurfaceObj2D_type_R - 131, 67") {
|
||||
runTestR<TestType>(131, 67);
|
||||
}
|
||||
|
||||
SECTION("Unit_hipSurfaceObj2D_type_R - 263, 131") {
|
||||
runTestR<TestType>(263, 131);
|
||||
}
|
||||
const int width = GENERATE(31, 67);
|
||||
const int height = GENERATE(131, 263);
|
||||
runTestR<TestType>(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<TestType>(23, 67);
|
||||
}
|
||||
|
||||
SECTION("Unit_hipSurfaceObj2D_type_W - 67, 23") {
|
||||
runTestW<TestType>(67, 23);
|
||||
}
|
||||
|
||||
SECTION("Unit_hipSurfaceObj2D_type_W - 131, 67") {
|
||||
runTestW<TestType>(131, 67);
|
||||
}
|
||||
|
||||
SECTION("Unit_hipSurfaceObj2D_type_W - 263, 23") {
|
||||
runTestW<TestType>(263, 23);
|
||||
}
|
||||
const int width = GENERATE(31, 67);
|
||||
const int height = GENERATE(131, 263);
|
||||
runTestW<TestType>(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<TestType>(23, 67);
|
||||
}
|
||||
|
||||
SECTION("Unit_hipSurfaceObj2D_type_RW - 67, 131") {
|
||||
runTestRW<TestType>(67, 131);
|
||||
}
|
||||
|
||||
SECTION("Unit_hipSurfaceObj2D_type_RW - 131, 263") {
|
||||
runTestRW<TestType>(131, 263);
|
||||
}
|
||||
|
||||
SECTION("Unit_hipSurfaceObj2D_type_RW - 263, 67") {
|
||||
runTestRW<TestType>(263, 67);
|
||||
}
|
||||
const int width = GENERATE(31, 67);
|
||||
const int height = GENERATE(131, 263);
|
||||
runTestRW<TestType>(width, height);
|
||||
}
|
||||
@@ -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 <hip_array_common.hh>
|
||||
#include <hip_test_common.hh>
|
||||
#include <hip_texture_helper.hh>
|
||||
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
#pragma clang diagnostic ignored "-Wunused-parameter"
|
||||
|
||||
#define LOG_DATA 0
|
||||
|
||||
template <typename T>
|
||||
__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<T>(outputData + y * width + x, surfaceObject, x * sizeof(T), y, 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__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<T>(inputData[y * width + x], surfaceObject, x * sizeof(T), y, 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__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<T>(&data, surfaceObject, x * sizeof(T), y, 0);
|
||||
surf2DLayeredwrite<T>(data, outputSurfObj, x * sizeof(T), y, 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename T> 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<T>();
|
||||
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<T><<<dimGrid, dimBlock>>>(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 <typename T> 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<T>();
|
||||
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<T><<<dimGrid, dimBlock>>>(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 <typename T> 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<T>();
|
||||
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<T><<<dimGrid, dimBlock>>>(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<TestType>(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<TestType>(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<TestType>(width, height);
|
||||
}
|
||||
+116
-132
@@ -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 <hip_test_common.hh>
|
||||
|
||||
/**
|
||||
* @addtogroup surf3D surf3D
|
||||
* @{
|
||||
* @ingroup SurfaceTest
|
||||
*/
|
||||
|
||||
#include <hip_array_common.hh>
|
||||
#include <hip_test_common.hh>
|
||||
#include <hip_texture_helper.hh>
|
||||
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
#pragma clang diagnostic ignored "-Wunused-parameter"
|
||||
|
||||
template <typename T>
|
||||
__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 <typename T>
|
||||
__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 <typename T>
|
||||
__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 <typename T>
|
||||
static void runTestR(const int width, const int height, const int depth)
|
||||
{
|
||||
template <typename T> 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<T><<<dimGrid, dimBlock>>>(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 <typename T>
|
||||
static void runTestW(const int width, const int height, const int depth)
|
||||
{
|
||||
template <typename T> 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<T><<<dimGrid, dimBlock>>>(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 <typename T>
|
||||
static void runTestRW(const int width, const int height, const int depth)
|
||||
{
|
||||
template <typename T> 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<T><<<dimGrid, dimBlock>>>(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<TestType>(31, 67, 131);
|
||||
}
|
||||
|
||||
SECTION("Unit_hipSurfaceObj3D_type_R - 67, 31, 263") {
|
||||
runTestR<TestType>(67, 31, 263);
|
||||
}
|
||||
|
||||
SECTION("Unit_hipSurfaceObj3D_type_R - 131, 131, 67") {
|
||||
runTestR<TestType>(131, 131, 67);
|
||||
}
|
||||
|
||||
SECTION("Unit_hipSurfaceObj3D_type_R - 263, 131, 263") {
|
||||
runTestR<TestType>(263, 131, 263);
|
||||
}
|
||||
const int width = GENERATE(31, 67);
|
||||
const int height = GENERATE(131, 263);
|
||||
const int depth = GENERATE(4, 11);
|
||||
runTestR<TestType>(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<TestType>(31, 67, 131);
|
||||
}
|
||||
|
||||
SECTION("Unit_hipSurfaceObj3D_type_W - 67, 67, 31") {
|
||||
runTestW<TestType>(67, 67, 31);
|
||||
}
|
||||
|
||||
SECTION("Unit_hipSurfaceObj3D_type_W - 131, 131, 67") {
|
||||
runTestW<TestType>(131, 131, 67);
|
||||
}
|
||||
|
||||
SECTION("Unit_hipSurfaceObj3D_type_W - 263, 131, 263") {
|
||||
runTestW<TestType>(263, 131, 263);
|
||||
}
|
||||
const int width = GENERATE(31, 67);
|
||||
const int height = GENERATE(131, 263);
|
||||
const int depth = GENERATE(4, 11);
|
||||
runTestR<TestType>(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<TestType>(31, 31, 67);
|
||||
}
|
||||
|
||||
SECTION("Unit_hipSurfaceObj3D_type_RW - 67, 67, 31") {
|
||||
runTestRW<TestType>(67, 67, 31);
|
||||
}
|
||||
|
||||
SECTION("Unit_hipSurfaceObj3D_type_RW - 131, 67, 263") {
|
||||
runTestRW<TestType>(131, 67, 263);
|
||||
}
|
||||
|
||||
SECTION("Unit_hipSurfaceObj3D_type_RW - 263, 131, 263") {
|
||||
runTestRW<TestType>(263, 131, 263);
|
||||
}
|
||||
const int width = GENERATE(31, 67);
|
||||
const int height = GENERATE(131, 263);
|
||||
const int depth = GENERATE(4, 11);
|
||||
runTestR<TestType>(width, height, depth);
|
||||
}
|
||||
@@ -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 <hip_array_common.hh>
|
||||
#include <hip_test_common.hh>
|
||||
#include <hip_texture_helper.hh>
|
||||
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
#pragma clang diagnostic ignored "-Wunused-parameter"
|
||||
|
||||
#define LOG_DATA 0
|
||||
|
||||
template <typename T>
|
||||
__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<T>(outputData + y * width + x, surfaceObject, x * sizeof(T), y, 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__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<T>(inputData[y * width + x], surfaceObject, x * sizeof(T), y, 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__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<T>(&data, surfaceObject, x * sizeof(T), y, 0);
|
||||
surfCubemapwrite<T>(data, outputSurfObj, x * sizeof(T), y, 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename T> 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<T>();
|
||||
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<T><<<dimGrid, dimBlock>>>(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 <typename T> 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<T>();
|
||||
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<T><<<dimGrid, dimBlock>>>(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 <typename T> 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<T>();
|
||||
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<T><<<dimGrid, dimBlock>>>(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<TestType>(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<TestType>(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<TestType>(width, height);
|
||||
}
|
||||
@@ -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 <hip_array_common.hh>
|
||||
#include <hip_test_common.hh>
|
||||
#include <hip_texture_helper.hh>
|
||||
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
#pragma clang diagnostic ignored "-Wunused-parameter"
|
||||
|
||||
#define LOG_DATA 0
|
||||
|
||||
template <typename T>
|
||||
__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<T>(outputData + y * width + x, surfaceObject, x * sizeof(T), y, 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__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<T>(inputData[y * width + x], surfaceObject, x * sizeof(T), y, 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__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<T>(&data, surfaceObject, x * sizeof(T), y, 0);
|
||||
surfCubemapLayeredwrite<T>(data, outputSurfObj, x * sizeof(T), y, 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename T> 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<T>();
|
||||
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<T><<<dimGrid, dimBlock>>>(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 <typename T> 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<T>();
|
||||
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<T><<<dimGrid, dimBlock>>>(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 <typename T> 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<T>();
|
||||
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<T>
|
||||
<<<dimGrid, dimBlock>>>(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<TestType>(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<TestType>(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<TestType>(width, height);
|
||||
}
|
||||
Yeni konuda referans
Bir kullanıcı engelle