cupy icon indicating copy to clipboard operation
cupy copied to clipboard

python primitive scalar float fails as jit.rawkernel argument

Open truher opened this issue 3 years ago • 1 comments

Description

Passing python primitive float as a jit.rawkernel argument seems not to work. Numpy.float32 works, python float does not.

To Reproduce

@jit.rawkernel()
def scalar_multiply(a, m, size):
    tid = jit.blockIdx.x * jit.blockDim.x + jit.threadIdx.x
    ntid = jit.gridDim.x * jit.blockDim.x
    for i in range(tid, size, ntid):
        a[i] = a[i] * m

size = 5
a = cp.random.random(size, dtype=np.float32)

print(a)
scalar_multiply((128,),(1024,),(a, np.float32(5.0), size))
print(a)
scalar_multiply((128,),(1024,),(a, 5.0, size))
print(a)

output:

[0.17959814 0.42873758 0.77541053 0.8213136 0.8284943 ] [0.8979907 2.143688 3.8770528 4.1065683 4.1424713] [0. 0. 0. 0. 0.]

Installation

Wheel

Environment

OS                           : Linux-5.15.0-41-generic-x86_64-with-glibc2.29
Python Version               : 3.8.10
CuPy Version                 : 11.0.0
CuPy Platform                : NVIDIA CUDA
NumPy Version                : 1.22.0
SciPy Version                : 1.4.1
Cython Build Version         : 0.29.24
Cython Runtime Version       : 0.29.28
CUDA Root                    : /usr/local/cuda
nvcc PATH                    : /usr/local/cuda/bin/nvcc
CUDA Build Version           : 11070
CUDA Driver Version          : 11070
CUDA Runtime Version         : 11070
cuBLAS Version               : (available)
cuFFT Version                : 10702
cuRAND Version               : 10210
cuSOLVER Version             : (11, 3, 5)
cuSPARSE Version             : (available)
NVRTC Version                : (11, 7)
Thrust Version               : 101500
CUB Build Version            : 101500
Jitify Build Version         : 4a37de0
cuDNN Build Version          : 8400
cuDNN Version                : 8401
NCCL Build Version           : None
NCCL Runtime Version         : None
cuTENSOR Version             : None
cuSPARSELt Build Version     : None
Device 0 Name                : NVIDIA GeForce GTX 950
Device 0 Compute Capability  : 52
Device 0 PCI Bus ID          : 0000:01:00.0

Additional Information

Thanks!

truher avatar Jul 30 '22 15:07 truher

@truher Thanks for your reporting! This bug will be fixed by https://github.com/cupy/cupy/pull/6948!

asi1024 avatar Aug 02 '22 09:08 asi1024