xref: /llvm-project/mlir/test/Dialect/SparseTensor/one_trip.mlir (revision c5a67e16b6117d0c37d004dd5467b56be006ad8f)
1// RUN: mlir-opt %s --sparse-reinterpret-map -sparsification -cse | FileCheck %s
2
3#Dense = #sparse_tensor.encoding<{
4  map = (d0, d1) -> (d0 : dense, d1 : dense)
5}>
6
7#trait_scale = {
8  indexing_maps = [
9    affine_map<(i,j) -> (i,j)>  // X (out)
10  ],
11  iterator_types = ["parallel", "parallel"],
12  doc = "X(i,j) = X(i,j) * 2.0"
13}
14
15// CHECK-LABEL: func.func @sparse_scale(
16// CHECK-SAME:    %[[VAL_0:.*]]: tensor<1x1xf32, #sparse{{[0-9]*}}>)
17// CHECK-DAG:     %[[VAL_1:.*]] = arith.constant 0 : index
18// CHECK-DAG:     %[[VAL_2:.*]] = arith.constant 2.000000e+00 : f32
19// CHECK:         %[[VAL_3:.*]] = sparse_tensor.values %[[VAL_0]] : tensor<1x1xf32, #sparse{{[0-9]*}}> to memref<?xf32>
20// CHECK:         %[[VAL_4:.*]] = memref.load %[[VAL_3]]{{\[}}%[[VAL_1]]] : memref<?xf32>
21// CHECK:         %[[VAL_5:.*]] = arith.mulf %[[VAL_4]], %[[VAL_2]] : f32
22// CHECK:         memref.store %[[VAL_5]], %[[VAL_3]]{{\[}}%[[VAL_1]]] : memref<?xf32>
23// CHECK:         %[[VAL_6:.*]] = sparse_tensor.load %[[VAL_0]] : tensor<1x1xf32, #sparse{{[0-9]*}}>
24// CHECK:         return %[[VAL_6]] : tensor<1x1xf32, #sparse{{[0-9]*}}>
25func.func @sparse_scale(%argx: tensor<1x1xf32, #Dense>) -> tensor<1x1xf32, #Dense> {
26  %c = arith.constant 2.0 : f32
27  %0 = linalg.generic #trait_scale
28    outs(%argx: tensor<1x1xf32, #Dense>) {
29      ^bb(%x: f32):
30        %1 = arith.mulf %x, %c : f32
31        linalg.yield %1 : f32
32  } -> tensor<1x1xf32, #Dense>
33  return %0 : tensor<1x1xf32, #Dense>
34}
35