Skip to content

Commit 020fd85

Browse files
authored
Add strong zero getters (#2427)
* Add strong zero getters * more * fix * fix * fix * fix * fix * e2 * fixup
1 parent b86f8b0 commit 020fd85

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Enzyme"
22
uuid = "7da242da-08ed-463a-9acd-ee780be4f1d9"
33
authors = ["William Moses <wmoses@mit.edu>", "Valentin Churavy <vchuravy@mit.edu>"]
4-
version = "0.13.47"
4+
version = "0.13.48"
55

66
[deps]
77
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
@@ -39,7 +39,7 @@ EnzymeStaticArraysExt = "StaticArrays"
3939
BFloat16s = "0.2, 0.3, 0.4, 0.5"
4040
CEnum = "0.4, 0.5"
4141
ChainRulesCore = "1"
42-
EnzymeCore = "0.8.10"
42+
EnzymeCore = "0.8.11"
4343
Enzyme_jll = "0.0.181"
4444
GPUArraysCore = "0.1.6, 0.2"
4545
GPUCompiler = "1.3"

lib/EnzymeCore/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "EnzymeCore"
22
uuid = "f151be2c-9106-41f4-ab19-57ee4f262869"
33
authors = ["William Moses <wmoses@mit.edu>", "Valentin Churavy <vchuravy@mit.edu>"]
4-
version = "0.8.10"
4+
version = "0.8.11"
55

66
[compat]
77
Adapt = "3, 4"

lib/EnzymeCore/src/EnzymeCore.jl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ Abstract type for which differentiation mode will be used.
258258
- `ABI`: what runtime [`ABI`](@ref) to use
259259
- `ErrIfFuncWritten`: whether to error when the function differentiated is a closure and written to.
260260
- `RuntimeActivity`: whether to enable runtime activity (default off). Runtime Activity is required is the differentiability of all mutable variables cannot be determined statically. For a deeper explanation see the [FAQ](@ref faq-runtime-activity)
261-
- `StrongZero`: whether to enforce that propagating a zero derivative input always ends up in zero derivative outputs. This is required to avoid nan's if one of the arguments may be infinite or nan. For a deeper explanation see the [FAQ](@ref faq-runtime-activity)
261+
- `StrongZero`: whether to enforce that propagating a zero derivative input always ends up in zero derivative outputs. This is required to avoid nan's if one of the arguments may be infinite or nan. For a deeper explanation see the [FAQ](@ref faq-strong-zero)
262262
263263
!!! warning
264264
The type parameters of `Mode` are not part of the public API and can change without notice.
@@ -271,6 +271,24 @@ Abstract type for which differentiation mode will be used.
271271
"""
272272
abstract type Mode{ABI, ErrIfFuncWritten, RuntimeActivity, StrongZero} end
273273

274+
"""
275+
runtime_activity(::Mode)
276+
strong_zero(::Type{<:Mode})
277+
278+
Returns whether the given mode has runtime activity set. For a deeper explanation of what strong zero is see the [FAQ](@ref faq-runtime-activity)
279+
"""
280+
runtime_activity(::Mode{<:Any, <:Any, RuntimeActivity}) where RuntimeActivity = RuntimeActivity
281+
runtime_activity(::Type{<:Mode{<:Any, <:Any, RuntimeActivity}}) where RuntimeActivity = RuntimeActivity
282+
283+
"""
284+
strong_zero(::Mode)
285+
strong_zero(::Type{<:Mode})
286+
287+
Returns whether the given mode has strong zero set. For a deeper explanation of what strong zero is see the [FAQ](@ref faq-strong-zero)
288+
"""
289+
strong_zero(::Mode{<:Any, <:Any, <:Any, StrongZero}) where StrongZero = StrongZero
290+
strong_zero(::Type{<:Mode{<:Any, <:Any, <:Any, StrongZero}}) where StrongZero = StrongZero
291+
274292
"""
275293
struct ReverseMode{
276294
ReturnPrimal,

lib/EnzymeCore/src/rules.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import EnzymeCore: Annotation, Const, Duplicated, Mode
55
export RevConfig, RevConfigWidth
66
export FwdConfig, FwdConfigWidth
77
export AugmentedReturn
8+
import ..EnzymeCore: needs_primal
89
export needs_primal, needs_shadow, width, overwritten, runtime_activity
910
export primal_type, shadow_type, tape_type
1011

src/Enzyme.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ import EnzymeCore:
5454
clear_strong_zero,
5555
within_autodiff,
5656
WithPrimal,
57-
NoPrimal
57+
NoPrimal,
58+
needs_primal,
59+
runtime_activity,
60+
strong_zero
5861
export Annotation,
5962
Const,
6063
Active,
@@ -75,7 +78,10 @@ export Annotation,
7578
clear_strong_zero,
7679
WithPrimal,
7780
NoPrimal,
78-
within_autodiff
81+
within_autodiff,
82+
needs_primal,
83+
runtime_activity,
84+
strong_zero
7985

8086
import EnzymeCore: BatchDuplicatedFunc
8187
export BatchDuplicatedFunc

0 commit comments

Comments
 (0)