# ds-simple-fpga-nn **Repository Path**: luzhihaoTestingLab/ds-simple-fpga-nn ## Basic Information - **Project Name**: ds-simple-fpga-nn - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-20 - **Last Updated**: 2026-06-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # FPGA NN 实现集合 三个 2-4-1 全连接神经网络推理的 Verilog 实现,从简单到复杂逐步演进。 ## 项目结构 ``` ├── simple_nn/ # 整数权重版 │ ├── simple_nn.v # 设计(硬编码整数权重) │ ├── tb_simple_nn.v # testbench │ └── verify_nn.py # Python 参考模型 │ ├── simple_nn_fixed/ # 定点 Q8.8 版 │ ├── simple_nn_fixed.v # 设计(扁平实现) │ ├── simple_nn_fixed_top.v # 设计(模块化,使用 dense_layer) │ ├── tb_simple_nn_fixed_top.v # testbench │ └── verify_nn_fixed.py # Python 参考模型 │ ├── simple_nn_pipe/ # 流水线 Q8.8 版 │ ├── simple_nn_pipe.v # 设计(使用 dense_layer_pipe) │ └── tb_simple_nn_pipe.v # testbench │ └── common/ # 共享模块 ├── relu_saturate.v # ReLU + 8-bit 饱和截断 ├── dense_layer.v # 全连接层(组合逻辑 + 1 拍输出) └── dense_layer_pipe.v # 全连接层(输入寄存 + 输出寄存,2 拍延迟) ``` ## 三个版本对比 | 版本 | 权重格式 | 延迟 | 吞吐量 | 适用场景 | |------|---------|------|--------|---------| | simple_nn | 整数 | 1 拍 | 1 个/周期 | 快速验证,整数推理 | | simple_nn_fixed | Q8.8 定点 | 2 拍 | 1 个/周期 | 定点小数推理 | | simple_nn_pipe | Q8.8 定点 | 4 拍 | 1 个/周期 | 高吞吐流水线 | ## 编译与仿真 需要 [Icarus Verilog](http://iverilog.icarus.com/) (iverilog + vvp)。 ```sh # 整数权重版 iverilog -o simple_nn/tb.vvp simple_nn/simple_nn.v simple_nn/tb_simple_nn.v vvp simple_nn/tb.vvp # 定点 Q8.8 版 iverilog -o simple_nn_fixed/tb.vvp common/relu_saturate.v common/dense_layer.v simple_nn_fixed/simple_nn_fixed_top.v simple_nn_fixed/tb_simple_nn_fixed_top.v vvp simple_nn_fixed/tb.vvp # 流水线版 iverilog -o simple_nn_pipe/tb.vvp common/relu_saturate.v common/dense_layer_pipe.v simple_nn_pipe/simple_nn_pipe.v simple_nn_pipe/tb_simple_nn_pipe.v vvp simple_nn_pipe/tb.vvp ``` ## Python 验证 ```sh python simple_nn/verify_nn.py # 整数版参考模型 python simple_nn_fixed/verify_nn_fixed.py # 定点版参考模型 ```