Altera_Forum
Honored Contributor
7 years agoNon-Kernel Functions called from a Kernel
I'm looking to better understand how the offline compiler handles function calls. For example, I have a function definition:
void computeValue(specialStruct *mystruct, ushort *answer); I'm calling it from a while loop / case statement in a single work item kernel. The loop/case statement is intended to work like a synchronous state machine. The ii of the loop is being reported as 2, and I suspect it has something to do with calling the function. I've tried several structures of passing by reference / value or returning the answer versus assigning it to a passed parameter. Could anyone point me to any documentation or reference that talks about calling functions from device kernels? Or building a state machine in openCL? I'd like to get the ii back to 1, and have the while loop essentially stall when the function is called until the value is returned. Any suggestions welcome.
__kernel
__attribute__((task))
void dostuff(.....)
{
structType mystruct;
ushort answer;
while(someCondition)
{
switch(currentState):
case(somevalue1):
.....
if (abc)
currentState = somevalue1;
else
currentState = somevalue2;
break;
case(somevalue2):
computeValue(&mystruct, &answer);
if (answer)
currentState = somevalue1;
else
currentState = somevalue2;
break;
}
}