Skip to content

Accidentally calling GPU intrinsics on the host causes segfaults #60

Description

@Keno
CUDA_VISIBLE_DEVICES=3 julia --project=..
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.0.3 (2018-12-18)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using CUDAnative

julia> f(x) = CUDAnative.tanh(x)
f (generic function with 1 method)

julia> @code_typed f(1f0)
CodeInfo(
1 1 ─ %1 = Base.llvmcall::IntrinsicFunction                                                                                              │╻╷ tanh
  │   %2 = (%1)(("declare float @__nv_tanhf(float)", "%2 =  call float @__nv_tanhf(float %0)\nret float %2"), Float32, Tuple{Float32}, x)::Float32o expansion
  └──      return %2                                                                                                                     │
) => Float32

julia> f(1f0)

signal (11): Segmentation fault
in expression starting at no file:0
_ITM_registerTMCloneTable at /opt/julia/julia-1.0.3/bin/../lib/julia/libspqr.so (unknown line)
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2184
eval_user_input at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/REPL/src/REPL.jl:82
macro expansion at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/REPL/src/REPL.jl:117 [inlined]
JuliaGPU/CUDAnative.jl#28 at ./task.jl:259
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2184
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1537 [inlined]
start_task at /buildworker/worker/package_linux64/build/src/task.c:268
unknown function (ip: 0xffffffffffffffff)
Allocations: 4184659 (Pool: 4183753; Big: 906); GC: 8
Segmentation fault (core dumped)

My suggestion would be to

  1. Switch this to ccall with llvmcall calling convention
  2. Add an llvmcall_gpu calling convention that emits an error when somebody tries to compile it for a host backend.

cc @maleadt

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcuda kernelsStuff about writing CUDA kernels.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions