Page 4 of 10 FirstFirst 12345678 ... LastLast
Results 31 to 40 of 100

Thread: OpenCL C++ Bindings

  1. #31
    Junior Member
    Join Date
    Apr 2009
    Posts
    27

    Re: OpenCL C++ Bindings

    It is a good point about the pointers over references. The reasons pointers are used in certain places is that they map directly to where this are map as pointers in the underlying C model. In general, I agree that references should be used but I do not particularly like the fact that C++ allows something to be side-effected without indicating it on the side of the call. I understand the argument about the NULL pointer and will think more about this.

  2. #32
    Junior Member
    Join Date
    Apr 2009
    Posts
    27

    Re: OpenCL C++ Bindings

    We have C++ bindings for the GL extensions that we will be releasing in the near future.

  3. #33

    Re: OpenCL C++ Bindings

    I assume you mean CL extensions?

  4. #34
    Junior Member
    Join Date
    Oct 2009
    Posts
    15

    Re: OpenCL C++ Bindings

    cl_extension for oepngl-context sharing

    can you announce it here, when you release them?

    thanks

  5. #35
    Junior Member
    Join Date
    Apr 2009
    Posts
    27

    Re: OpenCL C++ Bindings

    Yes I did mean CL

    I will be sure to comment here when they go up.

  6. #36
    Junior Member
    Join Date
    Nov 2009
    Posts
    3

    Re: OpenCL C++ Bindings

    Hi Ben, I'm really enjoying reading the C++ bindings header - great job!

    I'm also trying to learn from it how to use the C API properly. One thing I notice is that in cl::Platform::get() you call clGetDeviceIDs twice: first to get the number of available platforms, and then to read them. The first call has the following parameters: (num_entries = 0, *platforms = NULL, *num_platforms = &n). According to Section 4.1 of the standard:
    "The number of OpenCL platforms returned is the mininum of the value specified by num_entries or the number of OpenCL platforms available.
    But if the number of returned platforms is the minimum, then it should be 0, not 1 as returned both by AMD's and NVIDIA's implementations. So where's the bug -- in the standard or in the code?

  7. #37

    Re: OpenCL C++ Bindings

    I guess the bug is with you The "number of OpenCL platforms returned" refers to the number of platforms written to the "platforms" pointer, not to the integer returned in "num_platforms".

  8. #38
    Junior Member
    Join Date
    Nov 2009
    Posts
    3

    Re: OpenCL C++ Bindings

    eyebex, you are right. But still there is a bug - a typo in the word "mininum" .

    P.S. I don't like when an API call can serve two separate functions: in this case, to get the number of available platforms and to get the platforms proper. But I see how it reduces the total number of API functions, which is a good thing.

  9. #39
    Junior Member
    Join Date
    Dec 2009
    Posts
    5

    Re: OpenCL C++ Bindings

    I have recently started using OpenCL via C++ binding, which are of great help. I have been trying to pass int2 arguments to the kernel and found that a most obvious way to do it does not work with the C++ bindings.

    Code :
    const char* OpenCLSource =
     "__kernel void test1(__global uint* out, int2 a){"
     "  unsigned int i = get_global_id(0);"
     "  out[i] = a[i%2];}"
    int main(void) {
      cl_int2  a = {0,1};
      const int sz = 128;
      cl::Buffer _out( context,CL_MEM_WRITE_ONLY, sz*sizeof(unsigned int) );
    //Setup code omitted for brevity..............
        cl::KernelFunctor func = kernel.bind(queue,cl::NDRange(sz),cl::NDRange()   );
        func(_out, a).wait(); //Generates incorrect calls to C API: 
       //   Currently:  clSetKernelArg(object_, 1, sizeof(int*), &a);
       //   Should be: clSetKernelArg(object_, 1, sizeof(int[2]), a );

    The work around is to use
    Code :
    kernel.setArg(1,sizeof(cl_int2), a);
    But the first method is cleaner and is a default way to do it, unless you know better. I have implemented a fix which I will post in the next message.

  10. #40
    Junior Member
    Join Date
    Dec 2009
    Posts
    5

    Re: OpenCL C++ Bindings

    As described in my previous message, fixed size vector arguments are not handled correctly. To support correct handling of arguments of type float2, int4 , etc... I propose the following change
    Code :
    --- cl_orig.hpp	Thu Dec 17 16:21:25 2009
    +++ cl.hpp	Thu Dec 17 15:40:17 2009
    @@ -2990,10 +2991,39 @@
     template <typename T>
     struct KernelArgumentHandler
     {
    -    static ::size_t size(const T& value) { return sizeof(T); }
    -    static T* ptr(T& value) { return &value; }
    +  static ::size_t size(const T& value)   { return sizeof(T); }
    +  static void const* ptr(T const& value) { return &value;    }
     };
     
    +template <typename T>
    +struct KernelArgumentHandler< T[2] >
    +{
    +  static ::size_t size(const T value[2])   { return sizeof(T[2]); }
    +  static void const* ptr(const T value[2]) { return value;        }
    +};
    +
    +template <typename T>
    +struct KernelArgumentHandler< T[4] >
    +{
    +  static ::size_t size(const T value[4])   { return sizeof(T[4]); }
    +  static void const* ptr(const T value[4]) { return value;        }
    +};
    +
    +template <typename T>
    +struct KernelArgumentHandler< T[8] >
    +{
    +  static ::size_t size(const T value[8])   { return sizeof(T[8]); }
    +  static void const* ptr(const T value[8]) { return value;        }
    +};
    +
    +template <typename T>
    +struct KernelArgumentHandler< T[16] >
    +{
    +  static ::size_t size(const T value[16])   { return sizeof(T[16]);}
    +  static void const* ptr(const T value[16]) { return value;        }
    +};
    +
    +
     template <>
     struct KernelArgumentHandler<LocalSpaceArg>
     {
    @@ -3225,7 +3255,7 @@
          * generated.
          */
         template <typename T>
    -    cl_int setArg(cl_uint index, T value)
    +    cl_int setArg(cl_uint index, T const & value)
         {
             return detail::errHandler(
                 ::clSetKernelArg(

    Basically I define template specialisations for data types T[2],T[4],T[8] and T[16] for any basic type T. Also with my compiler (Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3052 for 80x86) I had to change
    Code :
    Kernel::setArg(index, T value)   // TO
    Kernel::setArg(index, T const & value)
    for this scheme to work, but I think this might be a more proper way of doing it anyway.

Page 4 of 10 FirstFirst 12345678 ... LastLast

Similar Threads

  1. PyOpenCL: OpenCL Python Bindings
    By inducer77 in forum OpenCL
    Replies: 2
    Last Post: 11-03-2011, 05:46 AM
  2. OpenCL C# bindings
    By The Fiddler in forum OpenCL
    Replies: 1
    Last Post: 08-11-2009, 03:00 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
  •