brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.0 KiB · 015ac13 Raw
109 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// REDEFINE: %{env} = TENSOR0=%mlir_src_dir/test/Integration/data/test_symmetric.mtx22// RUN: %{compile} | env %{env} %{run} | FileCheck %s23//24// Do the same run, but now with direct IR generation.25// REDEFINE: %{sparsifier_opts} = enable-runtime-library=false26// RUN: %{compile} | env %{env} %{run} | FileCheck %s27//28// Do the same run, but now with vectorization.29// REDEFINE: %{sparsifier_opts} = enable-runtime-library=false vl=2 reassociate-fp-reductions=true enable-index-optimizations=true30// RUN: %{compile} | env %{env} %{run} | FileCheck %s31//32// Do the same run, but now with  VLA vectorization.33// RUN: %if mlir_arm_sve_tests %{ %{compile_sve} | env %{env} %{run_sve} | FileCheck %s %}34 35// TODO: The test currently only operates on the triangular part of the36// symmetric matrix.37 38!Filename = !llvm.ptr39 40#SparseMatrix = #sparse_tensor.encoding<{41  map = (d0, d1) -> (d0 : compressed, d1 : compressed)42}>43 44#trait_sum_reduce = {45  indexing_maps = [46    affine_map<(i,j) -> (i,j)>, // A47    affine_map<(i,j) -> ()>     // x (out)48  ],49  iterator_types = ["reduction", "reduction"],50  doc = "x += A(i,j)"51}52 53//54// Integration test that lowers a kernel annotated as sparse to55// actual sparse code, initializes a matching sparse storage scheme56// from file, and runs the resulting code with the JIT compiler.57//58module {59  //60  // A kernel that sum-reduces a matrix to a single scalar.61  //62  func.func @kernel_sum_reduce(%arga: tensor<?x?xf64, #SparseMatrix>,63                               %argx: tensor<f64>) -> tensor<f64> {64    %0 = linalg.generic #trait_sum_reduce65      ins(%arga: tensor<?x?xf64, #SparseMatrix>)66      outs(%argx: tensor<f64>) {67      ^bb(%a: f64, %x: f64):68        %0 = arith.addf %x, %a : f6469        linalg.yield %0 : f6470    } -> tensor<f64>71    return %0 : tensor<f64>72  }73 74  func.func private @getTensorFilename(index) -> (!Filename)75 76  //77  // Main driver that reads matrix from file and calls the sparse kernel.78  //79  func.func @main() {80    %d0 = arith.constant 0.0 : f6481    %c0 = arith.constant 0 : index82 83    // Setup memory for a single reduction scalar,84    // initialized to zero.85    %x = tensor.from_elements %d0 : tensor<f64>86 87    // Read the sparse matrix from file, construct sparse storage.88    %fileName = call @getTensorFilename(%c0) : (index) -> (!Filename)89    %a = sparse_tensor.new %fileName : !Filename to tensor<?x?xf64, #SparseMatrix>90 91    // Call the kernel.92    %0 = call @kernel_sum_reduce(%a, %x)93      : (tensor<?x?xf64, #SparseMatrix>, tensor<f64>) -> tensor<f64>94 95    // Print the result for verification.96    //97    // CHECK: 24.198    //99    %v = tensor.extract %0[] : tensor<f64>100    vector.print %v : f64101 102    // Release the resources.103    bufferization.dealloc_tensor %a : tensor<?x?xf64, #SparseMatrix>104    bufferization.dealloc_tensor %0 : tensor<f64>105 106    return107  }108}109