Dynamic Memory Allocation on the Host

Hello,

I’ve one question about CUDA. Before I use the “cudaMemcpy” function I should allocate memory on the “Host”. Normally I use “malloc” or “new” for allocating new memory on the “Host” but I can’t use this keywords. Unfortunately I should use memory on the “stack” and then I can use the copy function (cudaMemcpy ) of CUDA. Now my question: Why I can’t use “new” or “malloc” for allocating dynamically memory of e.g. arrays?

cheers
chero :rolleyes:

Uh, I’m confused. I have used both new and malloc() to allocate host memory and pass it to cudaMemcpy(). It works fine.

Uh, I’m confused. I have used both new and malloc() to allocate host memory and pass it to cudaMemcpy(). It works fine.

That is confusing. Basically, the steps are:

  1. create/allocate data on the HOST (eg. setup an array of floats)

  2. cudaMemcpy from HOST to DEVICE

  3. do GPU computations

  4. cudaMemcpy from DEVICE to HOST

If you think that CUDA forces you to allocate on the host with their own special commands, this is not true. Just get the data you want via normal means (hard-coded, user input, text files, etc.).

That is confusing. Basically, the steps are:

  1. create/allocate data on the HOST (eg. setup an array of floats)

  2. cudaMemcpy from HOST to DEVICE

  3. do GPU computations

  4. cudaMemcpy from DEVICE to HOST

If you think that CUDA forces you to allocate on the host with their own special commands, this is not true. Just get the data you want via normal means (hard-coded, user input, text files, etc.).

Hello,

yes of course the normal cudaMemcpy is working correctly I meant the cudaMalloc2D but it works also. May be my mistake :-D.

Thank you for your encouragement.

cheers
chero

Hello,

yes of course the normal cudaMemcpy is working correctly I meant the cudaMalloc2D but it works also. May be my mistake :-D.

Thank you for your encouragement.

cheers
chero