-
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 14 commits
b22192a
bcb2711
b15b6c0
88d313c
849fed9
7f62590
f081eea
2224ab8
71dcdf9
51529c1
821a306
87442d1
e4e6fd2
e8e2811
9ce7695
9653e23
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,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 | ||
KseniyaTikhomirova marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| enum class backend : char { | ||
KseniyaTikhomirova marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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 | ||
KseniyaTikhomirova marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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>; | ||
KseniyaTikhomirova marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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 | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -41,8 +41,8 @@ | |||||||
|
|
||||||||
| # else // _WIN32 | ||||||||
|
|
||||||||
| # define _LIBSYCL_DLL_LOCAL [[__gnu__::__visibility__("hidden")]] | ||||||||
| # define _LIBSYCL_EXPORT [[__gnu__::__visibility__("default")]] | ||||||||
| # define _LIBSYCL_DLL_LOCAL __attribute__((visibility("hidden"))) | ||||||||
| # define _LIBSYCL_EXPORT __attribute__((visibility("default"))) | ||||||||
|
Comment on lines
+44
to
+45
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. I think this change is fine, but I'm curious what motivated it. For consistency elsewhere perhaps?
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. it seems that gnu::visibility has limitation that attribute (visibility) - don't: llvm-project/libsycl/src/platform.cpp Lines 36 to 38 in e8e2811
with " error: an attribute list cannot appear here"
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. That's right; the C++11 attribute syntax is more restrictive in where it can be placed. Can we not use use the C++11 placement everywhere though? Or would that conflict with the syntax location required for Microsoft's
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. could you please clarify: |
||||||||
|
|
||||||||
| # endif // _WIN32 | ||||||||
| # endif // _LIBSYCL_EXPORT | ||||||||
|
|
||||||||
| 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."); | ||
KseniyaTikhomirova marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| #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. | ||
KseniyaTikhomirova marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // 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. | ||
KseniyaTikhomirova marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # 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." | ||
KseniyaTikhomirova marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # 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,81 @@ | ||||||||||||||||
| //===----------------------------------------------------------------------===// | ||||||||||||||||
| // | ||||||||||||||||
| // 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. | ||||||||||||||||
| 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)); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| // std::hash support (4.5.2. Common reference semantics) | ||||||||||||||||
KseniyaTikhomirova marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||
| template <typename T> struct HashBase { | ||||||||||||||||
| size_t operator()(const T &Obj) const { | ||||||||||||||||
| #ifdef __SYCL_DEVICE_ONLY__ | ||||||||||||||||
| (void)Obj; | ||||||||||||||||
|
Comment on lines
+65
to
+68
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. The
Suggested change
|
||||||||||||||||
| return 0; | ||||||||||||||||
|
Comment on lines
+67
to
+69
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. If this function won't implement useful semantics when compiled for the device, can we at least have it trap at run-time instead of returning a valid object that doesn't satisfy the function postconditions? E.g.,
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.
This automatically assumes, that the underlying device compiler (and any formats for representing device code) support such semantics. That is not the case for SPIR-V, as far as I know, for example. What is the reason for having the macro in the first place here? I can't imagine hash APIs being used from device code without violating some other restrictions or simply being a UB. As such, triggering a compilation/link failure through an unresolved symbol wouldn't be a bad idea. We can just leave this function as a declaration-only for device code as well.
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.
https://godbolt.org/z/qd8fGTMrG . Shouldn't we see llvm-spirv fail here then?
That is still a good point though, we don't know about other targets like PTX.
Not an expert in std headers implementation but it fails to compile https://godbolt.org/z/Eb94KMMed |
||||||||||||||||
| #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_UTILS_HPP | ||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.