Skip to content

Commit

Permalink
Use SIMDDualNumbers for forward diff special functions
Browse files Browse the repository at this point in the history
  • Loading branch information
chriselrod committed Oct 6, 2021
1 parent 2758296 commit 7c2b4b1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 31 deletions.
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LoopVectorization"
uuid = "bdcacae8-1622-11e9-2a5c-532679323890"
authors = ["Chris Elrod <[email protected]>"]
version = "0.12.82"
version = "0.12.83"

[deps]
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
Expand All @@ -15,6 +15,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
PolyesterWeave = "1d0040c9-8b98-4ee7-8388-3f51789ca0ad"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
SIMDDualNumbers = "3cdde19b-5bb0-4aaf-8931-af3e248e098b"
SLEEFPirates = "476501e8-09a2-5ece-8869-fb82de89a1fa"
Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
ThreadingUtilities = "8290d209-cae3-49c0-8002-c8c24d57dab5"
Expand All @@ -32,6 +33,7 @@ LayoutPointers = "0.1.2"
OffsetArrays = "1.4.1"
PolyesterWeave = "0.1"
Requires = "1"
SIMDDualNumbers = "0.1"
SLEEFPirates = "0.6.23"
Static = "0.3.3"
ThreadingUtilities = "0.4.5"
Expand Down
30 changes: 1 addition & 29 deletions src/simdfunctionals/vmap_grad_forwarddiff.jl
Original file line number Diff line number Diff line change
@@ -1,34 +1,6 @@
import .ForwardDiff
using SIMDDualNumbers

@generated function SLEEFPirates.tanh_fast(x::ForwardDiff.Dual{T,S,N}) where {T,S,N}
quote
$(Expr(:meta,:inline))
t = tanh_fast(x.value)
∂t = vfnmadd_fast(t, t, one(S))
p = x.partials
ForwardDiff.Dual{T}(t, ForwardDiff.Partials(Base.Cartesian.@ntuple $N n -> mul_fast(∂t, p[n])))
end
end
@generated function SLEEFPirates.sigmoid_fast(x::ForwardDiff.Dual{T,S,N}) where {T,S,N}
quote
$(Expr(:meta,:inline))
s = sigmoid_fast(x.value)
∂s = vfnmadd_fast(s,s,s)
p = x.partials
ForwardDiff.Dual{T}(s, ForwardDiff.Partials(Base.Cartesian.@ntuple $N n -> mul_fast(∂s, p[n])))
end
end
@generated function VectorizationBase.relu(x::ForwardDiff.Dual{T,S,N}) where {T,S,N}
quote
$(Expr(:meta,:inline))
v = x.value
z = zero(v)
cmp = v < z
r = ifelse(cmp, z, v)
p = x.partials
ForwardDiff.Dual{T}(r, ForwardDiff.Partials(Base.Cartesian.@ntuple $N n -> ifelse(cmp, z, p[n])))
end
end
@generated function init_dual(v::Tuple{Vararg{AbstractSIMD,A}}) where {A}
res = Expr(:tuple)
q = Expr(:block, Expr(:meta,:inline))
Expand Down
3 changes: 2 additions & 1 deletion test/grouptests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const START_TIME = time()

@time if LOOPVECTORIZATION_TEST == "all" || LOOPVECTORIZATION_TEST == "part2"
using Aqua
@time Aqua.test_all(LoopVectorization, ambiguities = VERSION v"1.6")
@time Aqua.test_all(LoopVectorization, ambiguities = VERSION v"1.6", stale_deps = false)
@time Aqua.test_stale_deps(LoopVectorization, ignore = [:SIMDDualNumbers])
# @test isempty(detect_unbound_args(LoopVectorization))

@time include("printmethods.jl")
Expand Down

2 comments on commit 7c2b4b1

@chriselrod
Copy link
Member Author

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/46183

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.83 -m "<description of version>" 7c2b4b15490e58ffb9ebd35f94d0838dd98d99d5
git push origin v0.12.83

Please sign in to comment.