714 changes: 714 additions & 0 deletions llvm/test/CodeGen/X86/eq-or-eq-range-of-2.ll

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions llvm/test/ExecutionEngine/JITLink/x86-64/ELF_vtune.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# REQUIRES: native && x86_64-linux && intel-jitevents

# RUN: rm -rf %t && mkdir %t
# RUN: llvm-mc -triple=x86_64-unknown-linux \
# RUN: -filetype=obj -o %t/ELF_x86-64_vtune.o %s
# RUN: llvm-jitlink -vtune-support %t/ELF_x86-64_vtune.o | \
# RUN: FileCheck %s

# CHECK: Method load [0]: {{.*}}, Size = {{[0-9]+}}
# CHECK: Method unload [0]
.file "test.c"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
endbr64
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl %edi, -4(%rbp)
movq %rsi, -16(%rbp)
movl -4(%rbp), %ebx
addl $1, %ebx
movl $0, %eax
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0"
.section .note.GNU-stack,"",@progbits
.section .note.gnu.property,"a"
.align 8
.long 1f - 0f
.long 4f - 1f
.long 5
0:
.string "GNU"
1:
.align 8
.long 0xc0000002
.long 3f - 2f
2:
.long 0x3
3:
.align 8
4:
3 changes: 3 additions & 0 deletions llvm/test/ExecutionEngine/JITLink/x86-64/lit.local.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
if not "X86" in config.root.targets:
config.unsupported = True

if config.llvm_use_intel_jitevents:
config.available_features.add("intel-jitevents")
68 changes: 68 additions & 0 deletions llvm/test/Transforms/CorrelatedValuePropagation/udiv-expansion.ll
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,74 @@ define i8 @constant.divisor.v7(i8 %x) {
ret i8 %div
}

define i8 @constant.divisor.v6to8(i8 %x) {
; CHECK-LABEL: @constant.divisor.v6to8(
; CHECK-NEXT: [[CMP_X_LOWER:%.*]] = icmp uge i8 [[X:%.*]], 6
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP_X_LOWER]])
; CHECK-NEXT: [[CMP_X_UPPER:%.*]] = icmp ult i8 [[X]], 9
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP_X_UPPER]])
; CHECK-NEXT: [[DIV:%.*]] = udiv i8 [[X]], 3
; CHECK-NEXT: ret i8 2
;
%cmp.x.lower = icmp uge i8 %x, 6
call void @llvm.assume(i1 %cmp.x.lower)
%cmp.x.upper = icmp ult i8 %x, 9
call void @llvm.assume(i1 %cmp.x.upper)
%div = udiv i8 %x, 3
ret i8 %div
}

define i8 @constant.divisor.v9to11(i8 %x) {
; CHECK-LABEL: @constant.divisor.v9to11(
; CHECK-NEXT: [[CMP_X_LOWER:%.*]] = icmp uge i8 [[X:%.*]], 9
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP_X_LOWER]])
; CHECK-NEXT: [[CMP_X_UPPER:%.*]] = icmp ult i8 [[X]], 12
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP_X_UPPER]])
; CHECK-NEXT: [[DIV:%.*]] = udiv i8 [[X]], 3
; CHECK-NEXT: ret i8 3
;
%cmp.x.lower = icmp uge i8 %x, 9
call void @llvm.assume(i1 %cmp.x.lower)
%cmp.x.upper = icmp ult i8 %x, 12
call void @llvm.assume(i1 %cmp.x.upper)
%div = udiv i8 %x, 3
ret i8 %div
}

define i8 @constant.divisor.v12to14(i8 %x) {
; CHECK-LABEL: @constant.divisor.v12to14(
; CHECK-NEXT: [[CMP_X_LOWER:%.*]] = icmp uge i8 [[X:%.*]], 12
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP_X_LOWER]])
; CHECK-NEXT: [[CMP_X_UPPER:%.*]] = icmp ult i8 [[X]], 15
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP_X_UPPER]])
; CHECK-NEXT: [[DIV:%.*]] = udiv i8 [[X]], 3
; CHECK-NEXT: ret i8 4
;
%cmp.x.lower = icmp uge i8 %x, 12
call void @llvm.assume(i1 %cmp.x.lower)
%cmp.x.upper = icmp ult i8 %x, 15
call void @llvm.assume(i1 %cmp.x.upper)
%div = udiv i8 %x, 3
ret i8 %div
}

define i8 @constant.divisor.v6to11(i8 %x) {
; CHECK-LABEL: @constant.divisor.v6to11(
; CHECK-NEXT: [[CMP_X_LOWER:%.*]] = icmp uge i8 [[X:%.*]], 6
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP_X_LOWER]])
; CHECK-NEXT: [[CMP_X_UPPER:%.*]] = icmp ult i8 [[X]], 12
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP_X_UPPER]])
; CHECK-NEXT: [[DIV:%.*]] = udiv i8 [[X]], 3
; CHECK-NEXT: ret i8 [[DIV]]
;
%cmp.x.lower = icmp uge i8 %x, 6
call void @llvm.assume(i1 %cmp.x.lower)
%cmp.x.upper = icmp ult i8 %x, 12
call void @llvm.assume(i1 %cmp.x.upper)
%div = udiv i8 %x, 3
ret i8 %div
}

; Both are variable. Bounds are known

define i8 @variable.v3(i8 %x, i8 %y) {
Expand Down
93 changes: 93 additions & 0 deletions llvm/test/Transforms/CorrelatedValuePropagation/urem-expansion.ll
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,74 @@ define i8 @constant.divisor.v7(i8 %x) {
ret i8 %rem
}

define i8 @constant.divisor.v6to8(i8 %x) {
; CHECK-LABEL: @constant.divisor.v6to8(
; CHECK-NEXT: [[CMP_X_LOWER:%.*]] = icmp uge i8 [[X:%.*]], 6
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP_X_LOWER]])
; CHECK-NEXT: [[CMP_X_UPPER:%.*]] = icmp ult i8 [[X]], 9
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP_X_UPPER]])
; CHECK-NEXT: [[REM:%.*]] = urem i8 [[X]], 3
; CHECK-NEXT: ret i8 [[REM]]
;
%cmp.x.lower = icmp uge i8 %x, 6
call void @llvm.assume(i1 %cmp.x.lower)
%cmp.x.upper = icmp ult i8 %x, 9
call void @llvm.assume(i1 %cmp.x.upper)
%rem = urem i8 %x, 3
ret i8 %rem
}

define i8 @constant.divisor.v9to11(i8 %x) {
; CHECK-LABEL: @constant.divisor.v9to11(
; CHECK-NEXT: [[CMP_X_LOWER:%.*]] = icmp uge i8 [[X:%.*]], 9
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP_X_LOWER]])
; CHECK-NEXT: [[CMP_X_UPPER:%.*]] = icmp ult i8 [[X]], 12
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP_X_UPPER]])
; CHECK-NEXT: [[REM:%.*]] = urem i8 [[X]], 3
; CHECK-NEXT: ret i8 [[REM]]
;
%cmp.x.lower = icmp uge i8 %x, 9
call void @llvm.assume(i1 %cmp.x.lower)
%cmp.x.upper = icmp ult i8 %x, 12
call void @llvm.assume(i1 %cmp.x.upper)
%rem = urem i8 %x, 3
ret i8 %rem
}

define i8 @constant.divisor.v12to14(i8 %x) {
; CHECK-LABEL: @constant.divisor.v12to14(
; CHECK-NEXT: [[CMP_X_LOWER:%.*]] = icmp uge i8 [[X:%.*]], 12
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP_X_LOWER]])
; CHECK-NEXT: [[CMP_X_UPPER:%.*]] = icmp ult i8 [[X]], 15
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP_X_UPPER]])
; CHECK-NEXT: [[REM:%.*]] = urem i8 [[X]], 3
; CHECK-NEXT: ret i8 [[REM]]
;
%cmp.x.lower = icmp uge i8 %x, 12
call void @llvm.assume(i1 %cmp.x.lower)
%cmp.x.upper = icmp ult i8 %x, 15
call void @llvm.assume(i1 %cmp.x.upper)
%rem = urem i8 %x, 3
ret i8 %rem
}

define i8 @constant.divisor.v6to11(i8 %x) {
; CHECK-LABEL: @constant.divisor.v6to11(
; CHECK-NEXT: [[CMP_X_LOWER:%.*]] = icmp uge i8 [[X:%.*]], 6
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP_X_LOWER]])
; CHECK-NEXT: [[CMP_X_UPPER:%.*]] = icmp ult i8 [[X]], 12
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP_X_UPPER]])
; CHECK-NEXT: [[REM:%.*]] = urem i8 [[X]], 3
; CHECK-NEXT: ret i8 [[REM]]
;
%cmp.x.lower = icmp uge i8 %x, 6
call void @llvm.assume(i1 %cmp.x.lower)
%cmp.x.upper = icmp ult i8 %x, 12
call void @llvm.assume(i1 %cmp.x.upper)
%rem = urem i8 %x, 3
ret i8 %rem
}

; Both are variable. Bounds are known

define i8 @variable.v3(i8 %x, i8 %y) {
Expand Down Expand Up @@ -226,6 +294,31 @@ define i8 @variable.v7(i8 %x, i8 %y) {
ret i8 %rem
}

define i8 @variable.v6to8.v3to4(i8 %x, i8 %y) {
; CHECK-LABEL: @variable.v6to8.v3to4(
; CHECK-NEXT: [[CMP_X_LOWER:%.*]] = icmp uge i8 [[X:%.*]], 6
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP_X_LOWER]])
; CHECK-NEXT: [[CMP_X_UPPER:%.*]] = icmp ult i8 [[X]], 8
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP_X_UPPER]])
; CHECK-NEXT: [[CMP_Y_LOWER:%.*]] = icmp uge i8 [[Y:%.*]], 3
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP_Y_LOWER]])
; CHECK-NEXT: [[CMP_Y_UPPER:%.*]] = icmp ule i8 [[Y]], 4
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP_Y_UPPER]])
; CHECK-NEXT: [[REM:%.*]] = urem i8 [[X]], [[Y]]
; CHECK-NEXT: ret i8 [[REM]]
;
%cmp.x.lower = icmp uge i8 %x, 6
call void @llvm.assume(i1 %cmp.x.lower)
%cmp.x.upper = icmp ult i8 %x, 8
call void @llvm.assume(i1 %cmp.x.upper)
%cmp.y.lower = icmp uge i8 %y, 3
call void @llvm.assume(i1 %cmp.y.lower)
%cmp.y.upper = icmp ule i8 %y, 4
call void @llvm.assume(i1 %cmp.y.upper)
%rem = urem i8 %x, %y
ret i8 %rem
}

; Constant divisor

define i8 @large.divisor.v0(i8 %x) {
Expand Down
19 changes: 18 additions & 1 deletion llvm/tools/llvm-jitlink/llvm-jitlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "llvm/ExecutionEngine/Orc/Debugging/DebugInfoSupport.h"
#include "llvm/ExecutionEngine/Orc/Debugging/DebuggerSupportPlugin.h"
#include "llvm/ExecutionEngine/Orc/Debugging/PerfSupportPlugin.h"
#include "llvm/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.h"
#include "llvm/ExecutionEngine/Orc/ELFNixPlatform.h"
#include "llvm/ExecutionEngine/Orc/EPCDebugObjectRegistrar.h"
#include "llvm/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.h"
Expand All @@ -34,6 +35,7 @@
#include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
#include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"
#include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderPerf.h"
#include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderVTune.h"
#include "llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
Expand Down Expand Up @@ -148,6 +150,10 @@ static cl::opt<bool> PerfSupport("perf-support",
cl::init(false), cl::Hidden,
cl::cat(JITLinkCategory));

static cl::opt<bool> VTuneSupport("vtune-support",
cl::desc("Enable vtune profiling support"),
cl::init(false), cl::Hidden,
cl::cat(JITLinkCategory));
static cl::opt<bool>
NoProcessSymbols("no-process-syms",
cl::desc("Do not resolve to llvm-jitlink process symbols"),
Expand Down Expand Up @@ -264,7 +270,10 @@ static LLVM_ATTRIBUTE_USED void linkComponents() {
<< (void *)&llvm_orc_registerJITLoaderGDBAllocAction << '\n'
<< (void *)&llvm_orc_registerJITLoaderPerfStart << '\n'
<< (void *)&llvm_orc_registerJITLoaderPerfEnd << '\n'
<< (void *)&llvm_orc_registerJITLoaderPerfImpl << '\n';
<< (void *)&llvm_orc_registerJITLoaderPerfImpl << '\n'
<< (void *)&llvm_orc_registerVTuneImpl << '\n'
<< (void *)&llvm_orc_unregisterVTuneImpl << '\n'
<< (void *)&llvm_orc_test_registerVTuneImpl << '\n';
}

static bool UseTestResultOverride = false;
Expand Down Expand Up @@ -1004,6 +1013,14 @@ Session::Session(std::unique_ptr<ExecutorProcessControl> EPC, Error &Err)
this->ES.getExecutorProcessControl(), *ProcessSymsJD, true, true)));
}

