DPC++ Memory Management
The sections below shows different ways to manage memory when offloading computation to heterogeneous devices.
- Buffers and Accessors
- Unified Shared Memory (USM)
Buffers and Accessors are new concepts introduced in SYCL specification, it is powerful, handles data dependency elegantly and makes handling 1-2-3 dimentional data objects easy, but may make the code more verbose since it requires creating buffers for each data object and corresponding accessor need to be created to manage memory on device side.
Unified Shared Memory uses a more familiar pointer-based approach to manage memory in heterogeneous programming and may be more easy to get started coming from C++ programming background. Code is also easy to follow since host and device side use the same data objects. Easy when dealing with pointer data objects.
Below are basic examples using both the concepts of memory management, the next couple lessons explains each in more details.
Buffers and Accessors
SYCL specification introduces concepts of Buffers and Accessors to move, control and modify memory on device. Buffers encapsulate the data object that need to be managed on device and Accessors are used to request control of buffer objects to access or modify the memory.
Unified Shared Memory
USM is pointer-based approach to manage memory in DPC++ language.
Both offer the same memory management functionality for heterogeneous programming, use which ever is easy and fits your application.
More details about Buffers and Accessors and Unified Shared Memory are in the next 2 lessons.