Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate if we need a custom hash for EnzymeCompilerParams #1182

Open
vchuravy opened this issue Dec 4, 2023 · 0 comments
Open

Investigate if we need a custom hash for EnzymeCompilerParams #1182

vchuravy opened this issue Dec 4, 2023 · 0 comments

Comments

@vchuravy
Copy link
Member

vchuravy commented Dec 4, 2023

GPUCompiler hashes CompilerConfig which contains the CompilerParams and uses that as a key for the global dictionary that splits the global inference cache in https://github.com/JuliaGPU/GPUCompiler.jl/blob/21ca075c1e91fe0c15f1330ab487b4831013ec1f/src/jlgen.jl#L175

struct EnzymeCompilerParams <: AbstractEnzymeCompilerParams

julia> using Enzyme, GPUCompiler

julia> f1(x) = x*x
       # Returns a tuple of active returns, which in this case is simply (2.0,)
f1 (generic function with 1 method)

julia> @test first(autodiff(Reverse, f1, Active(1.0))[1]) ≈ 2.0
ERROR: LoadError: UndefVarError: `@test` not defined
in expression starting at REPL[6]:1

julia> autodiff(Reverse, f1, Active(1.0))
((2.0,),)

julia> autodiff(Reverse, f1, Const(1.0))
((nothing,),)

julia> GPUCompiler.GLOBAL_CI_CACHES
Dict{CompilerConfig, GPUCompiler.CodeCache} with 5 entries:
  CompilerConfig for EnzymeTarget         => CodeCache(IdDict{MethodInstance, Vector{CodeInstance}}())
  CompilerConfig for EnzymeTarget         => CodeCache(IdDict{MethodInstance, Vector{CodeInstance}}())
  CompilerConfig for EnzymeTarget         => CodeCache(IdDict{MethodInstance, Vector{CodeInstance}}(MethodInstance for *(::Float64, ::Float64)=>[CodeInstance(MethodInstance for *(::Float64, ::Float64), #undef, 0x0000000000000001, 0xffffffffffffffff, Float64, #undef, "\x01\0\n\0\x03\0\0\0\0\b\b\x16\x88\xc2\xe6.\x1e\x…
  CompilerConfig for NativeCompilerTarget => CodeCache(IdDict{MethodInstance, Vector{CodeInstance}}(MethodInstance for *(::Float64, ::Float64)=>[CodeInstance(MethodInstance for *(::Float64, ::Float64), #undef, 0x0000000000000001, 0xffffffffffffffff, Float64, #undef, "\x01\0\n\0\x03\0\0\0\0\b\b\x16\x88\xc2\xe6.\x1e\x…
  CompilerConfig for EnzymeTarget         => CodeCache(IdDict{MethodInstance, Vector{CodeInstance}}(MethodInstance for *(::Float64, ::Float64)=>[CodeInstance(MethodInstance for *(::Float64, ::Float64), #undef, 0x0000000000000001, 0xffffffffffffffff, Float64, #undef, "\x01\0\n\0\x03\0\0\0\0\b\b\x16\x88\xc2\xe6.\x1e\x…

julia> 

So inference unnecessarily repeats work. We need to carefully define what we need to split the cache on. cc: @maleadt

Especially for JuliaGPU/GPUCompiler.jl#534 / JuliaLang/julia#52233

I think we should probably define a AbstractCacheKey and construct that from the compiler params, requiring downstream users to make those conscious choices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant