23 #ifndef SYCL_CONFIG_FILE_NAME
24 #define SYCL_CONFIG_FILE_NAME "sycl.conf"
25 #endif // SYCL_CONFIG_FILE_NAME
27 #define CONFIG(Name, MaxSize, CompileTimeDef) \
28 const char *SYCLConfigBase<Name>::MValueFromFile = nullptr; \
29 char SYCLConfigBase<Name>::MStorage[MaxSize + 1]; \
30 const char *const SYCLConfigBase<Name>::MCompileTimeDef = \
31 getStrOrNullptr(__SYCL_STRINGIFY(CompileTimeDef)); \
32 const char *const SYCLConfigBase<Name>::MConfigName = __SYCL_STRINGIFY(Name);
33 #include "detail/config.def"
36 static void initValue(
const char *Key,
const char *Value) {
37 #define CONFIG(Name, MaxSize, CompileTimeDef) \
38 if (0 == strncmp(Key, SYCLConfigBase<Name>::MConfigName, MAX_CONFIG_NAME)) { \
39 strncpy(SYCLConfigBase<Name>::MStorage, Value, MaxSize); \
40 SYCLConfigBase<Name>::MStorage[MaxSize] = '\0'; \
41 SYCLConfigBase<Name>::MValueFromFile = SYCLConfigBase<Name>::MStorage; \
44 #include "detail/config.def"
49 static bool Initialized =
false;
50 if (!ForceInitialization && Initialized) {
55 if (
const char *ConfigFile = getenv(
"SYCL_CONFIG_FILE_NAME"))
56 File.open(ConfigFile, std::ios::in);
58 const std::string LibSYCLDir = sycl::detail::OSUtil::getCurrentDSODir();
65 std::string BufString;
66 std::size_t Position = std::string::npos;
73 std::getline(File, BufString);
74 if (File.fail() && !File.eof()) {
76 File.clear(File.rdstate() & ~std::ios_base::failbit);
80 "An error occurred while attempting to read a line");
83 if ((BufString.length() > 0) &&
84 (BufString[BufString.length() - 1] ==
'\r')) {
88 if (BufString.find(
"#") != std::string::npos) {
89 BufString.erase(BufString.find(
"#"));
90 while ((BufString.length() > 0) &&
91 (BufString[BufString.length() - 1] ==
' ')) {
96 if ((BufString.length() == 0) ||
97 (BufString.find(
"=") == std::string::npos)) {
101 Position = BufString.find(
"=");
108 (BufString.length() != Position + 1)) {
111 if ((BufString[0] ==
' ') ||
112 (BufString[BufString.length() - 1] ==
' ') ||
113 (BufString[Position - 1] ==
' ') ||
114 (BufString[Position + 1] ==
' ')) {
117 "SPACE found at the beginning/end of the line "
118 "or before/after '='");
121 BufString.copy(Key, Position, 0);
122 Key[Position] =
'\0';
123 BufString.copy(Value, BufString.length() - (Position + 1),
125 Value[BufString.length() - (Position + 1)] =
'\0';
129 "The value contains more than " +
131 " characters or does not contain them at all");
135 "Variable name is more than " +
137 " or less than one character");
149 #define CONFIG(Name, MaxSize, CompileTimeDef) \
151 const char *Val = SYCLConfigBase<Name>::getRawValue(); \
152 std::cerr << SYCLConfigBase<Name>::MConfigName << " : " \
153 << (Val ? Val : "unset") << std::endl; \
155 #include "detail/config.def"
160 const std::array<std::pair<std::string, info::device_type>, 5> &
162 static const std::array<std::pair<std::string, info::device_type>, 5>
163 SyclDeviceTypeMap = {{{
"host", info::device_type::host},
164 {
"cpu", info::device_type::cpu},
165 {
"gpu", info::device_type::gpu},
166 {
"acc", info::device_type::accelerator},
168 return SyclDeviceTypeMap;
173 static const std::array<std::pair<std::string, backend>, 7> SyclBeMap = {
174 {{
"host", backend::host},
175 {
"opencl", backend::opencl},
176 {
"level_zero", backend::ext_oneapi_level_zero},
177 {
"cuda", backend::ext_oneapi_cuda},
178 {
"hip", backend::ext_oneapi_hip},
179 {
"esimd_emulator", backend::ext_intel_esimd_emulator},