2
0

SWDEV-470698 - fix formatting, add format check workflow (#657)

Este cometimento está contido em:
Danylo Lytovchenko
2025-08-20 16:28:06 +02:00
cometido por GitHub
ascendente 5840940caa
cometimento f7338717ae
1574 ficheiros modificados com 162972 adições e 199346 eliminações
+124 -130
Ver ficheiro
@@ -30,12 +30,12 @@ static bool testPassed1D = false;
static bool testPassed2D = false;
static constexpr auto NUM_ELM{1024};
/**
* @addtogroup hipArrayGetDescriptor
* @{
* @ingroup MemoryTest
* hipError_t hipArrayGetDescriptor(HIP_ARRAY_DESCRIPTOR* pArrayDescriptor, hipArray* array) -
* Gets a 1D or 2D array descriptor
*/
* @addtogroup hipArrayGetDescriptor
* @{
* @ingroup MemoryTest
* hipError_t hipArrayGetDescriptor(HIP_ARRAY_DESCRIPTOR* pArrayDescriptor, hipArray* array) -
* Gets a 1D or 2D array descriptor
*/
// Create 1D array
hipArray_t arrayCreate1D(int format, int channel) {
@@ -43,46 +43,46 @@ hipArray_t arrayCreate1D(int format, int channel) {
HIP_ARRAY_DESCRIPTOR desc;
// Number of channels would be 1, 2, 4.
switch (channel) {
case 1:
desc.NumChannels = channel;
break;
case 2:
desc.NumChannels = channel;
break;
case 4:
desc.NumChannels = channel;
break;
case 1:
desc.NumChannels = channel;
break;
case 2:
desc.NumChannels = channel;
break;
case 4:
desc.NumChannels = channel;
break;
}
desc.Width = 16;
desc.Height = 0;
// Number of Formats would be 8 as per enum format
switch (format) {
case 1:
desc.Format = HIP_AD_FORMAT_UNSIGNED_INT8;
break;
case 2:
desc.Format = HIP_AD_FORMAT_UNSIGNED_INT16;
break;
case 3:
desc.Format = HIP_AD_FORMAT_UNSIGNED_INT32;
break;
case 8:
desc.Format = HIP_AD_FORMAT_SIGNED_INT8;
break;
case 9:
desc.Format = HIP_AD_FORMAT_SIGNED_INT16;
break;
case 10:
desc.Format = HIP_AD_FORMAT_SIGNED_INT32;
break;
case 16:
desc.Format = HIP_AD_FORMAT_HALF;
break;
case 32:
desc.Format = HIP_AD_FORMAT_FLOAT;
break;
default:
desc.Format = HIP_AD_FORMAT_FLOAT;
case 1:
desc.Format = HIP_AD_FORMAT_UNSIGNED_INT8;
break;
case 2:
desc.Format = HIP_AD_FORMAT_UNSIGNED_INT16;
break;
case 3:
desc.Format = HIP_AD_FORMAT_UNSIGNED_INT32;
break;
case 8:
desc.Format = HIP_AD_FORMAT_SIGNED_INT8;
break;
case 9:
desc.Format = HIP_AD_FORMAT_SIGNED_INT16;
break;
case 10:
desc.Format = HIP_AD_FORMAT_SIGNED_INT32;
break;
case 16:
desc.Format = HIP_AD_FORMAT_HALF;
break;
case 32:
desc.Format = HIP_AD_FORMAT_FLOAT;
break;
default:
desc.Format = HIP_AD_FORMAT_FLOAT;
}
HIP_CHECK(hipArrayCreate(&array, &desc));
return array;
@@ -94,46 +94,46 @@ hipArray_t arrayCreate2D(int format, int channel) {
HIP_ARRAY_DESCRIPTOR desc;
// Number of channels would be 1, 2, 4.
switch (channel) {
case 1:
desc.NumChannels = channel;
break;
case 2:
desc.NumChannels = channel;
break;
case 4:
desc.NumChannels = channel;
break;
case 1:
desc.NumChannels = channel;
break;
case 2:
desc.NumChannels = channel;
break;
case 4:
desc.NumChannels = channel;
break;
}
desc.Width = 4;
desc.Height = 4;
// Number of Formats would be 8 as per enum format
switch (format) {
case 1:
desc.Format = HIP_AD_FORMAT_UNSIGNED_INT8;
break;
case 2:
desc.Format = HIP_AD_FORMAT_UNSIGNED_INT16;
break;
case 3:
desc.Format = HIP_AD_FORMAT_UNSIGNED_INT32;
break;
case 8:
desc.Format = HIP_AD_FORMAT_SIGNED_INT8;
break;
case 9:
desc.Format = HIP_AD_FORMAT_SIGNED_INT16;
break;
case 10:
desc.Format = HIP_AD_FORMAT_SIGNED_INT32;
break;
case 16:
desc.Format = HIP_AD_FORMAT_HALF;
break;
case 32:
desc.Format = HIP_AD_FORMAT_FLOAT;
break;
default:
desc.Format = HIP_AD_FORMAT_FLOAT;
case 1:
desc.Format = HIP_AD_FORMAT_UNSIGNED_INT8;
break;
case 2:
desc.Format = HIP_AD_FORMAT_UNSIGNED_INT16;
break;
case 3:
desc.Format = HIP_AD_FORMAT_UNSIGNED_INT32;
break;
case 8:
desc.Format = HIP_AD_FORMAT_SIGNED_INT8;
break;
case 9:
desc.Format = HIP_AD_FORMAT_SIGNED_INT16;
break;
case 10:
desc.Format = HIP_AD_FORMAT_SIGNED_INT32;
break;
case 16:
desc.Format = HIP_AD_FORMAT_HALF;
break;
case 32:
desc.Format = HIP_AD_FORMAT_FLOAT;
break;
default:
desc.Format = HIP_AD_FORMAT_FLOAT;
}
HIP_CHECK(hipArrayCreate(&array, &desc));
return array;
@@ -165,9 +165,9 @@ void thread_funct1D(hipArray_t array) {
HIP_ARRAY_DESCRIPTOR desc;
HIP_CHECK(hipArrayGetDescriptor(&desc, array));
// Verify array parameters
if ((desc.NumChannels == 2) && (desc.Width == 16) && (desc.Height == 0)
&& (desc.Format == HIP_AD_FORMAT_HALF) ) {
testPassed1D = true;
if ((desc.NumChannels == 2) && (desc.Width == 16) && (desc.Height == 0) &&
(desc.Format == HIP_AD_FORMAT_HALF)) {
testPassed1D = true;
} else {
testPassed1D = false;
}
@@ -177,9 +177,9 @@ void thread_funct2D(hipArray_t array) {
HIP_ARRAY_DESCRIPTOR desc;
HIP_CHECK(hipArrayGetDescriptor(&desc, array));
// Verify array parameters
if ((desc.NumChannels == 1) && (desc.Width == 4) && (desc.Height == 4)
&& (desc.Format == HIP_AD_FORMAT_FLOAT) ) {
testPassed2D = true;
if ((desc.NumChannels == 1) && (desc.Width == 4) && (desc.Height == 4) &&
(desc.Format == HIP_AD_FORMAT_FLOAT)) {
testPassed2D = true;
} else {
testPassed2D = false;
}
@@ -210,7 +210,7 @@ static hipArray_t arrayCreateSimple2D() {
float* funcToChkArray(hipArray_t array) {
HIP_ARRAY_DESCRIPTOR desc;
HIP_CHECK(hipArrayGetDescriptor(&desc, array));
float *A_h = nullptr;
float* A_h = nullptr;
static constexpr auto NUM_ELM{1024};
size_t mem_size = NUM_ELM * sizeof(float);
if (desc.Format == HIP_AD_FORMAT_FLOAT) {
@@ -241,11 +241,11 @@ TEST_CASE("Unit_hipArrayGetDescriptor_1D_2D_ArrayParameterChk") {
for (int i = 0; i < numDevices; i++) {
HIP_CHECK(hipSetDevice(i));
CHECK_IMAGE_SUPPORT
#if HT_NVIDIA
#if HT_NVIDIA
HIP_CHECK(hipInit(0));
hipCtx_t ctx;
HIP_CHECK(hipCtxCreate(&ctx, 0, i));
#endif
#endif
// 1D array parameters verification
SECTION("1D Array parameters verification") {
hipArray_t array1D = arrayCreate1D(1, 1);
@@ -266,16 +266,12 @@ TEST_CASE("Unit_hipArrayGetDescriptor_1D_2D_ArrayParameterChk") {
REQUIRE(desc1.NumChannels == j);
// Verify format of Array
REQUIRE(desc1.Format == i);
if (i == 3)
i = 7;
if (i == 10)
i = 15;
if (i == 16)
i = 31;
if (i == 3) i = 7;
if (i == 10) i = 15;
if (i == 16) i = 31;
HIP_CHECK(hipArrayDestroy(array1D1));
}
if (j == 2)
j = 3;
if (j == 2) j = 3;
}
}
@@ -297,21 +293,17 @@ TEST_CASE("Unit_hipArrayGetDescriptor_1D_2D_ArrayParameterChk") {
REQUIRE(desc.NumChannels == j);
// Verify format of Array
REQUIRE(desc.Format == i);
if (i == 3)
i = 7;
if (i == 10)
i = 15;
if (i == 16)
i = 31;
if (i == 3) i = 7;
if (i == 10) i = 15;
if (i == 16) i = 31;
HIP_CHECK(hipArrayDestroy(array2D1));
}
if (j == 2)
j = 3;
if (j == 2) j = 3;
}
}
#if HT_NVIDIA
#if HT_NVIDIA
HIP_CHECK(hipCtxDestroy(ctx));
#endif
#endif
}
}
/**
@@ -334,22 +326,23 @@ TEST_CASE("Unit_hipArrayGetDescriptor_MultiThreadScenarioFor1D_2D_Array") {
for (int i = 0; i < numDevices; i++) {
HIP_CHECK(hipSetDevice(i));
CHECK_IMAGE_SUPPORT
#if HT_NVIDIA
#if HT_NVIDIA
HIP_CHECK(hipInit(0));
hipCtx_t ctx;
HIP_CHECK(hipCtxCreate(&ctx, 0, i));
#endif
#endif
hipArray_t array_t1 = arrayCreate1D_Thread();
hipArray_t array_t2 = arrayCreate2D_Thread();
std::vector<std::thread> ThreadVector1D;
std::vector<std::thread> ThreadVector2D;
for (int j = 0; j < 10; j++) {
ThreadVector1D.emplace_back([&](){thread_funct1D(array_t1);});
ThreadVector2D.emplace_back([&](){thread_funct2D(array_t2);});}
for (auto &t : ThreadVector1D) {
ThreadVector1D.emplace_back([&]() { thread_funct1D(array_t1); });
ThreadVector2D.emplace_back([&]() { thread_funct2D(array_t2); });
}
for (auto& t : ThreadVector1D) {
t.join();
}
for (auto &t : ThreadVector2D) {
for (auto& t : ThreadVector2D) {
t.join();
}
// Validation
@@ -357,9 +350,9 @@ TEST_CASE("Unit_hipArrayGetDescriptor_MultiThreadScenarioFor1D_2D_Array") {
REQUIRE(testPassed2D);
HIP_CHECK(hipArrayDestroy(array_t1));
HIP_CHECK(hipArrayDestroy(array_t2));
#if HT_NVIDIA
#if HT_NVIDIA
HIP_CHECK(hipCtxDestroy(ctx));
#endif
#endif
}
}
/**
@@ -383,20 +376,21 @@ TEST_CASE("Unit_hipArrayGetDescriptor_Host2Array_Array2Host") {
for (int k = 0; k < numDevices; k++) {
HIP_CHECK(hipSetDevice(k));
CHECK_IMAGE_SUPPORT
#if HT_NVIDIA
#if HT_NVIDIA
HIP_CHECK(hipInit(0));
hipCtx_t ctx;
HIP_CHECK(hipCtxCreate(&ctx, 0, k));
#endif
#endif
int count_1D = 0;
size_t mem_size = NUM_ELM * sizeof(float);
float *A_h;
float* A_h;
A_h = reinterpret_cast<float*>(malloc(mem_size));
for (int i = 0; i < NUM_ELM; i++) {
A_h[i] = 2.0;}
A_h[i] = 2.0;
}
hipArray_t arraySimple1D = arrayCreateSimple1D();
HIP_CHECK(hipMemcpyHtoA(arraySimple1D, 0, A_h, mem_size));
float *A_h1 = funcToChkArray(arraySimple1D);
float* A_h1 = funcToChkArray(arraySimple1D);
for (int i = 0; i < NUM_ELM; i++) {
if (A_h[i] == A_h1[i]) {
count_1D += 1;
@@ -409,14 +403,15 @@ TEST_CASE("Unit_hipArrayGetDescriptor_Host2Array_Array2Host") {
SECTION("2D Array Verification") {
int count_2D = 0;
size_t mem_size1 = NUM_ELM * sizeof(float);
float *A_h2;
float* A_h2;
A_h2 = reinterpret_cast<float*>(malloc(mem_size1));
for (int i = 0; i < NUM_ELM; i++) {
A_h2[i] = 2.0;}
A_h2[i] = 2.0;
}
hipArray_t arraySimple2D = arrayCreateSimple2D();
HIP_CHECK(hipMemcpyHtoA(arraySimple2D, 0, A_h2, mem_size1));
float *A_h3 = funcToChkArray(arraySimple2D);
float* A_h3 = funcToChkArray(arraySimple2D);
for (int i = 0; i < NUM_ELM; i++) {
if (A_h2[i] == A_h3[i]) {
count_2D += 1;
@@ -427,9 +422,9 @@ TEST_CASE("Unit_hipArrayGetDescriptor_Host2Array_Array2Host") {
free(A_h2);
HIP_CHECK(hipArrayDestroy(arraySimple2D));
}
#if HT_NVIDIA
#if HT_NVIDIA
HIP_CHECK(hipCtxDestroy(ctx));
#endif
#endif
}
}
/**
@@ -450,17 +445,16 @@ TEST_CASE("Unit_hipArrayGetDescriptor_Negative_Scenarios") {
error = hipArrayGetDescriptor(&desc_Neg, nullptr);
REQUIRE(error != hipSuccess);
}
// Enable it for AMD only as it is failing on NVIDIA
#if HT_AMD
void *dptr;
// Enable it for AMD only as it is failing on NVIDIA
#if HT_AMD
void* dptr;
SECTION("Invalid Array Address") {
HIP_CHECK(hipMalloc(&dptr, 1024));
error = hipArrayGetDescriptor(&desc_Neg,
reinterpret_cast<hipArray_t> (dptr));
error = hipArrayGetDescriptor(&desc_Neg, reinterpret_cast<hipArray_t>(dptr));
REQUIRE(error != hipSuccess);
HIP_CHECK(hipFree(dptr));
}
#endif
#endif
}
/**
@@ -549,6 +543,6 @@ TEST_CASE("Unit_hipArrayGetDescriptor_Negative_Parameters") {
}
/**
* End doxygen group MemoryTest.
* @}
*/
* End doxygen group MemoryTest.
* @}
*/