Why is this an invalid symbol?

Hi.

When doing (in host code) …

curandState_t *dev_states;
int dev_states_n = 1024;
cudaMallocManaged(&dev_states, dev_states_n * sizeof(curandState_t));
size_t size;
cudaError_t error = cudaGetSymbolSize(&size, dev_states);
printf("size : %i bytes\n", (int) size);
printf("error: %i \n"     , (int) error);
printf("name : %s \n"     , cudaGetErrorName(error));

… I get:

size : 1024 bytes
error: 13 
name : cudaErrorInvalidSymbol 

My goal is to get the size of *dev_states. cudaGetSymbolSize() correctly populates size with 1024, but also returns error=13

CUDA docs say:

cudaErrorInvalidSymbol = 13
    This indicates that the symbol name/identifier passed to the API call is not a valid name or identifier. 

I also found this:
https://stackoverflow.com/a/11910573/3657691

Why isn’t *dev_states a valid name, identifier or symbol?

from here:

“Finds the size of the object associated with a CUDA symbol.”

“symbol is a variable that resides in global or constant memory space.”

Your dev_states variable doesn’t fit that description. A variable that resides in global space looks like:

__device__  int dev_var;

A variable that resides in constant memory space looks like:

__constant__ int const_var;

(your variable is a host variable, by that I mean it resides on the host/CPU thread stack)

I’m not really sure what you mean by the size of *dev_states. It is a pointer variable and it has a size of 8 (bytes). If you want to know what is the size of the allocation that that pointer variable points to, there isn’t an api that I know of that provides that (do you know of such an API in C or C++?) My suggestion would be to keep track of the size at the point of allocation.

Note that 1024 bytes is not the correct value for the size of the allocation that dev_states points to, nor is it the correct value for the size of dev_states itself. You already know the size of the allocation it points to, it is given by:

dev_states_n * sizeof(curandState_t)

and with a trivial piece of code you can confirm that value is not 1024.

1 Like

If you want to know what is the size of the allocation that that pointer variable points to, there isn’t an api that I know of that provides that (do you know of such an API in C or C++?) My suggestion would be to keep track of the size at the point of allocation.

That was exactly my point. My intention was to get rid rid of one parameter passing from host to kernel. I was looking for a function which allows me to determine inside the kernel the allocated size of memory allocated by cudaMallocManaged(). So instead of …

curandState_t *dev_states;
int dev_states_n = 1024;
cudaMallocManaged(&dev_states, dev_states_n * sizeof(curandState_t));
kernel <<<grid,block>>> (*dev_states, dev_states_n)

… I could say …

...
kernel <<<grid,block>>> (*dev_states)

… assuming that I can find out the size of *dev_states myself inside the kernel.