1 // RUN: mlir-opt %s -convert-linalg-to-loops -convert-scf-to-std -convert-linalg-to-llvm -lower-affine -convert-scf-to-std --convert-memref-to-llvm -convert-std-to-llvm -reconcile-unrealized-casts | \
2 // RUN: mlir-cpu-runner -e main -entry-point-result=void \
3 // RUN: -shared-libs=%mlir_integration_test_dir/libmlir_runner_utils%shlibext \
6 // RUN: mlir-opt %s -linalg-tile="tile-sizes=2,2" -convert-linalg-to-loops -convert-scf-to-std \
7 // RUN: -convert-linalg-to-llvm -lower-affine -convert-scf-to-std --convert-memref-to-llvm -convert-std-to-llvm -reconcile-unrealized-casts | \
8 // RUN: mlir-cpu-runner -e main -entry-point-result=void \
9 // RUN: -shared-libs=%mlir_integration_test_dir/libmlir_runner_utils%shlibext \
10 // RUN: | FileCheck %s
12 func private @print_memref_f32(memref<*xf32>)
14 // Creates and returns a 2-D buffer of size (%s1, %s2) filled with the value %f
15 func @alloc_2d_filled_f32(%s1 : index, %s2 : index, %f : f32) -> memref<?x?xf32> {
16 %buf = memref.alloc(%s1, %s2) : memref<?x?xf32>
17 linalg.fill(%f, %buf) : f32, memref<?x?xf32>
18 return %buf : memref<?x?xf32>
21 func @conv_2d(%arg0: memref<?x?xf32>, %arg1: memref<?x?xf32>, %arg2: memref<?x?xf32>) {
22 linalg.conv_2d ins (%arg0, %arg1: memref<?x?xf32>, memref<?x?xf32>)
23 outs (%arg2: memref<?x?xf32>)
28 %c0 = arith.constant 0 : index
29 %c1 = arith.constant 1 : index
30 %c3 = arith.constant 3 : index
31 %c6 = arith.constant 6 : index
32 %c8 = arith.constant 8 : index
33 %f10 = arith.constant 10.00000e+00 : f32
34 %val = arith.constant 2.00000e+00 : f32
35 %zero = arith.constant 0.00000e+00 : f32
37 %filter2D = call @alloc_2d_filled_f32(%c3, %c3, %val) : (index, index, f32) -> (memref<?x?xf32>)
38 %in2D = call @alloc_2d_filled_f32(%c8, %c8, %val) : (index, index, f32) -> (memref<?x?xf32>)
39 %out2D = call @alloc_2d_filled_f32(%c6, %c6, %zero) : (index, index, f32) -> (memref<?x?xf32>)
41 memref.store %f10, %in2D[%c0, %c3] : memref<?x?xf32>
42 call @conv_2d(%in2D, %filter2D, %out2D) : (memref<?x?xf32>, memref<?x?xf32>, memref<?x?xf32>) -> ()
43 %out2D_ = memref.cast %out2D : memref<?x?xf32> to memref<*xf32>
44 call @print_memref_f32(%out2D_): (memref<*xf32>) -> ()
46 memref.dealloc %filter2D : memref<?x?xf32>
47 memref.dealloc %in2D : memref<?x?xf32>
48 memref.dealloc %out2D : memref<?x?xf32>
52 // CHECK: Unranked Memref {{.*}}
54 // CHECK-SAME: [36, 52, 52, 52, 36, 36],
55 // CHECK-COUNT-5: [36, 36, 36, 36, 36, 36]