Skip to content

Instantly share code, notes, and snippets.

@rejuvyesh
Last active February 9, 2022 17:32
Show Gist options
  • Save rejuvyesh/be230c57faa1bffeffc57f6d4f9a9514 to your computer and use it in GitHub Desktop.
Save rejuvyesh/be230c57faa1bffeffc57f6d4f9a9514 to your computer and use it in GitHub Desktop.
DLPACk segfault reproduce on CUDA+Jax
using PyCall
using CUDA
using DLPack
using Test
#using Zygote
#using ChainRulesCore
@show DLPack.PYCALL_NOOP_DELETER
jax = pyimport("jax")
dlpack = pyimport("jax.dlpack")
numpy = pyimport("numpy")
pyto_dlpack(x) = @pycall dlpack.to_dlpack(x)::PyObject
pyfrom_dlpack(x) = @pycall dlpack.from_dlpack(x)::PyObject
@testset "dlpack" begin
key = jax.random.PRNGKey(0)
for dims in ((10,), (1, 10), (2, 3, 5), (2, 3, 4, 5))
xto = jax.random.normal(key, dims)
xjl = DLArray(xto, pyto_dlpack)
@test isapprox(numpy.array(xto), Array(xjl))
end
end
cujl = CuArray(randn(Float32, 2, 3, 5))
cujax = DLPack.share(cujl, pyfrom_dlpack)
@test (jax.numpy.sum(cujax).item()) ≈ sum(cujl)
@rejuvyesh
Copy link
Author

julia> include("test/stresstest_jax_dlpack.jl")
DLPack.PYCALL_NOOP_DELETER = Ptr{Nothing} @0x00007f460e72e0d0

