GPUCompiler.jl icon indicating copy to clipboard operation
GPUCompiler.jl copied to clipboard

Method overrides cannot override kernels

Open maleadt opened this issue 4 years ago • 3 comments

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 avatar Jun 23 '21 10:06 maleadt

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

maleadt avatar Jun 23 '21 10:06 maleadt

Note that you can hook that InferenceState constructor.

vchuravy avatar Jun 23 '21 16:06 vchuravy