R and nvblas.dynlib (on a mac)

南楼画角 提交于 2019-12-22 10:38:23

问题


I have R on my mac installed via CRAN. I also have openblas installed via homebrew. I can switch between BLAS implementations as follows:

Reference blas (netlib I think):

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

vecLib (Apple's BLAS):

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

openblas (provided via homebrew):

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

Of the 3 options, openblas seems to be the fastest option (though vecLib is a very close second).

However, I want to try more power:

I installed CUDA 6.5 from NVIDIA. This downloads a bunch of files to /Developer/NVIDIA/ and links some of them to /usr/local/cuda. I set my cuda environment variables in ~/.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"

I then made an "/Users/me/nvblas.conf" with the following entries:

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

In theory, this should point nvblas.dylib back to libopenblas.dylib for BLAS functions that are not includes in nvblas.dylib.

So far so good. The next step is to link R against nvblas.dylib:

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

However, when I start R, it seems that libRlapack.dylib can't find all of the BLAS functions its looking for:

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 works fine on its own, and provides all the functionality R is looking for, so I think the error is that libnvblas.dylib isn't properly falling back to libopenblas.dylib.

This happens no matter what CPU BLAS I points libnvblas.dylib at (netlib, vecLib, openblas). Can anyone help me sort out this error? Is there anything else I need to add to my path or link to get libnvblas.dylib properly working with R on a mac?

The relevant error is probably:

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

Which looks to me like nvblas isn't forwarding _dasum_ to openblas.

/edit:

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

Yields:

/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:


I had the same problem as you. Under OSX overriding the library instead of replacing the library in the R.framework solved the problem for me:

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


来源:https://stackoverflow.com/questions/28179093/r-and-nvblas-dynlib-on-a-mac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!