brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.9 KiB · 814acd6 Raw
59 lines · plain
1// RUN: mlir-opt %s --sparse-reinterpret-map -sparsification | FileCheck %s2 3#SM = #sparse_tensor.encoding<{ map = (d0, d1) -> (d0 : dense, d1 : compressed) }>4 5#trait = {6  indexing_maps = [7    affine_map<(i,j) -> (i,j)> // A8  ],9  iterator_types = ["parallel", "parallel"],10  doc = "A(i,j) += 2.0 where A(i,j) != 0"11}12 13module {14  // Example of a semi-ring operation that only adds a15  // constant at stored values (something that would16  // typically not sparsify since it would densify the17  // implicit zeros in the normal case). The sparse18  // compiler should see that this is a "simply dynamic"19  // operation, and the values can be change "in-place".20  //21  // CHECK-LABEL: func.func @add_only_where_nonzero(22  // CHECK-SAME:    %[[VAL_0:.*]]: tensor<8x8xf64, #sparse{{[0-9]*}}>) -> tensor<8x8xf64, #sparse{{[0-9]*}}> {23  // CHECK-DAG:     %[[VAL_1:.*]] = arith.constant 8 : index24  // CHECK-DAG:     %[[VAL_2:.*]] = arith.constant 0 : index25  // CHECK-DAG:     %[[VAL_3:.*]] = arith.constant 1 : index26  // CHECK-DAG:     %[[VAL_4:.*]] = arith.constant 2.000000e+00 : f6427  // CHECK-DAG:     %[[VAL_5:.*]] = sparse_tensor.positions %[[VAL_0]] {level = 1 : index} : tensor<8x8xf64, #sparse{{[0-9]*}}> to memref<?xindex>28  // CHECK-DAG:     %[[VAL_6:.*]] = sparse_tensor.values %[[VAL_0]] : tensor<8x8xf64, #sparse{{[0-9]*}}> to memref<?xf64>29  // CHECK:         scf.for %[[VAL_7:.*]] = %[[VAL_2]] to %[[VAL_1]] step %[[VAL_3]] {30  // CHECK:           %[[VAL_8:.*]] = memref.load %[[VAL_5]]{{\[}}%[[VAL_7]]] : memref<?xindex>31  // CHECK:           %[[VAL_9:.*]] = arith.addi %[[VAL_7]], %[[VAL_3]] : index32  // CHECK:           %[[VAL_10:.*]] = memref.load %[[VAL_5]]{{\[}}%[[VAL_9]]] : memref<?xindex>33  // CHECK:           scf.for %[[VAL_11:.*]] = %[[VAL_8]] to %[[VAL_10]] step %[[VAL_3]] {34  // CHECK:             %[[VAL_12:.*]] = memref.load %[[VAL_6]]{{\[}}%[[VAL_11]]] : memref<?xf64>35  // CHECK:             %[[VAL_13:.*]] = arith.addf %[[VAL_12]], %[[VAL_4]] : f6436  // CHECK:             memref.store %[[VAL_13]], %[[VAL_6]]{{\[}}%[[VAL_11]]] : memref<?xf64>37  // CHECK:           } {"Emitted from" = "linalg.generic"}38  // CHECK:         } {"Emitted from" = "linalg.generic"}39  // CHECK:         %[[VAL_14:.*]] = sparse_tensor.load %[[VAL_0]] : tensor<8x8xf64, #sparse{{[0-9]*}}>40  // CHECK:         return %[[VAL_14]] : tensor<8x8xf64, #sparse{{[0-9]*}}>41  // CHECK:       }42  func.func @add_only_where_nonzero(%argA: tensor<8x8xf64, #SM>) -> tensor<8x8xf64, #SM> {43    %c = arith.constant 2.0 : f6444    %result = linalg.generic #trait45      outs(%argA: tensor<8x8xf64, #SM>) {46        ^bb(%a: f64):47           %u = sparse_tensor.unary %a : f64 to f6448             present={49                ^bb0(%p: f64):50                  %add = arith.addf %p, %c : f6451                  sparse_tensor.yield %add : f6452             }53             absent={}54           linalg.yield %u : f6455    } -> tensor<8x8xf64, #SM>56    return %result : tensor<8x8xf64, #SM>57  }58}59