blob: e56b5076d46f953f57e540c4e829b5e24616c896 [file] [view] [edit]
# SYCL runtime implementation
:::{contents}
:local: true
:::
(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:
```c++
#include <sycl/sycl.hpp>
class TestKernel;
int main() {
sycl::queue q;
const size_t dataSize = 32;
int *dataPtr = sycl::malloc_shared<int>(32, q);
for (int i = 0; i < dataSize; ++i)
dataPtr[i] = 0;
q.submit([&](sycl::handler &cgh) {
cgh.parallel_for<TestKernel>(
sycl::range<1>(dataSize),
[=](sycl::id<1> idx) { dataPtr[idx] = idx[0]; });
});
q.wait();
bool error = false;
for (int i = 0; i < dataSize; ++i)
if (dataPtr[i] != i) error = true;
free(dataPtr, q);
return error;
}
```
This requires at least partial support of the following functionality on the
libsycl side:
- `sycl::platform` class
- `sycl::device` class
- `sycl::context` class
- `sycl::queue` class
- `sycl::handler` class
- `sycl::id` and `sycl::range` classes
- Unified shared memory allocation/deallocation
- 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.
```console
#!/bin/sh
build_llvm=`pwd`/build-llvm
installprefix=`pwd`/install
llvm=`pwd`
mkdir -p $build_llvm
mkdir -p $installprefix
cmake -G Ninja -S $llvm/llvm -B $build_llvm \
-DLLVM_ENABLE_PROJECTS="clang" \
-DLLVM_INSTALL_UTILS=ON \
-DCMAKE_INSTALL_PREFIX=$installprefix \
-DLLVM_ENABLE_RUNTIMES="offload;openmp;libsycl" \
-DCMAKE_BUILD_TYPE=Release \
# must be default and configured in liboffload,
# requires level zero, see offload/cmake/Modules/LibomptargetGetDependencies.cmake
-DLIBOMPTARGET_PLUGINS_TO_BUILD=level_zero
ninja -C $build_llvm install
```
## Limitations
Libsycl is not currently supported on Windows because it depends on liboffload
which doesn't currently support Windows.
## TODO for added SYCL classes
- `exception`: methods with context are not implemented, to add once context is ready
- `backend`: CUDA and HIP backends are not supported, to add together with the corresponding backend extensions; devices of these liboffload backends are ignored
- `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`:
- Add caching
- Change double and half widths to return 0 if the corresponding aspect is absent.
- Implement missing descriptors:
- max_num_sub_groups
- sub_group_sizes
- preferred_vector_width_long_long
- native_vector_width_long_long
- image_support
- max_read_image_args
- max_write_image_args
- image2d_max_width
- image2d_max_height
- image3d_max_width
- image3d_max_height
- image3d_max_depth
- image_max_buffer_size
- max_samplers
- max_parameter_size
- mem_base_addr_align
- global_mem_cache_type
- global_mem_cache_line_size
- global_mem_cache_size
- max_constant_buffer_size
- max_constant_args
- local_mem_type
- error_correction_support
- host_unified_memory
- atomic_memory_order_capabilities
- atomic_fence_order_capabilities
- atomic_memory_scope_capabilities
- atomic_fence_scope_capabilities
- profiling_timer_resolution
- is_endian_little
- is_available
- is_compiler_available
- is_linker_available
- execution_capabilities
- queue_profiling
- built_in_kernel_ids
- built_in_kernels
- profile
- version
- backend_version
- aspects
- extensions
- printf_buffer_size
- preferred_interop_user_sync
- parent_device
- partition_max_sub_devices
- partition_properties
- partition_affinity_domains
- partition_type_property
- partition_type_affinity_domain
- `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
- `context`: to implement get_info, properties once context support is added to liboffload
- `queue`:
- to implement USM methods
- to implement synchronization methods
- to implement submit & copy with accessors (low priority)
- get_info
- properties:
- every queue is in-order: liboffload creates in-order queues only, so the
`in_order` property does not change how a queue behaves and
`is_in_order()` reports whether the property was passed, not the actual
behavior of the queue. To revisit once liboffload supports out-of-order
queues
- `enable_profiling` is accepted only to be rejected with
`errc::feature_not_supported`: the queue does not capture profiling
information and `event::get_profiling_info` cannot report it, to
implement once liboffload supports profiling
- ctors that accepts context (blocked by lack of liboffload support)
- nd_range kernel submissions: offset is not supported by liboffload now, SYCL2020 deprecated feature
- cross-context events wait (host tasks are needed)
- implement check if lambda arguments are device copyable (requires clang support of corresponding builtins) unless FE will fully cover it
- kernel instantiating on host (debugging purposes)
- `property_list`: to fully implement and integrate with existing SYCL runtime classes supporting it
- usm allocations:
- handle sub devices once they are implemented (blocked by liboffload support)
- `event`:
- get_info, get_profiling_info (no liboffload support) are not implemented
- get_wait_list should be aligned with the results of this discussion: <https://github.com/KhronosGroup/SYCL-Docs/issues/1017>
- `range`, `id` - `__SYCL_DISABLE_ID_TO_INT_CONV__` and `__SYCL_ASSUME_ID_RANGE` optimizations are not implemented
- general opens:
- define a way to report errors from object dtors
- unittests: add functions to reset libsycl internal state completely (static variables)