WINDOWS10 Theano Enable Gpu:cuda + Anaconda

Source: Internet
Author: User
Tags theano nvcc

Recently in the study of deep learning related content, according to the example of each chapter in the http://deeplearning.net/tutorial/code. and refactoring part of the code, the code address is inside the https://github.com/wangzhics/deeplearning.

Deeplearning inside the code is based on http://deeplearning.net/software/theano/tutorial/index.html#tutorial, Theano we can define variables, Using its built-in formulas and combining them without worrying about the specific implementation process can speed up our learning. Theano in the code can run on the GPU, the front in order to quickly learn the algorithm, has not been tossing this, the two smallpox time to fix.

In fact, the official document Http://deeplearning.net/software/theano/install_windows.html#gpu-windows has been compared, but because it is based on the older version of the software introduced, There are some problems with the new version, and here are some records of the process

The installation of Cuda is an interface that NVIDIA can use for GPU programming with C + +, officially https://developer.nvidia.com/cuda-downloads, with the latest version of 7.5. Cuda requires C + + compilers, Windows can use Visual C + +, we can directly download their official website recommended visual Studio. However note: CUDA 7.5 does not support vs, http://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/#axzz46v2MC6l8, I chose vs. Express.
Cuda and VS2013 directly download the installation is good, do not need to set up, first add system environment variables
Cuda in the installation may be reminded that the system cannot find the VS environment, this does not matter, we install VS2013 just to give Cuda compiled environment. We can run Cuda provided examples to determine if Cuda is installed, open C:\ProgramData\NVIDIA Corporation\cuda samples\v7.5\1_utilities\devicequery run directly DeviceQuery.cpp, you can see your video card device information, so Cuda installed Theano Windows has a lot of Python scientific computing distribution kit, I directly use the Anaconda, its installation is simple and convenient, the official https:/ /www.continuum.io/downloads, I use the python3.x version (ie Anaconda3), directly download the installation package to install just fine. Note: Many tutorials on the web are said to run directly
Conda Install MinGW Libpython
To install MinGW and Libpython, the following error occurs when you use the python3.x anaconda only if the Mingw,libpython is installed correctly and cannot be installed successfully
C:\users\wangz>conda Install libpythonusing Anaconda Cloud API site Https://api.anaconda.orgFetching Package Metadata: .... Solving Package Specifications: ....  The following specifications were found to being in conflict:-Conda, Conda-env-conda, Menuinst-conda Pycosat-conda, Python 2.7*|3.3*|3.4*-Conda, Pyyaml-conda, Requests-conda-env (target=conda-env -2.4.5-py35_0.tar.bz2), Python 2.7*|3.3*|3.4*|3.5*-Libpython, Python 2.6*|2.7*|3.3*|3.4*-Menuinst (target= menuinst-1.3.2-py35_0.tar.bz2), Python 2.6*|2.7*|3.3*|3.4*|3.5*-pip (target=pip-8.1.1-py35_1.tar.bz2), Python 2.7*|3.3*|3.4*-Pycosat (target=pycosat-0.6.1-py35_0.tar.bz2)-Python 2.6*|2.7*|3.3*|3.4*|3.5*-python 3.5 *-Pyyaml (target=pyyaml-3.11-py35_3.tar.bz2), Python 2.6*|2.7*|3.3*|3.4*-Requests (target=requests-2.9.1-py35_ 0.tar.bz2), Python 2.6*|2.7*|3.3*|3.4*|3.5*-Setuptools (target=setuptools-20.3-py35_0.tar.bz2), PythOn 2.6*|2.7*|3.3*|3.4*|3.5*-Wheel (target=wheel-0.29.0-py35_0.tar.bz2), Python 2.7*|3.3*|3.4*|3.5*use "Conda Info <package> "To see the dependencies for each package.
This is because Libpython only supports python3.4.x, and ANACONDA3 default environment is python3.5.1
C:\users\wangz>conda info libpythonusing Anaconda Cloud API site https://api.anaconda.orgFetching Package metadata:.. .. Libpython 1.0 py26_0--------------------file name   : Libpython-1.0-py26_0.tar.bz2name        : Libpythonversion     : 1.0build number:0build string:py26_0channel     : defaultssize        : kbdate        : 2014-08-22license_family: OTHERMD5         : 11614b71090b7ad155e033c14f8216dbinstalled environments:dependencies:    mingw 4.7    python 2.6* ... libpython 1.0 py34_1--------------------file name   : Libpython-1.0-py34_1.tar.bz2name        : Libpythonversion     : 1.0build number:1build string:py34_1channel     : defaultssize        : kbdate        : 2014-08-22license_ FAMILY:OTHERMD5         : b13c6d4f28d81e05f85cb50e0f6b63ebinstalled environments:dependencies:    mingw 4.7    Python 3.4*
What then? Anaconda is very powerful. We can create a specific version of the Python environment and execute the following command:
c:\users\wangz>cd/d E:\anaconda3\scriptse:\anaconda3\scripts>conda create-n python34 python=3.4.4Using Anaconda Cloud API Site https://api.anaconda.orgFetching Package metadata: .... Solving Package Specifications: ..... Package plan for installation in environment E:\anaconda3\envs\python34:the following packages would be Downloaded:pack            Age |                Build---------------------------|-----------------vs2010_runtime-10.00.40219.1|                0 1.1 MB python-3.4.4 |           4 31.7 MB setuptools-20.7.0 |           Py34_0 767 KB wheel-0.29.0 |           Py34_0 123 KB pip-8.1.1 |                                           Py34_1 1.6 MB------------------------------------------------------------         total:35.3 mbthe following NEW packages would be installed:pip:8.1.1-py34_1 python:    3.4.4-4Setuptools:20.7.0-py34_0 vs2010_runtime:10.00.40219.1-0 wheel:0.29.0-py34_0proceed ([y]/n)? yfetching Packages Vs2010_runtime 100% |###############################| time:0:00:09 121.08 kb/spython-3.4.4-4 100% |###############################| Time:0:02:51 194.47 kb/ssetuptools-20. 100% |###############################| time:0:00:05 134.58 kb/swheel-0.29.0-p 100% |###############################| time:0:00:01 81.65 kb/spip-8.1.1-py34 100% |###############################| Time:0:00:17 99.02 kb/sextracting Packages ... [Complete]|##################################################| 100%linking packages ... [Complete]|##################################################| 100%## to activate this environment, use:# > Activate python34#e:\anaconda3\scripts>
The directive creates an python3.4.4 environment under Env, and the file name is the-n parameter.
Then we need to point the old system parameters to our new Python3.4.4 instead of
and then reboot, be sure to restartAfter the Conda command is not available, you can use the absolute path reference, its location under anaconda3\scripts and then run "Conda install Libpython-n python34", Libpython depends on MinGW, MinGW will be installed automatically
E:\anaconda3\scripts>conda Install libpython-n python34using Anaconda Cloud API site https:// Api.anaconda.orgFetching Package metadata: .... Solving Package Specifications: ..... Package plan for installation in environment E:\anaconda3\envs\python34:the following packages would be Downloaded:pack            Age |                Build---------------------------|-----------------mingw-4.7 |           1 56.1 MB libpython-1.0 |                                           Py34_1 KB------------------------------------------------------------ total:56.2 mbthe following NEW packages would be installed:libpython:1.0-py34_1 Mingw:4.7-1proce Ed ([y]/n)? yfetching Packages Mingw-4.7-1.ta 100% |###############################| time:0:04:28 218.86 kb/slibpython-1.0-100% |###############################| time:0:00:01 72.85 kb/sextracting Packages ... [Complete]|##################################################| 100%linking packages ... [Complete]|##################################################| 100%e:\anaconda3\scripts>
Installing Theano Running "Pip install Theano" directly under script will make an error
E:\ANACONDA3\SCRIPTS&GT;CD E:\anaconda3\envs\python34\scriptse:\anaconda3\envs\python34\scripts>pip Install Theanocollecting theanocollecting scipy>=0.11 (from Theano) Using cached scipy-0.17.0.tar.gz complete output from C Ommand python setup.py egg_info:non-existing path in ' numpy\\distutils ': ' Site.cfg ' Running from NumPy source Direc    Tory. C:\users\wangz\appdata\local\temp\easy_install-z7doyvws\numpy-1.11.0\setup.py:327:userwarning:unrecognized Setuptools command, proceeding with generating cython sources and expanding templates Warnings.warn ("Unrecognized set Uptools command, proceeding with "File" E:\Anaconda3\envs\python34\lib\site-packages\setuptools-20.7.0-py3 .4.egg\pkg_resources\__init__.py ", line 1104, in obtain File" E:\Anaconda3\envs\python34\lib\site-packages\setuptool s-20.7.0-py3.4.egg\setuptools\dist.py ", line 380, in Fetch_build_egg File" E:\Anaconda3\envs\python34\lib\site-packa Ges\setuptools-20.7.0-py3.4.egg\setuptools\command\easy_install.py ", line 640, in Easy_install File" E:\Anaconda3\envs\python34\lib\site-packages\setuptools- 20.7.0-py3.4.egg\setuptools\command\easy_install.py ", line 670, in Install_item File" E:\Anaconda3\envs\python34\lib \site-packages\setuptools-20.7.0-py3.4.egg\setuptools\command\easy_install.py ", line 850, in Install_eggs File" E:\A naconda3\envs\python34\lib\site-packages\setuptools-20.7.0-py3.4.egg\setuptools\command\easy_install.py ", line 1078, in Build_and_install File "E:\Anaconda3\envs\python34\lib\site-packages\setuptools-20.7.0-py3.4.egg\ setuptools\command\easy_install.py ", line 1066, in Run_setup Distutils.errors.DistutilsError:Setup script exited with    Error:microsoft Visual C + + 10.0 is required (unable to find Vcvarsall.bat). ----------------------------------------Command "python setup.py egg_info" failed with the error code 1 in C:\Users\WangZ\ Appdata\local\temp\pip-build-y5922frd\scipye:\anaconda3\envs\python34\scripts>

This is because we do not have a Python build environment, Python relies on VC2010, we can install VC2010 and then run Vcvarsall.bat under VC2010 in the command line, but Anaconda provides an easier way
E:\anaconda3\scripts>conda Install scipy-n python34using Anaconda Cloud API site Https://api.anaconda.orgFetching Package metadata: .... Solving Package Specifications: ..... Package plan for installation in environment E:\anaconda3\envs\python34:the following packages would be Downloaded:pack            Age |           Build---------------------------|-----------------numpy-1.11.0 |      PY34_0 2.7 MB scipy-0.17.0 |                                           Np111py34_1 10.3 MB------------------------------------------------------------    total:13.0 mbthe following NEW packages would be installed:mkl:11.3.1-0 Numpy:1.11.0-py34_0 Scipy:0.17.0-np111py34_1proceed ([y]/n)? yfetching Packages Numpy-1.11.0-p 100% |###############################| Time:0:00:18 147.81 kb/sscipy-0.17.0-n 100% |###############################| time:0:01:06 162.73 kb/sextracting Packages ... [CompletE]|##################################################| 100%linking packages ... [Complete]|##################################################| 100%e:\anaconda3\scripts>
E:\anaconda3\envs\python34\scripts>pip Install theanocollecting theanorequirement already satisfied (use--upgrade To upgrade): numpy>=1.7.1 in E:\anaconda3\envs\python34\lib\site-packages (from Theano) collecting six>=1.9.0 ( From Theano)  Using cached six-1.10.0-py2.py3-none-any.whlrequirement already satisfied (use--upgrade to upgrade): scipy>=0.11 in E:\anaconda3\envs\python34\lib\site-packages (from Theano) installing collected Packages:six, Theanosuccessfully installed six-1.10.0 theano-0.8.2e:\anaconda3\envs\python34\scripts>
Configure Theano to create a new ". Theanorc.txt" document under the personal home folder, such as my in C:\Users\WangZ, how the document is configured for reference http://deeplearning.net/software/theano/ Library/config.html
[GLOBAL]FLOATX = Float32device = Gpu[nvcc]flags=-le:\anaconda3\envs\python34\libscompiler_bindir=c:/program Files ( x86)/microsoft Visual Studio 12.0/vc/bin
Run results Reference http://deeplearning.net/software/theano/tutorial/using_gpu.html python test script inside
From Theano import function, config, shared, Sandboximport theano.tensor as timport numpyimport Timevlen = ten * 768
   # x #cores x # threads per coreiters = 1000RNG = Numpy.random.RandomState 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 ')
Run directly, will error
Unicodedecodeerror: ' Utf-8 ' codec can ' t decode byte 0xd5 in position 11:invalid continuation byte
This is because the string returned with NVCC is used cwindows default encoding, the source error is changed to *.decode ("GBK") can, then changed the source forgotten ...
E:\Anaconda3\envs\python34\python.exe e:/ml/deeplearning/test_gpu.pyusing GPU Device 0:geforce GT 750M (Cnmem is Disabled, CuDNN not available) DEBUG:NVCC STDOUT mod.cu Creating library C:/users/wangz/appdata/local/theano/compiledir_ windows-10-10.0.10586-intel64_family_6_model_58_stepping_9_genuineintel-3.4.4-64/tmp313wmfq0/ Meb404c8cd39208f6884dd773b584b7d7.lib and Object C:/users/wangz/appdata/local/theano/compiledir_ windows-10-10.0.10586-intel64_family_6_model_58_stepping_9_genuineintel-3.4.4-64/tmp313wmfq0/ MEB404C8CD39208F6884DD773B584B7D7.EXPDEBUG:NVCC STDOUT Mod.cu is creating the library C:/users/wangz/appdata/local/theano/compiledir _windows-10-10.0.10586-intel64_family_6_model_58_stepping_9_genuineintel-3.4.4-64/tmpk8he1yq1/ Md9b7b5ef5d727b2e8e3d2cc34bb9d0eb.lib and Object C:/users/wangz/appdata/local/theano/compiledir_ windows-10-10.0.10586-intel64_family_6_model_58_stepping_9_genuineintel-3.4.4-64/tmpk8he1yq1/ MD9B7B5EF5D727B2E8E3D2CC34BB9D0EB.EXPDEBUG:NVCC STDOUT Mod.cu is creating the library c:/users/wangz/appdata/local/theano/compiledir_windows-10-10.0.10586-intel64_family_6_model_58_stepping_9_genuineintel-3.4.4-64/tmp3mv9lkx8/ Mfeb646abb02bed7115bdc204940fcfff.lib and Object C:/users/wangz/appdata/local/theano/compiledir_ windows-10-10.0.10586-intel64_family_6_model_58_stepping_9_genuineintel-3.4.4-64/tmp3mv9lkx8/ Mfeb646abb02bed7115bdc204940fcfff.exp[gpuelemwise{exp,no_inplace} (<cudandarraytype (float32, Vector) >), Hostfromgpu (gpuelemwise{exp,no_inplace}.0)]looping Times took 1.319867 secondsresult is [1.23178029 1.61879349 1.5 2278066, 2.20771813 2.29967761 1.62323296]used the GPU
Bingo! Precautions
    1. The version of CUBE and VS must be selected, and the path to the VS is added to the environment variable
    2. Anaconda is only responsible for Python-related, it can install those in the machine can not compile the module, is automatically help you manage a mingw, if you want to manually install a MinGW is also possible
    3. Theano development environment is older, but the principle is Python call dynamic library, step by step, the problem of more than Google
A) If the following error occurs because the Libpython is not installed, or the environment variable is not changed after the newly created python3.4.4 environment
c:\users\wangz\appdata\local\temp\ccu0pnp5.o:in function ' _import_array ': e:/anaconda3/lib/site-packages/numpy/ core/include/numpy/__multiarray_api.h:1641:undefined reference to ' __imp_pyexc_importerror ' E:/Anaconda3/lib/ site-packages/numpy/core/include/numpy/__multiarray_api.h:1647:undefined reference to ' __imp_pyexc_ Attributeerror ' e:/anaconda3/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h:1652:undefined Reference to ' __imp_pycapsule_type ' e:/anaconda3/lib/site-packages/numpy/core/include/numpy/__multiarray_api.h : 1653:undefined reference to ' __imp_pyexc_runtimeerror '
b) There is no need to have GCC configured in the. Theanorc.txt, because there is already an environment variable inside the Anaconda








WINDOWS10 Theano Enable Gpu:cuda + Anaconda

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.