8 Replies Latest reply on Jun 17, 2013 2:19 AM by himanshu.gautam

    reinterpret_cast in OpenCL1.1

    usachovandrii

      Does exist any possibility to use reinterpret_cast in kernel using OpenCL1.1?????

      Because it works in OpenCL1.2 but return segmentation fault in OpenCL1.1

        • Re: reinterpret_cast in OpenCL1.1
          LeeHowes

          OpenCL C is not C++-based. It's technically invalid. It might work if the compiler happens to be a C++ compielr with modifications but there's no guarantee and it's certainly not portable.

          • Re: reinterpret_cast in OpenCL1.1
            gbilotta

            OpenCL C is, as the name says, C and not C++, so there is no reinterpret_cast. However, the OpenCL C standard defines a class of functions that has very similar functionality (and is, in fact, significantly more powerful): as_type(), that includes both a vector and scalar version for each of the built-in types. As explained in the linked document, the functions allow you to reinterpret the bit sequence of a built-in scalar or vector type as a different scalar of vector type of the same width. How it works if you change the number of components (e.g. int someint; char4 v4 = as_char4(someint)) is implementation-defined.

            • Re: reinterpret_cast in OpenCL1.1
              usachovandrii

              but how to convert float4 to float[4]?

                • Re: reinterpret_cast in OpenCL1.1
                  gbilotta

                  usachovandrii wrote:

                   

                  but how to convert float4 to float[4]?

                  Vector data types cannot be converted to arrays of the corresponding scalar type, as their run-time management is implementation-defined and depends on hardware properties (e.g. on hardware with vector registers a float4 might be a single register).

                  What is it exactly that you are trying to achieve?

                    • Re: reinterpret_cast in OpenCL1.1
                      himanshu.gautam

                      float4 to float[4] can be done using:

                       

                      floatvar[0] = float4var.s0;

                      floatvar[1] = float4var.s1;

                      floatvar[2] = float4var.s2;

                      floatvar[3] = float4var.s3;

                       

                      This is an explicit way. You cannot do this implicity by a cast - as much as I know.

                       

                      There is an ugly way to do this, like (assuming private variable space)

                      *(__private float4 *)( &floatVar[0]) = float4Var;


                      At this point, I dont even know if this will be compiled. I would recommend against using these constructs.

                      Thats the feedback I received when I tried to use such constructs.

                      -

                      Bruhaspati

                  • Re: reinterpret_cast in OpenCL1.1
                    usachovandrii

                    but i also can't convert float4.s"i" to float if "i" is variable and its value is changing.
                    Is it true? or i don't know about some way?

                    • Re: reinterpret_cast in OpenCL1.1
                      usachovandrii

                      I can do it only using reinterpret_casr in opencl1.2. it's realy problem for me and it's only because of unusuable format of access to element's of float4.

                      Does exist some problems to make access to elements of float4 identically as access to float[4]?

                        • Re: reinterpret_cast in OpenCL1.1
                          himanshu.gautam

                          I can do it only using reinterpret_casr in opencl1.2. it's realy problem for me and it's only because of unusuable format of access to element's of float4.


                          Does exist some problems to make access to elements of float4 identically as access to float[4]?

                          I guess there no way for that currently. You can raise a request on KHRONOS forums.

                          One issue seems to be that subscript method requires a pointer, and float4 cannot be treated as one. Anyways a method to dynamically select a item from float4 will be useful.