Skip to main content
We’ve written a complete program that copies data to and from the device, but both our host and device still need to define the dimensions M and N. Now we introduce compile time parameters to set M and N while compiling our code, and show how our host code can read these values from the compile output.

Learning Objectives

After completing this tutorial, you should know how to:
  • Define compile time parameters for your device code
  • Set the value of compile time parameters when compiling
  • Read the value of compile time parameters from compile output in your host code

Example Overview

Our program will run on a single processing element (PE). Like the previous tutorials, we will demonstrate the program with a simulated fabric consisting of an 8 x 3 block of PEs. Our problem steps are identical to the previous tutorial. We need to modify our device code to replace the constants M and N with parameters, and modify our compile command to set these parameter values. Our host code must be modified to read these values from compile output.

Modifying the CSL

How must we modify our layout code to support compile time parameters for M and N?
  1. We need to define top level parameters for M and N that will be set by the compile command
  2. We need to pass these parameters along to our PE program
Let’s take a look at the modified layout.csl:
Notice that we’ve defined two parameters at the top of the file:
Additionally, we pass these parameters along to our PE program inside of our @set_tile_code call:
Now let’s take a look at the modified pe_program.csl:
pe_program.csl must also contain parameter declarations for M and N. When this file is compiled, it uses the values passed to it by layout.csl’s @set_tile_code call to bind them. M and N are no longer hard-coded in this file.

Compiling and Running the Program

We’ve shown how the device and host code use the compile time parameters, but how do we set them? Our compile command now includes a --params flag, which specifies the values:
We use the same command to run. You should see a SUCCESS! message at the end of execution.

Exercises

A is stored row-major in the above code. How would you rewrite A_dsd and the gemv function if A were stored column major instead?

Next

We’ve gone over some basics for writing a complete program using a single PE. Now let’s move on to using multiple PEs.