Skip to content
Closed
27 changes: 22 additions & 5 deletions libsycl/docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
=====================
===========================
SYCL runtime implementation
=====================
===========================

.. contents::
:local:

.. _index:

Current Status
========
==============

The implementation is in the very early stages of upstreaming. The first milestone is to get
support for a simple SYCL application with device code using Unified Shared Memory:
Expand Down Expand Up @@ -54,7 +54,7 @@ This requires at least partial support of the following functionality on the lib
* Program manager, an internal component for retrieving and using device images from the multi-architectural binaries

Build steps
========
===========

To build LLVM with libsycl runtime enabled the following script can be used.

Expand All @@ -79,7 +79,24 @@ To build LLVM with libsycl runtime enabled the following script can be used.


Limitations
========
===========

SYCL runtime is not tested and is not guaranteed to work on Windows because offloading runtime (liboffload) used by SYCL runtime doesn't currently support Windows.
The limitation to be revised once liboffload will add support for Windows.

TODO for added SYCL classes
===========================

* ``exception``: methods with context are not implemented, to add once context is ready
* ``platform``: deprecated info descriptor is not implemented (info::platform::extensions), to implement on RT level with ``device::get_info<info::device::aspects>()``
* ``device``:

* ``get_info``: to find an efficient way to map descriptors to liboffload types, add other descriptors, add cache of info data
* ``has(aspect)``: same as get_info
* ``create_sub_devices``: partitioning is not supported by liboffload now, blocked
* ``has_extension``: deprecated API, to implement on RT level with ``device::has``

* device selection: to add compatibility with old SYCL 1.2.1 device selectors, still part of SYCL 2020 specification



43 changes: 43 additions & 0 deletions libsycl/include/sycl/__impl/aspect.hpp
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

// 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
158 changes: 158 additions & 0 deletions libsycl/include/sycl/__impl/device.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
//===----------------------------------------------------------------------===//
//
// 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 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_base.hpp>

_LIBSYCL_BEGIN_NAMESPACE_SYCL

class platform;

namespace detail {
class device_impl;
} // namespace detail

// 4.6.4. Device class
class _LIBSYCL_EXPORT device
: public detail::ObjBase<detail::device_impl *, device> {
public:
/// Constructs a SYCL device instance using the default device.
device();

/// Constructs a SYCL device instance using the device
/// identified by the device selector provided.
/// \param DeviceSelector is SYCL 2020 Device Selector, a simple callable that
/// takes a device and returns an int
template <
typename DeviceSelector,
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. Information descriptors.
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 must be thrown.
///
/// \param ComputeUnits is a desired count of compute units in each sub
/// device.
/// \return A vector class of 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 must be thrown.
///
/// \param Counts is a std::vector of desired compute units in sub devices.
/// \return a std::vector of 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 info::affinity_domain provided a feature_not_supported
/// exception must be thrown.
///
/// \param AffinityDomain is one of the values described in Table 4.20 of SYCL
/// Spec
/// \return a vector class of 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 SYCL Spec
/// \return a std::vector containing 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::device_impl *Impl) : ObjBase(Impl) {}
friend detail::ObjBase<detail::device_impl *, device>;
};

_LIBSYCL_END_NAMESPACE_SYCL

template <>
struct std::hash<sycl::device>
: public sycl::detail::HashBase<sycl::device> {};

#endif // _LIBSYCL___IMPL_DEVICE_HPP
69 changes: 69 additions & 0 deletions libsycl/include/sycl/__impl/device_selector.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//===----------------------------------------------------------------------===//
//
// 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 standard device selectors
/// (4.6.1.1. Device selector) included with all SYCL implementations.
///
//===----------------------------------------------------------------------===//

#ifndef _LIBSYCL___IMPL_DEVICE_SELECTOR_HPP
#define _LIBSYCL___IMPL_DEVICE_SELECTOR_HPP

#include <sycl/__impl/aspect.hpp>
#include <sycl/__impl/detail/config.hpp>

#include <functional>

_LIBSYCL_BEGIN_NAMESPACE_SYCL

class device;
class context;

namespace detail {

// 4.6.1.1. Device selector:
// The interface for a device selector is any object that meets the C++ named
// requirement Callable, taking a parameter of type const device & and returning
// a value that is implicitly convertible to int.
using DeviceSelectorInvocableType = std::function<int(const sycl::device &)>;

template <typename DeviceSelector>
using EnableIfDeviceSelectorIsInvocable = std::enable_if_t<
std::is_invocable_r_v<int, DeviceSelector &, const device &>>;

_LIBSYCL_EXPORT device
SelectDevice(const DeviceSelectorInvocableType &DeviceSelector);

} // namespace detail

_LIBSYCL_EXPORT int default_selector_v(const device &dev);
_LIBSYCL_EXPORT int gpu_selector_v(const device &dev);
_LIBSYCL_EXPORT int cpu_selector_v(const device &dev);
_LIBSYCL_EXPORT int accelerator_selector_v(const device &dev);
_LIBSYCL_EXPORT detail::DeviceSelectorInvocableType
aspect_selector(const std::vector<aspect> &RequireList,
const std::vector<aspect> &DenyList = {});

template <typename... AspectListT>
detail::DeviceSelectorInvocableType aspect_selector(AspectListT... AspectList) {
std::vector<aspect> RequireList;
RequireList.reserve(sizeof...(AspectList));
(RequireList.emplace_back(AspectList), ...);

return aspect_selector(RequireList, {});
}

template <aspect... AspectList>
detail::DeviceSelectorInvocableType aspect_selector() {
return aspect_selector({AspectList...}, {});
}

_LIBSYCL_END_NAMESPACE_SYCL

#endif //_LIBSYCL___IMPL_DEVICE_SELECTOR_HPP
Loading