-
-
Notifications
You must be signed in to change notification settings - Fork 83
mapreduce
(sum
, prod
, etc.) fail in some cases when given a dims
argument.
#583
Comments
Couple of issues here. First of all, you're executing CPU code (cos, sin, etc) on the GPU. With broadcast, we try to substitute CPU functions for their GPU counterparts; this isn't as easy for mapreduce. Furthermore, it works for some arrays because GPUArrays falls back to a CPU reduction when dealing with small data: https://github.com/JuliaGPU/GPUArrays.jl/blob/02b3fb82f06c741c7542e331022463683c01c6f5/src/host/mapreduce.jl#L171-L174 julia> x = cu(rand(3,3));
julia> sum(cos, x)
8.2665415f0
julia> x = cu(rand(300,300));
julia> sum(cos, x)
┌ Warning: calls to Base intrinsics might be GPU incompatible
│ exception =
│ You called cos(x::T) where T<:Union{Float32, Float64} in Base.Math at special/trig.jl:100, maybe you intended to call cos(x::Float32) in CUDAnative at /home/tim/Julia/pkg/CUDAnative/src/device/cuda/math.jl:6 instead?
│ Stacktrace:
│ [1] cos at special/trig.jl:100
│ [2] reduce_kernel at /home/tim/Julia/pkg/GPUArrays/src/host/mapreduce.jl:134
└ @ CUDAnative ~/Julia/pkg/CUDAnative/src/compiler/irgen.jl:111 On recent versions of Julia some of these math functions are implemented in Julia, and will result in normal output. However, switching to using |
I see... A (sub-optimal) fix could maybe be to include a fallback like
? Although allocating an intermediate array, at least it would work... |
I'm hoping JuliaGPU/CUDAnative.jl#334 will land sometime soon and we won't have to deal with that. The workaround (from user code, without a fallback in CuArrays) should work for you now already? |
Yeah, sure. The question was more about whether this should be included in |
PR linked above fixes most of these issues: you can now safely reduce using |
Great! Thanks a lot! |
I finally got some time for a closer look at this again, and I'm afraid you should reopen the issue, @maleadt. While reduction over the entire CuArray works:
reduction over only one dimension makes Julia crash:
(after which Julia freezes) Current package status: (v1.3) pkg> st CuArrays
Status `~/.julia/environments/v1.3/Project.toml`
[79e6a3ab] Adapt v1.0.1
[fa961155] CEnum v0.2.0
[3895d2a7] CUDAapi v3.1.0
[c5f51814] CUDAdrv v6.0.0
[be33ccc6] CUDAnative v2.10.2
[3a865a2d] CuArrays v1.7.3
[864edb3b] DataStructures v0.17.10
[0c68f7d7] GPUArrays v2.0.1
[1914dd2f] MacroTools v0.5.4
[872c559c] NNlib v0.6.6 |
These fixes are not part of a release yet. |
Ah. My mistake. Sorry. Never mind, then. |
Describe the bug
mapreduce(f, op, A...; dims = dims)
and friends (sum(f, A; dims = dims)
,prod(f, A; dims = dims)
...) fail for many (but not all) functionsf
when adims ≠ :
argument is given.To Reproduce
The Minimal Working Example (MWE) for this bug:
Environment details
Details on Julia:
Julia packages:
CUDA: toolkit and driver version
The text was updated successfully, but these errors were encountered: