Skip to content

Commit 67d9f2a

Browse files
committed
Follow-up fixes
Signed-off-by: Artur Gainullin <[email protected]>
1 parent 4c24517 commit 67d9f2a

File tree

7 files changed

+41
-49
lines changed

7 files changed

+41
-49
lines changed

sycl/doc/EnvironmentVariables.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ subject to change. Do not rely on these variables in production code.
1212
| Environment variable | Values | Description |
1313
| -------------------- | ------ | ----------- |
1414
| SYCL_PI_TRACE | Described [below](#sycl_pi_trace-options) | Enable specified level of tracing for PI. |
15-
| SYCL_BE | PI_OPENCL, PI_CUDA | When SYCL RT is built with PI, force SYCL to consider only devices of the specified backend during the device selection. |
15+
| SYCL_BE | PI_OPENCL, PI_CUDA | Force SYCL RT to consider only devices of the specified backend during the device selection. |
1616
| SYCL_DEVICE_TYPE | One of: CPU, GPU, ACC, HOST | Force SYCL to use the specified device type. If unset, default selection rules are applied. If set to any unlisted value, this control has no effect. If the requested device type is not found, a `cl::sycl::runtime_error` exception is thrown. If a non-default device selector is used, a device must satisfy both the selector and this control to be chosen. This control only has effect on devices created with a selector. |
1717
| SYCL_PROGRAM_COMPILE_OPTIONS | String of valid OpenCL compile options | Override compile options for all programs. |
1818
| SYCL_PROGRAM_LINK_OPTIONS | String of valid OpenCL link options | Override link options for all programs. |
@@ -41,10 +41,10 @@ SYCL_PRINT_EXECUTION_GRAPH can accept one or more comma separated values from th
4141

4242
### SYCL_PI_TRACE Options
4343

44-
SYCL_PI_TRACE can accept one of the values from the table below
44+
SYCL_PI_TRACE accepts a bit-mask. Supported tracing levels are in the table below
4545

4646
| Option | Description |
4747
| ------ | ----------- |
48-
| 1 | Enable basic tracing |
48+
| 1 | Enable basic tracing, which is tracing of PI plugins/devices discovery |
4949
| 2 | Enable tracing of the PI calls |
50-
| -1 | Enable all levelis of tracing |
50+
| -1 | Enable all levels of tracing |

sycl/include/CL/sycl/detail/pi.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ enum TraceLevel {
5555
// Return true if we want to trace PI related activities.
5656
bool trace(TraceLevel level);
5757

58-
const char *traceLabel();
59-
6058
#ifdef SYCL_RT_OS_WINDOWS
6159
#define OPENCL_PLUGIN_NAME "pi_opencl.dll"
6260
#define CUDA_PLUGIN_NAME "pi_cuda.dll"

sycl/source/detail/config.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ CONFIG(SYCL_PRINT_EXECUTION_GRAPH, 32, __SYCL_PRINT_EXECUTION_GRAPH)
1414
CONFIG(SYCL_DISABLE_EXECUTION_GRAPH_CLEANUP, 1, __SYCL_DISABLE_EXECUTION_GRAPH_CLEANUP)
1515
CONFIG(SYCL_DEVICE_ALLOWLIST, 1024, __SYCL_DEVICE_ALLOWLIST)
1616
CONFIG(SYCL_BE, 16, __SYCL_BE)
17-
CONFIG(SYCL_PI_TRACE, 4, __SYCL_PI_TRACE)
17+
CONFIG(SYCL_PI_TRACE, 16, __SYCL_PI_TRACE)

sycl/source/detail/config.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,15 @@ template <> class SYCLConfig<SYCL_BE> {
106106
using BaseT = SYCLConfigBase<SYCL_BE>;
107107

108108
public:
109-
static backend get() {
109+
static backend *get() {
110110
static bool Initialized = false;
111+
static bool IsSet = false;
111112
static backend Backend = backend::opencl;
112113

113114
// Configuration parameters are processed only once, like reading a string
114115
// from environment and converting it into a typed object.
115116
if (Initialized)
116-
return Backend;
117+
return IsSet ? &Backend : nullptr;
117118

118119
const char *ValStr = BaseT::getRawValue();
119120
const std::map<std::string, backend> SyclBeMap{
@@ -124,9 +125,12 @@ template <> class SYCLConfig<SYCL_BE> {
124125
pi::die("Invalid backend. "
125126
"Valid values are PI_OPENCL/PI_CUDA");
126127
Backend = It->second;
128+
Initialized = true;
129+
IsSet = true;
130+
return &Backend;
127131
}
128132
Initialized = true;
129-
return Backend;
133+
return nullptr;
130134
}
131135
};
132136

sycl/source/detail/pi.cpp

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -195,37 +195,24 @@ bool trace(TraceLevel Level) {
195195
return (TraceLevelMask & Level) == Level;
196196
}
197197

198-
const char *traceLabel() {
199-
int TraceLevelMask = SYCLConfig<SYCL_PI_TRACE>::get();
200-
switch (TraceLevelMask) {
201-
case PI_TRACE_BASIC:
202-
return "SYCL_PI_TRACE[PI_TRACE_BASIC]: ";
203-
case PI_TRACE_CALLS:
204-
return "SYCL_PI_TRACE[PI_TRACE_CALLS]: ";
205-
case PI_TRACE_ALL:
206-
return "SYCL_PI_TRACE[PI_TRACE_ALL]: ";
207-
default:
208-
assert("Unsupported trace level");
209-
}
210-
return nullptr;
211-
}
212-
213198
// Initializes all available Plugins.
214199
vector_class<plugin> initialize() {
215200
vector_class<plugin> Plugins;
216201
vector_class<std::pair<std::string, backend>> PluginNames;
217202
findPlugins(PluginNames);
218203

219204
if (PluginNames.empty() && trace(PI_TRACE_ALL))
220-
std::cerr << traceLabel() << "No Plugins Found." << std::endl;
205+
std::cerr << "SYCL_PI_TRACE[all]: "
206+
<< "No Plugins Found." << std::endl;
221207

222208
PiPlugin PluginInformation;
223209
for (unsigned int I = 0; I < PluginNames.size(); I++) {
224210
void *Library = loadPlugin(PluginNames[I].first);
225211

226212
if (!Library) {
227213
if (trace(PI_TRACE_ALL)) {
228-
std::cerr << traceLabel() << "Check if plugin is present. "
214+
std::cerr << "SYCL_PI_TRACE[all]: "
215+
<< "Check if plugin is present. "
229216
<< "Failed to load plugin: " << PluginNames[I].first
230217
<< std::endl;
231218
}
@@ -234,25 +221,27 @@ vector_class<plugin> initialize() {
234221

235222
if (!bindPlugin(Library, &PluginInformation)) {
236223
if (trace(PI_TRACE_ALL)) {
237-
std::cerr << traceLabel() << "Failed to bind PI APIs to the plugin: "
224+
std::cerr << "SYCL_PI_TRACE[all]: "
225+
<< "Failed to bind PI APIs to the plugin: "
238226
<< PluginNames[I].first << std::endl;
239227
}
240228
continue;
241229
}
242-
if (SYCLConfig<SYCL_BE>::get() == backend::opencl &&
243-
PluginNames[I].first.find("opencl") != std::string::npos) {
230+
backend *BE = SYCLConfig<SYCL_BE>::get();
231+
if (!BE || (*BE == backend::opencl &&
232+
PluginNames[I].first.find("opencl") != std::string::npos)) {
244233
// Use the OpenCL plugin as the GlobalPlugin
245234
GlobalPlugin =
246235
std::make_shared<plugin>(PluginInformation, backend::opencl);
247-
}
248-
if (SYCLConfig<SYCL_BE>::get() == backend::cuda &&
249-
PluginNames[I].first.find("cuda") != std::string::npos) {
236+
} else if (*BE == backend::cuda &&
237+
PluginNames[I].first.find("cuda") != std::string::npos) {
250238
// Use the CUDA plugin as the GlobalPlugin
251239
GlobalPlugin = std::make_shared<plugin>(PluginInformation, backend::cuda);
252240
}
253241
Plugins.emplace_back(plugin(PluginInformation, PluginNames[I].second));
254242
if (trace(TraceLevel::PI_TRACE_BASIC))
255-
std::cerr << traceLabel() << "Plugin found and successfully loaded: "
243+
std::cerr << "SYCL_PI_TRACE[basic]: "
244+
<< "Plugin found and successfully loaded: "
256245
<< PluginNames[I].first << std::endl;
257246
}
258247

sycl/source/device.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ vector_class<device> device::get_devices(info::device_type deviceType) {
5353
for (const auto &plt : platform::get_platforms()) {
5454
// If SYCL_BE is set then skip platforms which doesn't have specified
5555
// backend.
56-
if (std::getenv("SYCL_BE")) {
57-
if (plt.is_host() ||
58-
detail::getSyclObjImpl(plt)->getPlugin().getBackend() !=
59-
detail::SYCLConfig<detail::SYCL_BE>::get())
56+
backend *ForcedBackend = detail::SYCLConfig<detail::SYCL_BE>::get();
57+
if (ForcedBackend)
58+
if (!plt.is_host() &&
59+
(detail::getSyclObjImpl(plt)->getPlugin().getBackend() !=
60+
*ForcedBackend))
6061
continue;
61-
}
6262
if (includeHost && plt.is_host()) {
6363
vector_class<device> host_device(
6464
plt.get_devices(info::device_type::host));

sycl/source/device_selector.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ device device_selector::select_device() const {
3838
string_class PlatformVersion = dev.get_info<info::device::platform>()
3939
.get_info<info::platform::version>();
4040
string_class DeviceName = dev.get_info<info::device::name>();
41-
std::cout << detail::pi::traceLabel()
41+
std::cout << "SYCL_PI_TRACE[all]: "
4242
<< "select_device(): -> score = " << score << std::endl
43-
<< detail::pi::traceLabel() << " platform: " << PlatformVersion
44-
<< std::endl
45-
<< detail::pi::traceLabel() << " device: " << DeviceName
46-
<< std::endl;
43+
<< "SYCL_PI_TRACE[all]: "
44+
<< " platform: " << PlatformVersion << std::endl
45+
<< "SYCL_PI_TRACE[all]: "
46+
<< " device: " << DeviceName << std::endl;
4747
}
4848

4949
// SYCL spec says: "If more than one device receives the high score then
@@ -63,11 +63,12 @@ device device_selector::select_device() const {
6363
string_class PlatformVersion = res->get_info<info::device::platform>()
6464
.get_info<info::platform::version>();
6565
string_class DeviceName = res->get_info<info::device::name>();
66-
std::cout << detail::pi::traceLabel() << "Selected device ->" << std::endl
67-
<< detail::pi::traceLabel() << " platform: " << PlatformVersion
68-
<< std::endl
69-
<< detail::pi::traceLabel() << " device: " << DeviceName
70-
<< std::endl;
66+
std::cout << "SYCL_PI_TRACE[all]: "
67+
<< "Selected device ->" << std::endl
68+
<< "SYCL_PI_TRACE[all]: "
69+
<< " platform: " << PlatformVersion << std::endl
70+
<< "SYCL_PI_TRACE[all]: "
71+
<< " device: " << DeviceName << std::endl;
7172
}
7273
return *res;
7374
}

0 commit comments

Comments
 (0)