Windows7配置GPU和Theano编程环境

可参考Windows安装Theano官方教程:
http://deeplearning.net/software/theano/install_windows.html#install-windows
但是内容太多,不看也罢,很多软件已经不需要配置,或者是冗余的。如果你恰好和我一样都是Windows系统,Nvidia带GPU显卡,且你安装的时间离现在2016/02/03的日子还比较近,那么按照下面的顺序装机吧:
1. 安装Nvidia显卡驱动,官网:
http://www.nvidia.cn/Download/index.aspx?lang=cn
2. 安装Visual_Studio:
https://www.visualstudio.com/
3. 安装JDK
http://www.oracle.com/technetwork/java/javase/downloads/index.html
4. 安装CUDA 使用GPU加速(选择自己的配置,如Windows – x86_64-7-local)
https://developer.nvidia.com/cuda-downloads
5. 安装ANACOND可以免去安装很多Python库的麻烦:
https://www.continuum.io/downloads#_windows
6. Python IDE: PyCharm:
http://www.jetbrains.com/pycharm/download/#section=windows
7. 配置G++
官网给的建议是安装TDM-GCC(http://tdm-gcc.tdragon.net/),但是我安装之后出现g++加载错误,不确定是不是版本不匹配的问题。在参考博文(http://blog.sina.com.cn/s/blog_96b836170102vq22.html)中提到可以安装MinGW解决g++问题,解决方案为:在cmd输入:conda install mingw libpython,MinGW等文件夹会自动装到anaconda下面。
8. 安装Theano
https://github.com/Theano/Theano/archive/master.zip
解压,进入目录在命令行中执行“python setup.py develop
9. 配置GPU和G++编译环境:创建文件C:Usersjacoxu.theanorc,内容如下:

  1. [global]   
  2. device = gpu   
  3. floatX = float32   
  4.   
  5. [nvcc]   
  6. compiler_bindir=C:Program Files (x86)Microsoft Visual Studio 12.0VCin   
  7. cxxflags = -IC:Anaconda2MinGW  

重启电脑

10. 测试
import theano
==输出以下信息=====
Using gpu device 0: GeForce GT 970 (CNMeM is disabled)
注意:第一次使用一些库的时候,theano会自己创建库并打印一些信息,第二次再使用时则不会出现。另外打印信息中出现(CNMeM is disabled),有些用户则没有此信息或者是(CNMeM is enabled),目前尚未确定此信息为何意,但是并不影响Theano和GPU的正常使用。
根据官网给出的示例程序测试当前环境下是否可以正常使用GPU:
http://deeplearning.net/software/theano/tutorial/using_gpu.html#using-gpu

  1. from theano import function, config, shared, sandbox   
  2. import theano.tensor as T   
  3. import numpy   
  4. import time  
  5.   
  6. vlen = 10 * 30 * 768 # 10 x #cores x # threads per core   
  7. iters = 1000   
  8.   
  9. rng = numpy.random.RandomState(22)   
  10. x = shared(numpy.asarray(rng.rand(vlen), config.floatX))   
  11. f = function([], T.exp(x))   
  12. print(f.maker.fgraph.toposort())   
  13. t0 = time.time()   
  14. for i in xrange(iters):   
  15. r = f()   
  16. t1 = time.time()   
  17. print(“Looping %d times took %f seconds” % (iters, t1 - t0))   
  18. print(“Result is %s” % (r,))   
  19. if numpy.any([isinstance(x.op, T.Elemwise) for x in f.maker.fgraph.toposort()]):   
  20. print(‘Used the cpu’)   
  21. else:   
  22. print(‘Used the gpu’)  

如果GPU正常使用,则应该输出如下:
D:>python check1.py
Using gpu device 0: GeForce GTX 970 (CNMeM is disabled)
[GpuElemwise{exp,no_inplace}(), HostFromGpu(Gp
uElemwise{exp,no_inplace}.0)]
Looping 1000 times took 0.858000 seconds
Result is [ 1.23178029 1.61879349 1.52278066 ..., 2.20771813 2.29967761
1.62323296]
Used the gpu

大功告成~!如有问题请留言,祝各位好运!Cross fingers~~

博文出处:http://jacoxu.com/?p=1810

原文地址:https://www.cnblogs.com/GarfieldEr007/p/5342700.html