> ## 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 [Build a GEMV Kernel](/csl/tutorials).
</Note>

## GEMV Tutorial Series

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

<Card title="1. Basic CSL Syntax" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/gemv-00-basic-syntax" horizontal arrow="true">
  First in a series; covers preliminaries of CSL syntax.
</Card>

<Card title="2. A Complete Program" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/gemv-01-complete-program" horizontal arrow="true">
  A complete, runnable CSL program on a single PE.
</Card>

<Card title="3. Memory DSDs" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/gemv-02-memory-dsds" horizontal arrow="true">
  Use memory data structure descriptors (DSDs) for efficient tensor operations.
</Card>

<Card title="4. Host-Device Memcpy" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/gemv-03-memcpy" horizontal arrow="true">
  Copy tensors between host and device with the `memcpy` functionality of `SdkRuntime`.
</Card>

<Card title="5. Compile-Time Parameters" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/gemv-04-params" horizontal arrow="true">
  Use compile-time parameters to specialize a program.
</Card>

<Card title="6. Multiple PEs" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/gemv-05-multiple-pes" horizontal arrow="true">
  Extend the program to run on multiple PEs.
</Card>

<Card title="7. Routes and Colors" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/gemv-06-routes-1" horizontal arrow="true">
  Use routes and colors to distribute a single GEMV across multiple PEs.
</Card>

<Card title="8. Advanced Routing" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/gemv-07-routes-2" horizontal arrow="true">
  More advanced routing across multiple PEs.
</Card>

<Card title="9. Routing Across a 2D Grid" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/gemv-08-routes-3" horizontal arrow="true">
  Further extend the GEMV computation across a 2D grid.
</Card>

<Card title="10. Streaming GEMV" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/gemv-09-streaming" horizontal arrow="true">
  Alternative streaming version of the previous example.
</Card>

## Topic Tutorials

Focused examples illustrating specific language or library features.

<Columns cols={2}>
  <Card title="Arrays and Pointers" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-01-arrays-and-pointers" arrow="true">
    Pass and return arrays in compile-time functions.
  </Card>

  <Card title="Compiler Libraries" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-02-libraries" arrow="true">
    Use libraries bundled with the CSL compiler.
  </Card>

  <Card title="Streaming Wavelet Data" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-03-streaming-wavelet-data" arrow="true">
    Tasks activated in response to incoming wavelets.
  </Card>

  <Card title="Sparse Tensors" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-04-sparse-tensors" arrow="true">
    Efficiently stream only non-zero entries of sparse tensors.
  </Card>

  <Card title="Sentinels" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-05-sentinels" arrow="true">
    Use sentinels with routable colors.
  </Card>

  <Card title="Fabric Switches" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-06-switches" arrow="true">
    Fabric switches for limited runtime control of routes.
  </Card>

  <Card title="Switches as Entry Points" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-07-switches-entrypt" arrow="true">
    Encode a special entry point with fabric switches.
  </Card>

  <Card title="Fabric Filters" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-08-filters" arrow="true">
    Fabric filters that let a PE selectively accept incoming wavelets.
  </Card>

  <Card title="FIFOs" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-09-fifos" arrow="true">
    Buffer PE input/output with a FIFO DSD.
  </Card>

  <Card title="The @map Builtin" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-10-map-builtin" arrow="true">
    The `@map` builtin for custom operations on data.
  </Card>

  <Card title="Collectives" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-11-collectives" arrow="true">
    Inter-PE communication with the `<collectives_2d>` library.
  </Card>

  <Card title="The Debug Library" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-12-debug-library" arrow="true">
    Tracing via the `<debug>` library.
  </Card>

  <Card title="Simulator Printing" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-13-simprint" arrow="true">
    Print values directly from the simulator.
  </Card>

  <Card title="Color Swap" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-14-color-swap" arrow="true">
    Color swap feature on WSE-2.
  </Card>

  <Card title="WSE-3 Microthreads" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-15-wse3-microthreads" arrow="true">
    Explicit microthread IDs on WSE-3.
  </Card>

  <Card title="Queue Flushing" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/topic-16-queue-flush" arrow="true">
    Flushing output queues on WSE-3 when multiple colors share a queue.
  </Card>
</Columns>

## Pipeline Tutorials

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

