hughperkins / clnn

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

Build failing on OS X: CL/cl.h not found #11

Closed sorrge closed 9 years ago

sorrge commented 9 years ago

Hi,

I have a problem building clnn. When trying to use EasyCL, it can't find a header file:

In file included from clnn/SpatialMaxPooling.cpp:8: /torch/install/include/easycl/EasyCL.h:12:10: fatal error: 'CL/cl.h' file not found

include "CL/cl.h"

Plus several similar errors.

My cltorch installation is fine and passes all tests. I've checked the torch installation folder and it has the lib/libEasyCL.dylib file, meaning that EasyCL itself was built. So it seems to be a problem of how clnn uses it.

szagoruyko commented 9 years ago

I had to manually fix all #include <CL/cl.h> to be #include <OpenCL/cl.h> on OS X in clnn

sorrge commented 9 years ago

Ok, I'll try that, thank you. But how was it possible to build the EasyCL library itself then? Does it not try to include "CL/cl.h"?

hughperkins commented 9 years ago

But how was it possible to build the EasyCL library itself then? Does it not try to include "CL/cl.h"?

The EasyCL build adds thirdparty/clew/include/proxy-opencl to the include path, which contains a cl.h file. It also defines the macro USE_CLEW, which replaces cl.h includes with clew.h includes. I think that Sergey's fix sounds good for now, and in the meantime, I will look at how to make the build not need manual patching in the future.

sorrge commented 9 years ago

Wouldn't it be a good solution to add this folder to the include path of clnn as well, and/or define USE_CLEW?

sorrge commented 9 years ago

Ok, the only way to fix it at the moment is to change the includes. Seems like it's platform-dependent. In the standard sources (https://www.khronos.org/registry/cl/api/1.2/cl.h) they use code like this:

#ifdef __APPLE__
#include <OpenCL/cl_platform.h>
#else
#include <CL/cl_platform.h>
#endif
brunoro commented 9 years ago

clBLAS also uses something similar:

#if defined(__APPLE__) || defined(__MACOSX)
#include <OpenCL/cl.h>
#else
#include <CL/cl.h>
#endif

I managed to build replacing the #include "CL/cl.h" with that on the following headers:

torch/install/include/easycl/DeviceInfo.h
torch/install/include/easycl/deviceinfo_helper.h
torch/install/include/easycl/DevicesInfo.h
torch/install/include/easycl/EasyCL.h
torch/install/include/easycl/platforminfo_helper.h
hughperkins commented 9 years ago

Hi Sorrge and Gustavo,

Yes, I think that replacing the #include "CL/cl.h" if #ifdef'd versions is a good cross-platform solution. If you submit a pull request for that, I can merge that in.

brunoro commented 9 years ago

cool, I'll do that.

hughperkins commented 9 years ago

Thank-you Gustavo for the pull request. This is merged to EasyCL master now, and cltorch master has been updated to point to this latest EasyCL.

To anyone in this thread who still has an issue with failing to find the cl header files, please can you do try doing luarocks install cltorch, followed by luarocks install clnn?

hughperkins commented 9 years ago

I think I can close this now. Please feel free to reopen it if you still have the problem.