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: %{sparsifier_opts} = enable-runtime-library=true 9// 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_utils 13// DEFINE: %{run_libs_sve} = -shared-libs=%native_mlir_runner_utils,%native_mlir_c_runner_utils 14// DEFINE: %{run_opts} = -e main -entry-point-result=void 15// 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// TODO: make this work with libgen 22 23// Do the same run, but now with direct IR generation. 24// REDEFINE: %{sparsifier_opts} = enable-runtime-library=false enable-buffer-initialization=true 25// RUN: %{compile} | %{run} | FileCheck %s 26// 27 28#BatchedCSR = #sparse_tensor.encoding<{ 29 map = (d0, d1, d2) -> (d0 : batch, d1 : dense, d2 : compressed) 30}> 31 32module { 33 34 // 35 // Main driver that tests 3-D sparse tensor printing. 36 // 37 func.func @main() { 38 39 %pos = arith.constant dense< 40 [[ 0, 8, 16, 24, 32], 41 [ 0, 8, 16, 24, 32]] 42 > : tensor<2x5xindex> 43 44 %crd = arith.constant dense< 45 [[0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7], 46 [0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7]] 47 > : tensor<2x32xindex> 48 49 %val = arith.constant dense< 50 [[ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 51 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 52 23., 24., 25., 26., 27., 28., 29., 30., 31., 32.], 53 [33., 34., 35., 36., 37., 38., 39., 40., 41., 42., 43., 54 44., 45., 46., 47., 48., 49., 50., 51., 52., 53., 54., 55 55., 56., 57., 58., 59., 60., 61., 62., 63., 64.]] 56 > : tensor<2x32xf64> 57 58 %X = sparse_tensor.assemble (%pos, %crd), %val 59 : (tensor<2x5xindex>, tensor<2x32xindex>), tensor<2x32xf64> to tensor<2x4x8xf64, #BatchedCSR> 60 61 // CHECK: ---- Sparse Tensor ---- 62 // CHECK-NEXT: nse = 32 63 // CHECK-NEXT: dim = ( 2, 4, 8 ) 64 // CHECK-NEXT: lvl = ( 2, 4, 8 ) 65 // CHECK-NEXT: pos[2] : ( ( 0, 8, 16, 24, 32 )( 0, 8, 16, 24, 32 ) ) 66 // CHECK-NEXT: crd[2] : ( ( 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7 ) 67 // CHECK-SAME: ( 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7 ) ) 68 // CHECK-NEXT: values : ( ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 ) 69 // CHECK-SAME: ( 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, 60, 61, 62, 63, 64 ) ) 70 // CHECK-NEXT: ---- 71 sparse_tensor.print %X : tensor<2x4x8xf64, #BatchedCSR> 72 73 return 74 } 75} 76