Pytorch、theano+cuda配置

Pytorch与theano的cuda 配置:

一、pytorch 无需安装cuda与cudnn,直接使用官网命令“conda install pytorch torchvision cudatoolkit==10.2 -c pytorch”(版本自行选择)即可

二、theano cuda加速需要先安装cuda与cudnn(9.0已成功,切记使用.run文件安装,跳过nvidia显卡驱动安装!!),完成安装后再安装theano(conda install theano,直接安装最新版本1.0.5),并且在pycharm的terminal或吃哦那大虚拟环境中输入命令“conda install cudatoolkit 自动安装8.0版本”。最后进行GPU配置,输入命令“sudo gedit ~/.theanorc”,编辑内容如下:
[cuda]
root=/usr/local/cuda-9.0
[global]
device=cuda
floatX=float32
[nvcc]
fastmath=True
完成后采用测试代码:

from theano import function, config, shared, tensor
import numpy
import time
 
vlen = 10 * 30 * 768  # 10 x #cores x # threads per core
iters = 1000
 
rng = numpy.random.RandomState(22)
x = shared(numpy.asarray(rng.rand(vlen), config.floatX))
f = function([], tensor.exp(x))
print(f.maker.fgraph.toposort())
t0 = time.time()
for i in range(iters):
    r = f()
t1 = time.time()
print("Looping %d times took %f seconds" % (iters, t1 - t0))
print("Result is %s" % (numpy.asarray(r),))
if numpy.any([isinstance(x.op, tensor.Elemwise) and
              ('Gpu' not in type(x.op).__name__)
              for x in f.maker.fgraph.toposort()]):
    print('Used the cpu')
else:
    print('Used the gpu')
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值