SWDEV-232428 - Fix HIP printf tests on Windows
On Windows there's something fundamentally broken about redirecting IO into a file and then restoring that said IO to it's original state. Even though no syscalls would fail, the output would sometimes either go into CLI or straight up nowhere. Simply using pipes instead of a temporary file magically resolves the above issue ¯\_(ツ)_/¯ Unfortunately the max pipe size on Linux is 1Mb, which is not enough to store all the data printed by the kernel. This leads to a softhang in vprintf(). Stick to using a temporary file on Linux, but switch to pipes on Windows. Slightly refactor the CaptureStream struct to accomadate this difference. Change-Id: Id8e68f150df47815a4f652ee2bcd6cfb7c3e3bac
This commit is contained in:
@@ -58,17 +58,18 @@ __global__ void kernel_mixed0(int *retval) {
|
||||
}
|
||||
|
||||
static void test_mixed0(int *retval, uint num_blocks, uint threads_per_block) {
|
||||
CaptureStream captured(stdout);
|
||||
CaptureStream capture(stdout);
|
||||
|
||||
uint num_threads = num_blocks * threads_per_block;
|
||||
for (uint i = 0; i != num_threads; ++i) {
|
||||
retval[i] = 0x23232323;
|
||||
}
|
||||
|
||||
capture.Begin();
|
||||
hipLaunchKernelGGL(kernel_mixed0, dim3(num_blocks), dim3(threads_per_block),
|
||||
0, 0, retval);
|
||||
hipStreamSynchronize(0);
|
||||
auto CapturedData = captured.getCapturedData();
|
||||
capture.End();
|
||||
|
||||
for (uint ii = 0; ii != num_threads; ++ii) {
|
||||
switch (ii % 3) {
|
||||
@@ -84,8 +85,12 @@ static void test_mixed0(int *retval, uint num_blocks, uint threads_per_block) {
|
||||
}
|
||||
}
|
||||
|
||||
std::string data = capture.getData();
|
||||
std::stringstream dataStream;
|
||||
dataStream << data;
|
||||
|
||||
std::map<std::string, int> linecount;
|
||||
for (std::string line; std::getline(CapturedData, line);) {
|
||||
for (std::string line; std::getline(dataStream, line);) {
|
||||
linecount[line]++;
|
||||
}
|
||||
|
||||
@@ -115,17 +120,18 @@ __global__ void kernel_mixed1(int *retval) {
|
||||
}
|
||||
|
||||
static void test_mixed1(int *retval, uint num_blocks, uint threads_per_block) {
|
||||
CaptureStream captured(stdout);
|
||||
CaptureStream capture(stdout);
|
||||
|
||||
uint num_threads = num_blocks * threads_per_block;
|
||||
for (uint i = 0; i != num_threads; ++i) {
|
||||
retval[i] = 0x23232323;
|
||||
}
|
||||
|
||||
capture.Begin();
|
||||
hipLaunchKernelGGL(kernel_mixed1, dim3(num_blocks), dim3(threads_per_block),
|
||||
0, 0, retval);
|
||||
hipStreamSynchronize(0);
|
||||
auto CapturedData = captured.getCapturedData();
|
||||
capture.End();
|
||||
|
||||
for (uint ii = 0; ii != num_threads; ++ii) {
|
||||
switch (ii % 3) {
|
||||
@@ -141,8 +147,12 @@ static void test_mixed1(int *retval, uint num_blocks, uint threads_per_block) {
|
||||
}
|
||||
}
|
||||
|
||||
std::string data = capture.getData();
|
||||
std::stringstream dataStream;
|
||||
dataStream << data;
|
||||
|
||||
std::map<std::string, int> linecount;
|
||||
for (std::string line; std::getline(CapturedData, line);) {
|
||||
for (std::string line; std::getline(dataStream, line);) {
|
||||
linecount[line]++;
|
||||
}
|
||||
|
||||
@@ -165,25 +175,30 @@ __global__ void kernel_mixed2(int *retval) {
|
||||
}
|
||||
|
||||
static void test_mixed2(int *retval, uint num_blocks, uint threads_per_block) {
|
||||
CaptureStream captured(stdout);
|
||||
CaptureStream capture(stdout);
|
||||
|
||||
uint num_threads = num_blocks * threads_per_block;
|
||||
for (uint i = 0; i != num_threads; ++i) {
|
||||
retval[i] = 0x23232323;
|
||||
}
|
||||
|
||||
capture.Begin();
|
||||
hipLaunchKernelGGL(kernel_mixed2, dim3(num_blocks), dim3(threads_per_block),
|
||||
0, 0, retval);
|
||||
hipStreamSynchronize(0);
|
||||
auto CapturedData = captured.getCapturedData();
|
||||
capture.End();
|
||||
|
||||
for (uint ii = 0; ii != num_threads; ++ii) {
|
||||
HIPASSERT(retval[ii] ==
|
||||
strlen(msg_short) + strlen(msg_long1) + strlen(msg_long2) + 1);
|
||||
}
|
||||
|
||||
std::string data = capture.getData();
|
||||
std::stringstream dataStream;
|
||||
dataStream << data;
|
||||
|
||||
std::map<std::string, int> linecount;
|
||||
for (std::string line; std::getline(CapturedData, line);) {
|
||||
for (std::string line; std::getline(dataStream, line);) {
|
||||
linecount[line]++;
|
||||
}
|
||||
|
||||
@@ -216,17 +231,18 @@ __global__ void kernel_mixed3(int *retval) {
|
||||
}
|
||||
|
||||
static void test_mixed3(int *retval, uint num_blocks, uint threads_per_block) {
|
||||
CaptureStream captured(stdout);
|
||||
CaptureStream capture(stdout);
|
||||
|
||||
uint num_threads = num_blocks * threads_per_block;
|
||||
for (uint i = 0; i != num_threads; ++i) {
|
||||
retval[i] = 0x23232323;
|
||||
}
|
||||
|
||||
capture.Begin();
|
||||
hipLaunchKernelGGL(kernel_mixed3, dim3(num_blocks), dim3(threads_per_block),
|
||||
0, 0, retval);
|
||||
hipStreamSynchronize(0);
|
||||
auto CapturedData = captured.getCapturedData();
|
||||
capture.End();
|
||||
|
||||
for (uint ii = 0; ii != num_threads; ++ii) {
|
||||
if (ii % 3 == 0) {
|
||||
@@ -237,8 +253,12 @@ static void test_mixed3(int *retval, uint num_blocks, uint threads_per_block) {
|
||||
}
|
||||
}
|
||||
|
||||
std::string data = capture.getData();
|
||||
std::stringstream dataStream;
|
||||
dataStream << data;
|
||||
|
||||
std::map<std::string, int> linecount;
|
||||
for (std::string line; std::getline(CapturedData, line);) {
|
||||
for (std::string line; std::getline(dataStream, line);) {
|
||||
linecount[line]++;
|
||||
}
|
||||
|
||||
@@ -257,19 +277,24 @@ __global__ void kernel_numbers() {
|
||||
}
|
||||
|
||||
static void test_numbers(uint num_blocks, uint threads_per_block) {
|
||||
CaptureStream captured(stdout);
|
||||
CaptureStream capture(stdout);
|
||||
uint num_threads = num_blocks * threads_per_block;
|
||||
|
||||
capture.Begin();
|
||||
hipLaunchKernelGGL(kernel_numbers, dim3(num_blocks), dim3(threads_per_block),
|
||||
0, 0);
|
||||
hipStreamSynchronize(0);
|
||||
auto CapturedData = captured.getCapturedData();
|
||||
capture.End();
|
||||
|
||||
std::string data = capture.getData();
|
||||
std::stringstream dataStream;
|
||||
dataStream << data;
|
||||
|
||||
std::vector<uint> points;
|
||||
while (true) {
|
||||
uint i;
|
||||
CapturedData >> i;
|
||||
if (CapturedData.fail())
|
||||
dataStream >> i;
|
||||
if (dataStream.fail())
|
||||
break;
|
||||
points.push_back(i);
|
||||
}
|
||||
@@ -278,8 +303,6 @@ static void test_numbers(uint num_blocks, uint threads_per_block) {
|
||||
points.erase(std::unique(points.begin(), points.end()), points.end());
|
||||
HIPASSERT(points.size() == 21 * num_threads);
|
||||
HIPASSERT(points.back() == 21 * num_threads - 1);
|
||||
|
||||
passed();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
Reference in New Issue
Block a user