C++ Single-Source Heterogeneous Programming for OpenCL
Khronos SYCL
Bekket McClane
@ Advanced Programming
Language, Jenq-Kuen Lee
2016 Spring, NTHU
Syllabus
❖ Heterogeneous Computing By OpenCL
❖ Introducing to SYCL
❖ SYCL Internals
❖ Programming Model
❖ Execution Model
❖ Memory Model
❖ Summary
OpenCL
Host Program
(C/C++, …)
OpenCL Kernel
(OpenCL C)
Dispatch
Propertied
Device Compiler
Accelerated
Devices
(GPU, DSP…)
SPIR-V
Compiler
Source
Propertied
SPIR-V Compiler
SPIR-V
OpenCL the Bad Part 1
OpenCL the Bad Part 1
Kernel Code
OpenCL the Bad Part 1
Kernel Code
Host Code
OpenCL the Bad Part 2
OpenCL the Bad Part 3
OPENCL
(CPU) FALLBACK IMPLEMENTATION?
OpenCL the Bad Part 3
OPENCL
(CPU) FALLBACK IMPLEMENTATION?
SYCL Start Up
SYCL Start Up
Single Source
SYCL Start Up
Single Source
Multiple Implementations
SYCL Programming Model
❖ All C++14 features. Except Runtime Type Information(RTTI)
❖ Exception Handling
❖ C++11 lambda
❖ C++11 variadic templates, template aliases
❖ C++11 rvalue reference
❖ C++11 std::function, std::string, std::vector
SYCL Data Parallel 101
SYCL Data Parallel With Workgroup
SYCL Execution Model
❖ Platforms
❖ Devices
❖ Command Queue
❖ Command Group
❖ Kernel
❖ Context
❖ Program
Terms
SYCL Execution Model
❖ Platforms
❖ Devices
❖ Command Queue
❖ Command Group
❖ Kernel
❖ Context
❖ Program
Terms
Same as OpenCL
SYCL Command Group
❖ Group of OpenCL commands
❖ Commands in group are executed in-order
❖ The smallest scheduling unit
❖ Different command groups may executed out-of-order
SYCL Command Group
SYCL Kernel
SYCL Kernel
SYCL Device-side Enqueue
❖ Has same behavior as that in OpenCL 2.x
❖ Sub-kernel has separated command queue
❖ Use out-of-order command queue like OpenCL

