当前位置:首页 > 报告详情

GPU 加速 python 计算.pdf

上传人: li 编号:29485 2021-02-07 37页 41.09MB

1、NVIDIAGPU ACCELERATION INPYTHONDominic Wang I Solution ArchitectGTC CHINA#page#AGENDAGetting StartedBackgroundTesting SetupNumba CodeStep through Numba modificationsCuPy CodeStep through CuPy mmodifications#page#AVERAGE USERSC/C+Python106CoActive Developers20PythonC/C+LanguageSource:http#page#WHY AR

2、E WE HERE2?“Am a Python developer but really need the performance of CUDA C+.”“1 have custom arithmetic,i.e, SciPy, that doesnt exist otherGPUaccelerated package,i.e.CuPy.”“i have custom Numba kernels and im nervous about porting code toCuPys RawKernel.”“Are there any improvements that can be made t

3、o my currentNumba/CuPy code?nvID#page#GETTING STARTEDDrop-in GPU LibraryCustom Numba CUDA KernelsCustom Raw CUDAKernelsReplacementsLeverage JIT compilation andTomatch native CUDA speeds,NumPy - CuPyNumbas CUDA support to quicklywrap raw CUDA kernels in CuPy;Pandas - CuDFbuild and test custom CUDApre

4、compile and cache kernel toScikit-Learn - CUMLkernels with a Pythonic APIavoid JIT overheadNetwork-X-CuGraphPros:Pros:PrOS:Quickly build custom featuresMatches CUDA C+ speedTrivial code changeBoilerplate codeNo excess SW layer“Free” PerformanceCons:Cons:Cons;JIT compilation overheadLimited debugging

5、 toolsPotentially sub-optimalExcess register pressureSupport multiple dtypesLimited controlGPUAccelerating SciPySignal withNumba and CuPy ISciPy202013nttp5#page#TESTINGFind and run the codehttps:/ fallconda env create-f gtc_fall.ymlbash test_script.shInput size-210;Outputsize-220Performed onaDGX1Tes

6、laV100-SXM2-32GBIntel Xeon CPUE5-2598 v42.2GHzSetting GPUsudo nvidia-smi-ac 877,1530-i0#Set clockssudo nvidia-smi -pl 250 -i0 # Set power levels#page#PYTHON CODESciPy (Lombscargle)for i in range(freqs.shapeO)XC=0.tau=atan2(2*cs,cc-ss)/(2*freqsi)XS=0.C_tau= cos(freqsitau)CC=0.S_tau = sin(freqsi*tau)c

word格式文档无特别注明外均可编辑修改,预览文件经过压缩,下载原文更清晰!
三个皮匠报告文库所有资源均是客户上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作商用。
本文主要介绍了如何使用Numba和CuPy在Python中进行GPU加速。主要内容包括: 1. 背景介绍:Python开发者需要CUDA C++的性能,但不想使用其他GPU加速包,如CuPy。 2. 测试设置:使用Numba和CuPy对SciPy的Lombscargle算法进行GPU加速,并与SciPy的CPU实现进行比较。 3. Numba代码:使用Numba的JIT编译和CUDA支持快速构建和测试自定义CUDA内核。 4. CuPy代码:使用CuPy的RawKernel来匹配CUDA C++的速度,避免JIT开销。 5. 比较结果:Numba和CuPy的性能与SciPy的CPU实现相当,但CuPy的RawKernel在单精度浮点数上表现更好。 6. 最终思考:用户级缓存可以减少内核启动时间;Numba和CuPy的内核性能在双精度浮点数上非常相似;快速数学是一个有吸引力的特性,但要注意精度损失;预编译的内核可以减少首次执行时间;从Numba迁移到CuPy需要显式指定数据类型和变量管理。
如何使用Numba和CuPy加速Python中的GPU计算? Numba和CuPy在GPU加速Python计算方面有何不同? 如何优化Numba和CuPy代码以获得更好的性能?
客服
商务合作
小程序
服务号
折叠