-
Notifications
You must be signed in to change notification settings - Fork 262
SparseMatricesCSR Dispatch #2720
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f0ea60b
init csr dispatch
Abdelrahman912 27f6a6c
csr dispatch
Abdelrahman912 0d94447
fix runic
Abdelrahman912 6c44661
conversion from CSR to CuCSC + fix cu
Abdelrahman912 f9386f4
minor fix
Abdelrahman912 627c794
add more conversions + mirror sparse conversion tests
Abdelrahman912 a75c768
add CSRExt to test env
Abdelrahman912 d32a6b6
Merge branch 'master' into csr-dispatch
Abdelrahman912 30a4f3f
move tests to `libraries/cusparse`
Abdelrahman912 0e80594
Merge branch 'master' into csr-dispatch
Abdelrahman912 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| module SparseMatricesCSRExt | ||
|
|
||
| using CUDA | ||
| import CUDA.CUSPARSE: | ||
| CuSparseMatrixCSR, CuSparseMatrixCSC, CuSparseMatrixCOO, CuSparseMatrixBSR, | ||
| SparseMatrixCSC | ||
| using SparseMatricesCSR | ||
| import SparseMatricesCSR: SparseMatrixCSR | ||
| import Adapt | ||
|
|
||
| # CPU → GPU | ||
| CUSPARSE.CuSparseMatrixCSR{T}(Mat::SparseMatrixCSR) where {T} = | ||
| CUSPARSE.CuSparseMatrixCSR{T}( | ||
| CuVector{Cint}(Mat.rowptr), CuVector{Cint}(Mat.colval), | ||
| CuVector{T}(Mat.nzval), size(Mat) | ||
| ) | ||
| CUSPARSE.CuSparseMatrixCSC{T}(Mat::SparseMatrixCSR) where {T} = CuSparseMatrixCSC(CuSparseMatrixCSR{T}(Mat)) | ||
| CUSPARSE.CuSparseMatrixCOO{T}(Mat::SparseMatrixCSR) where {T} = CuSparseMatrixCOO(CuSparseMatrixCSR{T}(Mat)) | ||
| CUSPARSE.CuSparseMatrixBSR{T}(Mat::SparseMatrixCSR, blockdim) where {T} = CuSparseMatrixBSR(CuSparseMatrixCSR{T}(Mat), blockdim) | ||
|
|
||
| # GPU → CPU | ||
| SparseMatricesCSR.SparseMatrixCSR(A::CUSPARSE.CuSparseMatrixCSR) = SparseMatrixCSR{1}(size(A)..., Array(A.rowPtr), Array(A.colVal), Array(A.nzVal)) | ||
| SparseMatricesCSR.SparseMatrixCSR(A::CUSPARSE.CuSparseMatrixCOO) = SparseMatrixCSR(CuSparseMatrixCSR(A)) | ||
| SparseMatricesCSR.SparseMatrixCSR(A::CUSPARSE.CuSparseMatrixCSC) = SparseMatrixCSR(CuSparseMatrixCSR(A)) | ||
| SparseMatricesCSR.SparseMatrixCSR(A::CUSPARSE.CuSparseMatrixBSR) = SparseMatrixCSR(CuSparseMatrixCSR(A)) | ||
|
|
||
| # Adapt | ||
| Adapt.adapt_storage(::Type{CuArray}, xs::SparseMatrixCSR) = CUSPARSE.CuSparseMatrixCSR(xs) | ||
| Adapt.adapt_storage(::Type{CuArray{T}}, xs::SparseMatrixCSR) where {T} = CUSPARSE.CuSparseMatrixCSR{T}(xs) | ||
| Adapt.adapt_storage(::Type{Array}, mat::CUSPARSE.CuSparseMatrixCSR) = SparseMatrixCSR(mat) | ||
|
|
||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| using SparseMatricesCSR | ||
| using SparseArrays | ||
| using CUDA | ||
| using CUDA.CUSPARSE | ||
| using Test | ||
|
|
||
| @testset "SparseMatricesCSRExt" begin | ||
|
|
||
| for (n, bd, p) in [(100, 5, 0.02), (5, 1, 0.8), (4, 2, 0.5)] | ||
| v"12.0" <= CUSPARSE.version() < v"12.1" && n == 4 && continue | ||
| @testset "conversions between CuSparseMatrices (n, bd, p) = ($n, $bd, $p)" begin | ||
| _A = sprand(n, n, p) | ||
| A = SparseMatrixCSR(_A) | ||
| blockdim = bd | ||
| for CuSparseMatrixType1 in (CuSparseMatrixCSC, CuSparseMatrixCSR, CuSparseMatrixCOO, CuSparseMatrixBSR) | ||
| dA1 = CuSparseMatrixType1 == CuSparseMatrixBSR ? CuSparseMatrixType1(A, blockdim) : CuSparseMatrixType1(A) | ||
| @testset "conversion $CuSparseMatrixType1 --> SparseMatrixCSR" begin | ||
| @test SparseMatrixCSR(dA1) ≈ A | ||
| end | ||
| for CuSparseMatrixType2 in (CuSparseMatrixCSC, CuSparseMatrixCSR, CuSparseMatrixCOO, CuSparseMatrixBSR) | ||
| CuSparseMatrixType1 == CuSparseMatrixType2 && continue | ||
| dA2 = CuSparseMatrixType2 == CuSparseMatrixBSR ? CuSparseMatrixType2(dA1, blockdim) : CuSparseMatrixType2(dA1) | ||
| @testset "conversion $CuSparseMatrixType1 --> $CuSparseMatrixType2" begin | ||
| @test collect(dA1) ≈ collect(dA2) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.