numba numpy计算加速器 官方教程 GPU CUDA配置
官网:http://numba.pydata.org/
官方教程:http://numba.pydata.org/numba-doc/latest/user/5minguide.html
因为我3.7版本的python(也有可能是其他因素影响)找不到numba.autojit加速了,所以想到官网看看到底发生了什么
示例
以下代码加速理想
from numba import jit
import numpy as npx = np.arange(100).reshape(10, 10)@jit(nopython=True) # Set "nopython" mode for best performance, equivalent to @njit
def go_fast(a): # Function is compiled to machine code when called the first timetrace = 0.0for i in range(a.shape[0]): # Numba likes loopstrace += np.tanh(a[i, i]) # Numba likes NumPy functionsreturn a + trace # Numba likes NumPy broadcastingprint(go_fast(x))
以下代码加速不理想(函数不能享受numba加速)
from numba import jit
import pandas as pdx = {'a': [1, 2, 3], 'b': [20, 30, 40]}@jit
def use_pandas(a): # Function will not benefit from Numba jitdf = pd.DataFrame.from_dict(a) # Numba doesn't know about pd.DataFramedf += 1 # Numba doesn't understand what this isreturn df.cov() # or this!print(use_pandas(x))
需要注意的是,numba使用函数装饰器来加速函数,第一次执行函数时,会将函数编译成机器码,需要耗费一定时间,以后每次调用函数,就是直接用机器码执行,从而获得加速
所以,一般比较常用的是@njit
或@jit(nopython=True)
(一样的)
其他功能
Numba has quite a few decorators, we’ve seen @jit, but there’s also:
@njit - this is an alias for @jit(nopython=True) as it is so commonly used!@vectorize - produces NumPy ufunc s (with all the ufunc methods supported). Docs are here.@guvectorize - produces NumPy generalized ufunc s. Docs are here.@stencil - declare a function as a kernel for a stencil like operation. Docs are here.@jitclass - for jit aware classes. Docs are here.@cfunc - declare a function for use as a native call back (to be called from C/C++ etc). Docs are here.@overload - register your own implementation of a function for use in nopython mode, e.g. @overload(scipy.special.j0). Docs are here.
Extra options available in some decorators:
parallel = True - enable the automatic parallelization of the function.fastmath = True - enable fast-math behaviour for the function.
ctypes/cffi/cython interoperability:
cffi - The calling of CFFI functions is supported in nopython mode.ctypes - The calling of ctypes wrapped functions is supported in nopython mode. .Cython exported functions are callable.
GPU targets:
Numba can target Nvidia CUDA and (experimentally) AMD ROC GPUs. You can write a kernel in pure Python and have Numba handle the computation and data movement (or do this explicitly). Click for Numba documentation on CUDA or ROC.
http://numba.pydata.org/numba-doc/latest/cuda/index.html#numba-for-cuda-gpus
有点多
不过没有看到@autojit
,莫非是取消了??
numba numpy计算加速器 官方教程 GPU CUDA配置相关推荐
- 网页更新提醒官方教程(选项配置)
网页更新提醒:任何网页.任何RSS.任何API,给您24小时盯着 全局配置 全局配置用于设置所有任务公共或默认属性,避免相同的重复设置. 公共配置 选取模式:具体参考网页更新提醒官方教程(区域圈选) ...
- Python ln_Python入门教程(三):史上最全的Numpy计算函数总结,建议收藏!
点击上方 蓝字 关注我们 Numpy提供了灵活的.静态类型的.可编译的程序接口口来优化数组的计算,也被称作向量操作,因此在Python数据科学界Numpy显得尤为重要.Numpy的向量操作是通过通用函 ...
- python乘法表运算_Python入门教程(三):史上最全的Numpy计算函数总结,建议收藏!...
点击上方 蓝字 关注我们 Numpy提供了灵活的.静态类型的.可编译的程序接口口来优化数组的计算,也被称作向量操作,因此在Python数据科学界Numpy显得尤为重要.Numpy的向量操作是通过通用函 ...
- paddlepaddle 使用GPU 计算,安装cuDNN 和 CUDA记录
paddlepaddle 使用GPU 计算,安装cuDNN 和 CUDA记录 根据paddlepaddle 指导文档选择安装版本,早点选择10.2不用浪费半天.查看N卡版本信号 如果你使用的是安培架构 ...
- pytorch官方教程中文版(二)学习PyTorch
pytorch编程环境是1.9.1+cu10.2 建议有能力的直接看官方网站英文版! 下面所示是本次教程的主要目录: pytorch官方教程中文版: PyTorch介绍 学习PyTorch 图像和视频 ...
- 60分钟入门PyTorch,官方教程手把手教你训练第一个深度学习模型(附链接)
来源:机器之心 本文约800字,建议阅读5分钟. 本文介绍了官方教程入门PyTorch的技巧训练. 近期的一份调查报告显示:PyTorch 已经力压 TensorFlow 成为各大顶会的主流深度学习框 ...
- 60分钟入门PyTorch,官方教程手把手教你训练第一个深度学习模型
点击我爱计算机视觉标星,更快获取CVML新技术 本文转载自机器之心. 近期的一份调查报告显示:PyTorch 已经力压 TensorFlow 成为各大顶会的主流深度学习框架.想发论文,不学 PyTor ...
- TensorFlow2.0 Guide官方教程 学习笔记17 -‘Using the SavedModel format‘
本笔记参照TensorFlow官方教程,主要是对'Save a model-Training checkpoints'教程内容翻译和内容结构编排,原文链接:Using the SavedModel f ...
- pytorch官方教程中文版(一)PyTorch介绍
pytorch编程环境是1.9.1+cu10.2 建议有能力的直接看官方网站英文版! 下面所示是本次教程的主要目录: pytorch官方教程中文版: PyTorch介绍 学习PyTorch 图像和视频 ...
最新文章
- 吴恩达神经网络和深度学习——第三周笔记
- python 执行ping命令_Python黑科技:在家远程遥控公司电脑,python+微信一键连接!...
- python3 collections模块_Python3之collections模块
- regex在.NET里判断输入信息的合法性
- 应用交付脚本工具在HTTP服务中的应用
- input和textarea的区别
- 去掉 RHEL AS 3 内存检测达不到256MB的警告
- 【matlab】直方图(hist函数的应用)
- 3D呈现transform-style(CSS3)
- 总结const、readonly、static三者的区别【收藏、转载】20190614
- construct2游戏设计与制作
- SeaChest Utilities 工具,让你的硬盘功耗又低又长寿
- 电视hdmi接口在哪_变废为宝!把旧笔记本电脑当电视盒子用
- 衣服不管染上什么,用这招都能洗掉!99%的人不知道!
- 思杰desktop7.6申请90天试用的License
- 电商支付平台支付安全保障措施
- HP 员工挑战老板的一封信
- Apple macOS 下载汇总
- 西门子300PLC转以太网无需编程实现与1200PLC转以太网数据通信
- [C语言]——整型的截断与提升