我试图了解是否可以在vivado_hls中实例化具有hls::stream<>引用成员的类,这样我就可以直接读取/写入流,而不必将流作为参数传递到调用链中。
注意:这在vivado_hls 2018.2中,该项目的顶层模块是"ModuleX“,请考虑下面的简化场景:
#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个时钟周期--没有很好的理由)。
#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自动生成的)
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发布于 2018-12-09 18:52:20
我不确定底层机制,但是删除static限定符可以让Vivado HLS 2018.2合成这个示例。然而,这在每次顶级函数调用上都会生成一个新的X实例,因此它的字段不会持久存在。下面的示例通过在顶层函数中添加另一个静态变量来解决这个问题,并通过引用X的构造函数将其传递给它。
#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();
}https://stackoverflow.com/questions/53641059
复制相似问题