티스토리 뷰

먼저 참고한 글들을 나열하고...


https://lepisma.github.io/articles/2015/07/30/up-with-theano-and-cuda/

https://planetanacreon.wordpress.com/2015/10/09/install-theano-on-windows-8-1-with-visual-studio-2013-cuda-7-5/

https://my6266blog.wordpress.com/2015/01/21/installing-theano-pylearn2-and-even-gpu-on-windows/

http://deeplearning.net/software/theano/tutorial/using_gpu.html

http://rosinality.ncity.net/doku.php?id=python:installing_theano

http://deeplearning.net/software/theano/install_windows.html

https://www.kaggle.com/c/otto-group-product-classification-challenge/forums/t/13973/a-few-tips-to-install-theano-on-windows-64-bits


설치 환경은

Windows 10 x64

Microsoft Visual Studio 2013 Community (VC12)

CUDA Toolkit 7.5

Python 3.4


조합이 매우 중요하니, 모든 글을 숙지한 다음에 설치할 것



1. Visual Studio 설치

2015 Community를 설치했었는데, nvcc (NVIDIA CUDA Compiler) 지원 목록에 없다. 2013 Community 버전을 설치하도록 하자.



2. CUDA Toolkit 설치

여기서 다운로드하면 되고, 내가 설치한 버전은 cuda_7.5.18_win10.exe



3. Python 설치

공학용인 anaconda를 설치하는게 속 편하다. 2.7 버전은 개발이 중지되고, 보안 관련 수정만 되고 있고, 3 이상 버전을 모두들 추천하고 있다. 그 중에서도 다음에 설치할 libpython package가 3.5 최신 버전에 없으니, 3.4 버전을 설치하도록 한다. 아카이브에 가서 구버전 2.3.0을 다운받아서 설치하고, 아래 명령어를 통해서 dependency를 설치한다.


conda install mingw libpython


원한다면 다른 package도 일괄적으로 업데이트

conda update conda

conda update -all

Documentation이 잘 되어 있는 편이니 찾아보면 된다.



3. Theano 설치

Github에서 최신 파일을 받아서 임시 폴더에 압축을 풀고 아래 명령어를 이용해서 설치해도 되고...

pip install c:\Theano-master\.


아니면 미리 컴파일된 바이너리를 다운 받아서 아래와 같이 설치해도 된다.

pip install c:\file\path\Theano-0.7.0-py3-none-any.whl


같은 방법으로 pycuda를 설치해 주고 opencv도 필요하면 같이 설치해 준다.

pycuda-2015.1.3+cuda7518-cp34-none-win_amd64.whl

opencv_python-3.1.0-cp34-none-win_amd64.whl

python 버전과 x86 x64 버전에 주의


설치가 끝난 후에, 아래와 같은 theano 설정 파일을 %USERPROFILE% 폴더 아래에 .theanorc 이름으로 저장한다.

#!sh
[global]
device = gpu
floatX = float32

[nvcc]
fastmath = True
flags=-LC:\Anaconda3\libs
compiler_bindir=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin
# flags=-m32 # we have this hard coded for now

[blas]
ldflags =
# ldflags = -lopenblas # placeholder for openblas support

각종 설정은 여기를 참고


import theano

를 통해 단순히 체크해 볼 수 있고, 아래 코드를 돌려보면 된다.

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')



4. PyCUDA 설치

설치는 위의 방법을 통해서 하면 되고, 혹시 환경 변수 문제가 있을 경우, 여기 글의 5번 7번 항목을 참고해서 설정해주면 된다. 아래 코드로 테스트


import pycuda.autoinit

import pycuda.driver as drv

import numpy


from pycuda.compiler import SourceModule

mod = SourceModule("""

__global__ void multiply_them(float *dest, float *a, float *b)

{

  const int i = threadIdx.x;

  dest[i] = a[i] * b[i];

}

""")


multiply_them = mod.get_function("multiply_them")


a = numpy.random.randn(400).astype(numpy.float32)

b = numpy.random.randn(400).astype(numpy.float32)


dest = numpy.zeros_like(a)

multiply_them(

        drv.Out(dest), drv.In(a), drv.In(b),

        block=(400,1,1), grid=(1,1))


print(dest-a*b)





댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함