Skip to content

Commit 3571ef0

Browse files
committed
Fix and test transposed offset array access.
1 parent 806e50f commit 3571ef0

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/loopstartstopmanager.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,19 @@ function indices_calculated_by_pointer_offsets(ls::LoopSet, ar::ArrayReferenceMe
6565
out
6666
end
6767

68-
@inline onetozeroindexgephack(sptr::AbstractStridedPointer) = gesp(sptr, (Static{-1}(),)) # go backwords
68+
@generated function set_first_stride(sptr::StridedPointer{T,N,C,B,R}) where {T,N,C,B,R}
69+
minrank = argmin(R)
70+
newC = C > 0 ? (C == minrank ? 1 : 0) : C
71+
newB = C > 0 ? (C == minrank ? B : 0) : B #TODO: confirm correctness
72+
quote
73+
$(Expr(:meta,:inline))
74+
VectorizationBase.StridedPointer{$T,1,$newC,$newB,$(R[minrank],)}(pointer(sptr), (sptr.strd[$minrank],), (Zero(),))
75+
end
76+
end
77+
set_first_stride(x) = x # cross fingers that this works
78+
@inline onetozeroindexgephack(sptr::AbstractStridedPointer) = gesp(set_first_stride(sptr), (Static{-1}(),)) # go backwords
6979
@inline onetozeroindexgephack(sptr::AbstractStridedPointer{T,1}) where {T} = sptr
80+
# @inline onetozeroindexgephack(sptr::StridedPointer{T,1}) where {T} = sptr
7081
@inline onetozeroindexgephack(x) = x
7182

7283
"""

src/reconstruct_loopset.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,11 @@ function add_mref!(
133133
sp = ArrayInterface.rank_to_sortperm(R)
134134
# maybe no change needed? -- optimize common case
135135
column_major = ntuple(identity, N)
136-
if sp === column_major
136+
li = ar.loopedindex;
137+
if sp === column_major || isone(length(li))
137138
return pushvarg!(ls, ar, i, name)
138139
end
139-
li = ar.loopedindex; lic = copy(li);
140+
lic = copy(li);
140141
inds = getindices(ar); indsc = copy(inds);
141142
offsets = ar.ref.offsets; offsetsc = copy(offsets);
142143

test/dot.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ using Test
3030
end
3131
s
3232
end
33+
3334

3435
selfdotq = :(for i eachindex(a)
3536
s += a[i]*a[i]
@@ -51,6 +52,13 @@ using Test
5152
end
5253
s
5354
end
55+
function myselfdotavx_v2(a)
56+
s = zero(eltype(a))
57+
@avx for i 1:length(a)
58+
s += a[i]*a[i]
59+
end
60+
s
61+
end
5462
function myselfdotavx_range(a)
5563
s = zero(eltype(a))
5664
rng = axes(a, 1)
@@ -249,10 +257,17 @@ using Test
249257
@test dot_unroll3avx_inline(a,b) s
250258
s = myselfdot(a)
251259
@test myselfdotavx(a) s
260+
@test myselfdotavx_v2(a) s
252261
@test myselfdotavx_range(a) s
253262
@test myselfdot_avx(a) s
254263
@test myselfdotavx(a) s
255264

265+
A = OffsetArray(rand(37, 61), -5, 10);
266+
s = myselfdot(A);
267+
@test myselfdotavx(A) myselfdotavx(A') s
268+
@test myselfdotavx_v2(A) myselfdotavx_v2(A') s
269+
# @test myselfdot_avx(A) ≈ myselfdot_avx(A') ≈ s
270+
256271
@test dot17(a,b) @view(a[1:17])' * @view(b[1:17])
257272
@test dot33(a,b) @view(a[1:33])' * @view(b[1:33])
258273

0 commit comments

Comments
 (0)