2019-07-31 10:32:35 +05:30
|
|
|
/*
|
2021-07-02 11:19:03 -07:00
|
|
|
Copyright (c) 2019 - 2021 Advanced Micro Devices, Inc. All rights reserved.
|
2021-11-25 04:38:06 -05:00
|
|
|
|
2019-07-31 10:32:35 +05:30
|
|
|
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:
|
2021-11-25 04:38:06 -05:00
|
|
|
|
2019-07-31 10:32:35 +05:30
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
|
all copies or substantial portions of the Software.
|
2021-11-25 04:38:06 -05:00
|
|
|
|
2019-07-31 10:32:35 +05:30
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* HIT_START
|
2021-07-22 21:46:05 -04:00
|
|
|
* BUILD: %t %s ../test_common.cpp
|
2021-08-19 00:58:14 -04:00
|
|
|
* // Test hipFilterModePoint
|
|
|
|
|
* TEST: %t --textureFilterMode 0
|
|
|
|
|
* // Test hipFilterModeLinear
|
|
|
|
|
* TEST: %t --textureFilterMode 1
|
2019-07-31 10:32:35 +05:30
|
|
|
* HIT_END
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "test_common.h"
|
2021-07-22 21:46:05 -04:00
|
|
|
#include <math.h>
|
2019-07-31 10:32:35 +05:30
|
|
|
#define SIZE 10
|
2021-08-19 00:58:14 -04:00
|
|
|
#define EPSILON 0.00001
|
|
|
|
|
#define THRESH_HOLD 0.01 // For filter mode
|
2020-02-05 10:26:18 -05:00
|
|
|
|
|
|
|
|
static float getNormalizedValue(const float value,
|
2020-04-23 21:42:06 +05:30
|
|
|
const hipChannelFormatDesc& desc) {
|
|
|
|
|
if ((desc.x == 8) && (desc.f == hipChannelFormatKindSigned))
|
|
|
|
|
return (value / SCHAR_MAX);
|
|
|
|
|
if ((desc.x == 8) && (desc.f == hipChannelFormatKindUnsigned))
|
|
|
|
|
return (value / UCHAR_MAX);
|
|
|
|
|
if ((desc.x == 16) && (desc.f == hipChannelFormatKindSigned))
|
|
|
|
|
return (value / SHRT_MAX);
|
|
|
|
|
if ((desc.x == 16) && (desc.f == hipChannelFormatKindUnsigned))
|
|
|
|
|
return (value / USHRT_MAX);
|
|
|
|
|
return value;
|
2020-02-05 10:26:18 -05:00
|
|
|
}
|
|
|
|
|
|
2020-04-23 21:42:06 +05:30
|
|
|
texture<char, hipTextureType1D, hipReadModeNormalizedFloat> texc;
|
|
|
|
|
|
|
|
|
|
texture<unsigned char, hipTextureType1D, hipReadModeNormalizedFloat> texuc;
|
|
|
|
|
|
|
|
|
|
texture<short, hipTextureType1D, hipReadModeNormalizedFloat> texs;
|
|
|
|
|
|
|
|
|
|
texture<unsigned short, hipTextureType1D, hipReadModeNormalizedFloat> texus;
|
|
|
|
|
|
2019-07-31 10:32:35 +05:30
|
|
|
|
2020-04-23 21:42:06 +05:30
|
|
|
template<typename T>
|
2019-07-31 10:32:35 +05:30
|
|
|
__global__ void normalizedValTextureTest(unsigned int numElements, float* pDst)
|
|
|
|
|
{
|
2021-12-02 01:16:13 -05:00
|
|
|
#if !defined(__HIP_NO_IMAGE_SUPPORT) || !__HIP_NO_IMAGE_SUPPORT
|
2019-07-31 10:32:35 +05:30
|
|
|
unsigned int elementID = hipThreadIdx_x;
|
|
|
|
|
if(elementID >= numElements)
|
2020-04-23 21:42:06 +05:30
|
|
|
return;
|
|
|
|
|
float coord =(float) elementID/numElements;
|
|
|
|
|
if(std::is_same<T, char>::value)
|
|
|
|
|
pDst[elementID] = tex1D(texc, coord);
|
|
|
|
|
else if(std::is_same<T, unsigned char>::value)
|
|
|
|
|
pDst[elementID] = tex1D(texuc, coord);
|
|
|
|
|
else if(std::is_same<T, short>::value)
|
|
|
|
|
pDst[elementID] = tex1D(texs, coord);
|
|
|
|
|
else if(std::is_same<T, unsigned short>::value)
|
|
|
|
|
pDst[elementID] = tex1D(texus, coord);
|
2021-12-02 01:16:13 -05:00
|
|
|
#endif
|
2019-07-31 10:32:35 +05:30
|
|
|
}
|
|
|
|
|
|
2021-08-19 00:58:14 -04:00
|
|
|
bool textureVerifyFilterModePoint(float *hOutputData, float *expected, size_t size) {
|
|
|
|
|
bool testResult = true;
|
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
|
if ((hOutputData[i] == expected[i])
|
|
|
|
|
|| (i >= 1 && hOutputData[i] == expected[i - 1]) || // round down
|
|
|
|
|
(i < (size - 1) && hOutputData[i] == expected[i + 1])) // round up
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
printf("mismatch at output[%d]:%f expected[%d]:%f", i, hOutputData[i], i,
|
|
|
|
|
expected[i]);
|
|
|
|
|
if (i >= 1) {
|
|
|
|
|
printf(", expected[%d]:%f", i - 1, expected[i - 1]);
|
|
|
|
|
}
|
|
|
|
|
if (i < (size - 1)) {
|
|
|
|
|
printf(", expected[%d]:%f", i + 1, expected[i + 1]);
|
|
|
|
|
}
|
|
|
|
|
printf("\n");
|
|
|
|
|
testResult = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return testResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool textureVerifyFilterModeLinear(float *hOutputData, float *expected, size_t size) {
|
|
|
|
|
bool testResult = true;
|
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
|
float mean = (fabs(expected[i]) + fabs(hOutputData[i])) / 2;
|
|
|
|
|
float ratio = fabs(expected[i] - hOutputData[i]) / (mean + EPSILON);
|
|
|
|
|
if (ratio > THRESH_HOLD) {
|
|
|
|
|
printf("mismatch at output[%d]:%f expected[%d]:%f, ratio:%f\n", i,
|
|
|
|
|
hOutputData[i], i, expected[i], ratio);
|
|
|
|
|
testResult = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return testResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<hipTextureFilterMode fMode = hipFilterModePoint>
|
|
|
|
|
bool textureVerify(float *hOutputData, float *expected, size_t size) {
|
|
|
|
|
bool testResult = true;
|
|
|
|
|
if (fMode == hipFilterModePoint) {
|
|
|
|
|
testResult = textureVerifyFilterModePoint(hOutputData, expected, size);
|
|
|
|
|
} else if (fMode == hipFilterModeLinear) {
|
|
|
|
|
testResult = textureVerifyFilterModeLinear(hOutputData, expected, size);
|
|
|
|
|
}
|
|
|
|
|
return testResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T, hipTextureFilterMode fMode = hipFilterModePoint>
|
2020-04-23 21:42:06 +05:30
|
|
|
bool textureTest(texture<T, hipTextureType1D, hipReadModeNormalizedFloat> *tex)
|
2019-07-31 10:32:35 +05:30
|
|
|
{
|
2020-04-23 21:42:06 +05:30
|
|
|
hipChannelFormatDesc desc = hipCreateChannelDesc<T>();
|
|
|
|
|
hipArray_t dData;
|
|
|
|
|
HIPCHECK(hipMallocArray(&dData, &desc, SIZE, 1, hipArrayDefault));
|
|
|
|
|
|
|
|
|
|
T hData[] = {65, 66, 67, 68, 69, 70, 71, 72, 73, 74};
|
|
|
|
|
HIPCHECK(hipMemcpy2DToArray(dData, 0, 0, hData, sizeof(T)*SIZE, sizeof(T)*SIZE, 1, hipMemcpyHostToDevice));
|
|
|
|
|
|
|
|
|
|
tex->normalized = true;
|
|
|
|
|
tex->channelDesc = desc;
|
2021-08-19 00:58:14 -04:00
|
|
|
tex->filterMode = fMode;
|
2020-04-23 21:42:06 +05:30
|
|
|
HIPCHECK(hipBindTextureToArray(tex, dData, &desc));
|
|
|
|
|
|
2019-07-31 10:32:35 +05:30
|
|
|
float *dOutputData = NULL;
|
2019-11-07 13:17:46 +05:30
|
|
|
HIPCHECK(hipMalloc((void **) &dOutputData, sizeof(float)*SIZE));
|
2020-04-23 21:42:06 +05:30
|
|
|
|
|
|
|
|
hipLaunchKernelGGL(normalizedValTextureTest<T>, dim3(1,1,1), dim3(SIZE,1,1), 0, 0, SIZE, dOutputData);
|
2019-07-31 10:32:35 +05:30
|
|
|
|
|
|
|
|
float *hOutputData = new float[SIZE];
|
2020-04-23 21:42:06 +05:30
|
|
|
HIPCHECK(hipMemcpy(hOutputData, dOutputData, (sizeof(float)*SIZE), hipMemcpyDeviceToHost));
|
|
|
|
|
|
2021-08-19 00:58:14 -04:00
|
|
|
float expected[SIZE];
|
|
|
|
|
for(int i = 0; i < SIZE; i++) {
|
|
|
|
|
expected[i] = getNormalizedValue(float(hData[i]), desc);
|
2019-07-31 10:32:35 +05:30
|
|
|
}
|
2021-08-19 00:58:14 -04:00
|
|
|
bool testResult = textureVerify<fMode>(hOutputData, expected, SIZE);
|
2020-04-23 21:42:06 +05:30
|
|
|
|
|
|
|
|
HIPCHECK(hipFreeArray(dData));
|
|
|
|
|
HIPCHECK(hipFree(dOutputData));
|
2019-07-31 10:32:35 +05:30
|
|
|
delete [] hOutputData;
|
|
|
|
|
return testResult;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-19 00:58:14 -04:00
|
|
|
template<hipTextureFilterMode fMode = hipFilterModePoint>
|
|
|
|
|
bool runTest() {
|
|
|
|
|
bool status = true;
|
|
|
|
|
status &= textureTest<char, fMode>(&texc);
|
|
|
|
|
status &= textureTest<unsigned char, fMode>(&texuc);
|
|
|
|
|
status &= textureTest<short, fMode>(&texs);
|
|
|
|
|
status &= textureTest<unsigned short, fMode>(&texus);
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-31 10:32:35 +05:30
|
|
|
int main(int argc, char** argv)
|
|
|
|
|
{
|
2021-12-02 01:16:13 -05:00
|
|
|
int imageSupport = 0;
|
|
|
|
|
hipDeviceGetAttribute(&imageSupport, hipDeviceAttributeImageSupport,
|
|
|
|
|
p_gpuDevice);
|
|
|
|
|
if (!imageSupport) {
|
|
|
|
|
printf("Texture is not support on the device\n");
|
|
|
|
|
passed();
|
|
|
|
|
}
|
2021-08-19 00:58:14 -04:00
|
|
|
HipTest::parseStandardArguments(argc, argv, true);
|
2019-07-31 10:32:35 +05:30
|
|
|
int device = 0;
|
2021-08-19 00:58:14 -04:00
|
|
|
bool status = false;
|
2019-11-07 13:17:46 +05:30
|
|
|
HIPCHECK(hipSetDevice(device));
|
2019-07-31 10:32:35 +05:30
|
|
|
hipDeviceProp_t props;
|
2019-11-07 13:17:46 +05:30
|
|
|
HIPCHECK(hipGetDeviceProperties(&props, device));
|
2019-07-31 10:32:35 +05:30
|
|
|
std::cout << "Device :: " << props.name << std::endl;
|
2020-12-15 17:38:08 -05:00
|
|
|
#ifdef __HIP_PLATFORM_AMD__
|
2019-07-31 10:32:35 +05:30
|
|
|
std::cout << "Arch - AMD GPU :: " << props.gcnArch << std::endl;
|
|
|
|
|
#endif
|
2021-11-25 04:38:06 -05:00
|
|
|
|
2021-08-19 00:58:14 -04:00
|
|
|
if(textureFilterMode == 0) {
|
|
|
|
|
printf("Test hipFilterModePoint\n");
|
|
|
|
|
status = runTest<hipFilterModePoint>();
|
|
|
|
|
} else if(textureFilterMode == 1) {
|
|
|
|
|
printf("Test hipFilterModeLinear\n");
|
|
|
|
|
printf("THRESH_HOLD:%f, EPSILON:%f\n", THRESH_HOLD, EPSILON);
|
|
|
|
|
status = runTest<hipFilterModeLinear>();
|
|
|
|
|
} else {
|
|
|
|
|
printf("Wrong argument!\n");
|
|
|
|
|
printf("hipNormalizedFloatValueTex --textureFilterMode 0 for hipFilterModePoint\n");
|
|
|
|
|
printf("hipNormalizedFloatValueTex --textureFilterMode 1 for hipFilterModeLinear\n");
|
|
|
|
|
}
|
2020-04-23 21:42:06 +05:30
|
|
|
|
2019-07-31 10:32:35 +05:30
|
|
|
if(status){
|
|
|
|
|
passed();
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
failed("checks failed!");
|
|
|
|
|
}
|
|
|
|
|
}
|