The code and documentation for CIMFlow is currently under construction. Stay tuned!
CIMFlow LogoCIMFlow

Domain Specific Language

CIM-DSL A Domain Specific Language for Computing-in-Memory Architectures. Based on CIM-DSL, it can efficiently support complex computational tasks, reduce deployment costs, and seamlessly integrate with other upper-layer compilers.

Syntax Design

CIM-DSL features a concise and intuitive syntax design that not only provides comprehensive support for diverse data flows in CIM architectures, but also significantly reduces the learning curve and development effort for users.

Declaration

By specifying a (shape, data type, memory type) triple, a multidimensional memory block (Tile) can be declared on the specified memory. CIM-DSL requires the declared memory block shape to be constant. The data type can be selected from different options (integer, floating-point) with various bit-widths, and the memory type can be any type supported by the CIM architecture.

The example below declares a memory block with a shape of [3, 32, 32] and an 8-bit integer data type in the input memory:

input = Tile([3,32,32], int8, input_memory);

Statement List

Consists of one or more statements. Statement can be one of the following and must end with a semicolon:

  1. Assignment statement

An ID followed by an equal sign and an expression.

e.g. x = 1 + y;

  1. Call statement

A function call.

  1. Loop Statement

An optional unroll annotation, followed by the keyword for, an ID, the keyword in, a range, then a carry clause, and a statement list enclosed in curly braces. The range can take three forms:

for i in (10)     {....};     # 0 to 9
for i in (0,10)   {....};     # 0 to 9
for i in (0,10,2) {....};     # 0,2,4,6,8
  1. Conditional Statement

The keyword if followed by an expression in (), then a carry clause, a statement list, then the keyword else and another statement list (enclosed in {}).

if (x==1) {....}
else {....};
  1. Carry Statement

Composed of the keyword carry followed by a carry list in (). The carry list can be empty or contain one or more variables separated by ,.

  1. Return Statement

Composed of the keyword return followed by an expression.

Slicing

By specifying the source memory block and the slicing parameters for each dimension, the corresponding memory block slice can be obtained.

The slicing parameters for each dimension consist of three parts: start coordinate, end coordinate, and step size.

For programming convenience, all three parameters can be omitted:

  • When the start coordinate is omitted, it defaults to 0;
  • when the end coordinate is omitted, it defaults to the size of the source memory block in that dimension;
  • when the step size is omitted, it defaults to 1, indicating consecutive elements.

Following examples, including different slicing operations performed on the original memory block.

Example:

src = Tile([4,8], int8, input_memory);
slice_1 = src[1, :4];
slice_2 = src[1:3, :];
slice_3 = src[1:3, 1:3];
slice_4 = src[::2, ::2];

Operator Precedence Orde

Order from lowest to highest:

  • Conditional Operations (LE | GE | LT | GT | COND_EQ | COND_NE | AND)
  • Addition & Subtraction (ADD | SUB)
  • Multiplication, Division & Modulo (MUL | DIV | MOD)
  • Basic Expressions ( '(' expr ')' )
  • Atomic Expressions (calls, constants, slices)

Function Call

A function call consists of a function ID, parentheses, and a parameter list. The parameter list may be empty or contain multiple parameters separated by commas. Parameters can be one of the following types:

  • Datatype
  • Memory type
  • One-dimensional constant array
  • One-dimensional array
  • Any expression

Built-in Functions

CIM-DSL provides a set of built-in functions for performing operations based on memory blocks. A built-in function starts with the function name, followed by one or more input parameters. Each parameter can be a memory block, a scalar, or an expression type. To flexibly support different underlying VEC_OP instruction types, the VEC_OP built-in functions allow for a variable number of inputs.

On this page