I am trying to learn GPU acceleration using Numba and CuPy for my research work. In this process, I need to use SciPy routines along with Numba. I would like to know if it is possible to combine Numba’s loop parallelization with the usage of SciPy and CuPy functions. I would appreciate any suggestions on how to address these issues. The code is given below:
import numpy as np
import numba
from numba import cuda
import cupy as cp
@cuda.jit
def test(i, p):
"""
Square the input number and store it in the output array.
Inputs:
i: input number to be squared
p: output array to store the squared result
"""
p[i] = i**2
@cuda.jit
def main_gpu(p):
i = cuda.grid(1)
if i < p.shape[0]:
row = [0, 0, 1, 3, 1, 0, 0]
col = [0, 2, 1, 3, 1, 0, 0]
data = [1, 1, 1, 1, 1, 1, 1]
matrix=cp.sparse.coo_matrix((data, (row, col)), shape=(4, 4))
test(i, p)
tnum = 50
p = np.zeros(tnum)
threadsperblock = 32
blockspergrid = (tnum + (threadsperblock - 1)) // threadsperblock
main_gpu[blockspergrid, threadsperblock](p)
The error from this code is:
TypingError: Failed in cuda mode pipeline (step: nopython frontend)
Unknown attribute 'coo_matrix' of type Module(<module 'cupy.sparse' from '/usr/local/lib/python3.10/dist-packages/cupy/sparse/__init__.py'>)
File "<ipython-input-14-120ea31d09be>", line 23:
def main_gpu(p):
<source elided>
data = [1, 1, 1, 1, 1, 1, 1]
cp.sparse.coo_matrix((data, (row, col)), shape=(4, 4))
^
During: typing of get attribute at <ipython-input-14-120ea31d09be> (23)
File "<ipython-input-14-120ea31d09be>", line 23:
def main_gpu(p):
<source elided>
data = [1, 1, 1, 1, 1, 1, 1]
cp.sparse.coo_matrix((data, (row, col)), shape=(4, 4))
^