R和nvblas.dynlib(在mac上)

时间:2015-01-27 20:10:16

标签: r cuda blas openblas nvblas

我通过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是非常接近的选择)。

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

More Power

installed CUDA 6.5 from NVIDIA。这会将一大堆文件下载到/Developer/NVIDIA/,并将其中一些文件链接到/usr/local/cuda。我在~/.profile

中设置了我的cuda环境变量
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.dylib中未包含的BLAS函数,这应该将libopenblas.dylib指回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

无论我在(netlib,vecLib,openblas)指向libnvblas.dylib的CPU BLAS,都会发生这种情况。任何人都可以帮我解决这个错误吗?还有什么我需要添加到我的路径或链接以让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)

1 个答案:

答案 0 :(得分:2)

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

$ DYLD_FORCE_FLAT_NAMESPACE=y DYLD_INSERT_LIBRARIES=/Developer/NVIDIA/CUDA-7.0/lib/libnvblas.7.0.dylib R