{"id": "01_matmul-dynamic", "dialect": "linalg+memref+func", "difficulty": "easy", "nl": "Write a function that performs a matrix multiplication of two 2-D f32 memrefs with dynamic shapes and writes the result into a pre-allocated output memref.", "mlir": "module {\n func.func @mm(%A: memref, %B: memref, %C: memref) {\n linalg.matmul ins(%A, %B : memref, memref) outs(%C : memref)\n return\n }\n}\n", "notes": "canonical linalg.matmul"} {"id": "02_matmul-static-2x2", "dialect": "linalg+memref+func", "difficulty": "easy", "nl": "Write a function that performs a 2x2 matrix multiplication of f32 matrices. All inputs are statically-shaped memrefs.", "mlir": "module {\n func.func @mm22(%A: memref<2x2xf32>, %B: memref<2x2xf32>, %C: memref<2x2xf32>) {\n linalg.matmul ins(%A, %B : memref<2x2xf32>, memref<2x2xf32>) outs(%C : memref<2x2xf32>)\n return\n }\n}\n", "notes": "static-shape matmul"} {"id": "03_matmul-rectangular", "dialect": "linalg+memref+func", "difficulty": "medium", "nl": "Write a function that multiplies a 4x8xf32 matrix by an 8x2xf32 matrix, writing to a 4x2xf32 result memref.", "mlir": "module {\n func.func @mm482(%A: memref<4x8xf32>, %B: memref<8x2xf32>, %C: memref<4x2xf32>) {\n linalg.matmul ins(%A, %B : memref<4x8xf32>, memref<8x2xf32>) outs(%C : memref<4x2xf32>)\n return\n }\n}\n", "notes": "rectangular MxK * KxN"} {"id": "04_matmul-f64", "dialect": "linalg+memref+func", "difficulty": "medium", "nl": "Write a function that performs matmul on two f64 2-D memrefs into an f64 output memref.", "mlir": "module {\n func.func @mmf64(%A: memref, %B: memref, %C: memref) {\n linalg.matmul ins(%A, %B : memref, memref) outs(%C : memref)\n return\n }\n}\n", "notes": "f64 matmul"} {"id": "05_fill-matmul-chain", "dialect": "linalg+memref+arith+func", "difficulty": "hard", "nl": "Write a function that zeroes an f32 output memref using linalg.fill, then computes matmul of two input memrefs into it.", "mlir": "module {\n func.func @fm(%A: memref, %B: memref, %C: memref) {\n %z = arith.constant 0.0 : f32\n linalg.fill ins(%z : f32) outs(%C : memref)\n linalg.matmul ins(%A, %B : memref, memref) outs(%C : memref)\n return\n }\n}\n", "notes": "zero-then-matmul idiom"} {"id": "06_fill-zero-1d", "dialect": "linalg+memref+arith+func", "difficulty": "easy", "nl": "Write a function that fills a 1-D f32 memref with zeros.", "mlir": "module {\n func.func @f0(%m: memref) {\n %z = arith.constant 0.0 : f32\n linalg.fill ins(%z : f32) outs(%m : memref)\n return\n }\n}\n", "notes": "zero-fill 1D"} {"id": "07_fill-value-param", "dialect": "linalg+memref+func", "difficulty": "easy", "nl": "Write a function that fills a 2-D f32 memref with a given f32 value passed as a parameter.", "mlir": "module {\n func.func @fp(%v: f32, %m: memref) {\n linalg.fill ins(%v : f32) outs(%m : memref)\n return\n }\n}\n", "notes": "fill with parameter value"} {"id": "08_fill-i32", "dialect": "linalg+memref+arith+func", "difficulty": "easy", "nl": "Write a function that fills a 1-D i32 memref with the integer constant 7.", "mlir": "module {\n func.func @f7(%m: memref) {\n %c7 = arith.constant 7 : i32\n linalg.fill ins(%c7 : i32) outs(%m : memref)\n return\n }\n}\n", "notes": "integer-typed fill"} {"id": "09_copy-1d", "dialect": "linalg+memref+func", "difficulty": "easy", "nl": "Write a function that copies a 1-D f32 memref into another 1-D f32 memref of the same shape.", "mlir": "module {\n func.func @c1(%s: memref, %d: memref) {\n linalg.copy ins(%s : memref) outs(%d : memref)\n return\n }\n}\n", "notes": "1D copy"} {"id": "10_copy-2d-static", "dialect": "linalg+memref+func", "difficulty": "easy", "nl": "Write a function that copies a 4x4xf32 static memref into another 4x4xf32 memref.", "mlir": "module {\n func.func @c2(%s: memref<4x4xf32>, %d: memref<4x4xf32>) {\n linalg.copy ins(%s : memref<4x4xf32>) outs(%d : memref<4x4xf32>)\n return\n }\n}\n", "notes": "2D static copy"} {"id": "11_copy-i32", "dialect": "linalg+memref+func", "difficulty": "easy", "nl": "Write a function that copies a 1-D i32 memref into another 1-D i32 memref of the same shape.", "mlir": "module {\n func.func @ci(%s: memref, %d: memref) {\n linalg.copy ins(%s : memref) outs(%d : memref)\n return\n }\n}\n", "notes": "i32 copy"} {"id": "12_transpose-2d", "dialect": "linalg+memref+func", "difficulty": "medium", "nl": "Write a function that transposes a 2-D f32 memref into another 2-D f32 memref using permutation [1, 0].", "mlir": "module {\n func.func @t2(%s: memref, %d: memref) {\n linalg.transpose ins(%s : memref) outs(%d : memref) permutation = [1, 0]\n return\n }\n}\n", "notes": "2D transpose"} {"id": "13_transpose-3d", "dialect": "linalg+memref+func", "difficulty": "hard", "nl": "Write a function that transposes a 3-D f32 memref using permutation [0, 2, 1] (swap the last two dimensions).", "mlir": "module {\n func.func @t3(%s: memref, %d: memref) {\n linalg.transpose ins(%s : memref) outs(%d : memref) permutation = [0, 2, 1]\n return\n }\n}\n", "notes": "3D transpose"} {"id": "14_transpose-static", "dialect": "linalg+memref+func", "difficulty": "medium", "nl": "Write a function that transposes a 3x5xf32 memref to a 5x3xf32 memref using permutation [1, 0].", "mlir": "module {\n func.func @ts(%s: memref<3x5xf32>, %d: memref<5x3xf32>) {\n linalg.transpose ins(%s : memref<3x5xf32>) outs(%d : memref<5x3xf32>) permutation = [1, 0]\n return\n }\n}\n", "notes": "static-shape transpose"} {"id": "15_broadcast-1d-to-2d", "dialect": "linalg+memref+func", "difficulty": "medium", "nl": "Write a function that broadcasts a 1-D f32 memref to a 2-D f32 memref along the 0th dimension.", "mlir": "module {\n func.func @b1(%s: memref, %d: memref) {\n linalg.broadcast ins(%s : memref) outs(%d : memref) dimensions = [0]\n return\n }\n}\n", "notes": "1D to 2D broadcast, dim 0"} {"id": "16_broadcast-dim1", "dialect": "linalg+memref+func", "difficulty": "medium", "nl": "Write a function that broadcasts a 1-D f32 memref to a 2-D f32 memref along the 1st dimension.", "mlir": "module {\n func.func @b2(%s: memref, %d: memref) {\n linalg.broadcast ins(%s : memref) outs(%d : memref) dimensions = [1]\n return\n }\n}\n", "notes": "1D to 2D broadcast, dim 1"} {"id": "17_matvec", "dialect": "linalg+memref+func", "difficulty": "medium", "nl": "Write a function that performs a matrix-vector multiplication: input is a 2-D f32 memref and a 1-D f32 memref; output is a 1-D f32 memref.", "mlir": "module {\n func.func @mv(%A: memref, %x: memref, %y: memref) {\n linalg.matvec ins(%A, %x : memref, memref) outs(%y : memref)\n return\n }\n}\n", "notes": "canonical matvec"} {"id": "18_matvec-static", "dialect": "linalg+memref+func", "difficulty": "medium", "nl": "Write a function that multiplies a 4x8xf32 matrix by an 8xf32 vector, writing to a 4xf32 result memref.", "mlir": "module {\n func.func @mvs(%A: memref<4x8xf32>, %x: memref<8xf32>, %y: memref<4xf32>) {\n linalg.matvec ins(%A, %x : memref<4x8xf32>, memref<8xf32>) outs(%y : memref<4xf32>)\n return\n }\n}\n", "notes": "static matvec 4x8 by 8"} {"id": "19_matvec-f64", "dialect": "linalg+memref+func", "difficulty": "medium", "nl": "Write a function that performs a matvec on f64 inputs.", "mlir": "module {\n func.func @mvd(%A: memref, %x: memref, %y: memref) {\n linalg.matvec ins(%A, %x : memref, memref) outs(%y : memref)\n return\n }\n}\n", "notes": "f64 matvec"} {"id": "20_add-elemwise", "dialect": "linalg+memref+func", "difficulty": "easy", "nl": "Write a function that adds two 1-D f32 memrefs element-wise into a third output memref.", "mlir": "module {\n func.func @ae(%a: memref, %b: memref, %c: memref) {\n linalg.add ins(%a, %b : memref, memref) outs(%c : memref)\n return\n }\n}\n", "notes": "elemwise add"} {"id": "21_sub-elemwise", "dialect": "linalg+memref+func", "difficulty": "easy", "nl": "Write a function that subtracts two 1-D f32 memrefs element-wise.", "mlir": "module {\n func.func @se(%a: memref, %b: memref, %c: memref) {\n linalg.sub ins(%a, %b : memref, memref) outs(%c : memref)\n return\n }\n}\n", "notes": "elemwise sub"} {"id": "22_mul-elemwise-2d", "dialect": "linalg+memref+func", "difficulty": "medium", "nl": "Write a function that multiplies two 2-D f32 memrefs element-wise (Hadamard product) into an output memref.", "mlir": "module {\n func.func @me(%a: memref, %b: memref, %c: memref) {\n linalg.mul ins(%a, %b : memref, memref) outs(%c : memref)\n return\n }\n}\n", "notes": "Hadamard product"} {"id": "23_div-elemwise", "dialect": "linalg+memref+func", "difficulty": "medium", "nl": "Write a function that divides two 1-D f32 memrefs element-wise.", "mlir": "module {\n func.func @de(%a: memref, %b: memref, %c: memref) {\n linalg.div ins(%a, %b : memref, memref) outs(%c : memref)\n return\n }\n}\n", "notes": "elemwise div"} {"id": "24_exp-elemwise", "dialect": "linalg+memref+func", "difficulty": "easy", "nl": "Write a function that applies the elementwise exponential to a 1-D f32 memref, writing the result into another memref.", "mlir": "module {\n func.func @ee(%x: memref, %y: memref) {\n linalg.exp ins(%x : memref) outs(%y : memref)\n return\n }\n}\n", "notes": "elemwise exp"} {"id": "25_exp-2d", "dialect": "linalg+memref+func", "difficulty": "easy", "nl": "Write a function that applies elementwise exp to a 2-D f32 memref, writing into an output memref of the same shape.", "mlir": "module {\n func.func @e2(%x: memref, %y: memref) {\n linalg.exp ins(%x : memref) outs(%y : memref)\n return\n }\n}\n", "notes": "2D exp"} {"id": "26_abs-elemwise", "dialect": "linalg+memref+func", "difficulty": "easy", "nl": "Write a function that applies the elementwise absolute value to a 1-D f32 memref, writing the result into another memref.", "mlir": "module {\n func.func @ae(%x: memref, %y: memref) {\n linalg.abs ins(%x : memref) outs(%y : memref)\n return\n }\n}\n", "notes": "elemwise abs"} {"id": "27_abs-2d", "dialect": "linalg+memref+func", "difficulty": "easy", "nl": "Write a function that applies elementwise abs to a 2-D f32 memref.", "mlir": "module {\n func.func @a2(%x: memref, %y: memref) {\n linalg.abs ins(%x : memref) outs(%y : memref)\n return\n }\n}\n", "notes": "2D abs"} {"id": "28_fill-then-copy", "dialect": "linalg+memref+arith+func", "difficulty": "hard", "nl": "Write a function that fills a 1-D f32 memref with 1.0 and then copies its contents into a second memref.", "mlir": "module {\n func.func @fc(%m: memref, %d: memref) {\n %one = arith.constant 1.0 : f32\n linalg.fill ins(%one : f32) outs(%m : memref)\n linalg.copy ins(%m : memref) outs(%d : memref)\n return\n }\n}\n", "notes": "fill-then-copy chain"} {"id": "29_add-then-exp", "dialect": "linalg+memref+func", "difficulty": "hard", "nl": "Write a function that adds two 1-D f32 memrefs element-wise into a temporary buffer, then applies exp to the buffer into the final output.", "mlir": "module {\n func.func @ax(%a: memref, %b: memref, %t: memref, %y: memref) {\n linalg.add ins(%a, %b : memref, memref) outs(%t : memref)\n linalg.exp ins(%t : memref) outs(%y : memref)\n return\n }\n}\n", "notes": "add-then-exp chain"} {"id": "30_transpose-then-matmul", "dialect": "linalg+memref+func", "difficulty": "hard", "nl": "Write a function that transposes A (2-D f32) into a temp memref and then performs matmul of transposed A and B.", "mlir": "module {\n func.func @tm(%A: memref, %At: memref, %B: memref, %C: memref) {\n linalg.transpose ins(%A : memref) outs(%At : memref) permutation = [1, 0]\n linalg.matmul ins(%At, %B : memref, memref) outs(%C : memref)\n return\n }\n}\n", "notes": "transpose-then-matmul"}