Skip to content

Commit 5462b74

Browse files
authored
Merge pull request #206 from ChrisRackauckas/mapreduce
fix non-deterministic mapreduce compilation error and inbounds
2 parents e9725f8 + 4756a38 commit 5462b74

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/mapreduce.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ function Base._mapreducedim!(f, op, R::GPUArray, A::GPUSrcArray)
123123
return R
124124
end
125125

126-
simple_broadcast_index(A::AbstractArray, i) = A[i]
127-
simple_broadcast_index(x, i) = x
126+
@inline simple_broadcast_index(A::AbstractArray, i...) = @inbounds A[i...]
127+
@inline simple_broadcast_index(x, i...) = x
128128

129129
for i = 0:10
130130
args = ntuple(x-> Symbol("arg_", x), i)
@@ -138,19 +138,19 @@ for i = 0:10
138138
# # Loop sequentially over chunks of input vector
139139
# HACK: length(A) and axes(A) aren't GPU compatible, so pass them instead
140140
# https://github.com/JuliaGPU/CUDAnative.jl/issues/367
141-
while global_index <= len
141+
@inbounds while global_index <= len
142142
cartesian_global_index = Tuple(CartesianIndices(ax)[global_index])
143143
@inbounds element = f(A[cartesian_global_index...], $(fargs...))
144144
acc = op(acc, element)
145145
global_index += global_size(state)
146146
end
147147
# Perform parallel reduction
148148
local_index = threadidx_x(state) - 1
149-
tmp_local[local_index + 1] = acc
149+
@inbounds tmp_local[local_index + 1] = acc
150150
synchronize_threads(state)
151151

152152
offset = blockdim_x(state) ÷ 2
153-
while offset > 0
153+
@inbounds while offset > 0
154154
if (local_index < offset)
155155
other = tmp_local[local_index + offset + 1]
156156
mine = tmp_local[local_index + 1]
@@ -160,7 +160,7 @@ for i = 0:10
160160
offset = offset ÷ 2
161161
end
162162
if local_index == 0
163-
result[blockidx_x(state)] = tmp_local[1]
163+
@inbounds result[blockidx_x(state)] = tmp_local[1]
164164
end
165165
return
166166
end

0 commit comments

Comments
 (0)