brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · 526c3f4 Raw
58 lines · plain
1// RUN: mlir-opt %s --sparse-reinterpret-map -sparsification | FileCheck %s2 3//4// A contrived example where the sparse tensor B is only5// used in the linalg op to determine the number of iterations6// for the k-loop. This is included to make sure the sparse7// compiler still generates the correct loop nest for this case.8//9 10#SM = #sparse_tensor.encoding<{ map = (d0, d1) -> (d0 : dense, d1 : compressed) }>11 12#trait = {13  indexing_maps = [14    affine_map<(i,j,k) -> (i,j)>,  // A15    affine_map<(i,j,k) -> (k,j)>,  // B16    affine_map<(i,j,k) -> (i,j)>   // S_out17  ],18  iterator_types = ["parallel", "parallel", "reduction"],19  doc = "C(i,j) = SUM_k A(i,j)"20}21 22// CHECK-LABEL:   func.func @b_ununsed(23// CHECK-SAME:      %[[VAL_0:.*]]: tensor<2x4xf64>,24// CHECK-SAME:      %[[VAL_1:.*]]: tensor<8x4xf64, #sparse{{[0-9]*}}>,25// CHECK-SAME:      %[[VAL_2:.*]]: tensor<2x4xf64>) -> tensor<2x4xf64> {26// CHECK-DAG:       %[[VAL_3:.*]] = arith.constant 8 : index27// CHECK-DAG:       %[[VAL_4:.*]] = arith.constant 2 : index28// CHECK-DAG:       %[[VAL_5:.*]] = arith.constant 4 : index29// CHECK-DAG:       %[[VAL_6:.*]] = arith.constant 0 : index30// CHECK-DAG:       %[[VAL_7:.*]] = arith.constant 1 : index31// CHECK-DAG:       %[[VAL_8:.*]] = bufferization.to_buffer %[[VAL_0]] : tensor<2x4xf64>32// CHECK-DAG:       %[[VAL_9:.*]] = bufferization.to_buffer %[[VAL_2]] : tensor<2x4xf64>33// CHECK:           scf.for %[[VAL_10:.*]] = %[[VAL_6]] to %[[VAL_4]] step %[[VAL_7]] {34// CHECK:             scf.for %[[VAL_11:.*]] = %[[VAL_6]] to %[[VAL_3]] step %[[VAL_7]] {35// CHECK:               scf.for %[[VAL_12:.*]] = %[[VAL_6]] to %[[VAL_5]] step %[[VAL_7]] {36// CHECK:                 %[[VAL_13:.*]] = memref.load %[[VAL_9]]{{\[}}%[[VAL_10]], %[[VAL_12]]] : memref<2x4xf64>37// CHECK:                 %[[VAL_14:.*]] = memref.load %[[VAL_8]]{{\[}}%[[VAL_10]], %[[VAL_12]]] : memref<2x4xf64>38// CHECK:                 %[[VAL_15:.*]] = arith.addf %[[VAL_13]], %[[VAL_14]] : f6439// CHECK:                 memref.store %[[VAL_15]], %[[VAL_9]]{{\[}}%[[VAL_10]], %[[VAL_12]]] : memref<2x4xf64>40// CHECK:               }41// CHECK:             }42// CHECK:           }43// CHECK:           %[[VAL_16:.*]] = bufferization.to_tensor %[[VAL_9]] : memref<2x4xf64>44// CHECK:           return %[[VAL_16]] : tensor<2x4xf64>45// CHECK:         }46func.func @b_ununsed(%argA: tensor<2x4xf64>,47                     %argB: tensor<8x4xf64, #SM>,48                     %argC: tensor<2x4xf64>) -> tensor<2x4xf64> {49  %result = linalg.generic #trait50    ins(%argA, %argB: tensor<2x4xf64>, tensor<8x4xf64, #SM>)51    outs(%argC: tensor<2x4xf64>) {52      ^bb(%a: f64, %b: f64, %c: f64):53         %0 = arith.addf %c, %a : f6454         linalg.yield %0 : f6455  } -> tensor<2x4xf64>56  return %result : tensor<2x4xf64>57}58