-
Notifications
You must be signed in to change notification settings - Fork 53
CUDA copy_xj propagate sparse support and benchmarks #605
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
CarloLucibello
merged 3 commits into
JuliaGraphs:master
from
dferre97:df/copyxj-sparse-cuda
Jul 6, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
@@ -1,6 +1,10 @@ | ||
[deps] | ||
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" | ||
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" | ||
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c" | ||
GNNGraphs = "aed8fd31-079b-4b5a-b342-a13352159b8c" | ||
GNNlib = "a6a84749-d869-43f8-aacc-be26a1996e48" | ||
GraphNeuralNetworks = "cffab07f-9bc2-4db1-8861-388f63bf7694" | ||
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" | ||
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" | ||
Graphs = "093fc24a-ae57-5d10-9952-331d41423f4d" |
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,48 @@ | ||
# # Activate the perf environment | ||
# using Pkg | ||
# Pkg.activate(@__DIR__) | ||
# Pkg.develop(path=joinpath(@__DIR__, "..", "..", "GNNGraphs")) | ||
# Pkg.develop(path=joinpath(@__DIR__, "..", "..", "GNNlib")) | ||
# Pkg.develop(path=joinpath(@__DIR__, "..")) | ||
# Pkg.instantiate() | ||
using SparseArrays | ||
using GraphNeuralNetworks | ||
using BenchmarkTools | ||
import Random: seed! | ||
using LinearAlgebra | ||
using Flux, CUDA | ||
|
||
# ENV["JULIA_DEBUG"] = "GraphNeuralNetworks,GNNlib,GNNlibCUDAExt,GNNGraphs,GNNGraphsCUDAExt,CUDA" # packages with debugging enabled, don't put a whitespace between the package names | ||
|
||
function prop_copy_xj(graph_type, sp_p, n, feat_size) | ||
A = sprand(n, n, sp_p) | ||
b = rand(1, n) | ||
B = rand(feat_size, n) | ||
g = GNNGraph(A, | ||
ndata = (; b = b, B = B), | ||
edata = (; A = reshape(A.nzval, 1, :)), | ||
graph_type = graph_type) |> dev | ||
printstyled("propagate copy_xj for graph type: $graph_type", "\n", color=:yellow) | ||
CUDA.@sync propagate(copy_xj, g, +; xj = g.ndata.B) # run once to compile before benchmarking | ||
# @profview for _ in 1:1000 | ||
# propagate(copy_xj, g, +; xj = g.ndata.B) | ||
# end | ||
@btime CUDA.@sync propagate($copy_xj, $g, +; xj = $g.ndata.B) # using spmm for :sparse | ||
printstyled("gather/scatter propagate copy_xj for graph type: $graph_type", "\n", color=:yellow) | ||
CUDA.@sync propagate((xi, xj, e) -> xj, g, +; xj = g.ndata.B) # run once to compile before benchmarking | ||
@btime CUDA.@sync propagate((xi, xj, e) -> xj, $g, +; xj = $g.ndata.B) # using gather/scatter | ||
return nothing | ||
end | ||
|
||
seed!(0) | ||
dev = gpu_device() | ||
println("Device: ", dev) | ||
feat_size = 128 | ||
# test for :sparse graph_type | ||
for n in (32, 128, 1024) | ||
for sp_p in (0.01, 0.1, 0.9) | ||
printstyled("n = $n, feat_size = $feat_size, sparsity = $sp_p\n", color=:blue) | ||
prop_copy_xj(:sparse, sp_p, n, feat_size) | ||
println() | ||
end | ||
end |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the cast to the xj type necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, for the sparse case, because the SpMM mm! function in CUSPASE expects the type of the adjmat and the feature matrix to be the same, so we need to cast the adjmat before multiplying.