ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 3.5。 CUDA Python 中支持的 Python 功能 > 原文: [http://numba.pydata.org/numba-doc/latest/cuda/cudapysupported.html](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 编程指南](http://docs.nvidia.com/cuda/cuda-c-programming-guide/#programming-model)。 ### 3.5.1.2。构造 不支持以下 Python 构造: * 异常处理(`try .. except`,`try .. finally`) * 上下文管理(`with`语句) * 理解(列表,字典,集合或生成器理解) * 生成器(任何`yield`语句) 支持`raise`和`assert`语句。参见 [nopython 语言支持](../reference/pysupported.html#pysupported-language)。 ## 3.5.2。内置类型 以下内置类型支持从 CPU nopython 模式继承。 * INT * 浮动 * 复杂 * 布尔 * 没有 * 元组 参见 [nopython 内置类型](../reference/pysupported.html#pysupported-builtin-types)。 ## 3.5.3。内置功能 支持以下内置函数: * [`abs()`](https://docs.python.org/3/library/functions.html#abs "(in Python v3.7)") * [`bool`](https://docs.python.org/3/library/functions.html#bool "(in Python v3.7)") * [`complex`](https://docs.python.org/3/library/functions.html#complex "(in Python v3.7)") * [`enumerate()`](https://docs.python.org/3/library/functions.html#enumerate "(in Python v3.7)") * [`float`](https://docs.python.org/3/library/functions.html#float "(in Python v3.7)") * [`int`](https://docs.python.org/3/library/functions.html#int "(in Python v3.7)") :只有单参数形式 * [`len()`](https://docs.python.org/3/library/functions.html#len "(in Python v3.7)") * [`min()`](https://docs.python.org/3/library/functions.html#min "(in Python v3.7)") :只有多参数形式 * [`max()`](https://docs.python.org/3/library/functions.html#max "(in Python v3.7)") :只有多参数形式 * [`range`](https://docs.python.org/3/library/stdtypes.html#range "(in Python v3.7)") :即使在 Python 2 中,语义也类似于 Python 3:返回范围对象而不是值数组。 * [`round()`](https://docs.python.org/3/library/functions.html#round "(in Python v3.7)") * [`zip()`](https://docs.python.org/3/library/functions.html#zip "(in Python v3.7)") ## 3.5.4。标准库模块 ### 3.5.4.1。 `cmath` 支持 [`cmath`](https://docs.python.org/3/library/cmath.html#module-cmath "(in Python v3.7)") 模块的以下功能: * [`cmath.acos()`](https://docs.python.org/3/library/cmath.html#cmath.acos "(in Python v3.7)") * [`cmath.acosh()`](https://docs.python.org/3/library/cmath.html#cmath.acosh "(in Python v3.7)") * [`cmath.asin()`](https://docs.python.org/3/library/cmath.html#cmath.asin "(in Python v3.7)") * [`cmath.asinh()`](https://docs.python.org/3/library/cmath.html#cmath.asinh "(in Python v3.7)") * [`cmath.atan()`](https://docs.python.org/3/library/cmath.html#cmath.atan "(in Python v3.7)") * [`cmath.atanh()`](https://docs.python.org/3/library/cmath.html#cmath.atanh "(in Python v3.7)") * [`cmath.cos()`](https://docs.python.org/3/library/cmath.html#cmath.cos "(in Python v3.7)") * [`cmath.cosh()`](https://docs.python.org/3/library/cmath.html#cmath.cosh "(in Python v3.7)") * [`cmath.exp()`](https://docs.python.org/3/library/cmath.html#cmath.exp "(in Python v3.7)") * [`cmath.isfinite()`](https://docs.python.org/3/library/cmath.html#cmath.isfinite "(in Python v3.7)") * [`cmath.isinf()`](https://docs.python.org/3/library/cmath.html#cmath.isinf "(in Python v3.7)") * [`cmath.isnan()`](https://docs.python.org/3/library/cmath.html#cmath.isnan "(in Python v3.7)") * [`cmath.log()`](https://docs.python.org/3/library/cmath.html#cmath.log "(in Python v3.7)") * [`cmath.log10()`](https://docs.python.org/3/library/cmath.html#cmath.log10 "(in Python v3.7)") * [`cmath.phase()`](https://docs.python.org/3/library/cmath.html#cmath.phase "(in Python v3.7)") * [`cmath.polar()`](https://docs.python.org/3/library/cmath.html#cmath.polar "(in Python v3.7)") * [`cmath.rect()`](https://docs.python.org/3/library/cmath.html#cmath.rect "(in Python v3.7)") * [`cmath.sin()`](https://docs.python.org/3/library/cmath.html#cmath.sin "(in Python v3.7)") * [`cmath.sinh()`](https://docs.python.org/3/library/cmath.html#cmath.sinh "(in Python v3.7)") * [`cmath.sqrt()`](https://docs.python.org/3/library/cmath.html#cmath.sqrt "(in Python v3.7)") * [`cmath.tan()`](https://docs.python.org/3/library/cmath.html#cmath.tan "(in Python v3.7)") * [`cmath.tanh()`](https://docs.python.org/3/library/cmath.html#cmath.tanh "(in Python v3.7)") ### 3.5.4.2。 `math` 支持 [`math`](https://docs.python.org/3/library/math.html#module-math "(in Python v3.7)") 模块的以下功能: * [`math.acos()`](https://docs.python.org/3/library/math.html#math.acos "(in Python v3.7)") * [`math.asin()`](https://docs.python.org/3/library/math.html#math.asin "(in Python v3.7)") * [`math.atan()`](https://docs.python.org/3/library/math.html#math.atan "(in Python v3.7)") * `math.arctan()` * [`math.acosh()`](https://docs.python.org/3/library/math.html#math.acosh "(in Python v3.7)") * [`math.asinh()`](https://docs.python.org/3/library/math.html#math.asinh "(in Python v3.7)") * [`math.atanh()`](https://docs.python.org/3/library/math.html#math.atanh "(in Python v3.7)") * [`math.cos()`](https://docs.python.org/3/library/math.html#math.cos "(in Python v3.7)") * [`math.sin()`](https://docs.python.org/3/library/math.html#math.sin "(in Python v3.7)") * [`math.tan()`](https://docs.python.org/3/library/math.html#math.tan "(in Python v3.7)") * [`math.hypot()`](https://docs.python.org/3/library/math.html#math.hypot "(in Python v3.7)") * [`math.cosh()`](https://docs.python.org/3/library/math.html#math.cosh "(in Python v3.7)") * [`math.sinh()`](https://docs.python.org/3/library/math.html#math.sinh "(in Python v3.7)") * [`math.tanh()`](https://docs.python.org/3/library/math.html#math.tanh "(in Python v3.7)") * [`math.atan2()`](https://docs.python.org/3/library/math.html#math.atan2 "(in Python v3.7)") * [`math.erf()`](https://docs.python.org/3/library/math.html#math.erf "(in Python v3.7)") * [`math.erfc()`](https://docs.python.org/3/library/math.html#math.erfc "(in Python v3.7)") * [`math.exp()`](https://docs.python.org/3/library/math.html#math.exp "(in Python v3.7)") * [`math.expm1()`](https://docs.python.org/3/library/math.html#math.expm1 "(in Python v3.7)") * [`math.fabs()`](https://docs.python.org/3/library/math.html#math.fabs "(in Python v3.7)") * [`math.gamma()`](https://docs.python.org/3/library/math.html#math.gamma "(in Python v3.7)") * [`math.lgamma()`](https://docs.python.org/3/library/math.html#math.lgamma "(in Python v3.7)") * [`math.log()`](https://docs.python.org/3/library/math.html#math.log "(in Python v3.7)") * [`math.log10()`](https://docs.python.org/3/library/math.html#math.log10 "(in Python v3.7)") * [`math.log1p()`](https://docs.python.org/3/library/math.html#math.log1p "(in Python v3.7)") * [`math.sqrt()`](https://docs.python.org/3/library/math.html#math.sqrt "(in Python v3.7)") * [`math.pow()`](https://docs.python.org/3/library/math.html#math.pow "(in Python v3.7)") * [`math.ceil()`](https://docs.python.org/3/library/math.html#math.ceil "(in Python v3.7)") * [`math.floor()`](https://docs.python.org/3/library/math.html#math.floor "(in Python v3.7)") * [`math.copysign()`](https://docs.python.org/3/library/math.html#math.copysign "(in Python v3.7)") * [`math.fmod()`](https://docs.python.org/3/library/math.html#math.fmod "(in Python v3.7)") * [`math.isnan()`](https://docs.python.org/3/library/math.html#math.isnan "(in Python v3.7)") * [`math.isinf()`](https://docs.python.org/3/library/math.html#math.isinf "(in Python v3.7)") ### 3.5.4.3。 `operator` 支持 [`operator`](https://docs.python.org/3/library/operator.html#module-operator "(in Python v3.7)") 模块的以下功能: * [`operator.add()`](https://docs.python.org/3/library/operator.html#operator.add "(in Python v3.7)") * [`operator.and_()`](https://docs.python.org/3/library/operator.html#operator.and_ "(in Python v3.7)") * `operator.div()`(仅限 Python 2) * [`operator.eq()`](https://docs.python.org/3/library/operator.html#operator.eq "(in Python v3.7)") * [`operator.floordiv()`](https://docs.python.org/3/library/operator.html#operator.floordiv "(in Python v3.7)") * [`operator.ge()`](https://docs.python.org/3/library/operator.html#operator.ge "(in Python v3.7)") * [`operator.gt()`](https://docs.python.org/3/library/operator.html#operator.gt "(in Python v3.7)") * [`operator.iadd()`](https://docs.python.org/3/library/operator.html#operator.iadd "(in Python v3.7)") * [`operator.iand()`](https://docs.python.org/3/library/operator.html#operator.iand "(in Python v3.7)") * `operator.idiv()`(仅限 Python 2) * [`operator.ifloordiv()`](https://docs.python.org/3/library/operator.html#operator.ifloordiv "(in Python v3.7)") * [`operator.ilshift()`](https://docs.python.org/3/library/operator.html#operator.ilshift "(in Python v3.7)") * [`operator.imod()`](https://docs.python.org/3/library/operator.html#operator.imod "(in Python v3.7)") * [`operator.imul()`](https://docs.python.org/3/library/operator.html#operator.imul "(in Python v3.7)") * [`operator.invert()`](https://docs.python.org/3/library/operator.html#operator.invert "(in Python v3.7)") * [`operator.ior()`](https://docs.python.org/3/library/operator.html#operator.ior "(in Python v3.7)") * [`operator.ipow()`](https://docs.python.org/3/library/operator.html#operator.ipow "(in Python v3.7)") * [`operator.irshift()`](https://docs.python.org/3/library/operator.html#operator.irshift "(in Python v3.7)") * [`operator.isub()`](https://docs.python.org/3/library/operator.html#operator.isub "(in Python v3.7)") * [`operator.itruediv()`](https://docs.python.org/3/library/operator.html#operator.itruediv "(in Python v3.7)") * [`operator.ixor()`](https://docs.python.org/3/library/operator.html#operator.ixor "(in Python v3.7)") * [`operator.le()`](https://docs.python.org/3/library/operator.html#operator.le "(in Python v3.7)") * [`operator.lshift()`](https://docs.python.org/3/library/operator.html#operator.lshift "(in Python v3.7)") * [`operator.lt()`](https://docs.python.org/3/library/operator.html#operator.lt "(in Python v3.7)") * [`operator.mod()`](https://docs.python.org/3/library/operator.html#operator.mod "(in Python v3.7)") * [`operator.mul()`](https://docs.python.org/3/library/operator.html#operator.mul "(in Python v3.7)") * [`operator.ne()`](https://docs.python.org/3/library/operator.html#operator.ne "(in Python v3.7)") * [`operator.neg()`](https://docs.python.org/3/library/operator.html#operator.neg "(in Python v3.7)") * [`operator.not_()`](https://docs.python.org/3/library/operator.html#operator.not_ "(in Python v3.7)") * [`operator.or_()`](https://docs.python.org/3/library/operator.html#operator.or_ "(in Python v3.7)") * [`operator.pos()`](https://docs.python.org/3/library/operator.html#operator.pos "(in Python v3.7)") * [`operator.pow()`](https://docs.python.org/3/library/operator.html#operator.pow "(in Python v3.7)") * [`operator.rshift()`](https://docs.python.org/3/library/operator.html#operator.rshift "(in Python v3.7)") * [`operator.sub()`](https://docs.python.org/3/library/operator.html#operator.sub "(in Python v3.7)") * [`operator.truediv()`](https://docs.python.org/3/library/operator.html#operator.truediv "(in Python v3.7)") * [`operator.xor()`](https://docs.python.org/3/library/operator.html#operator.xor "(in Python v3.7)") ## 3.5.5。 Numpy 支持 由于 CUDA 编程模型,内核内的动态内存分配效率低下且通常不需要。 Numba 不允许任何内存分配功能。这会禁用大量 NumPy API。为了获得最佳性能,用户应编写代码,以便每个线程一次处理单个元素。 支持的 numpy 功能: * 访问 <cite>ndarray</cite> 属性 <cite>.shape</cite> , <cite>.strides</cite> , <cite>.ndim</cite> , <cite>.size</cite> 等。 * 标量 ufuncs 在<cite>数学</cite>模块中具有等价物;即`np.sin(x[0])`,其中 x 是 1D 阵列。 * 索引和切片工作。 不受支持的 numpy 功能: * 数组创建 API。 * 数组方法。 * 返回新数组的函数。