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

Serial mapreduce kernel broken on -g2 #418

@maleadt

Description

@maleadt

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*

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions