91 lines · plain
1// RUN: mlir-opt %s --stage-sparse-ops --lower-sparse-ops-to-foreach --canonicalize --cse | FileCheck %s2 3#SparseVector64 = #sparse_tensor.encoding<{4 map = (d0) -> (d0 : compressed),5 posWidth = 64,6 crdWidth = 647}>8 9#SparseVector32 = #sparse_tensor.encoding<{10 map = (d0) -> (d0 : compressed),11 posWidth = 32,12 crdWidth = 3213}>14 15#SparseVector = #sparse_tensor.encoding<{16 map = (d0) -> (d0 : compressed)17}>18 19#SortedCOO2D = #sparse_tensor.encoding<{20 map = (d0, d1) -> (d0 : compressed(nonunique), d1 : singleton),21}>22 23#SortedCOO3D = #sparse_tensor.encoding<{24 map = (d0, d1, d2) -> (d0 : compressed(nonunique), d1 : singleton(nonunique), d2 : singleton)25 26}>27 28#TsssPermuted = #sparse_tensor.encoding<{29 map = (d0, d1, d2) -> (d2 : compressed, d0 : compressed, d1 : compressed)30}>31 32#COOSlice = #sparse_tensor.encoding<{33 map = (d0 : #sparse_tensor<slice(2, 2, 1)>, d1 : #sparse_tensor<slice(12, 13, 1)>) -> (d0 : compressed(nonunique), d1 : singleton)34}>35 36// CHECK-LABEL: func.func @sparse_nop_convert37// CHECK-NEXT: return38func.func @sparse_nop_convert(%arg0: tensor<64xf32, #SparseVector>) -> tensor<64xf32, #SparseVector> {39 %0 = sparse_tensor.convert %arg0 : tensor<64xf32, #SparseVector> to tensor<64xf32, #SparseVector>40 return %0 : tensor<64xf32, #SparseVector>41}42 43// CHECK-LABEL: func.func @sparse_hidden_nop_cast44// CHECK-NEXT: sparse_tensor.convert45// CHECK-NEXT: return46func.func @sparse_hidden_nop_cast(%arg0: tensor<32xf32, #SparseVector>) -> tensor<?xf32, #SparseVector> {47 %0 = sparse_tensor.convert %arg0 : tensor<32xf32, #SparseVector> to tensor<?xf32, #SparseVector>48 return %0 : tensor<?xf32, #SparseVector>49}50 51// CHECK-LABEL: func.func @sparse_convert_1d_ss(52// CHECK-NEXT: sparse_tensor.convert53// CHECK-NEXT: return54func.func @sparse_convert_1d_ss(%arg0: tensor<?xf32, #SparseVector64>) -> tensor<?xf32, #SparseVector32> {55 %0 = sparse_tensor.convert %arg0 : tensor<?xf32, #SparseVector64> to tensor<?xf32, #SparseVector32>56 return %0 : tensor<?xf32, #SparseVector32>57}58 59// CHECK-LABEL: func.func @sparse_convert(60// CHECK-NEXT: sparse_tensor.convert61// CHECK-NEXT: return62func.func @sparse_convert(%arg0: tensor<?xf32, #SparseVector64>) -> tensor<?xf32, #SparseVector32> {63 %0 = sparse_tensor.convert %arg0 : tensor<?xf32, #SparseVector64> to tensor<?xf32, #SparseVector32>64 return %0 : tensor<?xf32, #SparseVector32>65}66 67// CHECK-LABEL: func.func @sparse_convert_permuted68// CHECK: sparse_tensor.foreach69// CHECK: tensor.insert70// CHECK: sparse_tensor.load71// CHECK: sparse_tensor.reorder_coo72// CHECK: sparse_tensor.foreach73// CHECK: tensor.insert74// CHECK: sparse_tensor.load75// CHECK: return76func.func @sparse_convert_permuted(%arg0: tensor<?x?x?xf32, #SortedCOO3D>) -> tensor<?x?x?xf32, #TsssPermuted> {77 %0 = sparse_tensor.convert %arg0 : tensor<?x?x?xf32, #SortedCOO3D> to tensor<?x?x?xf32, #TsssPermuted>78 return %0 : tensor<?x?x?xf32, #TsssPermuted>79}80 81// CHECK-LABEL: func.func @sparse_convert_slice82// CHECK: sparse_tensor.foreach83// CHECK: tensor.insert84// CHECK: sparse_tensor.load85// CHECK-NOT: sparse_tensor.reorder_coo86// CHECK: return87func.func @sparse_convert_slice(%arg0: tensor<2x13xi32, #COOSlice>) -> (tensor<2x13xi32, #SortedCOO2D>) {88 %0 = sparse_tensor.convert %arg0 : tensor<2x13xi32, #COOSlice> to tensor<2x13xi32, #SortedCOO2D>89 return %0 : tensor<2x13xi32, #SortedCOO2D>90}91