简体   繁体   中英

Error while running the python cuda program

I am new to python kernel programming, For learning, I followed this link . While trying to run the sample Cuda python program, I got an error like below. I have no idea, what this about? Please help me to solve this issue so that I can continue learning.

Traceback (most recent call last):
File "numpycuda.py", line 17, in <module>
my_kernel[blockspergrid, threadsperblock](data)

File "/home/face/.local/lib/python2.7/site- 
packages/numba/cuda/simulator/kernel.py", line 103, in 
__getitem__
normalize_kernel_dimensions(*configuration[:2])

File "/home/face/.local/lib/python2.7/site- 
packages/numba/cuda/errors.py", line 38, in 
normalize_kernel_dimensions
griddim = check_dim(griddim, 'griddim')

File "/home/face/.local/lib/python2.7/site- 
packages/numba/cuda/errors.py", line 33, in check_dim
% (name, dim)).

TypeError: griddim must be a sequence of integers, got [1.0]

Python program

from __future__ import division
from numba import cuda
import numpy
import math

# CUDA kernel
@cuda.jit
def my_kernel(io_array):
   pos = cuda.grid(1)
   if pos < io_array.size:
      io_array[pos] *= 2 # do the computation

# Host code   
data = numpy.ones(256)
threadsperblock = 256
blockspergrid = math.ceil(data.shape[0] / threadsperblock)
my_kernel[blockspergrid, threadsperblock](data)
print(data)

I installed numba, CUDA and numpy library, What might be the issue? I am using python version of 2.7.12

The Numba kernel launch requires that the execution parameters be integers or tuples of integers. Your use of math.ceil(data.shape[0] / threadsperblock) is producing a floating point number which is illegal to use as an execution parameter.

You could do something like this:

data = numpy.ones(250)
threadsperblock = 64
blockspergrid = (data.shape[0] + threadsperblock - 1) // threadsperblock
my_kernel[blockspergrid, threadsperblock](data)

which should work correctly

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM