Skip to content

Commit 25c34bf

Browse files
authored
[SYCL] Introduce SYCL_PI_SUPPRESS_ERROR_MESSAGE (#6428)
Prevent `check_error` from printing error message. This is handy in CI where we would like to match on messages generated by the underlying driver, over which we have no control, and `check_error` could garble that output.
1 parent 9ba8238 commit 25c34bf

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

sycl/doc/EnvironmentVariables.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ variables in production code.</span>
111111
| `SYCL_HOST_UNIFIED_MEMORY` | Integer | Enforce host unified memory support or lack of it for the execution graph builder. If set to 0, it is enforced as not supported by all devices. If set to 1, it is enforced as supported by all devices. |
112112
| `SYCL_CACHE_TRACE` | Any(\*) | If the variable is set, messages are sent to std::cerr when caching events or non-blocking failures happen (e.g. unable to access cache item file). |
113113
| `SYCL_PARALLEL_FOR_RANGE_ROUNDING_TRACE` | Any(\*) | Enables tracing of `parallel_for` invocations with rounded-up ranges. |
114+
| `SYCL_PI_SUPPRESS_ERROR_MESSAGE` | Any(\*) | Suppress printing of error message, only used for CI in order not to interrupt errors generated by underlying toolchains; note that the variable only modifies the printing of the error message (error value, name, description and location), the handling of error return code and aborting/throwing behaviour remains unchanged. |
114115

115116
`(*) Note: Any means this environment variable is effective when set to any non-null value.`
116117

sycl/plugins/cuda/pi_cuda.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,21 @@ pi_result check_error(CUresult result, const char *function, int line,
133133
return PI_SUCCESS;
134134
}
135135

136-
const char *errorString = nullptr;
137-
const char *errorName = nullptr;
138-
cuGetErrorName(result, &errorName);
139-
cuGetErrorString(result, &errorString);
140-
std::cerr << "\nPI CUDA ERROR:"
141-
<< "\n\tValue: " << result
142-
<< "\n\tName: " << errorName
143-
<< "\n\tDescription: " << errorString
144-
<< "\n\tFunction: " << function
145-
<< "\n\tSource Location: " << file << ":" << line << "\n"
146-
<< std::endl;
136+
if (std::getenv("SYCL_PI_SUPPRESS_ERROR_MESSAGE") == nullptr) {
137+
const char *errorString = nullptr;
138+
const char *errorName = nullptr;
139+
cuGetErrorName(result, &errorName);
140+
cuGetErrorString(result, &errorString);
141+
std::stringstream ss;
142+
ss << "\nPI CUDA ERROR:"
143+
<< "\n\tValue: " << result
144+
<< "\n\tName: " << errorName
145+
<< "\n\tDescription: " << errorString
146+
<< "\n\tFunction: " << function << "\n\tSource Location: " << file
147+
<< ":" << line << "\n"
148+
<< std::endl;
149+
std::cerr << ss.str();
150+
}
147151

148152
if (std::getenv("PI_CUDA_ABORT") != nullptr) {
149153
std::abort();

sycl/plugins/hip/pi_hip.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -189,17 +189,21 @@ pi_result check_error(hipError_t result, const char *function, int line,
189189
return PI_SUCCESS;
190190
}
191191

192-
const char *errorString = nullptr;
193-
const char *errorName = nullptr;
194-
errorName = hipGetErrorName(result);
195-
errorString = hipGetErrorString(result);
196-
std::cerr << "\nPI HIP ERROR:"
197-
<< "\n\tValue: " << result
198-
<< "\n\tName: " << errorName
199-
<< "\n\tDescription: " << errorString
200-
<< "\n\tFunction: " << function
201-
<< "\n\tSource Location: " << file << ":" << line << "\n"
202-
<< std::endl;
192+
if (std::getenv("SYCL_PI_SUPPRESS_ERROR_MESSAGE") == nullptr) {
193+
const char *errorString = nullptr;
194+
const char *errorName = nullptr;
195+
errorName = hipGetErrorName(result);
196+
errorString = hipGetErrorString(result);
197+
std::stringstream ss;
198+
ss << "\nPI HIP ERROR:"
199+
<< "\n\tValue: " << result
200+
<< "\n\tName: " << errorName
201+
<< "\n\tDescription: " << errorString
202+
<< "\n\tFunction: " << function << "\n\tSource Location: " << file
203+
<< ":" << line << "\n"
204+
<< std::endl;
205+
std::cerr << ss.str();
206+
}
203207

204208
if (std::getenv("PI_HIP_ABORT") != nullptr) {
205209
std::abort();

0 commit comments

Comments
 (0)