I am trying to install from source a project on another system that I have successfully compiled in one so far. This project has been tested in many other systems so it is most likely not a bug (or not a major bug) in the code. The main code base is a mixture of .cpp, .hpp and .cu files.
At the beginning, the Makefile calls the g++ compiler to produce the objects of some .cpp files. After that, the Makefile calls the nvcc compile the .cu files and produce the equivalent .cuo object files. There is where the problems start. The first file that is being compiled with the nvcc (the first .cu file) #includes a .hpp file that has the following code lines (and is causing the compilation errors):
// other lines of code ...
#include <math.h>
#define DEFINE_VSL_UNARY_FUNC(name, operation) \
template<typename Dtype> \
void v##name(const int n, const Dtype* a, Dtype* y) { \
CHECK_GT(n, 0); CHECK(a); CHECK(y); \
for (int i = 0; i < n; ++i) { operation; } \
} \
inline void vs##name( \
const int n, const float* a, float* y) { \
v##name<float>(n, a, y); \
} \
inline void vd##name( \
const int n, const double* a, double* y) { \
v##name<double>(n, a, y); \
}
DEFINE_VSL_UNARY_FUNC(Sqr, y[i] = a[i] * a[i]);
DEFINE_VSL_UNARY_FUNC(Exp, y[i] = exp(a[i]));
DEFINE_VSL_UNARY_FUNC(Abs, y[i] = fabs(a[i]));
// other lines of code ...
When this code is #included to .cpp files that are compiled with the g++ it returns no errors. On the other hand, when it is trying to compile the .cu file with the nvcc I am getting the following errors (and many others related to functions defined on the same way with the function factory pattern):
./included_file.hpp: In function ‘void vSqr(int, const Dtype*, Dtype*)’:
./include_file.hpp:34:378: error: invalid qualifiers on non-member function type
DEFINE_VSL_UNARY_FUNC(Sqr, y[i] = a[i] * a[i]);
./included_file.hpp:34:378: error: invalid qualifiers on non-member function type
./included_file.hpp:34:561: error: invalid qualifiers on non-member function type
DEFINE_VSL_UNARY_FUNC(Sqr, y[i] = a[i] * a[i]);
./included_file.hpp:34:561: error: invalid qualifiers on non-member function type
./included_file.hpp: In function ‘void vExp(int, const Dtype*, Dtype*)’:
./included_file.hpp:35:378: error: invalid qualifiers on non-member function type
DEFINE_VSL_UNARY_FUNC(Exp, y[i] = exp(a[i]));
./included_file.hpp:35:378: error: invalid qualifiers on non-member function type
./included_file.hpp:35:561: error: invalid qualifiers on non-member function type
DEFINE_VSL_UNARY_FUNC(Exp, y[i] = exp(a[i]));
// Many more errors of the same type (related to functions defined with the function factory pattern)
My system is:
OS: Ubuntu 14.04
g++ -v: gcc version 4.8.1 (Ubuntu 4.8.1-2ubuntu1~12.04) - there is also g++ v4.4 installed but the v4.8 is in use.
GPU name: Tesla K20c
Nvidia driver: 340.29 (from the nvidia-smi command)
CUDA version: 6.5 (also tested with 6.0, but returns the same erros)
nvcc -V: release 6.5, V6.5.12
I have searched for the past few days and did not find anything relevant to this anywhere. I do not think that there is anything wrong with the code, because it is tested on other systems and no one has reported something like that. There is also an CPU-only version (without using the nvcc and compiling the CUDA code) which works fine. I would much appreciate any help on this; if you know what it might be wrong.
Thank you in advance!