hughperkins / clnn

OpenCL backend for Torch nn neural networks library
BSD 2-Clause "Simplified" License
125 stars 16 forks source link

CLNN master/thnn4 build error #30

Closed adrien806 closed 8 years ago

adrien806 commented 8 years ago

Hi Hugh, I believe there is a link error in the current thnn4 / master branch. The function GET_BLOCKS is in common.h, which has been compiled correctly

[ 25%] Building CXX object CMakeFiles/clnn.dir/common.cpp.o [100%] Linking CXX shared module libTHCLNN.so Undefined symbols for architecture x86_64: "GET_BLOCKS(THClState*, int)", referenced from: _THNN_ClSpatialAveragePooling_updateOutput in SpatialAveragePooling.cpp.o

Thanks in advance for the help.

hughperkins commented 8 years ago

It builds ok for me. Can you do the following and check the problem does/doesnt still occur:

luarocks install torch
luarocks install nn
luarocks install cltorch
luarocks install clnn
hughperkins commented 8 years ago

Ah, seems travis, on Mac OS X, has the same issue, https://travis-ci.org/hughperkins/clnn/builds/107116666 Hmmm.

hughperkins commented 8 years ago

Can you confirm what platform you are on please?

adrien806 commented 8 years ago

EDIT: post-typo

I am on Mac OS 10.11.3

To confirm, all the master branches are now in sync - so we can disregard the "bleeding edge" instructions?

I ran

luarocks install torch luarocks install nn luarocks install cltorch luarocks install clnn

And clnn did not build.

hughperkins commented 8 years ago

sorry, I meant luarocks install torch, corrected this above.

adrien806 commented 8 years ago

Corrected as well.

hughperkins commented 8 years ago

I am on Mac OS 10.11.3

yes, I think it's a problem specific to Mac OS X. Luckily, I do have Mac OS X build on travis, so I can try .. stuff... see if I can fix it. If you happen to have any ideas in the meantime please let me know. It problably involves a combination of one or both of the following mac-specific things:

hughperkins commented 8 years ago

Seems the symbols really are needed, so it's probably to do with the first issue.

hughperkins commented 8 years ago

I've moved common.cpp/.h into lib/THCLNN directory/dylib. That hopefully eliminates the build errors with GET_BLOCKS and GET_CL_NUM_THREADS. Then, (if those are fixed), "just" need to fix the issues with the TemplatedKernel symbols (which are in libEasylCL, I think)

adrien806 commented 8 years ago

Indeed, the missing symbols are now from the classes TemplatedKernel and EasyCL.

hughperkins commented 8 years ago

So, basically, on linux, by doing objdump somelib.so | grep NEEDED, starting with build/lib/THCLNN/lib/libTHCLNN.so, we have the following chain of dependencies:

Unfortunately, libTHCLNN.so needs a couple of symbols from libEasyCL.so, and, on Mac, these are not available to libTHCLNN.so by default. Needs some magic linking options I think.

Edit: Update: the GET_BLOCKS and GET_CL_NUM_THREADS errors have now disappeared https://travis-ci.org/hughperkins/clnn/builds/107120893 Editedit: ah you saw that too :-)

hughperkins commented 8 years ago

Ah, the easiest way to try it I think is something like:

git clone https://github.com/hughperkins/clnn.git
cd clnn
luarocks make rocks/clnn-scm-1.rockspec

Once you've done this once, then you can run cmake directly:

cd build
# if you want, you can run ccmake from here, like: ccmake ..
# otherwise, directly:
make
adrien806 commented 8 years ago

Thanks, as far as I know the directory where shared libraries are looked up is different on Mac.

But it could just be that the install/lib/ torch folder does not have a libEasyCL.so, but a libEasyCL.dylib (http://stackoverflow.com/questions/2339679/what-are-the-differences-between-so-and-dylib-on-osx)

hughperkins commented 8 years ago

Yeah, when I say .so on mac, that will sometimes be .dylib, sometimes .so, depending on the linker options supplied.

hughperkins commented 8 years ago

I've added EasyCL as a direct dependency of THCLNN, maybe that will help. But I should go to bed now-ish really, so I will check in the morning. https://github.com/hughperkins/clnn/commit/19ab3b5f8d7229cefe73e88f92782f97827ecb05

hughperkins commented 8 years ago

Built ok :-) https://travis-ci.org/hughperkins/clnn/builds/107126113

adrien806 commented 8 years ago

Built ok too, thanks for the help.

hughperkins commented 8 years ago

Cool :-)