Results 1 to 6 of 6

Thread: Check whether cl_mem object is valid

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    6

    Check whether cl_mem object is valid

    Hi all,

    what I am trying to do seems rather simple to me, but at the moment I have the feeling it is not possible with OpenCL:

    I want to check whether some cl_mem-object is actually valid before releasing it:

    Code :
    cl_mem someimage;
    if ( isvalid(someimage) ) clReleaseMemObject(someobject);

    The reason is simple: If I call clReleaseMemObject without initializing "someimage", my program crashes. I could put a "try {...} catch {...}" around the call, but this seems somehow dirty to me.

    Any call like "clGetImageInfo(someimage)" also crashes, if it is not initialized.

    How could I implement "isvalid(someimage)"?

    Many thanks for any hints, Jakob

  2. #2

    Re: Check whether cl_mem object is valid

    Querying properties on invalid mem objects should return safely with the CL_INVALID_MEM_OBJECT error. Your program crashing indicates a possible bug in the OpenCL implementation you are using.

  3. #3
    Junior Member
    Join Date
    Aug 2011
    Posts
    6

    Re: Check whether cl_mem object is valid

    Thank you. My impression somehow was, that this should be the desired behavior - but I could not believe that there is such a rather dirty bug in the nVidia OpenCL implementation. I use a nVidia GTS 250 card with the developer driver version 270.81. I just realized that there is a newer driver release - I will check if this helps.

  4. #4
    Senior Member
    Join Date
    Aug 2011
    Posts
    271

    Re: Check whether cl_mem object is valid

    cl_mem is a pointer type.

    Normal C conventions are to initialise pointers to NULL (which is always just 0), which will then be the same 0 result as from a failed allocation and treated the same way.

    Then just test it before releasing it:

    if (someimage) clReleaseMemObject(someimage);

    If 'someimage' is a value on the stack, it will be initialised with completely random data. Checking the validity of pointers is too expensive to add to every call, so it's not surprising using a completely invalid pointer causes a crash.

  5. #5
    Junior Member
    Join Date
    Aug 2011
    Posts
    6

    Re: Check whether cl_mem object is valid

    I was not sure whether an initialization with "NULL" was okay for the cl_mem object.

    In case cl_mem is a pointer type, this is of course the clean solution.

    Thanks a lot!

  6. #6

    Re: Check whether cl_mem object is valid

    Even though initialization to NULL is a way to work around this, the implementation should still not segfault on encountering an invalid cl_mem object. I suggest you do report it to the manufacturer, although considering it's nvidia I don't know how much they'll care about it.

Similar Threads

  1. render cl_mem(image object) to window
    By opencl_beginner in forum OpenCL
    Replies: 4
    Last Post: 12-10-2010, 05:55 AM
  2. Printing a cl_mem object
    By arunr14 in forum OpenCL
    Replies: 1
    Last Post: 05-30-2010, 07:31 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
  •