Skip to content

Tutorial

The tutorial introduces the language extensions of csl++ with one small program, which changes from step to step. It assumes that you know CSL as taught in the tutorials of the Cerebras SDK: tasks, DSDs, colors and routes, and memcpy.

Three PEs form a row. Each of the two outer PEs holds a value and sends it to the middle PE. The middle PE receives the two values and adds them.

PE 0 PE 1 PE 2
sender.csl ─────────► receiver.csl ◄───────── sender.csl
west_color east_color

The outer PEs run sender.csl, which is vanilla CSL. When the host calls compute, the PE sends its value x to the middle PE:

src/sender.csl
// Called by the host.
fn compute() void {
@fmovs(out_dsd, x[0]);
sys_mod.unblock_cmd_stream();
}

The middle PE runs receiver.csl. It has one input queue and one fabric input DSD for each neighbor:

src/receiver.csl
// One input queue per neighbor.
const west_queue: input_queue = @get_input_queue(2);
const east_queue: input_queue = @get_input_queue(3);
const west_in_dsd = @get_dsd(fabin_dsd, .{ .extent = 1, .input_queue = west_queue });
const east_in_dsd = @get_dsd(fabin_dsd, .{ .extent = 1, .input_queue = east_queue });

The tutorial is about the rest of this file: the code that receives the two values and stores their sum. The layout file routes one color from each outer PE to the middle PE. The host program writes a value to each outer PE, calls compute on all PEs, and reads the sum from the middle PE.

Every step has a complete program in the csl++ repository, in website/examples/tutorial. With csl-pp and the Cerebras SDK on your PATH, as described in Installation, clone the repository and run the script of a step:

Terminal window
git clone https://github.com/esa-tu-darmstadt/csl-pp.git
cd csl-pp/website/examples/tutorial/1-suspend
./commands_wse3.sh

The script compiles the program for WSE-3 and runs it on the simulator of the SDK. commands_wse2.sh does the same for WSE-2.

commands_wse3.sh
#!/usr/bin/env bash
set -e
csl-pp ./src/layout.csl --arch=wse3 --fabric-dims=10,3 --fabric-offsets=4,1 \
-o out --memcpy --channels=1
cs_python ./run.py --name out

csl-pp takes the arguments of cslc. The host program prints the two values and the sum that it read from the middle PE:

1.5 + 2.25 = 3.75
SUCCESS!
  1. Suspending a task: a task waits for an operation with suspend.
  2. Async functions: the wait becomes a function that is called with @await.
  3. Claiming resources: the program claims its colors, queues and task ID instead of choosing numbers.
  4. Parallel calls: @await_parallel receives both values at the same time.