请问conda如何安装pyCUDA

安装pycuda还挺麻烦的,我觉得它更适合windows安装,并且不使用虚拟环境,可以灵活设置环境变量以及查找cuda安装路径。否则编译安装,或者驱动的升级,依赖包的安装,cuda环境变量位置的指定,会让你很难受。

0. 写在前面

安装环境:ubuntu18.04(16和18差不多,但是18太爽了)和python3(具体版本忘了,应该是3.6)

参考链接:参考了验证程序

1. 安装pyCUDA之前必须安装CUDA

    参考本人上一个博客

2.安装pyCUDA

    首先用pip3安装一般服务器会超时,这个时候也可以用清华源或者其他国内源安装,标准命令是"pip3 install pycuda",但是这种安装方式我没试过。

   如果用sudo apt install python3-pycuda会发现这个包并不是最新包,除非降低显卡驱动版本,反正我不愿意。

   以下是本人实测的方法。

   pyCUDA各版本的变化可以参考这个,最新的编译包贴在,python.org上也有,github有各版本压缩包,安装步骤参考这个的第一步和第三步(如下图),第二步忽略(一般都是安装numpy了的),注意对于python3第三步中的"python configure.py ..."改成"python3 ..."

 

3. 检验pyCUDA安装

    新建py脚本如下


   
   
  1. import pycuda
  2. import pycuda.driver as drv
  3. drv.init()
  4. print( 'CUDA device query (PyCUDA version) \n')
  5. print( 'Detected {} CUDA Capable device(s) \n'. format(drv.Device.count()))
  6. for i in range(drv.Device.count()):
  7. gpu_device = drv.Device(i)
  8. print( 'Device {}: {}'. format( i, gpu_device.name() ) )
  9. compute_capability = float( '%d.%d' % gpu_device.compute_capability() )
  10. print( '\t Compute Capability: {}'. format(compute_capability))
  11. print( '\t Total Memory: {} megabytes'. format(gpu_device.total_memory()//( 1024** 2)))
  12. # The following will give us all remaining device attributes as seen
  13. # in the original deviceQuery.
  14. # We set up a dictionary as such so that we can easily index
  15. # the values using a string descriptor.
  16. device_attributes_tuples = gpu_device.get_attributes().items()
  17. device_attributes = {}
  18. for k, v in device_attributes_tuples:
  19. device_attributes[ str(k)] = v
  20. num_mp = device_attributes[ 'MULTIPROCESSOR_COUNT']
  21. # Cores per multiprocessor is not reported by the GPU!
  22. # We must use a lookup table based on compute capability.
  23. # See the following:
  24. # http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#compute-capabilities
  25. cuda_cores_per_mp = { 5.0 : 128, 5.1 : 128, 5.2 : 128, 6.0 : 64, 6.1 : 128, 6.2 : 128}[compute_capability]
  26. print( '\t ({}) Multiprocessors, ({}) CUDA Cores / Multiprocessor: {} CUDA Cores'. format(num_mp, cuda_cores_per_mp, num_mp*cuda_cores_per_mp))
  27. device_attributes.pop( 'MULTIPROCESSOR_COUNT')
  28. for k in device_attributes.keys():
  29. print( '\t {}: {}'. format(k, device_attributes[k]))

    应该得到输出结果如下


   
   
  1. CUDA device query (PyCUDA version)
  2. Detected 1 CUDA Capable device(s)
  3. Device 0: GeForce GTX 1060
  4. Compute Capability: 6.1
  5. Total Memory: 6078 megabytes
  6. (10) Multiprocessors, (128) CUDA Cores / Multiprocessor: 1280 CUDA Cores
  7. ASYNC_ENGINE_COUNT: 2
  8. CAN_MAP_HOST_MEMORY: 1
  9. CLOCK_RATE: 1733000
  10. COMPUTE_CAPABILITY_MAJOR: 6
  11. COMPUTE_CAPABILITY_MINOR: 1
  12. COMPUTE_MODE: DEFAULT
  13. CONCURRENT_KERNELS: 1
  14. ....
  15. ....
  16. TEXTURE_PITCH_ALIGNMENT: 32
  17. TOTAL_CONSTANT_MEMORY: 65536
  18. UNIFIED_ADDRESSING: 1
  19. WARP_SIZE: 32

 

我觉得这个小哥写得还算可以,如果系统合适软件匹配,那么照着官网安装起来应该也不难。但往往人们会使用其他各种环境,比如linux,conda等,这就会导致一些问题,甚至导致环境需要重新安装。

例如:

https://www.lfd.uci.edu/~gohlke/pythonlibs/#pycuda
https://mathema.tician.de/software/pycuda/
https://gitcode.net/mirrors/inducer/pycuda?utm_source=csdn_github_accelerator
https://blog.csdn.net/zziahgf/article/details/74640889

编译暗转安装弄,pip直接安装会报错:

https://blog.csdn.net/quantum7/article/details/83548723

还有的人说cuda.h找不到了:

https://www.freesion.com/article/30071156594/

有的人说版本不对:

https://blog.csdn.net/qq_63019407/article/details/123707287
https://blog.csdn.net/weixin_45885232/article/details/106210807
https://www.jianshu.com/p/c5b8ae1b99ce

windows?pycuda的更新很慢,这些个牵扯到c的编译工具安装一般都很麻烦。

https://blog.csdn.net/Blue_Whale2020/article/details/122012760

有的人说设置环境变量:

https://blog.csdn.net/z649431508/article/details/102562859
https://blog.51cto.com/u_13161667/4983498
https://blog.csdn.net/Chris_zhangrx/article/details/90170973

真的能安装好,效果还不错:

https://blog.csdn.net/qq_35397715/article/details/111788622

我也知道要先装cuda,可是啊,conda表示找不到啊:

http://t.zoukankan.com/hzcya1995-p-13281732.html
您也知道cuda路径可能没有啊:
https://blog.csdn.net/qq_43314783/article/details/107582671

这个小哥安装倒是生猛,只能说你的环境很好:

https://blog.csdn.net/weixin_34910922/article/details/117451337
https://blog.csdn.net/jacke121/article/details/109400466

nvcc在conda环境下也很难找:

https://blog.csdn.net/qq_40290810/article/details/124253840

stackoverflow上也有一些提问:

https://stackoverflow.com/questions/53042921/anaconda-install-pycuda

关于【conda虚拟环境安装CUDA路径】:

https://blog.csdn.net/Mr__George/article/details/102972958
https://blog.csdn.net/weixin_42303803/article/details/116691022
https://blog.csdn.net/qq_36642243/article/details/109641330

还是有难度啊:

https://blog.csdn.net/weixin_43240387/article/details/89354160

我也想用下pycuda,各位大佬们有用linux的conda环境安装成功的,希望不吝赐教:

https://recomm.cnblogs.com/blogpost/12559576?page=1
https://www.cnblogs.com/qxcheng/p/12559576.html
https://blog.csdn.net/baobei0112/article/details/101224056

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值