brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.3 KiB · 43674f6 Raw
112 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=false25// RUN: %{compile} | %{run} | FileCheck %s26//27// Do the same run, but now with vectorization.28// REDEFINE: %{sparsifier_opts} = enable-runtime-library=false vl=2 reassociate-fp-reductions=true enable-index-optimizations=true29// RUN: %{compile} | %{run} | FileCheck %s30//31// Do the same run, but now with  VLA vectorization.32// RUN: %if mlir_arm_sve_tests %{ %{compile_sve} | %{run_sve} | FileCheck %s %}33 34#SortedCOO = #sparse_tensor.encoding<{35  map = (d0, d1) -> (d0 : compressed(nonunique), d1 : singleton(soa))36}>37 38module {39 40  // A linalg representation of some higher "transpose" op.41  func.func @transpose_coo(%arga: tensor<10x5xf32, #SortedCOO>)42                               -> tensor<5x10xf32, #SortedCOO> {43    %0 = tensor.empty() : tensor<5x10xf32, #SortedCOO>44    %1 = linalg.generic {45      indexing_maps = [affine_map<(d0, d1) -> (d1, d0)>,46                       affine_map<(d0, d1) -> (d0, d1)>],47      iterator_types = ["parallel", "parallel"]}48      ins(%arga : tensor<10x5xf32, #SortedCOO>)49      outs(%0 : tensor<5x10xf32, #SortedCOO>) {50        ^bb0(%in: f32, %out: f32):51           linalg.yield %in : f3252      } -> tensor<5x10xf32, #SortedCOO>53    return %1 : tensor<5x10xf32, #SortedCOO>54  }55 56  func.func @main() {57    %f0  = arith.constant 0.0 : f3258    %c0  = arith.constant 0   : index59    %c1  = arith.constant 1   : index60 61    %A = arith.constant dense<62        [ [ 10.0, 20.0, 30.0, 40.0, 50.0 ],63          [ 11.0, 21.0, 31.0, 41.0, 51.0 ],64          [ 12.0, 22.0, 32.0, 42.0, 52.0 ],65          [ 13.0, 23.0, 33.0, 43.0, 53.0 ],66          [ 14.0, 24.0, 34.0, 44.0, 54.0 ],67          [ 15.0, 25.0, 35.0, 45.0, 55.0 ],68          [ 16.0, 26.0, 36.0, 46.0, 56.0 ],69          [ 17.0, 27.0, 37.0, 47.0, 57.0 ],70          [ 18.0, 28.0, 38.0, 48.0, 58.0 ],71          [ 19.0, 29.0, 39.0, 49.0, 59.0 ] ]72    > : tensor<10x5xf32>73 74    // Stress test with a "sparse" version of A.75    %SA = sparse_tensor.convert %A76      : tensor<10x5xf32> to tensor<10x5xf32, #SortedCOO>77    %SAT = call @transpose_coo(%SA) : (tensor<10x5xf32, #SortedCOO>)78                                    -> tensor<5x10xf32, #SortedCOO>79 80    //81    // Verify original and transposed sorted COO.82    //83    // CHECK:      ---- Sparse Tensor ----84    // CHECK-NEXT: nse = 5085    // CHECK-NEXT: dim = ( 10, 5 )86    // CHECK-NEXT: lvl = ( 10, 5 )87    // CHECK-NEXT: pos[0] : ( 0, 50 )88    // CHECK-NEXT: crd[0] : ( 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9 )89    // CHECK-NEXT: crd[1] : ( 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 )90    // CHECK-NEXT: values : ( 10, 20, 30, 40, 50, 11, 21, 31, 41, 51, 12, 22, 32, 42, 52, 13, 23, 33, 43, 53, 14, 24, 34, 44, 54, 15, 25, 35, 45, 55, 16, 26, 36, 46, 56, 17, 27, 37, 47, 57, 18, 28, 38, 48, 58, 19, 29, 39, 49, 59 )91    // CHECK-NEXT: ----92    // CHECK:      ---- Sparse Tensor ----93    // CHECK-NEXT: nse = 5094    // CHECK-NEXT: dim = ( 5, 10 )95    // CHECK-NEXT: lvl = ( 5, 10 )96    // CHECK-NEXT: pos[0] : ( 0, 50 )97    // CHECK-NEXT: crd[0] : ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 )98    // CHECK-NEXT: crd[1] : ( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 )99    // CHECK-NEXT: values : ( 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59 )100    // CHECK-NEXT: ----101    //102    sparse_tensor.print %SA : tensor<10x5xf32, #SortedCOO>103    sparse_tensor.print %SAT : tensor<5x10xf32, #SortedCOO>104 105    // Release resources.106    bufferization.dealloc_tensor %SA  : tensor<10x5xf32, #SortedCOO>107    bufferization.dealloc_tensor %SAT : tensor<5x10xf32, #SortedCOO>108 109    return110  }111}112