Successfully reported this slideshow.

OpenCL SPIR BOF - SIGGRAPH 2014

753 views

Published on

SPIR slide presentation from the 2014 SIGGRAPH BOF

Published in: Technology
  • Be the first to comment

OpenCL SPIR BOF - SIGGRAPH 2014

  1. 1. SPIR 2.0 Provisional © Copyright Khronos Group 2014 - Page SIGGRAPH, Vancouver August 2014 1
  2. 2. Standard Portable Intermediate Representation Enables compiler ecosystem for portable parallel programs © Copyright Khronos Group 2014 - Page Goals 1. Portable interchange format for partially compiled OpenCL C 2. Target format for other languages 2
  3. 3. OpenCL as Parallel Language Backend Harlan High level language for GPU programming Compiler directives for Fortran, C and C++ © Copyright Khronos Group 2014 - Page JavaScript binding for initiation of OpenCL C kernels River Trail Language extensions to JavaScript MulticoreWare open source project on Bitbucket OpenCL provides vendor optimized, cross-platform, cross-vendor access to heterogeneous compute resources Java language extensions for parallelism PyOpenCL Python wrapper around OpenCL Language for image processing and computational photography Embedded array language for Haskell 3
  4. 4. © Copyright Khronos Group 2014 - Page Builds on LLVM and OpenCL ! ! ! ! ! ! ! ! ! • Optimizing compiler toolkit • Portable, flexible, well understood • Open source platform for innovation ! ! ! ! ! ! ! ! ! • Proven platform for heterogeneous parallel programming • Multi-vendor: CPU, GPU, FPGA etc. 4
  5. 5. © Copyright Khronos Group 2014 - Page Why use SPIR? • Without SPIR: • Vendors shipping source - Risk IP leakage • Vendors shipping multiple binaries - Complexity - Miss optimizations in new compilers - Forward compatibility issues • With SPIR: • Ship a single binary per platform - E.g. SPIR file can support Intel & AMD • Many vendors support SPIR consumption • Shipped application can retarget new devices and new vendors Opportunity to unleash innovation: Domain Specific Languages, C++ Compilers, Halide, …. 5
  6. 6. © Copyright Khronos Group 2014 - Page What’s new in SPIR 2.0? • Full support of OpenCL 2.0 “C” kernel language - Generic address space - Device side kernel enqueue - C++11 atomics - Pipes - More… • LLVM 3.4 with restrictions and conventions If you can do it in OpenCL C You can do it in SPIR 6
  7. 7. SPIR ecosystem is… • IR definition - Portable non-source encoding for OpenCL 1.2 or 2.0 device programs - SPIR 1.2 is based on LLVM 3.2 - SPIR 2.0 is based on LLVM 3.4 • Consumption API for target hardware - cl_khr_spir extension to OpenCL runtime API • Example generator - Open source patch to Clang translates OpenCL C to SPIR IR - Available in github: https://github.com/KhronosGroup/SPIR • Ease of use tools - SPIR Verifier, SPIR built-ins name mangler - Available in github: https://github.com/KhronosGroup/SPIR-Tools © Copyright Khronos Group 2014 - Page 7
  8. 8. © Copyright Khronos Group 2014 - Page Longevity and Versioning • SPIR to track both LLVM and OpenCL versions - SPIR 1.2 ! LLVM 3.2 + OpenCL 1.2 - SPIR 2.0 ! LLVM 3.4 + OpenCL 2.0 ! • SPIR consumer tells you what versions can be loaded ! • Khronos members contributing to mainline LLVM+Clang - Backward compatibility fixes and tests - Full SPIR support in Clang - Ease of use tools 8
  9. 9. © Copyright Khronos Group 2014 - Page Call to Action • Seeking feedback on SPIR 2.0 provisional - A Provisional specification - http://www.khronos.org/registry/spir/ - https://www.khronos.org/opencl/spir2_0_feedback_forum ! • Innovate on the Front end - New languages, abstractions - Target production quality backends ! • Innovate on the Back end - New target platforms: Multi core, Vector, VLIW… - Reuse production quality frontends ! • Innovate on Tooling - Program analysis, optimization 9
  10. 10. Getting Started • IR Specification - Khronos SPIR registry - http://www.khronos.org/registry/spir/ Same open source license as mainline LLVM and Clang © Copyright Khronos Group 2014 - Page ! • Front end - Khronos-patched Clang from Github ! • Verifier - LLVM pass checks SPIR validity - Khronos Github ! • Backend - Check your favorite OpenCL implementation for cl_khr_spir 10
  11. 11. © Copyright Khronos Group 2014 - Page More About Flows 11
  12. 12. © Copyright Khronos Group 2014 - Page OpenCL: Source Compilation Flow • ISV ships their kernel source - Exposes their IP • Supports only OpenCL C User application !!!!! Vendor specific !!!!! OpenCL C Kernel Source OpenCL Host Library 12
  13. 13. © Copyright Khronos Group 2014 - Page OpenCL: Binary compilation flow OpenCL C Kernel Source Platform specific container Vendor specific !!!! ! ! • ISV ships vendor-specific binary OpenCL Host Library - Proliferation: devices, driver revisions, vendors - Market-lagging: target shipped products Vendor specific binary Vendor specific !!!! Vendor specific binary OpenCL Host Library 13
  14. 14. © Copyright Khronos Group 2014 - Page OpenCL: SPIR flow ISV ships kernels in SPIR form • User runs application on platform of their choice Platform specific container Vendor specific !!!! OpenCL C Kernel Source OpenCL Host Library Standard Portable Intermediate Vendor specific !!!! OpenCL Host Library Standard Portable Intermediate 14
  15. 15. © Copyright Khronos Group 2014 - Page SPIR Reference Flow Standard Portable Intermediate Platform specific container SPIR Generator Vendor specific !!!! OpenCL Runtime Generation Device program source Consumption Standard Portable Intermediate cl_khr_spir 15
  16. 16. © Copyright Khronos Group 2014 - Page SPIR Today Standard Portable Intermediate Platform specific container OpenCL C Patched Clang SPIR Generator Vendor specific !!!! OpenCL Runtime Generation Device program source Consumption Standard Portable Intermediate cl_khr_spir 16
  17. 17. © Copyright Khronos Group 2014 - Page Sample SPIR Consumption Flow Standard Portable Intermediate clBuildProgram( “ -x spir -spir-std=2.0”….) ! Device specific binary clCreateProgramWithBinary ! 17
  18. 18. Sample SPIR Flow: Room for Optimizations © Copyright Khronos Group 2014 - Page clBuildProgram !!!!!!!!!!!!!!!! !!!!!!! cl_program !!!!!!! Standard Portable Intermediate SPIR Verifier Standard LLVM optimizations Custom optimizations E.g. vectorize Materialization (Convert to device specific IR) LLVM IR ABI fixup, Target IR custom optimizations JIT Device executable 18
  19. 19. Resources • IR Specification - Khronos SPIR registry - http://www.khronos.org/registry/spir/ © Copyright Khronos Group 2014 - Page ! • Feedback Forum Thread - https://www.khronos.org/opencl/spir2_0_feedback_forum ! • Khronos-patch Clang and Tools - https://github.com/KhronosGroup/SPIR - https://github.com/KhronosGroup/SPIR-Tools ! • Backend - Check your favorite OpenCL implementation for cl_khr_spir 19
  20. 20. © Copyright Khronos Group 2014 - Page Questions? 20

×