Skip to content

Commit

Permalink
Fix interpreter caches (#1698)
Browse files Browse the repository at this point in the history
* Sdebug alloc inline

* Update Project.toml

* Update Enzyme.jl

* Update compiler.jl

* Update compiler.jl

* Update compiler.jl

* Fix 1.6/1.7
  • Loading branch information
wsmoses authored Aug 4, 2024
1 parent 8a850c7 commit c44bf01
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3361,20 +3361,38 @@ struct EnzymeCacheToken
always_inline
method_table::Core.MethodTable
param_type::Type
mode::API.CDerivativeMode
is_fwd::API.CDerivativeMode
end

GPUCompiler.ci_cache_token(job::CompilerJob{<:Any,<:AbstractEnzymeCompilerParams}) =
EnzymeCacheToken(
typeof(job.config.target), job.config.always_inline, GPUCompiler.method_table(job),
typeof(job.config.params), job.config.params.mode,
typeof(job.config.params), job.config.params.mode == API.DEM_ForwardMode,
)

GPUCompiler.get_interpreter(job::CompilerJob{<:Any,<:AbstractEnzymeCompilerParams}) =
Interpreter.EnzymeInterpreter(GPUCompiler.ci_cache_token(job), GPUCompiler.method_table(job), job.world, job.config.params.mode)
else

# the codeinstance cache to use -- should only be used for the constructor
# Note that the only way the interpreter modifies codegen is either not inlining a fwd mode
# rule or not inlining a rev mode rule. Otherwise, all caches can be re-used.
const GLOBAL_FWD_CACHE = GPUCompiler.CodeCache()
const GLOBAL_REV_CACHE = GPUCompiler.CodeCache()
function enzyme_ci_cache(job::CompilerJob{<:Any,<:AbstractEnzymeCompilerParams})
return if job.config.params.mode == API.DEM_ForwardMode
GLOBAL_FWD_CACHE
else
GLOBAL_REV_CACHE
end
end

@static if VERSION < v"1.8"
GPUCompiler.ci_cache(job::CompilerJob{<:Any,<:AbstractEnzymeCompilerParams}) = enzyme_ci_cache(job)
end

GPUCompiler.get_interpreter(job::CompilerJob{<:Any,<:AbstractEnzymeCompilerParams}) =
Interpreter.EnzymeInterpreter(GPUCompiler.ci_cache(job), GPUCompiler.method_table(job), job.world, job.config.params.mode)
Interpreter.EnzymeInterpreter(enzyme_ci_cache(job), GPUCompiler.method_table(job), job.world, job.config.params.mode)
end

include("compiler/passes.jl")
Expand Down Expand Up @@ -6952,7 +6970,7 @@ end
run_enzyme = false
Const
else
A
A
end

if run_enzyme && !(A2 <: Const) && guaranteed_const_nongen(rrt, World)
Expand Down

2 comments on commit c44bf01

@wsmoses
Copy link
Member Author

@wsmoses wsmoses commented on c44bf01 Aug 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/112393

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.12.27 -m "<description of version>" c44bf01460942f2c94b97fd8b2b93755e1973a32
git push origin v0.12.27

Please sign in to comment.