OpenCL SPIR BOF - SIGGRAPH 2014

20
© Copyright Khronos Group 2014 - Page SPIR 2.0 Provisional SIGGRAPH, Vancouver August 2014 1

description

SPIR slide presentation from the 2014 SIGGRAPH BOF

Transcript of OpenCL SPIR BOF - SIGGRAPH 2014

Page 1: OpenCL SPIR BOF - SIGGRAPH 2014

© Copyright Khronos Group 2014 - Page

SPIR 2.0 ProvisionalSIGGRAPH, Vancouver

August 2014

1

Page 2: OpenCL SPIR BOF - SIGGRAPH 2014

© Copyright Khronos Group 2014 - Page

Standard

Portable

Intermediate

Representation

Enables compiler ecosystem for

portable parallel programs

Goals 1. Portable interchange format for partially compiled OpenCL C

2. Target format for other languages

2

Page 3: OpenCL SPIR BOF - SIGGRAPH 2014

© Copyright Khronos Group 2014 - Page

OpenCL as Parallel Language Backend

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

Harlan High level language for GPU

programming

Compiler directives for

Fortran,C and C++

Java language extensions

for parallelism

PyOpenCL Python

wrapperaround OpenCL

Language for image

processing and computational photography

Embedded array language

for Haskell

3

Page 4: OpenCL SPIR BOF - SIGGRAPH 2014

© 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

Page 5: OpenCL SPIR BOF - SIGGRAPH 2014

© 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

Page 6: OpenCL SPIR BOF - SIGGRAPH 2014

© 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

Page 7: OpenCL SPIR BOF - SIGGRAPH 2014

© Copyright Khronos Group 2014 - Page

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

7

Page 8: OpenCL SPIR BOF - SIGGRAPH 2014

© 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

Page 9: OpenCL SPIR BOF - SIGGRAPH 2014

© 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

Page 10: OpenCL SPIR BOF - SIGGRAPH 2014

© Copyright Khronos Group 2014 - Page

Getting Started• IR Specification - Khronos SPIR registry - http://www.khronos.org/registry/spir/ !

• 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

Same open source license as mainline

LLVM and Clang

10

Page 11: OpenCL SPIR BOF - SIGGRAPH 2014

© Copyright Khronos Group 2014 - Page

More About Flows

11

Page 12: OpenCL SPIR BOF - SIGGRAPH 2014

© Copyright Khronos Group 2014 - Page

• ISV ships their kernel source - Exposes their IP

• Supports only OpenCL C

User application !!!!!

OpenCL: Source Compilation Flow

Vendor specific !!!!!

OpenCL C Kernel Source

OpenCL Host Library

12

Page 13: OpenCL SPIR BOF - SIGGRAPH 2014

© Copyright Khronos Group 2014 - Page

Platform specific container

OpenCL: Binary compilation flow

!!

• ISV ships vendor-specific binary - Proliferation: devices, driver revisions, vendors - Market-lagging: target shipped products

Vendor specific !!!!

OpenCL C Kernel Source

OpenCL Host Library

Vendor specific binary

Vendor specific !!!!

Vendor specific binary

OpenCL Host Library

13

Page 14: OpenCL SPIR BOF - SIGGRAPH 2014

© Copyright Khronos Group 2014 - Page

Platform specific container

OpenCL: SPIR flowISV ships kernels in SPIR form • User runs application on platform of their choice

Vendor specific !!!!

OpenCL C Kernel Source

OpenCL Host Library

Standard Portable

Intermediate

Vendor specific !!!!

OpenCL Host Library

Standard Portable

Intermediate

14

Page 15: OpenCL SPIR BOF - SIGGRAPH 2014

© Copyright Khronos Group 2014 - Page

SPIR Reference Flow

Standard Portable

Intermediate

Platform specific container

Vendor specific !!!!

OpenCL Runtime

SPIR Generator

Generation

Consumption

Device program source

Standard Portable

Intermediate

cl_khr_spir15

Page 16: OpenCL SPIR BOF - SIGGRAPH 2014

© Copyright Khronos Group 2014 - Page

SPIR Today

Standard Portable

Intermediate

Platform specific container

Vendor specific !!!!

OpenCL Runtime

SPIR Generator

Generation

Consumption

Device program source

Standard Portable

Intermediate

cl_khr_spir

OpenCL C Patched Clang

16

Page 17: OpenCL SPIR BOF - SIGGRAPH 2014

© Copyright Khronos Group 2014 - Page

Sample SPIR Consumption Flow

Standard Portable

Intermediate

clBuildProgram( “ -x spir -spir-std=2.0”….) !

Device specific binary

clCreateProgramWithBinary !

17

Page 18: OpenCL SPIR BOF - SIGGRAPH 2014

© Copyright Khronos Group 2014 - Page

clBuildProgram !!!!!!!!!!!!!!!!

!!!!!!!

cl_program !!!!!!!

Sample SPIR Flow: Room for OptimizationsStandard Portable

IntermediateSPIR Verifier

Standard LLVM optimizations

Custom optimizations E.g. vectorize

Materialization (Convert to device specific IR)

LLVM IR

Target IRABI fixup, custom optimizations

JITDevice

executable

18

Page 19: OpenCL SPIR BOF - SIGGRAPH 2014

© Copyright Khronos Group 2014 - Page

Resources• IR Specification - Khronos SPIR registry - http://www.khronos.org/registry/spir/ !

• 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

Page 20: OpenCL SPIR BOF - SIGGRAPH 2014

© Copyright Khronos Group 2014 - Page

Questions?

20