Repository: cupy/cupy

Issue:
python primitive scalar float fails as jit.rawkernel argument
### Description

Passing python primitive float as a jit.rawkernel argument seems not to work.  Numpy.float32 works, python float does not.

### To Reproduce

```py
@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!


Discussion:

Resolving patch:
diff --git a/cupyx/jit/_interface.py b/cupyx/jit/_interface.py
--- a/cupyx/jit/_interface.py
+++ b/cupyx/jit/_interface.py
@@ -10,6 +10,7 @@
 from cupyx.jit import _cuda_typerules
 from cupyx.jit import _cuda_types
 from cupyx.jit import _internal_types
+from cupyx.jit._cuda_types import Scalar
 
 
 class _CudaFunction:
@@ -113,7 +114,16 @@ def __call__(
             kern = module.get_function(fname)
             self._cache[(in_types, device_id)] = (kern, enable_cg)
 
-        kern(grid, block, args, shared_mem, stream, enable_cg)
+        new_args = []
+        for a, t in zip(args, in_types):
+            if isinstance(t, Scalar):
+                if t.dtype.char == 'e':
+                    a = numpy.float32(a)
+                else:
+                    a = t.dtype.type(a)
+            new_args.append(a)
+
+        kern(grid, block, tuple(new_args), shared_mem, stream, enable_cg)
 
     def __getitem__(self, grid_and_block):
         """Numba-style kernel call.


Test patch:
diff --git a/tests/cupyx_tests/jit_tests/test_raw.py b/tests/cupyx_tests/jit_tests/test_raw.py
--- a/tests/cupyx_tests/jit_tests/test_raw.py
+++ b/tests/cupyx_tests/jit_tests/test_raw.py
@@ -745,3 +745,27 @@ def f(x):
             assert 'unroll' not in f.cached_code
         elif unroll >= 0:
             assert f'#pragma unroll({unroll})\n' in f.cached_code
+
+    @pytest.mark.parametrize('ctype', (bool, int, float, complex))
+    def test_scalar_args(self, ctype):
+        @jit.rawkernel()
+        def f(x, y):
+            tid = jit.threadIdx.x + jit.blockDim.x * jit.blockIdx.x
+            x[tid] = y
+
+        x = cupy.zeros((30), dtype=ctype)
+        y = ctype(1)
+        f((5,), (6,), (x, y))
+        testing.assert_array_equal(x, numpy.full_like(x, 1))
+
+    @testing.for_all_dtypes()
+    def test_numpy_scalar_args(self, dtype):
+        @jit.rawkernel()
+        def f(x, y):
+            tid = jit.threadIdx.x + jit.blockDim.x * jit.blockIdx.x
+            x[tid] = y
+
+        x = cupy.zeros((30), dtype=dtype)
+        y = numpy.dtype(dtype).type(1)
+        f((5,), (6,), (x, y))
+        testing.assert_array_equal(x, numpy.full_like(x, 1))