Supported StableHLO Operations
Overview
The iree-tools transpiler supports a subset of the StableHLO specification. Operations outside this set will be silently skipped during parsing.
stablehlo.constant
stablehlo.convert
stablehlo.convolution
N-dimensional convolution with configurable strides, padding, and dilation.
MLIR Syntax
%v1 = stablehlo.convolution(%arg0, %v0)
dim_numbers = [b, f, 0, 1]x[o, i, 0, 1]->[b, f, 0, 1],
window = {stride = [1, 1], pad = [[0, 0], [0, 0]], rhs_dilate = [1, 1]}
{batch_group_count = 1 : i64, feature_group_count = 1 : i64}
: (tensor<1x3x4x4xf32>, tensor<1x3x1x1xf32>) -> tensor<1x1x4x4xf32>
IR Dataclass
ConvolutionOp(
result_name="%v1",
lhs="%arg0", # input tensor
rhs="%v0", # kernel tensor
lhs_type=TensorType([1,3,4,4], "f32"), # [N, C_IN, H, W]
rhs_type=TensorType([1,3,1,1], "f32"), # [C_OUT, C_IN, KH, KW]
result_type=TensorType([1,1,4,4], "f32"),# [N, C_OUT, OH, OW]
strides=[1, 1],
padding=[[0, 0], [0, 0]],
rhs_dilate=[1, 1],
batch_group_count=1,
feature_group_count=1
)
Generated C (1×1 Optimized)
When kernel is 1×1, stride is 1, and padding is 0:
// 1x1 convolution: 3 input channels -> 1 output channels
for (int i = 0; i < 16; i++) {
float sum = 0.0f;
for (int c = 0; c < 3; c++) {
sum += input_0[c * 16 + i] * v0[c];
}
output_0[i] = sum;
}
Generated C (General Case)
For non-1×1 kernels:
// General convolution: [N,C_IN,IH,IW] * [C_OUT,C_IN,KH,KW] -> [N,C_OUT,OH,OW]
for (int n_idx = 0; n_idx < N; n_idx++) {
for (int oc = 0; oc < C_OUT; oc++) {
for (int oh_idx = 0; oh_idx < OH; oh_idx++) {
for (int ow_idx = 0; ow_idx < OW; ow_idx++) {
float sum = 0.0f;
for (int ic = 0; ic < C_IN; ic++) {
for (int kh_idx = 0; kh_idx < KH; kh_idx++) {
for (int kw_idx = 0; kw_idx < KW; kw_idx++) {
int ih_idx = oh_idx * STRIDE_H + kh_idx * DIL_H;
int iw_idx = ow_idx * STRIDE_W + kw_idx * DIL_W;
sum += input[...] * kernel[...];
}
}
}
output[...] = sum;
}
}
}
}
Unsupported Operations
Operations not listed above are silently skipped during parsing. Common StableHLO operations that are NOT yet supported:
-
stablehlo.dot_general(matrix multiply — use convolution instead) -
stablehlo.transpose -
stablehlo.reshape -
stablehlo.broadcast_in_dim -
stablehlo.maximum/stablehlo.minimum -
stablehlo.reduce -
stablehlo.concatenate -
stablehlo.slice -
stablehlo.gather/stablehlo.scatter