Kernel writing conventions¶
Variable suffixes¶
We prefer suffixes to prefixes because:
- avoids looking at the middle of the variable to find the interesting part
- It allows quick comparaison, for example
q = q_ptr + q_offs
, everything starts weq
and we reduce mistakes - It follows the pronunciation
Suffixes list:
_idx
integer representing an index_size
integer representing a size_off
integer representing an offset_offs
vector or matrix of integers to be used as offset for pointers_ptrs
vector or matrix of pointers_ptr
single pointer_range_offs
output oftl.arange(0, N)
to be used as offset for pointers_ptr_mask
bool matrix or vector to be used at mask for load and store operations_LOAD_MASK_NEEDED
boolean, usually used as constexpr to determine if we need to use a mask when loading or storing tensor
Variable prefixes¶
is_
,has_
orshould_
for booleans
Dimension naming¶
- Dimension is singular
- If dimension follows variable name from a formula. You can use this name. Example MNK for matmul
- Use
col
orrow
singular if you don't have a name for the last two dimensions
Tensor Stride naming¶
p_d_stride
p
is the name of the tensord
is the name of the dimension
For example:
q_batch_stride
output_row_stride
Tensor Size naming¶
p_d_size
p
is the name of the tensord
is the name of the dimension
For example:
q_batch_size
output_row_size