151 lines · plain
1//--------------------------------------------------------------------------------------------------2// WHEN CREATING A NEW TEST, PLEASE JUST COPY & PASTE WITHOUT EDITS.3//4// Set-up that's shared across all tests in this directory. In principle, this5// config could be moved to lit.local.cfg. However, there are downstream users that6// do not use these LIT config files. Hence why this is kept inline.7//8// DEFINE: %{sparsifier_opts} = enable-runtime-library=true9// DEFINE: %{sparsifier_opts_sve} = enable-arm-sve=true %{sparsifier_opts}10// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"11// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"12// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils13// DEFINE: %{run_libs_sve} = -shared-libs=%native_mlir_runner_utils,%native_mlir_c_runner_utils14// DEFINE: %{run_opts} = -e main -entry-point-result=void15// DEFINE: %{run} = mlir-runner %{run_opts} %{run_libs}16// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs_sve}17//18// DEFINE: %{env} =19//--------------------------------------------------------------------------------------------------20 21// RUN: %{compile} | %{run} | FileCheck %s22//23// Do the same run, but now with direct IR generation.24// REDEFINE: %{sparsifier_opts} = enable-runtime-library=false enable-buffer-initialization=true25// RUN: %{compile} | %{run} | FileCheck %s26//27// Do the same run, but now with direct IR generation and vectorization.28// REDEFINE: %{sparsifier_opts} = enable-runtime-library=false enable-buffer-initialization=true vl=2 reassociate-fp-reductions=true enable-index-optimizations=true29// RUN: %{compile} | %{run} | FileCheck %s30//31// Do the same run, but now with direct IR generation and VLA vectorization.32// RUN: %if mlir_arm_sve_tests %{ %{compile_sve} | %{run_sve} | FileCheck %s %}33 34#DCSR = #sparse_tensor.encoding<{35 map = (d0, d1) -> (d0 : compressed, d1 : compressed)36}>37 38#DCSC = #sparse_tensor.encoding<{39 map = (d0, d1) -> (d1 : compressed, d0 : compressed)40}>41 42//43// Integration test that tests conversions between sparse tensors,44// where the dynamic sizes of the shape of the enveloping tensor45// may change (the actual underlying sizes obviously never change).46//47module {48 func.func @main() {49 %t1 = arith.constant sparse<50 [ [0,0], [0,1], [0,63], [1,0], [1,1], [31,0], [31,63] ],51 [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ]> : tensor<32x64xf64>52 %t2 = tensor.cast %t1 : tensor<32x64xf64> to tensor<?x?xf64>53 54 // Four dense to sparse conversions.55 %1 = sparse_tensor.convert %t1 : tensor<32x64xf64> to tensor<?x?xf64, #DCSR>56 %2 = sparse_tensor.convert %t1 : tensor<32x64xf64> to tensor<?x?xf64, #DCSC>57 %3 = sparse_tensor.convert %t2 : tensor<?x?xf64> to tensor<?x?xf64, #DCSR>58 %4 = sparse_tensor.convert %t2 : tensor<?x?xf64> to tensor<?x?xf64, #DCSC>59 60 // Two cross conversions.61 %5 = sparse_tensor.convert %3 : tensor<?x?xf64, #DCSR> to tensor<?x?xf64, #DCSC>62 %6 = sparse_tensor.convert %4 : tensor<?x?xf64, #DCSC> to tensor<?x?xf64, #DCSR>63 64 //65 // Verify the outputs.66 //67 // CHECK: ---- Sparse Tensor ----68 // CHECK-NEXT: nse = 769 // CHECK-NEXT: dim = ( 32, 64 )70 // CHECK-NEXT: lvl = ( 32, 64 )71 // CHECK-NEXT: pos[0] : ( 0, 3 )72 // CHECK-NEXT: crd[0] : ( 0, 1, 31 )73 // CHECK-NEXT: pos[1] : ( 0, 3, 5, 7 )74 // CHECK-NEXT: crd[1] : ( 0, 1, 63, 0, 1, 0, 63 )75 // CHECK-NEXT: values : ( 1, 2, 3, 4, 5, 6, 7 )76 // CHECK-NEXT: ----77 //78 // CHECK: ---- Sparse Tensor ----79 // CHECK-NEXT: nse = 780 // CHECK-NEXT: dim = ( 32, 64 )81 // CHECK-NEXT: lvl = ( 64, 32 )82 // CHECK-NEXT: pos[0] : ( 0, 3 )83 // CHECK-NEXT: crd[0] : ( 0, 1, 63 )84 // CHECK-NEXT: pos[1] : ( 0, 3, 5, 7 )85 // CHECK-NEXT: crd[1] : ( 0, 1, 31, 0, 1, 0, 31 )86 // CHECK-NEXT: values : ( 1, 4, 6, 2, 5, 3, 7 )87 // CHECK-NEXT: ----88 //89 // CHECK: ---- Sparse Tensor ----90 // CHECK-NEXT: nse = 791 // CHECK-NEXT: dim = ( 32, 64 )92 // CHECK-NEXT: lvl = ( 32, 64 )93 // CHECK-NEXT: pos[0] : ( 0, 3 )94 // CHECK-NEXT: crd[0] : ( 0, 1, 31 )95 // CHECK-NEXT: pos[1] : ( 0, 3, 5, 7 )96 // CHECK-NEXT: crd[1] : ( 0, 1, 63, 0, 1, 0, 63 )97 // CHECK-NEXT: values : ( 1, 2, 3, 4, 5, 6, 7 )98 // CHECK-NEXT: ----99 //100 // CHECK: ---- Sparse Tensor ----101 // CHECK-NEXT: nse = 7102 // CHECK-NEXT: dim = ( 32, 64 )103 // CHECK-NEXT: lvl = ( 64, 32 )104 // CHECK-NEXT: pos[0] : ( 0, 3 )105 // CHECK-NEXT: crd[0] : ( 0, 1, 63 )106 // CHECK-NEXT: pos[1] : ( 0, 3, 5, 7 )107 // CHECK-NEXT: crd[1] : ( 0, 1, 31, 0, 1, 0, 31 )108 // CHECK-NEXT: values : ( 1, 4, 6, 2, 5, 3, 7 )109 // CHECK-NEXT: ----110 //111 // CHECK: ---- Sparse Tensor ----112 // CHECK-NEXT: nse = 7113 // CHECK-NEXT: dim = ( 32, 64 )114 // CHECK-NEXT: lvl = ( 64, 32 )115 // CHECK-NEXT: pos[0] : ( 0, 3 )116 // CHECK-NEXT: crd[0] : ( 0, 1, 63 )117 // CHECK-NEXT: pos[1] : ( 0, 3, 5, 7 )118 // CHECK-NEXT: crd[1] : ( 0, 1, 31, 0, 1, 0, 31 )119 // CHECK-NEXT: values : ( 1, 4, 6, 2, 5, 3, 7 )120 // CHECK-NEXT: ----121 //122 // CHECK: ---- Sparse Tensor ----123 // CHECK-NEXT: nse = 7124 // CHECK-NEXT: dim = ( 32, 64 )125 // CHECK-NEXT: lvl = ( 32, 64 )126 // CHECK-NEXT: pos[0] : ( 0, 3 )127 // CHECK-NEXT: crd[0] : ( 0, 1, 31 )128 // CHECK-NEXT: pos[1] : ( 0, 3, 5, 7 )129 // CHECK-NEXT: crd[1] : ( 0, 1, 63, 0, 1, 0, 63 )130 // CHECK-NEXT: values : ( 1, 2, 3, 4, 5, 6, 7 )131 // CHECK-NEXT: ----132 //133 sparse_tensor.print %1 : tensor<?x?xf64, #DCSR>134 sparse_tensor.print %2 : tensor<?x?xf64, #DCSC>135 sparse_tensor.print %3 : tensor<?x?xf64, #DCSR>136 sparse_tensor.print %4 : tensor<?x?xf64, #DCSC>137 sparse_tensor.print %5 : tensor<?x?xf64, #DCSC>138 sparse_tensor.print %6 : tensor<?x?xf64, #DCSR>139 140 // Release the resources.141 bufferization.dealloc_tensor %1 : tensor<?x?xf64, #DCSR>142 bufferization.dealloc_tensor %2 : tensor<?x?xf64, #DCSC>143 bufferization.dealloc_tensor %3 : tensor<?x?xf64, #DCSR>144 bufferization.dealloc_tensor %4 : tensor<?x?xf64, #DCSC>145 bufferization.dealloc_tensor %5 : tensor<?x?xf64, #DCSC>146 bufferization.dealloc_tensor %6 : tensor<?x?xf64, #DCSR>147 148 return149 }150}151