CarloLucibello / GraphNeuralNetworks.jl

Graph Neural Networks in Julia
https://carlolucibello.github.io/GraphNeuralNetworks.jl/dev/
MIT License
211 stars 47 forks source link

Error in getgraph when graph is on gpu #161

Open oysteinsolheim opened 2 years ago

oysteinsolheim commented 2 years ago

Running the following script

using Flux
using GraphNeuralNetworks

n = m = d = N = 10

g = Flux.batch([rand_graph(n, m, ndata=rand(d, n)) for i in 1:N])
getgraph(g, 1)
getgraph(g |> gpu, 1)

results in the following error message for the last call:

LoadError: GPU compilation of kernel broadcast_kernel(CUDA.CuKernelContext, CUDA.CuDeviceVector{Bool, 1}, Base.Broadcast.Broadcasted{Nothing, Tuple{Base.OneTo{Int64}}, typeof(in), Tuple{Base.Broadcast.Extruded{CUDA.CuDeviceVector{Int64, 1}, Tuple{Bool}, Tuple{Int64}}, CUDA.CuRefValue{Vector{Int64}}}}, Int64) failed
KernelError: passing and using non-bitstype argument

Argument 4 to your kernel function is of type Base.Broadcast.Broadcasted{Nothing, Tuple{Base.OneTo{Int64}}, typeof(in), Tuple{Base.Broadcast.Extruded{CUDA.CuDeviceVector{Int64, 1}, Tuple{Bool}, Tuple{Int64}}, CUDA.CuRefValue{Vector{Int64}}}}, which is not isbits:
  .args is of type Tuple{Base.Broadcast.Extruded{CUDA.CuDeviceVector{Int64, 1}, Tuple{Bool}, Tuple{Int64}}, CUDA.CuRefValue{Vector{Int64}}} which is not isbits.
    .2 is of type CUDA.CuRefValue{Vector{Int64}} which is not isbits.
      .x is of type Vector{Int64} which is not isbits.

I am on Julia 1.7.2, Flux version 0.12.9 and GraphNeuralNetworks 0.3.14. Edit: Also error with GNN 0.4.0 and Flux 0.13.0 Am I missing something?

CarloLucibello commented 2 years ago

Maybe with a function barrier on this line https://github.com/CarloLucibello/GraphNeuralNetworks.jl/blob/eb43bc9e23f02c15c8b8640e5d055d0f14b480bc/src/GNNGraphs/transform.jl#L460 we can make it gpu friendly

oysteinsolheim commented 2 years ago

Thanks! But looking around I realised that the helper function brodcast_nodes in utils.jl pretty much do what I wanted to do today (distribute global features to nodes) so there's no hurry with this one as far as I'm concerned.

Dolgalad commented 1 year ago

Hi, I have been encountering the same problem recently and am wondering if a solution exists. As far as I understand a problem arises constructing the nodemap and graphmap structures.

https://github.com/CarloLucibello/GraphNeuralNetworks.jl/blob/65c0faaa3f6b015b70b04d00687f03e671208f15/src/GNNGraphs/transform.jl#L564

CarloLucibello commented 1 year ago

yes I think this problem can be fixed, at least in the case in which g.graph_indicator is monotonic (which covers most uses I guess). @Dolgalad is also differentiability of getgraph a requirement for you, i.e. are you using it in a gradient computing context?