JuliaGPU / GPUCompiler.jl

Reusable compiler infrastructure for Julia GPU backends.
Other
157 stars 50 forks source link

Method overrides cannot override kernels #208

Open maleadt opened 3 years ago

maleadt commented 3 years ago
julia> kernel() = 0
kernel (generic function with 1 method)

julia> GPUCompiler.@override method_table kernel() = 1

julia> native_code_llvm(kernel, Tuple{})
;  @ REPL[1]:1 within `kernel`
; Function Attrs: alwaysinline
define i64 @julia_kernel_683() local_unnamed_addr #0 {
top:
  ret i64 0
}

The reason for this is that we implement Core.Compiler.method_table(interp::GPUInterpreter, sv::InferenceState), whereas for the outermost function Core.Compiler.method_table(interp::GPUInterpreter) seem to be called. But we can't implement that method, because that breaks InferenceState construction:

ERROR: LoadError: MethodError: no method matching convert(::Type{Core.Compiler.CachedMethodTable{Core.Compiler.InternalMethodTable}}, ::Core.Compiler.CachedMethodTable{Core.Compiler.OverlayMethodTable})
Closest candidates are:
  convert(::Type{Union{}}, ::Any) at essentials.jl:216
  convert(::Type{Any}, ::Any) at essentials.jl:217
  convert(::Type{T}, ::T) where T at essentials.jl:218
Stacktrace:
  [1] Core.Compiler.InferenceState(result::Core.Compiler.InferenceResult, src::Core.CodeInfo, cached::Bool, interp::GPUCompiler.GPUInterpreter)
    @ Core.Compiler ./compiler/inferencestate.jl:106
maleadt commented 3 years ago

This also doesn't work with the 1.6 world age-based overlay table, but for different reasons.

vchuravy commented 3 years ago

Note that you can hook that InferenceState constructor.