-
Notifications
You must be signed in to change notification settings - Fork 72
Updating LoopVectorization for 1.12 #557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
9edd0de
971f309
4befd36
6ce5e10
f11c21a
4fd0f3d
c46223c
f07def8
d6e39b1
7671a4f
db7af8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,5 +30,3 @@ Pages = [ | |
] | ||
Depth = 1 | ||
``` | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,14 +1,14 @@ | ||||||||||||||||||||||||||
module ForwardDiffExt | ||||||||||||||||||||||||||
import ForwardDiff, ChainRulesCore | ||||||||||||||||||||||||||
using LoopVectorization, VectorizationBase, SLEEFPirates, ForwardDiff | ||||||||||||||||||||||||||
using LoopVectorization, VectorizationBase, SLEEFPirates, ForwardDiff, NNlib | ||||||||||||||||||||||||||
using SLEEFPirates: tanh_fast, sigmoid_fast | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
import IfElse: ifelse | ||||||||||||||||||||||||||
using VectorizationBase: AbstractSIMD, AbstractMask, zero_offsets | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
using LoopVectorization: | ||||||||||||||||||||||||||
AbstractSIMD, | ||||||||||||||||||||||||||
AbstractStridedPointer, | ||||||||||||||||||||||||||
relu, | ||||||||||||||||||||||||||
vmap, | ||||||||||||||||||||||||||
VectorizationBase, | ||||||||||||||||||||||||||
vmapt, | ||||||||||||||||||||||||||
|
@@ -140,7 +140,8 @@ end | |||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||
@generated function VectorizationBase.relu( | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
@generated function NNlib.relu( | ||||||||||||||||||||||||||
x::ForwardDiff.Dual{T,S,N} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
) where {T,S,N} | ||||||||||||||||||||||||||
quote | ||||||||||||||||||||||||||
|
@@ -157,6 +158,27 @@ end | |||||||||||||||||||||||||
end | ||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
@generated function NNlib.leakyrelu( | ||||||||||||||||||||||||||
x::ForwardDiff.Dual{T,S,N}, | ||||||||||||||||||||||||||
|
@inline function NNlib.leakyrelu( | |
x::LoopVectorization.AbstractSIMD, | |
a = NNlib.oftf(x, NNlib.leakyrelu_a), | |
) | |
LoopVectorization.ifelse(x > zero(x), float(x), NNlib.oftf(x, a * x)) # max(a*x, x) is 3x slower | |
end | |
@inline function NNlib.leakyrelu( | |
x::ForwardDiff.Dual{<:Any,<:LoopVectorization.AbstractSIMD}, | |
a = NNlib.oftf(x, NNlib.leakyrelu_a), | |
) | |
LoopVectorization.ifelse(x > zero(x), float(x), NNlib.oftf(x, a * x)) # max(a*x, x) is 3x slower | |
end |
The new ones work for any
S
. This is why the new ones commit type piracy, while the old ones only sort of did (sort of, because LoopVectorization doesn't itself define AbstractSIMD
, but has permission to add methods if needed).
Probably SLEEFPirates is a better place for this, with an NNlib extension.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, should I remove these tests and the new associated functions from the PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, it seems strange that many functions defined in the extension aren't being tested; I can add a new set of tests if that's within scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just make them dispatch on AbstractSIMD again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NNLib should be a separate extension. Not only is this breaking, it also means that it won't properly trigger for most users.