Sycl provides a way to have more granular or fine access to the hardware as sometimes you might need to specialize a kernel for a specific hardware. There are many methods that the user can use to find perfect solution for their hardware.
Types of kernel code.
- Generic: runs anywhere
- Device_Types: run on a device and tuned to specific model.
- Tuned Device Type Kernel: tuned from very small amount to detailed optimizations.
Better to write separate kernels if we are using different algos rather than parameterizing.
- Finding Device Name
sycl::queue m_queue{sycl::cpu_selector_v};
std::println("{}", m_queue.get_device().get_info<sycl::info::device::name>());
sycl::queue m_queue2{sycl::gpu_selector_v};
std::println("{}", m_queue2.get_device().get_info<sycl::info::device::name>());
Setting gpu or cpu doesn’t guarantee that it will run on that specific device. What if gpu isn’t present what if there are multiple gpus.
Aspects
Sycl aspectsare a list of capabilities of a device? like a device has them or doesn’t have them it’s sort of a boolean.
Examples
aspect::cpu aspect::gpu aspect::custom aspect::accelerator aspect::emulated
And more depending on the device.
get_info<>
for (auto const& this_platform: sycl::platform::get_platforms()) {
std::println("{}", this_platform.get_info<sycl::info::platform::name>());
for (auto const& device: this_platform.get_devices()) {
std::println("{}", device.get_info<sycl::info::device::name>());
}
Device Specific kernel info descriptors
Conditions and Informations (Correctness vs useful for tuning can be incorrect)
For Correctness
Device Queries
- max_work_item_sizes
- max_work_group_size
- global_mem_size
- local_mem_size
- max_compute_units
- sub_group_sizes
Kernel Queries
- work_group_size
- compile_work_group_size
- compile_sub_group_size
- compile_num_sub_groups
- max_sub_group_size
- max_num_sub_groups
For Tuning/optimizations
Device Queries For Tuning
- global_mem_cache_line_size
- global_mem_cache_size
- local_mem_type local(SRAM ) vs global(abstraction)
Kernel Queries For Tuning
- preferred_work_group_size
- preferred_work_group_size_multiple
for best performance work group size shouldn’t be greater than this.
Runtime VS Compile-Time Properties
most of the things discussed are runtime attributes there can be compile time attributes we can specialize kernel by writing different for different devices.
Attributes
- device_has(aspect, …)
- reqd_work_group_size(dim0) -> must
- reqd_work_group_size(dim0, dim1)
- reqd_work_group_size(dim0, dim1, dim2)
- work_group_size_hint(dim0) -> hint compiler
- reqd_sub_group_size(dim0)
Example of Attributes
if (m_queue.get_device().has(sycl::aspect::fp64)) {
// kernel 1 impl
} else {
// different impl
}