Skip to content

Commit 86473fc

Browse files
authored
fix: MIOpen only supports till dimension 5 (#601)
1 parent ddfe49b commit 86473fc

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

ext/NNlibAMDGPUExt/activations.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
for (f, op) in [
2-
NNlib.relu => MIOpen.relu,
3-
NNlib.relu6 => x -> MIOpen.clippedrelu(x, 6),
4-
NNlib.softplus => MIOpen.softrelu,
5-
NNlib.σ => MIOpen.sigmoid,
6-
Base.tanh => MIOpen.tanh,
7-
# TODO define for leakyrelu, elu, etc.?
8-
]
2+
NNlib.relu => MIOpen.relu,
3+
NNlib.relu6 => x -> MIOpen.clippedrelu(x, 6),
4+
NNlib.softplus => MIOpen.softrelu,
5+
NNlib.σ => MIOpen.sigmoid,
6+
Base.tanh => MIOpen.tanh,
7+
# TODO define for leakyrelu, elu, etc.?
8+
], N in 1:5
99
@eval function Base.materialize(
10-
bc::Broadcast.Broadcasted{<:Any,<:Any,typeof($f),<:Tuple{ROCArray{<:MIOPENFloat}}}
10+
bc::Broadcast.Broadcasted{<:Any,<:Any,typeof($f),<:Tuple{ROCArray{<:MIOPENFloat,$N}}}
1111
)
1212
return $op(bc.args[1])
1313
end

test/ext_amdgpu/activations.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
@testset "Compare CPU & GPU" begin
2-
for (T, atol) in ((Float16, 1f-2), (Float32, 1f-5))
3-
x = randn(T, 16)
4-
gputest(x -> NNlib.relu.(x), x; atol)
5-
gputest(x -> NNlib.relu6.(x), x; atol)
6-
gputest(x -> NNlib.softplus.(x), x; atol)
7-
gputest(x -> tanh.(x), x; atol)
8-
gputest(x -> identity.(x), x; atol)
2+
for (T, atol) in ((Float16, 1.0f-2), (Float32, 1.0f-5))
3+
@testset "ndims: $(ndims(x))" for x in (randn(T, 16), randn(T, ntuple(_ -> 2, 5)...), randn(T, ntuple(_ -> 2, 6)...))
4+
gputest(x -> NNlib.relu.(x), x; atol)
5+
gputest(x -> NNlib.relu6.(x), x; atol)
6+
gputest(x -> NNlib.softplus.(x), x; atol)
7+
gputest(x -> tanh.(x), x; atol)
8+
gputest(x -> identity.(x), x; atol)
9+
end
910
end
1011
end

0 commit comments

Comments
 (0)