[SOLVED] Access to a constant inside cuda kernel

Hi,

It is possible access to a constant inside the cuda kernel?

If I have the follow kernel in a file kernel.cu:

__global__ myKernel(int*a)
{
    a+=MY_CONSTANT;
}

And I have MY_CONSTANT in a file constants.h, can the kernel access to the constant?

Tank you.

If constants.h contains something like

#define MY_CONSTANT  (-5)

and you have an

#include "constants.h"

in kernel.cu prior to the kernel definition, that should work just fine. Have you tried it?

Yes, it should work, if the constant is declared using a compiler macro

#define MY_CONSTANT 32

or via a global constant variable of POD type:

const int MY_CONSTANT=32;

note that a is a pointer type in your example, maybe you meant:

*a += MY_CONSTANT;

Hi,

Thank you, I try it and all works fine!