Sample demonstrates how to use Unified Shared Memory to represent pointer-based data structure like Linked List.
Based on the fact that USM allocators return pointers you can use them in standard pointer operations like:
- assignment -
a = b
; - incrementation -
a++
; - decrementation -
a--
; - comparison -
a == b
; - indirection -
*a
; - member of pointer -
a->b
;
Please note that device
memory is not accessible on host, so you can't dereference it.
If a kernel uses a memory allocation indirectly i.e. memory is not passed as a kernel argument then it should be specified using clSetKernelExecInfo
. It can be done explicitly by passing all pointers as CL_KERNEL_EXEC_INFO_USM_PTRS_INTEL
or implicitly by setting CL_KERNEL_EXEC_INFO_INDIRECT_HOST/DEVICE/SHARED_ACCESS_INTEL
.
usm_linked_list host
usm_linked_list device
usm_linked_list shared
usm_linked_list host --size 1024