그냥 경우에 당신이 우분투 나 민트를 사용하고, 쉽게 NumPy와와 openblas를 통해 모두 설치하여 openblas 연결 NumPy와이 할 수있는 새로운 고정 표시기 우분투에
sudo apt-get install numpy libopenblas-dev
으로 APT를-얻을, 나는 다음과 같은 스크립트를 테스트 openblas없이 "Installing Numpy and OpenBLAS"
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 563.8 ms
dotted two (4000) vectors in 5.16 us
SVD of (2000,1000) matrix in 6.084 s
Eigendecomp of (1500,1500) matrix in 14.605 s
내가
apt install openblas-dev
와 openblas를 설치 한 후
, 나는
import numpy as np
np.__config__.show()
와 NumPy와 연결을 확인하고 정보를
atlas_threads_info:
NOT AVAILABLE
openblas_info:
NOT AVAILABLE
atlas_blas_info:
NOT AVAILABLE
atlas_3_10_threads_info:
NOT AVAILABLE
blas_info:
library_dirs = ['/usr/lib']
libraries = ['blas', 'blas']
language = c
define_macros = [('HAVE_CBLAS', None)]
mkl_info:
NOT AVAILABLE
atlas_3_10_blas_threads_info:
NOT AVAILABLE
atlas_3_10_blas_info:
NOT AVAILABLE
openblas_lapack_info:
NOT AVAILABLE
lapack_opt_info:
library_dirs = ['/usr/lib']
libraries = ['lapack', 'lapack', 'blas', 'blas']
language = c
define_macros = [('NO_ATLAS_INFO', 1), ('HAVE_CBLAS', None)]
blas_opt_info:
library_dirs = ['/usr/lib']
libraries = ['blas', 'blas']
language = c
define_macros = [('NO_ATLAS_INFO', 1), ('HAVE_CBLAS', None)]
atlas_info:
NOT AVAILABLE
blas_mkl_info:
NOT AVAILABLE
lapack_mkl_info:
NOT AVAILABLE
atlas_3_10_info:
NOT AVAILABLE
lapack_info:
library_dirs = ['/usr/lib']
libraries = ['lapack', 'lapack']
language = f77
atlas_blas_threads_info:
NOT AVAILABLE
그것은 openblas에 연결이 표시되지 않습니다이다.그러나 스크립트의 새로운 결과는 NumPy와는 openblas를 사용해야합니다 것을 보여줍니다 :
dotted two (1000,1000) matrices in 15.2 ms
dotted two (4000) vectors in 2.64 us
SVD of (2000,1000) matrix in 0.469 s
Eigendecomp of (1500,1500) matrix in 2.794 s
때 당신은 문제가 추가 스레드를 보장 할만큼 큰 것을 확신, 성능 저하가 있었다라고? 너무 작은 문제의 경우 여분의 스레드를 사용할 때 성능 저하가 발생하며 openblas가 유용 할 때 여분의 스레드 만 사용할만큼 똑똑한 지 여부는 알 수 없습니다. – DaveP
다양한 크기 (100x100, 100x1000, 1000x1000, 1000x10000,10000x10000)의 무작위로 생성 된 행렬에 numpy.linalg.svd 함수를 사용하여 시도한 문제의 크기와 성능 차이가 있는지 확인하려면이 모든 경우에 가장 좋은 실행 시간은 openblas에서 단일 스레드로 달성됩니다. 계산 부하가 많은 경우 (예 : 10000x10000 행렬 SVD) 단일 스레드는 5000 초가 걸리고 3 스레드는 6000 초 걸립니다. 이 점이 나에게 조금 걱정 스럽다. 오픈 블라스 통합이 올바른지 확인하고 싶다. – Vijay