-
Notifications
You must be signed in to change notification settings - Fork 16k
[SYCL] Add sycl::device initial implementation #176972
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
5
commits into
llvm:main
Choose a base branch
from
KseniyaTikhomirova:add_device_pr
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
5 commits
Select commit
Hold shift + click to select a range
372e122
[SYCL] Add sycl::device initial implementation
KseniyaTikhomirova 35ee340
fix code-review comments
KseniyaTikhomirova b3acc5d
fix new comments
KseniyaTikhomirova 9dc313f
fix new comments
KseniyaTikhomirova ae54270
return string size back
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef _LIBSYCL___IMPL_ASPECT_HPP | ||
| #define _LIBSYCL___IMPL_ASPECT_HPP | ||
|
|
||
| #include <sycl/__impl/detail/config.hpp> | ||
|
|
||
| #include <cstdint> | ||
|
|
||
| _LIBSYCL_BEGIN_NAMESPACE_SYCL | ||
|
|
||
| // SYCL 2020 4.6.4.5. Aspects. | ||
| enum class aspect : std::uint32_t { | ||
| cpu, | ||
| gpu, | ||
| accelerator, | ||
| custom, | ||
| emulated, | ||
| host_debuggable, | ||
| fp16, | ||
| fp64, | ||
| atomic64, | ||
| image, | ||
| online_compiler, | ||
| online_linker, | ||
| queue_profiling, | ||
| usm_device_allocations, | ||
| usm_host_allocations, | ||
| usm_atomic_host_allocations, | ||
| usm_shared_allocations, | ||
| usm_atomic_shared_allocations, | ||
| usm_system_allocations | ||
| }; | ||
|
|
||
| _LIBSYCL_END_NAMESPACE_SYCL | ||
|
|
||
| #endif // _LIBSYCL___IMPL_ASPECT_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,183 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 2020 device class, which | ||
| /// represents a single SYCL device on which kernels can be executed. | ||
| /// | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef _LIBSYCL___IMPL_DEVICE_HPP | ||
| #define _LIBSYCL___IMPL_DEVICE_HPP | ||
|
|
||
| #include <sycl/__impl/aspect.hpp> | ||
| #include <sycl/__impl/backend.hpp> | ||
| #include <sycl/__impl/device_selector.hpp> | ||
| #include <sycl/__impl/info/device.hpp> | ||
|
|
||
| #include <sycl/__impl/detail/config.hpp> | ||
| #include <sycl/__impl/detail/obj_utils.hpp> | ||
|
|
||
| _LIBSYCL_BEGIN_NAMESPACE_SYCL | ||
|
|
||
| class platform; | ||
|
|
||
| namespace detail { | ||
| class DeviceImpl; | ||
| } // namespace detail | ||
|
|
||
| // SYCL 2020 4.6.4. Device class. | ||
| class _LIBSYCL_EXPORT device { | ||
| public: | ||
| device(const device &rhs) = default; | ||
|
|
||
| device(device &&rhs) = default; | ||
|
|
||
| device &operator=(const device &rhs) = default; | ||
|
|
||
| device &operator=(device &&rhs) = default; | ||
|
|
||
| friend bool operator==(const device &lhs, const device &rhs) { | ||
| return lhs.impl == rhs.impl; | ||
| } | ||
|
|
||
| friend bool operator!=(const device &lhs, const device &rhs) { | ||
| return !(lhs == rhs); | ||
| } | ||
|
|
||
| /// Constructs a SYCL device instance using the default device (device chosen | ||
| /// by default device selector). | ||
| device(); | ||
|
|
||
| /// Constructs a SYCL device instance using the device | ||
| /// identified by the provided device selector. | ||
| /// \param DeviceSelector is SYCL 2020 device selector, a simple callable that | ||
| /// takes a device and returns an int. | ||
| template < | ||
| typename DeviceSelector, | ||
| // `DeviceImpl` (used as a parameter in private ctor) is incomplete | ||
| // so would result in a error trying to instantiate | ||
| // `EnableIfDeviceSelectorIsInvocable` below. Filter it out | ||
| // before trying to do that. | ||
| typename = | ||
| std::enable_if_t<!std::is_same_v<DeviceSelector, detail::DeviceImpl>>, | ||
| typename = detail::EnableIfDeviceSelectorIsInvocable<DeviceSelector>> | ||
| explicit device(const DeviceSelector &deviceSelector) | ||
| : device(detail::SelectDevice(deviceSelector)) {} | ||
|
|
||
| /// Returns the backend associated with this device. | ||
| /// | ||
| /// \return the backend associated with this device. | ||
| backend get_backend() const noexcept; | ||
|
|
||
| /// Check if device is a CPU device. | ||
| /// | ||
| /// \return true if SYCL device is a CPU device. | ||
| bool is_cpu() const; | ||
|
|
||
| /// Check if device is a GPU device. | ||
| /// | ||
| /// \return true if SYCL device is a GPU device. | ||
| bool is_gpu() const; | ||
|
|
||
| /// Check if device is an accelerator device. | ||
| /// | ||
| /// \return true if SYCL device is an accelerator device. | ||
| bool is_accelerator() const; | ||
|
|
||
| /// Get associated SYCL platform. | ||
| /// | ||
| /// \return The associated SYCL platform. | ||
| platform get_platform() const; | ||
|
|
||
| /// Queries this SYCL device for information requested by the template | ||
| /// parameter param. | ||
| /// | ||
| /// \return device info of type described in 4.6.4.4. | ||
| template <typename Param> | ||
| detail::is_device_info_desc_t<Param> get_info() const; | ||
|
|
||
| /// Queries this SYCL device for SYCL backend-specific information. | ||
| /// | ||
| /// The return type depends on information being queried. | ||
| template <typename Param> | ||
| typename detail::is_backend_info_desc<Param>::return_type | ||
| get_backend_info() const; | ||
|
|
||
| /// Queries which optional features this device supports (if any). | ||
| /// | ||
| /// \return true if this device has the given aspect. | ||
| bool has(aspect asp) const; | ||
|
|
||
| /// Partition device into sub devices. | ||
| /// | ||
| /// Available only when prop is info::partition_property::partition_equally. | ||
| /// If this SYCL device does not support | ||
| /// info::partition_property::partition_equally a feature_not_supported | ||
| /// exception will be thrown. | ||
| /// | ||
| /// \param ComputeUnits is a desired count of compute units in each sub | ||
| /// device. | ||
| /// \return sub devices partitioned from this SYCL device equally based on the | ||
| /// ComputeUnits parameter. | ||
| template <info::partition_property prop> | ||
| std::vector<device> create_sub_devices(size_t ComputeUnits) const; | ||
|
|
||
| /// Partition device into sub devices. | ||
| /// | ||
| /// Available only when prop is info::partition_property::partition_by_counts. | ||
| /// If this SYCL device does not support | ||
| /// info::partition_property::partition_by_counts a feature_not_supported | ||
| /// exception will be thrown. | ||
| /// | ||
| /// \param Counts is a std::vector of desired compute units in sub devices. | ||
| /// \return sub devices partitioned from this SYCL device by count sizes based | ||
| /// on the Counts parameter. | ||
| template <info::partition_property prop> | ||
| std::vector<device> | ||
| create_sub_devices(const std::vector<size_t> &Counts) const; | ||
|
|
||
| /// Partition device into sub devices. | ||
| /// | ||
| /// Available only when prop is | ||
| /// info::partition_property::partition_by_affinity_domain. If this SYCL | ||
| /// device does not support | ||
| /// info::partition_property::partition_by_affinity_domain or the SYCL device | ||
| /// does not support provided info::affinity_domain provided a | ||
| /// feature_not_supported exception will be thrown. | ||
| /// | ||
| /// \param AffinityDomain is one of the values described in Table 4.20 of the | ||
| /// SYCL 2020 specification. | ||
| /// \return sub devices partitioned from this SYCL device by affinity domain | ||
| /// based on the AffinityDomain parameter. | ||
| template <info::partition_property prop> | ||
| std::vector<device> | ||
| create_sub_devices(info::partition_affinity_domain AffinityDomain) const; | ||
|
|
||
| /// Query available SYCL devices. | ||
| /// | ||
| /// \param deviceType is one of the values described in A.3 of the SYCL 2020 | ||
| /// specification. | ||
| /// \return all SYCL devices available in the system of the device type | ||
| /// specified. | ||
| static std::vector<device> | ||
| get_devices(info::device_type deviceType = info::device_type::all); | ||
|
|
||
| private: | ||
| device(detail::DeviceImpl &Impl) : impl(&Impl) {} | ||
| detail::DeviceImpl *impl; | ||
|
|
||
| friend sycl::detail::ImplUtils; | ||
| }; // class device | ||
|
|
||
| _LIBSYCL_END_NAMESPACE_SYCL | ||
|
|
||
| template <> | ||
| struct std::hash<sycl::device> : public sycl::detail::HashBase<sycl::device> {}; | ||
|
|
||
| #endif // _LIBSYCL___IMPL_DEVICE_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.
Uh oh!
There was an error while loading. Please reload this page.