-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL] Add support for devices white list #867
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
[SYCL] Add support for devices white list #867
Conversation
sycl/source/detail/platform_impl.cpp
Outdated
}; | ||
|
||
static std::vector<DevDescT> getWhiteListDesc() { | ||
// TODO: Replace with const char *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.
Waiting for #859 to resolve this.
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.
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.
Please add a test
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.
Please add a test.
sycl/source/detail/platform_impl.cpp
Outdated
continue; | ||
|
||
pi_devices[i] = pi_devices.back(); | ||
pi_devices.pop_back(); |
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 is going to change order of devices, right? It should not matter for a properly written program, but can be unexpected. It should be easy to change the loop and iterate forward instead (with two indices: insertion point and current device).
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.
Sorry, didn't get the idea how to change the loop.
Furthermore I don't think we should try to preserve the order as program relying on this is 200% invalid. The are source of order change already anyway(icd filenames, OCL_ICD_FILENAMES, OCL_ICD_VENDORS).
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 don't think we should try to preserve the order as program relying on this is 200% invalid.
Relying on the order is invalid, but let's not break it if we can.
The idea is simple: iterate over devices (index i) and have another index where the next "good" device should be written.
int insert_idx = 0;
for (int i = 0; i < devices.size(); ++i) {
if (isgood(devices[i]) {
devices[insert_idx++] = devices[i];
}
}
devices.resize(insert_idx);
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.
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.
c4ddc85
to
cc76e05
Compare
Don't know how to write a test, do you have some ideas? |
Sounds good! |
cc76e05
to
8f879e6
Compare
// TODO: Replace with const char *str = | ||
// SYCLConfig<SYCL_DEVICE_WHITE_LIST>::get(); | ||
const char *str = getenv("SYCL_DEVICE_WHITE_LIST"); | ||
if (!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.
I would like to check this condition as early as possible i.e. before calling filterWhiteList
to avoid unnecessary overhead.
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 additional check before calling filterWhiteList
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 like to check this condition as early as possible i.e. before calling filterWhiteList to avoid unnecessary overhead.
This is already the first operation in filterWhiteList
, which overhead you are trying to avoid?
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.
vector creation/deletion + function calls.
Add support for SYCL_DEVICE_WHITE_LIST config which allows to specify the white list of devices and their minimum driver version. This is done by setting configuration in the following format: DeviceName:{{XXX}},DriverVersion:{{X.Y.Z.W}}|DeviceName:{{XXX}},DriverVersion:{{X.Y.Z.W}} Where values in {{ }} can be specified in ECMAScript regular expressions pattern syntax Devices that do not satisfy the pattern from the white list are ignored. Signed-off-by: Vlad Romanov <[email protected]>
Signed-off-by: Vlad Romanov <[email protected]>
Signed-off-by: Vlad Romanov <[email protected]>
8f879e6
to
98067b0
Compare
// Skip ':' | ||
str += 1; | ||
|
||
if ('{' != *str || '{' != *(str + 1)) |
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 should check that *str != '\0'
.
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.
No, it is actually not needed here.
Signed-off-by: Vlad Romanov <[email protected]>
Signed-off-by: Vlad Romanov <[email protected]>
Done. |
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.
All comments are resolved.
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 looks like a good introduction about why we need #include <algorithm>
:-)
Perhaps https://www.youtube.com/watch?v=pUEnO6SvAMo might be interesting.
// As device name string will be used as regexp pattern, we need to | ||
// get rid of symbols that can be treated in a special way. | ||
// Replace common special symbols with '.' which matches to any sybmol | ||
for (char &Sym : DevName) { |
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 about using algorithms instead?
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 replace with:
std::replace_if(DevName.begin(), DevName.end(),
[](const char Sym) { return '(' == Sym || ')' == Sym; }, '.');
Speaking honestly, I think loop code is more readable.
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 was thinking to a simpler:
std::replace(DevName.begin(), DevName.end(), '(', '.');
std::replace(DevName.begin(), DevName.end(), ')', '.');
since everything is in the cache, it should be fast.
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 understand that it's a test but I don't think we should sacrifice performance in order to make C++ code more readable...
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 think it is very subjective.
for (char &Sym : DevName) {
if (')' == Sym || '(' == Sym)
Sym = '.';
}
IMO this code is more readable than:
std::replace(DevName.begin(), DevName.end(), '(', '.');
std::replace(DevName.begin(), DevName.end(), ')', '.');
const char driverVerStr[] = "DriverVersion"; | ||
decDescs.emplace_back(); | ||
while ('\0' != *str) { | ||
const char **valuePtr = nullptr; |
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.
It smells badly in a C++ code...
throw sycl::runtime_error("Malformed device white list"); | ||
|
||
++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.
Is it possible to rewrite this loop in something higher-level so it is more understandable?
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 try.
Signed-off-by: Vlad Romanov [email protected]