20 inline namespace _V1 {
23 #ifndef SYCL_CONFIG_FILE_NAME
24 #define SYCL_CONFIG_FILE_NAME "sycl.conf"
28 #ifndef __SYCL_STRINGIFY
29 #define __SYCL_STRINGIFY(x) #x
32 #define CONFIG(Name, MaxSize, CompileTimeDef) \
33 const char *SYCLConfigBase<Name>::MValueFromFile = nullptr; \
34 char SYCLConfigBase<Name>::MStorage[MaxSize + 1]; \
35 const char *const SYCLConfigBase<Name>::MCompileTimeDef = \
36 getStrOrNullptr(__SYCL_STRINGIFY(CompileTimeDef)); \
37 const char *const SYCLConfigBase<Name>::MConfigName = __SYCL_STRINGIFY(Name);
38 #include "detail/config.def"
41 static void initValue(
const char *Key,
const char *Value) {
42 #define CONFIG(Name, MaxSize, CompileTimeDef) \
43 if (0 == strncmp(Key, SYCLConfigBase<Name>::MConfigName, MAX_CONFIG_NAME)) { \
44 strncpy(SYCLConfigBase<Name>::MStorage, Value, MaxSize); \
45 SYCLConfigBase<Name>::MStorage[MaxSize] = '\0'; \
46 SYCLConfigBase<Name>::MValueFromFile = SYCLConfigBase<Name>::MStorage; \
49 #include "detail/config.def"
54 static bool Initialized =
false;
55 if (!ForceInitialization && Initialized) {
60 if (
const char *ConfigFile = getenv(
"SYCL_CONFIG_FILE_NAME"))
61 File.open(ConfigFile, std::ios::in);
63 const std::string LibSYCLDir = sycl::detail::OSUtil::getCurrentDSODir();
70 std::string BufString;
71 std::size_t Position = std::string::npos;
78 std::getline(File, BufString);
79 if (File.fail() && !File.eof()) {
81 File.clear(File.rdstate() & ~std::ios_base::failbit);
85 "An error occurred while attempting to read a line");
88 if ((BufString.length() > 0) &&
89 (BufString[BufString.length() - 1] ==
'\r')) {
93 if (BufString.find(
"#") != std::string::npos) {
94 BufString.erase(BufString.find(
"#"));
95 while ((BufString.length() > 0) &&
96 (BufString[BufString.length() - 1] ==
' ')) {
101 if ((BufString.length() == 0) ||
102 (BufString.find(
"=") == std::string::npos)) {
106 Position = BufString.find(
"=");
113 (BufString.length() != Position + 1)) {
116 if ((BufString[0] ==
' ') ||
117 (BufString[BufString.length() - 1] ==
' ') ||
118 (BufString[Position - 1] ==
' ') ||
119 (BufString[Position + 1] ==
' ')) {
122 "SPACE found at the beginning/end of the line "
123 "or before/after '='");
126 BufString.copy(Key, Position, 0);
127 Key[Position] =
'\0';
128 BufString.copy(Value, BufString.length() - (Position + 1),
130 Value[BufString.length() - (Position + 1)] =
'\0';
134 "The value contains more than " +
136 " characters or does not contain them at all");
140 "Variable name is more than " +
142 " or less than one character");
154 #define CONFIG(Name, MaxSize, CompileTimeDef) \
156 const char *Val = SYCLConfigBase<Name>::getRawValue(); \
157 std::cerr << SYCLConfigBase<Name>::MConfigName << " : " \
158 << (Val ? Val : "unset") << std::endl; \
160 #include "detail/config.def"
169 static const std::array<std::pair<std::string, backend>, 7> SyclBeMap = {
170 {{
"host", backend::host},
#define SYCL_CONFIG_FILE_NAME
void readConfig(bool ForceInitialization)
constexpr int MAX_CONFIG_VALUE
const std::array< std::pair< std::string, backend >, 7 > & getSyclBeMap()
constexpr int MAX_CONFIG_NAME
static void initValue(const char *Key, const char *Value)
std::error_code make_error_code(sycl::errc E) noexcept
Constructs an error code using e and sycl_category()