cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

rick_weber
Adept II

Weird error using double precision

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.




0 Likes
10 Replies
gaurav_garg
Adept I

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;

0 Likes

Ok, cool. Thanks!

0 Likes

Gaurav,

I tried your suggestion, but Brook+ appears to always put zero in for the literal regardless of what I set it to.

E.g.

kernel void(out val<>
{
double l0 = 2.0;

val = l0;
}

will return a stream of all zeros. Any suggestions? Also, is it a requirement that all variables be declared before any non-declarative operations/assignments take place? 

0 Likes

That seems strange. Kernel code has to be C compliant.

0 Likes

Also, could you try error checking and errorLog on your outputs stream?

 

Call error() and errorLog() on your output stream and see if you get any information.

0 Likes

Originally posted by: gaurav.garg Also, could you try error checking and errorLog on your outputs stream?

 

 

 

Call error() and errorLog() on your output stream and see if you get any information.

 

 

No dice. I've commented everything out of my code except for basically

double l0 = 1.0;
output = l0;

I don't see any errors whatsoever. Assigning the output to an input stream does work, so I don't think my stream allocations are incorrect.

 

0 Likes
Ceq
Journeyman III

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;
}
}
0 Likes

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; 



0 Likes
Ceq
Journeyman III

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;
}
0 Likes

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.

0 Likes