-
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 10 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,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> { | ||
KseniyaTikhomirova marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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.
Outdated
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 | ||
Uh oh!
There was an error while loading. Please reload this page.