// RUN: mlir-opt %s -convert-linalg-to-loops -convert-linalg-to-llvm | \ // RUN: mlir-cpu-runner -O3 -e main -entry-point-result=void \ // RUN: -shared-libs=%mlir_integration_test_dir/libmlir_runner_utils%shlibext \ // RUN: | FileCheck %s func private @print_memref_f32(memref<*xf32>) func @matmul(%A: memref, %B: memref) -> (memref) { %c0 = constant 0 : index %c1 = constant 1 : index %f0 = constant 0.0 : f32 %x = dim %A, %c0 : memref %y = dim %B, %c1 : memref %C = alloc(%x, %y) : memref linalg.fill(%C, %f0) : memref, f32 linalg.matmul ins(%A, %B: memref, memref) outs(%C: memref) return %C : memref } func @matvec(%A: memref, %B: memref) -> (memref) { %c0 = constant 0 : index %c1 = constant 1 : index %f0 = constant 0.0 : f32 %m = dim %A, %c0 : memref %x = dim %A, %c1 : memref %n = dim %B, %c1 : memref %C = alloc(%m, %n) : memref linalg.fill(%C, %f0) : memref, f32 scf.for %i = %c0 to %n step %c1 { %b = subview %B[0, %i][%x, 1][1, 1] : memref to memref %c = subview %C[0, %i][%m, 1][1, 1] : memref to memref linalg.matvec ins(%A, %b: memref, memref) outs(%c: memref) } return %C : memref } func @main() { %c0 = constant 0 : index %c1 = constant 1 : index %m = constant 5 : index %x = constant 3 : index %n = constant 2 : index %val1 = constant 13.0 : f32 %val2 = constant 17.0 : f32 %A = alloc(%m, %x) : memref %B = alloc(%x, %n) : memref linalg.fill(%A, %val1) : memref, f32 linalg.fill(%B, %val2) : memref, f32 store %val1, %B[%c0, %c0] : memref %C1 = call @matmul(%A, %B) : (memref, memref) -> memref %C2 = call @matvec(%A, %B) : (memref, memref) -> memref scf.for %i = %c0 to %m step %c1 { scf.for %j = %c0 to %n step %c1 { %e1 = load %C1[%i, %j] : memref %e2 = load %C2[%i, %j] : memref %c = cmpf "oeq", %e1, %e2 : f32 assert %c, "Matmul does not produce same output as matvec" } } %C2_ = memref_cast %C2 : memref to memref<*xf32> call @print_memref_f32(%C2_) : (memref<*xf32>) -> () return } // CHECK: Unranked Memref base@ = {{.*}} rank = 2 offset = 0 sizes = [5, 2] strides = [2, 1] data = // CHECK-NEXT: [ // CHECK-SAME: [611, 663], // CHECK-NEXT: [611, 663], // CHECK-NEXT: [611, 663], // CHECK-NEXT: [611, 663], // CHECK-NEXT: [611, 663] // CHECK-SAME: ]