最近在美帝搞了台台式机,总算有机会可以玩玩Ubuntu了,正好ST790的project需要用到TensorFlow,当然就要先配置一下Python,特别是numpy。
首先安装openblas
sudo apt-get install libopenblas-base切换blas库
sudo update-alternatives --config libblas.so.3安装numpy(pip或者apt-get均可)
测试
我用了两段代码测试。
import numpy as np a1 = np.random.rand(10000, 10000) a2 = np.random.rand(10000, 10000) np.dot(a1, a2)用时13s左右
import numpy as np
import numpy.random as npr
import time
# --- Test 1
N = 1
n = 1000
A = npr.randn(n,n)
B = npr.randn(n,n)
t = time.time()
for i in range(N):
C = np.dot(A, B)
td = time.time() - t
print("dotted two (%d,%d) matrices in %0.1f ms" % (n, n, 1e3*td/N))
# --- Test 2
N = 100
n = 4000
A = npr.randn(n)
B = npr.randn(n)
t = time.time()
for i in range(N):
C = np.dot(A, B)
td = time.time() - t
print("dotted two (%d) vectors in %0.2f us" % (n, 1e6*td/N))
# --- Test 3
m,n = (2000,1000)
A = npr.randn(m,n)
t = time.time()
[U,s,V] = np.linalg.svd(A, full_matrices=False)
td = time.time() - t
print("SVD of (%d,%d) matrix in %0.3f s" % (m, n, td))
# --- Test 4
n = 1500
A = npr.randn(n,n)
t = time.time()
w, v = np.linalg.eig(A)
td = time.time() - t
print("Eigendecomp of (%d,%d) matrix in %0.3f s" % (n, n, td))
输出为:
dotted two (1000,1000) matrices in 547.5 ms
dotted two (4000) vectors in 5.73 us
SVD of (2000,1000) matrix in 6.938 s
Eigendecomp of (1500,1500) matrix in 16.114 s
跑程序的时候通过htop可见8核全开。
本文介绍了如何在Ubuntu 16.04上链接numpy到openblas,包括安装openblas,切换blas库,使用pip或apt-get安装numpy,以及进行性能测试。测试结果显示,numpy运行时能够充分利用8核处理器。
13万+

被折叠的 条评论
为什么被折叠?



