UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
443 Views
Registered: ‎09-13-2018

Resolving struct pointers in functions parameters

Hi

 

I would like to move "bea_is_dual_infeasible" fuction into hardware (ZCU102, SDSoC 18.03, UBUNTU 18.04).

int bea_is_dual_infeasible( arc_t *arc, cost_t red_cost )
{
 printf(sizeof(arc_t));
   return(    (red_cost < 0 && arc->ident == AT_LOWER)
            || (red_cost > 0 && arc->ident == AT_UPPER) );
}

And here is arc_t and arc definittions:

typedef struct arc arc_t;
...
struct arc
{
  int id;
  cost_t cost;
  node_p tail, head;
  short ident;
  arc_p nextout, nextin;
  flow_t flow;
  cost_t org_cost;
};

Any idea how to resolve the pointer issue in this case? 

Regards

Hooman

0 Kudos
6 Replies
Xilinx Employee
Xilinx Employee
409 Views
Registered: ‎08-20-2018

Re: Resolving struct pointers in functions parameters

Hi nikmehr@gmail.com 

I did not understand your question.

Can you explain exactly what do you see as blocking point?

Best Regards,
Nutan
-------------------------------------------------------------------------------
Please don't forget to reply, kudo and accept as a solution
0 Kudos
391 Views
Registered: ‎09-13-2018

Re: Resolving struct pointers in functions parameters

Hi,

Parameters of function "cost_compare" are pointers to 2 data structures as listed in my first post. I want to offload this function to FPGA but I dont know how to deal with these pointers?

Regards

Hooman

0 Kudos
Xilinx Employee
Xilinx Employee
353 Views
Registered: ‎08-20-2018

Re: Resolving struct pointers in functions parameters

Hi nikmehr@gmail.com 

Please have a look at the below example. 

https://github.com/Xilinx/SDSoC_Examples/tree/master/cpp/getting_started/custom_data_type

It will definitely help you.

Best Regards,
Nutan
-------------------------------------------------------------------------------
Please don't forget to reply, kudo and accept as a solution
0 Kudos
311 Views
Registered: ‎09-13-2018

Re: Resolving struct pointers in functions parameters

Thanks nutang for the link. Actually i posted my problem on stackoverflow since I felt this was mostly a programming issue that could be resolved by C programers. And here is my code for cost_compare function based on their suggestions:

    typedef struct arc *arc_p;
    typedef LONG cost_t;

    typedef struct basket
    {
        arc_t *a;
        cost_t cost;
        cost_t abs_cost;
        LONG number;
    } BASKET;
    /* ... */
    typedef struct arc
    {
        int id;
        cost_t cost;
        node_p tail, head;
        short ident;
        arc_p nextout, nextin;
        flow_t flow;
        cost_t org_cost;
    } arc;
    /* ... */
    int cost_compare( void *x, void *y )
    {
      BASKET *b1 = x;
      BASKET *b2 = y;

      if( b1->abs_cost < b2->abs_cost )
        return 1;
      if( b1->abs_cost > b2->abs_cost )
        return -1;
      if( b1->a->id > b2->a->id )
        return 1;
      else
        return -1;
    }

Although the new code works fine in SW, when runs in SDSoC, it gives me the following errors:

    ERROR: [SYNCHK 200-61] /home/a1083898/Xilinx_examples/original_routeplanning/src/pbeampp.c:85: unsupported memory access on variable 'x' which is (or contains) an array with unknown size at compile time.

    ERROR: [SYNCHK 200-41] /home/a1083898/Xilinx_examples/original_routeplanning/src/pbeampp.c:89: unsupported pointer reinterpretation from type 'i8*' to type '%struct.arc.1.4.6 = type { i32, i64, %struct.node.0.3.5*, %s...' on variable 'x'.

    ERROR: [SYNCHK 200-11] /home/a1083898/Xilinx_examples/original_routeplanning/src/pbeampp.c:89: Argument 'x' has an unsynthesizable type 'i8*' (possible cause(s): pointer to pointer or global pointer).

    ERROR: [SYNCHK 200-11] /home/a1083898/Xilinx_examples/original_routeplanning/src/pbeampp.c:89: Argument 'x' has an unsynthesizable type 'i8*' (possible cause(s): structure variable cannot be decomposed due to (1) unsupported type conversion; (2) memory copy operation; (3) function pointer used in struct; (4) unsupported pointer comparison).'

that correspond to

    if( b1->abs_cost < b2->abs_cost )  /*line 85*/

and

  if( b1->a->id > b2->a->id )  /*line 89*/

I don't think I can change the number of function's arguments since it is called by another 2 functions as

    spec_qsort(perm + 1, basket_sizes[thread], sizeof(BASKET*), cost_compare);

and 

    qsort(perm + 1, basket_sizes[thread], sizeof(BASKET*), cost_compare);

and cost_compare must have a specific signature since spec_qsort and qsort call const_compare with just two elements from the array it is going to sort.

My question is how to resolve this issue and make the code HW friendly so it could be synthesised by SDSoC?

Best regards

Hooman

 

 

0 Kudos
301 Views
Registered: ‎10-17-2017

Re: Resolving struct pointers in functions parameters

Hey nikmehr@gmail.com , 

 

HLS is not very good at making sense of pointers. 

When you are writing hw functions just avoid using them. Looking at your original post. Can you modify your code to be something like:  

 

int bea_is_dual_infeasible( arc_t arc, cost_t red_cost )
{
 printf(sizeof(arc_t));
   return(    (red_cost < 0 && arc.ident == AT_LOWER)
            || (red_cost > 0 && arc.ident == AT_UPPER) );
}

Also,

for HLS to better understand the structs, make sure that the size of the struct is some power of 2 

 

0 Kudos
296 Views
Registered: ‎10-17-2017

Re: Resolving struct pointers in functions parameters

nikmehr@gmail.com About your second code:

 

when you write this: 

int cost_compare( void *x, void *y )

 

I don't think you can use "void" as the function arguments . HLS needs to know exactly what data you want to pass to hardware. 

Its either that or HLS thinks you are trying to pass an array to the hardware. So it needs to know before hand what is the size of this array. Thats why the error : 

ERROR: [SYNCHK 200-61] /home/a1083898/Xilinx_examples/original_routeplanning/src/pbeampp.c:85: unsupported memory access on variable 'x' which is (or contains) an array with unknown size at compile time.

 

Remember that with SDSoC/HLS you cannot just take any C++ code and move it to hardware. You would have to design your code very carefully so that it is translated to the HW well and also you need to make sure that your code does not violate the rules of HLS

0 Kudos