I'm developing a program that use CUDA developing toolkit version 10.1 and I'm using visual studio 2012. I'm working on windows but I share code with a linux user. All the code works fine on the two cases, except for some line of code that works on linux but not on windows. So every time I have to change these lines. I would avoid to do this and by the fact that on linux the code compile well, I think there are some reasons why on windows doesn't compile, but these reasons must be for sure not about the code but about some visual studio setting or similar. Can you help me? In particular the line of codes are:
int n_devices = 0;
cudaGetDeviceCount(&n_devices);
cudaDeviceProp props[n_devices];
On the last line i have the error:
error: expression must have a constant value
I can fix this error defining const int n_devices = 1;
and commenting the function cudaGetDeviceCount(&n_devices);
. It works because I already know the right number of devices but for sure is less right solution than the previous one.
The other problem is that I have a utils.cuh file in which there are defined two const value
const float PI = 3.141592654f;
const float EPS = 1e-3f;
I invoke this two values in the utils.cu file and at compile time i have the error:
error: "PI" is undefined in device code
error: "EPS" is undefined in device code
I can fix this declaring these two variables in this way:
#define PI 3.141592654f
#define EPS 1e-3f
So even if I can fix all the two problems I really want to leave the code in the first configuration (since it works on linux). Could be a problem related to compiler version? I really don't know which could be the reason.