3.5。 CUDA Python 中支持的 Python 功能
原文: http://numba.pydata.org/numba-doc/latest/cuda/cudapysupported.html
此页面列出了 CUDA Python 支持的 Python 功能。这包括使用@cuda.jit和针对 CUDA GPU 的其他更高级 Numba 装饰器编译的所有内核和设备函数。
3.5.1。语言
3.5.1.1。执行模型
CUDA Python 直接映射到 CUDA 的 _ 单指令多线程 _ 执行(SIMT)模型。每条指令由多个线程并行隐式执行。使用此执行模型,数组表达式不太有用,因为我们不希望多个线程执行相同的任务。相反,我们希望线程以合作的方式执行任务。
有关详细信息,请参阅 CUDA 编程指南。
3.5.1.2。构造
不支持以下 Python 构造:
- 异常处理(
try .. except,try .. finally) - 上下文管理(
with语句) - 理解(列表,字典,集合或生成器理解)
- 生成器(任何
yield语句)
支持raise和assert语句。参见 nopython 语言支持。
3.5.2。内置类型
以下内置类型支持从 CPU nopython 模式继承。
- INT
- 浮动
- 复杂
- 布尔
- 没有
- 元组
参见 nopython 内置类型。
3.5.3。内置功能
支持以下内置函数:
abs()boolcomplexenumerate()floatint:只有单参数形式len()min():只有多参数形式max():只有多参数形式range:即使在 Python 2 中,语义也类似于 Python 3:返回范围对象而不是值数组。round()zip()
3.5.4。标准库模块
3.5.4.1。 cmath
支持 cmath 模块的以下功能:
cmath.acos()cmath.acosh()cmath.asin()cmath.asinh()cmath.atan()cmath.atanh()cmath.cos()cmath.cosh()cmath.exp()cmath.isfinite()cmath.isinf()cmath.isnan()cmath.log()cmath.log10()cmath.phase()cmath.polar()cmath.rect()cmath.sin()cmath.sinh()cmath.sqrt()cmath.tan()cmath.tanh()
3.5.4.2。 math
支持 math 模块的以下功能:
math.acos()math.asin()math.atan()math.arctan()math.acosh()math.asinh()math.atanh()math.cos()math.sin()math.tan()math.hypot()math.cosh()math.sinh()math.tanh()math.atan2()math.erf()math.erfc()math.exp()math.expm1()math.fabs()math.gamma()math.lgamma()math.log()math.log10()math.log1p()math.sqrt()math.pow()math.ceil()math.floor()math.copysign()math.fmod()math.isnan()math.isinf()
3.5.4.3。 operator
支持 operator 模块的以下功能:
operator.add()operator.and_()operator.div()(仅限 Python 2)operator.eq()operator.floordiv()operator.ge()operator.gt()operator.iadd()operator.iand()operator.idiv()(仅限 Python 2)operator.ifloordiv()operator.ilshift()operator.imod()operator.imul()operator.invert()operator.ior()operator.ipow()operator.irshift()operator.isub()operator.itruediv()operator.ixor()operator.le()operator.lshift()operator.lt()operator.mod()operator.mul()operator.ne()operator.neg()operator.not_()operator.or_()operator.pos()operator.pow()operator.rshift()operator.sub()operator.truediv()operator.xor()
3.5.5。 Numpy 支持
由于 CUDA 编程模型,内核内的动态内存分配效率低下且通常不需要。 Numba 不允许任何内存分配功能。这会禁用大量 NumPy API。为了获得最佳性能,用户应编写代码,以便每个线程一次处理单个元素。
支持的 numpy 功能:
- 访问
ndarray属性.shape,.strides,.ndim,.size等。 - 标量 ufuncs 在
数学模块中具有等价物;即np.sin(x[0]),其中 x 是 1D 阵列。 - 索引和切片工作。
不受支持的 numpy 功能:
- 数组创建 API。
- 数组方法。
- 返回新数组的函数。
