4

我通过CRAN在我的 Mac 上安装了 R 。我还通过homebrew安装了 openblas 。我可以在 BLAS 实现之间切换,如下所示:

参考 blas(我认为是 netlib):

ln -sf /Library/Frameworks/R.framework/Resources/lib/libRblas.0.dylib /Library/Frameworks/R.framework/Resources/lib/libRblas.dylib

vecLib(Apple 的 BLAS):

 ln -sf /System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Versions/Current/libBLAS.dylib /Library/Frameworks/R.framework/Resources/lib/libRblas.dylib

openblas(通过自制软件提供):

brew link openblas --force
ln -sf /usr/local/lib/libopenblas.dylib /Library/Frameworks/R.framework/Resources/lib/libRblas.dylib

在 3 个选项中,openblas 似乎是最快的选项(尽管 vecLib 紧随其后)。

但是,我想尝试更多的力量:

更多力量

从 NVIDIA 安装了 CUDA 6.5。这会将一堆文件下载到/Developer/NVIDIA/并将其中一些链接到/usr/local/cuda. 我将我的 cuda 环境变量设置为~/.profile

export PATH="/usr/local/cuda/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda/lib:$LD_LIBRARY_PATH"
export CUDA_ROOT="/usr/local/cuda/bin"
export CUDA_HOME="/usr/local/cuda"
export NVBLAS_CONFIG_FILE="/Users/me/nvblas.conf"

然后,我使用以下条目制作了一个“/Users/me/nvblas.conf”:

NVBLAS_CPU_BLAS_LIB /usr/local/lib/libopenblas.dylib
NVBLAS_GPU_LIST ALL0
NVBLAS_TILE_DIM 2048
NVBLAS_AUTOPIN_MEM_ENABLED

理论上,这应该指向nvblas.dyliblibopenblas.dylib包含在 BLAS 中的函数nvblas.dylib

到目前为止,一切都很好。下一步是将 R 链接到nvblas.dylib

ln -sf /usr/local/cuda/lib/libnvblas.dylib /Library/Frameworks/R.framework/Resources/lib/libRblas.dylib

但是,当我启动 R 时,似乎libRlapack.dylib找不到它正在寻找的所有 BLAS 函数:

me:~ me$ R
[NVBLAS] Using devices :0 
[NVBLAS] Config parsed

R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin13.4.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared object '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/stats/libs/stats.so':
  dlopen(/Library/Frameworks/R.framework/Versions/3.1/Resources/library/stats/libs/stats.so, 6): Symbol not found: _dasum_
  Referenced from: /Library/Frameworks/R.framework/Versions/3.1/Resources/lib/libRlapack.dylib
  Expected in: /Library/Frameworks/R.framework/Versions/3.1/Resources/lib/libRblas.dylib
 in /Library/Frameworks/R.framework/Versions/3.1/Resources/lib/libRlapack.dylib
During startup - Warning message:
package ‘stats’ in options("defaultPackages") was not found 

openblas 本身可以正常工作,并提供 R 正在寻找的所有功能,所以我认为错误是libnvblas.dylib没有正确回退到libopenblas.dylib.

无论我指向什么 CPU BLAS libnvblas.dylib(netlib、vecLib、openblas),都会发生这种情况。谁能帮我解决这个错误?我还需要在我的路径或链接中添加什么才能libnvblas.dylib在 Mac 上正确使用 R 吗?

相关的错误可能是:

Symbol not found: _dasum_
Referenced from: /Library/Frameworks/R.framework/Versions/3.1/Resources/lib/libRlapack.dylib
Expected in: /Library/Frameworks/R.framework/Versions/3.1/Resources/lib/libRblas.dylib

在我看来,nvblas 没有转发_dasum_到 openblas。

/编辑:

otool -L /Library/Frameworks/R.framework/Resources/lib/libRblas.dylib

产量:

/Library/Frameworks/R.framework/Resources/lib/libRblas.dylib:
    @rpath/libnvblas.6.5.dylib (compatibility version 0.0.0, current version 6.5.14)
    @rpath/libcublas.6.5.dylib (compatibility version 0.0.0, current version 6.5.14)
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 635.21.0)
    /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
4

1 回答 1

2

我和你有同样的问题。在 OSX 下覆盖库而不是替换 R.framework 中的库为我解决了这个问题:

$ DYLD_FORCE_FLAT_NAMESPACE=y DYLD_INSERT_LIBRARIES=/Developer/NVIDIA/CUDA-7.0/lib/libnvblas.7.0.dylib R
于 2015-06-06T19:11:08.197 回答