12
12
#include < CL/sycl/detail/defines.hpp>
13
13
#include < CL/sycl/detail/pi.hpp>
14
14
15
+ #include < algorithm>
15
16
#include < cstdlib>
16
- #include < map>
17
17
18
18
__SYCL_INLINE_NAMESPACE (cl) {
19
19
namespace sycl {
@@ -97,7 +97,7 @@ template <ConfigID Config> class SYCLConfig {
97
97
98
98
public:
99
99
static const char *get () {
100
- const char *ValStr = BaseT::getRawValue ();
100
+ static const char *ValStr = BaseT::getRawValue ();
101
101
return ValStr;
102
102
}
103
103
};
@@ -108,29 +108,30 @@ template <> class SYCLConfig<SYCL_BE> {
108
108
public:
109
109
static backend *get () {
110
110
static bool Initialized = false ;
111
- static bool IsSet = false ;
112
- static backend Backend = backend::opencl;
111
+ static backend *BackendPtr = nullptr ;
113
112
114
113
// Configuration parameters are processed only once, like reading a string
115
114
// from environment and converting it into a typed object.
116
115
if (Initialized)
117
- return IsSet ? &Backend : nullptr ;
116
+ return BackendPtr ;
118
117
119
118
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} }};
122
121
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
+ });
124
127
if (It == SyclBeMap.end ())
125
128
pi::die (" Invalid backend. "
126
129
" 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;
131
132
}
132
133
Initialized = true ;
133
- return nullptr ;
134
+ return BackendPtr ;
134
135
}
135
136
};
136
137
@@ -140,6 +141,8 @@ template <> class SYCLConfig<SYCL_PI_TRACE> {
140
141
public:
141
142
static int get () {
142
143
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.
143
146
static int Level = 0 ; // No tracing by default
144
147
145
148
// Configuration parameters are processed only once, like reading a string
0 commit comments