Hi!
I have a module that performs sparse tensor element-wise addition. It works for (CSR, Dense2D) -> CSR
, (CSR, CSR) -> CSR
, and a few others combinations (LLVM version 19.1.0-rc3
).
I can’t figure out Python binding calls for (Dense2D, Dense2D) -> Dense2D
as I keep getting Segmentation fault (core dumped)
.
My MLIR module is using sparse-assembler{direct-out=true}
:
#Dense = #sparse_tensor.encoding<{
map = (i, j) -> (i : dense, j : dense), posWidth = 64, crdWidth = 64
}>
#map = affine_map<(d0, d1) -> (d0, d1)>
func.func @add(%st_0 : tensor<3x4xf64, #Dense>, %st_1 : tensor<3x4xf64, #Dense>) -> tensor<3x4xf64> attributes { llvm.emit_c_interface } {
%out_st = tensor.empty() : tensor<3x4xf64>
%res = linalg.generic {indexing_maps = [#map, #map, #map], iterator_types = ["parallel", "parallel"]} ins(%st_0, %st_1 : tensor<3x4xf64, #Dense>, tensor<3x4xf64, #Dense>) outs(%out_st : tensor<3x4xf64>) {
^bb0(%in_0: f64, %in_1: f64, %out: f64):
%2 = sparse_tensor.binary %in_0, %in_1 : f64, f64 to f64
overlap = {
^bb0(%arg1: f64, %arg2: f64):
%3 = arith.addf %arg1, %arg2 : f64
sparse_tensor.yield %3 : f64
}
left = {
^bb0(%arg1: f64):
sparse_tensor.yield %arg1 : f64
}
right = {
^bb0(%arg1: f64):
sparse_tensor.yield %arg1 : f64
}
linalg.yield %2 : f64
} -> tensor<3x4xf64, #Dense>
return %res : tensor<3x4xf64, #Dense>
}
And I’m trying to call it with:
import mlir.runtime as rt
import ctypes
class Dense2D(ctypes.Structure):
_fields_ = [
("data", rt.make_nd_memref_descriptor(1, ctypes.c_double)),
]
result = Dense2D()
module_add.invoke(
"add",
ctypes.pointer(ctypes.pointer(result)),
ctypes.pointer(ctypes.pointer(input_1.data)),
ctypes.pointer(ctypes.pointer(input_2.data)),
)
I think the structure of inputs might be incorrect. I figured out how to call modules with CSR, COO inputs, but here with only Dense variants I’m missing something. For [dense,dense]
Tensor is it only data
array? Or is there additional pos
/indices
here?
Thank you for any help!