Skip to content

[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

Merged

Conversation

romanovvlad
Copy link
Contributor

@romanovvlad romanovvlad commented Nov 21, 2019

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.

Currently SYCLConfig can be used from source directory only.

Signed-off-by: Vlad Romanov [email protected]

Copy link
Contributor

@asavonic asavonic left a 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.

@romanovvlad romanovvlad force-pushed the private/vromanov/AddingConfigReader branch from c4ba968 to 32bbc2b Compare November 21, 2019 18:08
@romanovvlad romanovvlad changed the title [SYCL] Add SYCLConfig helper [WIP] [SYCL] Add SYCLConfig helper Nov 21, 2019
@romanovvlad romanovvlad force-pushed the private/vromanov/AddingConfigReader branch from 32bbc2b to 41b5fc1 Compare November 22, 2019 15:38
namespace detail {

#ifndef SYCL_CONFIG_FILE_NAME
#define SYCL_CONFIG_FILE_NAME "sycl.cfg"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sycl.conf?

Copy link
Contributor Author

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');
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

Copy link
Contributor

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???

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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]>
Signed-off-by: Vlad Romanov <[email protected]>
Signed-off-by: Vlad Romanov <[email protected]>
@romanovvlad romanovvlad force-pushed the private/vromanov/AddingConfigReader branch from 1c726ff to 48c43e8 Compare November 25, 2019 18:26
Signed-off-by: Vlad Romanov <[email protected]>
@romanovvlad romanovvlad force-pushed the private/vromanov/AddingConfigReader branch from 48c43e8 to 4c1f4d1 Compare November 25, 2019 19:41
Copy link
Contributor

@asavonic asavonic left a 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');
Copy link
Contributor

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]>
alexbatashev
alexbatashev previously approved these changes Nov 26, 2019
Copy link
Contributor

@alexbatashev alexbatashev left a 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.

@@ -0,0 +1,14 @@
// Singnature:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Singnature:
// Syntax:

Nit. Does this sound better?

Copy link
Contributor Author

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()) {
Copy link
Contributor

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)?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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]>
Copy link
Contributor

@asavonic asavonic left a 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()) {
Copy link
Contributor

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 romanovvlad merged commit edb985a into intel:sycl Nov 26, 2019
@romanovvlad romanovvlad deleted the private/vromanov/AddingConfigReader branch November 26, 2019 13:01
@bader
Copy link
Contributor

bader commented Nov 26, 2019

@romanovvlad, this pull request has [WIP] in the title, so it's not ready for merge yet.
Did you merge it by mistake or just forgot to remove [WIP] tag?

@romanovvlad
Copy link
Contributor Author

@romanovvlad, this pull request has [WIP] in the title, so it's not ready for merge yet.
Did you merge it by mistake or just forgot to remove [WIP] tag?

Forgot to remove [WIP] tag.

Copy link
Contributor

@keryell keryell left a 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
Copy link
Contributor

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...

Copy link
Contributor Author

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); \
Copy link
Contributor

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... :-(

Copy link
Contributor Author

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.

Copy link
Contributor

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');
Copy link
Contributor

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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is a Sybmols ?

Copy link
Contributor Author

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;
}
Copy link
Contributor

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;
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants