Closed allthetime closed 8 years ago
Hi allthetime, yes, I think it's an rpath issue, which I'm currently trying to fix, but not really succeeding yet.
What is rpath?
cltorch has a module called libcltorch.so
, which is installed at ~/torch/install/lib/lua/5.1/libcltorch.so
. When it loads, it needs to pull in some other libraries, like libTHCl.dylib
, and libclblas.dylib
, and a few others. To do this, on other systems it can read the paths from LD_LIBRARY_PATH
variable, but this seems not to work very well on Mac OS X, for various reasons, and is considered generally a Bad Idea, apparently.
The other way it can find them is, at build time, the linker stores the locations of the dependencies. It can do this using relative or absolute paths. On MAC OS X, I think it always uses absolute paths (?), but the first bit of such absolute paths can be a special varaible @rpath
, which will be replaced at runtime by the current value of @rpath
, which is also somehow set by the linker.
Now, I've set up a travis build, and run a few builds, eg https://travis-ci.org/hughperkins/cltorch/builds/113309396 , which all run from .travis.yml file. And in that build, I'm using otool
to examine the various paths stored in libcltorch.so
, at build time, by the linker. Here's how it looks:
https://travis-ci.org/hughperkins/cltorch/builds/113309396#L1024
0.48s$ otool -L ~/torch/install/lib/lua/5.1/libcltorch.so
/Users/travis/torch/install/lib/lua/5.1/libcltorch.so:
@rpath/libluaT.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/libTHCl.dylib (compatibility version 0.0.0, current version 0.0.0)
libclBLAS.2.dylib (compatibility version 2.0.0, current version 2.4.0)
@rpath/libTH.dylib (compatibility version 0.0.0, current version 0.0.0)
/System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate (compatibility version 1.0.0, current version 4.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1225.1.1)
libEasyCL.dylib (compatibility version 0.0.0, current version 0.0.0)
libclew.1.0.0.dylib (compatibility version 1.0.0, current version 0.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0)
Do you see? libTHCl.dylib uses @rpath
, but libclBLAS.2.dylib
does not, and it wont be found at runtime, because it's not in ~/torch/install/lib/lua/5.1
, it's actually in the parent of the parent, at ~/torch/install/lib
. What is @rpath
? It can be obatined by using otool too:
https://travis-ci.org/hughperkins/cltorch/builds/113309396#L1037
The command "otool -L ~/torch/install/lib/lua/5.1/libcltorch.so" exited with 0.
0.02s$ otool -l ~/torch/install/lib/lua/5.1/libcltorch.so | grep RPATH -A2
cmd LC_RPATH
cmdsize 40
path @executable_path/../lib (offset 12)
--
cmd LC_RPATH
cmdsize 48
path /Users/travis/torch/install/lib (offset 12)
=> it is ~/torch/install/lib
, which is what we want.
So, all the libraries which have @rpath
in their location are located. The others are not. If any of them fail to be located, cltorch fails to load.
As far as why it works with luajit -l cltorch
, and not with luajit -e 'require 'cltorch'
(or the other way around), that's interesting, that's new information, I'm not quite sure yet ;-)
Oh yes, wiki page on cmake and rpath:
some other links I've found:
@hughperkins thanks for the quick & informative reply, I'll let you know if I find anything.
(By the way, one option that apparently might work is, create direcotry ~/lib
, and copy all these dylibs from ~/torch/install/lib
into that directory, or simply symlink it, ie:
ln -s ~/torch/install/lib ~/lib
@hughperkins thanks for the quick & informative reply, I'll let you know if I find anything.
k :-)
@hughperkins nice, that symlink worked! thanks again.
Ok, cool :-)
Hi, I'm trying to set up cltorch on OSX el capitan on a macbook pro with AMD GPU.
The tests run and pass using
luajit -l cltorch -e 'cltorch.test()'
butth -l cltorch -e 'cltorch.test()'
fails with the output:/Users/chris/torch/install/lib/lua/5.1/libcltorch.so
definitely exists.and the output of
clinfo
is: