Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

Uncached JIT breaks recursion #122

Closed
tshort opened this issue Oct 7, 2017 · 5 comments
Closed

Uncached JIT breaks recursion #122

tshort opened this issue Oct 7, 2017 · 5 comments

Comments

@tshort
Copy link

tshort commented Oct 7, 2017

myf(x) = (sum([6,x]); return)
@cuda (1,1) myf(9)

This probably isn't a problem for you because I think it only overflows for code you shouldn't use.

I also have this issue at tshort/ExportWebAssembly.jl#3 -- that repo is almost entirely based on your code.

Here's the last part of the stack trace:

jl_compile_linfo at /mnt/raid/e/tmp/julia/src/codegen.cpp:1168
emit_invoke at /mnt/raid/e/tmp/julia/src/codegen.cpp:3015
emit_expr at /mnt/raid/e/tmp/julia/src/codegen.cpp:3770
emit_assignment at /mnt/raid/e/tmp/julia/src/codegen.cpp:3553 [inlined]
emit_expr at /mnt/raid/e/tmp/julia/src/codegen.cpp:3787
emit_stmtpos at /mnt/raid/e/tmp/julia/src/codegen.cpp:3696 [inlined]
emit_function at /mnt/raid/e/tmp/julia/src/codegen.cpp:5778
jl_compile_linfo at /mnt/raid/e/tmp/julia/src/codegen.cpp:1168
emit_invoke at /mnt/raid/e/tmp/julia/src/codegen.cpp:3015
emit_expr at /mnt/raid/e/tmp/julia/src/codegen.cpp:3770
emit_assignment at /mnt/raid/e/tmp/julia/src/codegen.cpp:3553 [inlined]
emit_expr at /mnt/raid/e/tmp/julia/src/codegen.cpp:3787
emit_stmtpos at /mnt/raid/e/tmp/julia/src/codegen.cpp:3696 [inlined]
emit_function at /mnt/raid/e/tmp/julia/src/codegen.cpp:5778
jl_compile_linfo at /mnt/raid/e/tmp/julia/src/codegen.cpp:1168
emit_invoke at /mnt/raid/e/tmp/julia/src/codegen.cpp:3015
emit_expr at /mnt/raid/e/tmp/julia/src/codegen.cpp:3770
emit_stmtpos at /mnt/raid/e/tmp/julia/src/codegen.cpp:3696 [inlined]
emit_function at /mnt/raid/e/tmp/julia/src/codegen.cpp:5778
jl_get_llvmf_defn at /mnt/raid/e/tmp/julia/src/codegen.cpp:1518
_dump_function_linfo at ./reflection.jl:805
_dump_function at ./reflection.jl:793
unknown function (ip: 0x7fc49bf3b03e)
jl_call_fptr_internal at /mnt/raid/e/tmp/julia/src/julia_internal.h:366 [inlined]
jl_call_method_internal at /mnt/raid/e/tmp/julia/src/julia_internal.h:385 [inlined]
jl_apply_generic at /mnt/raid/e/tmp/julia/src/gf.c:1980
irgen at /home/tshort/.julia/v0.7/CUDAnative/src/jit.jl:81
unknown function (ip: 0x7fc49bf37119)
jl_call_fptr_internal at /mnt/raid/e/tmp/julia/src/julia_internal.h:366 [inlined]
jl_call_method_internal at /mnt/raid/e/tmp/julia/src/julia_internal.h:385 [inlined]
jl_apply_generic at /mnt/raid/e/tmp/julia/src/gf.c:1980
#compile_function#51 at /home/tshort/.julia/v0.7/CUDAnative/src/jit.jl:395
unknown function (ip: 0x7fc49bf70b89)
jl_call_fptr_internal at /mnt/raid/e/tmp/julia/src/julia_internal.h:366 [inlined]
jl_call_method_internal at /mnt/raid/e/tmp/julia/src/julia_internal.h:385 [inlined]
jl_apply_generic at /mnt/raid/e/tmp/julia/src/gf.c:1980
compile_function at /home/tshort/.julia/v0.7/CUDAnative/src/jit.jl:389
jl_call_fptr_internal at /mnt/raid/e/tmp/julia/src/julia_internal.h:366 [inlined]
jl_call_method_internal at /mnt/raid/e/tmp/julia/src/julia_internal.h:385 [inlined]
jl_apply_generic at /mnt/raid/e/tmp/julia/src/gf.c:1980
cufunction at /home/tshort/.julia/v0.7/CUDAnative/src/jit.jl:459
@generated body at /home/tshort/.julia/v0.7/CUDAnative/src/execution.jl:108 [inlined]
_cuda at /home/tshort/.julia/v0.7/CUDAnative/src/execution.jl:80
unknown function (ip: 0x7fc49bf84d58)
jl_call_fptr_internal at /mnt/raid/e/tmp/julia/src/julia_internal.h:366 [inlined]
jl_call_method_internal at /mnt/raid/e/tmp/julia/src/julia_internal.h:385 [inlined]
jl_apply_generic at /mnt/raid/e/tmp/julia/src/gf.c:1980
jl_apply at /mnt/raid/e/tmp/julia/src/julia.h:1451 [inlined]
jl_f__apply at /mnt/raid/e/tmp/julia/src/builtins.c:556
jl_call_fptr_internal at /mnt/raid/e/tmp/julia/src/julia_internal.h:366 [inlined]
jl_call_method_internal at /mnt/raid/e/tmp/julia/src/julia_internal.h:385 [inlined]
jl_apply_generic at /mnt/raid/e/tmp/julia/src/gf.c:1980
do_call at /mnt/raid/e/tmp/julia/src/interpreter.c:70
eval at /mnt/raid/e/tmp/julia/src/interpreter.c:262
jl_interpret_toplevel_expr_in at /mnt/raid/e/tmp/julia/src/interpreter.c:50
jl_toplevel_eval_flex at /mnt/raid/e/tmp/julia/src/toplevel.c:640
jl_toplevel_eval_in at /mnt/raid/e/tmp/julia/src/builtins.c:626
eval at ./repl/REPL.jl:3
jl_call_fptr_internal at /mnt/raid/e/tmp/julia/src/julia_internal.h:366 [inlined]
jl_call_method_internal at /mnt/raid/e/tmp/julia/src/julia_internal.h:385 [inlined]
jl_apply_generic at /mnt/raid/e/tmp/julia/src/gf.c:1980
eval_user_input at ./repl/REPL.jl:69
jl_call_fptr_internal at /mnt/raid/e/tmp/julia/src/julia_internal.h:366 [inlined]
jl_call_method_internal at /mnt/raid/e/tmp/julia/src/julia_internal.h:385 [inlined]
jl_apply_generic at /mnt/raid/e/tmp/julia/src/gf.c:1980
macro expansion at ./repl/REPL.jl:100 [inlined]
#1 at ./event.jl:96
jl_call_fptr_internal at /mnt/raid/e/tmp/julia/src/julia_internal.h:366 [inlined]
jl_call_method_internal at /mnt/raid/e/tmp/julia/src/julia_internal.h:385 [inlined]
jl_apply_generic at /mnt/raid/e/tmp/julia/src/gf.c:1980
jl_apply at /mnt/raid/e/tmp/julia/src/julia.h:1451 [inlined]
start_task at /mnt/raid/e/tmp/julia/src/task.c:268
unknown function (ip: 0xffffffffffffffff)
ERROR: StackOverflowError:
Stacktrace:
 [1] _dump_function_linfo(::Core.MethodInstance, ::UInt64, ::Bool, ::Bool, ::Bool, ::Bool, ::Symbol, ::Bool, ::Base.CodegenParams) at ./reflection.jl:805
 [2] _dump_function(::Any, ::Any, ::Bool, ::Bool, ::Bool, ::Bool, ::Symbol, ::Bool, ::Base.CodegenParams) at ./reflection.jl:793
 [3] irgen(::Function, ::Type{T} where T<:Tuple) at /home/tshort/.julia/v0.7/CUDAnative/src/jit.jl:81
 [4] #compile_function#51(::Bool, ::Function, ::Function, ::Type{T} where T<:Tuple, ::VersionNumber) at /home/tshort/.julia/v0.7/CUDAnative/src/jit.jl:395
 [5] compile_function(::Function, ::Type{T} where T<:Tuple, ::VersionNumber) at /home/tshort/.julia/v0.7/CUDAnative/src/jit.jl:389
 [6] cufunction(::CUDAdrv.CuDevice, ::Function, ::Type{T} where T<:Tuple) at /home/tshort/.julia/v0.7/CUDAnative/src/jit.jl:459
 [7] @generated body at /home/tshort/.julia/v0.7/CUDAnative/src/execution.jl:108 [inlined]
 [8] _cuda(::Tuple{Int64,Int64}, ::Int64, ::CUDAdrv.CuStream, ::typeof(myf), ::Int64) at /home/tshort/.julia/v0.7/CUDAnative/src/execution.jl:80
