usmhelloworld
April 1, 2022 ยท View on GitHub
This sample shows basics of Unified Shared Memory. Application implements a simple copy buffer kernel and demonstrates essential operations related to the USM:
- Memory allocation
- Memory reads and writes
- Passing USM to OpenCL kernels
Source code is organized in a way to highlight similarities and differences between USM types: host, device and shared. To change used USM type just pass its name from a command line as an positional argument.
It is also possible to change allocation size simply by passing --size N option from a command line. N is a number of elements to allocate and each element has 4 bytes (cl_uint).
Basic structure of an application using USM is presented below:
- Check if
cl_intel_unified_shared_memoryextension is reported by a device. - Check if all required USM capabilities are supported.
- Allocate memory using:
clHostMemAllocINTEL;clDeviceMemAllocINTEL;clSharedMemAllocINTEL;malloc/new;
- Populate memory using for example:
memcpy/std::copy/clEnqueueMemcpyINTEL;memset/std::fill/clEnqueueMemsetINTEL;
- Create kernel.
- Set memory as kernel argument using
clSetKernelArgMemPointerINTEL. - Run kernel.
- Read results using for example:
memcpy/std::copy/clEnqueueMemcpyINTEL;
- Free memory using
clMemFreeINTEL.
Usage
usm_hello_world host
usm_hello_world device
usm_hello_world shared
usm_hello_world host --size 1024