Skip to content

Latest commit

 

History

History
33 lines (29 loc) · 1.61 KB

File metadata and controls

33 lines (29 loc) · 1.61 KB

usm_hello_world

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:

  1. Check if cl_intel_unified_shared_memory extension is reported by a device.
  2. Check if all required USM capabilities are supported.
  3. Allocate memory using:
    1. clHostMemAllocINTEL;
    2. clDeviceMemAllocINTEL;
    3. clSharedMemAllocINTEL;
    4. malloc/new;
  4. Populate memory using for example:
    1. memcpy/std::copy/clEnqueueMemcpyINTEL;
    2. memset/std::fill/clEnqueueMemsetINTEL;
  5. Create kernel.
  6. Set memory as kernel argument using clSetKernelArgMemPointerINTEL.
  7. Run kernel.
  8. Read results using for example:
    1. memcpy/std::copy/clEnqueueMemcpyINTEL;
  9. Free memory using clMemFreeINTEL.

Usage

usm_hello_world host
usm_hello_world device
usm_hello_world shared
usm_hello_world host --size 1024