-
Notifications
You must be signed in to change notification settings - Fork 798
[SYCL] Implement new env var SYCL_DEVICE_FILTER #2239
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
Merged
Changes from 10 commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
b4a5ffa
[SYCL] Implement new env var SYCL_DEVICE_TRIPLE
bso-intel 0456825
added description of SYCL_DEVICE_TRIPLE in doc
bso-intel 72634d5
disable windows tentatively
bso-intel 6ec2671
clean up format
bso-intel 5471b63
Merge remote-tracking branch 'upstream/sycl' into sycl-device-triple
bso-intel 6b25217
accmmodated feedback
bso-intel 0e9c8d4
added * for a backend type
bso-intel 6304163
Merge remote-tracking branch 'upstream/sycl' into sycl-device-triple
bso-intel 35937b5
changed the order of device triple
bso-intel 8e38292
clang-format
bso-intel 779d304
Update sycl/include/CL/sycl/device_triple.hpp
bso-intel f8034c3
Update sycl/source/device_triple.cpp
bso-intel da4eab2
feedback accmmodated
bso-intel b995852
Merge branch 'sycl-device-triple' of https://github.com/bso-intel/llv…
bso-intel fa1fd6e
clang-format
bso-intel 230bbd4
moved device_triple.hpp/cpp into 'detail' namespace
bso-intel 1e4bac0
Merge remote-tracking branch 'upstream/sycl' into sycl-device-triple
bso-intel ded32d0
Merge remote-tracking branch 'upstream/sycl' into sycl-device-triple
bso-intel 18bb025
refactored with device_filter data structure
bso-intel 0eb0697
clang-format
bso-intel 1b12fb2
Update sycl/include/CL/sycl/detail/device_filter.hpp
bso-intel c1475c7
added comments about Initialized
bso-intel 1c0226b
added back documentation of new env var
bso-intel a1f075e
fixed a typo
bso-intel e0d037f
clarifiied HOST availability for default_selector
bso-intel 7721ca5
typo
bso-intel 432eb20
Update sycl/doc/EnvironmentVariables.md
bso-intel ff720c4
added deprecation notice
bso-intel b70a425
Merge branch 'sycl-device-triple' of https://github.com/bso-intel/llv…
bso-intel 7a375f4
typo
bso-intel 52c1c88
added DeviceNum bonus point
bso-intel c46a497
description change
bso-intel facf402
format \*
bso-intel a996dc0
Merge branch 'sycl-device-triple' of https://github.com/bso-intel/llv…
bso-intel be44799
fix overflow
bso-intel 800afe4
moved loading plugin stmt
bso-intel dd06217
give bonus points only when backend, device_type, device_num matched.
bso-intel 6864017
clang-format
bso-intel 8494203
change as requested by feedback
bso-intel 156045a
respond to feedback
bso-intel 8de7500
clang-format
bso-intel 39c0725
typo
bso-intel f7f3718
clang-format
bso-intel 4399a96
respond to more feedback
bso-intel 9b83eee
Update sycl/test/filter_selector/select_device_cpu.cpp
bso-intel 092673f
Update sycl/test/filter_selector/select_device_acc.cpp
bso-intel 84a80ef
Update sycl/test/filter_selector/select_device_acc.cpp
bso-intel 0a0cf63
Update sycl/source/detail/config.hpp
bso-intel dd12cba
Update sycl/test/filter_selector/select_device_acc.cpp
bso-intel f3c6387
Update sycl/source/detail/device_filter.cpp
bso-intel 4708688
clang-format
bso-intel ba2c293
fixed error caused in lambda
bso-intel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| //==-------------- triple.hpp - SYCL device triple descripter --------------==// | ||
bso-intel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <CL/sycl/backend_types.hpp> | ||
| #include <CL/sycl/detail/defines.hpp> | ||
| #include <CL/sycl/info/info_desc.hpp> | ||
|
|
||
| #include <iostream> | ||
| #include <string> | ||
|
|
||
| __SYCL_INLINE_NAMESPACE(cl) { | ||
| namespace sycl { | ||
|
|
||
| class device_triple { | ||
bso-intel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| backend Backend; | ||
| info::device_type DeviceType; | ||
| int32_t DeviceNum; | ||
| const int DEVICE_NUM_UNSPECIFIED = -1; | ||
bso-intel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| public: | ||
| device_triple(std::string &TripleString); | ||
| backend getBackend() const { return Backend; } | ||
| info::device_type getDeviceType() const { return DeviceType; } | ||
| int32_t getDeviceNum() const { return DeviceNum; } | ||
| friend std::ostream &operator<<(std::ostream &Out, const device_triple &Trp); | ||
| }; | ||
|
|
||
| class device_triple_list { | ||
| std::vector<device_triple> TripleList; | ||
|
|
||
| public: | ||
| device_triple_list(std::string &TripleString); | ||
| device_triple_list(device_triple &Trp); | ||
| std::vector<device_triple> &get() { return TripleList; } | ||
| friend std::ostream &operator<<(std::ostream &Out, | ||
| const device_triple_list &List); | ||
| }; | ||
|
|
||
| inline std::ostream &operator<<(std::ostream &Out, const device_triple &Trp) { | ||
| switch (Trp.Backend) { | ||
| case backend::host: | ||
| Out << std::string("host"); | ||
| break; | ||
| case backend::opencl: | ||
| Out << std::string("opencl"); | ||
| break; | ||
| case backend::level_zero: | ||
| Out << std::string("level-zero"); | ||
| break; | ||
| case backend::cuda: | ||
| Out << std::string("cuda"); | ||
| break; | ||
| case backend::all: | ||
| Out << std::string("*"); | ||
| } | ||
| Out << std::string(":"); | ||
| if (Trp.DeviceType == info::device_type::host) { | ||
| Out << std::string("host"); | ||
| } else if (Trp.DeviceType == info::device_type::cpu) { | ||
| Out << std::string("cpu"); | ||
| } else if (Trp.DeviceType == info::device_type::gpu) { | ||
| Out << std::string("gpu"); | ||
| } else if (Trp.DeviceType == info::device_type::accelerator) { | ||
| Out << std::string("acceclerator"); | ||
| } else if (Trp.DeviceType == info::device_type::all) { | ||
| Out << std::string("*"); | ||
| } | ||
| if (Trp.DeviceNum != Trp.DEVICE_NUM_UNSPECIFIED) { | ||
| Out << std::string(":") << Trp.DeviceNum; | ||
| } | ||
| return Out; | ||
| } | ||
|
|
||
| inline std::ostream &operator<<(std::ostream &Out, | ||
| const device_triple_list &List) { | ||
| for (const device_triple &Trp : List.TripleList) { | ||
| Out << Trp; | ||
| Out << ","; | ||
| } | ||
| return Out; | ||
| } | ||
|
|
||
| } // namespace sycl | ||
| } // __SYCL_INLINE_NAMESPACE(cl) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| //==------------------- device_triple.cpp ----------------------------------==// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include <CL/sycl/device_triple.hpp> | ||
| #include <CL/sycl/info/info_desc.hpp> | ||
| #include <cstring> | ||
| #include <detail/config.hpp> | ||
| #include <detail/device_impl.hpp> | ||
bso-intel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| __SYCL_INLINE_NAMESPACE(cl) { | ||
| namespace sycl { | ||
|
|
||
| device_triple::device_triple(std::string &TripleString) { | ||
| const std::array<std::pair<std::string, info::device_type>, 5> | ||
| SyclDeviceTypeMap = {{{"host", info::device_type::host}, | ||
| {"cpu", info::device_type::cpu}, | ||
| {"gpu", info::device_type::gpu}, | ||
| {"acc", info::device_type::accelerator}, | ||
| {"*", info::device_type::all}}}; | ||
| const std::array<std::pair<std::string, backend>, 4> SyclBeMap = { | ||
| {{"opencl", backend::opencl}, | ||
| {"level_zero", backend::level_zero}, | ||
| {"cuda", backend::cuda}, | ||
| {"*", backend::all}}}; | ||
|
|
||
| // handle the optional 1st entry, backend | ||
| size_t Cursor = 0; | ||
| size_t ColonPos = TripleString.find(":", Cursor); | ||
| auto It = std::find_if( | ||
| std::begin(SyclBeMap), std::end(SyclBeMap), | ||
| [=, &Cursor](const std::pair<std::string, backend> &Element) { | ||
| size_t Found = TripleString.find(Element.first, Cursor); | ||
| if (Found != std::string::npos) { | ||
| Cursor = Found; | ||
| return true; | ||
| } | ||
| return false; | ||
| }); | ||
| if (It == SyclBeMap.end()) { | ||
| Backend = backend::all; | ||
| } else { | ||
| Backend = It->second; | ||
| if (ColonPos != std::string::npos) { | ||
| Cursor = ColonPos + 1; | ||
| } else { | ||
| Cursor = Cursor + It->first.size(); | ||
| } | ||
| } | ||
|
|
||
| // handle the optional 2nd entry, device type | ||
| auto Iter = std::find_if( | ||
| std::begin(SyclDeviceTypeMap), std::end(SyclDeviceTypeMap), | ||
| [=, &Cursor](const std::pair<std::string, info::device_type> &Element) { | ||
| size_t Found = TripleString.find(Element.first, Cursor); | ||
| if (Found != std::string::npos) { | ||
| Cursor = Found; | ||
| return true; | ||
| } | ||
| return false; | ||
| }); | ||
| if (Iter == SyclDeviceTypeMap.end()) { | ||
| DeviceType = info::device_type::all; | ||
| } else { | ||
| DeviceType = Iter->second; | ||
| ColonPos = TripleString.find(":", Cursor); | ||
| if (ColonPos != std::string::npos) { | ||
| Cursor = ColonPos + 1; | ||
| } else { | ||
| Cursor = Cursor + Iter->first.size(); | ||
| } | ||
| } | ||
|
|
||
| // handle the optional 3rd entry, device number | ||
| if (Cursor < TripleString.size()) { | ||
| try { | ||
| DeviceNum = stoi(TripleString.substr(ColonPos + 1)); | ||
| } catch (...) { | ||
| char message[100]; | ||
| strcpy(message, "Invalid device triple: "); | ||
| std::strcat(message, TripleString.c_str()); | ||
| std::strcat(message, | ||
| "\nPossible backend values are {opencl,level_zero,cuda,*}."); | ||
| std::strcat(message, "\nPossible device types are {host,cpu,gpu,acc,*}."); | ||
| std::strcat(message, | ||
| "\nDevice number should be an non-negative integer.\n"); | ||
| throw cl::sycl::invalid_parameter_error(message, PI_INVALID_VALUE); | ||
| } | ||
| } else { | ||
| DeviceNum = DEVICE_NUM_UNSPECIFIED; | ||
| } | ||
| } | ||
|
|
||
| device_triple_list::device_triple_list(std::string &TripleString) { | ||
| std::transform(TripleString.begin(), TripleString.end(), TripleString.begin(), | ||
| ::tolower); | ||
| size_t Pos = 0; | ||
| while (Pos < TripleString.size()) { | ||
| size_t CommaPos = TripleString.find(",", Pos); | ||
| if (CommaPos == std::string::npos) { | ||
| CommaPos = TripleString.size(); | ||
| } | ||
| std::string SubString = TripleString.substr(Pos, CommaPos - Pos); | ||
| TripleList.push_back(device_triple(SubString)); | ||
| Pos = CommaPos + 1; | ||
| } | ||
| } | ||
|
|
||
| } // namespace sycl | ||
| } // __SYCL_INLINE_NAMESPACE(cl) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.