Memory handling. How we use large global memory of device.

Hi,

I have just written a code that use a large amount of global memory in device. what i have written is given below:

I allocate large memory as char type array

                   char *chArray = 0;
             CUDA_SAFE_CALL( cudaMalloc((void**) &chArray , sizeof(int) *10000));

and using this as my need by typecasting it, as:

            int  *Int_array = (int*)chArray;
            double* Dou_array = (double*) &Int_array [500];

It is working fine.

But as we know type casting is a costly operations.

So, what is the efficient way to handle this problem.

Thanks :
Kundan

Typecasting is a compiler hint. It has no run-time component to it (unless u r dealing with some C++ may be…)

Why?

This works just as good and results in fewer headaches.

int *Int_Array = 0;

CUDA_SAFE_CALL( cudaMalloc((void**) &Int_Array , sizeof(int) *10000));

Regarding performance, Sarnath is right. There is no performance penalty. A type cast just tell the compiler how to deal with the array at compile time.