OpenCL SPIR BOF - SIGGRAPH 2014

Post on 25-Dec-2014

227 views 2 download

description

SPIR slide presentation from the 2014 SIGGRAPH BOF

Transcript of OpenCL SPIR BOF - SIGGRAPH 2014

© Copyright Khronos Group 2014 - Page

SPIR 2.0 ProvisionalSIGGRAPH, Vancouver

August 2014

1

© 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

© 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

© 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

© 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

© 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

© 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

© 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

© 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

© 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

© Copyright Khronos Group 2014 - Page

More About Flows

11

© 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

© 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

© 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

© 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

© 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

© Copyright Khronos Group 2014 - Page

Sample SPIR Consumption Flow

Standard Portable

Intermediate

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

Device specific binary

clCreateProgramWithBinary !

17

© 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

© 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

© Copyright Khronos Group 2014 - Page

Questions?

20