3 Replies Latest reply on Apr 22, 2008 5:35 PM by michael.chu

    Copying from RAM to GPU

    rahulgarg
      Lets assume an application allocates an array A in system memory. I want to transfer a copy of this array to the GPU. My understanding is that I need to do the following :

      a) Allocate an array A in system memory using lets say malloc. This is done by code over which I have no control.

      b) Allocate an array B using CAL as remote memory.

      c) Map B to CPU, Copy A into B and then unmap.

      d) Use calMemCpy to copy to GPU.

      Is this correct or is there a more direct method where I can avoid copying of the array from A to B?
        • Copying from RAM to GPU
          michael.chu
          You should be able to skip step a) and in step c) directly use the pointer you get from the resource mapping call.

          Now, you can also just allocate a local resource and when you map that resource, the routines will take care of copying data around for you. However, I don't know off hand if the initial map will end up copying over uninitialize GPU memory though.

          If you want to be more explicit, just get rid of a) and modify c) as stated above.

          Michael.
            • Copying from RAM to GPU
              rahulgarg
              Well the problem is that the array A has already been malloced and initialized by an external library. I cannot alter that library. So I have is a float *A and the sizes in the 2 dimensions where A is already referring to allocated and initialized memory.

              It would be nice if I could create remote resources from already allocated memory without copying and then copying it into GPU through DMA and not involving CPU.
                • Copying from RAM to GPU
                  michael.chu
                  Unfortunately, I don't think there is a way to do that right now. I think the issue is making sure the remote resources are created in a region of host memory that can be pinned in physical memory to prevent them from being swapped out half way through a DMA transfer.

                  I'll send your question out to the CAL team to check and will let you know if I discover otherwise.

                  Michael.