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

Inconsistency of == and isequal for CuArray #1524

Closed
JeffFessler opened this issue May 25, 2022 · 3 comments · Fixed by JuliaGPU/GPUArrays.jl#410
Closed

Inconsistency of == and isequal for CuArray #1524

JeffFessler opened this issue May 25, 2022 · 3 comments · Fixed by JuliaGPU/GPUArrays.jl#410
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@JeffFessler
Copy link

Describe the bug

Inconsistent behavior between == and isequal for CuArray

To reproduce

The Minimal Working Example (MWE) for this bug:

using CUDA: CuArray
import CUDA

CUDA.allowscalar(false)

x = ones(2,3)
y = ones(6)
xc = CuArray(x)
yc = CuArray(y)
@assert !isequal(x, y)
@assert x !== y
@assert !isequal(xc, yc)
@assert xc == yc # huh?
Manifest.toml

CUDA v3.10.0
Julia 1.7.1

Paste your Manifest.toml here, or accurately describe which version of CUDA.jl and its dependencies (GPUArrays.jl, GPUCompiler.jl, LLVM.jl) you are using.

Expected behavior

I expect two arrays of different dimensions to fail both isequal and ==.
Regular arrays have that property, so should CuArrays, right?

Version info

Details on Julia:

Julia Version 1.7.1
Commit ac5cc99908 (2021-12-22 19:35 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Xeon(R) Silver 4214 CPU @ 2.20GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, cascadelake)
Environment:
  JULIA_NUM_THREADS = 48

Details on CUDA:

CUDA toolkit 11.7, artifact installation
NVIDIA driver 510.73.5, for CUDA 11.6
CUDA driver 11.7

Libraries: 
- CUBLAS: 11.10.1
- CURAND: 10.2.10
- CUFFT: 10.7.2
- CUSOLVER: 11.3.5
- CUSPARSE: 11.7.3
- CUPTI: 17.0.0
- NVML: 11.0.0+510.73.5
- CUDNN: 8.30.2 (for CUDA 11.5.0)
- CUTENSOR: 1.4.0 (for CUDA 11.5.0)

Toolchain:
- Julia: 1.7.1
- LLVM: 12.0.1
- PTX ISA support: 3.2, 4.0, 4.1, 4.2, 4.3, 5.0, 6.0, 6.1, 6.3, 6.4, 6.5, 7.0
- Device capability support: sm_35, sm_37, sm_50, sm_52, sm_53, sm_60, sm_61, sm_62, sm_70, sm_72, sm_75, sm_80

4 devices:
  0: Quadro RTX 5000 (sm_75, 12.149 GiB / 16.000 GiB available)
  1: Quadro RTX 5000 (sm_75, 15.745 GiB / 16.000 GiB available)
  2: Quadro RTX 5000 (sm_75, 15.745 GiB / 16.000 GiB available)
  3: Quadro RTX 5000 (sm_75, 15.745 GiB / 16.000 GiB available)

Additional context

I am writing unit tests for another package to make it CUDA compatible
JeffFessler/LinearMapsAA.jl#43

@JeffFessler JeffFessler added the bug Something isn't working label May 25, 2022
@JeffFessler
Copy link
Author

Possibly related to this comment in the code:

# NOTE: we don't implement `isequal` or `hash` in order to fall back to `===` and `objectid`

@maleadt
Copy link
Member

maleadt commented May 26, 2022

That's comparison on contexts, unrelated to arrays.

@maleadt maleadt added the good first issue Good for newcomers label May 26, 2022
@JeffFessler
Copy link
Author

I just realized I can use @which to help determine the source of the difference.
isequal for two CuArrays reverts to the usual isequal for AbstractArrays in Base, which does an axes check as expected:
https://github.com/JuliaLang/julia/blob/742b9abb4dd4621b667ec5bb3434b8b3602f96fd/base/abstractarray.jl#L2525

But == for two CuArrays is calling a method in GPUArrays that uses mapreduce with no axes check:
https://github.com/JuliaGPU/GPUArrays.jl/blob/fc0d327ecc2fd0b3b73427cf6f491591aa096b75/src/host/mapreduce.jl#L88

So this issue really belongs with GPUArrays and is related to JuliaGPU/GPUArrays.jl#405.

After reading the manual more closely, I learned that == and isequal differ for arrays that have missing elements. https://docs.julialang.org/en/v1/base/math/#Base.:==

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants