当前位置: 首页 > news >正文

测试Theano使用GPU并行计算,以验证环境搭建是否成功

一、前提

安装好了cuda和theano

二、测试

(1)创建一个test.py文件
添加如下内容

from theano import function, config, shared, sandbox
import theano.tensor as T
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([], T.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, T.Elemwise) for x in f.maker.fgraph.toposort()]):
    print('Used the cpu')
else:
    print('Used the gpu')

保存。
(2)创建.theanorc文件
文件中添加如下内容

[global]
floatX=float32
device=cpu

终端输入命令

sudo vi ~/.theanorc

这里先测试cpu,测试完成后,修改成device=gpu,对比速度.
(3)执行文件
终端输入

python test.py

(4)测试结果
1.cpu
这里写图片描述
会看到cpu测试用了3秒多
2.gpu
这里写图片描述
相比cpu,gpu、使用了仅仅0.8秒
3.若无问题,即环境搭建成功

三、测试失败的解决办法

提示:
ERROR (theano.sandbox.cuda): Failed to compile cuda_ndarray.cu: libcublas.so.7.5: cannot open shared object file: No such file or directory
WARNING (theano.sandbox.cuda): CUDA is installed, but device gpu is not available (error: cuda unavilable) TensorType(float32, vector)>)]
Looping 1000 times took 3.337314 seconds
Result is [ 1.23178029 1.61879337 1.52278066 …, 2.20771813 2.29967761
1.62323284]

解决办法:
(a)检查cuda的环境变量是否配好
(b)终端输入命令

sudo ldconfig /usr/local/cuda/lib64

相关文章:

  • 安装cuda的错误解决办法
  • Anaconda 安装编译pycaffe
  • 服务器(多GPU)caffe安装和编译
  • DIGITS安装和配置
  • SeetaFaceEngine安装和测试
  • yolo的安装和使用
  • yolo-v1 train和test自己的分类和数据
  • yolo-v2修改只识别person
  • zigbee编译错误汇总(一)
  • 1.The Graphics View Architecture(图形视图框架)
  • 3.The Graphics View Coordinate System(图形视图坐标系)
  • 2.Classes in the Graphics View Framework(图形视图框架中的类)
  • 4.Key Features(主要特征)
  • 5.Performance(性能)
  • linux解决wifi问题
  • CEF与代理
  • centos安装java运行环境jdk+tomcat
  • Javascript设计模式学习之Observer(观察者)模式
  • Java比较器对数组,集合排序
  • Java方法详解
  • Linux各目录及每个目录的详细介绍
  • Otto开发初探——微服务依赖管理新利器
  • PyCharm搭建GO开发环境(GO语言学习第1课)
  • 猴子数据域名防封接口降低小说被封的风险
  • 理解在java “”i=i++;”所发生的事情
  • 利用阿里云 OSS 搭建私有 Docker 仓库
  • 深度学习中的信息论知识详解
  • 我有几个粽子,和一个故事
  • 学习JavaScript数据结构与算法 — 树
  • 用简单代码看卷积组块发展
  • 3月27日云栖精选夜读 | 从 “城市大脑”实践,瞭望未来城市源起 ...
  • AI又要和人类“对打”,Deepmind宣布《星战Ⅱ》即将开始 ...
  • Android开发者必备:推荐一款助力开发的开源APP
  • 翻译 | The Principles of OOD 面向对象设计原则
  • #define,static,const,三种常量的区别
  • #Linux(Source Insight安装及工程建立)
  • (173)FPGA约束:单周期时序分析或默认时序分析
  • (floyd+补集) poj 3275
  • (阿里巴巴 dubbo,有数据库,可执行 )dubbo zookeeper spring demo
  • (层次遍历)104. 二叉树的最大深度
  • (十二)python网络爬虫(理论+实战)——实战:使用BeautfulSoup解析baidu热搜新闻数据
  • (一)为什么要选择C++
  • (转)setTimeout 和 setInterval 的区别
  • .\OBJ\test1.axf: Error: L6230W: Ignoring --entry command. Cannot find argumen 'Reset_Handler'
  • .bat批处理(六):替换字符串中匹配的子串
  • .bat批处理出现中文乱码的情况
  • .NET Core IdentityServer4实战-开篇介绍与规划
  • .NET Core Web APi类库如何内嵌运行?
  • .net framework profiles /.net framework 配置
  • .NET I/O 学习笔记:对文件和目录进行解压缩操作
  • .net 程序发生了一个不可捕获的异常
  • .net 写了一个支持重试、熔断和超时策略的 HttpClient 实例池
  • .NET6实现破解Modbus poll点表配置文件
  • .net和jar包windows服务部署
  • .project文件