Results 1 to 5 of 5

Thread: Fast array initialization

  1. #1

    Fast array initialization

    Hi,

    I want to allocate an array in GPU memory initialized (all the positions) with a given value (for instance 0).

    I tried by creating a cpu array pointer with zeros and create the buffer with the CL_MEM_COPY_HOST_PTR flag.

    I also tried by running a kernel with one thread per position of the array an inside the kernel just assign the given value.

    The array is huge, by the way.

    I wonder if there is some way more efficient of doing this.

    Thank you.

  2. #2
    Senior Member
    Join Date
    Mar 2011
    Location
    Seoul
    Posts
    118

    Re: Fast array initialization

    Someone can correct me if I'm wrong, but you could allocate them cl_mem buffer on the device using a NULL host pointer, then run a kernel to zero all the array elements before running your desired kernel. That way you don't have to allocate and zero the array on the host and then do a host to device memory transfer, which all together could take a lot of time.

  3. #3

    Re: Fast array initialization

    Quote Originally Posted by sean.settle
    you could allocate them cl_mem buffer on the device using a NULL host pointer, then run a kernel to zero all the array elements before running your desired kernel.
    That's what I tried to explain (wrong apparently) when I said:

    Quote Originally Posted by nachovall
    I also tried by running a kernel with one thread per position of the array an inside the kernel just assign the given value.
    Thanks anyway.

  4. #4
    Senior Member
    Join Date
    Mar 2011
    Location
    Seoul
    Posts
    118

    Re: Fast array initialization

    Ah, I'm sorry I misunderstood.

    I guess another option (other than clEnqueueWriteBuffer) is to use clMapBuffer to write to the device memory through a host pointer. There are some examples of how to do this in the AMD and NVIDIA SDKs under memory optimizations/bandwidth (PCIe). If you do writing async then you can overlap some other computations while writing to the buffer.

  5. #5

    Re: Fast array initialization

    Quote Originally Posted by sean.settle
    Ah, I'm sorry I misunderstood.

    I guess another option (other than clEnqueueWriteBuffer) is to use clMapBuffer to write to the device memory through a host pointer.
    Nice one!! I'll try it.

    Thank you very much.

Similar Threads

  1. fast buffer initialization with zeros
    By MaximS in forum OpenCL
    Replies: 2
    Last Post: 07-08-2012, 08:34 AM
  2. Array initialization failed
    By pelangi15 in forum OpenCL
    Replies: 3
    Last Post: 06-13-2011, 07:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •