Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: Traversing a Tree using the root pointer

  1. #11
    Junior Member
    Join Date
    Jul 2010
    Posts
    1

    Re: Traversing a Tree using the root pointer

    You can implement a "clDevicePointer" as an OpenCL kernel

    Code :
    __kernel void getPtr( __global void *ptr, __global void * __global *out )
    {
     *out = ptr;
    }
    that can be invoked as follows

    Code :
    ...
     
    cl_mem auxBuf = clCreateBuffer( context, CL_MEM_READ_WRITE, sizeof(void*), NULL, NULL );
    void *gpuPtr;
     
    clSetKernelArg( getterKernel, 0, sizeof(cl_mem), &myBuf );
    clSetKernelArg( getterKernel, 1, sizeof(cl_mem), &auxBuf );
    clEnqueueTask( commandQueue, getterKernel, 0, NULL, NULL );
    clEnqueueReadBuffer( commandQueue, auxBuf, CL_TRUE, 0, sizeof(void*), &gpuPtr, 0, NULL, NULL );
     
    clReleaseMemObject(auxBuf);
     
    ...
    Now "gpuPtr" should contain the address of the beginning of "myBuf" in GPU memory space. Do the necessary modifications if you're not using a 32-bit matching-endianess architecture...

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

    Re: Traversing a Tree using the root pointer

    Now "gpuPtr" should contain the address of the beginning of "myBuf" in GPU memory space. Do the necessary modifications if you're not using a 32-bit matching-endianess architecture...
    There's no guarantee that this sort of code will be portable. Chances are it will break in some implementations.
    Disclaimer: Employee of Qualcomm Canada. Any opinions expressed here are personal and do not necessarily reflect the views of my employer. LinkedIn profile.

  3. #13
    Junior Member
    Join Date
    Feb 2011
    Posts
    5

    Re: Traversing a Tree using the root pointer

    To get back a pointer to device memory when creating buffers so that assemble the tree in a device
    will consume a lot of space in the memory and may thus result in the system slow down.This is because CUDA is not supported by most of the operating Systems .So I would rather advise to for some other software to solve this problem or recently launched symbian OS can also prove as an aid to the problem.

  4. #14
    Member
    Join Date
    Oct 2010
    Location
    Vancouver, Canada
    Posts
    66

    Re: Traversing a Tree using the root pointer

    You really don't want to use pointers. Not only are they potentially different sizes between devices (and host), but they are also potentially different sizes between address spaces (global, local, constant, private). And, even worse, buffers move.

    I recommend using indices. These can be byte indices, or they can be indices into arrays of structs (or other types). You can control their size (8, 16, 32 or 64 bit). You can range check them easily. They can be used to index into parallel arrays (e.g. if you decide to split structs into parallel arrays of sub-elements for optimization reasons). They remain valid if you transfer your data between address spaces (e.g. if you copy from global to local for performance reasons). They are valid across all devices and the host. They can be saved to disk and reloaded, or sent across networks. They are easily serialized and deserialized. And they remain valid no matter where the system copies your buffer.

    You can still use pointers in your code, if need be... converting from an index to a pointer or back again is simple. Just try to avoid storing pointers in your data structures.

Page 2 of 2 FirstFirst 12

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
  •