@maleadt
Copy link
Member

maleadt commented Nov 6, 2017

Sorry for the delayed response, I've been extremely busy.

This is due to recursion in sum, which is (currently) incompatible with CUDAnative's JIT because Base doesn't support multiple compilation caches. As a result, we compile with cached=false breaking recursion:

f = sum
tt = Tuple{Vector{Int}}
# works equally well with f(x) = f(x)

params = Base.CodegenParams(cached=false)
Base._dump_function(f, tt,
                    #=native=#false, #=wrapper=#false, #=strip=#false,
                    #=dump_module=#true, #=syntax=#:att, #=optimize=#false,
                    params)

# ERROR: StackOverflowError

A pure code generator, not relying on global state (ie. the cache we disable) should fix this, and @vtjnash has been slowly working towards this.

@maleadt maleadt changed the title Stack overflow on some code Uncached JIT breaks recursion Nov 6, 2017
@tshort
Copy link
Author

tshort commented Nov 6, 2017

Thanks, Tim. As a tangent, I've been hacking together my own version of code generation using your great LLVM package:

https://github.com/tshort/CodeGen.jl

It'll compile basic stuff right now, but there are plenty of holes (the tests in the package should give you some idea of what works). I'm aiming for static compilation (Emscripten), but this might also be of interest for GPU code generation.

@maleadt
Copy link
Member

maleadt commented Nov 11, 2017

Sweet! I recall @SimonDanisch starting something similar at https://github.com/SimonDanisch/StaticJulia.jl but yours looks much more advanced already. I'm afraid you'll quickly bump into limitations of the LLVM C API though, but do know that's why we have the entire llvm-extra annoyance (ie. making LLVM.jl hard to install), making it possible to expose additional C++ API functionality to C and Julia.

@tshort
Copy link
Author

tshort commented Nov 13, 2017

Thanks for the link. I wish I'd seen Simon's StaticJulia earlier.

@maleadt
Copy link
Member

maleadt commented May 12, 2020

This is fixed :-)

@maleadt maleadt closed this as completed May 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants