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
Этот коммит содержится в:
Vladislav Sytchenko
2021-03-07 21:04:23 -05:00
родитель 1c08fb58d0
Коммит 223dddae6d
10 изменённых файлов: 211 добавлений и 77 удалений
+9 -4
Просмотреть файл
@@ -49,20 +49,25 @@ int main() {
uint threads_per_block = 250;
uint threads_per_device = num_blocks * threads_per_block;
CaptureStream capture(stdout);
int num_devices = 0;
hipGetDeviceCount(&num_devices);
CaptureStream captured(stdout);
capture.Begin();
for (int i = 0; i != num_devices; ++i) {
hipSetDevice(i);
hipLaunchKernelGGL(print_things, dim3(num_blocks), dim3(threads_per_block),
0, 0);
hipDeviceSynchronize();
}
auto CapturedData = captured.getCapturedData();
capture.End();
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]++;
}