Date post: | 10-Jun-2015 |
Category: |
Technology |
Upload: | the-khronos-group-inc |
View: | 295 times |
Download: | 0 times |
© Copyright Khronos Group 2014
SYCL™ for OpenCL™ in a Nutshell
Luke Iwanski, Games Technology Programmer @ Codeplay !SIGGRAPH Vancouver 2014
1
© Copyright Khronos Group 2014
2
© Copyright Khronos Group 2014
SYCL for OpenCL in a nutshell
• Why?
• Where in the OpenCL ecosystem?
• Motivation
• Features overview
• Example time
• Roadmap
3
© Copyright Khronos Group 2014
• Modern C++ programming model for OpenCL (compiler, runtime)
• Ease to use
• High performance
• Single source
• Allows multi-compiler implementation. SYCL device compiler + Host compiler of your choice
• Portability across platforms and compilers
• Providing the full OpenCL feature set and seamless integration with existing OpenCL code
• Enabling the creation of higher level programming models and C++ templated libraries based on OpenCL
Why SYCL?
4
© Copyright Khronos Group 2014
Device X Device Y Device Z
Alternative Language for
Kernels
SPIR Generator (e.g. Khronos patched Clang
open source on GitHUB)
Alternative Language for
Kernels
Alternative Language for
Kernels
High-level FrameworksHigh-level
FrameworksApps and Frameworks
!OpenCL Runtime
SPIR Standard Portable
Intermediate Representation SPIR 1.2 Released
January 2014
SYCL A programming abstraction that combines the portability and efficiency of OpenCL
with the ease of use and flexibility of C++ SYCL 1.2 Provisional Released
March 2014
OpenCL ecosystemOpenCL C Kernel
Source
5
© Copyright Khronos Group 2014
OpenCL
SYCL for OpenCL
C++ template libraries
User application code
The layering of SYCL: Building an ecosystem
6
© Copyright Khronos Group 2014
Motivation
• We want to enable C++ for the OpenCL ecosystem
• Where more C++ developers can get the benefits of OpenCL
• With C++ libraries supported on OpenCL platforms
• C++ tools supported on OpenCL platforms
• Aim to achieve long-term support for OpenCL features with C++
• Multiple Sources of implementations (multiple vendors)
• Reliability by providing host fall-back
• Enable future innovations7
© Copyright Khronos Group 2014
SYCL features: Overview
8
© Copyright Khronos Group 2014
• OpenCL/SYCL interoperability
• Seamless integration of OpenCL C applications with SYCL applications
• OpenCL C data types and built-in functions available
• SYCL / OpenGL interoperability
• Based on OpenCL/OpenGL interoperability extensions
• C++ exception handling
• Host “fall-back” mode - using SYCL without OpenCL
• Introduced in SYCL Hierarchical data parallelism9
© Copyright Khronos Group 2014
buffer<int> my_buffer(data, 10); auto in_access = my_buffer.get_access<cl::sycl::access:read>(); auto out_access = my_buffer.access<cl::sycl::access:write>(); !command_group(my_queue, [&]() { " parallel_for_workgroup(nd_range(range(size), range(groupsize)), " " lambda<class hierarchical>([=](group group) " { " " parallel_for_workitem(group, [=](item tile) " " { " " " out_access[tile] = in_access[tile] * 2; " " }); " })); });
Task (nD-range)
WorkgroupWork item
Work item
Work item
Work item
Work item
Work item
WorkgroupWork item
Work item
Work item
Work item
Work item
Work item
WorkgroupWork item
Work item
Work item
Work item
Work item
Work item
WorkgroupWork item
Work item
Work item
Work item
Work item
Work item
Hierarchical Data Parallelism
Advantages:!
1. Easy to understand the concept of work-groups!
2. Performance-portable between CPU and GPU!
3. Barriers are automatically deduced!!
4. Easier to compose components and algorithms 10
© Copyright Khronos Group 2014
Example time: Simple kernel
11
© Copyright Khronos Group 2014
12
© Copyright Khronos Group 2014
13
Simple kernel summary
• Simple kernel demo source is only 20 lines of actual C++/ SYCL code
• Equivalent of simple kernel demo in OpenCL takes over 100
lines of code
• This code can be easily templated by changing 17 lines of code
• Plain OpenCL C will take many, many, .. many more lines of
code
© Copyright Khronos Group 2014
Example time: Templated kernel
14
© Copyright Khronos Group 2014
15
© Copyright Khronos Group 2014
16
© Copyright Khronos Group 2014
17
© Copyright Khronos Group 2014
18
Templated kernel summary
• Only 52 lines of code to create a templated kernel for the
subtract operation!
• Templates on the device!
• factor of 5 lines per new datatype! (including initialisation and
printing)
• SYCL is simple!!
© Copyright Khronos Group 2014
19
Final notes about SYCL
• Keep in mind
• Advantages of modern C++ (lambdas, templates, struct
arguments, static polymorphism)
• but, limitations of current OpenCL ( recursion, dynamic
allocation, static variables)
• It will get better with the next OpenCL iterations! 19
© Copyright Khronos Group 2014
• GDC, March 2014
• Released a provisional specification to enable feedback
• Developers can provide input into the standardisation process
• Feedback via Khronos forums
• Next steps
• Full specification, based on feedback
• Khronos test suite for implementations
• Release of implementations
SYCL roadmap
20
© Copyright Khronos Group 2014
SYCL Useful Links
• SYCL spec and forums:
• http://www.khronos.org/opencl/sycl
• triSYCL github:
• https://github.com/amd/triSYCL
• Codeplay’s blogs:
• http://www.codeplay.com/portal/
• Examples github
• https://github.com/codeplaysoftware/Siggraph14.git21
© Copyright Khronos Group 2014
Luke Iwanski
@liwanski_
Thanks!
22