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

Tá an tiomantas seo le fáil i:
Danylo Lytovchenko
2025-08-20 16:28:06 +02:00
tiomanta ag GitHub
tuismitheoir 5840940caa
tiomantas f7338717ae
D'athraigh 1574 comhad le 162972 breiseanna agus 199346 scriosta
@@ -38,28 +38,26 @@ __global__ void test_kernel() {
printf("%-#16.8x\n", 0x42);
}
/**
* @addtogroup printf printf
* @{
* @ingroup PrintfTest
* `int printf()` -
* Method to print the content on output device.
*/
* @addtogroup printf printf
* @{
* @ingroup PrintfTest
* `int printf()` -
* Method to print the content on output device.
*/
/**
* Test Description
* ------------------------
* - Test case to verify alternate forms of printf API.
* Test source
* ------------------------
* - catch/unit/printf/hipPrintfAltForms.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 6.2
*/
* Test Description
* ------------------------
* - Test case to verify alternate forms of printf API.
* Test source
* ------------------------
* - catch/unit/printf/hipPrintfAltForms.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 6.2
*/
TEST_CASE("Unit_Printf_PrintfAltFormsTsts") {
int pcieAtomic = 0;
HIP_CHECK(hipDeviceGetAttribute(&pcieAtomic,
hipDeviceAttributeHostNativeAtomicSupported,
0));
HIP_CHECK(hipDeviceGetAttribute(&pcieAtomic, hipDeviceAttributeHostNativeAtomicSupported, 0));
if (!pcieAtomic) {
HipTest::HIP_SKIP_TEST("Device doesn't support pcie atomic, Skipped");
return;
@@ -88,6 +86,6 @@ TEST_CASE("Unit_Printf_PrintfAltFormsTsts") {
REQUIRE(device_output == reference);
}
/**
* End doxygen group PrintfTest.
* @}
*/
* End doxygen group PrintfTest.
* @}
*/
+46 -56
Féach ar an gComhad
@@ -21,24 +21,25 @@ THE SOFTWARE.
#include <map>
#include "printf_common.h" // NOLINT
const char *msg_short = "Carpe diem.";
const char *msg_long1 = "Lorem ipsum dolor sit amet, consectetur nullam. In mollis imperdiet nibh nec ullamcorper."; // NOLINT
const char *msg_long2 = "Curabitur nec metus sit amet augue vehicula ultrices ut id leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit amet."; // NOLINT
const char* msg_short = "Carpe diem.";
const char* msg_long1 =
"Lorem ipsum dolor sit amet, consectetur nullam. In mollis imperdiet nibh nec ullamcorper."; // NOLINT
const char* msg_long2 =
"Curabitur nec metus sit amet augue vehicula ultrices ut id leo. Lorem ipsum dolor sit amet, "
"consectetur adipiscing elit amet."; // NOLINT
__global__ void kernel_uniform0(int *retval) {
__global__ void kernel_uniform0(int* retval) {
uint tid = hipThreadIdx_x + hipBlockIdx_x * hipBlockDim_x;
retval[tid] = printf("Hello World\n");
}
static void test_uniform0(int *retval, uint num_blocks,
uint threads_per_block) {
static void test_uniform0(int* retval, uint num_blocks, uint threads_per_block) {
CaptureStream captured(stdout);
uint num_threads = num_blocks * threads_per_block;
for (uint i = 0; i != num_threads; ++i) {
retval[i] = 0x23232323;
}
hipLaunchKernelGGL(kernel_uniform0, dim3(num_blocks), dim3(threads_per_block),
0, 0, retval);
hipLaunchKernelGGL(kernel_uniform0, dim3(num_blocks), dim3(threads_per_block), 0, 0, retval);
HIP_CHECK(hipStreamSynchronize(0));
auto CapturedData = captured.getCapturedData();
for (uint ii = 0; ii != num_threads; ++ii) {
@@ -52,23 +53,21 @@ static void test_uniform0(int *retval, uint num_blocks,
REQUIRE(linecount["Hello World"] == num_threads);
}
__global__ void kernel_uniform1(int *retval) {
__global__ void kernel_uniform1(int* retval) {
uint tid = hipThreadIdx_x + hipBlockIdx_x * hipBlockDim_x;
retval[tid] = printf("Six times Eight is %d\n", 42);
}
static void test_uniform1(int *retval, uint num_blocks,
uint threads_per_block) {
static void test_uniform1(int* retval, uint num_blocks, uint threads_per_block) {
CaptureStream captured(stdout);
uint num_threads = num_blocks * threads_per_block;
for (uint i = 0; i != num_threads; ++i) {
retval[i] = 0x23232323;
}
hipLaunchKernelGGL(kernel_uniform1, dim3(num_blocks), dim3(threads_per_block),
0, 0, retval);
hipLaunchKernelGGL(kernel_uniform1, dim3(num_blocks), dim3(threads_per_block), 0, 0, retval);
HIP_CHECK(hipStreamSynchronize(0));
auto CapturedData = captured.getCapturedData();
for (uint ii = 0; ii != num_threads; ++ii) {
for (uint ii = 0; ii != num_threads; ++ii) {
REQUIRE(retval[ii] == strlen("Six times Eight is 42") + 1);
}
std::map<std::string, int> linecount;
@@ -79,20 +78,18 @@ static void test_uniform1(int *retval, uint num_blocks,
REQUIRE(linecount["Six times Eight is 42"] == num_threads);
}
__global__ void kernel_divergent0(int *retval) {
__global__ void kernel_divergent0(int* retval) {
uint tid = hipThreadIdx_x + hipBlockIdx_x * hipBlockDim_x;
retval[tid] = printf("Thread ID: %d\n", tid);
}
static void test_divergent0(int *retval, uint num_blocks,
uint threads_per_block) {
static void test_divergent0(int* retval, uint num_blocks, uint threads_per_block) {
CaptureStream captured(stdout);
uint num_threads = num_blocks * threads_per_block;
for (uint i = 0; i != num_threads; ++i) {
retval[i] = 0x23232323;
}
hipLaunchKernelGGL(kernel_divergent0, dim3(num_blocks),
dim3(threads_per_block), 0, 0, retval);
hipLaunchKernelGGL(kernel_divergent0, dim3(num_blocks), dim3(threads_per_block), 0, 0, retval);
HIP_CHECK(hipStreamSynchronize(0));
auto CapturedData = captured.getCapturedData();
for (uint ii = 0; ii != 10; ++ii) {
@@ -112,7 +109,7 @@ static void test_divergent0(int *retval, uint num_blocks,
REQUIRE(threadIds.back() == num_threads - 1);
}
__global__ void kernel_divergent1(int *retval) {
__global__ void kernel_divergent1(int* retval) {
uint tid = hipThreadIdx_x + hipBlockIdx_x * hipBlockDim_x;
if (tid % 2) {
retval[tid] = printf("Hello World\n");
@@ -121,15 +118,13 @@ __global__ void kernel_divergent1(int *retval) {
}
}
static void test_divergent1(int *retval, uint num_blocks,
uint threads_per_block) {
static void test_divergent1(int* retval, uint num_blocks, uint threads_per_block) {
CaptureStream captured(stdout);
uint num_threads = num_blocks * threads_per_block;
for (uint i = 0; i != num_threads; ++i) {
retval[i] = 0x23232323;
}
hipLaunchKernelGGL(kernel_divergent1, dim3(num_blocks),
dim3(threads_per_block), 0, 0, retval);
hipLaunchKernelGGL(kernel_divergent1, dim3(num_blocks), dim3(threads_per_block), 0, 0, retval);
HIP_CHECK(hipStreamSynchronize(0));
auto CapturedData = captured.getCapturedData();
for (uint ii = 0; ii != num_threads; ++ii) {
@@ -147,7 +142,7 @@ static void test_divergent1(int *retval, uint num_blocks,
REQUIRE(linecount["Hello World"] == num_threads / 2);
}
__global__ void kernel_series(int *retval) {
__global__ void kernel_series(int* retval) {
const uint tid = hipThreadIdx_x + hipBlockIdx_x * hipBlockDim_x;
int result = 0;
result += printf("%s\n", msg_long1_dev);
@@ -156,22 +151,19 @@ __global__ void kernel_series(int *retval) {
retval[tid] = result;
}
static void test_series(int *retval, uint num_blocks, uint threads_per_block) {
static void test_series(int* retval, uint num_blocks, uint threads_per_block) {
CaptureStream captured(stdout);
uint num_threads = num_blocks * threads_per_block;
for (uint i = 0; i != num_threads; ++i) {
retval[i] = 0x23232323;
}
hipLaunchKernelGGL(kernel_series, dim3(num_blocks), dim3(threads_per_block),
0, 0, retval);
hipLaunchKernelGGL(kernel_series, dim3(num_blocks), dim3(threads_per_block), 0, 0, retval);
HIP_CHECK(hipStreamSynchronize(0));
auto CapturedData = captured.getCapturedData();
for (uint ii = 0; ii != num_threads; ++ii) {
REQUIRE(retval[ii] ==
strlen(msg_long1) + strlen(msg_short) +
strlen(msg_long2) + 3);
REQUIRE(retval[ii] == strlen(msg_long1) + strlen(msg_short) + strlen(msg_long2) + 3);
}
std::map<std::string, int> linecount;
std::map<std::string, int> linecount;
for (std::string line; std::getline(CapturedData, line);) {
linecount[line]++;
}
@@ -181,28 +173,26 @@ static void test_series(int *retval, uint num_blocks, uint threads_per_block) {
REQUIRE(linecount[msg_short] == num_threads);
}
/**
* @addtogroup printf printf
* @{
* @ingroup PrintfTest
* `int printf()` -
* Method to print the content on output device.
*/
* @addtogroup printf printf
* @{
* @ingroup PrintfTest
* `int printf()` -
* Method to print the content on output device.
*/
/**
* Test Description
* ------------------------
* - Test case to verify basic functionality of printf API.
* Test source
* ------------------------
* - catch/unit/printf/hipPrintfBasic.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 6.2
*/
* Test Description
* ------------------------
* - Test case to verify basic functionality of printf API.
* Test source
* ------------------------
* - catch/unit/printf/hipPrintfBasic.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 6.2
*/
TEST_CASE("Unit_Printf_PrintfBasicTsts") {
int pcieAtomic = 0;
HIP_CHECK(hipDeviceGetAttribute(&pcieAtomic,
hipDeviceAttributeHostNativeAtomicSupported,
0));
HIP_CHECK(hipDeviceGetAttribute(&pcieAtomic, hipDeviceAttributeHostNativeAtomicSupported, 0));
if (!pcieAtomic) {
HipTest::HIP_SKIP_TEST("Device doesn't support pcie atomic, Skipped");
return;
@@ -210,9 +200,9 @@ TEST_CASE("Unit_Printf_PrintfBasicTsts") {
uint num_blocks = 1;
uint threads_per_block = 64;
uint num_threads = num_blocks * threads_per_block;
void *retval_void;
void* retval_void;
HIP_CHECK(hipHostMalloc(&retval_void, 4 * num_threads));
auto retval = reinterpret_cast<int *>(retval_void);
auto retval = reinterpret_cast<int*>(retval_void);
test_uniform0(retval, num_blocks, threads_per_block);
test_uniform1(retval, num_blocks, threads_per_block);
test_divergent0(retval, num_blocks, threads_per_block);
@@ -221,6 +211,6 @@ TEST_CASE("Unit_Printf_PrintfBasicTsts") {
HIP_CHECK(hipFree(retval_void));
}
/**
* End doxygen group PrintfTest.
* @}
*/
* End doxygen group PrintfTest.
* @}
*/
@@ -23,36 +23,33 @@ THE SOFTWARE.
__global__ void print_things() {
uint tid = hipThreadIdx_x + hipBlockIdx_x * hipBlockDim_x;
const char *msg[] = {msg_short_dev, msg_long1_dev, msg_long2_dev};
const char* msg[] = {msg_short_dev, msg_long1_dev, msg_long2_dev};
printf("%s\n", msg[tid % 3]);
if (tid % 3 == 0)
printf("%s\n", msg_short_dev);
if (tid % 3 == 0) printf("%s\n", msg_short_dev);
printf("%s\n", msg[(tid + 1) % 3]);
printf("%s\n", msg[(tid + 2) % 3]);
}
/**
* @addtogroup printf printf
* @{
* @ingroup PrintfTest
* `int printf()` -
* Method to print the content on output device.
*/
* @addtogroup printf printf
* @{
* @ingroup PrintfTest
* `int printf()` -
* Method to print the content on output device.
*/
/**
* Test Description
* ------------------------
* - Test case to verify printf API functionality on many devices
* Test source
* ------------------------
* - catch/unit/printf/hipPrintfManyDevices.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 6.2
*/
* Test Description
* ------------------------
* - Test case to verify printf API functionality on many devices
* Test source
* ------------------------
* - catch/unit/printf/hipPrintfManyDevices.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 6.2
*/
TEST_CASE("Unit_Printf_ManyDevicesTest") {
int pcieAtomic = 0;
HIP_CHECK(hipDeviceGetAttribute(&pcieAtomic,
hipDeviceAttributeHostNativeAtomicSupported,
0));
HIP_CHECK(hipDeviceGetAttribute(&pcieAtomic, hipDeviceAttributeHostNativeAtomicSupported, 0));
if (!pcieAtomic) {
HipTest::HIP_SKIP_TEST("Device doesn't support pcie atomic, Skipped");
return;
@@ -65,8 +62,7 @@ TEST_CASE("Unit_Printf_ManyDevicesTest") {
CaptureStream captured(stdout);
for (int i = 0; i != num_devices; ++i) {
HIP_CHECK(hipSetDevice(i));
hipLaunchKernelGGL(print_things, dim3(num_blocks), dim3(threads_per_block),
0, 0);
hipLaunchKernelGGL(print_things, dim3(num_blocks), dim3(threads_per_block), 0, 0);
HIP_CHECK(hipDeviceSynchronize());
}
auto CapturedData = captured.getCapturedData();
@@ -78,10 +74,9 @@ TEST_CASE("Unit_Printf_ManyDevicesTest") {
REQUIRE(linecount.size() == 3);
REQUIRE(linecount[msg_long1] == num_threads);
REQUIRE(linecount[msg_long2] == num_threads);
REQUIRE(linecount[msg_short] ==
num_threads + ((threads_per_device + 2) / 3) * num_devices);
REQUIRE(linecount[msg_short] == num_threads + ((threads_per_device + 2) / 3) * num_devices);
}
/**
* End doxygen group PrintfTest.
* @}
*/
* End doxygen group PrintfTest.
* @}
*/
@@ -22,45 +22,44 @@ THE SOFTWARE.
#include <map>
#include "printf_common.h" // NOLINT
__global__ void kernel_mixed0(int *retval) {
__global__ void kernel_mixed0(int* retval) {
uint tid = hipThreadIdx_x + hipBlockIdx_x * hipBlockDim_x;
// Three strings passed as divergent values to the same hostcall.
const char *msg;
const char* msg;
switch (tid % 3) {
case 0:
msg = msg_short_dev;
break;
case 1:
msg = msg_long1_dev;
break;
case 2:
msg = msg_long2_dev;
break;
case 0:
msg = msg_short_dev;
break;
case 1:
msg = msg_long1_dev;
break;
case 2:
msg = msg_long2_dev;
break;
}
retval[tid] = printf("%s\n", msg);
}
static void test_mixed0(int *retval, uint num_blocks, uint threads_per_block) {
static void test_mixed0(int* retval, uint num_blocks, uint threads_per_block) {
CaptureStream captured(stdout);
uint num_threads = num_blocks * threads_per_block;
for (uint i = 0; i != num_threads; ++i) {
retval[i] = 0x23232323;
}
hipLaunchKernelGGL(kernel_mixed0, dim3(num_blocks), dim3(threads_per_block),
0, 0, retval);
hipLaunchKernelGGL(kernel_mixed0, dim3(num_blocks), dim3(threads_per_block), 0, 0, retval);
HIP_CHECK(hipStreamSynchronize(0));
auto CapturedData = captured.getCapturedData();
for (uint ii = 0; ii != num_threads; ++ii) {
switch (ii % 3) {
case 0:
REQUIRE(retval[ii] == strlen(msg_short) + 1);
break;
case 1:
REQUIRE(retval[ii] == strlen(msg_long1) + 1);
break;
case 2:
REQUIRE(retval[ii] == strlen(msg_long2) + 1);
break;
case 0:
REQUIRE(retval[ii] == strlen(msg_short) + 1);
break;
case 1:
REQUIRE(retval[ii] == strlen(msg_long1) + 1);
break;
case 2:
REQUIRE(retval[ii] == strlen(msg_long2) + 1);
break;
}
}
std::map<std::string, int> linecount;
@@ -73,43 +72,42 @@ static void test_mixed0(int *retval, uint num_blocks, uint threads_per_block) {
REQUIRE(linecount[msg_long2] == (num_threads + 0) / 3);
}
__global__ void kernel_mixed1(int *retval) {
__global__ void kernel_mixed1(int* retval) {
const uint tid = hipThreadIdx_x + hipBlockIdx_x * hipBlockDim_x;
// Three strings passed to divergent hostcalls.
switch (tid % 3) {
case 0:
retval[tid] = printf("%s\n", msg_short_dev);
break;
case 1:
retval[tid] = printf("%s\n", msg_long1_dev);
break;
case 2:
retval[tid] = printf("%s\n", msg_long2_dev);
break;
case 0:
retval[tid] = printf("%s\n", msg_short_dev);
break;
case 1:
retval[tid] = printf("%s\n", msg_long1_dev);
break;
case 2:
retval[tid] = printf("%s\n", msg_long2_dev);
break;
}
}
static void test_mixed1(int *retval, uint num_blocks, uint threads_per_block) {
static void test_mixed1(int* retval, uint num_blocks, uint threads_per_block) {
CaptureStream captured(stdout);
uint num_threads = num_blocks * threads_per_block;
for (uint i = 0; i != num_threads; ++i) {
retval[i] = 0x23232323;
}
hipLaunchKernelGGL(kernel_mixed1, dim3(num_blocks), dim3(threads_per_block),
0, 0, retval);
hipLaunchKernelGGL(kernel_mixed1, dim3(num_blocks), dim3(threads_per_block), 0, 0, retval);
HIP_CHECK(hipStreamSynchronize(0));
auto CapturedData = captured.getCapturedData();
for (uint ii = 0; ii != num_threads; ++ii) {
switch (ii % 3) {
case 0:
REQUIRE(retval[ii] == strlen(msg_short) + 1);
break;
case 1:
REQUIRE(retval[ii] == strlen(msg_long1) + 1);
break;
case 2:
REQUIRE(retval[ii] == strlen(msg_long2) + 1);
break;
case 0:
REQUIRE(retval[ii] == strlen(msg_short) + 1);
break;
case 1:
REQUIRE(retval[ii] == strlen(msg_long1) + 1);
break;
case 2:
REQUIRE(retval[ii] == strlen(msg_long2) + 1);
break;
}
}
std::map<std::string, int> linecount;
@@ -122,50 +120,40 @@ static void test_mixed1(int *retval, uint num_blocks, uint threads_per_block) {
REQUIRE(linecount[msg_long2] == (num_threads + 0) / 3);
}
__global__ void kernel_mixed2(int *retval) {
__global__ void kernel_mixed2(int* retval) {
const uint tid = hipThreadIdx_x + hipBlockIdx_x * hipBlockDim_x;
// Three different strings. All workitems print all three, but
// in different orders.
const char *msg[] = {msg_short_dev, msg_long1_dev, msg_long2_dev};
retval[tid] =
printf("%s%s%s\n", msg[tid % 3], msg[(tid + 1) % 3], msg[(tid + 2) % 3]);
const char* msg[] = {msg_short_dev, msg_long1_dev, msg_long2_dev};
retval[tid] = printf("%s%s%s\n", msg[tid % 3], msg[(tid + 1) % 3], msg[(tid + 2) % 3]);
}
static void test_mixed2(int *retval, uint num_blocks, uint threads_per_block) {
static void test_mixed2(int* retval, uint num_blocks, uint threads_per_block) {
CaptureStream captured(stdout);
uint num_threads = num_blocks * threads_per_block;
for (uint i = 0; i != num_threads; ++i) {
retval[i] = 0x23232323;
}
hipLaunchKernelGGL(kernel_mixed2, dim3(num_blocks), dim3(threads_per_block),
0, 0, retval);
hipLaunchKernelGGL(kernel_mixed2, dim3(num_blocks), dim3(threads_per_block), 0, 0, retval);
HIP_CHECK(hipStreamSynchronize(0));
auto CapturedData = captured.getCapturedData();
for (uint ii = 0; ii != num_threads; ++ii) {
REQUIRE(retval[ii] ==
strlen(msg_short) + strlen(msg_long1) +
strlen(msg_long2) + 1);
REQUIRE(retval[ii] == strlen(msg_short) + strlen(msg_long1) + strlen(msg_long2) + 1);
}
std::map<std::string, int> linecount;
for (std::string line; std::getline(CapturedData, line);) {
linecount[line]++;
}
std::string str1 =
std::string(msg_short) + std::string(msg_long1) +
std::string(msg_long2);
std::string str2 =
std::string(msg_long1) + std::string(msg_long2) +
std::string(msg_short);
std::string str3 =
std::string(msg_long2) + std::string(msg_short) +
std::string(msg_long1);
std::string str1 = std::string(msg_short) + std::string(msg_long1) + std::string(msg_long2);
std::string str2 = std::string(msg_long1) + std::string(msg_long2) + std::string(msg_short);
std::string str3 = std::string(msg_long2) + std::string(msg_short) + std::string(msg_long1);
REQUIRE(linecount.size() == 3);
REQUIRE(linecount[str1] == (num_threads + 2) / 3);
REQUIRE(linecount[str2] == (num_threads + 1) / 3);
REQUIRE(linecount[str3] == (num_threads + 0) / 3);
}
__global__ void kernel_mixed3(int *retval) {
__global__ void kernel_mixed3(int* retval) {
const uint tid = hipThreadIdx_x + hipBlockIdx_x * hipBlockDim_x;
int result = 0;
result += printf("%s\n", msg_long1_dev);
@@ -176,24 +164,20 @@ __global__ void kernel_mixed3(int *retval) {
retval[tid] = result;
}
static void test_mixed3(int *retval, uint num_blocks, uint threads_per_block) {
static void test_mixed3(int* retval, uint num_blocks, uint threads_per_block) {
CaptureStream captured(stdout);
uint num_threads = num_blocks * threads_per_block;
for (uint i = 0; i != num_threads; ++i) {
retval[i] = 0x23232323;
}
hipLaunchKernelGGL(kernel_mixed3, dim3(num_blocks), dim3(threads_per_block),
0, 0, retval);
hipLaunchKernelGGL(kernel_mixed3, dim3(num_blocks), dim3(threads_per_block), 0, 0, retval);
HIP_CHECK(hipStreamSynchronize(0));
auto CapturedData = captured.getCapturedData();
for (uint ii = 0; ii != num_threads; ++ii) {
for (uint ii = 0; ii != num_threads; ++ii) {
if (ii % 3 == 0) {
REQUIRE(retval[ii] ==
strlen(msg_long1) + strlen(msg_short) +
strlen(msg_long2) + 3);
REQUIRE(retval[ii] == strlen(msg_long1) + strlen(msg_short) + strlen(msg_long2) + 3);
} else {
REQUIRE(retval[ii] == strlen(msg_long1) +
strlen(msg_long2) + 2);
REQUIRE(retval[ii] == strlen(msg_long1) + strlen(msg_long2) + 2);
}
}
std::map<std::string, int> linecount;
@@ -217,16 +201,14 @@ __global__ void kernel_numbers() {
static void test_numbers(uint num_blocks, uint threads_per_block) {
CaptureStream captured(stdout);
uint num_threads = num_blocks * threads_per_block;
hipLaunchKernelGGL(kernel_numbers, dim3(num_blocks), dim3(threads_per_block),
0, 0);
hipLaunchKernelGGL(kernel_numbers, dim3(num_blocks), dim3(threads_per_block), 0, 0);
HIP_CHECK(hipStreamSynchronize(0));
auto CapturedData = captured.getCapturedData();
std::vector<uint> points;
while (true) {
uint i;
CapturedData >> i;
if (CapturedData.fail())
break;
if (CapturedData.fail()) break;
points.push_back(i);
}
std::sort(points.begin(), points.end());
@@ -235,28 +217,26 @@ static void test_numbers(uint num_blocks, uint threads_per_block) {
REQUIRE(points.back() == 21 * num_threads - 1);
}
/**
* @addtogroup printf printf
* @{
* @ingroup PrintfTest
* `int printf()` -
* Method to print the content on output device.
*/
* @addtogroup printf printf
* @{
* @ingroup PrintfTest
* `int printf()` -
* Method to print the content on output device.
*/
/**
* Test Description
* ------------------------
* - Test case to verify printf API functionality with different strings
* Test source
* ------------------------
* - catch/unit/printf/hipPrintfManyWaves.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 6.2
*/
* Test Description
* ------------------------
* - Test case to verify printf API functionality with different strings
* Test source
* ------------------------
* - catch/unit/printf/hipPrintfManyWaves.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 6.2
*/
TEST_CASE("Unit_Printf_PrintfManyWaves") {
int pcieAtomic = 0;
HIP_CHECK(hipDeviceGetAttribute(&pcieAtomic,
hipDeviceAttributeHostNativeAtomicSupported,
0));
HIP_CHECK(hipDeviceGetAttribute(&pcieAtomic, hipDeviceAttributeHostNativeAtomicSupported, 0));
if (!pcieAtomic) {
HipTest::HIP_SKIP_TEST("Device doesn't support pcie atomic, Skipped");
return;
@@ -264,9 +244,9 @@ TEST_CASE("Unit_Printf_PrintfManyWaves") {
uint num_blocks = 150;
uint threads_per_block = 250;
uint num_threads = num_blocks * threads_per_block;
void *retval_void;
void* retval_void;
HIP_CHECK(hipHostMalloc(&retval_void, 4 * num_threads));
auto retval = reinterpret_cast<int *>(retval_void);
auto retval = reinterpret_cast<int*>(retval_void);
test_mixed0(retval, num_blocks, threads_per_block);
test_mixed1(retval, num_blocks, threads_per_block);
test_mixed2(retval, num_blocks, threads_per_block);
@@ -275,6 +255,6 @@ TEST_CASE("Unit_Printf_PrintfManyWaves") {
HIP_CHECK(hipFree(retval_void));
}
/**
* End doxygen group PrintfTest.
* @}
*/
* End doxygen group PrintfTest.
* @}
*/
+21 -23
Féach ar an gComhad
@@ -18,7 +18,7 @@ THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <hip_test_defgroups.hh>
#include "printf_common.h" // NOLINT
#include "printf_common.h" // NOLINT
__global__ void test_kernel_star() {
printf("%*d\n", 16, 42);
@@ -27,28 +27,26 @@ __global__ void test_kernel_star() {
printf("%*.*f %s * %.*s\n", 16, 8, 123.456, "hello", 5, "worldxyz");
}
/**
* @addtogroup printf printf
* @{
* @ingroup PrintfTest
* `int printf()` -
* Method to print the content on output device.
*/
* @addtogroup printf printf
* @{
* @ingroup PrintfTest
* `int printf()` -
* Method to print the content on output device.
*/
/**
* Test Description
* ------------------------
* - Test case to verify the additional arguments (*) in the printf API
* Test source
* ------------------------
* - catch/unit/printf/hipPrintfStar.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 6.2
*/
* Test Description
* ------------------------
* - Test case to verify the additional arguments (*) in the printf API
* Test source
* ------------------------
* - catch/unit/printf/hipPrintfStar.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 6.2
*/
TEST_CASE("Unit_Printf_PrintfStar") {
int pcieAtomic = 0;
HIP_CHECK(hipDeviceGetAttribute(&pcieAtomic,
hipDeviceAttributeHostNativeAtomicSupported,
0));
HIP_CHECK(hipDeviceGetAttribute(&pcieAtomic, hipDeviceAttributeHostNativeAtomicSupported, 0));
if (!pcieAtomic) {
HipTest::HIP_SKIP_TEST("Device doesn't support pcie atomic, Skipped");
return;
@@ -67,6 +65,6 @@ TEST_CASE("Unit_Printf_PrintfStar") {
}
/**
* End doxygen group PrintfTest.
* @}
*/
* End doxygen group PrintfTest.
* @}
*/
@@ -37,28 +37,26 @@ __global__ void test_kernel_width() {
printf("%.5s\n", "helloxyz");
}
/**
* @addtogroup printf printf
* @{
* @ingroup PrintfTest
* `int printf()` -
* Method to print the content on output device.
*/
* @addtogroup printf printf
* @{
* @ingroup PrintfTest
* `int printf()` -
* Method to print the content on output device.
*/
/**
* Test Description
* ------------------------
* - Test case to verify the floating point details via printf API
* Test source
* ------------------------
* - catch/unit/printf/hipPrintfWidthPrecision.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 6.2
*/
* Test Description
* ------------------------
* - Test case to verify the floating point details via printf API
* Test source
* ------------------------
* - catch/unit/printf/hipPrintfWidthPrecision.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 6.2
*/
TEST_CASE("Unit_Printf_PrintfWidthPrecision") {
int pcieAtomic = 0;
HIP_CHECK(hipDeviceGetAttribute(&pcieAtomic,
hipDeviceAttributeHostNativeAtomicSupported,
0));
HIP_CHECK(hipDeviceGetAttribute(&pcieAtomic, hipDeviceAttributeHostNativeAtomicSupported, 0));
if (!pcieAtomic) {
HipTest::HIP_SKIP_TEST("Device doesn't support pcie atomic, Skipped");
return;
@@ -87,6 +85,6 @@ hello
}
/**
* End doxygen group PrintfTest.
* @}
*/
* End doxygen group PrintfTest.
* @}
*/
+9 -9
Féach ar an gComhad
@@ -24,12 +24,12 @@ THE SOFTWARE.
#include <hip_test_process.hh>
/**
* @addtogroup printf printf
* @{
* @ingroup PrintfTest
* `int printf()` -
* Method to print the content on output device.
*/
* @addtogroup printf printf
* @{
* @ingroup PrintfTest
* `int printf()` -
* Method to print the content on output device.
*/
/**
@@ -81,6 +81,6 @@ xyzzy
}
/**
* End doxygen group PrintfTest.
* @}
*/
* End doxygen group PrintfTest.
* @}
*/
@@ -18,27 +18,28 @@ THE SOFTWARE.
#include <hip_test_common.hh>
#include <hip_test_process.hh>
/**
* @addtogroup printf printf
* @{
* @ingroup PrintfTest
* `int printf()` -
* Method to print the content on output device.
*/
* @addtogroup printf printf
* @{
* @ingroup PrintfTest
* `int printf()` -
* Method to print the content on output device.
*/
/**
* Test Description
* ------------------------
* - Test case to verify the printf return value from other process for the compiler option -mprintf-kind=buffered
* - Fetch the printf content from a process. Compare it with reference string.
* Test source
* ------------------------
* - catch/unit/printf/printfFlagsNonHost.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.7
*/
* Test Description
* ------------------------
* - Test case to verify the printf return value from other process for the compiler option
* -mprintf-kind=buffered
* - Fetch the printf content from a process. Compare it with reference string.
* Test source
* ------------------------
* - catch/unit/printf/printfFlagsNonHost.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.7
*/
TEST_CASE("Unit_Buffered_Printf_Flags") {
int pcieAtomic = 0;
@@ -67,6 +68,6 @@ xyzzy
/**
* End doxygen group PrintfTest.
* @}
*/
* End doxygen group PrintfTest.
* @}
*/
+18 -20
Féach ar an gComhad
@@ -19,24 +19,22 @@
THE SOFTWARE.
*/
#include <hip_test_common.hh>
// Kernel Function
__global__ void run_printf(int *count) {
*count = printf("Hello World");
}
__global__ void run_printf(int* count) { *count = printf("Hello World"); }
/**
* @addtogroup printf printf
* @{
* @ingroup PrintfTest
* `int printf()` -
* Method to print the content on output device.
*/
* @addtogroup printf printf
* @{
* @ingroup PrintfTest
* `int printf()` -
* Method to print the content on output device.
*/
/**
* Test Description
* ------------------------
* - Test case to verify the printf return value(Number of Characters)for -mprintf-kind=hostcall compiler option
* Test source
* - Test case to verify the printf return value(Number of Characters)for -mprintf-kind=hostcall
* compiler option Test source
* ------------------------
* - catch/unit/printf/printfHost.cc
* Test requirements
@@ -60,16 +58,16 @@ TEST_CASE("Unit_Host_Printf") {
std::string str = "Hello World";
int length = str.length();
#if HT_AMD
REQUIRE(length == *count);
#else
REQUIRE(*count == 0);
#endif
#if HT_AMD
REQUIRE(length == *count);
#else
REQUIRE(*count == 0);
#endif
free(count);
HIP_CHECK(hipFree(count_d));
}
/**
* End doxygen group PrintfTest.
* @}
*/
* End doxygen group PrintfTest.
* @}
*/
@@ -24,12 +24,12 @@ THE SOFTWARE.
#include <hip_test_process.hh>
/**
* @addtogroup printf printf
* @{
* @ingroup PrintfTest
* `int printf()` -
* Method to print the content on output device.
*/
* @addtogroup printf printf
* @{
* @ingroup PrintfTest
* `int printf()` -
* Method to print the content on output device.
*/
/**
* Test Description
@@ -93,6 +93,6 @@ x
}
/**
* End doxygen group PrintfTest.
* @}
*/
* End doxygen group PrintfTest.
* @}
*/
@@ -41,7 +41,7 @@ __global__ void test_kernel() {
printf("%lx %lX\n", 42l, 42l);
printf("%llx %llX\n", 42ll, 42ll);
printf("%lf\n", 123.456);
printf("%lc\n", wint_t ('x'));
printf("%lc\n", wint_t('x'));
#if HT_AMD
const char* N = nullptr;
printf("%lF\n", 123.456);
+46 -52
Féach ar an gComhad
@@ -26,48 +26,46 @@
#define ITER_COUNT_FOR_THREAD (BLOCK_SIZE * THREADS_PER_BLOCK)
#define CONST_STR "Hello World from Device.Iam printing 55 bytes of data.\n"
//info_.printfBufferSize_ = PrintfDbg::WorkitemDebugSize(4096) * info().maxWorkGroupSize_(1024)
#define MAX_BUFF_SIZE (4096 * 1024)
// info_.printfBufferSize_ = PrintfDbg::WorkitemDebugSize(4096) * info().maxWorkGroupSize_(1024)
#define MAX_BUFF_SIZE (4096 * 1024)
//<control DWord (4 bytes)><format string hash (8 bytes)><printf arguments each aligned to 8 bytes>
#define Item_BUFF_SIZE (4 + 8 + 56) /* 56 = 55 + 1 byte null terminator */
#define VALID_COUNT (MAX_BUFF_SIZE / Item_BUFF_SIZE)
#define ITER_COUNT (VALID_COUNT + 1)
#define VALID_COUNT (MAX_BUFF_SIZE / Item_BUFF_SIZE)
#define ITER_COUNT (VALID_COUNT + 1)
// Kernel Functions
__global__ void run_printf_basic(int *count) {
*count = printf("Hello World\n");
}
__global__ void run_printf_basic(int* count) { *count = printf("Hello World\n"); }
__global__ void kernel_printf_loop(uint iterCount, int *count) {
__global__ void kernel_printf_loop(uint iterCount, int* count) {
for (uint i = 0; i < iterCount; i++) {
count[i] = printf("%s", CONST_STR);
}
}
__global__ void kernel_printf_thread(int *count) {
__global__ void kernel_printf_thread(int* count) {
uint tid = threadIdx.x + blockIdx.x * blockDim.x;
count[tid] = printf("%s", CONST_STR);
}
/**
* @addtogroup printf printf
* @{
* @ingroup PrintfTest
* `int printf()` -
* Method to print the content on output device.
*/
* @addtogroup printf printf
* @{
* @ingroup PrintfTest
* `int printf()` -
* Method to print the content on output device.
*/
/**
* Test Description
* ------------------------
* - Test case to verify the printf return value for -mprintf-kind=buffered compiler option
* - printf should return 0 for normal buffer.
* Test source
* ------------------------
* - catch/unit/printf/printfNonHost.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.7
*/
* Test Description
* ------------------------
* - Test case to verify the printf return value for -mprintf-kind=buffered compiler option
* - printf should return 0 for normal buffer.
* Test source
* ------------------------
* - catch/unit/printf/printfNonHost.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.7
*/
TEST_CASE("Unit_NonHost_Printf_basic") {
int pcieAtomic = 0;
@@ -93,9 +91,10 @@ TEST_CASE("Unit_NonHost_Printf_basic") {
/**
* Test Description
* ------------------------
* - Test case to verify the printf return value for big buffer for -mprintf-kind=buffered compiler option
* - Call the printf API for number of iterations in the Kernel Function. Printf should return -1 for overflow buffer.
* Test source
* - Test case to verify the printf return value for big buffer for -mprintf-kind=buffered compiler
* option
* - Call the printf API for number of iterations in the Kernel Function. Printf should return -1
* for overflow buffer. Test source
* ------------------------
* - catch/unit/printf/printfNonHost.cc
* Test requirements
@@ -114,18 +113,16 @@ TEST_CASE("Unit_NonHost_Printf_loop") {
count = reinterpret_cast<int*>(malloc(ITER_COUNT * sizeof(int)));
HIP_CHECK(hipMalloc(&count_d, ITER_COUNT * sizeof(int)));
hipLaunchKernelGGL(kernel_printf_loop, dim3(1), dim3(1), 0, 0,
ITER_COUNT, count_d);
hipLaunchKernelGGL(kernel_printf_loop, dim3(1), dim3(1), 0, 0, ITER_COUNT, count_d);
HIP_CHECK(hipMemcpy(count, count_d, ITER_COUNT * sizeof(int),
hipMemcpyDeviceToHost));
HIP_CHECK(hipMemcpy(count, count_d, ITER_COUNT * sizeof(int), hipMemcpyDeviceToHost));
int test = 0;
for (int i = 0; i < ITER_COUNT; i++) {
if (count[i] == -1) {
test = i;
}
}
if (test == (ITER_COUNT-1)) {
if (test == (ITER_COUNT - 1)) {
REQUIRE(true);
} else {
REQUIRE(false);
@@ -136,7 +133,8 @@ TEST_CASE("Unit_NonHost_Printf_loop") {
/**
* Test Description
* ------------------------
* - Test case to verify the printf return value for big buffer for -mprintf-kind=buffered compiler option
* - Test case to verify the printf return value for big buffer for -mprintf-kind=buffered compiler
* option
* - Call the single printf API for multiple threads. Printf should return -1 for overflow buffer.
* Test source
* ------------------------
@@ -158,17 +156,15 @@ TEST_CASE("Unit_NonHost_Printf_multiple_Threads") {
count = reinterpret_cast<int*>(malloc(ITER_COUNT_FOR_THREAD * sizeof(int)));
HIP_CHECK(hipMalloc(&count_d, ITER_COUNT_FOR_THREAD * sizeof(int)));
hipLaunchKernelGGL(kernel_printf_thread, dim3(BLOCK_SIZE),
dim3(THREADS_PER_BLOCK),
0, 0, count_d);
hipLaunchKernelGGL(kernel_printf_thread, dim3(BLOCK_SIZE), dim3(THREADS_PER_BLOCK), 0, 0,
count_d);
HIP_CHECK(hipMemcpy(count, count_d, ITER_COUNT_FOR_THREAD * sizeof(int),
hipMemcpyDeviceToHost));
HIP_CHECK(hipMemcpy(count, count_d, ITER_COUNT_FOR_THREAD * sizeof(int), hipMemcpyDeviceToHost));
int check = 0;
for (int i = 0; i < ITER_COUNT_FOR_THREAD; i++) {
if (count[i] == -1) {
check = check+1;
check = check + 1;
}
}
if (VALID_COUNT < ITER_COUNT_FOR_THREAD) {
@@ -202,24 +198,22 @@ TEST_CASE("Unit_NonHost_Printf_BufferAvailability") {
}
int *count{nullptr}, *count_d{nullptr};
count = reinterpret_cast<int*>(malloc((ITER_COUNT-1) * sizeof(int)));
HIP_CHECK(hipMalloc(&count_d, (ITER_COUNT-1) * sizeof(int)));
count = reinterpret_cast<int*>(malloc((ITER_COUNT - 1) * sizeof(int)));
HIP_CHECK(hipMalloc(&count_d, (ITER_COUNT - 1) * sizeof(int)));
int check = 0;
for (int i = 0; i < KERNEL_ITERATIONS; i++) {
hipLaunchKernelGGL(kernel_printf_loop, dim3(1), dim3(1), 0, 0,
ITER_COUNT-1, count_d);
hipLaunchKernelGGL(kernel_printf_loop, dim3(1), dim3(1), 0, 0, ITER_COUNT - 1, count_d);
HIP_CHECK(hipMemcpy(count, count_d, (ITER_COUNT-1) * sizeof(int),
hipMemcpyDeviceToHost));
HIP_CHECK(hipMemcpy(count, count_d, (ITER_COUNT - 1) * sizeof(int), hipMemcpyDeviceToHost));
HIP_CHECK(hipDeviceSynchronize());
int test = 0;
for (int i = 0; i < ITER_COUNT-1; i++) {
for (int i = 0; i < ITER_COUNT - 1; i++) {
if (count[i] == 0) {
test = test + 1;
}
}
if (test == (ITER_COUNT-1)) {
if (test == (ITER_COUNT - 1)) {
check = check + 1;
}
}
@@ -235,6 +229,6 @@ TEST_CASE("Unit_NonHost_Printf_BufferAvailability") {
/**
* End doxygen group PrintfTest.
* @}
*/
* End doxygen group PrintfTest.
* @}
*/
@@ -26,12 +26,12 @@ THE SOFTWARE.
#include <hip_test_process.hh>
/**
* @addtogroup printf printf
* @{
* @ingroup PrintfTest
* `int printf()` -
* Method to print the content on output device.
*/
* @addtogroup printf printf
* @{
* @ingroup PrintfTest
* `int printf()` -
* Method to print the content on output device.
*/
/**
* Test Description
@@ -189,6 +189,6 @@ TEST_CASE("Unit_Printf_Negative_Parameters_RTC") {
}
/**
* End doxygen group PrintfTest.
* @}
*/
* End doxygen group PrintfTest.
* @}
*/
@@ -22,27 +22,28 @@ THE SOFTWARE.
#include <hip_test_common.hh>
#include <hip_test_process.hh>
/**
* @addtogroup printf
* @{
* @ingroup PrintfTest
* `int printf()` -
* Method to print the content on output device.
*/
* @addtogroup printf
* @{
* @ingroup PrintfTest
* `int printf()` -
* Method to print the content on output device.
*/
/**
* Test Description
* ------------------------
* - Test case to verify the different format specifiers. Test case should compile with the compiler option -mprintf-kind=buffered
* - Fetch the printf content from a process which will verify format specifier. Compare it with reference string.
* Test source
* ------------------------
* - catch/unit/printf/printfSpecifiersNonHost.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.7
*/
* Test Description
* ------------------------
* - Test case to verify the different format specifiers. Test case should compile with the compiler
* option -mprintf-kind=buffered
* - Fetch the printf content from a process which will verify format specifier. Compare it with
* reference string. Test source
* ------------------------
* - catch/unit/printf/printfSpecifiersNonHost.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.7
*/
TEST_CASE("Unit_Buffered_Printf_Specifier") {
int pcieAtomic = 0;
@@ -122,6 +123,6 @@ x
}
/**
* End doxygen group PrintfTest.
* @}
*/
* End doxygen group PrintfTest.
* @}
*/
@@ -49,7 +49,7 @@ __global__ void test_kernel() {
printf("%G\n", -123.456);
printf("%c\n", 'x');
printf("%s\n", N);
printf("%p\n", (void *)N);
printf("%p\n", (void*)N);
#ifdef __HIP_PLATFORM_AMD__
printf("%.*f %*.*s %p\n", 8, 3.14159, 8, 5, s, (void*)0xf01dab1eca55e77e);
#else
@@ -63,4 +63,3 @@ int main() {
static_cast<void>(hipDeviceSynchronize());
return 0;
}
@@ -55,7 +55,7 @@ __global__ void test_kernel() {
printf("%A\n", -123.456);
printf("%c\n", 'x');
printf("%s\n", N);
printf("%p\n", (void *)N);
printf("%p\n", (void*)N);
#if HT_AMD
printf("%.*f %*.*s %p\n", 8, 3.14159, 8, 5, s, (void*)0xf01dab1eca55e77e);
#else
+20 -20
Féach ar an gComhad
@@ -34,7 +34,7 @@ struct CaptureStream {
char tempname[13] = "mytestXXXXXX";
explicit CaptureStream(FILE *original) {
explicit CaptureStream(FILE* original) {
orig_fd = fileno(original);
saved_fd = dup(orig_fd);
@@ -55,8 +55,7 @@ struct CaptureStream {
}
void restoreStream() {
if (saved_fd == -1)
return;
if (saved_fd == -1) return;
fflush(nullptr);
if (dup2(saved_fd, orig_fd) == -1) {
error(0, errno, "Error");
@@ -69,9 +68,7 @@ struct CaptureStream {
saved_fd = -1;
}
const char *getTempFilename() {
return (const char*)tempname;
}
const char* getTempFilename() { return (const char*)tempname; }
std::ifstream getCapturedData() {
restoreStream();
@@ -86,21 +83,24 @@ struct CaptureStream {
assert(false);
}
}
std::string gulp(std::ifstream &input) {
std::string retval;
input.seekg(0, std::ios_base::end);
retval.resize(input.tellg());
input.seekg(0, std::ios_base::beg);
input.read(&retval[0], retval.size());
input.close();
return retval;
std::string gulp(std::ifstream& input) {
std::string retval;
input.seekg(0, std::ios_base::end);
retval.resize(input.tellg());
input.seekg(0, std::ios_base::beg);
input.read(&retval[0], retval.size());
input.close();
return retval;
}
};
extern const char *msg_short;
extern const char *msg_long1;
extern const char *msg_long2;
extern const char* msg_short;
extern const char* msg_long1;
extern const char* msg_long2;
__device__ const char *msg_short_dev = "Carpe diem.";
__device__ const char *msg_long1_dev = "Lorem ipsum dolor sit amet, consectetur nullam. In mollis imperdiet nibh nec ullamcorper."; // NOLINT
__device__ const char *msg_long2_dev = "Curabitur nec metus sit amet augue vehicula ultrices ut id leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit amet."; // NOLINT
__device__ const char* msg_short_dev = "Carpe diem.";
__device__ const char* msg_long1_dev =
"Lorem ipsum dolor sit amet, consectetur nullam. In mollis imperdiet nibh nec ullamcorper."; // NOLINT
__device__ const char* msg_long2_dev =
"Curabitur nec metus sit amet augue vehicula ultrices ut id leo. Lorem ipsum dolor sit amet, "
"consectetur adipiscing elit amet."; // NOLINT
#endif