xref: /llvm-project/mlir/test/Dialect/SparseTensor/sparse_batch.mlir (revision ced2fc7819d5ddea616ec330f18e08ff284c1868)
1// RUN: mlir-opt %s --sparse-reinterpret-map -sparsification | FileCheck %s
2
3#map = affine_map<(d0, d1, d2) -> (d0, d1, d2)>
4#BCSR = #sparse_tensor.encoding<{ map = (d0, d1, d2) -> (d0 : batch, d1 : dense, d2 : compressed)}>
5
6// CHECK-LABEL:   func.func @main(
7// CHECK-SAME:      %[[VAL_0:.*]]: tensor<8x4x2xf32, #sparse{{[0-9]*}}>) -> tensor<8x4x2xf32> {
8// CHECK-DAG:       %[[VAL_1:.*]] = arith.constant 1 : index
9// CHECK-DAG:       %[[VAL_2:.*]] = arith.constant 0 : index
10// CHECK-DAG:       %[[VAL_3:.*]] = arith.constant 0.000000e+00 : f32
11// CHECK-DAG:       %[[VAL_4:.*]] = arith.constant 4 : index
12// CHECK-DAG:       %[[VAL_5:.*]] = arith.constant 8 : index
13// CHECK-DAG:       %[[VAL_6:.*]] = tensor.empty() : tensor<8x4x2xf32>
14// CHECK-DAG:       %[[VAL_7:.*]] = sparse_tensor.positions %[[VAL_0]] {level = 2 : index} : tensor<8x4x2xf32, #sparse{{[0-9]*}}> to memref<8x?xindex>
15// CHECK-DAG:       %[[VAL_8:.*]] = sparse_tensor.coordinates %[[VAL_0]] {level = 2 : index} : tensor<8x4x2xf32, #sparse{{[0-9]*}}> to memref<8x?xindex>
16// CHECK-DAG:       %[[VAL_9:.*]] = sparse_tensor.values %[[VAL_0]] : tensor<8x4x2xf32, #sparse{{[0-9]*}}> to memref<8x?xf32>
17// CHECK-DAG:       %[[VAL_10:.*]] = bufferization.to_memref %[[VAL_6]] : tensor<8x4x2xf32>
18// CHECK-DAG:       linalg.fill ins(%[[VAL_3]] : f32) outs(%[[VAL_10]] : memref<8x4x2xf32>)
19// CHECK:           scf.for %[[VAL_11:.*]] = %[[VAL_2]] to %[[VAL_5]] step %[[VAL_1]] {
20// CHECK:             scf.for %[[VAL_12:.*]] = %[[VAL_2]] to %[[VAL_4]] step %[[VAL_1]] {
21// CHECK:               %[[VAL_13:.*]] = memref.load %[[VAL_7]]{{\[}}%[[VAL_11]], %[[VAL_12]]] : memref<8x?xindex>
22// CHECK:               %[[VAL_14:.*]] = arith.addi %[[VAL_12]], %[[VAL_1]] : index
23// CHECK:               %[[VAL_15:.*]] = memref.load %[[VAL_7]]{{\[}}%[[VAL_11]], %[[VAL_14]]] : memref<8x?xindex>
24// CHECK:               scf.for %[[VAL_16:.*]] = %[[VAL_13]] to %[[VAL_15]] step %[[VAL_1]] {
25// CHECK:                 %[[VAL_17:.*]] = memref.load %[[VAL_8]]{{\[}}%[[VAL_11]], %[[VAL_16]]] : memref<8x?xindex>
26// CHECK:                 %[[VAL_18:.*]] = memref.load %[[VAL_9]]{{\[}}%[[VAL_11]], %[[VAL_16]]] : memref<8x?xf32>
27// CHECK:                 %[[VAL_19:.*]] = arith.negf %[[VAL_18]] : f32
28// CHECK:                 memref.store %[[VAL_19]], %[[VAL_10]]{{\[}}%[[VAL_11]], %[[VAL_12]], %[[VAL_17]]] : memref<8x4x2xf32>
29// CHECK:               }
30// CHECK:             }
31// CHECK:           }
32// CHECK:           %[[VAL_20:.*]] = bufferization.to_tensor %[[VAL_10]] : memref<8x4x2xf32>
33// CHECK:           return %[[VAL_20]] : tensor<8x4x2xf32>
34// CHECK:         }
35func.func @main(%arg0: tensor<8x4x2xf32, #BCSR>) -> tensor<8x4x2xf32> {
36  %0 = tensor.empty() : tensor<8x4x2xf32>
37  %1 = linalg.generic {
38    indexing_maps = [#map, #map],
39    iterator_types = ["parallel", "parallel", "parallel"]
40  }
41  ins(%arg0 : tensor<8x4x2xf32, #BCSR>)
42  outs(%0 : tensor<8x4x2xf32>) {
43  ^bb0(%in: f32, %out: f32):
44    %2 = arith.negf %in : f32
45    linalg.yield %2 : f32
46  } -> tensor<8x4x2xf32>
47  return %1 : tensor<8x4x2xf32>
48}
49