Syntax
Control flow, slicing, and expressions in CIM-DSL
Slicing
NumPy-style slicing with start:end:step syntax for accessing tensor elements:
src = Buffer(<4, 8>, int8, __INPUT_MEMORY__);
slice_1 = src[1, :4]; // Row 1, columns 0-3
slice_2 = src[1:3, :]; // Rows 1-2, all columns
slice_3 = src[::2, ::2]; // Every 2nd elementAll parameters are optional. Omitted values default to 0 for start, dimension size for end, and 1 for step.
For Loops
Python-like range() with a required carry clause for loop-carried variables:
for i in range(10) carry () {
Print(i);
};for i in range(0, 10, 2) carry () {
Print(i); // 0, 2, 4, 6, 8
};a = 1;
b = 1;
for i in range(6) carry (a, b) {
c = a + b;
a = b;
b = c;
};Loop Unrolling
Apply the @unroll decorator to duplicate the loop body at compile time:
@unroll
for i in range(4) carry () {
// Body duplicated 4 times
};All statements end with ; including loop and conditional blocks.
Conditionals
if (x == 1) carry () {
// then branch
} else {
// else branch
};Operators
Comparison
==Equal
!=Not equal
<<Less than
>>Greater than
<=Less or equal
>=Greater or equal
&&Logical AND
<< and >> are comparison operators, not bit shifts.
Arithmetic
+Add
-Subtract
*Multiply
/Divide
%Modulo
Last updated on