From 34dc3aa9ce349a28b393f53379aed6edc5f602fd Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Thu, 16 Apr 2026 10:42:20 +0200 Subject: [PATCH 1/8] chore: bump CUDA compat to v6 (cuSPARSE now a separate package) --- Project.toml | 8 +++++--- ext/SparseMatrixColoringsCUDAExt.jl | 2 +- test/Project.toml | 3 --- test/cuda.jl | 2 -- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/Project.toml b/Project.toml index 17a66304..30aaa67e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "SparseMatrixColorings" uuid = "0a514795-09f3-496d-8182-132a7b665d35" +version = "0.4.27" authors = ["Guillaume Dalle", "Alexis Montoison"] -version = "0.4.26" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" @@ -17,16 +17,18 @@ CliqueTrees = "60701a23-6482-424a-84db-faee86b9b1f8" Colors = "5ae59095-9a9b-59fe-a467-6f913c188581" JuMP = "4076af6c-e467-56ae-b986-b466b2749572" MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee" +cuSPARSE = "b26da814-b3bc-49ef-b0ee-c816305aa060" [extensions] -SparseMatrixColoringsCUDAExt = "CUDA" +SparseMatrixColoringsCUDAExt = ["CUDA", "cuSPARSE"] SparseMatrixColoringsCliqueTreesExt = "CliqueTrees" SparseMatrixColoringsColorsExt = "Colors" SparseMatrixColoringsJuMPExt = ["JuMP", "MathOptInterface"] [compat] ADTypes = "1.2.1" -CUDA = "5.8.2" +CUDA = "6.0.0" +cuSPARSE = "6.0.0" CliqueTrees = "1" Colors = "0.12.11, 0.13" DocStringExtensions = "0.8,0.9" diff --git a/ext/SparseMatrixColoringsCUDAExt.jl b/ext/SparseMatrixColoringsCUDAExt.jl index 2750964d..78a7a401 100644 --- a/ext/SparseMatrixColoringsCUDAExt.jl +++ b/ext/SparseMatrixColoringsCUDAExt.jl @@ -3,7 +3,7 @@ module SparseMatrixColoringsCUDAExt import SparseMatrixColorings as SMC using SparseArrays: SparseMatrixCSC, rowvals, nnz, nzrange using CUDA: CuVector, CuMatrix -using CUDA.CUSPARSE: AbstractCuSparseMatrix, CuSparseMatrixCSC, CuSparseMatrixCSR +using cuSPARSE: AbstractCuSparseMatrix, CuSparseMatrixCSC, CuSparseMatrixCSR SMC.matrix_versions(A::AbstractCuSparseMatrix) = (A,) diff --git a/test/Project.toml b/test/Project.toml index 4c505efa..284f410b 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -23,6 +23,3 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" SparseMatrixColorings = "0a514795-09f3-496d-8182-132a7b665d35" StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" - -[compat] -CUDA = "=5.9.5" diff --git a/test/cuda.jl b/test/cuda.jl index 6549b168..b403f1e6 100644 --- a/test/cuda.jl +++ b/test/cuda.jl @@ -6,8 +6,6 @@ import SparseMatrixColorings as SMC using StableRNGs using Test -include("utils.jl") - rng = StableRNG(63) asymmetric_params = vcat( From 5f4e222d5b1e683d264a902a3816ec1344e4b610 Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Thu, 16 Apr 2026 10:54:09 +0200 Subject: [PATCH 2/8] More renaming --- test/Project.toml | 1 + test/cuda.jl | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/test/Project.toml b/test/Project.toml index 284f410b..5e41ceb2 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -23,3 +23,4 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" SparseMatrixColorings = "0a514795-09f3-496d-8182-132a7b665d35" StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +cuSPARSE = "b26da814-b3bc-49ef-b0ee-c816305aa060" diff --git a/test/cuda.jl b/test/cuda.jl index b403f1e6..a1d4f32f 100644 --- a/test/cuda.jl +++ b/test/cuda.jl @@ -1,4 +1,4 @@ -using CUDA.CUSPARSE: CuSparseMatrixCSC, CuSparseMatrixCSR +using cuSPARSE: CuSparseMatrixCSC, CuSparseMatrixCSR using LinearAlgebra using SparseArrays using SparseMatrixColorings @@ -21,34 +21,34 @@ symmetric_params = vcat( ) @testset verbose = true "Column coloring & decompression" begin - problem = ColoringProblem(; structure=:nonsymmetric, partition=:column) - algo = GreedyColoringAlgorithm(; decompression=:direct) + problem = ColoringProblem(; structure = :nonsymmetric, partition = :column) + algo = GreedyColoringAlgorithm(; decompression = :direct) @testset for T in (CuSparseMatrixCSC, CuSparseMatrixCSR) @testset "$((; m, n, p))" for (m, n, p) in asymmetric_params A0 = T(sprand(rng, m, n, p)) - test_coloring_decompression(A0, problem, algo; gpu=true) + test_coloring_decompression(A0, problem, algo; gpu = true) end end end; @testset verbose = true "Row coloring & decompression" begin - problem = ColoringProblem(; structure=:nonsymmetric, partition=:row) - algo = GreedyColoringAlgorithm(; decompression=:direct) + problem = ColoringProblem(; structure = :nonsymmetric, partition = :row) + algo = GreedyColoringAlgorithm(; decompression = :direct) @testset for T in (CuSparseMatrixCSC, CuSparseMatrixCSR) @testset "$((; m, n, p))" for (m, n, p) in asymmetric_params A0 = T(sprand(rng, m, n, p)) - test_coloring_decompression(A0, problem, algo; gpu=true) + test_coloring_decompression(A0, problem, algo; gpu = true) end end end; @testset verbose = true "Symmetric coloring & direct decompression" begin - problem = ColoringProblem(; structure=:symmetric, partition=:column) - algo = GreedyColoringAlgorithm(; postprocessing=false, decompression=:direct) + problem = ColoringProblem(; structure = :symmetric, partition = :column) + algo = GreedyColoringAlgorithm(; postprocessing = false, decompression = :direct) @testset for T in (CuSparseMatrixCSC, CuSparseMatrixCSR) @testset "$((; n, p))" for (n, p) in symmetric_params A0 = T(sparse(Symmetric(sprand(rng, n, n, p)))) - test_coloring_decompression(A0, problem, algo; gpu=true) + test_coloring_decompression(A0, problem, algo; gpu = true) end A0 = T(sparse(Diagonal(ones(10)))) result = coloring(A0, problem, algo) From ab2953ee350a89966ea60263882079c9d69010f0 Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Thu, 16 Apr 2026 10:57:06 +0200 Subject: [PATCH 3/8] Format --- test/cuda.jl | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/cuda.jl b/test/cuda.jl index a1d4f32f..8b27e07b 100644 --- a/test/cuda.jl +++ b/test/cuda.jl @@ -21,34 +21,34 @@ symmetric_params = vcat( ) @testset verbose = true "Column coloring & decompression" begin - problem = ColoringProblem(; structure = :nonsymmetric, partition = :column) - algo = GreedyColoringAlgorithm(; decompression = :direct) + problem = ColoringProblem(; structure=:nonsymmetric, partition=:column) + algo = GreedyColoringAlgorithm(; decompression=:direct) @testset for T in (CuSparseMatrixCSC, CuSparseMatrixCSR) @testset "$((; m, n, p))" for (m, n, p) in asymmetric_params A0 = T(sprand(rng, m, n, p)) - test_coloring_decompression(A0, problem, algo; gpu = true) + test_coloring_decompression(A0, problem, algo; gpu=true) end end end; @testset verbose = true "Row coloring & decompression" begin - problem = ColoringProblem(; structure = :nonsymmetric, partition = :row) - algo = GreedyColoringAlgorithm(; decompression = :direct) + problem = ColoringProblem(; structure=:nonsymmetric, partition=:row) + algo = GreedyColoringAlgorithm(; decompression=:direct) @testset for T in (CuSparseMatrixCSC, CuSparseMatrixCSR) @testset "$((; m, n, p))" for (m, n, p) in asymmetric_params A0 = T(sprand(rng, m, n, p)) - test_coloring_decompression(A0, problem, algo; gpu = true) + test_coloring_decompression(A0, problem, algo; gpu=true) end end end; @testset verbose = true "Symmetric coloring & direct decompression" begin - problem = ColoringProblem(; structure = :symmetric, partition = :column) - algo = GreedyColoringAlgorithm(; postprocessing = false, decompression = :direct) + problem = ColoringProblem(; structure=:symmetric, partition=:column) + algo = GreedyColoringAlgorithm(; postprocessing=false, decompression=:direct) @testset for T in (CuSparseMatrixCSC, CuSparseMatrixCSR) @testset "$((; n, p))" for (n, p) in symmetric_params A0 = T(sparse(Symmetric(sprand(rng, n, n, p)))) - test_coloring_decompression(A0, problem, algo; gpu = true) + test_coloring_decompression(A0, problem, algo; gpu=true) end A0 = T(sparse(Diagonal(ones(10)))) result = coloring(A0, problem, algo) From 487493c881539c665a2bd262af024518dcc9b5ef Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Thu, 16 Apr 2026 11:41:28 +0200 Subject: [PATCH 4/8] Fix compression? --- ext/SparseMatrixColoringsCUDAExt.jl | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/ext/SparseMatrixColoringsCUDAExt.jl b/ext/SparseMatrixColoringsCUDAExt.jl index 78a7a401..256a948e 100644 --- a/ext/SparseMatrixColoringsCUDAExt.jl +++ b/ext/SparseMatrixColoringsCUDAExt.jl @@ -9,15 +9,7 @@ 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} +function SMC.compress(A::AbstractCuSparseMatrix, result::SMC.AbstractColoringResult) return CuMatrix(SMC.compress(SparseMatrixCSC(A), result)) end From 2592da0ec81f133a41d796a6fd44162194e49e3e Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Thu, 16 Apr 2026 12:47:22 +0200 Subject: [PATCH 5/8] Generic compression and result --- Project.toml | 5 +- ext/SparseMatrixColoringsCUDAExt.jl | 82 -------------------- ext/SparseMatrixColoringsGPUArraysExt.jl | 96 ++++++++++++++++++++++++ test/runtests.jl | 2 +- 4 files changed, 101 insertions(+), 84 deletions(-) create mode 100644 ext/SparseMatrixColoringsGPUArraysExt.jl diff --git a/Project.toml b/Project.toml index 30aaa67e..9ef7826d 100644 --- a/Project.toml +++ b/Project.toml @@ -15,6 +15,7 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" CliqueTrees = "60701a23-6482-424a-84db-faee86b9b1f8" Colors = "5ae59095-9a9b-59fe-a467-6f913c188581" +GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7" JuMP = "4076af6c-e467-56ae-b986-b466b2749572" MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee" cuSPARSE = "b26da814-b3bc-49ef-b0ee-c816305aa060" @@ -23,19 +24,21 @@ cuSPARSE = "b26da814-b3bc-49ef-b0ee-c816305aa060" SparseMatrixColoringsCUDAExt = ["CUDA", "cuSPARSE"] SparseMatrixColoringsCliqueTreesExt = "CliqueTrees" SparseMatrixColoringsColorsExt = "Colors" +SparseMatrixColoringsGPUArraysExt = "GPUArrays" SparseMatrixColoringsJuMPExt = ["JuMP", "MathOptInterface"] [compat] ADTypes = "1.2.1" CUDA = "6.0.0" -cuSPARSE = "6.0.0" CliqueTrees = "1" Colors = "0.12.11, 0.13" DocStringExtensions = "0.8,0.9" +GPUArrays = "11.5.0" JuMP = "1.29.1" LinearAlgebra = "1" MathOptInterface = "1.45.0" PrecompileTools = "1.2.1" Random = "1" SparseArrays = "1" +cuSPARSE = "6.0.0" julia = "1.10" diff --git a/ext/SparseMatrixColoringsCUDAExt.jl b/ext/SparseMatrixColoringsCUDAExt.jl index 256a948e..6462ea6b 100644 --- a/ext/SparseMatrixColoringsCUDAExt.jl +++ b/ext/SparseMatrixColoringsCUDAExt.jl @@ -5,88 +5,6 @@ using SparseArrays: SparseMatrixCSC, rowvals, nnz, nzrange using CUDA: CuVector, CuMatrix using cuSPARSE: AbstractCuSparseMatrix, CuSparseMatrixCSC, CuSparseMatrixCSR -SMC.matrix_versions(A::AbstractCuSparseMatrix) = (A,) - -## Compression (slow, through CPU) - -function SMC.compress(A::AbstractCuSparseMatrix, result::SMC.AbstractColoringResult) - 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) diff --git a/ext/SparseMatrixColoringsGPUArraysExt.jl b/ext/SparseMatrixColoringsGPUArraysExt.jl new file mode 100644 index 00000000..c90982a3 --- /dev/null +++ b/ext/SparseMatrixColoringsGPUArraysExt.jl @@ -0,0 +1,96 @@ +module SparseMatrixColoringsGPUArraysExt + +using GPUArrays: dense_array_type +using SparseArrays: SparseMatrixCSC +import SparseMatrixColorings as SMC + +SMC.matrix_versions(A::AbstractGPUSparseMatrix) = (A,) + +## Compression (slow, through CPU) + +function SMC.compress(A::AbstractGPUSparseMatrix, result::SMC.AbstractColoringResult) + A_cpu = SparseMatrixCSC(A) + B_cpu = SMC.compress(A_cpu, result) + B = dense_array_type(A)(B_cpu) + return B +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=dense_array_type(A)(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=dense_array_type(A)(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=dense_array_type(A)(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=dense_array_type(A)(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=dense_array_type(A)(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=dense_array_type(A)(compressed_indices)) + return SMC.StarSetColoringResult( + A, ag, color, group, compressed_indices, additional_info + ) +end + +end diff --git a/test/runtests.jl b/test/runtests.jl index 9494e5e2..ec679d4e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -12,7 +12,7 @@ include("utils.jl") @testset verbose = true "SparseMatrixColorings" begin if get(ENV, "JULIA_SMC_TEST_GROUP", nothing) == "GPU" @testset "CUDA" begin - using CUDA + using CUDA, cuSPARSE include("cuda.jl") end else From 6c4472f1a1f6cdc6c5d744ad9ae75659d56533fd Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Thu, 16 Apr 2026 12:51:16 +0200 Subject: [PATCH 6/8] Import --- ext/SparseMatrixColoringsGPUArraysExt.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/SparseMatrixColoringsGPUArraysExt.jl b/ext/SparseMatrixColoringsGPUArraysExt.jl index c90982a3..6ce6ccd9 100644 --- a/ext/SparseMatrixColoringsGPUArraysExt.jl +++ b/ext/SparseMatrixColoringsGPUArraysExt.jl @@ -1,6 +1,6 @@ module SparseMatrixColoringsGPUArraysExt -using GPUArrays: dense_array_type +using GPUArrays: AbstractGPUSparseMatrix, dense_array_type using SparseArrays: SparseMatrixCSC import SparseMatrixColorings as SMC From 1d2359e05b41bc79fcada8d2a3ff4971e34d5698 Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Thu, 16 Apr 2026 12:54:35 +0200 Subject: [PATCH 7/8] No generic result --- ext/SparseMatrixColoringsCUDAExt.jl | 74 ++++++++++++++++++++++ ext/SparseMatrixColoringsGPUArraysExt.jl | 78 ------------------------ 2 files changed, 74 insertions(+), 78 deletions(-) diff --git a/ext/SparseMatrixColoringsCUDAExt.jl b/ext/SparseMatrixColoringsCUDAExt.jl index 6462ea6b..ed33eece 100644 --- a/ext/SparseMatrixColoringsCUDAExt.jl +++ b/ext/SparseMatrixColoringsCUDAExt.jl @@ -5,6 +5,80 @@ using SparseArrays: SparseMatrixCSC, rowvals, nnz, nzrange using CUDA: CuVector, CuMatrix using cuSPARSE: AbstractCuSparseMatrix, CuSparseMatrixCSC, CuSparseMatrixCSR +## 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) diff --git a/ext/SparseMatrixColoringsGPUArraysExt.jl b/ext/SparseMatrixColoringsGPUArraysExt.jl index 6ce6ccd9..8df40b5a 100644 --- a/ext/SparseMatrixColoringsGPUArraysExt.jl +++ b/ext/SparseMatrixColoringsGPUArraysExt.jl @@ -15,82 +15,4 @@ function SMC.compress(A::AbstractGPUSparseMatrix, result::SMC.AbstractColoringRe return B 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=dense_array_type(A)(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=dense_array_type(A)(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=dense_array_type(A)(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=dense_array_type(A)(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=dense_array_type(A)(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=dense_array_type(A)(compressed_indices)) - return SMC.StarSetColoringResult( - A, ag, color, group, compressed_indices, additional_info - ) -end - end From 426bc72be1ab8f8e7832e09af05a01adccf83981 Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Thu, 16 Apr 2026 13:57:07 +0200 Subject: [PATCH 8/8] Fix ambiguity --- ext/SparseMatrixColoringsGPUArraysExt.jl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ext/SparseMatrixColoringsGPUArraysExt.jl b/ext/SparseMatrixColoringsGPUArraysExt.jl index 8df40b5a..37574e73 100644 --- a/ext/SparseMatrixColoringsGPUArraysExt.jl +++ b/ext/SparseMatrixColoringsGPUArraysExt.jl @@ -8,7 +8,18 @@ SMC.matrix_versions(A::AbstractGPUSparseMatrix) = (A,) ## Compression (slow, through CPU) -function SMC.compress(A::AbstractGPUSparseMatrix, result::SMC.AbstractColoringResult) +function SMC.compress( + A::AbstractGPUSparseMatrix, result::SMC.AbstractColoringResult{structure,:column} +) where {structure} + A_cpu = SparseMatrixCSC(A) + B_cpu = SMC.compress(A_cpu, result) + B = dense_array_type(A)(B_cpu) + return B +end + +function SMC.compress( + A::AbstractGPUSparseMatrix, result::SMC.AbstractColoringResult{structure,:row} +) where {structure} A_cpu = SparseMatrixCSC(A) B_cpu = SMC.compress(A_cpu, result) B = dense_array_type(A)(B_cpu)