Recently I moved my main PC from MBA mid 2011 to MBP mid 2014.
This machine has GPU.
There are some libraries to use GPU from python. i.e. PyCuda, PyOpenGL, Theano, etc…
I used theano and write very simple test.
Compare the time for calculate dot product of two arrays of numpy and theano.
import numpy as np import theano import theano.tensor as T tm1 = T.matrix() tm2 = T.matrix() matd = theano.dot(tm1,tm2) f=theano.function([tm1,tm2],matd)
1st round 2×2.
m1 = np.matrix([[1,2],[3,4]]) m2 = np.matrix([[3,4],[5,6]]) time np.dot(m1,m2) CPU times: user 19 µs, sys: 2 µs, total: 21 µs Wall time: 22.9 µs matrix([[13, 16], [29, 36]]) time f([[1,2],[3,4]],[[3,4],[5,6]]) CPU times: user 168 µs, sys: 25 µs, total: 193 µs Wall time: 171 µs array([[ 13., 16.], [ 29., 36.]])
Hmm, numpy was faster than theano.
2nd round 1000×1000
a = [range(1000) for i in range(1000)] b = [range(1000) for i in range(1000)] ma=np.asarray(a) mb=np.asarray(b) time c=np.dot(ma,mb) CPU times: user 1.84 s, sys: 5.33 ms, total: 1.85 s Wall time: 1.85 s time tc = f(a,b) CPU times: user 256 ms, sys: 12.1 ms, total: 268 ms Wall time: 174 ms
Theano was faster than numpy.
3rd round 10000×10000
a = [range(10000) for i in range(10000)] b = [range(10000) for i in range(10000)] ma=np.asarray(a) mb=np.asarray(b) time c=np.dot(ma,mb) #logtime.....;-( time c=f(a,b) CPU times: user 2min 16s, sys: 1.4 s, total: 2min 18s Wall time: 31.9 s
I don’t have enough knowledge about GPU coding, but I think theano is powerful tool.