Skip to content

Instantly share code, notes, and snippets.

View matthias-springer's full-sized avatar

Matthias Springer matthias-springer

View GitHub Profile
@matthias-springer
matthias-springer / pattern_rollback_failure.mlir
Created October 3, 2025 13:06
pattern_rollback_failure.mlir
// RUN: mlir-opt %s --test-emulate-narrow-int="arith-compute-bitwidth=1 memref-load-bitwidth=8"
func.func @vector_load_i4(%arg0: index, %arg1: index, %arg2: index, %arg3: index) -> vector<128xi4> {
%0 = memref.alloc(%arg0, %arg1) : memref<?x?xi4>
%1 = vector.load %0[%arg2, %arg3] : memref<?x?xi4>, vector<128xi4>
return %1 : vector<128xi4>
}
func.func @foo() {
"foo"() {attr = [0.0 : f8E4M3, 1.0 : f8E4M3, 2.0 : f8E4M3FNUZ, 3.0 : f4E2M1FN, 4.0 : f8E8M0FNU, 5.0 : f6E2M3FN, 6.0 : f8E4M3FN, 7.0 : f8E5M2FNUZ, 8.0 : tf32, 9.0 : f80, 10.0 : f64, 11.0 : f6E2M3FN, 12.0 : f8E3M4, 13.0 : bf16, 14.0 : f6E2M3FN, 15.0 : f8E3M4, 16.0 : tf32, 17.0 : f32, 18.0 : f8E4M3FNUZ, 19.0 : f8E4M3B11FNUZ, 20.0 : f8E3M4, 21.0 : f8E4M3B11FNUZ, 22.0 : f6E3M2FN, 23.0 : f80, 24.0 : f8E8M0FNU, 25.0 : f16, 26.0 : f8E4M3FN, 27.0 : f8E4M3B11FNUZ, 28.0 : f128, 29.0 : tf32, 30.0 : f4E2M1FN, 31.0 : f6E2M3FN, 32.0 : f8E8M0FNU, 33.0 : f8E4M3FNUZ, 34.0 : f8E3M4, 35.0 : f8E4M3B11FNUZ, 36.0 : f8E8M0FNU, 37.0 : f8E4M3, 38.0 : tf32, 39.0 : f8E3M4, 40.0 : f64, 41.0 : f80, 42.0 : f6E2M3FN, 43.0 : f16, 44.0 : bf16, 45.0 : f8E4M3FN, 46.0 : f16, 47.0 : f32, 48.0 : f6E2M3FN, 49.0 : f8E3M4, 50.0 : f8E3M4, 51.0 : f8E4M3, 52.0 : f8E4M3FN, 53.0 : f4E2M1FN, 54.0 : f8E4M3FNUZ, 55.0 : f64, 56.0 : f8E4M3FN, 57.0 : f6E3M2FN, 58.0 : f80, 59.0 : f8E8M0FNU, 60.0 : f32, 61.0 : f32, 62.0 : tf32, 63.0 : f128, 6
// RUN: mlir-opt %s -test-transform-dialect-interpreter="debug-payload-root-tag=payload"
module attributes {transform.target_tag="payload"} {
// Batched TOSA matrix multiplication. %A and %B are the inputs, %C is the
// output.
func.func @test_matmul(%A: memref<1x17x19xf32>, %B: memref<1x19x29xf32>,
%C: memref<1x17x29xf32>) {
%A_tensor = bufferization.to_tensor %A restrict : memref<1x17x19xf32>
%B_tensor = bufferization.to_tensor %B restrict : memref<1x19x29xf32>
// RUN: mlir-opt %s -test-transform-dialect-interpreter="debug-payload-root-tag=payload"
module attributes {transform.target_tag="payload"} {
func.func @test(%f0: f32, %f1: f32, %out: memref<3xf32>) {
// Create a new tensor with [%f0, %f0, %f0].
%0 = tensor.from_elements %f0, %f0, %f0 : tensor<3xf32>
// Result should be stored in %out.
bufferization.materialize_in_destination %0 in restrict writable %out
// RUN: mlir-opt %s -test-transform-dialect-interpreter="debug-payload-root-tag=payload"
module attributes {transform.target_tag="payload"} {
// TOSA element-wise addition. %A and %B are the inputs, %C is the output.
func.func @test_matmul(%A_tensor: tensor<100xf32>, %B_tensor: tensor<100xf32>,
%C_tensor: tensor<100xf32>) -> tensor<100xf32> {
%0 = tosa.add %A_tensor, %B_tensor
: (tensor<100xf32>, tensor<100xf32>) -> tensor<100xf32>
%r = bufferization.materialize_in_destination %0 in %C_tensor
// RUN: mlir-opt %s -test-transform-dialect-interpreter="debug-payload-root-tag=payload" -transform-dialect-drop-schedule
module attributes {transform.target_tag="payload"} {
// Batched TOSA matrix multiplication. %A and %B are the inputs, %C is the
// output.
func.func @test_matmul(%A: memref<1x17x19xf32>, %B: memref<1x19x29xf32>,
%C: memref<1x17x29xf32>) {
%A_tensor = bufferization.to_tensor %A restrict : memref<1x17x19xf32>
%B_tensor = bufferization.to_tensor %B restrict : memref<1x19x29xf32>
@matthias-springer
matthias-springer / presentation_urls.txt
Last active September 20, 2025 22:53
MLIR Bufferization: From Tensors to MemRefs
Debugging Spurious Copies: Mini Example
https://gist.github.com/matthias-springer/81748fe1e530974dd5ff6b3ad57e3eeb
Debugging Spurious Copies: Matmul, Tiled
https://gist.github.com/matthias-springer/372162baa30e79c49180bb3ace216995
https://gist.github.com/matthias-springer/b664feb23be0159f72726025923bb9ca
Empty Tensor Elimination
https://gist.github.com/matthias-springer/b3f40d1667c977c29a76cc7a469cc1a0
https://gist.github.com/matthias-springer/e531580242d27f14e0a239e0b6fe80ae
// RUN: mlir-opt %s -test-transform-dialect-interpreter="debug-payload-root-tag=payload"
module attributes {transform.target_tag="payload"} {
func.func @test(%f0: f32, %f1: f32, %out: memref<3xf32>) {
// Create a new tensor with [%f0, %f0, %f0].
%0 = tensor.from_elements %f0, %f0, %f0 : tensor<3xf32>
bufferization.materialize_in_destination %0 in restrict writable %out
: (tensor<3xf32>, memref<3xf32>) -> ()
func.return
// RUN: mlir-opt %s -test-transform-dialect-interpreter="debug-payload-root-tag=payload"
module attributes {transform.target_tag="payload"} {
func.func @test(%f0: f32, %f1: f32, %idx: index, %idx2: index)
-> (f32, tensor<3xf32>) {
// Create a new tensor with [%f0, %f0, %f0].
%0 = tensor.from_elements %f0, %f0, %f0 : tensor<3xf32>
// Insert something into the new tensor.
// RUN: mlir-opt %s -test-transform-dialect-interpreter="debug-payload-root-tag=payload"
#map = affine_map<(d0) -> (d0)>
module attributes {transform.target_tag="payload"} {
// TOSA element-wise addition. %A and %B are the inputs, %C is the output.
func.func @test_matmul(%arg0: memref<100xf32>, %arg1: memref<100xf32>, %arg2: memref<100xf32>) {
%0 = bufferization.to_tensor %arg0 restrict : memref<100xf32>
%1 = bufferization.to_tensor %arg1 restrict : memref<100xf32>