Skip to content
This repository has been archived by the owner on Mar 12, 2021. It is now read-only.

Serial mapreduce kernel broken on -g2 #418

Closed
maleadt opened this issue Sep 17, 2019 · 1 comment
Closed

Serial mapreduce kernel broken on -g2 #418

maleadt opened this issue Sep 17, 2019 · 1 comment
Labels

Comments

@maleadt
Copy link
Member

maleadt commented Sep 17, 2019

This makes me sad.

julia> a = ones(2,2)
2×2 Array{Float64,2}:
 1.0  1.0
 1.0  1.0

julia> da = CuArray(a)
2×2 CuArray{Float64,2}:
 1.0  1.0
 1.0  1.0

julia> a = Base.mapreduce(identity, +, a, dims=2)
2×1 Array{Float64,2}:
 2.0
 2.0

julia> da = Base.mapreduce(identity, +, da, dims=2)
blk = 1
thr = 2
f = identity
op = +
R = [0.0; 0.0]
A = [1.0 1.0; 1.0 1.0]
range = (nothing, Base.OneTo(2))
R = [0.0; 0.0]
2×1 CuArray{Float64,2}:
 0.0
 0.0

Adding the following side effect-free statement (expanded from (I...)[1]) to the kernel "fixes" the issue:

--- a/src/mapreduce.jl
+++ b/src/mapreduce.jl
@@ -3,6 +3,7 @@ using CuArrays: @cuindex, cudims
 function mapreducedim_kernel_serial(f, op, R, A, range)
     I = @cuindex R
     newrange = map((r, i) -> r === nothing ? i : r, range, I)
+    @inbounds ((Tuple(CartesianIndices(R)[(blockIdx().x-1) * blockDim().x + threadIdx().x]))...)[1]
     for I′ in CartesianIndices(newrange)
         @inbounds R[I...] = op(R[I...], f(A[I′]))
     end

IR is minimally different:

   %.fca.1.extract7 = extractvalue { [2 x i64], i64 } %0, 1
   %.fca.0.0.extract2 = extractvalue { [2 x i64], i64 } %1, 0, 0
   %.fca.1.extract = extractvalue { [2 x i64], i64 } %1, 1
-  %30 = add i64 %.in, 1
-  %31 = mul i64 %.pn101, %18
-  %32 = add i64 %31, %.in
+  %28 = add nsw i64 %14, -1
+  %29 = sdiv i64 %28, %.fca.0.0.extract5
+  %30 = mul i64 %29, %18
+  %31 = sub i64 %28, %30
+  %32 = add i64 %31, 1
   %33 = inttoptr i64 %.fca.1.extract7 to double*
@maleadt maleadt added the bug label Sep 17, 2019
@maleadt
Copy link
Member Author

maleadt commented Jan 30, 2020

Serial mapreduce kernel has been removed. Looking into adding a CI job on debug: #578

@maleadt maleadt closed this as completed Jan 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant