-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[SYCL] Add platform enumeration and info query using liboffload #166927
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
Open
KseniyaTikhomirova
wants to merge
10
commits into
llvm:main
Choose a base branch
from
KseniyaTikhomirova:add_get_platforms
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b22192a
[SYCL] Add platform enumeration and info query using liboffload (#2)
KseniyaTikhomirova bcb2711
add partial spec and base for std::hash support
KseniyaTikhomirova b15b6c0
fix comments
KseniyaTikhomirova 88d313c
early init of platforms
KseniyaTikhomirova 849fed9
remove unique_ptr, make ref const, add operator==
KseniyaTikhomirova 7f62590
fix installation
KseniyaTikhomirova f081eea
fix format
KseniyaTikhomirova 2224ab8
remove offload codes from distributed headers
KseniyaTikhomirova 71dcdf9
change ref to impl to raw ptr
KseniyaTikhomirova 51529c1
add asserts for impl
KseniyaTikhomirova 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
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,71 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| /// | ||
| /// \file | ||
| /// This file contains the declaration of the SYCL enum class backend that is | ||
| /// implementation-defined and is populated with a unique identifier for each | ||
| /// SYCL backend that the SYCL implementation can support. | ||
| /// | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef _LIBSYCL___IMPL_BACKEND_HPP | ||
| #define _LIBSYCL___IMPL_BACKEND_HPP | ||
|
|
||
| #include <sycl/__impl/detail/config.hpp> | ||
|
|
||
| #include <string_view> | ||
| #include <type_traits> | ||
|
|
||
| _LIBSYCL_BEGIN_NAMESPACE_SYCL | ||
|
|
||
| // 4.1. Backends | ||
| enum class backend : char { | ||
| opencl = 1, | ||
| level_zero = 2, | ||
| cuda = 3, | ||
| hip = 4, | ||
| all = 5, | ||
| }; | ||
|
|
||
| namespace detail { | ||
| template <typename T> struct is_backend_info_desc : std::false_type {}; | ||
| } // namespace detail | ||
|
|
||
| // 4.5.1.1. Type traits backend_traits | ||
| template <backend Backend> class backend_traits; | ||
|
|
||
| template <backend Backend, typename SYCLObjectT> | ||
| using backend_input_t = | ||
| typename backend_traits<Backend>::template input_type<SYCLObjectT>; | ||
| template <backend Backend, typename SYCLObjectT> | ||
| using backend_return_t = | ||
| typename backend_traits<Backend>::template return_type<SYCLObjectT>; | ||
|
|
||
| namespace detail { | ||
| // Used by SYCL tools | ||
| inline std::string_view get_backend_name(const backend &Backend) { | ||
| switch (Backend) { | ||
| case backend::opencl: | ||
| return "opencl"; | ||
| case backend::level_zero: | ||
| return "level_zero"; | ||
| case backend::cuda: | ||
| return "cuda"; | ||
| case backend::hip: | ||
| return "hip"; | ||
| case backend::all: | ||
| return "all"; | ||
| } | ||
|
|
||
| return ""; | ||
| } | ||
| } // namespace detail | ||
|
|
||
| _LIBSYCL_END_NAMESPACE_SYCL | ||
|
|
||
| #endif // _LIBSYCL___IMPL_BACKEND_HPP | ||
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,52 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| /// | ||
| /// \file | ||
| /// This file contains macro definitions used in SYCL implementation. | ||
| /// | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef _LIBSYCL___IMPL_DETAIL_MACRO_DEFINITIONS_HPP | ||
| #define _LIBSYCL___IMPL_DETAIL_MACRO_DEFINITIONS_HPP | ||
|
|
||
| #ifndef __SYCL2020_DEPRECATED | ||
| # if SYCL_LANGUAGE_VERSION == 202012L && \ | ||
| !defined(SYCL2020_DISABLE_DEPRECATION_WARNINGS) | ||
| # define __SYCL2020_DEPRECATED(message) [[deprecated(message)]] | ||
| # else | ||
| # define __SYCL2020_DEPRECATED(message) | ||
| # endif | ||
| #endif // __SYCL2020_DEPRECATED | ||
|
|
||
| static_assert(__cplusplus >= 201703L, | ||
| "SYCL RT does not support C++ version earlier than C++17."); | ||
|
|
||
| #if defined(_WIN32) && !defined(_DLL) && !defined(__SYCL_DEVICE_ONLY__) | ||
| // SYCL library is designed such a way that STL objects cross DLL boundary, | ||
| // which is guaranteed to work properly only when the application uses the same | ||
| // C++ runtime that SYCL library uses. | ||
| // The appplications using sycl.dll must be linked with dynamic/release C++ MSVC | ||
| // runtime, i.e. be compiled with /MD switch. Similarly, the applications using | ||
| // sycld.dll must be linked with dynamic/debug C++ runtime and be compiled with | ||
| // /MDd switch. | ||
| // Compiler automatically adds /MD or /MDd when -fsycl switch is used. | ||
| // The options /MD and /MDd that make the code to use dynamic runtime also | ||
| // define the _DLL macro. | ||
| # define ERROR_MESSAGE \ | ||
| "SYCL library is designed to work safely with dynamic C++ runtime." \ | ||
| "Please use /MD switch with sycl.dll, /MDd switch with sycld.dll, " \ | ||
| "or -fsycl switch to set C++ runtime automatically." | ||
| # if defined(_MSC_VER) | ||
| # pragma message(ERROR_MESSAGE) | ||
| # else | ||
| # warning ERROR_MESSAGE | ||
| # endif | ||
| # undef ERROR_MESSAGE | ||
| #endif // defined(_WIN32) && !defined(_DLL) && !defined(__SYCL_DEVICE_ONLY__) | ||
|
|
||
| #endif //_LIBSYCL___IMPL_DETAIL_MACRO_DEFINITIONS_HPP |
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 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| /// | ||
| /// \file | ||
| /// This file contains helper functions for tranformation between implementation | ||
| /// and SYCL's interface objects. | ||
| /// | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef _LIBSYCL___IMPL_DETAIL_OBJ_BASE_HPP | ||
| #define _LIBSYCL___IMPL_DETAIL_OBJ_BASE_HPP | ||
|
|
||
| #include <sycl/__impl/detail/config.hpp> | ||
|
|
||
| #include <cassert> | ||
| #include <optional> | ||
| #include <type_traits> | ||
| #include <utility> | ||
|
|
||
| _LIBSYCL_BEGIN_NAMESPACE_SYCL | ||
|
|
||
| namespace detail { | ||
|
|
||
| template <typename Impl, typename SyclObject> class ObjBase; | ||
| template <typename Impl, typename SyclObject> | ||
| class ObjBase<Impl *, SyclObject> { | ||
| public: | ||
| using ImplType = Impl; | ||
| using ImplPtrType = Impl *; | ||
| using Base = ObjBase<Impl *, SyclObject>; | ||
|
|
||
| protected: | ||
| ImplPtrType impl; | ||
|
|
||
| explicit ObjBase(ImplPtrType pImpl) : impl(pImpl) { | ||
| assert(impl && "Impl can not be nullptr"); | ||
| } | ||
| ObjBase() = default; | ||
|
|
||
| static SyclObject createSyclProxy(ImplPtrType impl) { | ||
| return SyclObject(impl); | ||
| } | ||
|
|
||
| ImplType &getImpl() const { | ||
| assert(impl && "Impl can not be nullptr"); | ||
| return *impl; | ||
| } | ||
|
|
||
| template <class Obj> | ||
| friend const typename Obj::ImplType &getSyclObjImpl(const Obj &Object); | ||
|
|
||
| template <class Obj> | ||
| friend Obj createSyclObjFromImpl( | ||
| std::add_lvalue_reference_t<const typename Obj::ImplPtrType> ImplObj); | ||
| }; | ||
KseniyaTikhomirova marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| template <class Obj> | ||
| const typename Obj::ImplType &getSyclObjImpl(const Obj &Object) { | ||
| assert(Object.impl && "Impl can not be nullptr"); | ||
| return *Object.impl; | ||
| } | ||
|
|
||
| template <class Obj> | ||
| Obj createSyclObjFromImpl( | ||
| std::add_lvalue_reference_t<const typename Obj::ImplPtrType> ImplObj) { | ||
| return Obj::Base::createSyclProxy(ImplObj); | ||
| } | ||
|
|
||
| // std::hash support (4.5.2. Common reference semantics) | ||
| template <typename T> struct HashBase { | ||
| size_t operator()(const T &Obj) const { | ||
| #ifdef __SYCL_DEVICE_ONLY__ | ||
| (void)Obj; | ||
| return 0; | ||
| #else | ||
| auto &Impl = sycl::detail::getSyclObjImpl(Obj); | ||
| return std::hash<std::decay_t<decltype(Impl)>>{}(Impl); | ||
| #endif | ||
| } | ||
| }; | ||
|
|
||
| } // namespace detail | ||
|
|
||
| _LIBSYCL_END_NAMESPACE_SYCL | ||
|
|
||
| #endif // _LIBSYCL___IMPL_DETAIL_OBJ_BASE_HPP | ||
Oops, something went wrong.
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.
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 we need to use something like
_LIBCPP_HIDE_FROM_ABIhere, if I understand the idea behind it correctly.Uh oh!
There was an error while loading. Please reload this page.
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 leave questions about ABI till the time I will add ABI tests
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.
If I understand correctly, in
intel/llvmthis function is defined in headers only because we want to use it in thesycl-lstool so the tool is always aligned on "known" backend with the SYCL RT.If this intent still stands, I would add a comment about it, or otherwise this function should not exist here at all, because we don't use it anywhere else in the headers
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 is still used in sycl-ls.
added tiny comment
b15b6c0