> ## 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.

# Compiling and Running Examples

> Compile and run Cerebras SDK code examples using the provided command scripts and the CSL compiler and Python host runtime.

The [SDK Code Examples](/csl/sdk-examples) section contains CSL programs, the `.csl` files, that each either demonstrate individual features of the language, or solve a larger application problem. A Python script, the `run.py` file, accompanies each program to run it with the simulator.

The source for these code examples is hosted at the [SDK examples GitHub repository](https://github.com/Cerebras/sdk-examples).

For the GEMV tutorial code examples, we additionally provide step-by-step explanations of the code in the [Tutorials](/csl/tutorials) section.

<Note>
  If you’re just getting started, we recommend walking through the step-by-step tutorials in [Tutorials](/csl/tutorials/) to get a fuller explanation of these programs.
</Note>

## Compile the Code Examples

Each code example contains a CSL file as the top-level source file, typically named `layout.csl`. This file may reference additional CSL source files in that directory.

Each code example also contains a `commands.sh` script, which contains the commands required to compile and run it.

For example, the `tutorials/gemv-01-complete-program/commands.sh` in the [SDK examples repository](https://github.com/Cerebras/sdk-examples/tree/master/tutorials/gemv-01-complete-program) contains:

```bash theme={"languages":{"custom":["/languages/csl-tmlanguage.json"]}}
cslc ./layout.csl --fabric-dims=8,3 \
  --fabric-offsets=4,1 -o out --memcpy --channels 1
cs_python run.py --name out
```

<Tip>
  See [CSL Compiler](/csl/csl-compiler) for the compiler options documentation.
</Tip>

To compile the program:

1. First, cd into the directory that contains the CSL files.
2. Then run the `cslc` command shown in the `commands.sh` file to compile the program. Note, this command may span multiple lines and produces files with the `elf` extension. For example:

```bash theme={"languages":{"custom":["/languages/csl-tmlanguage.json"]}}
$ cd tutorials/gemv-01-complete-program/
$ cslc ./layout.csl --fabric-dims=8,3 --fabric-offsets=4,1 -o out --memcpy --channels 1
$ ls out
bin  east  generated  out.json  west
$ ls out/bin
out_0_0.elf  out_rpc.json
```

## Run the Program

Use the `run.py` Python script that is in the code example directory to execute the compiled program. For example, to run the above compiled program, execute the following command in the `gemv-01-complete-program` directory:

```bash theme={"languages":{"custom":["/languages/csl-tmlanguage.json"]}}
$ cs_python run.py --name out
```

If the program runs correctly, you will see the message `SUCCESS!` near the end of the output.

## Debug Your Program

See [Debugging Guide](/debug/debugging) and [SDK GUI](/debug/sdk-gui).

## Move from Simulation to Hardware

After successfully simulating your CSL program, you can run it on hardware by following the guidelines below when using `cslc`:

### Pass the `--arch` Flag

Use the `--arch` flag with `cslc` to ensure the compiler targets the appropriate Cerebras system.

Allowed values are `--arch=wse2` for WSE-2 architecture and `--arch=wse3` for WSE-3 architecture. The default value is `wse2`. For example:

```bash theme={"languages":{"custom":["/languages/csl-tmlanguage.json"]}}
cslc --arch=wse2 ./layout.csl --fabric-dims=8,3 \
  --fabric-offsets=4,1 -o out --memcpy --channels 1
```

Note that `wse3` is not yet supported for all example programs.

### Provide `--fabric-dims`

When compiling for simulation with `cslc`, the `--fabric-dims` flag can be any bounding box large enough to contain your program’s PEs. However, when compiling for hardware, these dimensions must match your Cerebras system’s fabric dimensions. For example:

```bash theme={"languages":{"custom":["/languages/csl-tmlanguage.json"]}}
cslc --arch=wse2 ./layout.csl --fabric-dims=757,996 \
  --fabric-offsets=4,1 -o out --memcpy --channels 1
```

### Provide an IP Address to SdkRuntime

To run on the Cerebras system hardware, you must pass the IP and port address of the network-attached Cerebras system to the `cmaddr` argument of the `SdkRuntime` constructor in your `run.py`:

```python theme={"languages":{"custom":["/languages/csl-tmlanguage.json"]}}
runner = SdkRuntime(compile_dir, cmaddr="1.2.3.4:9000")
```


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