1// RUN: mlir-opt %s -convert-linalg-to-std -convert-linalg-to-llvm \
2// RUN: | mlir-cpu-runner -e dot -entry-point-result=f32 -shared-libs=%linalg_test_lib_dir/libmlir_test_cblas%shlibext,%linalg_test_lib_dir/libmlir_test_cblas_interface%shlibext \
3// RUN: | FileCheck %s
4
5// RUN: mlir-opt %s -convert-linalg-to-loops -convert-linalg-to-std -convert-linalg-to-llvm \
6// RUN: | mlir-cpu-runner -e dot -entry-point-result=f32 -shared-libs=%linalg_test_lib_dir/libmlir_test_cblas%shlibext,%linalg_test_lib_dir/libmlir_test_cblas_interface%shlibext \
7// RUN: | FileCheck %s
8
9// RUN: mlir-opt %s -convert-linalg-to-std -convert-linalg-to-llvm \
10// RUN: | mlir-cpu-runner -e matmul -entry-point-result=f32 -shared-libs=%linalg_test_lib_dir/libmlir_test_cblas%shlibext,%linalg_test_lib_dir/libmlir_test_cblas_interface%shlibext \
11// RUN: | FileCheck %s
12
13// RUN: mlir-opt %s -convert-linalg-to-loops -convert-linalg-to-std -convert-linalg-to-llvm \
14// RUN: | mlir-cpu-runner -e matmul -entry-point-result=f32 -shared-libs=%linalg_test_lib_dir/libmlir_test_cblas%shlibext,%linalg_test_lib_dir/libmlir_test_cblas_interface%shlibext \
15// RUN: | FileCheck %s
16
17// RUN: mlir-opt %s -linalg-tile="linalg-tile-sizes=2,3,4" -linalg-promote-subviews -convert-linalg-to-loops -convert-linalg-to-std -convert-linalg-to-llvm \
18// RUN: | mlir-cpu-runner -e matmul -entry-point-result=f32 -shared-libs=%linalg_test_lib_dir/libmlir_test_cblas%shlibext,%linalg_test_lib_dir/libmlir_test_cblas_interface%shlibext \
19// RUN: | FileCheck %s
20
21// RUN: mlir-opt %s -linalg-tile="linalg-tile-sizes=2,3,4" -linalg-promote-subviews -convert-linalg-to-std -convert-linalg-to-llvm \
22// RUN: | mlir-cpu-runner -e matmul -entry-point-result=f32 -shared-libs=%linalg_test_lib_dir/libmlir_test_cblas%shlibext,%linalg_test_lib_dir/libmlir_test_cblas_interface%shlibext \
23// RUN: | FileCheck %s
24
25// Creates and returns a 1-D buffer of size %s filled with the value %f
26func @alloc_filled_f32(%s : index, %f : f32) -> memref<?xi8> {
27  %c0 = constant 0 : index
28  %c1 = constant 1 : index
29  %c4 = constant 4 : index
30  %s4 = muli %s, %c4: index
31  %buf = alloc(%s4) {alignment = 256} : memref<?xi8>
32  %V = view %buf[%c0][%s] : memref<?xi8> to memref<?xf32>
33  linalg.fill(%V, %f) : memref<?xf32>, f32
34  return %buf : memref<?xi8>
35}
36
37// Test for linalg.dot.
38func @dot() -> f32 {
39  %c0 = constant 0 : index
40  %c1 = constant 1 : index
41  %c16 = constant 16 : index
42  %f10 = constant 10.00000e+00 : f32
43  %f1 = constant 1.00000e+00 : f32
44  %f2 = constant 2.00000e+00 : f32
45
46  %bA = call @alloc_filled_f32(%c16, %f2) : (index, f32) -> (memref<?xi8>)
47  %bB = call @alloc_filled_f32(%c16, %f1) : (index, f32) -> (memref<?xi8>)
48  %bC = call @alloc_filled_f32(%c1, %f10) : (index, f32) -> (memref<?xi8>)
49
50  %A = view %bA[%c0][%c16] : memref<?xi8> to memref<?xf32>
51  %B = view %bB[%c0][%c16] : memref<?xi8> to memref<?xf32>
52  %C = view %bC[%c0][] : memref<?xi8> to memref<f32>
53
54  linalg.dot ins(%A, %B : memref<?xf32>, memref<?xf32>)
55            outs(%C : memref<f32>)
56  %res = load %C[] : memref<f32>
57
58  dealloc %bC : memref<?xi8>
59  dealloc %bB : memref<?xi8>
60  dealloc %bA : memref<?xi8>
61
62  return %res : f32
63}
64
65// Test for linalg.matmul.
66func @matmul() -> f32 {
67  %c0 = constant 0 : index
68  %c1 = constant 1 : index
69  %c6 = constant 6 : index
70  %c7 = constant 7 : index
71  %c2 = constant 2 : index
72  %c16 = constant 16 : index
73  %c4 = constant 4 : index
74  %c32 = constant 32 : index
75  %f1 = constant 1.00000e+00 : f32
76  %f2 = constant 2.00000e+00 : f32
77  %f10 = constant 10.00000e+00 : f32
78
79  %bA = call @alloc_filled_f32(%c32, %f2) : (index, f32) -> (memref<?xi8>)
80  %bB = call @alloc_filled_f32(%c32, %f1) : (index, f32) -> (memref<?xi8>)
81  %bC = call @alloc_filled_f32(%c4, %f10) : (index, f32) -> (memref<?xi8>)
82
83  %A = view %bA[%c0][%c2, %c16] : memref<?xi8> to memref<?x?xf32>
84  %B = view %bB[%c0][%c16, %c2] : memref<?xi8> to memref<?x?xf32>
85  %C = view %bC[%c0][%c2, %c2] : memref<?xi8> to memref<?x?xf32>
86
87  linalg.matmul ins(%A, %B : memref<?x?xf32>, memref<?x?xf32>)
88               outs(%C : memref<?x?xf32>)
89  %res = load %C[%c0, %c1] : memref<?x?xf32>
90
91  dealloc %bC : memref<?xi8>
92  dealloc %bB : memref<?xi8>
93  dealloc %bA : memref<?xi8>
94
95  return %res : f32
96}
97
98// All tests return this value
99// CHECK: 4.2{{0+}}e+01
100