-
Couldn't load subscription status.
- Fork 6
feat: decompression for cuSPARSE matrices #253
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
16 commits
Select commit
Hold shift + click to select a range
77002f4
Decompression for CuSparseMatrixCSC
gdalle 649a3c8
Add test
gdalle 52d9c6a
CuRef
gdalle 2d8fc5a
Broken test
gdalle 94d9ff4
Self-hosted
gdalle 4334c2a
Revert self-hosted
gdalle 51a7b54
Separate GPU test
gdalle a6110ec
Remove CuRef
gdalle f7daa2f
Write CUDA kernel
gdalle 92594c4
Store CSR indices as additional info
gdalle 82e11a0
Exclude kernel from coverage
gdalle 8de2593
Remove kernel
gdalle 25b1dc7
Update .github/workflows/Test-GPU.yml
amontoison 998d4db
Use `copyto!` of a `view`
gdalle dd94814
Add error
gdalle 5d9e198
No uplo for row or column
gdalle 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| name: Test-GPU | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| pull_request: | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} | ||
|
|
||
| # needed to allow julia-actions/cache to delete old caches that it has created | ||
| permissions: | ||
| actions: write | ||
| contents: read | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: self-hosted | ||
| env: | ||
| CUDA_VISIBLE_DEVICES: 1 | ||
| JULIA_DEPOT_PATH: /scratch/github-actions/julia_depot_smc | ||
| JULIA_SMC_TEST_GROUP: "GPU" | ||
| strategy: | ||
| matrix: | ||
| julia-version: ['1.10', '1'] | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: julia-actions/setup-julia@v2 | ||
| with: | ||
| version: ${{ matrix.julia-version }} | ||
| arch: x64 | ||
| - uses: julia-actions/julia-downgrade-compat@v1 | ||
| if: ${{ matrix.version == '1.10' }} | ||
| with: | ||
| skip: LinearAlgebra, Random, SparseArrays | ||
| - uses: julia-actions/cache@v2 | ||
| - uses: julia-actions/julia-buildpkg@v1 | ||
| - uses: julia-actions/julia-runtest@v1 | ||
| - uses: julia-actions/julia-processcoverage@v1 | ||
| - uses: codecov/codecov-action@v5 | ||
| with: | ||
| files: lcov.info | ||
| token: ${{ secrets.CODECOV_TOKEN }} | ||
| fail_ci_if_error: false |
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,155 @@ | ||
| module SparseMatrixColoringsCUDAExt | ||
|
|
||
| import SparseMatrixColorings as SMC | ||
| using SparseArrays: SparseMatrixCSC, rowvals, nnz, nzrange | ||
| using CUDA: CuVector, CuMatrix | ||
| using CUDA.CUSPARSE: AbstractCuSparseMatrix, CuSparseMatrixCSC, CuSparseMatrixCSR | ||
|
|
||
| SMC.matrix_versions(A::AbstractCuSparseMatrix) = (A,) | ||
|
|
||
| ## Compression (slow, through CPU) | ||
|
|
||
| function SMC.compress( | ||
| A::AbstractCuSparseMatrix, result::SMC.AbstractColoringResult{structure,:column} | ||
| ) where {structure} | ||
| return CuMatrix(SMC.compress(SparseMatrixCSC(A), result)) | ||
| end | ||
|
|
||
| function SMC.compress( | ||
| A::AbstractCuSparseMatrix, result::SMC.AbstractColoringResult{structure,:row} | ||
| ) where {structure} | ||
| return CuMatrix(SMC.compress(SparseMatrixCSC(A), result)) | ||
| end | ||
|
|
||
| ## CSC Result | ||
|
|
||
| function SMC.ColumnColoringResult( | ||
| A::CuSparseMatrixCSC, bg::SMC.BipartiteGraph{T}, color::Vector{<:Integer} | ||
| ) where {T<:Integer} | ||
| group = SMC.group_by_color(T, color) | ||
| compressed_indices = SMC.column_csc_indices(bg, color) | ||
| additional_info = (; compressed_indices_gpu_csc=CuVector(compressed_indices)) | ||
| return SMC.ColumnColoringResult( | ||
| A, bg, color, group, compressed_indices, additional_info | ||
| ) | ||
| end | ||
|
|
||
| function SMC.RowColoringResult( | ||
| A::CuSparseMatrixCSC, bg::SMC.BipartiteGraph{T}, color::Vector{<:Integer} | ||
| ) where {T<:Integer} | ||
| group = SMC.group_by_color(T, color) | ||
| compressed_indices = SMC.row_csc_indices(bg, color) | ||
| additional_info = (; compressed_indices_gpu_csc=CuVector(compressed_indices)) | ||
| return SMC.RowColoringResult(A, bg, color, group, compressed_indices, additional_info) | ||
| end | ||
|
|
||
| function SMC.StarSetColoringResult( | ||
| A::CuSparseMatrixCSC, | ||
| ag::SMC.AdjacencyGraph{T}, | ||
| color::Vector{<:Integer}, | ||
| star_set::SMC.StarSet{<:Integer}, | ||
| ) where {T<:Integer} | ||
| group = SMC.group_by_color(T, color) | ||
| compressed_indices = SMC.star_csc_indices(ag, color, star_set) | ||
| additional_info = (; compressed_indices_gpu_csc=CuVector(compressed_indices)) | ||
| return SMC.StarSetColoringResult( | ||
| A, ag, color, group, compressed_indices, additional_info | ||
| ) | ||
| end | ||
|
|
||
| ## CSR Result | ||
|
|
||
| function SMC.ColumnColoringResult( | ||
| A::CuSparseMatrixCSR, bg::SMC.BipartiteGraph{T}, color::Vector{<:Integer} | ||
| ) where {T<:Integer} | ||
| group = SMC.group_by_color(T, color) | ||
| compressed_indices = SMC.column_csc_indices(bg, color) | ||
| compressed_indices_csr = SMC.column_csr_indices(bg, color) | ||
| additional_info = (; compressed_indices_gpu_csr=CuVector(compressed_indices_csr)) | ||
| return SMC.ColumnColoringResult( | ||
| A, bg, color, group, compressed_indices, additional_info | ||
| ) | ||
| end | ||
|
|
||
| function SMC.RowColoringResult( | ||
| A::CuSparseMatrixCSR, bg::SMC.BipartiteGraph{T}, color::Vector{<:Integer} | ||
| ) where {T<:Integer} | ||
| group = SMC.group_by_color(T, color) | ||
| compressed_indices = SMC.row_csc_indices(bg, color) | ||
| compressed_indices_csr = SMC.row_csr_indices(bg, color) | ||
| additional_info = (; compressed_indices_gpu_csr=CuVector(compressed_indices_csr)) | ||
| return SMC.RowColoringResult(A, bg, color, group, compressed_indices, additional_info) | ||
| end | ||
|
|
||
| function SMC.StarSetColoringResult( | ||
| A::CuSparseMatrixCSR, | ||
| ag::SMC.AdjacencyGraph{T}, | ||
| color::Vector{<:Integer}, | ||
| star_set::SMC.StarSet{<:Integer}, | ||
| ) where {T<:Integer} | ||
| group = SMC.group_by_color(T, color) | ||
| compressed_indices = SMC.star_csc_indices(ag, color, star_set) | ||
| additional_info = (; compressed_indices_gpu_csr=CuVector(compressed_indices)) | ||
| return SMC.StarSetColoringResult( | ||
| A, ag, color, group, compressed_indices, additional_info | ||
| ) | ||
| end | ||
|
|
||
| ## Decompression | ||
|
|
||
| for R in (:ColumnColoringResult, :RowColoringResult) | ||
| # loop to avoid method ambiguity | ||
| @eval function SMC.decompress!( | ||
| A::CuSparseMatrixCSC, B::CuMatrix, result::SMC.$R{<:CuSparseMatrixCSC} | ||
gdalle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
| compressed_indices = result.additional_info.compressed_indices_gpu_csc | ||
| copyto!(A.nzVal, view(B, compressed_indices)) | ||
| return A | ||
| end | ||
|
|
||
| @eval function SMC.decompress!( | ||
| A::CuSparseMatrixCSR, B::CuMatrix, result::SMC.$R{<:CuSparseMatrixCSR} | ||
| ) | ||
| compressed_indices = result.additional_info.compressed_indices_gpu_csr | ||
| copyto!(A.nzVal, view(B, compressed_indices)) | ||
| return A | ||
| end | ||
| end | ||
|
|
||
| function SMC.decompress!( | ||
| A::CuSparseMatrixCSC, | ||
| B::CuMatrix, | ||
| result::SMC.StarSetColoringResult{<:CuSparseMatrixCSC}, | ||
| uplo::Symbol=:F, | ||
| ) | ||
| if uplo != :F | ||
| throw( | ||
| SMC.UnsupportedDecompressionError( | ||
| "Single-triangle decompression is not supported on GPU matrices" | ||
| ), | ||
| ) | ||
| end | ||
| compressed_indices = result.additional_info.compressed_indices_gpu_csc | ||
| copyto!(A.nzVal, view(B, compressed_indices)) | ||
| return A | ||
| end | ||
|
|
||
| function SMC.decompress!( | ||
| A::CuSparseMatrixCSR, | ||
| B::CuMatrix, | ||
| result::SMC.StarSetColoringResult{<:CuSparseMatrixCSR}, | ||
| uplo::Symbol=:F, | ||
| ) | ||
| if uplo != :F | ||
| throw( | ||
| SMC.UnsupportedDecompressionError( | ||
| "Single-triangle decompression is not supported on GPU matrices" | ||
| ), | ||
| ) | ||
| end | ||
| compressed_indices = result.additional_info.compressed_indices_gpu_csr | ||
| copyto!(A.nzVal, view(B, compressed_indices)) | ||
| return A | ||
| end | ||
|
|
||
| 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
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
Oops, something went wrong.
Oops, something went wrong.
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.