一、基础准备
1.安装python
2.安装anaconda
3.在anaconda中安装theano
二、CUDA安装
1.下载CUDA和cudnn(版本一定要对应)
CUDA:https://developer.nvidia.com/cuda-downloads
cudnn:https://developer.nvidia.com/rdp/cudnn-archive
2.将cudnn压缩包中的文件复制到CUDA安装目录中,选择覆盖。
3.用CMD命令行中输入查询nvcc -V
,如果能够正确显示版本信息就表明安装成功。
三、其他配置
1.在C:\Users\WP目录下创建文件“.theanorc.txt”
文件内容为:
device = cuda
floatX = float32
四、使用python测试是否为GPU运行
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" % (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')
若输出结果为:
测试输出结果
则表明环境配置成功。
网友评论