Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discussion: Finch-mlir API #3

Open
mtsokol opened this issue Sep 11, 2024 · 2 comments
Open

Discussion: Finch-mlir API #3

mtsokol opened this issue Sep 11, 2024 · 2 comments

Comments

@mtsokol
Copy link
Member

mtsokol commented Sep 11, 2024

Hi @nullplay,

I wanted to start a discussion on Finch-MLIR <-> MLIR tensors API. In https://github.com/pydata/sparse/tree/main/sparse/mlir_backend we have an initial Tensor class which provides constructors for MLIR sparse/dense tensors:

tensor< dim0 x dim1 x ... x data_type[, sparse_format]>

Here are examples of MLIR tensors that can be created and will be passed to the API exposed by Finch-mlir:

// Dense
tensor<3x4xf64>
tensor<10xi64>
tensor<1x5x10xi32>

// CSR
#CSR = #sparse_tensor.encoding<{
    map = (i, j) -> (i : dense, j : compressed), posWidth = 64, crdWidth = 64
}>
tensor<4x4xf64, #CSR>
tensor<10x8xi64, #CSR>

// CSC
#CSC = #sparse_tensor.encoding<{
    map = (i, j) -> (j : dense, i : compressed), posWidth = 64, crdWidth = 64
}>
tensor<4x4xf32, #CSC>

// COO
#COO = #sparse_tensor.encoding<{
    map = (i, j) -> (i : compressed(nonunique), j : singleton), posWidth = 64, crdWidth = 64
}>
tensor<4x4xi64, #COO>
tensor<10x100x50xf32, #COO>

// CSF
#CSF = #sparse_tensor.encoding<{
    map = (i, j, k) -> (i : dense, j : compressed, k : compressed), posWidth = 64, crdWidth = 64
}>
tensor<4x4x10xf64, #CSF>

One of the first questions is: What would be the API to call some basic operations, let's say unary and binary elemwise operations, matmul (tensordot?) and reductions? Like:

func.func @add(%arg0: tensor<...>, %arg1: tensor<...>) -> tensor<...>
func.func @sub(%arg0: tensor<...>, %arg1: tensor<...>) -> tensor<...>
...
func.func @sum(%arg: tensor<...>, %axis: array<index>) -> tensor<...>
@hameerabbasi
Copy link
Collaborator

I would say all of this needs to be in one function, because optimising across function boundaries is difficult.

@mtsokol
Copy link
Member Author

mtsokol commented Oct 2, 2024

@nullplay so maybe let's first establish the MLIR code that would perform addition, substitution, reductions etc. using looplets, given that the input is a:

tensor< dim0 x dim1 x ... x data_type[, sparse_format]>

Where access to underlying memrefs is:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants