SWDEV-470698 - fix formatting, add format check workflow (#657)
This commit is contained in:
committed by
GitHub
parent
5840940caa
commit
f7338717ae
@@ -23,34 +23,27 @@ THE SOFTWARE.
|
||||
|
||||
#if CUDA_VERSION < CUDA_12000
|
||||
|
||||
#define SIZE 10
|
||||
#define EPSILON 0.00001
|
||||
#define THRESH_HOLD 0.01 // For filter mode
|
||||
#define SIZE 10
|
||||
#define EPSILON 0.00001
|
||||
#define THRESH_HOLD 0.01 // For filter mode
|
||||
|
||||
static float getNormalizedValue(const float value,
|
||||
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);
|
||||
static float getNormalizedValue(const float value, 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;
|
||||
}
|
||||
|
||||
texture<char, hipTextureType1D, hipReadModeNormalizedFloat> texc;
|
||||
texture<unsigned char, hipTextureType1D, hipReadModeNormalizedFloat> texuc;
|
||||
texture<char, hipTextureType1D, hipReadModeNormalizedFloat> texc;
|
||||
texture<unsigned char, hipTextureType1D, hipReadModeNormalizedFloat> texuc;
|
||||
|
||||
template<typename T>
|
||||
__global__ void normalizedValTextureTest(unsigned int numElements,
|
||||
float* pDst) {
|
||||
template <typename T>
|
||||
__global__ void normalizedValTextureTest(unsigned int numElements, float* pDst) {
|
||||
#if !__HIP_NO_IMAGE_SUPPORT
|
||||
unsigned int elementID = threadIdx.x;
|
||||
if (elementID >= numElements)
|
||||
return;
|
||||
float coord = elementID/static_cast<float>(numElements);
|
||||
if (elementID >= numElements) return;
|
||||
float coord = elementID / static_cast<float>(numElements);
|
||||
if (std::is_same<T, char>::value)
|
||||
pDst[elementID] = tex1D(texc, coord);
|
||||
else if (std::is_same<T, unsigned char>::value)
|
||||
@@ -58,16 +51,15 @@ __global__ void normalizedValTextureTest(unsigned int numElements,
|
||||
#endif
|
||||
}
|
||||
|
||||
static void textureVerifyFilterModePoint(float *hOutputData,
|
||||
float *expected, int size) {
|
||||
static void textureVerifyFilterModePoint(float* hOutputData, float* expected, int size) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
if ((hOutputData[i] == expected[i])
|
||||
|| (i >= 1 && hOutputData[i] == expected[i - 1]) || // round down
|
||||
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;
|
||||
}
|
||||
INFO("Mismatch at output[" << i << "]:" << hOutputData[i] <<
|
||||
" expected[" << i << "]:" << expected[i]);
|
||||
INFO("Mismatch at output[" << i << "]:" << hOutputData[i] << " expected[" << i
|
||||
<< "]:" << expected[i]);
|
||||
if (i >= 1) {
|
||||
INFO(", expected[" << i - 1 << "]:" << expected[i - 1]);
|
||||
}
|
||||
@@ -78,21 +70,20 @@ static void textureVerifyFilterModePoint(float *hOutputData,
|
||||
}
|
||||
}
|
||||
|
||||
static void textureVerifyFilterModeLinear(float *hOutputData,
|
||||
float *expected, int size) {
|
||||
static void textureVerifyFilterModeLinear(float* hOutputData, float* expected, int size) {
|
||||
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) {
|
||||
INFO("Mismatch found at output[" << i << "]:" << hOutputData[i] <<
|
||||
" expected[" << i << "]:" << expected[i] << ", ratio:" << ratio);
|
||||
INFO("Mismatch found at output[" << i << "]:" << hOutputData[i] << " expected[" << i
|
||||
<< "]:" << expected[i] << ", ratio:" << ratio);
|
||||
REQUIRE(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<hipTextureFilterMode fMode = hipFilterModePoint>
|
||||
static void textureVerify(float *hOutputData, float *expected, size_t size) {
|
||||
template <hipTextureFilterMode fMode = hipFilterModePoint>
|
||||
static void textureVerify(float* hOutputData, float* expected, size_t size) {
|
||||
if (fMode == hipFilterModePoint) {
|
||||
textureVerifyFilterModePoint(hOutputData, expected, size);
|
||||
} else if (fMode == hipFilterModeLinear) {
|
||||
@@ -100,34 +91,32 @@ static void textureVerify(float *hOutputData, float *expected, size_t size) {
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, hipTextureFilterMode fMode = hipFilterModePoint>
|
||||
static void textureTest(texture<T, hipTextureType1D,
|
||||
hipReadModeNormalizedFloat> *tex) {
|
||||
template <typename T, hipTextureFilterMode fMode = hipFilterModePoint>
|
||||
static void textureTest(texture<T, hipTextureType1D, hipReadModeNormalizedFloat>* tex) {
|
||||
hipChannelFormatDesc desc = hipCreateChannelDesc<T>();
|
||||
hipArray_t dData;
|
||||
HIP_CHECK(hipMallocArray(&dData, &desc, SIZE, 1, hipArrayDefault));
|
||||
|
||||
T hData[] = {65, 66, 67, 68, 69, 70, 71, 72, 73, 74};
|
||||
HIP_CHECK(hipMemcpy2DToArray(dData, 0, 0, hData, sizeof(T) * SIZE,
|
||||
sizeof(T) * SIZE, 1, hipMemcpyHostToDevice));
|
||||
HIP_CHECK(hipMemcpy2DToArray(dData, 0, 0, hData, sizeof(T) * SIZE, sizeof(T) * SIZE, 1,
|
||||
hipMemcpyHostToDevice));
|
||||
|
||||
tex->normalized = true;
|
||||
tex->channelDesc = desc;
|
||||
tex->filterMode = fMode;
|
||||
HIP_CHECK(hipBindTextureToArray(tex, dData, &desc));
|
||||
|
||||
float *dOutputData = NULL;
|
||||
float* dOutputData = NULL;
|
||||
HIP_CHECK(hipMalloc(&dOutputData, sizeof(float) * SIZE));
|
||||
REQUIRE(dOutputData != nullptr);
|
||||
|
||||
hipLaunchKernelGGL(normalizedValTextureTest<T>, dim3(1, 1, 1),
|
||||
dim3(SIZE, 1, 1), 0, 0, SIZE, dOutputData);
|
||||
HIP_CHECK(hipGetLastError());
|
||||
hipLaunchKernelGGL(normalizedValTextureTest<T>, dim3(1, 1, 1), dim3(SIZE, 1, 1), 0, 0, SIZE,
|
||||
dOutputData);
|
||||
HIP_CHECK(hipGetLastError());
|
||||
|
||||
float *hOutputData = new float[SIZE];
|
||||
float* hOutputData = new float[SIZE];
|
||||
REQUIRE(hOutputData != nullptr);
|
||||
HIP_CHECK(hipMemcpy(hOutputData, dOutputData, (sizeof(float) * SIZE),
|
||||
hipMemcpyDeviceToHost));
|
||||
HIP_CHECK(hipMemcpy(hOutputData, dOutputData, (sizeof(float) * SIZE), hipMemcpyDeviceToHost));
|
||||
|
||||
float expected[SIZE];
|
||||
for (int i = 0; i < SIZE; i++) {
|
||||
@@ -137,10 +126,10 @@ static void textureTest(texture<T, hipTextureType1D,
|
||||
|
||||
HIP_CHECK(hipFreeArray(dData));
|
||||
HIP_CHECK(hipFree(dOutputData));
|
||||
delete [] hOutputData;
|
||||
delete[] hOutputData;
|
||||
}
|
||||
|
||||
template<hipTextureFilterMode fMode = hipFilterModePoint>
|
||||
template <hipTextureFilterMode fMode = hipFilterModePoint>
|
||||
static void runTest_hipTextureFilterMode() {
|
||||
textureTest<char, fMode>(&texc);
|
||||
textureTest<unsigned char, fMode>(&texuc);
|
||||
|
||||
Reference in New Issue
Block a user