4 Replies Latest reply on Aug 20, 2011 7:48 AM by Meteorhead

    typecasting

    Meteorhead
      worked before, now it doesn't

      Somebody tell me why are the following lines returning a compiler error!

      The ^ mark is pointing at the T symbol, but nonetheless, nothing in the expression should be entity of float, everything is cast to float4.

      This code worked before, but now it doesn't with SDK 2.5 and Catalyst 11.8 under Win7 64-bit.

       

      void calculateTS(uint chainlength, uint vectors_per_thread, __global int4* height, __global uint4* share, __global int4* output_T, __global float4* output_S) { uint my_share; int4 x; int4 T = (int4)0; float4 S = (float4)0; float4 one_per_m_T; ... ... // T has now been calculated one_per_m_T = ( (float4)(T) / ( (float4)(32.0f * (float4)vectors_per_thread) ) ); ... ... } ERROR IS: OpenCL Compile Error: clBuildProgram failed (CL_BUILD_PROGRAM_FAILURE). Line 321: error: a value of type "int4" cannot be used to initialize an entity of type "float" one_per_m_T = (float4)(T) / ( 32.0f * (float4)vectors_per_thread); ^

        • typecasting
          maximmoroz

           

          Explicit casts between vector types are not legal. Use explicit conversions:

          convert_float4(T)

          convert_float4(vectors_per_thread)



            • typecasting
              Meteorhead

              Thank you for the reply. I was not aware of that, as it used to work properly before.

                • typecasting
                  maximmoroz

                  AMD implementation of OpenCL is more... relaxed and forgiving than others. There were several cases when the code considered corect by AMD APP was considered incorrect by other compilers. Well, maybe it ceases to be this way.

                    • typecasting
                      Meteorhead

                      Specification said that when using mixed vector and scalar operations, the wider will determine the size of the result vector, with the scalar being widened to match. This implicit casting of scalars to vectors seemed autocratic enough to assume that typecasting a vector does not require special funtions.

                      Anyhow, I'll get used to typecasting vectors in this manner to keep code portable. (This very program did not cause any trouble on NVIDIA cards also) The compiler knew what I wanted to do.