if (VTuneSupport && TT.isOSBinFormatELF()) {
ObjLayer.addPlugin(ExitOnErr(DebugInfoPreservationPlugin::Create()));
ObjLayer.addPlugin(ExitOnErr(
VTuneSupportPlugin::Create(this->ES.getExecutorProcessControl(),
*ProcessSymsJD, /*EmitDebugInfo=*/true,
/*TestMode=*/true)));
}

// Set up the platform.
if (!OrcRuntime.empty()) {
assert(ProcessSymsJD && "ProcessSymsJD should have been set");
Expand Down
14 changes: 14 additions & 0 deletions llvm/unittests/Analysis/ValueTrackingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2359,6 +2359,20 @@ TEST_F(ComputeKnownBitsTest, ComputeKnownBitsFreeze) {
EXPECT_EQ(Known.One.getZExtValue(), 0u);
}

TEST_F(ComputeKnownBitsTest, ComputeKnownBitsReturnedRangeConflict) {
parseAssembly(
"declare i16 @foo(i16 returned)\n"
"\n"
"define i16 @test() {\n"
" %A = call i16 @foo(i16 4095), !range !{i16 32, i16 33}\n"
" ret i16 %A\n"
"}\n");
// The call returns 32 according to range metadata, but 4095 according to the
// returned arg operand. Given the conflicting information we expect that the
// known bits information simply is cleared.
expectKnownBits(/*zero*/ 0u, /*one*/ 0u);
}

TEST_F(ComputeKnownBitsTest, ComputeKnownBitsAddWithRange) {
parseAssembly("define void @test(ptr %p) {\n"
" %A = load i64, ptr %p, !range !{i64 64, i64 65536}\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ static_library("Debugging") {
"DebuggerSupportPlugin.cpp",
"LLJITUtilsCBindings.cpp",
"PerfSupportPlugin.cpp",
"VTuneSupportPlugin.cpp",
]
if (current_os == "linux") {
libs = [ "rt" ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ static_library("TargetProcess") {
"ExecutorSharedMemoryMapperService.cpp",
"JITLoaderGDB.cpp",
"JITLoaderPerf.cpp",
"JITLoaderVTune.cpp",
"OrcRTBootstrap.cpp",
"RegisterEHFrames.cpp",
"SimpleExecutorDylibManager.cpp",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ static_library("Instrumentation") {
"InstrProfiling.cpp",
"Instrumentation.cpp",
"KCFI.cpp",
"PGOForceFunctionAttrs.cpp",
"MemProfiler.cpp",
"MemorySanitizer.cpp",
"PGOForceFunctionAttrs.cpp",
"PGOInstrumentation.cpp",
"PGOMemOPSizeOpt.cpp",
"PoisonChecking.cpp",
"RemoveTrapsPass.cpp",
"SanitizerBinaryMetadata.cpp",
"SanitizerCoverage.cpp",
"ThreadSanitizer.cpp",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -88,7 +88,7 @@ module {
//
// Main driver that reads matrix from file and calls the sparse kernel.
//
func.func @entry() {
func.func @main() {
%i0 = arith.constant 0 : i32
%c0 = arith.constant 0 : index
%c1 = arith.constant 1 : index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -84,7 +84,7 @@ module {
//
// Main driver that reads matrix from file and calls the sparse kernel.
//
func.func @entry() {
func.func @main() {
%f0 = arith.constant 0.0 : f64
%cst0 = arith.constant 0 : index
%cst1 = arith.constant 1 : index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -60,7 +60,7 @@ module {
}

// Driver method to call and verify kernel.
func.func @entry() {
func.func @main() {
%c0 = arith.constant 0 : index
%f0 = arith.constant 0.0 : f32

Expand All @@ -84,11 +84,18 @@ module {
//
// Verify results. Only two entries stored in result!
//
// CHECK: ( 14, 20, 0, 0 )
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 2
// CHECK-NEXT: dim = ( 32, 16 )
// CHECK-NEXT: lvl = ( 32, 16 )
// CHECK-NEXT: pos[0] : ( 0, 2
// CHECK-NEXT: crd[0] : ( 2, 31
// CHECK-NEXT: pos[1] : ( 0, 1, 2
// CHECK-NEXT: crd[1] : ( 2, 0
// CHECK-NEXT: values : ( 14, 20
// CHECK-NEXT: ----
//
%val = sparse_tensor.values %0 : tensor<32x16xf32, #DCSR> to memref<?xf32>
%vv = vector.transfer_read %val[%c0], %f0: memref<?xf32>, vector<4xf32>
vector.print %vv : vector<4xf32>
sparse_tensor.print %0 : tensor<32x16xf32, #DCSR>

// Release the resources.
bufferization.dealloc_tensor %sta : tensor<32x16xf32, #DCSR>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -70,10 +70,7 @@ module {
}

// Driver method to call and verify tensor kernel.
func.func @entry() {
%c0 = arith.constant 0 : index
%i0 = arith.constant 0 : i32

func.func @main() {
// Setup very sparse 3-d tensors.
%t1 = arith.constant sparse<
[ [1,1,3], [2,0,0], [2,2,1], [2,2,2], [2,2,3] ], [ 1, 2, 3, 4, 5 ]
Expand All @@ -94,23 +91,23 @@ module {
//
// Verify results. Only two entries stored in result. Correct structure.
//
// CHECK: ( 7, 69, 0, 0 )
// CHECK-NEXT: ( ( 0, 0, 0 ), ( 0, 7, 0 ), ( 0, 0, 69 ) )
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 2
// CHECK-NEXT: dim = ( 3, 3 )
// CHECK-NEXT: lvl = ( 3, 3 )
// CHECK-NEXT: pos[0] : ( 0, 2
// CHECK-NEXT: crd[0] : ( 1, 2
// CHECK-NEXT: pos[1] : ( 0, 1, 2
// CHECK-NEXT: crd[1] : ( 1, 2
// CHECK-NEXT: values : ( 7, 69
// CHECK-NEXT: ----
//
%val = sparse_tensor.values %0
: tensor<?x?xi32, #SparseMatrix> to memref<?xi32>
%vv = vector.transfer_read %val[%c0], %i0: memref<?xi32>, vector<4xi32>
vector.print %vv : vector<4xi32>
%dm = sparse_tensor.convert %0
: tensor<?x?xi32, #SparseMatrix> to tensor<?x?xi32>
%vm = vector.transfer_read %dm[%c0, %c0], %i0: tensor<?x?xi32>, vector<3x3xi32>
vector.print %vm : vector<3x3xi32>
sparse_tensor.print %0 : tensor<?x?xi32, #SparseMatrix>

// Release the resources.
bufferization.dealloc_tensor %st1 : tensor<?x?x?xi32, #SparseTensor>
bufferization.dealloc_tensor %st2 : tensor<?x?x?xi32, #SparseTensor>
bufferization.dealloc_tensor %0 : tensor<?x?xi32, #SparseMatrix>
bufferization.dealloc_tensor %dm : tensor<?x?xi32>

return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -70,7 +70,7 @@ module {
//
// Main driver that reads matrix from file and calls the sparse kernel.
//
func.func @entry() {
func.func @main() {
%d0 = arith.constant 0.0 : f64
%c0 = arith.constant 0 : index

Expand All @@ -83,11 +83,18 @@ module {

// Print the result for verification.
//
// CHECK: ( 1, 1.96, 4, 6.25, 9, 16.81, 16, 27.04, 25 )
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 9
// CHECK-NEXT: dim = ( 5, 5 )
// CHECK-NEXT: lvl = ( 5, 5 )
// CHECK-NEXT: pos[0] : ( 0, 5
// CHECK-NEXT: crd[0] : ( 0, 1, 2, 3, 4
// CHECK-NEXT: pos[1] : ( 0, 2, 4, 5, 7, 9
// CHECK-NEXT: crd[1] : ( 0, 3, 1, 4, 2, 0, 3, 1, 4
// CHECK-NEXT: values : ( 1, 1.96, 4, 6.25, 9, 16.81, 16, 27.04, 25
// CHECK-NEXT: ----
//
%m = sparse_tensor.values %0 : tensor<?x?xf64, #DCSR> to memref<?xf64>
%v = vector.transfer_read %m[%c0], %d0: memref<?xf64>, vector<9xf64>
vector.print %v : vector<9xf64>
sparse_tensor.print %0 : tensor<?x?xf64, #DCSR>

// Release the resources.
bufferization.dealloc_tensor %x : tensor<?x?xf64, #DCSR>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -54,7 +54,7 @@ module {
//
// Main driver.
//
func.func @entry() {
func.func @main() {
%c0 = arith.constant 0 : index
%f0 = arith.constant 0.0 : f64
%i0 = arith.constant 0 : i32
Expand Down
53 changes: 33 additions & 20 deletions mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_pack_d.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -48,7 +48,7 @@ module {
//
// Main driver.
//
func.func @entry() {
func.func @main() {
%c0 = arith.constant 0 : index
%f0 = arith.constant 0.0 : f32

Expand Down Expand Up @@ -107,26 +107,39 @@ module {
//
// Verify.
//
// CHECK: ( ( ( 1, 2 ), ( 3, 4 ), ( 0, 0 ) ), ( ( 0, 0 ), ( 0, 0 ), ( 0, 0 ) ), ( ( 0, 0 ), ( 5, 0 ), ( 6, 7 ) ), ( ( 0, 0 ), ( 8, 0 ), ( 0, 0 ) ) )
// CHECK: ( ( ( 1, 2 ), ( 0, 3 ), ( 4, 0 ) ), ( ( 5, 6 ), ( 0, 0 ), ( 0, 7 ) ), ( ( 8, 9 ), ( 10, 11 ), ( 12, 13 ) ), ( ( 14, 0 ), ( 0, 15 ), ( 0, 16 ) ) )
// CHECK: ( ( ( 1, 2 ), ( 0, 3 ), ( 4, 0 ) ), ( ( 5, 6 ), ( 0, 0 ), ( 0, 7 ) ), ( ( 8, 9 ), ( 10, 11 ), ( 12, 13 ) ), ( ( 14, 0 ), ( 0, 15 ), ( 0, 16 ) ) )
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 8
// CHECK-NEXT: dim = ( 4, 3, 2 )
// CHECK-NEXT: lvl = ( 4, 3, 2 )
// CHECK-NEXT: pos[0] : ( 0, 3
// CHECK-NEXT: crd[0] : ( 0, 2, 3
// CHECK-NEXT: pos[1] : ( 0, 2, 4, 5
// CHECK-NEXT: crd[1] : ( 0, 1, 1, 2, 1
// CHECK-NEXT: pos[2] : ( 0, 2, 4, 5, 7, 8
// CHECK-NEXT: crd[2] : ( 0, 1, 0, 1, 0, 0, 1, 0
// CHECK-NEXT: values : ( 1, 2, 3, 4, 5, 6, 7, 8
// CHECK-NEXT: ----
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 16
// CHECK-NEXT: dim = ( 4, 3, 2 )
// CHECK-NEXT: lvl = ( 4, 3, 2 )
// CHECK-NEXT: pos[2] : ( 0, 2, 3, 4, 6, 6, 7, 9, 11, 13, 14, 15, 16
// CHECK-NEXT: crd[2] : ( 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1
// CHECK-NEXT: values : ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
// CHECK-NEXT: ----
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 22
// CHECK-NEXT: dim = ( 4, 3, 2 )
// CHECK-NEXT: lvl = ( 4, 3, 2 )
// CHECK-NEXT: pos[1] : ( 0, 3, 5, 8, 11
// CHECK-NEXT: crd[1] : ( 0, 1, 2, 0, 2, 0, 1, 2, 0, 1, 2
// CHECK-NEXT: values : ( 1, 2, 0, 3, 4, 0, 5, 6, 0, 7, 8, 9, 10, 11, 12, 13, 14, 0, 0, 15, 0, 16
// CHECK-NEXT: ----
//
sparse_tensor.print %s0 : tensor<4x3x2xf32, #CCC>
sparse_tensor.print %s1 : tensor<4x3x2xf32, #BatchedCSR>
sparse_tensor.print %s2 : tensor<4x3x2xf32, #CSRDense>

%d0 = sparse_tensor.convert %s0 : tensor<4x3x2xf32, #CCC> to tensor<4x3x2xf32>
%v0 = vector.transfer_read %d0[%c0, %c0, %c0], %f0 : tensor<4x3x2xf32>, vector<4x3x2xf32>
vector.print %v0 : vector<4x3x2xf32>

%d1 = sparse_tensor.convert %s1 : tensor<4x3x2xf32, #BatchedCSR> to tensor<4x3x2xf32>
%v1 = vector.transfer_read %d1[%c0, %c0, %c0], %f0 : tensor<4x3x2xf32>, vector<4x3x2xf32>
vector.print %v1 : vector<4x3x2xf32>

%d2 = sparse_tensor.convert %s2 : tensor<4x3x2xf32, #CSRDense> to tensor<4x3x2xf32>
%v2 = vector.transfer_read %d1[%c0, %c0, %c0], %f0 : tensor<4x3x2xf32>, vector<4x3x2xf32>
vector.print %v2 : vector<4x3x2xf32>

bufferization.dealloc_tensor %d0 : tensor<4x3x2xf32>
bufferization.dealloc_tensor %d1 : tensor<4x3x2xf32>
bufferization.dealloc_tensor %d2 : tensor<4x3x2xf32>
// FIXME: doing this explicitly crashes runtime
// bufferization.dealloc_tensor %s0 : tensor<4x3x2xf32, #CCC>
// bufferization.dealloc_tensor %s1 : tensor<4x3x2xf32, #BatchedCSR>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -47,7 +47,7 @@ func.func @pooling_nhwc_sum(%input: tensor<1x4x4x1xf32>, %filter: tensor<2x2xf32
}


func.func @entry() {
func.func @main() {
%c0 = arith.constant 0 : index
%zero = arith.constant 0.00000e+00 : f32

Expand Down Expand Up @@ -76,17 +76,26 @@ func.func @entry() {
//
// Sparse pooling should have the same output.
//

// CHECK-NEXT: ( ( ( ( 6 ), ( 6 ), ( 6 ) ), ( ( 6 ), ( 6 ), ( 6 ) ), ( ( 6 ), ( 6 ), ( 6 ) ) ) )
%s1 = sparse_tensor.convert %CCCC_ret : tensor<1x3x3x1xf32, #CCCC> to tensor<1x3x3x1xf32>
%v1 = vector.transfer_read %s1[%c0, %c0, %c0, %c0], %zero
: tensor<1x3x3x1xf32>, vector<1x3x3x1xf32>
vector.print %v1 : vector<1x3x3x1xf32>
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 9
// CHECK-NEXT: dim = ( 1, 3, 3, 1 )
// CHECK-NEXT: lvl = ( 1, 3, 3, 1 )
// CHECK-NEXT: pos[0] : ( 0, 1
// CHECK-NEXT: crd[0] : ( 0
// CHECK-NEXT: pos[1] : ( 0, 3
// CHECK-NEXT: crd[1] : ( 0, 1, 2
// CHECK-NEXT: pos[2] : ( 0, 3, 6, 9
// CHECK-NEXT: crd[2] : ( 0, 1, 2, 0, 1, 2, 0, 1, 2
// CHECK-NEXT: pos[3] : ( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
// CHECK-NEXT: crd[3] : ( 0, 0, 0, 0, 0, 0, 0, 0, 0
// CHECK-NEXT: values : ( 6, 6, 6, 6, 6, 6, 6, 6, 6
// CHECK-NEXT: ----
//
sparse_tensor.print %CCCC_ret : tensor<1x3x3x1xf32, #CCCC>

// Releases resources.
bufferization.dealloc_tensor %in_CCCC : tensor<1x4x4x1xf32, #CCCC>
bufferization.dealloc_tensor %CCCC_ret : tensor<1x3x3x1xf32, #CCCC>
bufferization.dealloc_tensor %dense_ret : tensor<1x3x3x1xf32>
bufferization.dealloc_tensor %s1 : tensor<1x3x3x1xf32>
return
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -49,7 +49,7 @@ module {
return %0: tensor<5x6xi32>
}

func.func @entry() {
func.func @main() {
%c0 = arith.constant 0 : index
%i0 = arith.constant 0 : i32

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -114,39 +114,8 @@ module {
return %0 : tensor<?x?xf64, #CSR>
}

// Dumps a sparse vector of type f64.
func.func @dump_vec(%arg0: tensor<?xf64, #SparseVector>) {
// Dump the values array to verify only sparse contents are stored.
%c0 = arith.constant 0 : index
%d0 = arith.constant 0.0 : f64
%0 = sparse_tensor.values %arg0 : tensor<?xf64, #SparseVector> to memref<?xf64>
%1 = vector.transfer_read %0[%c0], %d0: memref<?xf64>, vector<8xf64>
vector.print %1 : vector<8xf64>
// Dump the dense vector to verify structure is correct.
%dv = sparse_tensor.convert %arg0 : tensor<?xf64, #SparseVector> to tensor<?xf64>
%2 = vector.transfer_read %dv[%c0], %d0: tensor<?xf64>, vector<16xf64>
vector.print %2 : vector<16xf64>
bufferization.dealloc_tensor %dv : tensor<?xf64>
return
}

// Dump a sparse matrix.
func.func @dump_mat(%arg0: tensor<?x?xf64, #CSR>) {
// Dump the values array to verify only sparse contents are stored.
%c0 = arith.constant 0 : index
%d0 = arith.constant 0.0 : f64
%0 = sparse_tensor.values %arg0 : tensor<?x?xf64, #CSR> to memref<?xf64>
%1 = vector.transfer_read %0[%c0], %d0: memref<?xf64>, vector<16xf64>
vector.print %1 : vector<16xf64>
%dm = sparse_tensor.convert %arg0 : tensor<?x?xf64, #CSR> to tensor<?x?xf64>
%2 = vector.transfer_read %dm[%c0, %c0], %d0: tensor<?x?xf64>, vector<5x5xf64>
vector.print %2 : vector<5x5xf64>
bufferization.dealloc_tensor %dm : tensor<?x?xf64>
return
}

// Driver method to call and verify vector kernels.
func.func @entry() {
func.func @main() {
%c0 = arith.constant 0 : index

// Setup sparse matrices.
Expand All @@ -171,19 +140,43 @@ module {
//
// Verify the results.
//
// CHECK: ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0 )
// CHECK-NEXT: ( ( 1, 2, 0, 0, 0 ), ( 3, 0, 0, 0, 0 ), ( 0, 0, 4, 5, 6 ), ( 7, 0, 8, 9, 0 ), ( 0, 0, 0, 0, 0 ) )
// CHECK-NEXT: ( 6, 5, 4, 3, 2, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
// CHECK-NEXT: ( ( 6, 0, 0, 0, 0 ), ( 0, 0, 0, 5, 0 ), ( 4, 0, 0, 3, 0 ), ( 0, 2, 0, 0, 0 ), ( 0, 11, 0, 0, 0 ) )
// CHECK-NEXT: ( 7, 7, 9, 8, 7, 7, 12, 11, 11, 0, 0, 0, 0, 0, 0, 0 )
// CHECK-NEXT: ( ( 7, 0, 0, 7, 0 ), ( 9, 0, 0, 0, 0 ), ( 8, 7, 0, 7, 0 ), ( 12, 11, 0, 11, 0 ), ( 0, 0, 0, 0, 0 ) )
// CHECK-NEXT: ( 7, 7, 9, 8, 7, 7, 12, 11, 11, 0, 0, 0, 0, 0, 0, 0 )
// CHECK-NEXT: ( ( 7, 0, 0, 7, 0 ), ( 9, 0, 0, 0, 0 ), ( 8, 7, 0, 7, 0 ), ( 12, 11, 0, 11, 0 ), ( 0, 0, 0, 0, 0 ) )
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 9
// CHECK-NEXT: dim = ( 4, 5 )
// CHECK-NEXT: lvl = ( 4, 5 )
// CHECK-NEXT: pos[1] : ( 0, 2, 3, 6, 9
// CHECK-NEXT: crd[1] : ( 0, 1, 0, 2, 3, 4, 0, 2, 3
// CHECK-NEXT: values : ( 1, 2, 3, 4, 5, 6, 7, 8, 9
// CHECK-NEXT: ----
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 6
// CHECK-NEXT: dim = ( 5, 4 )
// CHECK-NEXT: lvl = ( 5, 4 )
// CHECK-NEXT: pos[1] : ( 0, 1, 2, 4, 5, 6
// CHECK-NEXT: crd[1] : ( 0, 3, 0, 3, 1, 1
// CHECK-NEXT: values : ( 6, 5, 4, 3, 2, 11
// CHECK-NEXT: ----
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 9
// CHECK-NEXT: dim = ( 4, 4 )
// CHECK-NEXT: lvl = ( 4, 4 )
// CHECK-NEXT: pos[1] : ( 0, 2, 3, 6, 9
// CHECK-NEXT: crd[1] : ( 0, 3, 0, 0, 1, 3, 0, 1, 3
// CHECK-NEXT: values : ( 7, 7, 9, 8, 7, 7, 12, 11, 11
// CHECK-NEXT: ----
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 9
// CHECK-NEXT: dim = ( 4, 4 )
// CHECK-NEXT: lvl = ( 4, 4 )
// CHECK-NEXT: pos[1] : ( 0, 2, 3, 6, 9
// CHECK-NEXT: crd[1] : ( 0, 3, 0, 0, 1, 3, 0, 1, 3
// CHECK-NEXT: values : ( 7, 7, 9, 8, 7, 7, 12, 11, 11
// CHECK-NEXT: ----
//
call @dump_mat(%sm1) : (tensor<?x?xf64, #CSR>) -> ()
call @dump_mat(%sm2r) : (tensor<?x?xf64, #CSR>) -> ()
call @dump_mat(%5) : (tensor<?x?xf64, #CSR>) -> ()
call @dump_mat(%6) : (tensor<?x?xf64, #CSR>) -> ()
sparse_tensor.print %sm1 : tensor<?x?xf64, #CSR>
sparse_tensor.print %sm2r : tensor<?x?xf64, #CSR>
sparse_tensor.print %5 : tensor<?x?xf64, #CSR>
sparse_tensor.print %6 : tensor<?x?xf64, #CSR>

// Release the resources.
bufferization.dealloc_tensor %sm1 : tensor<?x?xf64, #CSR>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -89,39 +89,9 @@ module {
return %0 : tensor<?xf64, #SparseVector>
}

// Dumps a sparse vector of type f64.
func.func @dump_vec(%arg0: tensor<?xf64, #SparseVector>) {
// Dump the values array to verify only sparse contents are stored.
%c0 = arith.constant 0 : index
%d0 = arith.constant 0.0 : f64
%0 = sparse_tensor.values %arg0 : tensor<?xf64, #SparseVector> to memref<?xf64>
%1 = vector.transfer_read %0[%c0], %d0: memref<?xf64>, vector<8xf64>
vector.print %1 : vector<8xf64>
// Dump the dense vector to verify structure is correct.
%dv = sparse_tensor.convert %arg0 : tensor<?xf64, #SparseVector> to tensor<?xf64>
%2 = vector.transfer_read %dv[%c0], %d0: tensor<?xf64>, vector<16xf64>
vector.print %2 : vector<16xf64>
bufferization.dealloc_tensor %dv : tensor<?xf64>
return
}

// Dump a sparse matrix.
func.func @dump_mat(%arg0: tensor<?x?xf64, #CSR>) {
// Dump the values array to verify only sparse contents are stored.
%c0 = arith.constant 0 : index
%d0 = arith.constant 0.0 : f64
%0 = sparse_tensor.values %arg0 : tensor<?x?xf64, #CSR> to memref<?xf64>
%1 = vector.transfer_read %0[%c0], %d0: memref<?xf64>, vector<16xf64>
vector.print %1 : vector<16xf64>
%dm = sparse_tensor.convert %arg0 : tensor<?x?xf64, #CSR> to tensor<?x?xf64>
%2 = vector.transfer_read %dm[%c0, %c0], %d0: tensor<?x?xf64>, vector<5x5xf64>
vector.print %2 : vector<5x5xf64>
bufferization.dealloc_tensor %dm : tensor<?x?xf64>
return
}

// Driver method to call and verify vector kernels.
func.func @entry() {
func.func @main() {
%c0 = arith.constant 0 : index

// Setup sparse matrices.
Expand All @@ -144,15 +114,43 @@ module {
//
// Verify the results.
//
// CHECK: ( 2, 3, 120, 504, 0, 0, 0, 0 )
// CHECK-NEXT: ( 2, 3, 120, 504, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
// CHECK-NEXT: ( 6, 5, 12, 2, 11, 0, 0, 0 )
// CHECK-NEXT: ( 6, 5, 12, 2, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 9
// CHECK-NEXT: dim = ( 4, 5 )
// CHECK-NEXT: lvl = ( 4, 5 )
// CHECK-NEXT: pos[1] : ( 0, 2, 3, 6, 9
// CHECK-NEXT: crd[1] : ( 0, 1, 0, 2, 3, 4, 0, 2, 3
// CHECK-NEXT: values : ( 1, 2, 3, 4, 5, 6, 7, 8, 9
// CHECK-NEXT: ----
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 6
// CHECK-NEXT: dim = ( 5, 4 )
// CHECK-NEXT: lvl = ( 5, 4 )
// CHECK-NEXT: pos[1] : ( 0, 1, 2, 4, 5, 6
// CHECK-NEXT: crd[1] : ( 0, 3, 0, 3, 1, 1
// CHECK-NEXT: values : ( 6, 5, 4, 3, 2, 11
// CHECK-NEXT: ----
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 4
// CHECK-NEXT: dim = ( 4 )
// CHECK-NEXT: lvl = ( 4 )
// CHECK-NEXT: pos[0] : ( 0, 4
// CHECK-NEXT: crd[0] : ( 0, 1, 2, 3
// CHECK-NEXT: values : ( 2, 3, 120, 504
// CHECK-NEXT: ----
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 5
// CHECK-NEXT: dim = ( 5 )
// CHECK-NEXT: lvl = ( 5 )
// CHECK-NEXT: pos[0] : ( 0, 5
// CHECK-NEXT: crd[0] : ( 0, 1, 2, 3, 4
// CHECK-NEXT: values : ( 6, 5, 12, 2, 11
// CHECK-NEXT: ----
//
call @dump_mat(%sm1) : (tensor<?x?xf64, #CSR>) -> ()
call @dump_mat(%sm2r) : (tensor<?x?xf64, #CSR>) -> ()
call @dump_vec(%1) : (tensor<?xf64, #SparseVector>) -> ()
call @dump_vec(%2) : (tensor<?xf64, #SparseVector>) -> ()
sparse_tensor.print %sm1 : tensor<?x?xf64, #CSR>
sparse_tensor.print %sm2r : tensor<?x?xf64, #CSR>
sparse_tensor.print %1 : tensor<?xf64, #SparseVector>
sparse_tensor.print %2 : tensor<?xf64, #SparseVector>

// Release the resources.
bufferization.dealloc_tensor %sm1 : tensor<?x?xf64, #CSR>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -145,7 +145,7 @@ module {
return
}

func.func @entry() {
func.func @main() {
%ri = arith.constant dense<0> : tensor<i32>

// Sparse vector of length 8 with 2 stored elements (and thus 6 implicit zeros).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -106,7 +106,7 @@ module {
return
}

func.func @entry() {
func.func @main() {
%ri = arith.constant dense< 7 > : tensor<i32>
%rf = arith.constant dense< 2.0 > : tensor<f32>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -82,7 +82,7 @@ module {
return
}

func.func @entry() {
func.func @main() {
%ri = arith.constant dense<999> : tensor<i32>

// Vectors with a few zeros.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -162,7 +162,7 @@ module {
return
}

func.func @entry() {
func.func @main() {
// Note: Constants bufferize to read-only buffers.
%ri = arith.constant dense< 7 > : tensor<i32>
%rf = arith.constant dense< 2.0 > : tensor<f32>
Expand Down
53 changes: 37 additions & 16 deletions mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_reshape.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -63,7 +63,7 @@ module {
}


func.func @entry() {
func.func @main() {
%m = arith.constant dense <[ [ 1.1, 0.0, 1.3, 0.0 ],
[ 2.1, 0.0, 2.3, 0.0 ],
[ 3.1, 0.0, 3.3, 0.0 ]]> : tensor<3x4xf64>
Expand All @@ -76,20 +76,41 @@ module {
%c0 = arith.constant 0 : index
%df = arith.constant -1.0 : f64

// CHECK: ( 1.1, 1.3, 2.1, 2.3, 3.1, 3.3
%b0 = sparse_tensor.values %reshaped0: tensor<2x6xf64, #SparseMatrix> to memref<?xf64>
%v0 = vector.transfer_read %b0[%c0], %df: memref<?xf64>, vector<12xf64>
vector.print %v0 : vector<12xf64>

// CHECK: ( 1.1, 1.3, 2.1, 2.3, 3.1, 3.3
%b1 = sparse_tensor.values %reshaped1: tensor<12xf64, #SparseVector> to memref<?xf64>
%v1 = vector.transfer_read %b1[%c0], %df: memref<?xf64>, vector<12xf64>
vector.print %v1 : vector<12xf64>

// CHECK: ( 1.1, 1.3, 2.1, 2.3, 3.1, 3.3
%b2 = sparse_tensor.values %reshaped2: tensor<2x3x2xf64, #Sparse3dTensor> to memref<?xf64>
%v2 = vector.transfer_read %b2[%c0], %df: memref<?xf64>, vector<12xf64>
vector.print %v2: vector<12xf64>
//
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 6
// CHECK-NEXT: dim = ( 2, 6 )
// CHECK-NEXT: lvl = ( 2, 6 )
// CHECK-NEXT: pos[0] : ( 0, 2
// CHECK-NEXT: crd[0] : ( 0, 1
// CHECK-NEXT: pos[1] : ( 0, 3, 6
// CHECK-NEXT: crd[1] : ( 0, 2, 4, 0, 2, 4
// CHECK-NEXT: values : ( 1.1, 1.3, 2.1, 2.3, 3.1, 3.3
// CHECK-NEXT: ----
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 6
// CHECK-NEXT: dim = ( 12 )
// CHECK-NEXT: lvl = ( 12 )
// CHECK-NEXT: pos[0] : ( 0, 6
// CHECK-NEXT: crd[0] : ( 0, 2, 4, 6, 8, 10
// CHECK-NEXT: values : ( 1.1, 1.3, 2.1, 2.3, 3.1, 3.3
// CHECK-NEXT: ----
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 6
// CHECK-NEXT: dim = ( 2, 3, 2 )
// CHECK-NEXT: lvl = ( 2, 3, 2 )
// CHECK-NEXT: pos[0] : ( 0, 2
// CHECK-NEXT: crd[0] : ( 0, 1
// CHECK-NEXT: pos[1] : ( 0, 3, 6
// CHECK-NEXT: crd[1] : ( 0, 1, 2, 0, 1, 2
// CHECK-NEXT: pos[2] : ( 0, 1, 2, 3, 4, 5, 6
// CHECK-NEXT: crd[2] : ( 0, 0, 0, 0, 0, 0
// CHECK-NEXT: values : ( 1.1, 1.3, 2.1, 2.3, 3.1, 3.3
// CHECK-NEXT: ----
//
sparse_tensor.print %reshaped0: tensor<2x6xf64, #SparseMatrix>
sparse_tensor.print %reshaped1: tensor<12xf64, #SparseVector>
sparse_tensor.print %reshaped2: tensor<2x3x2xf64, #Sparse3dTensor>

bufferization.dealloc_tensor %sm : tensor<3x4xf64, #SparseMatrix>
bufferization.dealloc_tensor %reshaped0 : tensor<2x6xf64, #SparseMatrix>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand All @@ -28,7 +28,7 @@
// RUN: %if mlir_arm_sve_tests %{ %{compile_sve} | %{run_sve} | FileCheck %s %}

module {
func.func @entry() {
func.func @main() {
%c0 = arith.constant 0 : index
%c1 = arith.constant 1 : index
%c10 = arith.constant 10 : index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -64,7 +64,7 @@ module {
}

// The main driver.
func.func @entry() {
func.func @main() {
%c0 = arith.constant 0 : i32
%c1 = arith.constant 1 : i32
%c2 = arith.constant 2 : i32
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -81,7 +81,7 @@ module {
//
// Main driver that reads matrix from file and calls the sparse kernel.
//
func.func @entry() {
func.func @main() {
%d0 = arith.constant 0.0 : f32
%c0 = arith.constant 0 : index
%c1 = arith.constant 1 : index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -169,7 +169,7 @@ module {
//
// Main driver.
//
func.func @entry() {
func.func @main() {
%d0 = arith.constant 0.0 : f64
%c0 = arith.constant 0 : index

Expand Down Expand Up @@ -207,22 +207,36 @@ module {
// CHECK-SAME: ( 0, 0, 0, 0, 0, 0, 0, 0 ), ( 0, 0, 0, 0, 0, 0, 0, 0 ),
// CHECK-SAME: ( 0, 0, 0, 0, 0, 0, 0, 0 ), ( 0, 0, 0, 0, 0, 0, 0, 192 ) )
//
// CHECK-NEXT: ( 96, 192, 0, 0 )
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 2
// CHECK-NEXT: dim = ( 8, 8 )
// CHECK-NEXT: lvl = ( 8, 8 )
// CHECK-NEXT: pos[0] : ( 0, 2
// CHECK-NEXT: crd[0] : ( 0, 7
// CHECK-NEXT: pos[1] : ( 0, 1, 2
// CHECK-NEXT: crd[1] : ( 0, 7
// CHECK-NEXT: values : ( 96, 192
// CHECK-NEXT: ----
//
// CHECK-NEXT: ( 96, 192, 0, 0 )
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 2
// CHECK-NEXT: dim = ( 8, 8 )
// CHECK-NEXT: lvl = ( 8, 8 )
// CHECK-NEXT: pos[0] : ( 0, 2
// CHECK-NEXT: crd[0] : ( 0, 7
// CHECK-NEXT: pos[1] : ( 0, 1, 2
// CHECK-NEXT: crd[1] : ( 0, 7
// CHECK-NEXT: values : ( 96, 192
// CHECK-NEXT: ----
//
%m2 = sparse_tensor.values %2 : tensor<8x8xf64, #SM> to memref<?xf64>
%m3 = sparse_tensor.values %3 : tensor<8x8xf64, #SM> to memref<?xf64>
%v0 = vector.transfer_read %0[%c0, %c0], %d0
: tensor<8x8xf64>, vector<8x8xf64>
%v1 = vector.transfer_read %1[%c0, %c0], %d0
: tensor<8x8xf64>, vector<8x8xf64>
%v2 = vector.transfer_read %m2[%c0], %d0 : memref<?xf64>, vector<4xf64>
%v3 = vector.transfer_read %m3[%c0], %d0 : memref<?xf64>, vector<4xf64>
vector.print %v0 : vector<8x8xf64>
vector.print %v1 : vector<8x8xf64>
vector.print %v2 : vector<4xf64>
vector.print %v3 : vector<4xf64>
sparse_tensor.print %2 : tensor<8x8xf64, #SM>
sparse_tensor.print %3 : tensor<8x8xf64, #SM>

// Release the resources.
bufferization.dealloc_tensor %s : tensor<8x8xf64, #SM>
Expand Down
17 changes: 11 additions & 6 deletions mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_scale.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -65,7 +65,7 @@ module {
// and then calls the sparse scaling kernel with the sparse tensor
// as input argument.
//
func.func @entry() {
func.func @main() {
%c0 = arith.constant 0 : index
%f0 = arith.constant 0.0 : f32

Expand All @@ -88,11 +88,16 @@ module {

// Print the resulting compacted values for verification.
//
// CHECK: ( 2, 2, 2, 4, 6, 8, 2, 10, 2, 2, 12, 2, 14, 2, 2, 16 )
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 16
// CHECK-NEXT: dim = ( 8, 8 )
// CHECK-NEXT: lvl = ( 8, 8 )
// CHECK-NEXT: pos[1] : ( 0, 3, 4, 5, 6, 8, 11, 14, 16
// CHECK-NEXT: crd[1] : ( 0, 2, 7, 1, 2, 3, 1, 4, 1, 2, 5, 2, 6, 7, 2, 7
// CHECK-NEXT: values : ( 2, 2, 2, 4, 6, 8, 2, 10, 2, 2, 12, 2, 14, 2, 2, 16
// CHECK-NEXT: ----
//
%m = sparse_tensor.values %2 : tensor<8x8xf32, #CSR> to memref<?xf32>
%v = vector.transfer_read %m[%c0], %f0: memref<?xf32>, vector<16xf32>
vector.print %v : vector<16xf32>
sparse_tensor.print %2 : tensor<8x8xf32, #CSR>

// Release the resources.
bufferization.dealloc_tensor %1 : tensor<8x8xf32, #CSR>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -68,17 +68,7 @@ module @func_sparse.2 {
return %1 : tensor<2x3x4xf64, #SparseMatrix>
}

func.func @dump(%arg0: tensor<2x3x4xf64, #SparseMatrix>) {
%d0 = arith.constant 0.0 : f64
%c0 = arith.constant 0 : index
%dm = sparse_tensor.convert %arg0 : tensor<2x3x4xf64, #SparseMatrix> to tensor<2x3x4xf64>
%0 = vector.transfer_read %dm[%c0, %c0, %c0], %d0: tensor<2x3x4xf64>, vector<2x3x4xf64>
vector.print %0 : vector<2x3x4xf64>
bufferization.dealloc_tensor %dm : tensor<2x3x4xf64>
return
}

func.func public @entry() {
func.func public @main() {
%src = arith.constant dense<[
[ [ 1.0, 2.0, 3.0, 4.0 ],
[ 5.0, 6.0, 7.0, 8.0 ],
Expand All @@ -96,10 +86,34 @@ module @func_sparse.2 {
%sm_t = call @condition(%t, %sm) : (i1, tensor<2x3x4xf64, #SparseMatrix>) -> tensor<2x3x4xf64, #SparseMatrix>
%sm_f = call @condition(%f, %sm) : (i1, tensor<2x3x4xf64, #SparseMatrix>) -> tensor<2x3x4xf64, #SparseMatrix>

// CHECK: ( ( ( 0, 1, 2, 3 ), ( 4, 5, 6, 7 ), ( 8, 9, 10, 11 ) ), ( ( 12, 13, 14, 15 ), ( 16, 17, 18, 19 ), ( 20, 21, 22, 23 ) ) )
// CHECK-NEXT: ( ( ( 2, 3, 4, 5 ), ( 6, 7, 8, 9 ), ( 10, 11, 12, 13 ) ), ( ( 14, 15, 16, 17 ), ( 18, 19, 20, 21 ), ( 22, 23, 24, 25 ) ) )
call @dump(%sm_t) : (tensor<2x3x4xf64, #SparseMatrix>) -> ()
call @dump(%sm_f) : (tensor<2x3x4xf64, #SparseMatrix>) -> ()
//
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 24
// CHECK-NEXT: dim = ( 2, 3, 4 )
// CHECK-NEXT: lvl = ( 2, 3, 4 )
// CHECK-NEXT: pos[0] : ( 0, 2
// CHECK-NEXT: crd[0] : ( 0, 1
// CHECK-NEXT: pos[1] : ( 0, 3, 6
// CHECK-NEXT: crd[1] : ( 0, 1, 2, 0, 1, 2
// CHECK-NEXT: pos[2] : ( 0, 4, 8, 12, 16, 20, 24
// CHECK-NEXT: crd[2] : ( 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3
// CHECK-NEXT: values : ( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23
// CHECK-NEXT: ----
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 24
// CHECK-NEXT: dim = ( 2, 3, 4 )
// CHECK-NEXT: lvl = ( 2, 3, 4 )
// CHECK-NEXT: pos[0] : ( 0, 2
// CHECK-NEXT: crd[0] : ( 0, 1
// CHECK-NEXT: pos[1] : ( 0, 3, 6
// CHECK-NEXT: crd[1] : ( 0, 1, 2, 0, 1, 2
// CHECK-NEXT: pos[2] : ( 0, 4, 8, 12, 16, 20, 24
// CHECK-NEXT: crd[2] : ( 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3
// CHECK-NEXT: values : ( 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25
// CHECK-NEXT: ----
//
sparse_tensor.print %sm_t : tensor<2x3x4xf64, #SparseMatrix>
sparse_tensor.print %sm_f : tensor<2x3x4xf64, #SparseMatrix>

bufferization.dealloc_tensor %sm : tensor<2x3x4xf64, #SparseMatrix>
bufferization.dealloc_tensor %sm_t : tensor<2x3x4xf64, #SparseMatrix>
Expand Down
83 changes: 38 additions & 45 deletions mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_select.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -97,39 +97,8 @@ module {
return %0 : tensor<?x?xf64, #CSR>
}

// Dumps a sparse vector of type f64.
func.func @dump_vec(%arg0: tensor<?xf64, #SparseVector>) {
// Dump the values array to verify only sparse contents are stored.
%c0 = arith.constant 0 : index
%d0 = arith.constant 0.0 : f64
%0 = sparse_tensor.values %arg0 : tensor<?xf64, #SparseVector> to memref<?xf64>
%1 = vector.transfer_read %0[%c0], %d0: memref<?xf64>, vector<8xf64>
vector.print %1 : vector<8xf64>
// Dump the dense vector to verify structure is correct.
%dv = sparse_tensor.convert %arg0 : tensor<?xf64, #SparseVector> to tensor<?xf64>
%2 = vector.transfer_read %dv[%c0], %d0: tensor<?xf64>, vector<16xf64>
vector.print %2 : vector<16xf64>
bufferization.dealloc_tensor %dv : tensor<?xf64>
return
}

// Dump a sparse matrix.
func.func @dump_mat(%arg0: tensor<?x?xf64, #CSR>) {
// Dump the values array to verify only sparse contents are stored.
%c0 = arith.constant 0 : index
%d0 = arith.constant 0.0 : f64
%0 = sparse_tensor.values %arg0 : tensor<?x?xf64, #CSR> to memref<?xf64>
%1 = vector.transfer_read %0[%c0], %d0: memref<?xf64>, vector<16xf64>
vector.print %1 : vector<16xf64>
%dm = sparse_tensor.convert %arg0 : tensor<?x?xf64, #CSR> to tensor<?x?xf64>
%2 = vector.transfer_read %dm[%c0, %c0], %d0: tensor<?x?xf64>, vector<5x5xf64>
vector.print %2 : vector<5x5xf64>
bufferization.dealloc_tensor %dm : tensor<?x?xf64>
return
}

// Driver method to call and verify vector kernels.
func.func @entry() {
func.func @main() {
%c0 = arith.constant 0 : index

// Setup sparse matrices.
Expand All @@ -151,19 +120,43 @@ module {
//
// Verify the results.
//
// CHECK: ( 1, 2, -4, 0, 5, 0, 0, 0 )
// CHECK-NEXT: ( 0, 1, 0, 2, 0, -4, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0 )
// CHECK-NEXT: ( 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
// CHECK-NEXT: ( ( 0, 0, 0, 1, 0 ), ( 0, 0, 0, 0, 2 ), ( 0, 3, 0, 4, 0 ), ( 0, 0, 0, 5, 6 ), ( 0, 0, 7, 0, 0 ) )
// CHECK-NEXT: ( 1, 2, 5, 0, 0, 0, 0, 0 )
// CHECK-NEXT: ( 0, 1, 0, 2, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0 )
// CHECK-NEXT: ( 1, 2, 4, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
// CHECK-NEXT: ( ( 0, 0, 0, 1, 0 ), ( 0, 0, 0, 0, 2 ), ( 0, 0, 0, 4, 0 ), ( 0, 0, 0, 0, 6 ), ( 0, 0, 0, 0, 0 ) )
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 5
// CHECK-NEXT: dim = ( 10 )
// CHECK-NEXT: lvl = ( 10 )
// CHECK-NEXT: pos[0] : ( 0, 5
// CHECK-NEXT: crd[0] : ( 1, 3, 5, 7, 9
// CHECK-NEXT: values : ( 1, 2, -4, 0, 5
// CHECK-NEXT: ----
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 7
// CHECK-NEXT: dim = ( 5, 5 )
// CHECK-NEXT: lvl = ( 5, 5 )
// CHECK-NEXT: pos[1] : ( 0, 1, 2, 4, 6, 7
// CHECK-NEXT: crd[1] : ( 3, 4, 1, 3, 3, 4, 2
// CHECK-NEXT: values : ( 1, 2, 3, 4, 5, 6, 7
// CHECK-NEXT: ----
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 3
// CHECK-NEXT: dim = ( 10 )
// CHECK-NEXT: lvl = ( 10 )
// CHECK-NEXT: pos[0] : ( 0, 3
// CHECK-NEXT: crd[0] : ( 1, 3, 9
// CHECK-NEXT: values : ( 1, 2, 5
// CHECK-NEXT: ----
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 4
// CHECK-NEXT: dim = ( 5, 5 )
// CHECK-NEXT: lvl = ( 5, 5 )
// CHECK-NEXT: pos[1] : ( 0, 1, 2, 3, 4, 4
// CHECK-NEXT: crd[1] : ( 3, 4, 3, 4
// CHECK-NEXT: values : ( 1, 2, 4, 6
// CHECK-NEXT: ----
//
call @dump_vec(%sv1) : (tensor<?xf64, #SparseVector>) -> ()
call @dump_mat(%sm1) : (tensor<?x?xf64, #CSR>) -> ()
call @dump_vec(%1) : (tensor<?xf64, #SparseVector>) -> ()
call @dump_mat(%2) : (tensor<?x?xf64, #CSR>) -> ()
sparse_tensor.print %sv1 : tensor<?xf64, #SparseVector>
sparse_tensor.print %sm1 : tensor<?x?xf64, #CSR>
sparse_tensor.print %1 : tensor<?xf64, #SparseVector>
sparse_tensor.print %2 : tensor<?x?xf64, #CSR>

// Release the resources.
bufferization.dealloc_tensor %sv1 : tensor<?xf64, #SparseVector>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -60,7 +60,7 @@ module {
}

// Driver method to call and verify vector kernels.
func.func @entry() {
func.func @main() {
%c0 = arith.constant 0 : index
%f0 = arith.constant 0.0 : f64

Expand All @@ -86,20 +86,24 @@ module {
tensor<5x5xf64, #DCSR>) -> tensor<5x5xf64, #DCSR>


// CHECK: ( ( 0.1, 1.1, 0, 0, 0 ),
// CHECK-SAME: ( 0, 1.1, 2.2, 0, 0 ),
// CHECK-SAME: ( 0, 0, 2.1, 3.3, 0 ),
// CHECK-SAME: ( 0, 0, 0, 3.1, 4.4 ),
// CHECK-SAME: ( 0, 0, 0, 0, 4.1 ) )
%r = sparse_tensor.convert %1 : tensor<5x5xf64, #DCSR> to tensor<5x5xf64>
%v2 = vector.transfer_read %r[%c0, %c0], %f0 : tensor<5x5xf64>, vector<5x5xf64>
vector.print %v2 : vector<5x5xf64>
//
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 9
// CHECK-NEXT: dim = ( 5, 5 )
// CHECK-NEXT: lvl = ( 5, 5 )
// CHECK-NEXT: pos[0] : ( 0, 5
// CHECK-NEXT: crd[0] : ( 0, 1, 2, 3, 4
// CHECK-NEXT: pos[1] : ( 0, 2, 4, 6, 8, 9
// CHECK-NEXT: crd[1] : ( 0, 1, 1, 2, 2, 3, 3, 4, 4
// CHECK-NEXT: values : ( 0.1, 1.1, 1.1, 2.2, 2.1, 3.3, 3.1, 4.4, 4.1
// CHECK-NEXT: ----
//
sparse_tensor.print %1 : tensor<5x5xf64, #DCSR>

// Release the resources.
bufferization.dealloc_tensor %sl: tensor<5x5xf64, #DCSR>
bufferization.dealloc_tensor %sr: tensor<5x5xf64, #DCSR>
bufferization.dealloc_tensor %1: tensor<5x5xf64, #DCSR>
bufferization.dealloc_tensor %r : tensor<5x5xf64>

return
}
Expand Down
17 changes: 11 additions & 6 deletions mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_sign.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -79,7 +79,7 @@ module {
}

// Driver method to call and verify sign kernel.
func.func @entry() {
func.func @main() {
%c0 = arith.constant 0 : index
%du = arith.constant 0.0 : f64

Expand Down Expand Up @@ -110,11 +110,16 @@ module {
//
// Verify the results.
//
// CHECK: ( -1, 1, -1, 1, 1, -1, nan, -nan, 1, -1, -0, 0, 0 )
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 12
// CHECK-NEXT: dim = ( 32 )
// CHECK-NEXT: lvl = ( 32 )
// CHECK-NEXT: pos[0] : ( 0, 12
// CHECK-NEXT: crd[0] : ( 0, 3, 5, 11, 13, 17, 18, 20, 21, 28, 29, 31
// CHECK-NEXT: values : ( -1, 1, -1, 1, 1, -1, nan, -nan, 1, -1, -0, 0
// CHECK-NEXT: ----
//
%1 = sparse_tensor.values %0 : tensor<?xf64, #SparseVector> to memref<?xf64>
%2 = vector.transfer_read %1[%c0], %du: memref<?xf64>, vector<13xf64>
vector.print %2 : vector<13xf64>
sparse_tensor.print %0 : tensor<?xf64, #SparseVector>

// Release the resources.
bufferization.dealloc_tensor %sv1 : tensor<?xf64, #SparseVector>
Expand Down
200 changes: 68 additions & 132 deletions mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_sorted_coo.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand All @@ -35,19 +35,19 @@
!Filename = !llvm.ptr

#SortedCOO = #sparse_tensor.encoding<{
map = (d0, d1) -> (d0 : compressed(nonunique), d1 : singleton)
map = (d0, d1) -> (d0 : compressed(nonunique), d1 : singleton(soa))
}>

#SortedCOOPermuted = #sparse_tensor.encoding<{
map = (d0, d1) -> (d1 : compressed(nonunique), d0 : singleton),
map = (d0, d1) -> (d1 : compressed(nonunique), d0 : singleton(soa)),
}>

#SortedCOO3D = #sparse_tensor.encoding<{
map = (d0, d1, d2) -> (d0 : compressed(nonunique), d1 : singleton(nonunique), d2 : singleton)
map = (d0, d1, d2) -> (d0 : compressed(nonunique), d1 : singleton(nonunique, soa), d2 : singleton(soa))
}>

#SortedCOO3DPermuted = #sparse_tensor.encoding<{
map = (d0, d1, d2) -> (d2 : compressed(nonunique), d0 : singleton(nonunique), d1 : singleton)
map = (d0, d1, d2) -> (d2 : compressed(nonunique), d0 : singleton(nonunique, soa), d1 : singleton(soa))

}>

Expand Down Expand Up @@ -82,29 +82,7 @@ module {
return %0 : tensor<?x?xf64, #SortedCOO>
}

func.func @dumpi(%arg0: memref<?xindex>) {
%c0 = arith.constant 0 : index
%v = vector.transfer_read %arg0[%c0], %c0: memref<?xindex>, vector<20xindex>
vector.print %v : vector<20xindex>
return
}

func.func @dumpsi(%arg0: memref<?xindex, strided<[?], offset: ?>>) {
%c0 = arith.constant 0 : index
%v = vector.transfer_read %arg0[%c0], %c0: memref<?xindex, strided<[?], offset: ?>>, vector<20xindex>
vector.print %v : vector<20xindex>
return
}

func.func @dumpf(%arg0: memref<?xf64>) {
%c0 = arith.constant 0 : index
%nan = arith.constant 0x0 : f64
%v = vector.transfer_read %arg0[%c0], %nan: memref<?xf64>, vector<20xf64>
vector.print %v : vector<20xf64>
return
}

func.func @entry() {
func.func @main() {
%c0 = arith.constant 0 : index
%c1 = arith.constant 1 : index

Expand All @@ -125,130 +103,88 @@ module {
%4 = sparse_tensor.convert %m : tensor<5x4xf64> to tensor<?x?xf64, #SortedCOO>

//
// CHECK: ( 0, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
// CHECK-NEXT: ( 0, 0, 0, 0, 1, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0 )
// CHECK-NEXT: ( 0, 126, 127, 254, 1, 253, 2, 0, 1, 3, 98, 126, 127, 128, 249, 253, 255, 0, 0, 0 )
// CHECK-NEXT: ( -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, -13, 14, -15, 16, -17, 0, 0, 0 )
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 17
// CHECK-NEXT: dim = ( 4, 256 )
// CHECK-NEXT: lvl = ( 4, 256 )
// CHECK-NEXT: pos[0] : ( 0, 17
// CHECK-NEXT: crd[0] : ( 0, 0, 0, 0, 1, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
// CHECK-NEXT: crd[1] : ( 0, 126, 127, 254, 1, 253, 2, 0, 1, 3, 98, 126, 127, 128, 249, 253, 255
// CHECK-NEXT: values : ( -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, -13, 14, -15, 16, -17
// CHECK-NEXT: ----
//
%p0 = sparse_tensor.positions %0 { level = 0 : index }
: tensor<?x?xf64, #SortedCOO> to memref<?xindex>
%i00 = sparse_tensor.coordinates %0 { level = 0 : index }
: tensor<?x?xf64, #SortedCOO> to memref<?xindex, strided<[?], offset: ?>>
%i01 = sparse_tensor.coordinates %0 { level = 1 : index }
: tensor<?x?xf64, #SortedCOO> to memref<?xindex, strided<[?], offset: ?>>
%v0 = sparse_tensor.values %0
: tensor<?x?xf64, #SortedCOO> to memref<?xf64>
call @dumpi(%p0) : (memref<?xindex>) -> ()
call @dumpsi(%i00) : (memref<?xindex, strided<[?], offset: ?>>) -> ()
call @dumpsi(%i01) : (memref<?xindex, strided<[?], offset: ?>>) -> ()
call @dumpf(%v0) : (memref<?xf64>) -> ()
sparse_tensor.print %0 : tensor<?x?xf64, #SortedCOO>

//
// CHECK-NEXT: ( 0, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
// CHECK-NEXT: ( 0, 0, 1, 1, 2, 3, 98, 126, 126, 127, 127, 128, 249, 253, 253, 254, 255, 0, 0, 0 )
// CHECK-NEXT: ( 0, 3, 1, 3, 2, 3, 3, 0, 3, 0, 3, 3, 3, 1, 3, 0, 3, 0, 0, 0 )
// CHECK-NEXT: ( -1, 8, -5, -9, -7, 10, -11, 2, 12, -3, -13, 14, -15, 6, 16, 4, -17, 0, 0, 0 )
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 17
// CHECK-NEXT: dim = ( 4, 256 )
// CHECK-NEXT: lvl = ( 256, 4 )
// CHECK-NEXT: pos[0] : ( 0, 17
// CHECK-NEXT: crd[0] : ( 0, 0, 1, 1, 2, 3, 98, 126, 126, 127, 127, 128, 249, 253, 253, 254, 255
// CHECK-NEXT: crd[1] : ( 0, 3, 1, 3, 2, 3, 3, 0, 3, 0, 3, 3, 3, 1, 3, 0, 3
// CHECK-NEXT: values : ( -1, 8, -5, -9, -7, 10, -11, 2, 12, -3, -13, 14, -15, 6, 16, 4, -17
// CHECK-NEXT: ----
//
%p1 = sparse_tensor.positions %1 { level = 0 : index }
: tensor<?x?xf64, #SortedCOOPermuted> to memref<?xindex>
%i10 = sparse_tensor.coordinates %1 { level = 0 : index }
: tensor<?x?xf64, #SortedCOOPermuted> to memref<?xindex, strided<[?], offset: ?>>
%i11 = sparse_tensor.coordinates %1 { level = 1 : index }
: tensor<?x?xf64, #SortedCOOPermuted> to memref<?xindex, strided<[?], offset: ?>>
%v1 = sparse_tensor.values %1
: tensor<?x?xf64, #SortedCOOPermuted> to memref<?xf64>
call @dumpi(%p1) : (memref<?xindex>) -> ()
call @dumpsi(%i10) : (memref<?xindex, strided<[?], offset: ?>>) -> ()
call @dumpsi(%i11) : (memref<?xindex, strided<[?], offset: ?>>) -> ()
call @dumpf(%v1) : (memref<?xf64>) -> ()
sparse_tensor.print %1 : tensor<?x?xf64, #SortedCOOPermuted>

//
// CHECK-NEXT: ( 0, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
// CHECK-NEXT: ( 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 )
// CHECK-NEXT: ( 0, 0, 1, 1, 2, 2, 2, 2, 0, 0, 0, 1, 1, 1, 1, 2, 2, 0, 0, 0 )
// CHECK-NEXT: ( 0, 0, 1, 1, 2, 2, 2, 2, 0, 0, 0, 1, 1, 1, 1, 2, 2, 0, 0, 0 )
// CHECK-NEXT: ( 3, 63, 11, 100, 66, 61, 13, 43, 77, 10, 46, 61, 53, 3, 75, 22, 18, 0, 0, 0 )
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 17
// CHECK-NEXT: dim = ( 2, 3, 4 )
// CHECK-NEXT: lvl = ( 2, 3, 4 )
// CHECK-NEXT: pos[0] : ( 0, 17
// CHECK-NEXT: crd[0] : ( 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1
// CHECK-NEXT: crd[1] : ( 0, 0, 1, 1, 2, 2, 2, 2, 0, 0, 0, 1, 1, 1, 1, 2, 2
// CHECK-NEXT: crd[2] : ( 2, 3, 1, 2, 0, 1, 2, 3, 0, 2, 3, 0, 1, 2, 3, 1, 2
// CHECK-NEXT: values : ( 3, 63, 11, 100, 66, 61, 13, 43, 77, 10, 46, 61, 53, 3, 75, 22, 18
// CHECK-NEXT: ----
//
%p2 = sparse_tensor.positions %2 { level = 0 : index }
: tensor<?x?x?xf64, #SortedCOO3D> to memref<?xindex>
%i20 = sparse_tensor.coordinates %2 { level = 0 : index }
: tensor<?x?x?xf64, #SortedCOO3D> to memref<?xindex, strided<[?], offset: ?>>
%i21 = sparse_tensor.coordinates %2 { level = 1 : index }
: tensor<?x?x?xf64, #SortedCOO3D> to memref<?xindex, strided<[?], offset: ?>>
%i22 = sparse_tensor.coordinates %2 { level = 2 : index }
: tensor<?x?x?xf64, #SortedCOO3D> to memref<?xindex, strided<[?], offset: ?>>
%v2 = sparse_tensor.values %2
: tensor<?x?x?xf64, #SortedCOO3D> to memref<?xf64>
call @dumpi(%p2) : (memref<?xindex>) -> ()
call @dumpsi(%i20) : (memref<?xindex, strided<[?], offset: ?>>) -> ()
call @dumpsi(%i21) : (memref<?xindex, strided<[?], offset: ?>>) -> ()
call @dumpsi(%i21) : (memref<?xindex, strided<[?], offset: ?>>) -> ()
call @dumpf(%v2) : (memref<?xf64>) -> ()
sparse_tensor.print %2 : tensor<?x?x?xf64, #SortedCOO3D>

//
// CHECK-NEXT: ( 0, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
// CHECK-NEXT: ( 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 0, 0, 0 )
// CHECK-NEXT: ( 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0 )
// CHECK-NEXT: ( 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0 )
// CHECK-NEXT: ( 66, 77, 61, 11, 61, 53, 22, 3, 100, 13, 10, 3, 18, 63, 43, 46, 75, 0, 0, 0 )
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 17
// CHECK-NEXT: dim = ( 2, 3, 4 )
// CHECK-NEXT: lvl = ( 4, 2, 3 )
// CHECK-NEXT: pos[0] : ( 0, 17
// CHECK-NEXT: crd[0] : ( 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3
// CHECK-NEXT: crd[1] : ( 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1
// CHECK-NEXT: crd[2] : ( 2, 0, 1, 1, 2, 1, 2, 0, 1, 2, 0, 1, 2, 0, 2, 0, 1
// CHECK-NEXT: values : ( 66, 77, 61, 11, 61, 53, 22, 3, 100, 13, 10, 3, 18, 63, 43, 46, 75
// CHECK-NEXT: ----
//
%p3 = sparse_tensor.positions %3 { level = 0 : index }
: tensor<?x?x?xf64, #SortedCOO3DPermuted> to memref<?xindex>
%i30 = sparse_tensor.coordinates %3 { level = 0 : index }
: tensor<?x?x?xf64, #SortedCOO3DPermuted> to memref<?xindex, strided<[?], offset: ?>>
%i31 = sparse_tensor.coordinates %3 { level = 1 : index }
: tensor<?x?x?xf64, #SortedCOO3DPermuted> to memref<?xindex, strided<[?], offset: ?>>
%i32 = sparse_tensor.coordinates %3 { level = 2 : index }
: tensor<?x?x?xf64, #SortedCOO3DPermuted> to memref<?xindex, strided<[?], offset: ?>>
%v3 = sparse_tensor.values %3
: tensor<?x?x?xf64, #SortedCOO3DPermuted> to memref<?xf64>
call @dumpi(%p3) : (memref<?xindex>) -> ()
call @dumpsi(%i30) : (memref<?xindex, strided<[?], offset: ?>>) -> ()
call @dumpsi(%i31) : (memref<?xindex, strided<[?], offset: ?>>) -> ()
call @dumpsi(%i31) : (memref<?xindex, strided<[?], offset: ?>>) -> ()
call @dumpf(%v3) : (memref<?xf64>) -> ()
sparse_tensor.print %3 : tensor<?x?x?xf64, #SortedCOO3DPermuted>

//
// CHECK-NEXT: ( 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
// CHECK-NEXT: ( 0, 1, 2, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
// CHECK-NEXT: ( 0, 3, 0, 3, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
// CHECK-NEXT: ( 6, 5, 4, 3, 2, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 6
// CHECK-NEXT: dim = ( 5, 4 )
// CHECK-NEXT: lvl = ( 5, 4 )
// CHECK-NEXT: pos[0] : ( 0, 6
// CHECK-NEXT: crd[0] : ( 0, 1, 2, 2, 3, 4
// CHECK-NEXT: crd[1] : ( 0, 3, 0, 3, 1, 1
// CHECK-NEXT: values : ( 6, 5, 4, 3, 2, 11
// CHECK-NEXT: ----
//
%p4 = sparse_tensor.positions %4 { level = 0 : index }
: tensor<?x?xf64, #SortedCOO> to memref<?xindex>
%i40 = sparse_tensor.coordinates %4 { level = 0 : index }
: tensor<?x?xf64, #SortedCOO> to memref<?xindex, strided<[?], offset: ?>>
%i41 = sparse_tensor.coordinates %4 { level = 1 : index }
: tensor<?x?xf64, #SortedCOO> to memref<?xindex, strided<[?], offset: ?>>
%v4 = sparse_tensor.values %4
: tensor<?x?xf64, #SortedCOO> to memref<?xf64>
call @dumpi(%p4) : (memref<?xindex>) -> ()
call @dumpsi(%i40) : (memref<?xindex, strided<[?], offset: ?>>) -> ()
call @dumpsi(%i41) : (memref<?xindex, strided<[?], offset: ?>>) -> ()
call @dumpf(%v4) : (memref<?xf64>) -> ()
sparse_tensor.print %4 : tensor<?x?xf64, #SortedCOO>

// And last but not least, an actual operation applied to COO.
// Note that this performs the operation "in place".
%5 = call @sparse_scale(%4) : (tensor<?x?xf64, #SortedCOO>) -> tensor<?x?xf64, #SortedCOO>

//
// CHECK-NEXT: ( 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
// CHECK-NEXT: ( 0, 1, 2, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
// CHECK-NEXT: ( 0, 3, 0, 3, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
// CHECK-NEXT: ( 12, 10, 8, 6, 4, 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 6
// CHECK-NEXT: dim = ( 5, 4 )
// CHECK-NEXT: lvl = ( 5, 4 )
// CHECK-NEXT: pos[0] : ( 0, 6
// CHECK-NEXT: crd[0] : ( 0, 1, 2, 2, 3, 4
// CHECK-NEXT: crd[1] : ( 0, 3, 0, 3, 1, 1
// CHECK-NEXT: values : ( 12, 10, 8, 6, 4, 22
// CHECK-NEXT: ----
//
%p5 = sparse_tensor.positions %5 { level = 0 : index }
: tensor<?x?xf64, #SortedCOO> to memref<?xindex>
%i50 = sparse_tensor.coordinates %5 { level = 0 : index }
: tensor<?x?xf64, #SortedCOO> to memref<?xindex, strided<[?], offset: ?>>
%i51 = sparse_tensor.coordinates %5 { level = 1 : index }
: tensor<?x?xf64, #SortedCOO> to memref<?xindex, strided<[?], offset: ?>>
%v5 = sparse_tensor.values %5
: tensor<?x?xf64, #SortedCOO> to memref<?xf64>
call @dumpi(%p5) : (memref<?xindex>) -> ()
call @dumpsi(%i50) : (memref<?xindex, strided<[?], offset: ?>>) -> ()
call @dumpsi(%i51) : (memref<?xindex, strided<[?], offset: ?>>) -> ()
call @dumpf(%v5) : (memref<?xf64>) -> ()
sparse_tensor.print %5 : tensor<?x?xf64, #SortedCOO>

// Release the resources.
bufferization.dealloc_tensor %0 : tensor<?x?xf64, #SortedCOO>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -76,7 +76,7 @@ module {
//
// Main driver that reads matrix from file and calls the sparse kernel.
//
func.func @entry() {
func.func @main() {
%i0 = arith.constant 0.0 : f64
%c0 = arith.constant 0 : index
%c1 = arith.constant 1 : index
Expand Down
197 changes: 67 additions & 130 deletions mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_storage.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -72,7 +72,7 @@ module {
// are typically not concerned with such details, but the test ensures
// everything is working "under the hood".
//
func.func @entry() {
func.func @main() {
%c0 = arith.constant 0 : index
%c1 = arith.constant 1 : index
%d0 = arith.constant 0.0 : f64
Expand Down Expand Up @@ -107,166 +107,103 @@ module {
//
// Inspect storage scheme of Dense.
//
// CHECK: ( 1, 0, 2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0,
// CHECK-SAME: 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0,
// CHECK-SAME: 0, 0, 0, 0, 6, 0, 0, 0, 0, 7, 8, 0, 0, 0, 0, 9,
// CHECK-SAME: 0, 0, 10, 0, 0, 0, 11, 12, 0, 13, 14, 0, 0, 0, 15, 16,
// CHECK-SAME: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0 )
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 80
// CHECK-NEXT: dim = ( 10, 8 )
// CHECK-NEXT: lvl = ( 10, 8 )
// CHECK-NEXT: values : ( 1, 0, 2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 7, 8, 0, 0, 0, 0, 9, 0, 0, 10, 0, 0, 0, 11, 12, 0, 13, 14, 0, 0, 0, 15, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0
// CHECK-NEXT: ----
//
%5 = sparse_tensor.values %0 : tensor<10x8xf64, #Dense> to memref<?xf64>
%6 = vector.transfer_read %5[%c0], %d0: memref<?xf64>, vector<80xf64>
vector.print %6 : vector<80xf64>
sparse_tensor.print %0 : tensor<10x8xf64, #Dense>

//
// Inspect storage scheme of CSR.
//
// positions(1)
// indices(1)
// values
//
// CHECK: ( 0, 3, 3, 4, 5, 6, 9, 12, 16, 16, 17 )
// CHECK: ( 0, 2, 7, 2, 3, 4, 1, 2, 7, 2, 6, 7, 1, 2, 6, 7, 6 )
// CHECK: ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 )
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 17
// CHECK-NEXT: dim = ( 10, 8 )
// CHECK-NEXT: lvl = ( 10, 8 )
// CHECK-NEXT: pos[1] : ( 0, 3, 3, 4, 5, 6, 9, 12, 16, 16, 17
// CHECK-NEXT: crd[1] : ( 0, 2, 7, 2, 3, 4, 1, 2, 7, 2, 6, 7, 1, 2, 6, 7, 6
// CHECK-NEXT: values : ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17
// CHECK-NEXT: ----
//
%7 = sparse_tensor.positions %1 { level = 1 : index } : tensor<10x8xf64, #CSR> to memref<?xindex>
%8 = vector.transfer_read %7[%c0], %c0: memref<?xindex>, vector<11xindex>
vector.print %8 : vector<11xindex>
%9 = sparse_tensor.coordinates %1 { level = 1 : index } : tensor<10x8xf64, #CSR> to memref<?xindex>
%10 = vector.transfer_read %9[%c0], %c0: memref<?xindex>, vector<17xindex>
vector.print %10 : vector<17xindex>
%11 = sparse_tensor.values %1 : tensor<10x8xf64, #CSR> to memref<?xf64>
%12 = vector.transfer_read %11[%c0], %d0: memref<?xf64>, vector<17xf64>
vector.print %12 : vector<17xf64>
sparse_tensor.print %1 : tensor<10x8xf64, #CSR>

//
// Inspect storage scheme of DCSR.
//
// positions(0)
// indices(0)
// positions(1)
// indices(1)
// values
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 17
// CHECK-NEXT: dim = ( 10, 8 )
// CHECK-NEXT: lvl = ( 10, 8 )
// CHECK-NEXT: pos[0] : ( 0, 8
// CHECK-NEXT: crd[0] : ( 0, 2, 3, 4, 5, 6, 7, 9
// CHECK-NEXT: pos[1] : ( 0, 3, 4, 5, 6, 9, 12, 16, 17
// CHECK-NEXT: crd[1] : ( 0, 2, 7, 2, 3, 4, 1, 2, 7, 2, 6, 7, 1, 2, 6, 7, 6
// CHECK-NEXT: values : ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17
// CHECK-NEXT: ----
//
// CHECK: ( 0, 8 )
// CHECK: ( 0, 2, 3, 4, 5, 6, 7, 9 )
// CHECK: ( 0, 3, 4, 5, 6, 9, 12, 16, 17 )
// CHECK: ( 0, 2, 7, 2, 3, 4, 1, 2, 7, 2, 6, 7, 1, 2, 6, 7, 6 )
// CHECK: ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 )
//
%13 = sparse_tensor.positions %2 { level = 0 : index } : tensor<10x8xf64, #DCSR> to memref<?xindex>
%14 = vector.transfer_read %13[%c0], %c0: memref<?xindex>, vector<2xindex>
vector.print %14 : vector<2xindex>
%15 = sparse_tensor.coordinates %2 { level = 0 : index } : tensor<10x8xf64, #DCSR> to memref<?xindex>
%16 = vector.transfer_read %15[%c0], %c0: memref<?xindex>, vector<8xindex>
vector.print %16 : vector<8xindex>
%17 = sparse_tensor.positions %2 { level = 1 : index } : tensor<10x8xf64, #DCSR> to memref<?xindex>
%18 = vector.transfer_read %17[%c0], %c0: memref<?xindex>, vector<9xindex>
vector.print %18 : vector<9xindex>
%19 = sparse_tensor.coordinates %2 { level = 1 : index } : tensor<10x8xf64, #DCSR> to memref<?xindex>
%20 = vector.transfer_read %19[%c0], %c0: memref<?xindex>, vector<17xindex>
vector.print %20 : vector<17xindex>
%21 = sparse_tensor.values %2 : tensor<10x8xf64, #DCSR> to memref<?xf64>
%22 = vector.transfer_read %21[%c0], %d0: memref<?xf64>, vector<17xf64>
vector.print %22 : vector<17xf64>
sparse_tensor.print %2 : tensor<10x8xf64, #DCSR>

//
// Inspect storage scheme of CSC.
//
// positions(1)
// indices(1)
// values
//
// CHECK: ( 0, 1, 3, 8, 9, 10, 10, 13, 17 )
// CHECK: ( 0, 5, 7, 0, 2, 5, 6, 7, 3, 4, 6, 7, 9, 0, 5, 6, 7 )
// CHECK: ( 1, 7, 13, 2, 4, 8, 10, 14, 5, 6, 11, 15, 17, 3, 9, 12, 16 )
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 17
// CHECK-NEXT: dim = ( 10, 8 )
// CHECK-NEXT: lvl = ( 8, 10 )
// CHECK-NEXT: pos[1] : ( 0, 1, 3, 8, 9, 10, 10, 13, 17
// CHECK-NEXT: crd[1] : ( 0, 5, 7, 0, 2, 5, 6, 7, 3, 4, 6, 7, 9, 0, 5, 6, 7
// CHECK-NEXT: values : ( 1, 7, 13, 2, 4, 8, 10, 14, 5, 6, 11, 15, 17, 3, 9, 12, 16
// CHECK-NEXT: ----
//
%23 = sparse_tensor.positions %3 { level = 1 : index } : tensor<10x8xf64, #CSC> to memref<?xindex>
%24 = vector.transfer_read %23[%c0], %c0: memref<?xindex>, vector<9xindex>
vector.print %24 : vector<9xindex>
%25 = sparse_tensor.coordinates %3 { level = 1 : index } : tensor<10x8xf64, #CSC> to memref<?xindex>
%26 = vector.transfer_read %25[%c0], %c0: memref<?xindex>, vector<17xindex>
vector.print %26 : vector<17xindex>
%27 = sparse_tensor.values %3 : tensor<10x8xf64, #CSC> to memref<?xf64>
%28 = vector.transfer_read %27[%c0], %d0: memref<?xf64>, vector<17xf64>
vector.print %28 : vector<17xf64>
sparse_tensor.print %3 : tensor<10x8xf64, #CSC>

//
// Inspect storage scheme of DCSC.
//
// positions(0)
// indices(0)
// positions(1)
// indices(1)
// values
//
// CHECK: ( 0, 7 )
// CHECK: ( 0, 1, 2, 3, 4, 6, 7 )
// CHECK: ( 0, 1, 3, 8, 9, 10, 13, 17 )
// CHECK: ( 0, 5, 7, 0, 2, 5, 6, 7, 3, 4, 6, 7, 9, 0, 5, 6, 7 )
// CHECK: ( 1, 7, 13, 2, 4, 8, 10, 14, 5, 6, 11, 15, 17, 3, 9, 12, 16 )
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 17
// CHECK-NEXT: dim = ( 10, 8 )
// CHECK-NEXT: lvl = ( 8, 10 )
// CHECK-NEXT: pos[0] : ( 0, 7
// CHECK-NEXT: crd[0] : ( 0, 1, 2, 3, 4, 6, 7
// CHECK-NEXT: pos[1] : ( 0, 1, 3, 8, 9, 10, 13, 17
// CHECK-NEXT: crd[1] : ( 0, 5, 7, 0, 2, 5, 6, 7, 3, 4, 6, 7, 9, 0, 5, 6, 7
// CHECK-NEXT: values : ( 1, 7, 13, 2, 4, 8, 10, 14, 5, 6, 11, 15, 17, 3, 9, 12, 16
// CHECK-NEXT: ----
//
%29 = sparse_tensor.positions %4 { level = 0 : index } : tensor<10x8xf64, #DCSC> to memref<?xindex>
%30 = vector.transfer_read %29[%c0], %c0: memref<?xindex>, vector<2xindex>
vector.print %30 : vector<2xindex>
%31 = sparse_tensor.coordinates %4 { level = 0 : index } : tensor<10x8xf64, #DCSC> to memref<?xindex>
%32 = vector.transfer_read %31[%c0], %c0: memref<?xindex>, vector<7xindex>
vector.print %32 : vector<7xindex>
%33 = sparse_tensor.positions %4 { level = 1 : index } : tensor<10x8xf64, #DCSC> to memref<?xindex>
%34 = vector.transfer_read %33[%c0], %c0: memref<?xindex>, vector<8xindex>
vector.print %34 : vector<8xindex>
%35 = sparse_tensor.coordinates %4 { level = 1 : index } : tensor<10x8xf64, #DCSC> to memref<?xindex>
%36 = vector.transfer_read %35[%c0], %c0: memref<?xindex>, vector<17xindex>
vector.print %36 : vector<17xindex>
%37 = sparse_tensor.values %4 : tensor<10x8xf64, #DCSC> to memref<?xf64>
%38 = vector.transfer_read %37[%c0], %d0: memref<?xf64>, vector<17xf64>
vector.print %38 : vector<17xf64>
sparse_tensor.print %4 : tensor<10x8xf64, #DCSC>

//
// Inspect storage scheme of BlockRow.
//
// positions(0)
// indices(0)
// values
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 64
// CHECK-NEXT: dim = ( 10, 8 )
// CHECK-NEXT: lvl = ( 10, 8 )
// CHECK-NEXT: pos[0] : ( 0, 8
// CHECK-NEXT: crd[0] : ( 0, 2, 3, 4, 5, 6, 7, 9
// CHECK-NEXT: values : ( 1, 0, 2, 0, 0, 0, 0, 3, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 7, 8, 0, 0, 0, 0, 9, 0, 0, 10, 0, 0, 0, 11, 12, 0, 13, 14, 0, 0, 0, 15, 16, 0, 0, 0, 0, 0, 0, 17, 0
// CHECK-NEXT: ----
//
// CHECK: ( 0, 8 )
// CHECK: ( 0, 2, 3, 4, 5, 6, 7, 9 )
// CHECK: ( 1, 0, 2, 0, 0, 0, 0, 3, 0, 0, 4, 0, 0, 0, 0, 0,
// CHECK-SAME: 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0,
// CHECK-SAME: 0, 7, 8, 0, 0, 0, 0, 9, 0, 0, 10, 0, 0, 0, 11, 12,
// CHECK-SAME: 0, 13, 14, 0, 0, 0, 15, 16, 0, 0, 0, 0, 0, 0, 17, 0 )
//
%39 = sparse_tensor.positions %x { level = 0 : index } : tensor<10x8xf64, #BlockRow> to memref<?xindex>
%40 = vector.transfer_read %39[%c0], %c0: memref<?xindex>, vector<2xindex>
vector.print %40 : vector<2xindex>
%41 = sparse_tensor.coordinates %x { level = 0 : index } : tensor<10x8xf64, #BlockRow> to memref<?xindex>
%42 = vector.transfer_read %41[%c0], %c0: memref<?xindex>, vector<8xindex>
vector.print %42 : vector<8xindex>
%43 = sparse_tensor.values %x : tensor<10x8xf64, #BlockRow> to memref<?xf64>
%44 = vector.transfer_read %43[%c0], %d0: memref<?xf64>, vector<64xf64>
vector.print %44 : vector<64xf64>
sparse_tensor.print %x : tensor<10x8xf64, #BlockRow>

//
// Inspect storage scheme of BlockCol.
//
// positions(0)
// indices(0)
// values
//
// CHECK: ( 0, 7 )
// CHECK: ( 0, 1, 2, 3, 4, 6, 7 )
// CHECK: ( 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 13, 0, 0, 2, 0, 4, 0,
// CHECK-SAME: 0, 8, 10, 14, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0,
// CHECK-SAME: 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 15, 0, 17, 3, 0, 0, 0, 0, 9, 12, 16, 0, 0 )
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 70
// CHECK-NEXT: dim = ( 10, 8 )
// CHECK-NEXT: lvl = ( 8, 10 )
// CHECK-NEXT: pos[0] : ( 0, 7
// CHECK-NEXT: crd[0] : ( 0, 1, 2, 3, 4, 6, 7
// CHECK-NEXT: values : ( 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 13, 0, 0, 2, 0, 4, 0, 0, 8, 10, 14, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 15, 0, 17, 3, 0, 0, 0, 0, 9, 12, 16, 0, 0
// CHECK-NEXT: ----
//
%45 = sparse_tensor.positions %y { level = 0 : index } : tensor<10x8xf64, #BlockCol> to memref<?xindex>
%46 = vector.transfer_read %45[%c0], %c0: memref<?xindex>, vector<2xindex>
vector.print %46 : vector<2xindex>
%47 = sparse_tensor.coordinates %y { level = 0 : index } : tensor<10x8xf64, #BlockCol> to memref<?xindex>
%48 = vector.transfer_read %47[%c0], %c0: memref<?xindex>, vector<7xindex>
vector.print %48 : vector<7xindex>
%49 = sparse_tensor.values %y : tensor<10x8xf64, #BlockCol> to memref<?xf64>
%50 = vector.transfer_read %49[%c0], %d0: memref<?xf64>, vector<70xf64>
vector.print %50 : vector<70xf64>
sparse_tensor.print %y : tensor<10x8xf64, #BlockCol>

// Release the resources.
bufferization.dealloc_tensor %0 : tensor<10x8xf64, #Dense>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -78,7 +78,7 @@ func.func @conv_2d_nhwc_hwcf_dual_CDCC(%arg0: tensor<?x?x?x?xf32, #CDCC>, %arg1:
}


func.func @entry() {
func.func @main() {
%c0 = arith.constant 0 : index
%c1 = arith.constant 1 : index
%c3 = arith.constant 3 : index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -75,7 +75,7 @@ module {
//
// Main driver that reads matrix from file and calls the sparse kernel.
//
func.func @entry() {
func.func @main() {
%d0 = arith.constant 0.0 : f64
%c0 = arith.constant 0 : index

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -67,7 +67,7 @@ module {
//
// Main driver that reads matrix from file and calls the sparse kernel.
//
func.func @entry() {
func.func @main() {
// Setup input sparse matrix from compressed constant.
%d = arith.constant dense <[
[ 1.1, 1.2, 0.0, 1.4 ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -75,7 +75,7 @@ module {
//
// Main driver that reads matrix from file and calls the sparse kernel.
//
func.func @entry() {
func.func @main() {
//%d0 = arith.constant 0.0 : complex<f64>
%d0 = complex.constant [0.0 : f64, 0.0 : f64] : complex<f64>
%c0 = arith.constant 0 : index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -66,7 +66,7 @@ module {
//
// Main driver that reads matrix from file and calls the sparse kernel.
//
func.func @entry() {
func.func @main() {
// Setup input sparse matrix from compressed constant.
%d = arith.constant dense <[
[ 1.1, 1.2, 0.0, 1.4 ],
Expand Down
37 changes: 11 additions & 26 deletions mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_tanh.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -56,28 +56,8 @@ module {
return %0 : tensor<?xf64, #SparseVector>
}

// Dumps a sparse vector of type f64.
func.func @dump_vec_f64(%arg0: tensor<?xf64, #SparseVector>) {
// Dump the values array to verify only sparse contents are stored.
%c0 = arith.constant 0 : index
%d0 = arith.constant -1.0 : f64
%n = sparse_tensor.number_of_entries %arg0: tensor<?xf64, #SparseVector>
vector.print %n : index
%0 = sparse_tensor.values %arg0
: tensor<?xf64, #SparseVector> to memref<?xf64>
%1 = vector.transfer_read %0[%c0], %d0: memref<?xf64>, vector<9xf64>
vector.print %1 : vector<9xf64>
// Dump the dense vector to verify structure is correct.
%dv = sparse_tensor.convert %arg0
: tensor<?xf64, #SparseVector> to tensor<?xf64>
%3 = vector.transfer_read %dv[%c0], %d0: tensor<?xf64>, vector<32xf64>
vector.print %3 : vector<32xf64>
bufferization.dealloc_tensor %dv : tensor<?xf64>
return
}

// Driver method to call and verify vector kernels.
func.func @entry() {
func.func @main() {
// Setup sparse vector.
%v1 = arith.constant sparse<
[ [0], [3], [11], [17], [20], [21], [28], [29], [31] ],
Expand All @@ -93,11 +73,16 @@ module {
//
// Verify the results (within some precision).
//
// CHECK: 9
// CHECK-NEXT: {{( -0.761[0-9]*, 0.761[0-9]*, 0.96[0-9]*, 0.99[0-9]*, 0.99[0-9]*, 0.99[0-9]*, 0.99[0-9]*, 0.99[0-9]*, 1 )}}
// CHECK-NEXT: {{( -0.761[0-9]*, 0, 0, 0.761[0-9]*, 0, 0, 0, 0, 0, 0, 0, 0.96[0-9]*, 0, 0, 0, 0, 0, 0.99[0-9]*, 0, 0, 0.99[0-9]*, 0.99[0-9]*, 0, 0, 0, 0, 0, 0, 0.99[0-9]*, 0.99[0-9]*, 0, 1 )}}
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 9
// CHECK-NEXT: dim = ( 32 )
// CHECK-NEXT: lvl = ( 32 )
// CHECK-NEXT: pos[0] : ( 0, 9
// CHECK-NEXT: crd[0] : ( 0, 3, 11, 17, 20, 21, 28, 29, 31
// CHECK-NEXT: values : ({{ -0.761[0-9]*, 0.761[0-9]*, 0.96[0-9]*, 0.99[0-9]*, 0.99[0-9]*, 0.99[0-9]*, 0.99[0-9]*, 0.99[0-9]*, 1}}
// CHECK-NEXT: ----
//
call @dump_vec_f64(%0) : (tensor<?xf64, #SparseVector>) -> ()
sparse_tensor.print %0 : tensor<?xf64, #SparseVector>

// Release the resources.
bufferization.dealloc_tensor %sv1 : tensor<?xf64, #SparseVector>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -67,7 +67,7 @@ module {
}

// Driver method to call and verify tensor multiplication kernel.
func.func @entry() {
func.func @main() {
%c0 = arith.constant 0 : index
%default_val = arith.constant -1.0 : f64

Expand Down Expand Up @@ -103,30 +103,28 @@ module {
%0 = call @tensor_mul(%sta, %stb)
: (tensor<?x?x?xf64, #ST>, tensor<?x?x?xf64, #ST>) -> tensor<?x?x?xf64, #ST>

// Verify results
//
// CHECK: 4
// CHECK-NEXT: ( 2.4, 3.5, 2, 8 )
// CHECK-NEXT: ( ( ( 0, 0, 0, 0, 0 ), ( 0, 0, 0, 0, 0 ), ( 2.4, 0, 3.5, 0, 0 ) ),
// CHECK-SAME: ( ( 0, 0, 0, 0, 0 ), ( 0, 0, 0, 0, 0 ), ( 0, 0, 0, 0, 0 ) ),
// CHECK-SAME: ( ( 2, 0, 0, 0, 0 ), ( 0, 0, 0, 0, 0 ), ( 0, 0, 8, 0, 0 ) ) )
// Verify results.
//
%n = sparse_tensor.number_of_entries %0 : tensor<?x?x?xf64, #ST>
vector.print %n : index
%m1 = sparse_tensor.values %0 : tensor<?x?x?xf64, #ST> to memref<?xf64>
%v1 = vector.transfer_read %m1[%c0], %default_val: memref<?xf64>, vector<4xf64>
vector.print %v1 : vector<4xf64>

// Print %0 in dense form.
%dt = sparse_tensor.convert %0 : tensor<?x?x?xf64, #ST> to tensor<?x?x?xf64>
%v2 = vector.transfer_read %dt[%c0, %c0, %c0], %default_val: tensor<?x?x?xf64>, vector<3x3x5xf64>
vector.print %v2 : vector<3x3x5xf64>
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 4
// CHECK-NEXT: dim = ( 3, 3, 5 )
// CHECK-NEXT: lvl = ( 3, 3, 5 )
// CHECK-NEXT: pos[0] : ( 0, 2
// CHECK-NEXT: crd[0] : ( 0, 2
// CHECK-NEXT: pos[1] : ( 0, 1, 3
// CHECK-NEXT: crd[1] : ( 2, 0, 2
// CHECK-NEXT: pos[2] : ( 0, 2, 3, 4
// CHECK-NEXT: crd[2] : ( 0, 2, 0, 2
// CHECK-NEXT: values : ( 2.4, 3.5, 2, 8
// CHECK-NEXT: ----
//
sparse_tensor.print %0 : tensor<?x?x?xf64, #ST>

// Release the resources.
bufferization.dealloc_tensor %sta : tensor<?x?x?xf64, #ST>
bufferization.dealloc_tensor %stb : tensor<?x?x?xf64, #ST>
bufferization.dealloc_tensor %0 : tensor<?x?x?xf64, #ST>
bufferization.dealloc_tensor %dt : tensor<?x?x?xf64>

return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
// DEFINE: %{run_opts} = -e main -entry-point-result=void
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
//
Expand Down Expand Up @@ -67,7 +67,7 @@ module {
}

// Driver method to call and verify tensor kernel.
func.func @entry() {
func.func @main() {
%c0 = arith.constant 0 : index
%d1 = arith.constant -1.0 : f64

Expand All @@ -90,22 +90,34 @@ module {
// Call sparse vector kernels.
%0 = call @tensor_scale(%st) : (tensor<?x?x?xf64, #ST1>) -> tensor<?x?x?xf64, #ST2>

//
// Sanity check on stored values.
//
// CHECK: 5
// CHECK-NEXT: ( 1, 2, 3, 4, 5 )
// CHECK-NEXT: 24
// CHECK-NEXT: ( 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 6, 8, 0, 0, 0, 0, 10 )
%m1 = sparse_tensor.values %st : tensor<?x?x?xf64, #ST1> to memref<?xf64>
%m2 = sparse_tensor.values %0 : tensor<?x?x?xf64, #ST2> to memref<?xf64>
%n1 = sparse_tensor.number_of_entries %st : tensor<?x?x?xf64, #ST1>
%n2 = sparse_tensor.number_of_entries %0 : tensor<?x?x?xf64, #ST2>
%v1 = vector.transfer_read %m1[%c0], %d1: memref<?xf64>, vector<5xf64>
%v2 = vector.transfer_read %m2[%c0], %d1: memref<?xf64>, vector<24xf64>
vector.print %n1 : index
vector.print %v1 : vector<5xf64>
vector.print %n2 : index
vector.print %v2 : vector<24xf64>
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 5
// CHECK-NEXT: dim = ( 3, 4, 8 )
// CHECK-NEXT: lvl = ( 3, 4, 8 )
// CHECK-NEXT: pos[0] : ( 0, 2
// CHECK-NEXT: crd[0] : ( 0, 2
// CHECK-NEXT: pos[1] : ( 0, 2, 3
// CHECK-NEXT: crd[1] : ( 0, 3, 2
// CHECK-NEXT: pos[2] : ( 0, 1, 2, 5
// CHECK-NEXT: crd[2] : ( 0, 7, 1, 2, 7
// CHECK-NEXT: values : ( 1, 2, 3, 4, 5
// CHECK-NEXT: ----
// CHECK: ---- Sparse Tensor ----
// CHECK-NEXT: nse = 24
// CHECK-NEXT: dim = ( 3, 4, 8 )
// CHECK-NEXT: lvl = ( 3, 4, 8 )
// CHECK-NEXT: pos[0] : ( 0, 2
// CHECK-NEXT: crd[0] : ( 0, 2
// CHECK-NEXT: pos[1] : ( 0, 2, 3
// CHECK-NEXT: crd[1] : ( 0, 3, 2
// CHECK-NEXT: values : ( 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 6, 8, 0, 0, 0, 0, 10
// CHECK-NEXT: ----
//
sparse_tensor.print %st : tensor<?x?x?xf64, #ST1>
sparse_tensor.print %0 : tensor<?x?x?xf64, #ST2>

// Release the resources.
bufferization.dealloc_tensor %st : tensor<?x?x?xf64, #ST1>
Expand Down
Loading