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

Add a CuSparseMatrixCOO type #220

Closed
irhum opened this issue Jun 12, 2020 · 4 comments · Fixed by #421
Closed

Add a CuSparseMatrixCOO type #220

irhum opened this issue Jun 12, 2020 · 4 comments · Fixed by #421
Assignees
Labels
cuda array Stuff about CuArray. enhancement New feature or request

Comments

@irhum
Copy link
Contributor

irhum commented Jun 12, 2020

It appears that the generic cusparseSpMM method offered by the C++ CUSPARSE API also allows the usage of a COO matrix (https://docs.nvidia.com/cuda/cusparse/index.html#cusparse-generic-function-spmm) and as of today, CUDA.jl doesn't seem to have a wrapper COO type that would allow higher level access in Julia to the API (kind of like how, since CuSparseMatrixCSR is defined to have a mul! method)

How would one go around defining a new CuSparseMatrixCOO type to implement similar functionality as well?

@irhum
Copy link
Contributor Author

irhum commented Jun 12, 2020

On a related note, I tried initializing a COO matrix in the format required by the generic function API (https://docs.nvidia.com/cuda/cusparse/index.html#cusparse-generic-spmat-create-coo), but this ended up segfaulting Julia. Any ideas on what might be going wrong here?

using CuArrays
CuArrays.allowscalar(false)

nnz = 30000
num_rows = 10000
num_cols = num_rows

rows = rand(1:num_rows, nnz)
cols = rand(1:num_cols, nnz)
nnzvals = zeros(Float32, nnz)

M = CUSPARSE.cusparseCreateCoo(CUSPARSE.cusparseSpMatDescr_t(),
                                num_rows,
                                num_cols,
                                nnz,
                                cu(rows),
                                cu(cols),
                                cu(nnzvals),
                                CUSPARSE.CUSPARSE_INDEX_64I,
                                CUSPARSE.cusparseindex('O'),
                                cudaDataType(Float32))

@marius311
Copy link
Contributor

FWIW I also tried once to create a COO matrix like this and similarly was getting segfaults. I don't recall if its exactly what you did above, but I confirm that when I run your code above with CuArrays 2.2.0 / CUDA version 10.1 I get a segfault.

Would be great to have a solution to this, since COO is often logically the easiest to construct, and for now I'm having to do that on CPU, convert to CSC, then convert to CuSparseMatrixCSC, which is leaving alot of performance on the table.

@maleadt maleadt added cuda array Stuff about CuArray. enhancement New feature or request labels Jun 17, 2020
@kshyatt kshyatt self-assigned this Jul 10, 2020
@kshyatt
Copy link
Contributor

kshyatt commented Jul 10, 2020

Hello @marius311 and @irhum, I can try to take a crack at this.

@marius311
Copy link
Contributor

marius311 commented Aug 7, 2020

Fyi I have a CuSparseMatrixCOO type working on https://github.com/marius311/CUDA.jl/tree/coo. Currently just the constructor and switch2csr implemented, but it'd be pretty trivial to do cusparseSpMM as well based on cusparseSpMV which is in there. I'm going to wait to see how #351 fleshes out (on which this branch depends), but then could contribute a PR as well, or help with whatever anyone else here may have made progress on too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cuda array Stuff about CuArray. enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants