Skip to content

Commit cb7b4eb

Browse files
committed
Address comments
Signed-off-by: Artur Gainullin <artur.gainullin@intel.com>
1 parent d27517d commit cb7b4eb

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

sycl/source/detail/config.hpp

+16-13
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include <CL/sycl/detail/defines.hpp>
1313
#include <CL/sycl/detail/pi.hpp>
1414

15+
#include <algorithm>
1516
#include <cstdlib>
16-
#include <map>
1717

1818
__SYCL_INLINE_NAMESPACE(cl) {
1919
namespace sycl {
@@ -97,7 +97,7 @@ template <ConfigID Config> class SYCLConfig {
9797

9898
public:
9999
static const char *get() {
100-
const char *ValStr = BaseT::getRawValue();
100+
static const char *ValStr = BaseT::getRawValue();
101101
return ValStr;
102102
}
103103
};
@@ -108,29 +108,30 @@ template <> class SYCLConfig<SYCL_BE> {
108108
public:
109109
static backend *get() {
110110
static bool Initialized = false;
111-
static bool IsSet = false;
112-
static backend Backend = backend::opencl;
111+
static backend *BackendPtr = nullptr;
113112

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

119118
const char *ValStr = BaseT::getRawValue();
120-
const std::map<std::string, backend> SyclBeMap{
121-
{"PI_OPENCL", backend::opencl}, {"PI_CUDA", backend::cuda}};
119+
const std::array<std::pair<std::string, backend>, 2> SyclBeMap = {
120+
{{"PI_OPENCL", backend::opencl}, {"PI_CUDA", backend::cuda}}};
122121
if (ValStr) {
123-
auto It = SyclBeMap.find(ValStr);
122+
auto It = std::find_if(
123+
std::begin(SyclBeMap), std::end(SyclBeMap),
124+
[&ValStr](const std::pair<std::string, backend> &element) {
125+
return element.first == ValStr;
126+
});
124127
if (It == SyclBeMap.end())
125128
pi::die("Invalid backend. "
126129
"Valid values are PI_OPENCL/PI_CUDA");
127-
Backend = It->second;
128-
Initialized = true;
129-
IsSet = true;
130-
return &Backend;
130+
static backend Backend = It->second;
131+
BackendPtr = &Backend;
131132
}
132133
Initialized = true;
133-
return nullptr;
134+
return BackendPtr;
134135
}
135136
};
136137

@@ -140,6 +141,8 @@ template <> class SYCLConfig<SYCL_PI_TRACE> {
140141
public:
141142
static int get() {
142143
static bool Initialized = false;
144+
// We don't use TraceLevel enum here because user can provide any bitmask
145+
// which can correspond to several enum values.
143146
static int Level = 0; // No tracing by default
144147

145148
// Configuration parameters are processed only once, like reading a string

sycl/test/basic_tests/event_release.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %clangxx -fsycl %s -o %t.out
2-
// RUN: env SYCL_PI_TRACE=1 %CPU_RUN_PLACEHOLDER %t.out 2>&1 %CPU_CHECK_PLACEHOLDER
2+
// RUN: env SYCL_PI_TRACE=2 %CPU_RUN_PLACEHOLDER %t.out 2>&1 %CPU_CHECK_PLACEHOLDER
33
#include <CL/sycl.hpp>
44
#include <cassert>
55
#include <iostream>

0 commit comments

Comments
 (0)