Constant memory variables give incorrect value, when declared, defined and used in separate files?



My project is divided into multiple/separate cu, cuh files. As a result, function declarations and constant memory declarations are done in header file and it is being used in various kernels and device functions. But I am not getting correct result.

When all the functions,variables and constant memory variables are in a single file, then constant values respond correctly, but when declaration is in cuh, definition is a cu file and usage in another file/device function, the results are not correct.
Please advise the design and usage of constant memory variable if separate files (like, header.cuh and exist.

You need to compile with appropriate settings for relocatable device code/separate compilation and linking. This is covered in the nvcc manual and there are plenty of CUDA sample projects that provide examples.

It may simply be sufficient for you to add -rdc=true to your compile command line.

Doing that may give you multiple declaration errors, in which case you’ll want to make sure that your constant declarations are only declared in one compilation unit each.