-
Notifications
You must be signed in to change notification settings - Fork 787
[WIP] [SYCL] Add SYCLConfig helper #859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] [SYCL] Add SYCLConfig helper #859
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This actually looks pretty good.
c4ba968
to
32bbc2b
Compare
32bbc2b
to
41b5fc1
Compare
sycl/source/detail/config.cpp
Outdated
namespace detail { | ||
|
||
#ifndef SYCL_CONFIG_FILE_NAME | ||
#define SYCL_CONFIG_FILE_NAME "sycl.cfg" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sycl.conf?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
File.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); | ||
continue; | ||
} | ||
File.getline(Value, sizeof(Value), '\n'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder what happens on Windows. People tend add \r\n
instead of \n
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a logic which removes \r if it exists. Cannot write proper test as we have no env vars sensitive to the additional character at the end. Did manual testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All this \n
should be handled transparently by iostream
, isn't it???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, \n is the default value of 3rd argument.. Will remove
// RUN: ls | grep dot | ||
// RUN: rm *.dot | ||
// RUN: env SYCL_PRINT_EXECUTION_GRAPH=always %t.out | ||
// RUN: ls | grep dot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure that this works on Windows if you don't have GNU coreutils installed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reused this idea from clang LIT tests so I expect it works on the same configurations as clang LIT tests work.
SYCLConfig helper provides an access to configs that is defined in config.hpp. Such configs can be set at compile time, using environment variable and configuration file. SYCLConfig checks all the sources and return value which was set using an option which has highest priority. Current priorities are: 1. Environment variable 2. Configuration file 3. Compiler time If a value is not set nullptr is returned. Signed-off-by: Vlad Romanov <[email protected]>
side effects of env var. Signed-off-by: Vlad Romanov <[email protected]>
Signed-off-by: Vlad Romanov <[email protected]>
Signed-off-by: Vlad Romanov <[email protected]>
1c726ff
to
48c43e8
Compare
Signed-off-by: Vlad Romanov <[email protected]>
48c43e8
to
4c1f4d1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall. Please check what happened with strncpy.
File.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); | ||
continue; | ||
} | ||
File.getline(Value, sizeof(Value), '\n'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
Signed-off-by: Vlad Romanov <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. My comments are minor and can be ignored for now.
sycl/source/detail/config.def
Outdated
@@ -0,0 +1,14 @@ | |||
// Singnature: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Singnature: | |
// Syntax: |
Nit. Does this sound better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -46,7 +47,7 @@ static bool IsSuitableSubReq(const Requirement *Req) { | |||
} | |||
|
|||
Scheduler::GraphBuilder::GraphBuilder() { | |||
if (const char *EnvVarCStr = std::getenv("SYCL_PRINT_EXECUTION_GRAPH")) { | |||
if (const char *EnvVarCStr = SYCLConfig<SYCL_PRINT_EXECUTION_GRAPH>::get()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use it for all environment variable (SYCL_DEVICE_TYPE, SYCL_DUMP_IMAGES, etc)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use it for environment variables that are "getenv'ed" inside source directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to mention this limitation in the commit message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, will do during merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated description with new sentence.
Signed-off-by: Vlad Romanov <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
@@ -46,7 +47,7 @@ static bool IsSuitableSubReq(const Requirement *Req) { | |||
} | |||
|
|||
Scheduler::GraphBuilder::GraphBuilder() { | |||
if (const char *EnvVarCStr = std::getenv("SYCL_PRINT_EXECUTION_GRAPH")) { | |||
if (const char *EnvVarCStr = SYCLConfig<SYCL_PRINT_EXECUTION_GRAPH>::get()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to mention this limitation in the commit message.
@romanovvlad, this pull request has [WIP] in the title, so it's not ready for merge yet. |
Forgot to remove [WIP] tag. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad news: C is a dangerous language. :-(
Good news: SYCL is programmed in C++! :-)
#include "detail/config.def" | ||
#undef CONFIG | ||
|
||
#define MAX_CONFIG_NAME 256 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All this smells a lot old C...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will replace with constexpr.
static void initValue(const char *Key, const char *Value) { | ||
#define CONFIG(Name, MaxSize, CompileTimeDef) \ | ||
if (0 == strncmp(Key, SYCLConfigBase<Name>::MConfigName, MAX_CONFIG_NAME)) { \ | ||
strncpy(SYCLConfigBase<Name>::MStorage, Value, MaxSize); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And what happens when you reach the limit ? A non-\0
ending string... :-(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. Will fix by guaranteeing \0 at the and of the Value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer just using safer C++ instead of lower-level C at the first place...
File.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); | ||
continue; | ||
} | ||
File.getline(Value, sizeof(Value), '\n'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All this \n
should be handled transparently by iostream
, isn't it???
} | ||
|
||
// Handle '\r' by nullifying it | ||
const std::streamsize ReadSybmols = File.gcount(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is a Sybmols ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will rename to "characters".
} | ||
} | ||
Initialized = true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All this is super hackish and obfuscated compared to the obvious algorithm: iterating on a plain getline()
and using std::find
or another algorithm to tokenize around =
|
||
// Consider strings starting with __ as unset | ||
constexpr const char *getStrOrNullptr(const char *Str) { | ||
return (Str[0] == '_' && Str[1] == '_') ? nullptr : Str; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happened if a string has less than 2 characters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add check for that.
SYCLConfig helper provides an access to configs that is defined in
config.hpp. Such configs can be set at compile time, using environment
variable and configuration file. SYCLConfig checks all the sources and
return value which was set using an option which has highest priority.
Current priorities are:
If a value is not set nullptr is returned.
Currently SYCLConfig can be used from source directory only.
Signed-off-by: Vlad Romanov [email protected]