Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Traversing a Tree using the root pointer

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    6

    Traversing a Tree using the root pointer

    hi

    I would like to create a kernel that looks like this:

    __kernel void Traverse(__global const TreeRoot *root)
    {
    // perform some operations...
    }

    Now, I need to copy the whole tree (obviously) to device. But how
    can I get back a pointer to device memory when creating buffers
    so that I can assemble the tree in device? I am sure this can be
    done in CUDA, but so far I have the feeling that it's not possible
    with OpenCL.

    thanks

  2. #2
    Senior Member
    Join Date
    May 2010
    Location
    Toronto, Canada
    Posts
    845

    Re: Traversing a Tree using the root pointer

    In OpenCL you don't want to store pointers to device memory inside a buffer --you'll run into portability problems very easily. Store byte offsets relative to the buffer's base address instead.
    Disclaimer: Employee of Qualcomm Canada. Any opinions expressed here are personal and do not necessarily reflect the views of my employer. LinkedIn profile.

  3. #3

    Re: Traversing a Tree using the root pointer

    Quote Originally Posted by david.garcia
    In OpenCL you don't want to store pointers to device memory inside a buffer --you'll run into portability problems very easily. Store byte offsets relative to the buffer's base address instead.
    Storing pointers sounds like a rather harmless thing to do. What kind of portability problems are you referring to?

  4. #4
    Junior Member
    Join Date
    May 2010
    Posts
    6

    Re: Traversing a Tree using the root pointer

    Portability problems? With pointers? Could this be due to potential different pointer size
    in some architectures (not being true 64-bit)?

    In my opinion this is quite essential. Since OpenCL is a C-like language, we need to have
    this! Why? simply because it's not always nice or intuitive to convert every structure that
    we need inside cl program into a compact memory, then using offsets to access it.

    So, is it possible? I haven't found yet any command to get a pointer from a cl buffer.
    Perhaps I am blind and someone knows already the way...

    greetings

  5. #5
    Junior Member
    Join Date
    May 2010
    Posts
    6

    Re: Traversing a Tree using the root pointer

    Also, another reason to have this, is because it will be then possible to pass just
    a few structs as cl kernel arguments that will carry pointers to device memory.

    Imagine for example, that I have a simple class in C++ that uses N different
    memory allocations on the heap.

    class foo
    {
    public:
    void *memory1;
    void *memory2;
    ...
    void *memoryN;
    };

    Now, I want to copy that foo class inside device memory using a cl struct analog,
    and pass that as kernel argument. How can I do that? so far, without having the
    availability of cl buffer pointers, I will need to pass all memory1,2..N pointers
    explicitly as kernel arguments - a very tedious job.

  6. #6
    Senior Member
    Join Date
    May 2010
    Location
    Toronto, Canada
    Posts
    845

    Re: Traversing a Tree using the root pointer

    Storing pointers sounds like a rather harmless thing to do. What kind of portability problems are you referring to?
    Perhaps I misunderstood the OP, but it seemed to me like he wanted to use the host to store pointers inside a buffer object. Obviously those pointers will be in the host address space and won't work when you run a kernel in the device. Many devices have an address space that is separate from the host address space, making the pointers that he stored in the buffer equivalent to garbage.

    I'll put it in a different way: try implementing this on a GPU device and let us know whether it works.

    As I said, the only portable solution I can think of is storing offsets to the base address of the buffer object. I understand it's inconvenient, but it's not rocket science either. You can create some macros to make it easier.
    Disclaimer: Employee of Qualcomm Canada. Any opinions expressed here are personal and do not necessarily reflect the views of my employer. LinkedIn profile.

  7. #7

    Re: Traversing a Tree using the root pointer

    I agree that the OP is a bit unclear on the details behind a TreeRoot*.

    What I would like to do is something like the following

    Code :
    struct SparseMatrix{
      cl_float* data;
      cl_uint* indices;
    }
    cl_mem data = clCreateBuffer(...);
    cl_mem indices = clCreateBuffer(..);
     
    SparseMatrix matrix;
    matrix.data = clDevicePointer(data);
    matrix.indices = clDevicePointer(indices);
    clSetKernelArg(..., sizeof(SparseMatrix), (void*)&matrix);

  8. #8
    Junior Member
    Join Date
    May 2010
    Posts
    6

    Re: Traversing a Tree using the root pointer

    Oh my, I was looking exactly for that (clDevicePointer)

    Muchas Gracias

  9. #9

    Re: Traversing a Tree using the root pointer

    I should probably clarify that clDevicePointer does not currently exist and was used here only to demonstrate the kind of operation we are discussing.

  10. #10
    Junior Member
    Join Date
    May 2010
    Posts
    6

    Re: Traversing a Tree using the root pointer

    Nooooooooooooooooooo

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 1
    Last Post: 12-27-2012, 06:03 PM
  2. How to get square root for longlong type value
    By Simpleton in forum OpenGL ES general technical discussions
    Replies: 2
    Last Post: 02-18-2005, 06:33 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
  •