What Is SYCL? How C++ Kernels Run on Devices and Where Portability Ends
SYCL is a C++ API standard for writing heterogeneous programs in which host code and kernels for devices such as GPUs can live in one source program. A program submits work to a `queue` and describes the kernel's index range and data access. Using the standard API does not mean every compiler supports every device or that the same code runs unchanged at the same speed everywhere.
What Is SYCL? How C++ Kernels Run on Devices and Where Portability Ends
SYCL is a C++ API standard for writing heterogeneous programs in which host code and kernels for devices such as GPUs can live in one source program. A program submits work to a queue and describes the kernel's index range and data access. Using the standard API does not mean every compiler supports every device or that the same code runs unchanged at the same speed everywhere.
How does a SYCL program run on a device?
A SYCL program runs on the host, usually a CPU. The host selects a device and submits a command group to a sycl::queue, which connects the host program to one device. The command group declares the data needed and the kernel to invoke. Submission does not normally stop the host until device work finishes, so wait on an event or call wait_and_throw() when the result is needed and asynchronous errors must be reported.[^1][^2]
parallel_for(range, kernel) asks the implementation to run the kernel for every point in an index space. A one-dimensional range of 1,024 therefore describes 1,024 work-items, but the implementation and device determine how those items are scheduled. When a program needs explicit work-group layout, it can use nd_range and group synchronization features; the target device's limits and supported features still need to be checked.[^3]
This example increments each integer in an array. The default selector chooses a device, the queue submits the kernel, and the host array is used again after the buffer lifetime ends. This is an explanatory example; it was not compiled or run here. A real project must build with the chosen SYCL implementation's headers and options and handle exceptions.[^1][^2]
#include <sycl/sycl.hpp>
#include <array>
#include <cstddef>
#include <iostream>
int main() {
constexpr std::size_t n = 8;
std::array<int, n> values{1, 2, 3, 4, 5, 6, 7, 8};
{
sycl::queue q{sycl::default_selector_v};
sycl::buffer<int, 1> data(values.data(), sycl::range<1>{n});
q.submit([&](sycl::handler& h) {
sycl::accessor items{data, h, sycl::read_write};
h.parallel_for(sycl::range<1>{n}, [=](sycl::id<1> i) {
items[i] += 1;
});
});
q.wait_and_throw();
} // The host array can be used again after the buffer lifetime ends.
for (int value : values) std::cout << value << ' ';
}The expected output is 2 3 4 5 6 7 8 9. Each range index maps to one array element, and the accessor tells the runtime that the kernel reads and writes the buffer. A buffer constructed from a host pointer assumes exclusive access to that memory while it is alive, so host code must not read or modify the same array concurrently. See the SYCL buffer reference.[^4]
How do buffers/accessors and USM represent memory differently?
The choice is not just whether to use pointers. It determines how the program describes data use to the runtime and how much control the programmer takes over memory and movement.
| Model | Code representation | Advantage | What to check |
|---|---|---|---|
| Buffers and accessors | Wrap data in sycl::buffer; request read/write accessors in a command group | Access declarations make dependencies between kernels easier to express | Buffer lifetime, when data returns to the host, and host access while the buffer is alive |
| USM pointers | Allocate with routines such as malloc_device or malloc_shared and pass a pointer to the kernel | Fits pointer-oriented C++ code and gives direct control over allocation and copies | USM is optional; check support for each host, device, or shared allocation kind and keep the queue and allocation in the same context |
Unified Shared Memory (USM) is a pointer-based model over a unified address space. The word “shared” does not mean every device always uses the same physical memory. A consistent pointer value is different from actual access by the host or a particular device. For example, a device allocation cannot be dereferenced directly by the host and may require a copy. A USM pointer must also be used with the context in which it was allocated. Query required allocation support with an aspect such as device.has(sycl::aspect::usm_shared_allocations) before choosing that path.[^5]
Buffers and accessors are often a clear starting point when expressing dependencies between kernels matters. USM may fit better when integrating pointer-based code or when the application needs precise control over allocation and copies. Neither model guarantees the best performance; profile transfers and synchronization in the selected implementation.
What is portable, and what must be checked for each device?
The SYCL standard defines a common host/device execution model and API, while implementations provide it through compilers, runtimes, and device backends. An implementation is not required to use OpenCL. To decide whether code can move to another environment, check which compiler produces device code and which backend and driver run it; “uses SYCL” alone is not enough.[^1]
Device code cannot assume that every C++ feature available on the host is available on a device. The standard places limits on the device-language features implementations must support, and implementations further document their supported scope. Optional capabilities such as FP64, certain atomic operations, subgroup features, and USM kinds can differ by device. device.has() and get_info() can report aspects and device information, but the actual kernel must still be built and run with the target compiler and driver.[^2][^6]
Portability usually means that the same source and API can be rebuilt for another conforming implementation. It does not mean a prebuilt binary runs on every device, that features or floating-point results are identical, or that performance is equal. Work-group size, memory layout, and tile size may need to be measured again because device memory systems and execution widths differ.[^1][^3]
Five steps to choose a SYCL implementation and validate a kernel
Use this process when deciding which environment combinations to test for an existing C++ computation. The specification and API descriptions here follow SYCL 2020 revision 13 and the Khronos reference checked on 2026-11-23. Supported devices and options vary by implementation version, so also check its current documentation.[^1]
**Fix the supported combination.** Record the operating system, SYCL implementation and compiler version, runtime, backend, device model, and driver. Check the implementation's support matrix; do not mix unrelated implementation headers and runtimes in one build.
**Confirm the selected device.** Read and record the device name and whether it is a CPU or GPU through `queue.get_device()`. The default selector does not guarantee a GPU. Select the intended device explicitly when needed and confirm that it actually ran the work.
**Query required features.** Use `device.has()` for optional features such as FP64, USM allocation kinds, or subgroup capabilities. If a feature is missing, report a clear error or choose a supported fallback. A positive feature query does not prove every input or kernel will build, so compile the real code too.
**Verify data dependencies and results.** Check that buffer access modes or USM copy commands, queue order, and event dependencies match the data flow. Compare small, boundary, and representative inputs with a CPU reference and collect asynchronous errors.
**Tune per device after correctness passes.** Profile input/output transfers, synchronization, initialization, and kernel time separately. Compare work-group or tile settings on the same inputs and record the device, driver, and compiler combination. Do not copy a tuning choice from one device as another device's default.
SYCL's value is a common model and API for expressing heterogeneous C++ programs. Real usability depends on the implementation's backends, device features, memory model, driver, and device-specific measurements. Decide based on whether the chosen implementation supports the required devices and features and meets correctness and performance needs—not on the SYCL label alone.
References
[Khronos SYCL Registry](https://registry.khronos.org/SYCL/)
[SYCL 2020 Specification, revision 13](https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html)
[Khronos SYCL Reference: Queues](https://github.khronos.org/SYCL_Reference/iface/queue.html)
[Khronos SYCL Reference: Command group handler](https://github.khronos.org/SYCL_Reference/iface/command-group-handler.html)
[Khronos SYCL Reference: Buffers](https://github.khronos.org/SYCL_Reference/iface/buffer.html)
[Khronos SYCL Reference: USM basic concept](https://github.khronos.org/SYCL_Reference/iface/usm_basic_concept.html)
[Khronos SYCL Reference: Devices and aspects](https://github.khronos.org/SYCL_Reference/iface/device.html)
[Khronos SYCL Reference: Range classes](https://github.khronos.org/SYCL_Reference/iface/range.html)
[Khronos SYCL Reference: Device selectors](https://github.khronos.org/SYCL_Reference/iface/device-selector.html)
[^1]: SYCL 2020 Specification, revision 13: purpose, single-source model, platform/backend/execution model, and kernel-language restrictions.
[^2]: Khronos SYCL Reference: Queues and Command group handler: queue submission, completion, command groups, and kernel invocation.
[^3]: SYCL 2020 Specification and Range classes: index spaces and basic/ND-range kernel models.
[^4]: Khronos SYCL Reference: Buffers: host data, lifetime, and accessor use.
[^5]: Khronos SYCL Reference: USM basic concept: USM kinds, optional support, accessibility, and context rules.
[^6]: Khronos SYCL Reference: Devices and aspects: device information and optional-feature queries through has().
References
- Khronos SYCL Registry
- SYCL 2020 Specification Revision 13
- Khronos SYCL Reference: Queues
- Khronos SYCL Reference: Command group handler
- Khronos SYCL Reference: Buffers
- Khronos SYCL Reference: USM basic concept
- Khronos SYCL Reference: Devices and aspects
- Khronos SYCL Reference: Range classes
- Khronos SYCL Reference: Device selectors