Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Python中与CUDA一起使用受支持的numpy和math函数?_Python_Numpy_Cuda_Numba - Fatal编程技术网

如何在Python中与CUDA一起使用受支持的numpy和math函数?

如何在Python中与CUDA一起使用受支持的numpy和math函数?,python,numpy,cuda,numba,Python,Numpy,Cuda,Numba,根据numba 0.51.2,CUDA Python支持多个math函数。但是,它在以下内核函数中不起作用: @cuda.jit def查找角度(角度): i、 j=cuda.grid(2) 如果ifloat64 cuda.grid()(即传递给atan2的i,j)返回的参数是整数值,因为它们与索引相关 numba找不到可以使用的、接受两个整型参数并返回浮点值的atan2: float64 = atan2(int64, int64) 一种可能的解决方案是转换atan2输入参数,以匹配numba

根据
numba 0.51.2
,CUDA Python支持多个
math
函数。但是,它在以下内核函数中不起作用:

@cuda.jit
def查找角度(角度):
i、 j=cuda.grid(2)
如果i
输出:

numba.core.errors.LoweringError: Failed in nopython mode pipeline (step: nopython mode backend)
No definition for lowering <built-in function atan2>(int64, int64) -> float64
numba.core.errors.LoweringError:在nopython模式管道中失败(步骤:nopython模式后端)
没有降低的定义(int64,int64)->float64

我是否错误地使用了该函数?

问题根源的提示如下:

无下降定义(int64,int64)->float64

cuda.grid()
(即传递给
atan2
i
j
)返回的参数是整数值,因为它们与索引相关

numba找不到可以使用的、接受两个整型参数并返回浮点值的
atan2

float64 = atan2(int64, int64)
一种可能的解决方案是转换
atan2
输入参数,以匹配numba似乎希望从该函数返回的类型,这显然是
float64

from numba import cuda, float64
import numpy
import math


@cuda.jit
def find_angle(angles):
    i, j = cuda.grid(2)
    if i < angles.shape[0] and j < angles.shape[1]:
        angles[i][j] = math.atan2(float64(j), float64(i))

block_x = 32
block_y = 32
block = (block_x, block_y)
x = 256
y = 256
grid = (x//block_x, y//block_y) # not for arbitrary x and y

angles = numpy.ones((x, y), numpy.float64)
find_angle[grid, block](angles)
来自numba导入cuda,浮点64
进口numpy
输入数学
@cuda.jit
def查找角度(角度):
i、 j=cuda.grid(2)
如果i
Well
arctan2
不在链接页面上支持的函数列表中。您对支持的文字描述也不是我在查看该页面时发现的内容。我看不到“most”
math
函数是受支持的,我看到提供了受支持函数的列表。如果你看一下<代码> NUBA TAG,那么你会发现代码<>数学< /COD>用法的例子,比如.@ RobertCrovella,我在调试<代码>数学< /COD>和<代码> NoMPy < /Cord>错误的过程中写下了这个问题,并把情况弄得一团糟。为了澄清这个问题,我将问题指向支持的
math
函数,特别是
math.atan(y,x)
。该链接提供支持的功能。