## What is SYCL?
## Learning Objectives * Learn about the SYCL specification and its implementations * Learn about the components of a SYCL implementation * Learn about how a SYCL source file is compiled * Learn where to find useful resources for SYCL
#### What is SYCL?
![SYCL](../common-revealjs/images/sycl_and_cpp.png "SYCL")
SYCL is a single source, high-level, standard C++ programming model, that can target a range of heterogeneous platforms
#### What is SYCL?
A first example of SYCL code. Elements will be explained in coming sections!
![SYCL](../common-revealjs/images/sycl_first_sample_code.png "SYCL")
## SYCL is... * SYCL extends C++ in two key ways: * device discovery (and information) * device control (kernels of work, memory) * SYCL is modern C++ * SYCL is open, multivendor, multiarchitecture
#### What is SYCL?
SYCL is a ***single source***, high-level, standard C++ programming model, that can target a range of heterogeneous platforms
![SYCL](../common-revealjs/images/sycl.png "SYCL")
* SYCL allows you to write both host CPU and device code in the same C++ source file * This requires two compilation passes; one for the host code and one for the device code
#### What is SYCL?
SYCL is a single source, ***high-level***, standard C++ programming model, that can target a range of heterogeneous platforms
* SYCL provides high-level abstractions over common boilerplate code * Platform/device selection * Buffer creation and data movement * Kernel function compilation * Dependency management and scheduling
#### What is SYCL?
SYCL is a single source, high-level ***standard C++*** programming model, that can target a range of heterogeneous platforms
![SYCL](../common-revealjs/images/code_comparison.png "SYCL-Comparison")
* SYCL allows you to write standard C++ * SYCL 2020 is based on C++17 * Unlike the other implementations shown on the left there are: * No language extensions * No pragmas * No attributes
#### What is SYCL?
SYCL is a single source, high-level standard C++ programming model, that can **target a range of heterogeneous platforms**
![SYCL](../common-revealjs/images/sycl_targets.png "SYCL-Targets")
* SYCL can target any device supported by its backend * SYCL can target a number of different backends SYCL has been designed to be implemented on top of a variety of backends. Current implementations support backends such as OpenCL, CUDA, HIP, OpenMP and others.
#### SYCL specification
#### SYCL implementations
SYCL-Implementations
#### What a SYCL implementation looks like
![SYCL Interface](../common-revealjs/images/sycl_implementation_interface.svg "SYCL-Interface")
* The SYCL interface is a C++ template library that developers can use to access the features of SYCL * The same interface is used for both the host and device code
* The host is generally the CPU and is used to dispatch the parallel execution of kernels * The device is the parallel unit used to execute the kernels, such as a GPU
#### What a SYCL implementation looks like
![SYCL Runtime](../common-revealjs/images/sycl_implementation_runtime.svg "SYCL-Runtime")
* The SYCL runtime is a library that schedules and executes work * It loads kernels, tracks data dependencies and schedules commands
#### What a SYCL implementation looks like
![SYCL CPU Device](../common-revealjs/images/sycl_implementation_cpu.svg "SYCL-CPU-Device")
* There is no Host Device in SYCL (as of SYCL 2020) * SYCL 1.2.1 had a concept of a 'magical' host device - an emulated backend * SYCL 2020 implementations generally offer a CPU device * Often, the best debugging on a platform is using a CPU device * Yet, debugging off the CPU is important to discover offloading issues
#### What a SYCL implementation looks like
![SYCL Backend](../common-revealjs/images/sycl_implementation_backend.svg "SYCL-Backend")
* The back-end interface is where the SYCL runtime calls down into a back-end in order to execute on a particular device * Many implementations provide OpenCL backends, but some provide additional or different backends.
#### What a SYCL implementation looks like
![SYCL Compiler](../common-revealjs/images/sycl_implementation_compiler.svg "SYCL-Compiler")
* The SYCL device compiler is a C++ compiler which can identify SYCL kernels and compile them down to an IR or ISA * This can be SPIR, SPIR-V, GCN, PTX or any proprietary vendor ISA * Some SYCL implementations are library only in which case they do not require a device compiler
**IR** = Intermediate Representation **ISA** = Instruction Set Architecture
#### Std C++ compilation model
![SYCL Backend](../common-revealjs/images/compilation_1.png "SYCL")
* This is the typical compilation model for a C++ source file.
#### Std C++ compilation model
![SYCL Backend](../common-revealjs/images/compilation_2.png "SYCL")
* So how do you compile a source file to also target the GPU?
#### Std C++ compilation model
![SYCL Backend](../common-revealjs/images/compilation_3.png "SYCL")
* As SYCL is single source the kernel functions are standard C++ function objects or lambda expressions. * These are defined by submitting them to specific APIs.
#### Std C++ compilation model
![SYCL Backend](../common-revealjs/images/compilation_4.png "SYCL")
* As well as the standard C++ compiler, the source file is also compiled by a SYCL device compiler. * This produces a device IR such as SPIR, SPIR-V or PTX or ISA for a specific architecture containing the GPU code.
#### Std C++ compilation model
![SYCL Backend](../common-revealjs/images/compilation_5.png "SYCL")
* The CPU object is then linked with the device IR or ISA to form a single executable with both the CPU and GPU code.
#### Std C++ compilation model
![SYCL Backend](../common-revealjs/images/compilation_5.png "SYCL")
* This is the multi-compiler compilation model. * This allows the host compiler (MSVC, clang, icx, gcc) to be independent of the SYCL device compiler.
#### Std C++ compilation model
![SYCL Backend](../common-revealjs/images/compilation_6.png "SYCL")
* SYCL also supports a single-compiler compilation model. * Where both the host compiler and SYCL device compiler are invoked from the same driver.
## Where to Get Started with SYCL * Visit https://sycl.tech to find out about all the SYCL book, implementations, tutorials, news, and videos * Visit https://www.khronos.org/sycl/ to find the latest SYCL specifications * Checkout the documentation provided with one of the SYCL implementations.
## Questions
#### Exercise
Code_Exercises/What_is_SYCL/source
Configure your environment for using SYCL and compile a source file with the SYCL compiler.