Skip to content

Commit ce3572e

Browse files
Merge pull request #51 from ChrisRackauckas-Claude/cc/cache-inactive-type
Declare cache-storage types as Enzyme inactive
2 parents 4c927d3 + 323c05a commit ce3572e

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "FunctionWrappersWrappers"
22
uuid = "77dc65aa-8811-40c2-897b-53d922fa7daf"
33
authors = ["Chris Elrod <elrodc@gmail.com> and contributors"]
4-
version = "1.9.0"
4+
version = "1.9.1"
55

66
[deps]
77
FunctionWrappers = "069b7b12-0de2-55c6-9aab-29f3d0a68a2e"

ext/FunctionWrappersWrappersEnzymeExt.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
module FunctionWrappersWrappersEnzymeExt
22

33
using FunctionWrappersWrappers
4+
using FunctionWrappersWrappers: SingleCacheStorage, DictCacheStorage, NoCacheStorage
45
using Enzyme
56
using EnzymeCore
67
using EnzymeCore.EnzymeRules
78

9+
# =============================================================================
10+
# Mark cache-storage types as inactive
11+
# =============================================================================
12+
# `SingleCacheStorage` and `DictCacheStorage` are mutable / contain a `Dict`,
13+
# and their cache-miss branches write to that storage. Without these
14+
# declarations Enzyme conservatively treats any closure that *might* touch a
15+
# `FunctionWrappersWrapper` (e.g. via `remake(prob; p = …)` capturing the
16+
# problem in scope) as potentially writing to the wrapper's cache, and
17+
# refuses to prove the captured argument read-only. The cache values are
18+
# `FunctionWrapper`s used purely for dispatch / dynamic call speedup; they
19+
# never hold derivative data.
20+
EnzymeCore.EnzymeRules.inactive_type(::Type{<:SingleCacheStorage}) = true
21+
EnzymeCore.EnzymeRules.inactive_type(::Type{<:DictCacheStorage}) = true
22+
EnzymeCore.EnzymeRules.inactive_type(::Type{NoCacheStorage}) = true
23+
824
# =============================================================================
925
# Helper: build a Forward mode from FwdConfig flags
1026
# =============================================================================

0 commit comments

Comments
 (0)