From bd1cca0520e7508860be22adf522c8d9739a47b8 Mon Sep 17 00:00:00 2001 From: Daniel Wennberg Date: Sun, 29 Sep 2024 21:51:34 -0700 Subject: [PATCH] Remove Box/Ref methods, redundant in current impl Could be relevant if redesigned to hit a fastpath for const content like make_zero! had; especially relevant for Box, which is not parameterized --- src/make_zero.jl | 73 +----------------------------------------------- 1 file changed, 1 insertion(+), 72 deletions(-) diff --git a/src/make_zero.jl b/src/make_zero.jl index 5e61e00049..3634f6e2cd 100644 --- a/src/make_zero.jl +++ b/src/make_zero.jl @@ -77,20 +77,6 @@ end return y end -@inline function _recursive_map( - ::Type{Core.Box}, f::F, seen::IdDict, xs::NTuple{N,Core.Box}, args... -) where {F,N} - if haskey(seen, xs) - return seen[xs]::Core.Box - end - xcontents = ntuple(j -> xs[j].contents, N) - ST = Core.Typeof(first(xcontents)) - res = Core.Box() - seen[xs] = res - res.contents = Base.Ref(recursive_map(ST, f, seen, xcontents, args...)) - return res -end - @inline function _recursive_map( ::Type{RT}, f::F, seen::IdDict, xs::NTuple{N,RT}, args... ) where {RT,F,N} @@ -199,22 +185,6 @@ end return newy end -@inline function EnzymeCore.make_zero!(prev::Base.RefValue{T}) where {T<:_RealOrComplexFloat} - prev[] = zero(T) - return nothing -end - -@inline function EnzymeCore.make_zero!( - prev::Base.RefValue{T}, seen::Base.IdSet, -) where {T<:_RealOrComplexFloat} - if prev in seen - return nothing - end - push!(seen, prev) - EnzymeCore.make_zero!(prev) - return nothing -end - @inline function EnzymeCore.make_zero!(prev::Array{T,N}) where {T<:_RealOrComplexFloat,N} fill!(prev, zero(T)) return nothing @@ -232,13 +202,8 @@ end end @inline function EnzymeCore.make_zero!(prev, seen::Base.IdSet=Base.IdSet()) - LeafType = Union{ - _RealOrComplexFloat, - Base.RefValue{<:_RealOrComplexFloat}, - Array{<:_RealOrComplexFloat}, - } isleaftype(_) = false - isleaftype(::Type{<:LeafType}) = true + isleaftype(::Type{<:Union{_RealOrComplexFloat,Array{<:_RealOrComplexFloat}}}) = true f(p) = make_zero(p) function f(pout::T, pin::T) where {T} @assert pout === pin @@ -291,42 +256,6 @@ end return nothing end -@inline function _recursive_map!( - f::F, y::Base.RefValue{T}, seen, xs::NTuple{N,Base.RefValue{T}}, isleaftype -) where {F,T,N} - if y in seen - return nothing - end - push!(seen, y) - yvalue = y[] - xvalues = ntuple(j -> xs[j][], N) - SBT = Core.Typeof(yvalue) - if active_reg_inner(SBT, (), nothing, Val(true)) == ActiveState #=justActive=# - y[] = recursive_map_immutable!(f, yvalue, seen, xvalues, isleaftype) - else - recursive_map!(f, yvalue, seen, xvalues, isleaftype) - end - return nothing -end - -@inline function _recursive_map!( - f::F, y::Core.Box, seen, xs::NTuple{N,Core.Box}, isleaftype -) where {F,N} - if y in seen - return nothing - end - push!(seen, y) - ycontents = y.contents - xcontents = ntuple(j -> xs[j].contents, N) - SBT = Core.Typeof(ycontents) - if active_reg_inner(SBT, (), nothing, Val(true)) == ActiveState #=justActive=# - y.contents = recursive_map_immutable!(f, ycontents, seen, xcontents, isleaftype) - else - recursive_map!(f, ycontents, seen, xcontents, isleaftype) - end - return nothing -end - @inline function _recursive_map!( f::F, y::T, seen, xs::NTuple{N,T}, isleaftype ) where {F,T,N}