Skip to content

Commit

Permalink
fix: remove inlining of sigmoid_fast pre 1.11- (#597)
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal authored Jul 16, 2024
1 parent a4111c1 commit 1ede301
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/activations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,10 @@ julia> hardσ(0.2f0)
0.53333336f0
```
"""
@inline function sigmoid_fast(x::Real)
function sigmoid_fast(x::Real)
@static if VERSION v"1.11-"
@inline
end
t = @fastmath exp(-abs(x))
y = ifelse(x 0, inv(1 + t), t / (1 + t))
ifelse(x > 40, one(y), ifelse(x < -80, zero(y), y))
Expand Down
10 changes: 10 additions & 0 deletions test/ext_cuda/activations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,13 @@ end
@test Array(y) == [tanh(1f0)]
@test Array(x) == [tanh(tanh(1f0))]
end

@testset "fused act addition broadcast" begin
x = CUDA.rand(Float32, 10, 10)
b = CUDA.rand(Float32, 10)

for act in getfield.((NNlib,), NNlib.ACTIVATIONS)
fused_act_add = act +
@test fused_act_add.(x, b) act.(x .+ b)
end
end

0 comments on commit 1ede301

Please sign in to comment.