Skip to content

Commit 4ba6321

Browse files
committed
Disable the GC during graph capture.
It cannot handle asynchronous frees.
1 parent 787a71f commit 4ba6321

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/cudadrv/graph.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,19 @@ mutable struct CuGraph
2828
return obj
2929
end
3030

31-
global function capture(f::Function; flags=STREAM_CAPTURE_MODE_GLOBAL, throw_error::Bool=true)
32-
cuStreamBeginCapture_v2(stream(), flags)
33-
31+
global function capture(f::Function; flags=STREAM_CAPTURE_MODE_GLOBAL,
32+
throw_error::Bool=true)
33+
# graph capture does not support asynchronous memory operations, so disable the GC
34+
gc_state = GC.enable(false)
3435
ctx = current_context()
3536
obj = nothing
3637
try
38+
cuStreamBeginCapture_v2(stream(), flags)
3739
f()
3840
finally
3941
handle_ref = Ref{CUgraph}()
4042
err = unchecked_cuStreamEndCapture(stream(), handle_ref)
43+
GC.enable(gc_state)
4144
if err == ERROR_STREAM_CAPTURE_INVALIDATED && !throw_error
4245
return nothing
4346
elseif err != CUDA_SUCCESS

0 commit comments

Comments
 (0)