Getting size of array allocated in global device memory Problems with cudaGetSymbolSize()

Hi All,

I have allocated a linear array in global GPU memory, and am trying to get the size of its allocation with cudaGetSymbolSize().
My code is below:

int devPtr;

*)&devPtr, sizei);
cudaMemcpyFromArray(devPtr, hostPtr, 0, 0, sizei, cudaMemcpyHostToDevice);

size_t sized;
cudaError_t er1 = cudaGetSymbolSize(&sized, devPtr);

However this always returns the error cudaErrorInvalidSymbol.
I’m not sure how I am supposed to pass in the symbol, i’ve also tried using the address of &, and also sending it as a string. No luck!

Does anybody have an idea?

Thank you.

cudaGetSymbolSize or cudaGetSymbolAddress are not used for dynamically allocated global arrays. They used for variables declared on the device.

In other words, if I had some device code with a global variable “myGlobalVariable”

__device__ int myGlobalVariable;

__global__ void myKernel() {



then the various symbol-related cuda functions could be used within host code to get its size, or get its address, or copy data to it or from it.

In your case with a dynamically allocated block of memory, I think you have to keep track of the size yourself.