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 weqand we reduce mistakes - It follows the pronunciation
Suffixes list:
_idxinteger representing an index_sizeinteger representing a size_offinteger representing an offset_offsvector or matrix of integers to be used as offset for pointers_ptrsvector or matrix of pointers_ptrsingle pointer_range_offsoutput oftl.arange(0, N)to be used as offset for pointers_ptr_maskbool matrix or vector to be used at mask for load and store operations_LOAD_MASK_NEEDEDboolean, 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
colorrowsingular if you don't have a name for the last two dimensions
Tensor Stride naming¶
p_d_stride
pis the name of the tensordis the name of the dimension
For example:
q_batch_strideoutput_row_stride
Tensor Size naming¶
p_d_size
pis the name of the tensordis the name of the dimension
For example:
q_batch_sizeoutput_row_size