Python Kernel Library¶
Pre-built AIE kernel wrappers for common operations. These provide ready-to-use
Worker-compatible callables backed by optimized native AIE code. For the C++
kernel sources these wrap, see C++ AIE kernels.
Element-wise operations¶
Element-wise kernel factories: passthrough, scale, add, mul, relu.
passthrough ¶
Element-wise passthrough kernel: copies input tile to output tile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile_size
|
int
|
Number of elements per tile. |
4096
|
dtype
|
type
|
Element data type ( |
int32
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction configured for |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in python/iron/kernels/eltwise.py
scale ¶
scale(
tile_size: int = 1024,
dtype: type = int32,
vectorized: bool = True,
use_chess: bool = False,
) -> ExternalFunction
Scalar-multiply kernel: multiplies each element of an input tile by a factor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile_size
|
int
|
Number of elements per tile. |
1024
|
dtype
|
type
|
Element data type. Must be |
int32
|
vectorized
|
bool
|
If |
True
|
use_chess
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction configured for the scale kernel. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in python/iron/kernels/eltwise.py
add ¶
Element-wise bf16 addition (tile_size must be 1024, hard-coded in C++).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile_size
|
int
|
Elements per tile (must be 1024). |
1024
|
dtype
|
type
|
Element data type (only |
bfloat16
|
vectorized
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction for eltwise_add_bf16. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in python/iron/kernels/eltwise.py
mul ¶
Element-wise bf16 multiplication (tile_size must be 1024, hard-coded in C++).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile_size
|
int
|
Elements per tile (must be 1024). |
1024
|
dtype
|
type
|
Element data type (only |
bfloat16
|
vectorized
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction for eltwise_mul_bf16. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in python/iron/kernels/eltwise.py
relu ¶
Element-wise bf16 ReLU (tile_size must be 1024, hard-coded in C++).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile_size
|
int
|
Elements per tile (must be 1024). |
1024
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction for bf16_relu. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in python/iron/kernels/eltwise.py
Reduction¶
Reduction kernel factories: reduce_add, reduce_min, reduce_max, compute_max.
reduce_add ¶
reduce_add(
tile_size: int = 1024,
dtype: type = int32,
vectorized: bool = True,
) -> ExternalFunction
Reduction kernel: sums all elements of a tile to a scalar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile_size
|
int
|
Number of elements in the input tile. |
1024
|
dtype
|
type
|
Element data type (only |
int32
|
vectorized
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction configured for the reduce_add kernel. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in python/iron/kernels/reduce.py
reduce_min ¶
reduce_min(
tile_size: int = 1024,
dtype: type = int32,
vectorized: bool = True,
) -> ExternalFunction
Reduction kernel: finds the minimum element of a tile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile_size
|
int
|
Number of elements in the input tile. |
1024
|
dtype
|
type
|
Element data type (only |
int32
|
vectorized
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction configured for the reduce_min kernel. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in python/iron/kernels/reduce.py
reduce_max ¶
reduce_max(
tile_size: int = 1024,
dtype: type = int32,
vectorized: bool = True,
) -> ExternalFunction
Reduction kernel: finds the maximum element of a tile (int32 or bfloat16).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile_size
|
int
|
Number of elements in the input tile. |
1024
|
dtype
|
type
|
Element data type ( |
int32
|
vectorized
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction configured for the reduce_max kernel. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in python/iron/kernels/reduce.py
compute_max ¶
Pairwise scalar max — companion to reduce_max for multi-core
reductions where each core produces a partial max and a final tree
reduces them pairwise.
Lives in the same reduce_max.cc as reduce_max; sharing the
output .o (via shared_object_file_name) means both factories
in the same design compile the source exactly once.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dtype
|
type
|
Element data type ( |
int32
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction configured for the |
ExternalFunction
|
is |
ExternalFunction
|
(DMA-aligned) tile of |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in python/iron/kernels/reduce.py
Linear algebra¶
Linear algebra kernel factories: mm, mv, cascade_mm.
mm ¶
mm(
dim_m: int = 64,
dim_k: int = 64,
dim_n: int = 64,
input_dtype: type = int16,
output_dtype: type = int16,
vectorized: bool = True,
b_col_maj: bool = False,
c_col_maj: bool = False,
use_chess: bool = False,
emulate_bf16_mmul_with_bfp16: bool = False,
) -> ExternalFunction
Matrix-multiply kernel: C += A * B.
The compiled .o exports both the matmul_* and zero_* symbols.
Use kernels.mm(...).zero to get a sibling Kernel binding the zero
symbol against the same .o, suitable for accumulator initialization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dim_m
|
int
|
Number of rows of A / C. |
64
|
dim_k
|
int
|
Number of columns of A / rows of B. |
64
|
dim_n
|
int
|
Number of columns of B / C. |
64
|
input_dtype
|
type
|
Input element type ( |
int16
|
output_dtype
|
type
|
Output element type. |
int16
|
vectorized
|
bool
|
If |
True
|
b_col_maj
|
bool
|
If |
False
|
c_col_maj
|
bool
|
If |
False
|
use_chess
|
bool
|
If |
False
|
emulate_bf16_mmul_with_bfp16
|
bool
|
AIE2P only, bf16 inputs only. When
|
False
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction configured for the matmul kernel. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in python/iron/kernels/linalg.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
mv ¶
mv(
dim_m: int = 32,
dim_k: int = 32,
input_dtype: type = int16,
output_dtype: type = int32,
vectorized: bool = True,
use_chess: bool = False,
) -> ExternalFunction
Matrix-vector multiply kernel: c += A * b.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dim_m
|
int
|
Number of rows of A (output vector length). |
32
|
dim_k
|
int
|
Number of columns of A (input vector length). |
32
|
input_dtype
|
type
|
Input element type. Only |
int16
|
output_dtype
|
type
|
Output element type. Only |
int32
|
vectorized
|
bool
|
If |
True
|
use_chess
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction configured for the matvec kernel. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When the dtype combination is not supported. |
Source code in python/iron/kernels/linalg.py
cascade_mm ¶
cascade_mm(
dim_m: int = 64,
dim_k: int = 64,
dim_n: int = 64,
input_dtype: type = int16,
output_dtype: type = int16,
use_chess: bool = False,
) -> ExternalFunction
Cascade matrix-multiply kernel for multi-core accumulation.
cascade_mm.cc emits all three cascade variants (get_only,
put_only, put_get) plus a zero companion in one .o. The
returned ExternalFunction binds the get_only symbol; the other
three are sibling Kernel\s available as attributes:
.get_only— same as the returned EF (top of the cascade chain)..put_only— bottom of the chain..put_get— middle of the chain..zero— accumulator initializer.
Designs typically use all four together, one per row of compute cores.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dim_m
|
int
|
Number of rows of A / C. |
64
|
dim_k
|
int
|
Number of columns of A / rows of B. |
64
|
dim_n
|
int
|
Number of columns of B / C. |
64
|
input_dtype
|
type
|
Input element type. |
int16
|
output_dtype
|
type
|
Output element type. |
int16
|
use_chess
|
bool
|
If |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
When the dtype combination is not supported. |
Source code in python/iron/kernels/linalg.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | |
Convolution¶
Convolution kernel factories: conv2dk1/3/14, bottleneck (bn_*) variants.
conv2dk1 ¶
conv2dk1(
input_width: int = 32,
input_channels: int = 64,
output_channels: int = 64,
act_dtype: type = int8,
) -> ExternalFunction
1x1 convolution kernel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_width
|
int
|
Spatial width of the input. |
32
|
input_channels
|
int
|
Number of input channels. |
64
|
output_channels
|
int
|
Number of output channels. |
64
|
act_dtype
|
type
|
Activation data type ( |
int8
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction configured for the conv2dk1 kernel. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in python/iron/kernels/conv.py
conv2dk3 ¶
conv2dk3(
input_width: int = 32,
input_channels: int = 64,
output_channels: int = 64,
act_dtype: type = int8,
weight_output_channels: int | None = None,
) -> ExternalFunction
3x3 convolution kernel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_width
|
int
|
Spatial width of the input. |
32
|
input_channels
|
int
|
Number of input channels. |
64
|
output_channels
|
int
|
Number of output channels produced by this call. |
64
|
act_dtype
|
type
|
Activation data type ( |
int8
|
weight_output_channels
|
int | None
|
Total number of output channels stored in the
weights buffer. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction configured for the conv2dk3 kernel. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in python/iron/kernels/conv.py
conv2dk1_skip ¶
conv2dk1_skip(
input_width: int = 32,
input_channels: int = 64,
output_channels: int = 64,
act_dtype: type = int8,
) -> ExternalFunction
1x1 convolution kernel with skip (residual) connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_width
|
int
|
Spatial width of the input. |
32
|
input_channels
|
int
|
Number of input channels. |
64
|
output_channels
|
int
|
Number of output channels. |
64
|
act_dtype
|
type
|
Activation data type ( |
int8
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction configured for the conv2dk1_skip kernel. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in python/iron/kernels/conv.py
conv2dk1_i8 ¶
conv2dk1_i8(
input_width: int = 32,
input_channels: int = 64,
output_channels: int = 64,
) -> ExternalFunction
1x1 convolution kernel with int8 activations/weights/output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_width
|
int
|
Spatial width of the input. |
32
|
input_channels
|
int
|
Number of input channels. |
64
|
output_channels
|
int
|
Number of output channels. |
64
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction configured for the conv2dk1_i8 kernel. |
Source code in python/iron/kernels/conv.py
conv2dk14 ¶
conv2dk14(
input_width: int = 224,
input_channels: int = 16,
output_channels: int = 16,
kernel_width: int = 14,
) -> ExternalFunction
14x14 convolution kernel (aie2p only).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_width
|
int
|
Spatial width of the input. |
224
|
input_channels
|
int
|
Number of input channels. |
16
|
output_channels
|
int
|
Number of output channels. |
16
|
kernel_width
|
int
|
Width (and height) of the convolution kernel. |
14
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction configured for the conv2dk14 kernel. |
Source code in python/iron/kernels/conv.py
conv2dk1_skip_init ¶
conv2dk1_skip_init(
input_width: int = 32,
input_channels: int = 64,
output_channels: int = 64,
act_dtype: type = int8,
skip_input_channels: int | None = None,
) -> ExternalFunction
1x1 convolution kernel with skip-init connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_width
|
int
|
Spatial width of the input. |
32
|
input_channels
|
int
|
Number of input channels. |
64
|
output_channels
|
int
|
Number of output channels. |
64
|
act_dtype
|
type
|
Activation data type ( |
int8
|
skip_input_channels
|
int | None
|
Number of input channels for the skip-projection
1x1 conv whose weights are concatenated after the main conv
weights in the same buffer. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction configured for the conv2dk1_skip_init kernel. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in python/iron/kernels/conv.py
bn_conv2dk1_relu ¶
bn_conv2dk1_relu(
input_width: int = 32,
input_channels: int = 64,
output_channels: int = 64,
) -> ExternalFunction
Bottleneck 1x1 conv + ReLU kernel (int8 in, uint8 out).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_width
|
int
|
Spatial width of the input. |
32
|
input_channels
|
int
|
Number of input channels. |
64
|
output_channels
|
int
|
Number of output channels. |
64
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction configured for the bn_conv2dk1_relu kernel. |
Source code in python/iron/kernels/conv.py
bn_conv2dk3 ¶
bn_conv2dk3(
input_width: int = 32,
input_channels: int = 64,
output_channels: int = 64,
) -> ExternalFunction
Bottleneck 3x3 conv with stride-2 kernel (int8 in, uint8 out).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_width
|
int
|
Spatial width of the input. |
32
|
input_channels
|
int
|
Number of input channels. |
64
|
output_channels
|
int
|
Number of output channels. |
64
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction configured for the bn_conv2dk3 kernel. |
Source code in python/iron/kernels/conv.py
bn_conv2dk1_i8 ¶
bn_conv2dk1_i8(
input_width: int = 32,
input_channels: int = 64,
output_channels: int = 64,
) -> ExternalFunction
Bottleneck 1x1 conv kernel (uint8 in, int8 out).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_width
|
int
|
Spatial width of the input. |
32
|
input_channels
|
int
|
Number of input channels. |
64
|
output_channels
|
int
|
Number of output channels. |
64
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction configured for the bn_conv2dk1_i8 kernel. |
Source code in python/iron/kernels/conv.py
bn_conv2dk1_skip ¶
bn_conv2dk1_skip(
input_width: int = 32,
input_channels: int = 64,
output_channels: int = 64,
skip_dtype: type = uint8,
) -> ExternalFunction
Bottleneck 1x1 conv with skip connection (uint8 in).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_width
|
int
|
Spatial width of the input. |
32
|
input_channels
|
int
|
Number of input channels. |
64
|
output_channels
|
int
|
Number of output channels. |
64
|
skip_dtype
|
type
|
Skip connection data type ( |
uint8
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction configured for the bn_conv2dk1_skip kernel. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in python/iron/kernels/conv.py
bn_conv2dk3_dw ¶
bn_conv2dk3_dw(
input_width: int = 32,
input_channels: int = 64,
output_channels: int = 64,
stride: int = 1,
) -> ExternalFunction
Bottleneck depthwise 3x3 conv + ReLU kernel (uint8 in/out).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_width
|
int
|
Spatial width of the input. |
32
|
input_channels
|
int
|
Number of input channels. |
64
|
output_channels
|
int
|
Number of output channels. |
64
|
stride
|
int
|
Convolution stride (1 or 2). |
1
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction configured for the bn_conv2dk3_dw kernel. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in python/iron/kernels/conv.py
bn_conv2dk1_relu_xy_pool_padded ¶
bn_conv2dk1_relu_xy_pool_padded(
input_width: int = 7,
input_channels: int = 80,
output_channels: int = 1280,
weight_chunk_count: int | None = None,
) -> ExternalFunction
Fused 1x1 conv + ReLU + xy-pool with channel padding (int8 in, uint16 out).
A post-stage kernel that fuses a pointwise (1x1) convolution, ReLU activation, and global xy avg-pool into a single pass, with output channels padded to a DMA-friendly multiple. Sized for MobileNet V3's post-bottleneck stage where the final 1x1 expand-conv collapses the 7x7 feature map into a 1x1 vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_width
|
int
|
Spatial width of the input. |
7
|
input_channels
|
int
|
Number of input channels. |
80
|
output_channels
|
int
|
Logical output channels (e.g. 1280). Sets both
the output buffer length AND, when |
1280
|
weight_chunk_count
|
int | None
|
Override the weight buffer's element count when
the design streams weights in chunks (cascade/output-split).
|
None
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction configured for the fused conv+relu+xy_pool kernel. |
Source code in python/iron/kernels/conv.py
bn_conv2dk1_partial_put_i8 ¶
bn_conv2dk1_partial_put_i8(
input_width: int = 7,
input_channels: int = 80,
weight_count: int = 4800,
*,
block_index: int = 13
) -> ExternalFunction
Cascade-PUT half of a width-split 1x1 conv on int8 activations.
The PUT tile of a two-tile cascade-split pointwise conv: consumes a
width slice of the activation, multiplies against its weight half,
and emits the partial sum onto the cascade stream (no separate
output buffer — cascade-only). Sister of
bn_conv2dk1_partial_get_relu_i8.
Currently defined in the .cc only for MobileNet V3's bn13 / bn14
(one wrapper symbol per block); block_index selects which.
Generalising this to arbitrary block names would require adding a
non-prefixed wrapper to bn_conv2dk1_i8.cc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_width
|
int
|
Spatial width of the input slice. |
7
|
input_channels
|
int
|
Number of input channels. |
80
|
weight_count
|
int
|
Per-call weight chunk size in elements (the design streams weights in chunks; full weight tensor is shared across multiple kernel invocations). |
4800
|
block_index
|
int
|
|
13
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction configured for the PUT tile. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in python/iron/kernels/conv.py
bn_conv2dk1_partial_get_relu_i8 ¶
bn_conv2dk1_partial_get_relu_i8(
input_width: int = 7,
input_channels: int = 80,
output_channels: int = 480,
weight_count: int = 4800,
*,
block_index: int = 13
) -> ExternalFunction
Cascade-GET half of a width-split 1x1 conv + ReLU on int8 activations.
The GET tile of a two-tile cascade-split pointwise conv: consumes
the cascade partial sum from its sister PUT tile, finishes the dot
product against its weight half, applies ReLU, and writes the full
output buffer. Sister of bn_conv2dk1_partial_put_i8.
Currently defined in the .cc only for MobileNet V3's bn13 / bn14
(one wrapper symbol per block); block_index selects which.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_width
|
int
|
Spatial width of the input slice. |
7
|
input_channels
|
int
|
Number of input channels. |
80
|
output_channels
|
int
|
Number of output channels (full L1 output width). |
480
|
weight_count
|
int
|
Per-call weight chunk size in elements. |
4800
|
block_index
|
int
|
|
13
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction configured for the GET tile. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in python/iron/kernels/conv.py
bn_conv2dk3_dw_out_split ¶
bn_conv2dk3_dw_out_split(
input_width: int = 7,
input_channels: int = 480,
output_split_channels: int = 240,
*,
block_index: int = 13
) -> ExternalFunction
Depthwise 3x3 stride-1 conv with split output stream (uint8 in/out).
A variant of bn_conv2dk3_dw (stride=1) that writes its output
to TWO separate buffers — the channel dimension is split in half so
downstream cascade-PUT tiles can each consume one slice. Used by
MobileNet V3's bn13 / bn14 depthwise stage to feed the L3 cascade.
Currently defined in the .cc only via per-block extern wrappers
(BN13 or BN14 macro picks the symbol prefix); block_index selects
which.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_width
|
int
|
Spatial width of the input. |
7
|
input_channels
|
int
|
Number of input channels (== output channels — depthwise). |
480
|
output_split_channels
|
int
|
Channels per output slice (half of
|
240
|
block_index
|
int
|
|
13
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction configured for the split-output DW kernel. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in python/iron/kernels/conv.py
bn_conv2dk1_input_split_partial_put_ui8 ¶
bn_conv2dk1_input_split_partial_put_ui8(
input_width: int = 7,
input_channels: int = 240,
weight_count: int = 9600,
*,
block_index: int = 13
) -> ExternalFunction
Input-split cascade-PUT half of a 1x1 conv on uint8 activations.
Like bn_conv2dk1_partial_put_i8 but consumes a CHANNEL slice
(input-split) of a uint8 activation instead of a width slice of int8.
Used by MobileNet V3's bn13 / bn14 L3 stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_width
|
int
|
Spatial width of the input slice. |
7
|
input_channels
|
int
|
Number of input channels (one half of the full input after split). |
240
|
weight_count
|
int
|
Per-call weight chunk size in elements. |
9600
|
block_index
|
int
|
|
13
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction configured for the input-split PUT tile. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in python/iron/kernels/conv.py
bn_conv2dk1_input_split_partial_skip_get ¶
bn_conv2dk1_input_split_partial_skip_get(
input_width: int = 7,
input_channels: int = 240,
output_channels: int = 80,
weight_count: int = 9600,
*,
block_index: int = 13
) -> ExternalFunction
Input-split cascade-GET half of a 1x1 conv + skip-add (uint8 in, int8 out).
The GET tile completes the cascade-split 1x1 + ReLU + residual add
pattern: consumes the partial sum from its sister PUT tile, finishes
the dot product, adds a skip row of int8 activations, and writes int8
output. Sister of bn_conv2dk1_input_split_partial_put_ui8.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_width
|
int
|
Spatial width of the input slice. |
7
|
input_channels
|
int
|
Number of input channels (one half after split). |
240
|
output_channels
|
int
|
Final output channels. |
80
|
weight_count
|
int
|
Per-call weight chunk size in elements. |
9600
|
block_index
|
int
|
|
13
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction configured for the input-split skip-GET tile. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in python/iron/kernels/conv.py
bn_fc_relu_ui16_pad ¶
bn_fc_relu_ui16_pad(
input_channels: int = 1280,
output_channels: int = 16,
weight_chunk_count: int | None = None,
) -> ExternalFunction
Fully-connected layer (1x1 conv on (1,1,C)) + ReLU, uint16 in/out, with padding.
A post-stage FC kernel used by MobileNet V3's classifier head. Input is
a (1,1,input_channels) feature vector held as uint16; output is
output_channels uint16 logits. Weights stored in a padded layout
(the input_channels_pad runtime arg selects the actual stride).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_channels
|
int
|
Number of input channels (e.g. 1280). |
1280
|
output_channels
|
int
|
Number of output channels per call (slice width, since the full FC is split across multiple tiles). |
16
|
weight_chunk_count
|
int | None
|
Override the weight buffer's element count when
the design streams weights in chunks (cascade/ping-pong).
|
None
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction configured for the post-L2 FC kernel. |
Source code in python/iron/kernels/conv.py
Activation functions¶
Activation kernel factories + numpy reference implementations.
Factories (each returns an ExternalFunction):
softmax, gelu, silu, swiglu, bf16_exp.
Companion numpy reference implementations for host-side verification
relu_ref, silu_ref, gelu_ref,
bf16_exp_ref, softmax_ref. These compute the AIE
kernel's op in float32 so designs don't each reimplement the math
in their verify path. Pair with
count_mismatches (rtol=0.128 is the
canonical LUT-tolerance default; see each ref's docstring for
per-op recommendations).
softmax ¶
Softmax activation kernel for bf16 tiles (tile_size must be 1024).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile_size
|
int
|
Number of elements per tile. |
1024
|
Returns:
| Type | Description |
|---|---|
ExternalFunction
|
ExternalFunction configured for the softmax kernel. |
Source code in python/iron/kernels/activation.py
gelu ¶
GELU activation kernel (tanh approximation) for bf16 tiles (must be 1024).
silu ¶
SiLU (Swish) activation kernel for bf16 tiles (must be 1024).
swiglu ¶
SwiGLU gated activation kernel for bf16 tiles (must be 1024).
bf16_exp ¶
Element-wise exponential kernel for bf16 tiles (must be 1024).
relu_ref ¶
numpy reference for a ReLU kernel — element-wise max(x, 0).
Exact; tolerance comparison is not needed. See aie.utils.verify
for the relaxed bf16/LUT-style comparators most kernels here want.
Source code in python/iron/kernels/activation.py
silu_ref ¶
numpy reference for silu (Swish) — x * sigmoid(x).
LUT-approximation territory; pair with rtol=0.128 (the default
in count_mismatches) when verifying.
Source code in python/iron/kernels/activation.py
gelu_ref ¶
numpy reference for gelu — tanh approximation
0.5 * x * (1 + tanh(sqrt(2/pi) * (x + 0.044715 * x^3))).
Matches the C++ kernel's tanh-GELU formula; pair with rtol=0.128,
atol=0.05 when verifying.
Source code in python/iron/kernels/activation.py
bf16_exp_ref ¶
numpy reference for bf16_exp — element-wise exp(x).
LUT approximation territory; the AIE kernel saturates on large inputs.
Pair with the canonical 12.8% relative tolerance and stop_at_
nonfinite=True (the default in
count_mismatches) when verifying.
Source code in python/iron/kernels/activation.py
softmax_ref ¶
numpy reference for softmax.
The AIE kernel computes softmax independently per tile_size-element
tile (no cross-tile reduction), so the reference splits x the same
way before applying the float32 softmax. x.size must be a
multiple of tile_size.
Source code in python/iron/kernels/activation.py
Vision¶
Vision kernel factories: color conversion, threshold, filter2d, add_weighted.
rgba2hue ¶
Converts a line of RGBA pixels to hue values.
Source code in python/iron/kernels/vision.py
threshold ¶
threshold(
line_width: int = 1920,
dtype: type = uint8,
use_chess: bool = False,
) -> ExternalFunction
Applies a threshold operation to a line of pixels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line_width
|
int
|
Number of elements per line. |
1920
|
dtype
|
type
|
Element data type ( |
uint8
|
use_chess
|
bool
|
When |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in python/iron/kernels/vision.py
bitwise_or ¶
bitwise_or(
line_width: int = 1920,
dtype: type = uint8,
use_chess: bool = False,
) -> ExternalFunction
Element-wise bitwise OR of two lines.
bitwise_and ¶
bitwise_and(
line_width: int = 1920,
dtype: type = uint8,
use_chess: bool = False,
) -> ExternalFunction
Element-wise bitwise AND of two lines.
gray2rgba ¶
Converts a grayscale line to RGBA.
rgba2gray ¶
Converts an RGBA line to grayscale.
Source code in python/iron/kernels/vision.py
filter2d ¶
Applies a 3x3 2D convolution filter across three input lines.
Source code in python/iron/kernels/vision.py
add_weighted ¶
add_weighted(
line_width: int = 1920,
dtype: type = uint8,
use_chess: bool = False,
) -> ExternalFunction
Weighted addition of two lines with a gamma offset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line_width
|
int
|
Number of elements per line. |
1920
|
dtype
|
type
|
Element data type ( |
uint8
|
use_chess
|
bool
|
When |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
When |