Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 7f68a81

Browse files
[SYCL] Set line buffering mode for stderr for some assert tests (#872)
Co-authored-by: Elovikov, Andrei <[email protected]>
1 parent f5faacd commit 7f68a81

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

SYCL/Assert/assert_in_simultaneous_kernels.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
// RUN: %ACC_RUN_PLACEHOLDER %t.out &> %t.txt
1717
// RUN: %ACC_RUN_PLACEHOLDER FileCheck %s --check-prefix=CHECK-ACC --input-file %t.txt
1818
//
19-
// CHECK: {{.*}}assert_in_simultaneous_kernels.hpp:12: void assertFunc(): global id: [9,7,0], local id: [0,0,0]
19+
// CHECK: {{.*}}assert_in_simultaneous_kernels.hpp:13: void assertFunc(): global id: [9,7,0], local id: [0,0,0]
2020
// CHECK-SAME: Assertion `false && "from assert statement"` failed.
2121
// CHECK-NOT: The test ended.
2222
//
23-
// CHECK-ACC-NOT: {{.*}}assert_in_simultaneous_kernels.hpp:12: void assertFunc(): global id: [9,7,0], local id: [0,0,0]
23+
// CHECK-ACC-NOT: {{.*}}assert_in_simultaneous_kernels.hpp:13: void assertFunc(): global id: [9,7,0], local id: [0,0,0]
2424
// CHECK-ACC: The test ended.
2525

2626
#include "assert_in_simultaneous_kernels.hpp"

SYCL/Assert/assert_in_simultaneous_kernels.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <CL/sycl.hpp>
22
#include <cassert>
3+
#include <cstdio>
34
#include <iostream>
45
#include <thread>
56

@@ -44,6 +45,15 @@ void runTestForTid(queue *Q, size_t Tid) {
4445
}
4546

4647
int main(int Argc, const char *Argv[]) {
48+
// On windows stderr output becomes messed up if several thread
49+
// output simultaneously. Hence, setting explicit line buffering here.
50+
#ifndef __SYCL_DEVICE_ONLY__
51+
if (setvbuf(stderr, nullptr, _IOLBF, BUFSIZ)) {
52+
std::cerr << "Can't set line-buffering mode fo stderr\n";
53+
return 1;
54+
}
55+
#endif
56+
4757
std::vector<std::thread> threadPool;
4858
threadPool.reserve(NUM_THREADS);
4959

SYCL/Assert/assert_in_simultaneous_kernels_win.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
//
1818
// FIXME Windows version prints '(null)' instead of '<unknown func>' once in a
1919
// while for some insane reason.
20-
// CHECK: {{.*}}assert_in_simultaneous_kernels.hpp:12: {{<unknown func>|(null)}}: global id: [9,7,0], local id: [0,0,0]
20+
// CHECK: {{.*}}assert_in_simultaneous_kernels.hpp:13: {{<unknown func>|(null)}}: global id: [9,7,0], local id: [0,0,0]
2121
// CHECK-SAME: Assertion `false && "from assert statement"` failed.
2222
// CHECK-NOT: The test ended.
2323
//
24-
// CHECK-ACC-NOT: {{.*}}assert_in_simultaneous_kernels.hpp:12: {{<unknown func>|(null)}}: global id: [9,7,0], local id: [0,0,0]
24+
// CHECK-ACC-NOT: {{.*}}assert_in_simultaneous_kernels.hpp:13: {{<unknown func>|(null)}}: global id: [9,7,0], local id: [0,0,0]
2525
// CHECK-ACC: The test ended.
2626

2727
#include "assert_in_simultaneous_kernels.hpp"

SYCL/Assert/assert_in_simultaneously_multiple_tus.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include "Inputs/kernels_in_file2.hpp"
2626
#include <CL/sycl.hpp>
27+
#include <cstdio>
2728
#include <iostream>
2829
#include <thread>
2930

@@ -82,6 +83,15 @@ void runTestForTid(queue *Q, size_t Tid) {
8283
}
8384

8485
int main(int Argc, const char *Argv[]) {
86+
#ifndef __SYCL_DEVICE_ONLY__
87+
// On windows stderr output becomes messed up if several thread
88+
// output simultaneously. Hence, setting explicit line buffering here.
89+
if (setvbuf(stderr, nullptr, _IOLBF, BUFSIZ)) {
90+
std::cerr << "Can't set line-buffering mode fo stderr\n";
91+
return 1;
92+
}
93+
#endif
94+
8595
std::vector<std::thread> threadPool;
8696
threadPool.reserve(NUM_THREADS);
8797

0 commit comments

Comments
 (0)