|
| 1 | +# # Activate the perf environment |
| 2 | +# using Pkg |
| 3 | +# Pkg.activate(@__DIR__) |
| 4 | +# Pkg.develop(path=joinpath(@__DIR__, "..", "..", "GNNGraphs")) |
| 5 | +# Pkg.develop(path=joinpath(@__DIR__, "..", "..", "GNNlib")) |
| 6 | +# Pkg.develop(path=joinpath(@__DIR__, "..")) |
| 7 | +# Pkg.instantiate() |
| 8 | +using SparseArrays |
| 9 | +using GraphNeuralNetworks |
| 10 | +using BenchmarkTools |
| 11 | +import Random: seed! |
| 12 | +using LinearAlgebra |
| 13 | +using Flux, CUDA |
| 14 | + |
| 15 | +# ENV["JULIA_DEBUG"] = "GraphNeuralNetworks,GNNlib,GNNlibCUDAExt,GNNGraphs,GNNGraphsCUDAExt,CUDA" # packages with debugging enabled, don't put a whitespace between the package names |
| 16 | + |
| 17 | +function prop_copy_xj(graph_type, sp_p, n, feat_size) |
| 18 | + A = sprand(n, n, sp_p) |
| 19 | + b = rand(1, n) |
| 20 | + B = rand(feat_size, n) |
| 21 | + g = GNNGraph(A, |
| 22 | + ndata = (; b = b, B = B), |
| 23 | + edata = (; A = reshape(A.nzval, 1, :)), |
| 24 | + graph_type = graph_type) |> dev |
| 25 | + printstyled("propagate copy_xj for graph type: $graph_type", "\n", color=:yellow) |
| 26 | + CUDA.@sync propagate(copy_xj, g, +; xj = g.ndata.B) # run once to compile before benchmarking |
| 27 | + # @profview for _ in 1:1000 |
| 28 | + # propagate(copy_xj, g, +; xj = g.ndata.B) |
| 29 | + # end |
| 30 | + @btime CUDA.@sync propagate($copy_xj, $g, +; xj = $g.ndata.B) # using spmm for :sparse |
| 31 | + printstyled("gather/scatter propagate copy_xj for graph type: $graph_type", "\n", color=:yellow) |
| 32 | + CUDA.@sync propagate((xi, xj, e) -> xj, g, +; xj = g.ndata.B) # run once to compile before benchmarking |
| 33 | + @btime CUDA.@sync propagate((xi, xj, e) -> xj, $g, +; xj = $g.ndata.B) # using gather/scatter |
| 34 | + return nothing |
| 35 | +end |
| 36 | + |
| 37 | +seed!(0) |
| 38 | +dev = gpu_device() |
| 39 | +println("Device: ", dev) |
| 40 | +feat_size = 128 |
| 41 | +# test for :sparse graph_type |
| 42 | +for n in (32, 128, 1024) |
| 43 | + for sp_p in (0.01, 0.1, 0.9) |
| 44 | + printstyled("n = $n, feat_size = $feat_size, sparsity = $sp_p\n", color=:blue) |
| 45 | + prop_copy_xj(:sparse, sp_p, n, feat_size) |
| 46 | + println() |
| 47 | + end |
| 48 | +end |
0 commit comments