Constant variables in SeExpr2 using VarBlocks

75 views
Skip to first unread message

Christopher Horvath

unread,
Jun 25, 2020, 5:26:37 PM6/25/20
to seexpr-discuss
Hi! I'm trying to add constant variables to my expressions. Specifically, I have a variable "time" which is the global time of my simulation. I'm using the Variable Blocks approach.

Here's what I tried:

SeExpr2::VarBlockCreator block_creator;
int time_handle = block_creator.registerVariable("time", SeExpr2::ExprType().FP(1).Constant());
int position_handle = block_creator.registerVariable("position", SeExpr2::TypeVec(2));
int output_handle = block_creator.registerVariable("__output", SeExpr2::TypeVec(2));

SeExpr2::Expression expression{expr_string};
expression.setDesiredReturnType(SeExpr2::TypeVec(2));
expression.setVarBlockCreator(&block_creator);

double time = ...;
double* positions = ...;
double* outputs = ...;

SeExpr2::VarBlock block = block_creator.create();
block.Pointer(time_handle) = &time;
block.Pointer(position_handle) = positions;
block.Pointer(output_handle) = outputs;
expression.evalMultiple(&block, output_handle, 0, N);

This code failed, and based on printing out the resulting output data, it looks like the 0th entry is correct, and every subsequent one is wrong. As far as I can tell, when accessing the 'time' variable it is treating it like varying and iterating through memory and getting garbage. If I make the 'time' variable artificially 'Varying' and make an array of the same value, everything works.

What am I doing wrong?

Thanks,
Chris

Andrew Selle

unread,
Jun 25, 2020, 6:49:56 PM6/25/20
to seexpr-...@googlegroups.com
It's been awhile. You probably want to be using uniform instead of constant. If you plan to use the same expression instance over multiple times without recompiling the block. It also may be possible that constants don't really work properly in variable blocks. Maybe someone inside WDAS has more experience.

--
You received this message because you are subscribed to the Google Groups "seexpr-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to seexpr-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/seexpr-discuss/1b1a9433-1092-409e-b86e-a9519e278674o%40googlegroups.com.

Andrew Selle

unread,
Jun 25, 2020, 8:03:33 PM6/25/20
to seexpr-...@googlegroups.com
Yes I think uniform will work as you expect. constant really is for things that can be truly constant folded into assembly code whereas time is uniform for all indirect indices.

It looks like there is code to handle the uniform case here:

in the llvm code

in the interpreter code

So definitely try uniform, I think constant would be improperly evaluated. I think constant is not valid to be in a var block, maybe. It probably could be made to work by changing these places. On the other hand, they probably could never be constant folded properly, so I think the type checker should pretty much reject this.

-A
Reply all
Reply to author
Forward
0 new messages