与SDSoC合成时处理硬件函数中的指针参数

时间:2019-06-05 00:05:04

标签: pointers function-pointers fpga synthesis

我很难使用用作功能 cost_compare 的输入参数的指针,我希望使用Xilinx SDSoC综合工具将其卸载到硬件。

根据@Gerardo Zinno的第一个建议,我设法解决了部分问题(请参阅using values instead of pointers as function arguments-第二个解决方案使情况变得更糟),现在我的代码如下

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

新代码可以在SW中正常运行,但是在SDSoC中运行时,会出现以下错误:

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).'

对应于

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

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

我认为我不能更改函数参数的数量,因为它被另外两个函数调用为

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

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

cost_compare 必须具有特定的签名,因为 spec_qsort qsort 调用 const_compare 时,只有两个元素将要排序的数组(感谢@Gerardo Zinno进行澄清)。

我的问题是如何解决此问题并使代码对硬件友好,以便可以由SDSoC进行合成?

最诚挚的问候

人类

0 个答案:

没有答案