<Card title="1. Basic Pipeline" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/pipeline-01-basic" horizontal arrow="true">
  Process one wavelet at a time with wavelet-triggered tasks.
</Card>

<Card title="2. Pipeline with a FIFO" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/pipeline-02-fifo" horizontal arrow="true">
  Use a FIFO to avoid stalls on large inputs.
</Card>

<Card title="3. Multiple Pipelines" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/pipeline-03-multiple" horizontal arrow="true">
  Reduce FIFO resource consumption with multiple pipelines.
</Card>

## SDK Layout Tutorials

Tutorials for the `SdkLayout` host API.

<Card title="1. Introduction to SdkLayout" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/sdklayout-01-introduction" horizontal arrow="true">
  Introduces the `SdkLayout` API.
</Card>

<Card title="2. Routing Between Regions" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/sdklayout-02-routing" horizontal arrow="true">
  Define routes between code regions.
</Card>

<Card title="3. Ports and Connections" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/sdklayout-03-ports-and-connections" horizontal arrow="true">
  Attach ports to code regions and wire them together.
</Card>

<Card title="4. Host-Device Streams" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/sdklayout-04-h2d-d2h" horizontal arrow="true">
  Connect ports to host-to-device and device-to-host streams.
</Card>

<Card title="5. A Complete GEMV Program" href="https://github.com/Cerebras/sdk-examples/tree/master/tutorials/sdklayout-05-gemv" horizontal arrow="true">
  Put the pieces together in a full GEMV program.
</Card>

## Benchmarks

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

<Columns cols={2}>
  <Card title="GEMV Checkerboard" href="https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/gemv-checkerboard-pattern" arrow="true">
    GEMV using a checkerboard distribution across PEs.
  </Card>

  <Card title="GEMV with Collectives" href="https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/gemv-collectives_2d" arrow="true">
    GEMV using the `<collectives_2d>` library.
  </Card>

  <Card title="GEMM with Collectives" href="https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/gemm-collectives_2d" arrow="true">
    SUMMA matrix-multiply using the `<collectives_2d>` library.
  </Card>

  <Card title="Residual Computation" href="https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/residual" arrow="true">
    Compute a residual `r = b - Ax` on a 2 x 2 rectangle of PEs.
  </Card>

  <Card title="Cholesky Factorization" href="https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/cholesky" arrow="true">
    Cholesky factorization of a symmetric positive-definite matrix.
  </Card>

  <Card title="25-Point Stencil" href="https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/25-pt-stencil" arrow="true">
    Time-marching 25-point stencil computation.
  </Card>

  <Card title="Bandwidth Test" href="https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/bandwidth-test" arrow="true">
    Measure host-to-device and device-to-host WSE bandwidth.
  </Card>

  <Card title="7-Point Stencil SpMV" href="https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/7pt-stencil-spmv" arrow="true">
    7-point stencil sparse matrix-vector performance test.
  </Card>

  <Card title="Power Method" href="https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/power-method" arrow="true">
    Power method on a sparse matrix.
  </Card>

  <Card title="Conjugate Gradient" href="https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/conjugate-gradient" arrow="true">
    Conjugate Gradient (CG) solver on a sparse matrix.
  </Card>

  <Card title="Preconditioned Conjugate Gradient" href="https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/preconditioned-conjugate-gradient" arrow="true">
    Preconditioned Conjugate Gradient solver.
  </Card>

  <Card title="BiCGSTAB Solver" href="https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/bicgstab" arrow="true">
    BiCGSTAB solver on a sparse matrix.
  </Card>

  <Card title="Single-Tile Matrix-Vector Product" href="https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/single-tile-matvec" arrow="true">
    Optimized matrix-vector products confined to single PEs.
  </Card>

  <Card title="Row and Column Broadcast" href="https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/row-col-broadcast" arrow="true">
    Row- and column-wise broadcasts across a PE rectangle.
  </Card>

  <Card title="3D FFT" href="https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/fft-3d" arrow="true">
    3D Discrete Fourier Transform with a pencil decomposition.
  </Card>

  <Card title="Conway's Game of Life" href="https://github.com/Cerebras/sdk-examples/tree/master/benchmarks/game-of-life" arrow="true">
    Conway's Game of Life on the WSE.
  </Card>
</Columns>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.