Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Views with repeating indices lead to different results than Base.Array #89

Open
clintonTE opened this issue Apr 17, 2020 · 2 comments
Open
Labels
bug Something isn't working cuda array Stuff about CuArray.

Comments

@clintonTE
Copy link
Contributor

Describe the bug
Views don't play well with assignments, leading to silent errors.

To Reproduce
The Minimal Working Example (MWE) for this bug:

using Revise, CuArrays, Flux
function cusubmwe(N)
  v = ones(Float32, N)
  vgpu = v|> gpu

  indices = (i->(i-1)%N + 1).(1:N^2)
  subv = view(v, indices)
  subvgpu = view(vgpu, indices)

  subv .+= 1
  subvgpu .+= 1

  @info "indices: $indices"
  @info "cpu: $(v)"
  @info "gpu: $(vgpu)"

end

Output:

[ Info: indices: [1, 2, 3, 1, 2, 3, 1, 2, 3]
[ Info: cpu: Float32[4.0, 4.0, 4.0]
[ Info: gpu: Float32[2.0, 2.0, 2.0]

Expected behavior
The cpu version provides a baseline.

Build log

   Building WebIO ──→ `C:\Users\Clinton\.julia\packages\WebIO\2mZPb\deps\build.log`
   Building NNlib ──→ `C:\Users\Clinton\.julia\packages\NNlib\FAI3o\deps\build.log`
   Building Libtask → `C:\Users\Clinton\.julia\packages\Libtask\GQPaW\deps\build.log`
   Building CMake ──→ `C:\Users\Clinton\.julia\packages\CMake\ULbyn\deps\build.log`
   Building NLopt ──→ `C:\Users\Clinton\.julia\packages\NLopt\eqN9a\deps\build.log`

Environment details (please complete this section)
Details on Julia:

Commit b8e9a9ecc6 (2020-03-21 16:36 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, skylake)
Environment:
  JULIA_EDITOR = "C:\Users\Clinton\AppData\Local\atom\app-1.45.0\atom.exe"  -a
  JULIA_NUM_THREADS = 6

Julia packages:
CuArrays v2.0.1 #master (https://github.com/JuliaGPU/CuArrays.jl.git)
GPUArrays v3.1.0 #master (https://github.com/JuliaGPU/GPUArrays.jl.git)
CUDAnative v3.0.4
Flux v0.10.4 #master (https://github.com/FluxML/Flux.jl.git)

CUDA: toolkit and driver version
10.2 / 441.66

Additional context
This came up in the context of FluxML/Zygote.jl#600, but I am basing the mwe on an example from Michael Abbott from Slack (https://julialang.slack.com/archives/C6G240ENA/p1587070650391500).

I think this is the reason I was having difficulties with Zygote AD on views of CuArrays as mentioned in that issue, though I don't know for sure.

@clintonTE clintonTE changed the title Silent errors for sub-array computation Computation involving sub-arrays silently leads to incorrect values Apr 17, 2020
@maleadt maleadt transferred this issue from JuliaGPU/CuArrays.jl May 27, 2020
@maleadt maleadt added bug Something isn't working cuda array Stuff about CuArray. labels May 27, 2020
@CarloLucibello
Copy link
Contributor

Any hint on how to fix this?

@maleadt
Copy link
Member

maleadt commented Mar 25, 2021

Views with repeating indices cannot be realistically supported without serializing the computation and losing all benefit of the GPU.

@maleadt maleadt changed the title Computation involving sub-arrays silently leads to incorrect values Views with repeating indices lead to different results than Base.Array Mar 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cuda array Stuff about CuArray.
Projects
None yet
Development

No branches or pull requests

3 participants