用python做GPU计算(1)——安装以及配置

实验小白鼠:联想Y470 显卡 GT550M 操作系统 ubuntu12.04 64位 python2.7

ubuntu12.04 需要重新安装显卡驱动,不过可以直接安装

cuda_5.0.35_linux_64_ubuntu11.10-1.run 程序包,会一并更新显卡驱动

这是官方的下载地址https://developer.nvidia.com/cuda-downloads,ubuntu12.04系统安装11.10即可。 alt+ctrl+F1进入终端 chmod a+x cuda_5.0.35_linux_32_ubuntu11.10.run sudo sh cuda_5.0.35_linux_64_ubuntu11.10-1.run 经过一段时间,然后重新启动就可以了。

由于不同的系统和机器型号会导致各种各样的问题,所以这里难以面面具到,建议大家安装之前多百度谷歌。

这里只提一点:由于Y470奇葩的双显卡切换模式,我们需要使用一款软件来管理双显卡:Bumblebee,它是一款可以管理双显卡的软件,能有效的减少平时耗电,提高视频性能。 安装过程如下

<!-- lang: shell -->
sudo add-apt-repository ppa:bumblebee/stable
sudo apt-get update
sudo apt-get install bumblebee bumblebee-nvidia

重启后,执行

<!-- lang: shell -->
optirun glxspheres

可以验证显卡的运行情况

<!-- lang: shell -->
lspci | grep -i vga

可以查看显卡的型号

http://mathema.tician.de/software/pycuda 是pycuda的主页,我们用他来做python上面的GPU运算 https://pypi.python.org/pypi/pycuda 这里可以安装pycuda,也可以直接

<!-- lang: shell -->
sudo easy_install pycuda

在终端中通过GPU启动python,键入命令

<!-- lang: shell -->
optirun python

然后在交互界面输入

<!-- lang: python -->
import pycuda.driver as cuda
import pycuda.autoinit
from pycuda.compiler import SourceModule

三条命令都没有问题了,说明已经成功安装好了cuda环境。可以import driver说明cuda程序安装正确,可以autoinit 说明显卡配置正确,失败的画需要google错误信息,应该都能找到

由于要用optirun 命令在终端执行来使应用程序可以使用GPU,我平时习惯使用eclipse,所以要加入eclipse的软链接,在终端键入以下命令:

<!-- lang: shell -->
cd /usr/local/bin
sudo ln -s /home/chenyu/eclipse/eclipse/eclipse 

然后输入optirun eclipse 就可以在eclipse中正确的import pycuda模块了

PS,GPU运算会产生大量热量,请做好散热工作,不然的话很容易黑屏。。。

转载于:https://my.oschina.net/chenyublog/blog/143242

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值