[英]Error while running the python cuda program
I am new to python kernel programming, For learning, I followed this link . 我是python内核编程的新手,要学习,我点击了此链接 。 While trying to run the sample Cuda python program, I got an error like below. 尝试运行示例Cuda python程序时,出现如下错误。 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 Python程序
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? 我安装了numba,CUDA和numpy库,可能是什么问题? I am using python version of 2.7.12 我正在使用2.7.12的python版本
The Numba kernel launch requires that the execution parameters be integers or tuples of integers. Numba内核启动要求执行参数为整数或整数元组。 Your use of math.ceil(data.shape[0] / threadsperblock)
is producing a floating point number which is illegal to use as an execution parameter. 您对math.ceil(data.shape[0] / threadsperblock)
将产生一个浮点数,该浮点数不能用作执行参数。
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 哪个应该正常工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.