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

stride_tricks.as_strided and advanced indexing don't play well with each other. #8130

Open
Nordicus opened this issue Jan 23, 2024 · 0 comments · May be fixed by #8150
Open

stride_tricks.as_strided and advanced indexing don't play well with each other. #8130

Nordicus opened this issue Jan 23, 2024 · 0 comments · May be fixed by #8150

Comments

@Nordicus
Copy link
Contributor

Description

The as_strided trick seems to cause some addresses to access invalid memory when using advanced indexing.
The indices must be valid, since the numpy example works, and the basic indexing example works, however the advanced indexing example fails with CUDA_ERROR_ILLEGAL_ADDRESS.
I have used the as_strided version, despite this being an example of the sliding window trick, since I have not yet been able to update to cupy 13 on my system.

To Reproduce

import cupy as cp
import numpy as np
import cupy_backends

if __name__ == '__main__':
    n = 1000
    window = 256
    x_np = np.arange(n ** 2).reshape((n, n))
    x_cp = cp.arange(n ** 2).reshape((n, n))
    shape = (n - window + 1, n - window + 1, window, window)
    x_np = np.lib.stride_tricks.as_strided(x_np, shape=shape, strides=2*x_np.strides)
    x_cp = cp.lib.stride_tricks.as_strided(x_cp, shape=shape, strides=2*x_cp.strides)

    i = 43
    j = 744

    cpu = x_np[i, j]
    gpu = x_cp[i, j]
    print("Regular indexing: ", np.all(cpu == cp.asnumpy(gpu)))
    cpu = x_np[np.array([i]), np.array([j])]
    gpu = x_cp[np.array([i]), np.array([j])]
    print("Advanced indexing: ", np.all(cpu == cp.asnumpy(gpu)))

    # i, j values found through the following search.
    # for i in range(x_np.shape[0]):
    #     for j in range(x_np.shape[1]):
    #         cpu = x_np[np.array([i]), np.array([j])]
    #         gpu = x_cp[np.array([i]), np.array([j])]
    #         try:
    #             if np.any(cpu != cp.asnumpy(gpu)):
    #                 print(i, j, cpu, cp.asnumpy(gpu))
    #         except cupy_backends.cuda.api.runtime.CUDARuntimeError:
    #             print(i, j)
    #             exit(1)

Installation

Conda-Forge (conda install ...)

Environment

OS                           : Linux-5.4.0-153-generic-x86_64-with-glibc2.31
Python Version               : 3.10.13
CuPy Version                 : 12.3.0
CuPy Platform                : NVIDIA CUDA
NumPy Version                : 1.26.2
SciPy Version                : 1.11.4
Cython Build Version         : 0.29.37
Cython Runtime Version       : None
CUDA Root                    : /home/uyy37579/miniconda3/envs/ptyrodactyl
nvcc PATH                    : None
CUDA Build Version           : 11080
CUDA Driver Version          : 11040
CUDA Runtime Version         : 11040
cuBLAS Version               : (available)
cuFFT Version                : 10502
cuRAND Version               : 10205
cuSOLVER Version             : (11, 2, 0)
cuSPARSE Version             : (available)
NVRTC Version                : (11, 4)
Thrust Version               : 101501
CUB Build Version            : 101501
Jitify Build Version         : d7180e1
cuDNN Build Version          : None
cuDNN Version                : None
NCCL Build Version           : None
NCCL Runtime Version         : None
cuTENSOR Version             : None
cuSPARSELt Build Version     : None
Device 0 Name                : NVIDIA A100-PCIE-40GB
Device 0 Compute Capability  : 80
Device 0 PCI Bus ID          : 0000:04:00.0
Device 1 Name                : NVIDIA A100-PCIE-40GB
Device 1 Compute Capability  : 80
Device 1 PCI Bus ID          : 0000:05:00.0

Additional Information

Possibly related to #4825 but I don't think that this is an issue with how much memory is being used, or it should fail in every case.

@Nordicus Nordicus added the cat:bug Bugs label Jan 23, 2024
@asi1024 asi1024 self-assigned this Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants