Results 1 to 2 of 2

Thread: Can the vector types be made more C++ friendly?

  1. #1

    Can the vector types be made more C++ friendly?

    The OpenCL vector types defined in cl_platform.h do not play well with C++. You can not do something this simple:

    #include <vector>
    typedef float cl_float4[4] __attribute__((aligned(16)));
    int main()
    {
    std::vector<cl_float4> vals;

    cl_float4 a = {1.0f, 2.0f, 3.0f, 4.0f};
    vals.push_back(a);
    }

    Because "ISO C++ forbids assignment of arrays". If the definition would be changed to a struct like the following:
    typedef struct cl_float4
    {
    float x,y,z,w;
    } cl_float4 __attribute__((aligned(16)));

    Not only would this play nicer with C++, it would also mirror the behaviour of float4 in device code, which is a win-win in my book.

    -Brian

    See also:
    http://groups.google.com/group/comp.lan ... 01707c9cc7
    http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40192

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

    Re: Can the vector types be made more C++ friendly?

    It is worth noting that cl_platform.h is only an example and a particular vendor is free to implement this file as they feel necessary. That said we have also run into this issue but after consideration we feel it makes more sense to implement the host vector types using the compiler's extension for vector types.

    For example cl_float4 with Visual Studio 2008 could be implemented as:

    typedef union __declspec(intrin_type) _CRT_ALIGN(16) cl_float4
    {
    cl_float f32[4];
    } cl_float4;

    and with __GNUC__ defined, this is what we have:

    typedef cl_float cl_float4 __attribute__ ((__vector_size__ (16), __may_alias__));

    As in both cases these define a non-array type it is valid to do assignment and so your example works.

Similar Threads

  1. Non-power of 2 vector types
    By PaulS in forum Suggestions for next release
    Replies: 2
    Last Post: 02-01-2010, 12:15 PM
  2. Replies: 1
    Last Post: 10-01-2009, 05:04 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
  •