(No command group?)
❖ Use events to manage command orders
❖ No concrete examples so far
SYCL Memory Model
❖ Global, Constant, Local, Private just like OpenCL
❖ cl::sycl::accessor
❖ cl::sycl::buffer : Unified handle to many kinds of
memory
❖ Allow Shared Virtual Memory
❖ Allow atomic access
SYCL Local Variables
SYCL Local Variables
Powerful Accessor Template
• Read
• Write
• Read/Write Atomic Related*
SVM Related
SYCL Shared Virtual Memory
SYCL Shared Virtual Memory
SVM buffer allocation
SYCL Shared Virtual Memory
Host Access
SVM buffer allocation
SYCL Shared Virtual Memory
Host Access
SVM buffer allocation
Device Access
SYCL the Good Part - Memory
❖ Both cl::sycl::buffer and cl::sycl::accessor
encapsulate underlying memory into a “handle”
❖ The “handle” provides a flexible way to manipulate data
❖ Adoption of C++ template reserves spaces for features in
the future
Summary
triSYCL
❖ Use Boost library(http://www.boost.org) to simulate
❖ The only implementation(and header files) seen so far
❖ Latest SYCL 2.2!
❖ Need to be compiled with C++14 ! (-std=c++14)
https://github.com/amd/triSYCL
SYCL the Missing Part
❖ Where are the (official)header files?
❖ Little examples
❖ SYCL to SPIR-V compiler?
❖ Still a young project
SYCL in a Nutshell
❖ Single source. Neat syntax
❖ All the shiny C++ features
❖ Easy-implement fallbacks
❖ Follow the version(steps) of OpenCL
❖ No real devices(platforms) available for playing so far
❖ *NOT intended to replace OpenCL

(Still needs exist OpenCL drivers/implementations)
Thank You
Q & A

Introduction to Khronos SYCL

  • 1.
    C++ Single-Source HeterogeneousProgramming for OpenCL Khronos SYCL Bekket McClane @ Advanced Programming Language, Jenq-Kuen Lee 2016 Spring, NTHU
  • 2.
    Syllabus ❖ Heterogeneous ComputingBy OpenCL ❖ Introducing to SYCL ❖ SYCL Internals ❖ Programming Model ❖ Execution Model ❖ Memory Model ❖ Summary
  • 3.
    OpenCL Host Program (C/C++, …) OpenCLKernel (OpenCL C) Dispatch Propertied Device Compiler Accelerated Devices (GPU, DSP…) SPIR-V Compiler Source Propertied SPIR-V Compiler SPIR-V
  • 4.
  • 5.
    OpenCL the BadPart 1 Kernel Code
  • 6.
    OpenCL the BadPart 1 Kernel Code Host Code
  • 7.
  • 8.
    OpenCL the BadPart 3 OPENCL (CPU) FALLBACK IMPLEMENTATION?
  • 9.
    OpenCL the BadPart 3 OPENCL (CPU) FALLBACK IMPLEMENTATION?
  • 10.
  • 11.
  • 12.
    SYCL Start Up SingleSource Multiple Implementations
  • 13.
    SYCL Programming Model ❖All C++14 features. Except Runtime Type Information(RTTI) ❖ Exception Handling ❖ C++11 lambda ❖ C++11 variadic templates, template aliases ❖ C++11 rvalue reference ❖ C++11 std::function, std::string, std::vector
  • 14.
  • 15.
    SYCL Data ParallelWith Workgroup
  • 16.
    SYCL Execution Model ❖Platforms ❖ Devices ❖ Command Queue ❖ Command Group ❖ Kernel ❖ Context ❖ Program Terms
  • 17.
    SYCL Execution Model ❖Platforms ❖ Devices ❖ Command Queue ❖ Command Group ❖ Kernel ❖ Context ❖ Program Terms Same as OpenCL
  • 18.
    SYCL Command Group ❖Group of OpenCL commands ❖ Commands in group are executed in-order ❖ The smallest scheduling unit ❖ Different command groups may executed out-of-order
  • 19.
  • 20.
  • 21.
  • 22.
    SYCL Device-side Enqueue ❖Has same behavior as that in OpenCL 2.x ❖ Sub-kernel has separated command queue ❖ Use out-of-order command queue like OpenCL
 (No command group?) ❖ Use events to manage command orders ❖ No concrete examples so far
  • 23.
    SYCL Memory Model ❖Global, Constant, Local, Private just like OpenCL ❖ cl::sycl::accessor ❖ cl::sycl::buffer : Unified handle to many kinds of memory ❖ Allow Shared Virtual Memory ❖ Allow atomic access
  • 24.
  • 25.
  • 26.
    Powerful Accessor Template •Read • Write • Read/Write Atomic Related* SVM Related
  • 27.
  • 28.
    SYCL Shared VirtualMemory SVM buffer allocation
  • 29.
    SYCL Shared VirtualMemory Host Access SVM buffer allocation
  • 30.
    SYCL Shared VirtualMemory Host Access SVM buffer allocation Device Access
  • 31.
    SYCL the GoodPart - Memory ❖ Both cl::sycl::buffer and cl::sycl::accessor encapsulate underlying memory into a “handle” ❖ The “handle” provides a flexible way to manipulate data ❖ Adoption of C++ template reserves spaces for features in the future
  • 32.
  • 33.
    triSYCL ❖ Use Boostlibrary(http://www.boost.org) to simulate ❖ The only implementation(and header files) seen so far ❖ Latest SYCL 2.2! ❖ Need to be compiled with C++14 ! (-std=c++14) https://github.com/amd/triSYCL
  • 34.
    SYCL the MissingPart ❖ Where are the (official)header files? ❖ Little examples ❖ SYCL to SPIR-V compiler? ❖ Still a young project
  • 35.
    SYCL in aNutshell ❖ Single source. Neat syntax ❖ All the shiny C++ features ❖ Easy-implement fallbacks ❖ Follow the version(steps) of OpenCL ❖ No real devices(platforms) available for playing so far ❖ *NOT intended to replace OpenCL
 (Still needs exist OpenCL drivers/implementations)
  • 36.