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) {
1919namespace sycl {
@@ -97,7 +97,7 @@ template <ConfigID Config> class SYCLConfig {
9797
9898public:
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> {
108108public:
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> {
140141public:
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
0 commit comments