10 Replies Latest reply on Mar 8, 2009 7:22 AM by dbnelson

    Weird error using double precision

    rick.weber

      Since the library of standard mathematical functions doesn't support double precision, I decided to write my own function to perform an exponential. In doing so I get this error:

       

      ERROR: Expected a object of type 'struct'

      While processing <buffer>:103

      In compiler at GetSubpart()[astsymbol.cpp:636]

        Name() = <literal>

        member_name = x

      Aborting...

      Problem with compiling basisFunc_computeBasisFunction.hlslERROR: Expected a object of type 'struct'

      While processing <buffer>:160

      In compiler at GetSubpart()[astsymbol.cpp:636]

        Name() = <literal>

        member_name = x

      Aborting...

      Problem with compiling basisFunc_computeBasisFunction_addr.hlsl

       

      (ignore the line numbers on the left. All numbers variables are declared as double).

       23   sum = 1.0; 

       24   exponent = val;

       26   sum += exponent;

       27   exponent*=exponent;

       28   tmp = exponent / 2.0;

       29   sum += tmp;

       30   exponent*=exponent;

       32   sum += exponent/6.0;

       33   exponent*=exponent;

       34   sum += exponent/24.0;

       35   exponent*=exponent;

       36   sum += exponent/120.0;

       37   exponent*=exponent;

       38   sum += exponent/720.0;

       39   exponent*=exponent;

       41   basis = sum;

      The error occurs because of the sum += exponent/<literal> lines. Is this a bug? I also get the error on line 28. While this isn't told in the error, I deduced this by commenting stuff out.




        • Weird error using double precision
          gaurav.garg

          Hi Rick,

           

          There seems to be some issue with codegen while using double literals in an expression.

          As a workaround you can declare your double literals before using them in an expression. e.g. change

          sum += exponent/<literal>

          to

          double temp = <literal>;

          sum += exponent/temp;

          • Weird error using double precision
            Ceq
            To the question: "Also, is it a requirement that all variables be declared before any non-declarative operations/assignments take place?"

            You can call other kernels as helper functions sou you don't need to declare every temporal variable at the beginning of the first kernel.
            You also can use brackets to define a new scope inside the kernel, but the variables defined inside it would be inaccesible after its end, example:

            kernel void ker(float i<>, out float o<>) {
            float t1 = 2.0f;
            float t2 = i * 3.0f;
            another_kernel(i, o);
            o = t1 + t2;
            {
            float t3 = 4.0f;
            o += 4.0f;
            }
            }
              • Weird error using double precision
                rick.weber

                 

                Originally posted by: Ceq To the question: "Also, is it a requirement that all variables be declared before any non-declarative operations/assignments take place?" You can call other kernels as helper functions sou you don't need to declare every temporal variable at the beginning of the first kernel. You also can use brackets to define a new scope inside the kernel, but the variables defined inside it would be inaccesible after its end, example: kernel void ker(float i<>, out float o<> { float t1 = 2.0f; float t2 = i * 3.0f; another_kernel(i, o); o = t1 + t2; { float t3 = 4.0f; o += 4.0f; } }


                Well, an example of code that doesn't compile for me is:

                kernel void(double in<>,out double output<>
                {
                double l0;
                l0 = 1.0;
                double test;

                output = in; 

                I get basisFunc.br(17) : Error (parse error) before 'double'

                double test;

                ^

                ***Unable to parse basisFunc.br

                However, this does:

                 

                kernel void(double in<>,out double output<>
                {
                double l0;
                double test;
                l0 = 1.0;

                output = in; 



              • Weird error using double precision
                Ceq
                Yes, but you can nest brackets and create new variables inside the new scope, try this:

                kernel void fun(double i<>, out double o<>) {
                double l0;
                l0 = 1.0;
                {
                double test;
                test = 2.0;
                l0 = l0 + test;
                }
                o = l0;
                }
                  • Weird error using double precision
                    dbnelson

                    Did this solve the problem? I'm getting similar errors (compiling with Brook+ 1.3), and while defining variables for all my constants removed the compile error, it appears the calculations are no longer working. It worked fine with floats, but now double-type variables fail.