問題描述
我了解 Theano 對 Windows 8.1 的支持僅處于試驗階段,但我想知道是否有人能夠解決我的問題.根據我的配置,我得到三種不同類型的錯誤.我認為解決我的任何錯誤都會解決我的問題.
I understand that the Theano support for Windows 8.1 is at experimental stage only but I wonder if anyone had any luck with resolving my issues. Depending on my config, I get three distinct types of errors. I assume that the resolution of any of my errors would solve my problem.
我已經使用 WinPython 32 位系統安裝了 Python,使用了 此處所述的 MinGW.我的 .theanorc
文件內容如下:
I have installed Python using WinPython 32-bit system, using MinGW as described here. The contents of my .theanorc
file are as follows:
[global]
openmp=False
device = gpu
[nvcc]
flags=-LC:TheanoPythonpython-2.7.6libs
compiler_bindir=C:Program Files (x86)Microsoft Visual Studio 10.0VCin
[blas]
ldflags =
當我運行 import theano
時,錯誤如下:
When I run import theano
the error is as follows:
nvcc fatal : nvcc cannot find a supported version of Microsoft Visual Studio.
Only the versions 2010, 2012, and 2013 are supported
['nvcc', '-shared', '-g', '-O3', '--compiler-bindir', 'C:\Program Files (x86)\
Microsoft Visual Studio 10.0\VC\bin# flags=-m32 # we have this hard coded for
now', '-Xlinker', '/DEBUG', '-m32', '-Xcompiler', '-DCUDA_NDARRAY_CUH=d67f7c8a21
306c67152a70a88a837011,/Zi,/MD', '-IC:\TheanoPython\python-2.7.6\lib\site-pa
ckages\theano\sandbox\cuda', '-IC:\TheanoPython\python-2.7.6\lib\site-pac
kages\numpy\core\include', '-IC:\TheanoPython\python-2.7.6\include', '-o',
'C:\Users\Matej\AppData\Local\Theano\compiledir_Windows-8-6.2.9200-Intel6
4_Family_6_Model_60_Stepping_3_GenuineIntel-2.7.6-32\cuda_ndarray\cuda_ndarray
.pyd', 'mod.cu', '-LC:\TheanoPython\python-2.7.6\libs', '-LNone\lib', '-LNon
e\lib64', '-LC:\TheanoPython\python-2.7.6', '-lpython27', '-lcublas', '-lcuda
rt']
ERROR (theano.sandbox.cuda): Failed to compile cuda_ndarray.cu: ('nvcc return st
atus', 1, 'for cmd', 'nvcc -shared -g -O3 --compiler-bindir C:\Program Files (x
86)\Microsoft Visual Studio 10.0\VC\bin# flags=-m32 # we have this hard coded
for now -Xlinker /DEBUG -m32 -Xcompiler -DCUDA_NDARRAY_CUH=d67f7c8a21306c67152a
70a88a837011,/Zi,/MD -IC:\TheanoPython\python-2.7.6\lib\site-packages\thean
o\sandbox\cuda -IC:\TheanoPython\python-2.7.6\lib\site-packages\numpy\co
re\include -IC:\TheanoPython\python-2.7.6\include -o C:\Users\Matej\AppDa
ta\Local\Theano\compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_60_Stepp
ing_3_GenuineIntel-2.7.6-32\cuda_ndarray\cuda_ndarray.pyd mod.cu -LC:\TheanoP
ython\python-2.7.6\libs -LNone\lib -LNone\lib64 -LC:\TheanoPython\python-2
.7.6 -lpython27 -lcublas -lcudart')
WARNING (theano.sandbox.cuda): CUDA is installed, but device gpu is not availabl
e
我還使用安裝在我的系統上的 Visual Studio 12.0
對其進行了測試,但出現以下錯誤:
I have also tested it using Visual Studio 12.0
which is installed on my system with the following error:
mod.cu
nvlink fatal : Could not open input file 'C:/Users/Matej/AppData/Local/Temp/tm
pxft_00001b70_00000000-28_mod.obj'
['nvcc', '-shared', '-g', '-O3', '--compiler-bindir', 'C:\Program Files (x86)\
Microsoft Visual Studio 12.0\VC\bin\', '-Xlinker', '/DEBUG', '-m32', '-Xcompi
ler', '-LC:\TheanoPython\python-2.7.6\libs,-DCUDA_NDARRAY_CUH=d67f7c8a21306c6
7152a70a88a837011,/Zi,/MD', '-IC:\TheanoPython\python-2.7.6\lib\site-package
s\theano\sandbox\cuda', '-IC:\TheanoPython\python-2.7.6\lib\site-packages
\numpy\core\include', '-IC:\TheanoPython\python-2.7.6\include', '-o', 'C:
Users\Matej\AppData\Local\Theano\compiledir_Windows-8-6.2.9200-Intel64_Fam
ily_6_Model_60_Stepping_3_GenuineIntel-2.7.6-32\cuda_ndarray\cuda_ndarray.pyd'
, 'mod.cu', '-LC:\TheanoPython\python-2.7.6\libs', '-LNone\lib', '-LNone\li
b64', '-LC:\TheanoPython\python-2.7.6', '-lpython27', '-lcublas', '-lcudart']
ERROR (theano.sandbox.cuda): Failed to compile cuda_ndarray.cu: ('nvcc return st
atus', 1, 'for cmd', 'nvcc -shared -g -O3 --compiler-bindir C:\Program Files (x
86)\Microsoft Visual Studio 12.0\VC\bin\ -Xlinker /DEBUG -m32 -Xcompiler -LC
:\TheanoPython\python-2.7.6\libs,-DCUDA_NDARRAY_CUH=d67f7c8a21306c67152a70a88
a837011,/Zi,/MD -IC:\TheanoPython\python-2.7.6\lib\site-packages\theano\sa
ndbox\cuda -IC:\TheanoPython\python-2.7.6\lib\site-packages\numpy\core\i
nclude -IC:\TheanoPython\python-2.7.6\include -o C:\Users\Matej\AppData\L
ocal\Theano\compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_60_Stepping_3
_GenuineIntel-2.7.6-32\cuda_ndarray\cuda_ndarray.pyd mod.cu -LC:\TheanoPython
\python-2.7.6\libs -LNone\lib -LNone\lib64 -LC:\TheanoPython\python-2.7.6
-lpython27 -lcublas -lcudart')
WARNING (theano.sandbox.cuda): CUDA is installed, but device gpu is not availabl
e
在后一個錯誤中,有幾個彈出窗口詢問我在拋出錯誤之前如何打開 (.res) 文件.
In the latter error, several pop-up windows ask me how would I like to open (.res) file before error is thrown.
cl.exe
存在于兩個文件夾中(即 VS 2010 和 VS 2013).
cl.exe
is present in both folders (i.e. VS 2010 and VS 2013).
最后,如果我在環境路徑中設置VS 2013,并設置.theanorc
內容如下:
Finally, if I set VS 2013 in the environment path and set .theanorc
contents as follows:
[global]
base_compiledir=C:Program Files (x86)Microsoft Visual Studio 12.0VCin
openmp=False
floatX = float32
device = gpu
[nvcc]
flags=-LC:TheanoPythonpython-2.7.6libs
compiler_bindir=C:Program Files (x86)Microsoft Visual Studio 12.0VCin
[blas]
ldflags =
我收到以下錯誤:
c: heanopythonpython-2.7.6includepymath.h(22): warning: dllexport/dllimport conflict with "round"
c:program files
vidia gpu computing toolkitcudav6.5includemath_functions.h(2455): here; dllimport/dllexport dropped
mod.cu(954): warning: statement is unreachable
mod.cu(1114): error: namespace "std" has no member "min"
mod.cu(1145): error: namespace "std" has no member "min"
mod.cu(1173): error: namespace "std" has no member "min"
mod.cu(1174): error: namespace "std" has no member "min"
mod.cu(1317): error: namespace "std" has no member "min"
mod.cu(1318): error: namespace "std" has no member "min"
mod.cu(1442): error: namespace "std" has no member "min"
mod.cu(1443): error: namespace "std" has no member "min"
mod.cu(1742): error: namespace "std" has no member "min"
mod.cu(1777): error: namespace "std" has no member "min"
mod.cu(1781): error: namespace "std" has no member "min"
mod.cu(1814): error: namespace "std" has no member "min"
mod.cu(1821): error: namespace "std" has no member "min"
mod.cu(1853): error: namespace "std" has no member "min"
mod.cu(1861): error: namespace "std" has no member "min"
mod.cu(1898): error: namespace "std" has no member "min"
mod.cu(1905): error: namespace "std" has no member "min"
mod.cu(1946): error: namespace "std" has no member "min"
mod.cu(1960): error: namespace "std" has no member "min"
mod.cu(3750): error: namespace "std" has no member "min"
mod.cu(3752): error: namespace "std" has no member "min"
mod.cu(3784): error: namespace "std" has no member "min"
mod.cu(3786): error: namespace "std" has no member "min"
mod.cu(3789): error: namespace "std" has no member "min"
mod.cu(3791): error: namespace "std" has no member "min"
mod.cu(3794): error: namespace "std" has no member "min"
mod.cu(3795): error: namespace "std" has no member "min"
mod.cu(3836): error: namespace "std" has no member "min"
mod.cu(3838): error: namespace "std" has no member "min"
mod.cu(4602): error: namespace "std" has no member "min"
mod.cu(4604): error: namespace "std" has no member "min"
31 errors detected in the compilation of "C:/Users/Matej/AppData/Local/Temp/tmpxft_00001d84_00000000-10_mod.cpp1.ii".
ERROR (theano.sandbox.cuda): Failed to compile cuda_ndarray.cu: ('nvcc return status', 2, 'for cmd', 'nvcc -shared -g -O3 -Xlinker /DEBUG -m32 -Xcompiler -DCUDA_NDARRAY_CUH=d67f7c8a21306c67152a70a88a837011,/Zi,/MD -IC:\TheanoPython\python-2.7.6\lib\site-packages\theano\sandbox\cuda -IC:\TheanoPython\python-2.7.6\lib\site-packages\numpy\core\include -IC:\TheanoPython\python-2.7.6\include -o C:\Users\Matej\AppData\Local\Theano\compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_60_Stepping_3_GenuineIntel-2.7.6-32\cuda_ndarray\cuda_ndarray.pyd mod.cu -LC:\TheanoPython\python-2.7.6\libs -LNone\lib -LNone\lib64 -LC:\TheanoPython\python-2.7.6 -lpython27 -lcublas -lcudart')
ERROR:theano.sandbox.cuda:Failed to compile cuda_ndarray.cu: ('nvcc return status', 2, 'for cmd', 'nvcc -shared -g -O3 -Xlinker /DEBUG -m32 -Xcompiler -DCUDA_NDARRAY_CUH=d67f7c8a21306c67152a70a88a837011,/Zi,/MD -IC:\TheanoPython\python-2.7.6\lib\site-packages\theano\sandbox\cuda -IC:\TheanoPython\python-2.7.6\lib\site-packages\numpy\core\include -IC:\TheanoPython\python-2.7.6\include -o C:\Users\Matej\AppData\Local\Theano\compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_60_Stepping_3_GenuineIntel-2.7.6-32\cuda_ndarray\cuda_ndarray.pyd mod.cu -LC:\TheanoPython\python-2.7.6\libs -LNone\lib -LNone\lib64 -LC:\TheanoPython\python-2.7.6 -lpython27 -lcublas -lcudart')
mod.cu
['nvcc', '-shared', '-g', '-O3', '-Xlinker', '/DEBUG', '-m32', '-Xcompiler', '-DCUDA_NDARRAY_CUH=d67f7c8a21306c67152a70a88a837011,/Zi,/MD', '-IC:\TheanoPython\python-2.7.6\lib\site-packages\theano\sandbox\cuda', '-IC:\TheanoPython\python-2.7.6\lib\site-packages\numpy\core\include', '-IC:\TheanoPython\python-2.7.6\include', '-o', 'C:\Users\Matej\AppData\Local\Theano\compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_60_Stepping_3_GenuineIntel-2.7.6-32\cuda_ndarray\cuda_ndarray.pyd', 'mod.cu', '-LC:\TheanoPython\python-2.7.6\libs', '-LNone\lib', '-LNone\lib64', '-LC:\TheanoPython\python-2.7.6', '-lpython27', '-lcublas', '-lcudart']
如果我在沒有開啟 GPU 選項的情況下運行 import theano
,它會毫無問題地運行.CUDA 樣本也可以正常運行.
If I run import theano
without the GPU option on, it runs without a problem. Also CUDA samples run without a problem.
推薦答案
Theano 是機器學習應用程序的絕佳工具,但我發現它在 Windows 上的安裝并非易事,尤其是對于編程的初學者(如我自己)而言.在我的例子中,當我在 GPU 上運行時,我看到我的腳本加速了 5-6 倍,所以這絕對是值得的.
Theano is a great tool for machine learning applications, yet I found that its installation on Windows is not trivial especially for beginners (like myself) in programming. In my case, I see 5-6x speedups of my scripts when run on a GPU so it was definitely worth the hassle.
我根據我的安裝過程編寫了本指南,旨在詳細說明并希望完整,即使對于事先不了解在 Windows 環境下構建程序的人來說也是如此.本指南的大部分內容都是基于這些 instructions 但我不得不更改一些步驟為了讓它在我的系統上工作.如果我所做的任何事情可能不是最佳的或在您的機器上不起作用,請告訴我,我將嘗試相應地修改本指南.
I wrote this guide based on my installation procedure and is meant to be verbose and hopefully complete even for people with no prior understanding of building programs under Windows environment. Most of this guide is based on these instructions but I had to change some of the steps in order for it to work on my system. If there is anything that I do that may not be optimal or that doesn't work on your machine, please, let me know and I will try to modify this guide accordingly.
這些是我在 Windows 8.1 機器上安裝啟用 GPU 的 Theano 時遵循的步驟(按順序):
These are the steps (in order) I followed when installing Theano with GPU enabled on my Windows 8.1 machine:
CUDA 可以從這里下載.就我而言,我為配備 Geforce 750m 的 NVIDIA Optimus 筆記本電腦選擇了 64 位筆記本版本.
CUDA can be downloaded from here. In my case, I chose 64-bit Notebook version for my NVIDIA Optimus laptop with Geforce 750m.
通過從命令行啟動 deviceQuery
來驗證您的安裝是否成功.在我的情況下,它位于以下文件夾中: C:ProgramDataNVIDIA CorporationCUDA Samplesv6.5inwin64Release
.如果成功,您應該在測試結束時看到 PASS.
Verify that your installation was successful by launching deviceQuery
from command line. In my case this was located in the following folder: C:ProgramDataNVIDIA CorporationCUDA Samplesv6.5inwin64Release
. If successful, you should see PASS at the end of the test.
我是通過 dreamspark 安裝的.如果您是學生,您有權獲得免費版本.如果沒有,您仍然可以安裝 Express 版本 應該也可以.安裝完成后,您應該能夠從開始菜單調用 Visual Studio 命令提示符 2010.
I installed this via dreamspark. If you are a student you are entitled for a free version. If not, you can still install the Express version which should work just as well. After install is complete you should be able to call Visual Studio Command Prompt 2010 from the start menu.
在撰寫本文時,GPU 上的 Theano 僅允許使用 32 位浮點數,并且主要為 2.7 版本的 Python 構建.Theano 需要大多數基本的科學 Python 庫,例如 scipy
和 numpy
.我發現安裝這些的最簡單方法是通過 WinPython.它將所有依賴項安裝在一個獨立的文件夾中,如果安裝過程中出現問題,可以輕松重新安裝,并且您還可以免費安裝一些有用的 IDE 工具,例如 ipython notebook 和 Spyder.為了便于使用,您可能希望在 環境變量.
At the time of writing, Theano on GPU only allows working with 32-bit floats and is primarily built for 2.7 version of Python. Theano requires most of the basic scientific Python libraries such as scipy
and numpy
. I found that the easiest way to install these was via WinPython. It installs all the dependencies in a self-contained folder which allows easy reinstall if something goes wrong in the installation process and you get some useful IDE tools such as ipython notebook and Spyder installed for free as well. For ease of use you might want to add the path to your python.exe and path to your Scripts folder in the environment variables.
找到這里.
設置文件在這里.我在安裝過程中檢查了所有基本安裝文件.如果您遇到下面描述的 g++ 錯誤,這是必需的.
Setup file is here. I checked all the base installation files during the installation process. This is required if you run into g++ error described below.
您可以在這里找到它.我基本上只使用此實用程序來提取基本安裝中已經提供的 PyCUDA tar 文件(因此安裝應該很簡單).
You can find it here. I basically used this utility only to extract PyCUDA tar file which is already provided in the base install (so the install should be straightforward).
打開位于 Python 安裝的 /lib/distutils/
目錄中的 msvc9compiler.py
.在我的例子中,第 641 行顯示為:ld_args.append ('/IMPLIB:' + implib_file)
.在此行之后添加以下內容(相同的縮進):
Open msvc9compiler.py
located in your /lib/distutils/
directory of your Python installation. Line 641 in my case reads: ld_args.append ('/IMPLIB:' + implib_file)
. Add the following after this line (same indentation):
ld_args.append('/MANIFEST')
PyCUDA 安裝
PyCUDA 的來源是 這里.
步驟:
打開cygwin并導航到PyCUDA文件夾(即/cygdrive/c/etc/etc
)并執行tar -xzf pycuda-2012.1.tar.gz
.
Open cygwin and navigate to the PyCUDA folder (i.e. /cygdrive/c/etc/etc
) and execute tar -xzf pycuda-2012.1.tar.gz
.
打開 Visual Studio 命令提示符 2010 并導航到解壓縮 tarball 的目錄并執行 python configure.py
Open Visual Studio Command Prompt 2010 and navigate to the directory where tarball was extracted and execute python configure.py
打開 ./siteconf.py 并更改值以使其讀取(例如對于 CUDA 6.5):
Open the ./siteconf.py and change the values so that it reads (for CUDA 6.5 for instance):
BOOST_INC_DIR = []
BOOST_LIB_DIR = []
BOOST_COMPILER = 'gcc43'
USE_SHIPPED_BOOST = True
BOOST_PYTHON_LIBNAME = ['boost_python']
BOOST_THREAD_LIBNAME = ['boost_thread']
CUDA_TRACE = False
CUDA_ROOT = 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5'
CUDA_ENABLE_GL = False
CUDA_ENABLE_CURAND = True
CUDADRV_LIB_DIR = ['${CUDA_ROOT}/lib/Win32']
CUDADRV_LIBNAME = ['cuda']
CUDART_LIB_DIR = ['${CUDA_ROOT}/lib/Win32']
CUDART_LIBNAME = ['cudart']
CURAND_LIB_DIR = ['${CUDA_ROOT}/lib/Win32']
CURAND_LIBNAME = ['curand']
CXXFLAGS = ['/EHsc']
LDFLAGS = ['/FORCE']
在VS2010命令提示符下執行以下命令:
Execute the following commands at the VS2010 command prompt:
set VS90COMNTOOLS=%VS100COMNTOOLS%
python setup.py build
python setup.py install
創建這個 python 文件并驗證你是否得到了結果:
Create this python file and verify that you get a result:
# from: http://documen.tician.de/pycuda/tutorial.html
import pycuda.gpuarray as gpuarray
import pycuda.driver as cuda
import pycuda.autoinit
import numpy
a_gpu = gpuarray.to_gpu(numpy.random.randn(4,4).astype(numpy.float32))
a_doubled = (2*a_gpu).get()
print a_doubled
print a_gpu
安裝 Theano
打開 git bash shell 并選擇要放置 Theano 安裝文件的文件夾并執行:
Install Theano
Open git bash shell and choose a folder in which you want to place Theano installation files and execute:
git clone git://github.com/Theano/Theano.git
python setup.py install
嘗試在VS2010命令提示符下打開python并運行import theano
Try opening python in VS2010 command prompt and run import theano
如果您遇到與 g++ 相關的錯誤,請打開安裝在此處的 MinGW msys.bat:C:MinGWmsys1.0
并嘗試在 MinGW shell 中導入 theano.然后重試從 VS2010 命令提示符導入 theano,它現在應該可以工作了.
If you get a g++ related error, open MinGW msys.bat in my case installed here: C:MinGWmsys1.0
and try importing theano in MinGW shell. Then retry importing theano from VS2010 Command Prompt and it should be working now.
在寫字板(不是記事本!)中創建一個文件,將其命名為 .theanorc.txt
并將其放入 C:UsersYour_Name
或您的用戶文件夾中的任何位置位于:
Create a file in WordPad (NOT Notepad!), name it .theanorc.txt
and put it in C:UsersYour_Name
or wherever your users folder is located:
#!sh
[global]
device = gpu
floatX = float32
[nvcc]
compiler_bindir=C:Program Files (x86)Microsoft Visual Studio 10.0VCin
# flags=-m32 # we have this hard coded for now
[blas]
ldflags =
# ldflags = -lopenblas # placeholder for openblas support
創建一個測試python腳本并運行它:
Create a test python script and run it:
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 xrange(iters):
r = f()
t1 = time.time()
print 'Looping %d times took' % iters, t1 - t0, 'seconds'
print 'Result is', 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'
最后驗證你有 Used the gpu
就完成了!
Verify you got Used the gpu
at the end and you're done!
這篇關于在啟用 GPU 的 Windows 8 上安裝 theano的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!