[英]Running Python on GPU using numba
I am trying to run python code in my NVIDIA GPU and googling seemed to tell me that numbapro was the module that I am looking for. 我试图在NVIDIA GPU中运行python代码,而谷歌搜索似乎告诉我numbapro是我正在寻找的模块。 However, according to this , numbapro is no longer continued but has been moved to the numba library.
然而,根据这个 ,numbapro不再继续,但已被移动到numba库。 I tried out numba and it's
@jit
decorator does seem to speed up some of my code very much. 我尝试了numba,它的
@jit
装饰器似乎确实可以大大加快我的某些代码的速度。 However, as I read up on it more, it seems to me that jit
simply compiles your code during run-time and in doing so, it does some heavy optimization and hence the speed-up. 但是,当我阅读更多内容时,在我看来
jit
只是在运行时编译您的代码,并且这样做会进行一些繁重的优化并因此提高了速度。
This is further re-enforced by the fact that jit
does not seem to speed up the already optimized numpy operations such as numpy.dot
etc. jit
似乎并不能加快已经优化的numpy操作(例如numpy.dot
等)的速度, jit
进一步加强了这一点。
Am I getting confused and way off the track here? 我会感到困惑并偏离这里的轨道吗? What exactly does
jit
do? jit
到底是做什么的? And if it does not make my code run on the GPU, how else do I do it? 如果它不能使我的代码在GPU上运行,我还应该怎么做?
You have to specifically tell Numba to target the GPU, either via a ufunc: 您必须通过ufunc专门告诉Numba将GPU定位为目标:
http://numba.pydata.org/numba-doc/latest/cuda/ufunc.html http://numba.pydata.org/numba-doc/latest/cuda/ufunc.html
or by programming your functions in a way that explicitly takes the GPU into account: 或通过以明确考虑GPU的方式对函数进行编程:
http://numba.pydata.org/numba-doc/latest/cuda/examples.html http://numba.pydata.org/numba-doc/latest/cuda/index.html http://numba.pydata.org/numba-doc/latest/cuda/examples.html http://numba.pydata.org/numba-doc/latest/cuda/index.html
The plain jit
function does not target the GPU and will typically not speed-up calls to things like np.dot
. 普通的
jit
函数并不针对GPU,通常不会加快对np.dot
类的np.dot
。 Typically Numba excels where you can either avoid creating intermediate temporary numpy arrays or if the code you are writing is hard to write in a vectorized fashion to begin with. 通常,Numba擅长于此,您可以避免创建中间临时numpy数组,或者如果您正在编写的代码很难以矢量化的方式开始编写。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.