27 inline namespace _V1 {
30 #ifdef DISABLE_CONFIG_FROM_ENV
36 #ifdef DISABLE_CONFIG_FROM_CONFIG_FILE
42 #ifdef DISABLE_CONFIG_FROM_COMPILE_TIME
54 #define CONFIG(name, ...) name,
62 return (Str[0] ==
'_' && Str[1] ==
'_') ? nullptr : Str;
66 void readConfig(
bool ForceInitialization =
false);
70 #define CONFIG(Name, MaxSize, CompileTimeDef) \
71 template <> class SYCLConfigBase<Name> { \
75 static char MStorage[MaxSize + 1]; \
77 static const char *MValueFromFile; \
79 static const char *const MConfigName; \
84 static const char *const MCompileTimeDef; \
86 static const char *getRawValue() { \
87 if (ConfigFromEnvEnabled) \
88 if (const char *ValStr = getenv(MConfigName)) \
91 if (ConfigFromFileEnabled) { \
94 return MValueFromFile; \
97 if (ConfigFromCompileDefEnabled && MCompileTimeDef) \
98 return MCompileTimeDef; \
103 #include "config.def"
106 #define INVALID_CONFIG_EXCEPTION(BASE, MSG) \
107 sycl::exception(sycl::make_error_code(sycl::errc::invalid), \
108 "Invalid value for " + std::string{BASE::MConfigName} + \
109 " environment variable: " + MSG)
115 static const char *
get() {
return getCachedValue(); }
117 static void reset() { (void)getCachedValue(
true); }
119 static const char *
getName() {
return BaseT::MConfigName; }
122 static const char *getCachedValue(
bool ResetCache =
false) {
123 static const char *ValStr = BaseT::getRawValue();
125 ValStr = BaseT::getRawValue();
135 static bool Initialized =
false;
138 static int Level = 0;
145 const char *ValStr = BaseT::getRawValue();
146 Level = (ValStr ? std::atoi(ValStr) : 0);
156 static unsigned int get() {
return getCachedValue(); }
158 static void reset() { (void)getCachedValue(
true); }
161 static unsigned int getCachedValue(
bool ResetCache =
false) {
162 const auto Parser = []() {
163 const char *ValStr = BaseT::getRawValue();
164 int SignedLevel = ValStr ? std::atoi(ValStr) : 0;
165 return SignedLevel >= 0 ? SignedLevel : 0;
168 static unsigned int Level = Parser();
176 template <>
class SYCLConfig<SYCL_PARALLEL_FOR_RANGE_ROUNDING_TRACE> {
181 static const char *ValStr = BaseT::getRawValue();
182 return ValStr !=
nullptr;
186 template <>
class SYCLConfig<SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING> {
191 static const char *ValStr = BaseT::getRawValue();
192 return ValStr !=
nullptr;
196 template <>
class SYCLConfig<SYCL_PARALLEL_FOR_RANGE_ROUNDING_PARAMS> {
203 static const char *RoundParams = BaseT::getRawValue();
204 if (RoundParams ==
nullptr)
207 static bool ProcessedFactors =
false;
211 if (!ProcessedFactors) {
215 size_t Pos = Params.find(
':');
216 if (Pos != std::string::npos) {
217 MF = std::stoi(Params.substr(0, Pos));
218 Params.erase(0, Pos + 1);
219 Pos = Params.find(
':');
220 if (Pos != std::string::npos) {
221 GF = std::stoi(Params.substr(0, Pos));
222 Params.erase(0, Pos + 1);
223 MR = std::stoi(Params);
226 ProcessedFactors =
true;
237 template <
bool supportAcc = false>
238 const std::array<std::pair<std::string, info::device_type>, 6> &
240 static const std::array<std::pair<std::string, info::device_type>, 6>
241 SyclDeviceTypeMap = {
249 return SyclDeviceTypeMap;
265 static bool Initialized =
false;
269 return DeviceTargets;
271 const char *ValStr = BaseT::getRawValue();
274 if (ValStr[0] ==
'\0')
275 throw invalid_parameter_error(
276 "Invalid value for ONEAPI_DEVICE_SELECTOR environment "
277 "variable: value should not be null.",
278 PI_ERROR_INVALID_VALUE);
284 return DeviceTargets;
288 #ifndef __INTEL_PREVIEW_BREAKING_CHANGES
294 SYCLConfig<SYCL_DEVICE_FILTER> {
295 using BaseT = SYCLConfigBase<SYCL_DEVICE_FILTER>;
298 static device_filter_list *
get() {
299 static bool Initialized =
false;
300 static device_filter_list *FilterList =
nullptr;
308 const char *ValStr = BaseT::getRawValue();
312 <<
"\nWARNING: The enviroment variable SYCL_DEVICE_FILTER"
313 " is deprecated. Please use ONEAPI_DEVICE_SELECTOR instead.\n"
314 "For more details, please refer to:\n"
315 "https://github.com/intel/llvm/blob/sycl/sycl/doc/"
316 "EnvironmentVariables.md#oneapi_device_selector\n\n";
337 constexpr
bool DefaultValue =
true;
339 const char *ValStr = getCachedValue();
344 return ValStr[0] ==
'1';
347 static void reset() { (void)getCachedValue(
true); }
350 (void)getCachedValue(
true, Val);
353 static const char *
getName() {
return BaseT::MConfigName; }
356 static const char *getCachedValue(
bool ResetCache =
false,
357 const char *Val =
nullptr) {
358 static const char *ValStr = BaseT::getRawValue();
360 ValStr = (Val !=
nullptr) ? Val : BaseT::getRawValue();
371 static int Value = [] {
372 const char *ValueStr = BaseT::getRawValue();
378 Result = std::stoi(ValueStr);
380 throw invalid_parameter_error(
381 "Invalid value for SYCL_QUEUE_THREAD_POOL_SIZE environment "
382 "variable: value should be a number",
383 PI_ERROR_INVALID_VALUE);
387 throw invalid_parameter_error(
388 "Invalid value for SYCL_QUEUE_THREAD_POOL_SIZE environment "
389 "variable: value should be larger than zero",
390 PI_ERROR_INVALID_VALUE);
403 static constexpr
bool Default =
false;
405 static bool get() {
return getCachedValue(); }
407 static void reset() { (void)getCachedValue(
true); }
409 static const char *
getName() {
return BaseT::MConfigName; }
412 static bool parseValue() {
417 <<
" environment variable is deprecated "
418 <<
"and has no effect. By default, persistent device code caching is "
419 << (Default ?
"enabled." :
"disabled.") <<
" Use " <<
getName()
420 <<
"=1/0 to enable/disable.\n";
423 const char *ValStr = BaseT::getRawValue();
426 if (strlen(ValStr) != 1 || (ValStr[0] !=
'0' && ValStr[0] !=
'1')) {
428 std::string{
"Invalid value for bool configuration variable "} +
430 throw runtime_error(Msg, PI_ERROR_INVALID_OPERATION);
432 return ValStr[0] ==
'1';
435 static bool getCachedValue(
bool ResetCache =
false) {
436 static bool Val = parseValue();
449 static void reset() { (void)getCachedValue(
true); }
451 static const char *
getName() {
return BaseT::MConfigName; }
457 const char *RootDir = BaseT::getRawValue();
461 constexpr
char DeviceCodeCacheDir[] =
"/libsycl_cache";
463 #if defined(__SYCL_RT_OS_LINUX)
464 const char *CacheDir = std::getenv(
"XDG_CACHE_HOME");
465 const char *HomeDir = std::getenv(
"HOME");
466 if (!CacheDir && !HomeDir)
472 const char *AppDataDir = std::getenv(
"AppData");
480 static std::string getCachedValue(
bool ResetCache =
false) {
488 template <>
class SYCLConfig<SYCL_REDUCTION_PREFERRED_WORKGROUP_SIZE> {
494 size_t Accelerator = 0;
499 ParsedValue Value = getCachedValue();
500 return getRefByDeviceType(Value, DeviceType);
503 static void reset() { (void)getCachedValue(
true); }
505 static const char *
getName() {
return BaseT::MConfigName; }
508 static size_t &getRefByDeviceType(ParsedValue &Value,
510 switch (DeviceType) {
516 return Value.Accelerator;
521 BaseT,
"Device types must be \"cpu\", \"gpu\", \"acc\", or \"*\".");
525 static ParsedValue parseValue() {
526 const char *ValueRaw = BaseT::getRawValue();
527 ParsedValue Result{};
537 size_t Start = 0, End = 0;
539 End = ValueStr.find(
',', Start);
540 if (End == std::string::npos)
541 End = ValueStr.size();
544 std::string DeviceConfigStr = ValueStr.substr(Start, End - Start);
547 size_t ConfigDelimLoc = DeviceConfigStr.find(
':');
548 if (ConfigDelimLoc == std::string::npos)
550 BaseT,
"Device-value pair \"" + DeviceConfigStr +
551 "\" does not contain the ':' delimiter.");
555 DeviceConfigStr.substr(0, ConfigDelimLoc);
556 std::string DeviceConfigValueStr = DeviceConfigStr.substr(
557 ConfigDelimLoc + 1, DeviceConfigStr.size() - ConfigDelimLoc - 1);
560 auto DeviceTypeIter = std::find_if(
561 std::begin(DeviceTypeMap), std::end(DeviceTypeMap),
562 [&](
auto Element) {
return DeviceConfigTypeStr == Element.first; });
563 if (DeviceTypeIter == DeviceTypeMap.end())
566 "\"" + DeviceConfigTypeStr +
"\" is not a recognized device type.");
569 int DeviceConfigValue = 1;
571 DeviceConfigValue = std::stoi(DeviceConfigValueStr);
574 BaseT,
"Value \"" + DeviceConfigValueStr +
"\" must be a number");
577 if (DeviceConfigValue < 1)
579 "Value \"" + DeviceConfigValueStr +
580 "\" must be larger than zero");
584 Result.GPU = DeviceConfigValue;
585 Result.CPU = DeviceConfigValue;
586 Result.Accelerator = DeviceConfigValue;
589 getRefByDeviceType(Result, DeviceTypeIter->second) = DeviceConfigValue;
595 }
while (Start < ValueStr.size());
599 static ParsedValue getCachedValue(
bool ResetCache =
false) {
600 static ParsedValue Val = parseValue();
612 constexpr
bool DefaultValue =
true;
614 const char *ValStr = getCachedValue();
619 return ValStr[0] ==
'1';
622 static void reset() { (void)getCachedValue(
true); }
624 static const char *
getName() {
return BaseT::MConfigName; }
627 static const char *getCachedValue(
bool ResetCache =
false) {
628 static const char *ValStr = BaseT::getRawValue();
630 ValStr = BaseT::getRawValue();
639 static constexpr
bool Default =
true;
640 static bool get() {
return getCachedValue(); }
641 static const char *
getName() {
return BaseT::MConfigName; }
644 static bool parseValue() {
645 const char *ValStr = BaseT::getRawValue();
648 if (strlen(ValStr) != 1 || (ValStr[0] !=
'0' && ValStr[0] !=
'1')) {
650 std::string{
"Invalid value for bool configuration variable "} +
652 throw runtime_error(Msg, PI_ERROR_INVALID_OPERATION);
654 return ValStr[0] ==
'1';
657 static bool getCachedValue() {
658 static bool Val = parseValue();
663 #undef INVALID_CONFIG_EXCEPTION
ods_target_list & getOneapiDeviceSelectorTargets(const std::string &InitValue)
device_filter_list & getDeviceFilterList(const std::string &InitValue)
static GlobalHandler & instance()
static ods_target_list * get()
static const char * getName()
static const char * getName()
static const char * getName()
static const char * getName()
static void resetWithValue(const char *Val)
static const char * getName()
static void GetSettings(size_t &MinFactor, size_t &GoodFactor, size_t &MinRange)
static const char * getName()
static size_t get(info::device_type DeviceType)
static unsigned int get()
static const char * getName()
static const char * get()
#define INVALID_CONFIG_EXCEPTION(BASE, MSG)
__SYCL_EXTERN_STREAM_ATTRS ostream cerr
Linked to standard error (unbuffered)
constexpr bool ConfigFromEnvEnabled
void readConfig(bool ForceInitialization)
const std::array< std::pair< std::string, backend >, 8 > & getSyclBeMap()
constexpr int MAX_CONFIG_VALUE
const std::array< std::pair< std::string, info::device_type >, 6 > & getSyclDeviceTypeMap()
constexpr const char * getStrOrNullptr(const char *Str)
constexpr bool ConfigFromFileEnabled
constexpr bool ConfigFromCompileDefEnabled
constexpr int MAX_CONFIG_NAME
signed char __SYCL2020_DEPRECATED
C++ wrapper of extern "C" PI interfaces.