首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >类型为hls::stream<int>&的Vivado HLS类会导致错误:“常数‘具有不可综合的类型.”

类型为hls::stream<int>&的Vivado HLS类会导致错误:“常数‘具有不可综合的类型.”
EN

Stack Overflow用户
提问于 2018-12-05 21:30:05
回答 1查看 1.1K关注 0票数 0

我试图了解是否可以在vivado_hls中实例化具有hls::stream<>引用成员的类,这样我就可以直接读取/写入流,而不必将流作为参数传递到调用链中。

注意:这在vivado_hls 2018.2中,该项目的顶层模块是"ModuleX“,请考虑下面的简化场景:

代码语言:javascript
复制
#include <hls_stream.h>
#include <ap_int.h>

using hls_int = ap_uint<32>;

class X
{
  private:
    hls::stream<hls_int> &s1;
    hls::stream<hls_int> &s2;

  public:
    X(hls::stream<hls_int> &_s1, hls::stream<hls_int> &_s2) :
        s1(_s1), s2(_s2)
    {}

    void Run()
    {
        hls_int s = s2.read();
        hls_int out = s * 2;
        s1.write(out);
    }
};

void ModuleX(hls::stream<hls_int> &s1, hls::stream<hls_int> &s2)
{
    #pragma HLS INTERFACE ap_ctrl_none PORT=return
    #pragma HLS STREAM VARIABLE=s1 DEPTH=1
    #pragma HLS STREAM VARIABLE=s2 DEPTH=1

    static X x {s1, s2};

    x.Run();
}

使用这种方法,我得到以下错误:ERROR: [SYNCHK 200-11] ClassWithStreamRefs.cpp:18: Constant 'x.s2.V.V' has an unsynthesizable type 'i32P*' (possible cause(s): pointer to pointer or global pointer).

我理解在底层,编译器可能将引用存储为指向流的指针,但就我所认为的这个场景的工具而言,这应该是一个bug,因为它是阻塞的,我认为它是有效的HLS。

希望有另一种方法来实现我正在寻找的东西(引用,而不是值存储在类中)。

我试过的其他有用的东西如下所示。但是,这是非常不可取的,因为这种方法增加了2个延迟时钟周期(在入口和出口各增加1个时钟周期--没有很好的理由)。

代码语言:javascript
复制
#include <hls_stream.h>
#include <ap_int.h>

using hls_int = ap_uint<32>;

class X
{
  public:
    hls::stream<hls_int> s1;
    hls::stream<hls_int> s2;
    X()
    {
        #pragma HLS STREAM VARIABLE=s1 DEPTH=1
        #pragma HLS STREAM VARIABLE=s2 DEPTH=1
    }

    void Run()
    {
        hls_int s = s2.read();
        hls_int out = s * 2;
        s1.write(out);
    }
};

void ModuleX(hls::stream<hls_int> &s1, hls::stream<hls_int> &s2)
{
    #pragma HLS INTERFACE ap_ctrl_none PORT=return
    #pragma HLS INLINE
    static X x;

    x.s2.write(s2.read());
    x.Run();
    s1.write(x.s1.read());
}

下面是一个示例tcl脚本(尽管它基本上是由vivado_hls自动生成的)

代码语言:javascript
复制
open_project ClassWithStreamRef
set_top ModuleX
add_files ClassWithStreamRefs.cpp -cflags "-std=c++11"
open_solution "solution1"
set_part {xczu19eg-ffvc1760-2-i} -tool vivado
create_clock -period 10 -name default
csynth_design
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-09 18:52:20

我不确定底层机制,但是删除static限定符可以让Vivado HLS 2018.2合成这个示例。然而,这在每次顶级函数调用上都会生成一个新的X实例,因此它的字段不会持久存在。下面的示例通过在顶层函数中添加另一个静态变量来解决这个问题,并通过引用X的构造函数将其传递给它。

代码语言:javascript
复制
#include <hls_stream.h>
#include <ap_int.h>

using hls_int = ap_uint<32>;

struct State
{
    hls_int counter;
};

class X
{
  private:
    hls::stream<hls_int> &s1;
    hls::stream<hls_int> &s2;
    State& state;

  public:
    X(hls::stream<hls_int> &_s1, hls::stream<hls_int> &_s2, State& _state) :
        s1(_s1), s2(_s2), state(_state)
    {}

    void Run()
    {
        hls_int s = s2.read();
        s1.write(s + state.counter++);
    }
};

void ModuleX(hls::stream<hls_int> &s1, hls::stream<hls_int> &s2)
{
    #pragma HLS INTERFACE ap_ctrl_none PORT=return
    #pragma HLS STREAM VARIABLE=s1 DEPTH=1
    #pragma HLS STREAM VARIABLE=s2 DEPTH=1

    static State state {0};
    X x {s1, s2, state};

    x.Run();
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53641059

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档