mirror of
https://github.com/SikongJueluo/Mini-Nav.git
synced 2026-07-13 04:25:32 +08:00
- Make cam_read_noise a pass-through module, removing all noise injection logic - Switch write noise to use noise_mask_bernoulli instead of noise_mask_grouped - Add state machine to cam_write_noise for mask generation timing - Remove noise_mask_grouped.sv (no longer needed) - Remove read noise parameters from cam_noisy and cam_top - Update simulation and benchmark code to reflect read noise removal - Sync documentation to reflect Phase 2 architecture
55 lines
1.4 KiB
Python
55 lines
1.4 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""
|
||
CAM 读取路径 pass-through 集成测试 — Phase 2 cleaned.
|
||
|
||
Read noise 已退休;cam_read_noise 是纯 pass-through。
|
||
本测试验证查询返回的 scores 与 pure matching 一致。
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import cocotb
|
||
import numpy as np
|
||
from cocotb.clock import Clock
|
||
from cocotb.triggers import RisingEdge
|
||
from model.ref_model import (
|
||
match_top1,
|
||
random_hashes,
|
||
unpack_score_debug_flat,
|
||
)
|
||
from tests.top.utils import (
|
||
collect_topk,
|
||
dut_hash_bits,
|
||
dut_lanes,
|
||
dut_num_rows,
|
||
get_param,
|
||
query_once,
|
||
query_topk_once,
|
||
reset_dut,
|
||
write_row,
|
||
write_rows,
|
||
)
|
||
|
||
|
||
@cocotb.test()
|
||
async def read_path_pass_through_produces_pure_matching(dut):
|
||
"""写 4 行,查询存过的行,验证 Top-1/Top-K 与 pure matching 一致。"""
|
||
cocotb.start_soon(Clock(dut.clk, 10, unit="ns").start())
|
||
await reset_dut(dut)
|
||
|
||
num_rows = dut_num_rows(dut)
|
||
hash_bits = dut_hash_bits(dut)
|
||
rng = np.random.default_rng(42)
|
||
rows = random_hashes(rng, num_rows, width=hash_bits)
|
||
|
||
await write_rows(dut, rows)
|
||
query = rows[min(50, num_rows - 1)]
|
||
|
||
top1_index, top1_score, score_debug = await query_once(dut, query)
|
||
expected = match_top1(query, rows, width=hash_bits)
|
||
|
||
assert top1_index == expected.top1_index
|
||
assert top1_score == expected.top1_score
|
||
if score_debug is not None:
|
||
assert np.array_equal(score_debug, expected.scores)
|