据我所知,Theano对Windows 8.1的支持仅处于试验阶段,但我想知道是否有人解决我的问题。根据我的配置,我会得到三种不同类型的错误。我认为解决我的任何错误都可以解决我的问题。
我使用WinPython 32位系统安装了Python,使用MinGW,如here所述。我的.theanorc
文件的内容如下:
[global]
openmp=False
device = gpu
[nvcc]
flags=-LC:\TheanoPython\python-2.7.6\libs
compiler_bindir=C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\
[blas]
ldflags =
当我运行import theano
时,错误如下:
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
对其进行了测试,但出现以下错误:
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)文件。
cl.exe
出现在两个文件夹中(即VS 2010和VS 2013)。
最后,如果我在环境路径中设置VS 2013并按如下方式设置.theanorc
内容:
[global]
base_compiledir=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin
openmp=False
floatX = float32
device = gpu
[nvcc]
flags=-LC:\TheanoPython\python-2.7.6\libs
compiler_bindir=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\
[blas]
ldflags =
我收到以下错误:
c:\theanopython\python-2.7.6\include\pymath.h(22): warning: dllexport/dllimport conflict with "round"
c:\program files\nvidia gpu computing toolkit\cuda\v6.5\include\math_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样本也没有问题。
答案 0 :(得分:30)
Theano是机器学习应用程序的一个很好的工具,但我发现它在Windows上的安装对于编程中的初学者(比如我自己)来说并不是微不足道的。在我的情况下,我在GPU上运行时看到我的脚本的5-6倍加速,所以这绝对值得麻烦。
我是根据我的安装程序编写本指南的,并且即使对于之前对Windows环境下构建程序没有任何了解的人来说也是如此。本指南的大部分内容都基于这些instructions,但我必须更改一些步骤才能使其在我的系统上运行。如果我做的任何事情可能不是最佳的或者在您的机器上不起作用,请告诉我,我会尝试相应地修改本指南。
这些是我在Windows 8.1计算机上安装支持GPU的Theano时遵循的步骤(按顺序):
可以从here下载CUDA。就我而言,我选择了64位笔记本版本用于配备Geforce 750m的NVIDIA Optimus笔记本电脑。
通过从命令行启动deviceQuery
来验证您的安装是否成功。在我的情况下,它位于以下文件夹中:C:\ProgramData\NVIDIA Corporation\CUDA Samples\v6.5\bin\win64\Release
。如果成功,您应该在测试结束时看到PASS。
我是通过dreamspark安装的。如果您是学生,您有权获得免费版本。如果没有,您仍然可以安装Express version,它也应该可以正常工作。安装完成后,您应该可以从开始菜单调用Visual Studio命令提示符2010。
在撰写本文时,GPU上的Theano仅允许使用32位浮点数,主要用于2.7版本的Python。 Theano需要大多数基本的科学Python库,例如scipy
和numpy
。我发现安装这些内容的最简单方法是通过WinPython。它将所有依赖项安装在一个独立的文件夹中,如果在安装过程中出现问题,您可以轻松地重新安装,并且您可以免费安装一些有用的IDE工具,如ipython notebook和Spyder。为了便于使用,您可能希望在environment variables中添加python.exe的路径和Scripts文件夹的路径。
找到here。
设置文件为here。我在安装过程中检查了所有基本安装文件。如果遇到下面描述的g ++错误,则需要这样做。
你可以找到它here。我基本上只使用此实用程序来提取已在基本安装中提供的PyCUDA tar文件(因此安装应该很简单)。
打开位于Python安装的msvc9compiler.py
目录中的/lib/distutils/
。在我的案例中,第641行为:ld_args.append ('/IMPLIB:' + implib_file)
。在此行之后添加以下内容(相同的缩进):
ld_args.append('/MANIFEST')
PyCUDA的来源是here。
<强>步骤:强>
打开cygwin并导航到PyCUDA文件夹(即/cygdrive/c/etc/etc
)并执行tar -xzf pycuda-2012.1.tar.gz
。
打开Visual Studio命令提示符2010并导航到提取tarball的目录并执行python configure.py
打开./siteconf.py并更改值以便读取(例如,对于CUDA 6.5):
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命令提示符处执行以下命令:
set VS90COMNTOOLS=%VS100COMNTOOLS%
python setup.py build
python setup.py install
创建此python文件并验证您是否得到结果:
# 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
打开git bash shell并选择要放置Theano安装文件的文件夹并执行:
git clone git://github.com/Theano/Theano.git
python setup.py install
尝试在VS2010命令提示符下打开python并运行import theano
如果您收到与g ++相关的错误,请在我的案例中打开MinGW msys.bat:C:\MinGW\msys\1.0
并尝试在MinGW shell中导入theano。然后重试从VS2010命令提示符导入theano,它现在应该正常工作。
在写字板中创建一个文件(不是记事本!),将其命名为.theanorc.txt
并将其放在C:\Users\Your_Name\
或用户文件夹所在的位置:
#!sh
[global]
device = gpu
floatX = float32
[nvcc]
compiler_bindir=C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin
# flags=-m32 # we have this hard coded for now
[blas]
ldflags =
# ldflags = -lopenblas # placeholder for openblas support
创建一个测试python脚本并运行它:
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
并且您已完成了!
答案 1 :(得分:5)
以下是我在a上安装theano的简单步骤 64位Windows 10机器。它在列出的代码here
上进行了测试(所有安装均使用默认安装路径)
[全球]
floatX = float32
device = gpu
[NVCC]
fastmath = True
compiler_bindir = C:\ Program Files(x86)\ Microsoft Visual Studio 12.0 \ VC \ bin \ cl.exe
[CUDA]
C:\ Program Files \ NVIDIA GPU Computing Toolkit \ CUDA \ v7.5
答案 2 :(得分:2)
以下是在64位Windows上使用CUDA安装theano的指南。
这似乎很简单,但我实际上并没有测试它以确保它有效。
http://pavel.surmenok.com/2014/05/31/installing-theano-with-gpu-on-windows-64-bit/
答案 3 :(得分:0)
按照Matt的教程,我遇到了与nvcc有关的问题。 我需要在nvcc.profile中添加VS2010可执行文件的路径(你可以在cuda bin文件夹中找到它):
"compiler-bindir = C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64"
答案 4 :(得分:0)
如果您想在Windows 8.1 x64上升级到MS Visual Studio 2012和CUDA 7,请在此处查看本教程:
http://machinelearning.berlin/?p=383
只要你完全坚持它就应该有效。 一切顺利
基督教
答案 5 :(得分:0)
我可以通过在“C:\ Program Files \ NVIDIA GPU Computing Toolkit \ CUDA \ v7.5 \ bin \ nvcc.profile”中的nvcc配置文件中添加所需的依赖项来编译cu文件。
我修改了include和lib路径,它开始工作了。
INCLUDES + =“ - I $(TOP)/ include”$( SPACE )“ - IC:/ Program Files(x86)/ Microsoft Visual Studio 12.0 / VC / include”$(< em> SPACE )“ - IC:\ Program Files(x86)\ Microsoft SDKs \ Windows \ v7.1A \ Include”$( SPACE ) LIBRARIES = + $( SPACE )“/ LIBPATH:$(TOP)/ lib / $(_ WIN_PLATFORM_)”$( SPACE )“/ LIBPATH:C:/ Program Files (x86)/ Microsoft Visual Studio 12.0 / VC / lib / amd64“$( SPACE )”/ LIBPATH:C:\ Program Files(x86)\ Microsoft SDKs \ Windows \ v7.1A \ Lib \ x64“$( SPACE )
我已经完成了安装的完整文档,希望它有助于https://planetanacreon.wordpress.com/2015/10/09/install-theano-on-windows-8-1-with-visual-studio-2013-cuda-7-5/
答案 6 :(得分:0)
我使用this guide,这非常有帮助。 许多Windows Theano指南只是顺便提一下(或根本没有提到),你需要从mingw shell编译theano,而不是从你的IDE编译。
我跑了mingw-w64.bat,并从那里“python”和“import theano”。只有在从pycharm导入后才能工作。
此外,关于deeplearning.net的官方说明很糟糕,因为它们会告诉您使用CUDA 5.5,但它不适用于较新的视频卡。
评论也很有帮助。如果它抱怨缺少crtdefs.h或basetsd.h,请做Sunando的回答。如果它仍然抱怨在objbase.h中未定义标识符“Iunknown”,请坚持以下内容 第236行的C:\ Program Files(x86)\ Microsoft SDKs \ Windows \ v7.1A \ Include \ _ objbase.h文件:
#include <wtypes.h>
#include <unknwn.h>
我必须做最后一部分才能使其适用于前沿安装(Keras部分所需)。
我还写了一份对我有用的事情清单,这里: http://acoupleofrobots.com/everything/?p=2238 这是64位版本。