问题描述
我刚买了一台配备 Ryzen 5950x 的 PC,通过检查 bench
命令的结果,它在 Matlab 2020b 上运行得非常快。
我遵循了在线建议,使用 MKL 2020.0 全局设置 MKL_DEBUG_cpu_TYPE=5。我通过anaconda安装了python 3.8.5,numpy 1.20.0
当我使用以下代码以 5950 倍尝试 numpy 时,平均需要 28 秒。我有另一台配备 intel i7-8700 的 PC,它只需要 0.66 秒。
谁能告诉我为什么?或者我应该安装 BLAS 而不是 MKL?
import numpy as np
import os
from time import time
print(os.environ.get('MKL_DEBUG_cpu_TYPE')) # it should print 5
# Let's take the randomness out of random numbers (for reproducibility)
np.random.seed(0)
size = 4096
A,B = np.random.random((size,size)),np.random.random((size,size))
C,D = np.random.random((size * 128,)),np.random.random((size * 128,))
E = np.random.random((int(size / 2),int(size / 4)))
F = np.random.random((int(size / 2),int(size / 2)))
F = np.dot(F,F.T)
G = np.random.random((int(size / 2),int(size / 2)))
N = 5
t = time()
for i in range(N):
np.dot(A,B)
delta = time() - t
print('Dotted two %dx%d matrices in %0.2f s.' % (size,size,delta / N))
解决方法
请安装 intel-oneapi-mkl-2021。对 ryzen 的支持嵌入在里面。您不必写 MKL_DEBUG_...
。
您可以点击链接:intel-oneapi