-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[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
base: main
Are you sure you want to change the base?
Changes from all commits
b22192a
bcb2711
b15b6c0
88d313c
849fed9
7f62590
f081eea
2224ab8
71dcdf9
51529c1
821a306
87442d1
e4e6fd2
e8e2811
9ce7695
9653e23
885947b
656227b
002eeb3
72ee9cd
fb91c2b
c90c2a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 | ||
|
|
||
| // SYCL 2020 4.1. Backends. | ||
| enum class backend : unsigned char { | ||
| opencl = 0, | ||
| level_zero, | ||
| cuda, | ||
| hip, | ||
| }; | ||
|
|
||
| namespace detail { | ||
| template <typename T> struct is_backend_info_desc : std::false_type {}; | ||
| } // namespace detail | ||
|
|
||
| // SYCL 2020 4.5.1.1. Type traits backend_traits. | ||
| template <backend Backend> class backend_traits; | ||
|
|
||
| template <backend Backend, typename SyclType> | ||
| using backend_input_t = | ||
| typename backend_traits<Backend>::template input_type<SyclType>; | ||
| template <backend Backend, typename SyclType> | ||
| using backend_return_t = | ||
| typename backend_traits<Backend>::template return_type<SyclType>; | ||
|
|
||
| _LIBSYCL_END_NAMESPACE_SYCL | ||
|
|
||
| #endif // _LIBSYCL___IMPL_BACKEND_HPP | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,49 @@ | ||||||||||||||
| //===----------------------------------------------------------------------===// | ||||||||||||||
| // | ||||||||||||||
| // 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 | ||||||||||||||
|
|
||||||||||||||
| static_assert(__cplusplus >= 201703L, "Libsycl requires C++17 or later."); | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Testing the value of
Suggested change
Yes, this is super annoying. |
||||||||||||||
|
|
||||||||||||||
| #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 | ||||||||||||||
|
|
||||||||||||||
| #if defined(_WIN32) && !defined(_DLL) && !defined(__SYCL_DEVICE_ONLY__) | ||||||||||||||
| // When built for use with the MSVC C++ standard library, libsycl requires | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it make sense to care about this now before we claim support for Windows?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now I don't use any OS-specific features in libsycl. So theoretically, once liboffload adds win support - base libsycl support on Win should be enabled automatically. (we will need some advanced handling of Win for shutdown but I want to keep this part for later upstreaming phases) |
||||||||||||||
| // use of the DLL versions of the MSVC run-time (RT) library. This requirement | ||||||||||||||
| // extends to applications that link with libsycl since the same MSVC run-time | ||||||||||||||
| // library must be used to ensure ABI compatibility for objects of C++ standard | ||||||||||||||
| // library types like std::vector that are passed to or returned from SYCL | ||||||||||||||
| // interfaces. Applications must therefore compile and link with the /MD option | ||||||||||||||
| // when linking to a release build of libsycl and with the /MDd option when | ||||||||||||||
| // linking to a debug build. | ||||||||||||||
| # define ERROR_MESSAGE \ | ||||||||||||||
| "Libsycl requires use of a DLL version of the MSVC RT library. " \ | ||||||||||||||
| "Please use /MD to link with a release build of libsycl or /MDd to link" \ | ||||||||||||||
| " with a debug build." | ||||||||||||||
| # 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 | ||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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_UTILS_HPP | ||
| #define _LIBSYCL___IMPL_DETAIL_OBJ_UTILS_HPP | ||
|
|
||
| #include <sycl/__impl/detail/config.hpp> | ||
|
|
||
| #include <cassert> | ||
| #include <memory> | ||
| #include <optional> | ||
| #include <type_traits> | ||
| #include <utility> | ||
|
|
||
| _LIBSYCL_BEGIN_NAMESPACE_SYCL | ||
|
|
||
| namespace detail { | ||
|
|
||
| // Note! This class relies on the fact that all SYCL interface | ||
| // classes contain "impl" field that points to implementation object. "impl" | ||
| // field should be accessible from this class. | ||
|
Comment on lines
+30
to
+32
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the pointer-to-impl idiom being used so extensively? I'm personally not a fan of it for performance reasons. If the reason is to create an ABI boundary, I think there are better ways to do that. |
||
| struct ImplUtils { | ||
| // Helper function for extracting implementation from SYCL's interface | ||
| // objects. | ||
| template <class Obj> | ||
| static const decltype(Obj::impl) &getSyclObjImpl(const Obj &SyclObj) { | ||
| assert(SyclObj.impl && "every constructor should create an impl"); | ||
| return SyclObj.impl; | ||
| } | ||
|
|
||
| // Helper function for creation SYCL interface objects from implementations. | ||
| template <typename SyclObject, typename From> | ||
| static SyclObject createSyclObjFromImpl(From &&from) { | ||
| if constexpr (std::is_same_v<decltype(SyclObject::impl), | ||
| std::shared_ptr<std::decay_t<From>>>) | ||
| return SyclObject{from.shared_from_this()}; | ||
| else | ||
| return SyclObject{std::forward<From>(from)}; | ||
| } | ||
| }; | ||
|
|
||
| template <class Obj> | ||
| auto getSyclObjImpl(const Obj &SyclObj) | ||
| -> decltype(ImplUtils::getSyclObjImpl(SyclObj)) { | ||
| return ImplUtils::getSyclObjImpl(SyclObj); | ||
| } | ||
|
|
||
| template <typename SyclObject, typename From> | ||
| SyclObject createSyclObjFromImpl(From &&from) { | ||
| return ImplUtils::createSyclObjFromImpl<SyclObject>(std::forward<From>(from)); | ||
| } | ||
|
|
||
| // SYCL 2020 4.5.2. Common reference semantics (std::hash support). | ||
| template <typename T> struct HashBase { | ||
| size_t operator()(const T &Obj) const { | ||
| auto &Impl = sycl::detail::getSyclObjImpl(Obj); | ||
| return std::hash<std::decay_t<decltype(Impl)>>{}(Impl); | ||
| } | ||
| }; | ||
|
|
||
| } // namespace detail | ||
|
|
||
| _LIBSYCL_END_NAMESPACE_SYCL | ||
|
|
||
| #endif // _LIBSYCL___IMPL_DETAIL_OBJ_UTILS_HPP | ||
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.
detail::is_backend_info_descdoesn't appear to be used in this PR. Should it be omitted for now? I seeplatform::get_backend_info()isn't implemented yet.