signal (11): Segmentation fault
in expression starting at /home/jagupt/.julia/dev/PyCallChainRules/test/stresstest_jax_dlpack.jl:26
unknown function (ip: 0x7f45f5292810)
_ZNSt16_Sp_counted_baseILN9__gnu_cxx12_Lock_policyE2EE10_M_releaseEv at /home/jagupt/local/anaconda/envs/nstrain/lib/python3.8/site-packages/jaxlib/xla_extension.so (unknown line)
_ZN3xla24PjRtStreamExecutorBuffer6DeleteEv at /home/jagupt/local/anaconda/envs/nstrain/lib/python3.8/site-packages/jaxlib/xla_extension.so (unknown line)
_ZN3xla24PjRtStreamExecutorBufferD2Ev at /home/jagupt/local/anaconda/envs/nstrain/lib/python3.8/site-packages/jaxlib/xla_extension.so (unknown line)
_ZN3xla24PjRtStreamExecutorBufferD0Ev at /home/jagupt/local/anaconda/envs/nstrain/lib/python3.8/site-packages/jaxlib/xla_extension.so (unknown line)
_ZNSt16_Sp_counted_baseILN9__gnu_cxx12_Lock_policyE2EE10_M_releaseEv at /home/jagupt/local/anaconda/envs/nstrain/lib/python3.8/site-packages/jaxlib/xla_extension.so (unknown line)
_ZN3xla8PyBufferD2Ev at /home/jagupt/local/anaconda/envs/nstrain/lib/python3.8/site-packages/jaxlib/xla_extension.so (unknown line)
_ZN3xla12_GLOBAL__N_119PyBuffer_tp_deallocEP7_object at /home/jagupt/local/anaconda/envs/nstrain/lib/python3.8/site-packages/jaxlib/xla_extension.so (unknown line)
pydecref_ at /home/jagupt/.julia/packages/PyCall/L0fLP/src/PyCall.jl:118 [inlined]
pydecref at /home/jagupt/.julia/packages/PyCall/L0fLP/src/PyCall.jl:123
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2247 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2429
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1788 [inlined]
run_finalizer at /buildworker/worker/package_linux64/build/src/gc.c:278
jl_gc_run_finalizers_in_list at /buildworker/worker/package_linux64/build/src/gc.c:365
run_finalizers at /buildworker/worker/package_linux64/build/src/gc.c:394
jl_gc_run_pending_finalizers at /buildworker/worker/package_linux64/build/src/gc.c:405
jl_mutex_unlock at /buildworker/worker/package_linux64/build/src/julia_locks.h:131 [inlined]
jl_generate_fptr at /buildworker/worker/package_linux64/build/src/jitlayers.cpp:359
jl_compile_method_internal at /buildworker/worker/package_linux64/build/src/gf.c:1980
jl_compile_method_internal at /buildworker/worker/package_linux64/build/src/gf.c:2246 [inlined]
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2239 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2429
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1788 [inlined]
do_call at /buildworker/worker/package_linux64/build/src/interpreter.c:126
eval_value at /buildworker/worker/package_linux64/build/src/interpreter.c:215
eval_stmt_value at /buildworker/worker/package_linux64/build/src/interpreter.c:166 [inlined]
eval_body at /buildworker/worker/package_linux64/build/src/interpreter.c:587
jl_interpret_toplevel_thunk at /buildworker/worker/package_linux64/build/src/interpreter.c:731
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:885
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:830
jl_toplevel_eval_in at /buildworker/worker/package_linux64/build/src/toplevel.c:944
eval at ./boot.jl:373 [inlined]
include_string at ./loading.jl:1196
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2247 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2429
_include at ./loading.jl:1253
include at ./client.jl:451
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2247 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2429
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1788 [inlined]
do_call at /buildworker/worker/package_linux64/build/src/interpreter.c:126
eval_value at /buildworker/worker/package_linux64/build/src/interpreter.c:215
eval_stmt_value at /buildworker/worker/package_linux64/build/src/interpreter.c:166 [inlined]
eval_body at /buildworker/worker/package_linux64/build/src/interpreter.c:587
jl_interpret_toplevel_thunk at /buildworker/worker/package_linux64/build/src/interpreter.c:731
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:885
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:830
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:830
eval_body at /buildworker/worker/package_linux64/build/src/interpreter.c:550
eval_body at /buildworker/worker/package_linux64/build/src/interpreter.c:516
jl_interpret_toplevel_thunk at /buildworker/worker/package_linux64/build/src/interpreter.c:731
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:885
jl_toplevel_eval_in at /buildworker/worker/package_linux64/build/src/toplevel.c:944
eval at ./boot.jl:373 [inlined]
eval_user_input at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:150
repl_backend_loop at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:246
start_repl_backend at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:231
#run_repl#47 at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:364
run_repl at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:351
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2247 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2429
#930 at ./client.jl:394
jfptr_YY.930_45169.clone_1 at /home/jagupt/.julia/juliaup/julia-1.7.2+0~x64/lib/julia/sys.so (unknown line)
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2247 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2429
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1788 [inlined]
jl_f__call_latest at /buildworker/worker/package_linux64/build/src/builtins.c:757
#invokelatest#2 at ./essentials.jl:716 [inlined]
invokelatest at ./essentials.jl:714 [inlined]
run_main_repl at ./client.jl:379
exec_options at ./client.jl:309
_start at ./client.jl:495
jfptr__start_38732.clone_1 at /home/jagupt/.julia/juliaup/julia-1.7.2+0~x64/lib/julia/sys.so (unknown line)
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2247 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2429
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1788 [inlined]
true_main at /buildworker/worker/package_linux64/build/src/jlapi.c:559
jl_repl_entrypoint at /buildworker/worker/package_linux64/build/src/jlapi.c:701
main at /buildworker/worker/package_linux64/build/cli/loader_exe.c:42
__libc_start_main at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
_start at /home/jagupt/.julia/juliaup/julia-1.7.2+0~x64/bin/julia (unknown line)
Allocations: 83303512 (Pool: 83273580; Big: 29932); GC: 83

@rejuvyesh
Copy link
Author

Edit: I haven't been able to get these again, huh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment