libblas.so无法在python中打开共享项目文件



在这方面我完全是个新手,所以请原谅我的无知。

我想从这个问题运行基准:

基准测试(python与使用BLAS的c++)和(numpy)

代码可在此处找到:https://github.com/zed/woltan-benchmark/

在运行make之后,我得到以下错误。

Traceback (most recent call last):
  File "main.py", line 8, in <module>
    _blaslib = ctypes.cdll.LoadLibrary("libblas.so")
  File "/usr/lib/python2.7/ctypes/__init__.py", line 443, in LoadLibrary
    return self._dlltype(name)
  File "/usr/lib/python2.7/ctypes/__init__.py", line 365, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libblas.so: cannot open shared object file: No such file or directory
make: *** [Test.csv] Error 1

我猜它找不到libblas.so库,但不知道它在哪里?如何检查它是否已安装?我运行的是Ubuntu 13.10。

谢谢

附加信息:

触发main.py中发现错误的python代码为:

import ctypes
from ctypes import byref, c_char, c_int, c_float
import numpy
import os
import subprocess
import timeit
_blaslib = ctypes.cdll.LoadLibrary("libblas.so")
def Mul(m1, m2, i, r):
    no_trans = c_char("n")
    n = c_int(i)
    one = c_float(1.0)
    zero = c_float(0.0)
    _blaslib.sgemm_(byref(no_trans), byref(no_trans), byref(n), byref(n), byref(n), byref(one), m1.ctypes.data_as(ctypes.c_void_p), byref(n), 
                                                                                                m2.ctypes.data_as(ctypes.c_void_p), byref(n), byref(zero),
                                                                                                r.ctypes.data_as(ctypes.c_void_p), byref(n))
if __name__ == '__main__':
    rNumpy = []
    rBlas = []
    p = subprocess.Popen("./bench {0}".format(str([x for x in range(5, 501, 5)])[1:-1]), shell = True)
    os.waitpid(p.pid, 0)
    for i in range(20, 501, 20):
        m1 = numpy.random.rand(i,i).astype(numpy.float32)
        m2 = numpy.random.rand(i,i).astype(numpy.float32)
        tNumpy = timeit.Timer("numpy.dot(m1, m2)", "import numpy; from __main__ import m1, m2")
        rNumpy.append((i, tNumpy.repeat(20, 1)))
        r = numpy.zeros((i,i), numpy.float32)
        tBlas = timeit.Timer("Mul(m1, m2, i, r)", "import numpy; from __main__ import i, m1, m2, r, Mul")
        rBlas.append((i, tBlas.repeat(20, 1)))
        print i
    f = open("Test.csv", "w")
    for (i, n), (j, b) in zip(rNumpy, rBlas):
        f.write("{0} {1} {2} {3} ".format(i, sum(n)/len(n), min(n), max(n)))
        f.write("{0} {1} {2} {3}n".format(j, sum(b)/len(b), min(b), max(b)))
    f.close()

编辑1:

运行locate libblas.so后,我更换了

_blaslib = ctypes.cdll.LoadLibrary("libblas.so")

带有

_blaslib = ctypes.cdll.LoadLibrary("/usr/lib/libblas/libblas/libblas.so.3")

不确定这是否正确,但现在的输出看起来像:

terminate called after throwing an instance of 'char const*'
Aborted (core dumped)

这两个错误(OSError和"核心转储")都是由于在main.pymain.cpp中没有相应的libblas.so,在您的情况下似乎应该使用libblas.so.3

我已经更新了基准测试,使libblas.so名称可配置。

在我的系统(Ubuntu 14.04)两者:

$ make clean && make

$ make clean && make LIBBLAS_SO=libblas.so.3

工作。

$ ls -l /usr/lib/libblas.so
... /usr/lib/libblas.so -> /etc/alternatives/libblas.so
$ update-alternatives --display libblas.so
libblas.so - auto mode
  link currently points to /usr/lib/openblas-base/libblas.so
/usr/lib/libblas/libblas.so - priority 10
  slave libblas.a: /usr/lib/libblas/libblas.a
/usr/lib/openblas-base/libblas.so - priority 40
  slave libblas.a: /usr/lib/openblas-base/libblas.a
Current 'best' version is '/usr/lib/openblas-base/libblas.so'.

相关内容

  • 没有找到相关文章

最新更新