Skip to content

Commit 369cebc

Browse files
authored
add new test for issue 543 (#562)
* add new test for issue 543 * update tests
1 parent 58992c9 commit 369cebc

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

test/staticsize.jl

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,71 @@ end
135135
@test sum2_10turbo(A) sum(A)
136136
end
137137
end
138+
139+
# Test for Issue #543: W=1 nested VecUnroll store on ARM
140+
# This tests the case where vector width is 1 (scalar) with nested unrolling
141+
function issue543_noavx!(data_out, matrix, data_in)
142+
for j in axes(data_out, 3), i in axes(data_out, 2), v in axes(data_out, 1)
143+
res = zero(eltype(data_out))
144+
for jj in axes(matrix, 2)
145+
res += matrix[j, jj] * data_in[v, i, jj]
146+
end
147+
data_out[v, i, j] = res
148+
end
149+
return nothing
150+
end
151+
152+
function issue543_turbo!(data_out, matrix, data_in)
153+
@turbo for j in axes(data_out, 3), i in axes(data_out, 2), v in axes(data_out, 1)
154+
res = zero(eltype(data_out))
155+
for jj in axes(matrix, 2)
156+
res += matrix[j, jj] * data_in[v, i, jj]
157+
end
158+
data_out[v, i, j] = res
159+
end
160+
return nothing
161+
end
162+
163+
@testset "Issue #543: W=1 Nested VecUnroll" begin
164+
# Test with static first dimension
165+
for v in 1:4, n in 2:8
166+
data_out_ref = StrideArray(undef, StaticInt(v), StaticInt(n), StaticInt(n))
167+
data_out_turbo = StrideArray(undef, StaticInt(v), StaticInt(n), StaticInt(n))
168+
matrix = StrideArray(undef, StaticInt(n), StaticInt(n))
169+
data_in = rand(v, n, n)
170+
171+
matrix .= rand.()
172+
173+
fill!(data_out_ref, 0.0)
174+
fill!(data_out_turbo, 0.0)
175+
176+
issue543_noavx!(data_out_ref, matrix, data_in)
177+
178+
# This is broken on Apple ARM CPUs (Apple M series) for some reason.
179+
# TODO: Fix the underlying issue!
180+
if (v == 1) && Sys.isapple() && Sys.ARCH == :aarch64
181+
@test_skip issue543_turbo!(data_out_turbo, matrix, data_in)
182+
else
183+
@test_nowarn issue543_turbo!(data_out_turbo, matrix, data_in)
184+
@test data_out_turbo data_out_ref
185+
end
186+
end
187+
188+
# Test with non-static first but static other dimensions
189+
for v in 1:4, n in 2:8
190+
data_out_ref = StrideArray(undef, v, StaticInt(n), StaticInt(n))
191+
data_out_turbo = StrideArray(undef, v, StaticInt(n), StaticInt(n))
192+
matrix = StrideArray(undef, StaticInt(n), StaticInt(n))
193+
data_in = rand(v, n, n)
194+
195+
matrix .= rand.()
196+
197+
fill!(data_out_ref, 0.0)
198+
fill!(data_out_turbo, 0.0)
199+
200+
issue543_noavx!(data_out_ref, matrix, data_in)
201+
issue543_turbo!(data_out_turbo, matrix, data_in)
202+
203+
@test data_out_turbo data_out_ref
204+
end
205+
end

0 commit comments

Comments
 (0)