我修改了测试以及内部代码,在顶层函数中,将输入直连输出,但是结果发现第一次inject时没有得到包,第二次则可以得到有包输出。…
- User
我修改了测试以及内部代码,在顶层函数中,将输入直连输出,但是结果发现第一次inject时没有得到包,第二次则可以得到有包输出。 测试代码添加了32个reset为1的周期以及32个reset为0的周期,在实际输入开始前,但是仍然没有得到第一次的输出。 根据这一情况,结合下面的测试代码/顶层函数/期望的C simulation输出以及错误的RTL simulation输出,详细分析问题原因,具体通俗解释并提供解决方案。 可能是因为什么#pragma Dataflow 需要第一次的数据初始化pipeline吗? 注意!!仔细分析我的代码逻辑,我注入每个包都等待了32个cycle,注入一个包随后,不注入任何东西,静等32个周期去看输出结果,理论上dataflow一定会被填充,因此不会存在覆盖,你如果从下一个包覆盖上一个包这种角度回答这个问题我就自杀。
1.测试代码:
#include "switch_top.hpp" #include "common.hpp" #include
// AXIS beat construction static axis_word make_header( ap_uint<ADDR_LENGTH> src, ap_uint<ADDR_LENGTH> dst, ap_uint<PACKET_TOTAL_LENGTH> words) { axis_word w; // Clear entire word w.data = 0; // Payload length (words inc. header) w.data(PACKET_TOTAL_LENGTH - 1, 0) = words; // Source & destination L2 addresses w.data(SRC_ADDR_START + ADDR_LENGTH - 1, SRC_ADDR_START) = src; w.data(DST_ADDR_START + ADDR_LENGTH - 1, DST_ADDR_START) = dst; // Single-word packet -> last = 1 w.last = 1; return w; }
// Push a single-word packet into ingress stream of port
pstatic void inject_packet(axis_strm (&rx)[NUM_PORTS], unsigned p, ap_uint<ADDR_LENGTH> src, ap_uint<ADDR_LENGTH> dst) { axis_word hdr = make_header(src, dst, 1); rx[p].write(hdr); }// Read out one packet (single word) if present, return true if got one static bool drain_packet(axis_strm &txPort, ap_uint<ADDR_LENGTH> &src, ap_uint<ADDR_LENGTH> &dst) { if (txPort.size() == 0) return false; axis_word w = txPort.read(); src = w.data(SRC_ADDR_START + ADDR_LENGTH - 1, SRC_ADDR_START); dst = w.data(DST_ADDR_START + ADDR_LENGTH - 1, DST_ADDR_START); return true; }
// Simulation constants
static void run_cycles(axis_strm (&rx)[NUM_PORTS], axis_strm (&tx)[NUM_PORTS], int cycles, ap_uint<1> &rst) { for (int c = 0; c < cycles; ++c) { switch_top(rx, tx, rst); for (int p = 0; p < NUM_PORTS; p++) { if (tx[p].size() > 0) { printf("cycle = %d, port = %d, size = %d \n", c, p, (int)tx[p].size()); } } } }
int main() {
axis_strm rx[NUM_PORTS]; axis_strm tx[NUM_PORTS];#pragma HLS STREAM variable=rx depth=32 #pragma HLS STREAM variable=tx depth=32
ap_uint<1> reset_ctrl = 1; run_cycles(rx, tx, 32, reset_ctrl); // clear reset_ctrl = 0; run_cycles(rx, tx, 32, reset_ctrl); // make it stable // Test #1 – Flooding on unknown destination // Packet: Port1 (addr=0x1) -> dst_addr = 0x2 (unknown) printf("Before injection: rx[1].size()=%d\n", (int)rx[1].size()); inject_packet(rx, 1, 0x1, 0x2); printf("After injection: rx[1].size()=%d\n", (int)rx[1].size()); run_cycles(rx, tx, 32, reset_ctrl); printf("After digest: rx[1].size()=%d\n", (int)rx[1].size()); for (unsigned p = 0; p < NUM_PORTS; ++p) { printf("tx[%u].size()=%d\n", p, (int)tx[p].size()); } bool flood_ok = true; ap_uint<ADDR_LENGTH> src, dst; // Expect one copy on every egress except port1 for (unsigned p = 0; p < NUM_PORTS; ++p) { if (p == 1) continue; bool got = drain_packet(tx[p], src, dst); flood_ok &= got && (dst == 0x2) && (src == 0x1); printf("got %u= %d\n", p, got ? 1 : 0); } // Port1 must be silent flood_ok &= (tx[1].size() == 0); printf("[TB] Flooding test : %s\n", flood_ok ? "PASS" : "FAIL"); // Test #2 – Learning + Unicast // Packet: Port2 (addr=0x2) -> dst = 0x1 (switch should have learned mappint (src_addr=0x1, port1) inject_packet(rx, 2, 0x2, 0x1); run_cycles(rx, tx, 32, reset_ctrl); bool unicast_ok = drain_packet(tx[1], src, dst) && src == 0x2 && dst == 0x1; // Ensure no duplicates on other egresses for (unsigned p = 0; p < NUM_PORTS; p++) { if (p == 1) continue; unicast_ok &= (tx[p].size() == 0); } printf("[TB] Learning & unicast test : %s\n", unicast_ok ? "PASS" : "FAIL"); // 4. Summary if (flood_ok && unicast_ok) { printf("[TB] *** ALL TESTS PASSED ***\n"); return 0; } else { printf("[TB] *** TESTS FAILED ***\n"); return 0; } Assistant
根据提供的代码和模拟结果,问题的根源在于 RTL流水线初始化和数据传递时序差异,具体分析如下:
问题根源分析
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.