安装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脚本如下
-
import pycuda
-
import pycuda.driver
as drv
-
drv.init()
-
print(
'CUDA device query (PyCUDA version) \n')
-
print(
'Detected {} CUDA Capable device(s) \n'.
format(drv.Device.count()))
-
for i
in
range(drv.Device.count()):
-
-
gpu_device = drv.Device(i)
-
print(
'Device {}: {}'.
format( i, gpu_device.name() ) )
-
compute_capability =
float(
'%d.%d' % gpu_device.compute_capability() )
-
print(
'\t Compute Capability: {}'.
format(compute_capability))
-
print(
'\t Total Memory: {} megabytes'.
format(gpu_device.total_memory()//(
1024**
2)))
-
-
# The following will give us all remaining device attributes as seen
-
# in the original deviceQuery.
-
# We set up a dictionary as such so that we can easily index
-
# the values using a string descriptor.
-
-
device_attributes_tuples = gpu_device.get_attributes().items()
-
device_attributes = {}
-
-
for k, v
in device_attributes_tuples:
-
device_attributes[
str(k)] = v
-
-
num_mp = device_attributes[
'MULTIPROCESSOR_COUNT']
-
-
# Cores per multiprocessor is not reported by the GPU!
-
# We must use a lookup table based on compute capability.
-
# See the following:
-
# http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#compute-capabilities
-
-
cuda_cores_per_mp = {
5.0 :
128,
5.1 :
128,
5.2 :
128,
6.0 :
64,
6.1 :
128,
6.2 :
128}[compute_capability]
-
-
print(
'\t ({}) Multiprocessors, ({}) CUDA Cores / Multiprocessor: {} CUDA Cores'.
format(num_mp, cuda_cores_per_mp, num_mp*cuda_cores_per_mp))
-
-
device_attributes.pop(
'MULTIPROCESSOR_COUNT')
-
-
for k
in device_attributes.keys():
-
print(
'\t {}: {}'.
format(k, device_attributes[k]))
应该得到输出结果如下
CUDA device query (PyCUDA version) Detected 1 CUDA Capable device(s) Device 0: GeForce GTX 1060 Compute Capability: 6.1 Total Memory: 6078 megabytes (10) Multiprocessors, (128) CUDA Cores / Multiprocessor: 1280 CUDA Cores ASYNC_ENGINE_COUNT: 2 CAN_MAP_HOST_MEMORY: 1 CLOCK_RATE: 1733000 COMPUTE_CAPABILITY_MAJOR: 6 COMPUTE_CAPABILITY_MINOR: 1 COMPUTE_MODE: DEFAULT CONCURRENT_KERNELS: 1 .... .... TEXTURE_PITCH_ALIGNMENT: 32 TOTAL_CONSTANT_MEMORY: 65536 UNIFIED_ADDRESSING: 1 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