Results 1 to 4 of 4

Thread: confusing duplication

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Posts
    2

    confusing duplication

    Hi all,

    To create and load a memory buffer I call the following functions:

    clInputBuffer := clCreateBuffer(clContext, CL_MEM_READ_WRITE or CL_MEM_USE_HOST_PTR, 4 {sizeof(cl_uint)}*720*576, src.bits, errNum);
    errNum := clEnqueueWriteBuffer(clCommandQueue, clInputBuffer, CL_TRUE, 0, 720*576*{sizeof(cl_uint)}4, src.bits, 0, NULL, NULL);

    why must the host pointer be initialised twice.? It works correctly but the duplication makes me think I am doing something wrong.

    Any info on the logic would be helpfull helpfull.

    thanks,
    Robert

  2. #2
    Senior Member
    Join Date
    Jul 2009
    Location
    Northern Europe
    Posts
    311

    Re: confusing duplication

    If you are creating the buffer to with CL_MEM_USE_HOST_PTR then it will reference the host pointer and you do not need to write it again. (You do need to be careful about changing/freeing the host pointer, though.)

    If you do not use CL_MEM_USE_HOST_PTR or CL_MEM_COPY_HOST_PTR then you need to write in the data.

  3. #3
    Junior Member
    Join Date
    Jan 2010
    Posts
    2

    Re: confusing duplication

    thanks for that,

    I now understand if you use (CL_MEM_USE_HOST_PTR or CL_MEM_COPY_HOST_PTR) you dont have to write the data but in the other case when you create the buffer you specify a pointer to the host data and a pointer to the memory object is returned so why pass the host data address again when you read or write the buffer, opencl already knows it when it was created.

  4. #4
    Senior Member
    Join Date
    Jul 2009
    Location
    Northern Europe
    Posts
    311

    Re: confusing duplication

    That's correct. When you use CL_MEM_USE_HOST_PTR OpenCL uses the provided host pointer as a backing store for the cl_mem object. This means that OpenCL will keep that data up to date. You will need to use the map/unmap commands to make sure that the memory is up-to-date before modifying it on the host.

    When you do not use either of those modes, OpenCL ignores the pointer you pass in to it, so you need to specify the data to be written explicitly.

Similar Threads

  1. vector component duplication
    By cantallo in forum OpenCL
    Replies: 1
    Last Post: 04-18-2012, 11:50 PM
  2. C++ Object to handle confusing parts
    By LucasCampos in forum OpenCL
    Replies: 0
    Last Post: 06-12-2011, 09:22 AM

Posting Permissions

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