> ## Documentation Index
> Fetch the complete documentation index at: https://sdk.cerebras.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# SDK Code Examples

> Tutorials and benchmarks from the Cerebras SDK examples repository.

Example CSL programs, including tutorials and benchmarks that demonstrate
individual language features and larger application kernels, live in the
[SDK examples GitHub repository](https://github.com/Cerebras/sdk-examples).

<Note>
  For step-by-step introductory tutorials that walk through the GEMV programs
  below, see [Tutorials](/csl/tutorials).
</Note>

## GEMV tutorial series

A progression of general matrix-vector product (GEMV) programs that introduce
CSL features one at a time.

### gemv-00-basic-syntax

First in a series; covers preliminaries of CSL syntax.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/gemv-00-basic-syntax)

### gemv-01-complete-program

A complete, runnable CSL program on a single PE.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/gemv-01-complete-program)

### gemv-02-memory-dsds

Use memory data structure descriptors (DSDs) for efficient tensor operations.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/gemv-02-memory-dsds)

### gemv-03-memcpy

Copy tensors between host and device with the `memcpy` functionality of
`SdkRuntime`.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/gemv-03-memcpy)

### gemv-04-params

Use compile-time parameters to specialize a program.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/gemv-04-params)

### gemv-05-multiple-pes

Extend the program to run on multiple PEs.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/gemv-05-multiple-pes)

### gemv-06-routes-1

Use routes and colors to distribute a single GEMV across multiple PEs.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/gemv-06-routes-1)

### gemv-07-routes-2

More advanced routing across multiple PEs.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/gemv-07-routes-2)

### gemv-08-routes-3

Further extend the GEMV computation across a 2D grid.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/gemv-08-routes-3)

### gemv-09-streaming

Alternative streaming version of the previous example.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/gemv-09-streaming)

## Topic tutorials

Focused examples illustrating specific language or library features.

### topic-01-arrays-and-pointers

Pass and return arrays in compile-time functions.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-01-arrays-and-pointers)

### topic-02-libraries

Use libraries bundled with the CSL compiler.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-02-libraries)

### topic-03-streaming-wavelet-data

Tasks activated in response to incoming wavelets.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-03-streaming-wavelet-data)

### topic-04-sparse-tensors

Efficiently stream only non-zero entries of sparse tensors.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-04-sparse-tensors)

### topic-05-sentinels

Use sentinels with routable colors.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-05-sentinels)

### topic-06-switches

Fabric switches for limited runtime control of routes.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-06-switches)

### topic-07-switches-entrypt

Encode a special entry point with fabric switches.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-07-switches-entrypt)

### topic-08-filters

Fabric filters that let a PE selectively accept incoming wavelets.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-08-filters)

### topic-09-fifos

Buffer PE input/output with a FIFO DSD.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-09-fifos)

### topic-10-map-builtin

The `@map` builtin for custom operations on data.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-10-map-builtin)

### topic-11-collectives

Inter-PE communication with the `<collectives_2d>` library.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-11-collectives)

### topic-12-debug-library

Tracing via the `<debug>` library.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-12-debug-library)

### topic-13-simprint

Print values directly from the simulator.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-13-simprint)

### topic-14-color-swap

Color swap feature on WSE-2.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-14-color-swap)

### topic-15-wse3-microthreads

Explicit microthread IDs on WSE-3.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-15-wse3-microthreads)

### topic-16-queue-flush

Flushing output queues on WSE-3 when multiple colors share a queue.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-16-queue-flush)

## Pipeline tutorials

Examples that build on wavelet-triggered tasks to process streaming data.

### pipeline-01-basic

Process one wavelet at a time with wavelet-triggered tasks.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/pipeline-01-basic)

### pipeline-02-fifo

Use a FIFO to avoid stalls on large inputs.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/pipeline-02-fifo)

### pipeline-03-multiple

Reduce FIFO resource consumption with multiple pipelines.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/pipeline-03-multiple)

## SDK Layout tutorials

Tutorials for the `SdkLayout` host API.

### sdklayout-01-introduction

Introduces the `SdkLayout` API.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/sdklayout-01-introduction)

### sdklayout-02-routing

Define routes between code regions.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/sdklayout-02-routing)

### sdklayout-03-ports-and-connections

Attach ports to code regions and wire them together.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/sdklayout-03-ports-and-connections)

### sdklayout-04-h2d-d2h

Connect ports to host-to-device and device-to-host streams.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/sdklayout-04-h2d-d2h)

### sdklayout-05-gemv

Put the pieces together in a full GEMV program.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/sdklayout-05-gemv)

## Benchmarks

Programs that demonstrate more complex kernels on the Wafer-Scale Engine.

### gemv-checkerboard

GEMV using a checkerboard distribution across PEs.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/gemv-checkerboard-pattern)

### gemv-collectives

GEMV using the `<collectives_2d>` library.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/gemv-collectives_2d)

### gemm-collectives

SUMMA matrix-multiply using the `<collectives_2d>` library.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/gemm-collectives_2d)

### residual

Compute a residual `r = b - Ax` on a 2 x 2 rectangle of PEs.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/residual)

### cholesky

Cholesky factorization of a symmetric positive-definite matrix.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/cholesky)

### 25-pt-stencil

Time-marching 25-point stencil computation.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/25-pt-stencil)

### bandwidth-test

Measure host-to-device and device-to-host WSE bandwidth.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/bandwidth-test)

### 7pt-stencil-spmv

7-point stencil sparse matrix-vector performance test.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/7pt-stencil-spmv)

### power-method

Power method on a sparse matrix.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/power-method)

### conjugate-gradient

Conjugate Gradient (CG) solver on a sparse matrix.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/conjugate-gradient)

### preconditioned-conjugate-gradient

Preconditioned Conjugate Gradient solver.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/preconditioned-conjugate-gradient)

### bicgstab

BiCGSTAB solver on a sparse matrix.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/bicgstab)

### single-tile-matvec

Optimized matrix-vector products confined to single PEs.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/single-tile-matvec)

### row-col-broadcast

Row- and column-wise broadcasts across a PE rectangle.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/row-col-broadcast)

### fft-3d

3D Discrete Fourier Transform with a pencil decomposition.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/fft-3d)

### game-of-life

Conway's Game of Life on the WSE.
[View on GitHub](https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/game-of-life)
