|
| 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, this |
| 5 | +// config could be moved to lit.local.cfg. However, there are downstream users that |
| 6 | +// do not use these LIT config files. Hence why this is kept inline. |
| 7 | +// |
| 8 | +// DEFINE: %{sparse_compiler_opts} = enable-runtime-library=true |
| 9 | +// DEFINE: %{sparse_compiler_opts_sve} = enable-arm-sve=true %{sparse_compiler_opts} |
| 10 | +// DEFINE: %{compile} = mlir-opt %s --sparse-compiler="%{sparse_compiler_opts}" |
| 11 | +// DEFINE: %{compile_sve} = mlir-opt %s --sparse-compiler="%{sparse_compiler_opts_sve}" |
| 12 | +// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils |
| 13 | +// DEFINE: %{run_opts} = -e entry -entry-point-result=void |
| 14 | +// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs} |
| 15 | +// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs} |
| 16 | +// |
| 17 | +// DEFINE: %{env} = |
| 18 | +//-------------------------------------------------------------------------------------------------- |
| 19 | + |
| 20 | +// RUN: %{compile} | %{run} | FileCheck %s |
| 21 | +// |
| 22 | +// Do the same run, but now with direct IR generation. |
| 23 | +// REDEFINE: %{sparse_compiler_opts} = enable-runtime-library=false enable-buffer-initialization=true |
| 24 | +// RUN: %{compile} | %{run} | FileCheck %s |
| 25 | +// |
| 26 | +// Do the same run, but now with direct IR generation and vectorization. |
| 27 | +// REDEFINE: %{sparse_compiler_opts} = enable-runtime-library=false enable-buffer-initialization=true vl=2 reassociate-fp-reductions=true enable-index-optimizations=true |
| 28 | +// RUN: %{compile} | %{run} | FileCheck %s |
| 29 | +// |
| 30 | +// Do the same run, but now with direct IR generation and VLA vectorization. |
| 31 | +// RUN: %if mlir_arm_sve_tests %{ %{compile_sve} | %{run_sve} | FileCheck %s %} |
| 32 | + |
| 33 | +#CSR = #sparse_tensor.encoding<{ |
| 34 | + map = (d0, d1) -> (d0 : dense, d1 : compressed) |
| 35 | +}> |
| 36 | + |
| 37 | +#CSC = #sparse_tensor.encoding<{ |
| 38 | + map = (d0, d1) -> (d1 : dense, d0 : compressed) |
| 39 | +}> |
| 40 | + |
| 41 | +#BSR = #sparse_tensor.encoding<{ |
| 42 | + map = ( i, j ) -> |
| 43 | + ( i floordiv 2 : dense, |
| 44 | + j floordiv 2 : compressed, |
| 45 | + i mod 2 : dense, |
| 46 | + j mod 2 : dense |
| 47 | + ) |
| 48 | +}> |
| 49 | + |
| 50 | + |
| 51 | +// |
| 52 | +// Integration test that tests conversions between sparse tensors. |
| 53 | +// |
| 54 | +module { |
| 55 | + // |
| 56 | + // Output utilities. |
| 57 | + // |
| 58 | + func.func @dumpf64(%arg0: memref<?xf64>) { |
| 59 | + %c0 = arith.constant 0 : index |
| 60 | + %d0 = arith.constant -1.0 : f64 |
| 61 | + %0 = vector.transfer_read %arg0[%c0], %d0: memref<?xf64>, vector<8xf64> |
| 62 | + vector.print %0 : vector<8xf64> |
| 63 | + return |
| 64 | + } |
| 65 | + |
| 66 | + // |
| 67 | + // Main driver. |
| 68 | + // |
| 69 | + func.func @entry() { |
| 70 | + %c0 = arith.constant 0 : index |
| 71 | + %c1 = arith.constant 1 : index |
| 72 | + %c2 = arith.constant 2 : index |
| 73 | + |
| 74 | + // |
| 75 | + // Initialize a 2-dim dense tensor. |
| 76 | + // |
| 77 | + %t = arith.constant dense<[ |
| 78 | + [ 1.0, 2.0, 3.0, 4.0 ], |
| 79 | + [ 5.0, 6.0, 7.0, 8.0 ] |
| 80 | + ]> : tensor<2x4xf64> |
| 81 | + |
| 82 | + |
| 83 | + %1 = sparse_tensor.convert %t : tensor<2x4xf64> to tensor<2x4xf64, #CSR> |
| 84 | + %2 = sparse_tensor.convert %1 : tensor<2x4xf64, #CSR> to tensor<2x4xf64, #BSR> |
| 85 | + %3 = sparse_tensor.convert %2 : tensor<2x4xf64, #BSR> to tensor<2x4xf64, #CSC> |
| 86 | + |
| 87 | + %v1 = sparse_tensor.values %1 : tensor<2x4xf64, #CSR> to memref<?xf64> |
| 88 | + %v2 = sparse_tensor.values %2 : tensor<2x4xf64, #BSR> to memref<?xf64> |
| 89 | + %v3 = sparse_tensor.values %3 : tensor<2x4xf64, #CSC> to memref<?xf64> |
| 90 | + |
| 91 | + // CHECK: ( 1, 2, 3, 4, 5, 6, 7, 8 ) |
| 92 | + // CHECK-NEXT: ( 1, 2, 5, 6, 3, 4, 7, 8 ) |
| 93 | + // CHECK-NEXT: ( 1, 5, 2, 6, 3, 7, 4, 8 ) |
| 94 | + call @dumpf64(%v1) : (memref<?xf64>) -> () |
| 95 | + call @dumpf64(%v2) : (memref<?xf64>) -> () |
| 96 | + call @dumpf64(%v3) : (memref<?xf64>) -> () |
| 97 | + |
| 98 | + return |
| 99 | + } |
| 100 | +} |
0 commit comments