# CSR matrices in CUDA.jl

**URL:** <https://discourse.julialang.org/t/csr-matrices-in-cuda-jl/87388>\
**Category:** GPU\
**Created:** [September 16, 2022, 8:34pm UTC](https://discourse.julialang.org/t/csr-matrices-in-cuda-jl/87388 "2022-09-16T20:34:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamblejoe](https://avatars.discourse-cdn.com/v4/letter/j/ee7513/32.png) [@jamblejoe](https://discourse.julialang.org/u/jamblejoe)\
**Post date:** [September 16, 2022, 8:34pm UTC](https://discourse.julialang.org/t/csr-matrices-in-cuda-jl/87388/1 "2022-09-16T20:34:02Z")

</div>

I can create CSC matrices on the GPU, e.g. via `cu(sprand(10,10,0.1))`. How do I create CSR matrices? How do I convert a CSC into a CSR matrix on the CPU or GPU?

I want to use `csreigvsi`, which requires CSR storage structure.

---

<div class="post-metadata">

**Author:** ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)\
**Post date:** [September 17, 2022, 7:56pm UTC](https://discourse.julialang.org/t/csr-matrices-in-cuda-jl/87388/2 "2022-09-17T19:56:33Z")

</div>

Call the `CuSparseMatrixCSR` constructor. Have a look at the CUDA.jl test suite (`test/cusparse.jl` and `test/cusparse/*`), there’s plenty of examples there.

---

<div class="post-metadata">

**Author:** ![jamblejoe](https://avatars.discourse-cdn.com/v4/letter/j/ee7513/32.png) [@jamblejoe](https://discourse.julialang.org/u/jamblejoe)\
**Post date:** [September 21, 2022, 8:41pm UTC](https://discourse.julialang.org/t/csr-matrices-in-cuda-jl/87388/3 "2022-09-21T20:41:41Z")

</div>

A CSR matrix can be constructed from a sparse matrix `A` via `CUSPARSE.CuSparseMatrixCSR(A)`. The element type of `A` will be conserved. The element type of the CSR matrix on the GPU can be directly specified via e.g. `CUSPARSE.CuSparseMatrixCSR{Float32}(A)`.
