Skip to content

Commit 64c6e5c

Browse files
committed
added comments for DSP inference
1 parent 78566b8 commit 64c6e5c

File tree

3 files changed

+89
-34
lines changed

3 files changed

+89
-34
lines changed

src/rs-dsp-macc.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,29 @@
22
* Copyright (C) 2022 RapidSilicon
33
*
44
*/
5+
6+
// Awais Abbas
7+
// The multiplier's output is added to the accumulator's output, and the result from the adder is fed back into the accumulator.
8+
// this kind of cell structure will be infered as MULTACC
9+
//
10+
//
11+
// _______ ____________
12+
// | | | |
13+
// ACC[19:0] `--->| | | | _________
14+
// | Mult |--------> | | | |___
15+
// In_B[17:0] ---->| | | |------->|D Q| |---------> output
16+
// |_______| | | | | |
17+
// | Add/Neg | | ACC | |
18+
// | | | | |
19+
// | | clk-->| | |
20+
// ACC[63:0] ---->| | |_________| |
21+
// | | | |
22+
// | |____________| |
23+
// | |
24+
// | |
25+
// | |
26+
// |________________________________________|
27+
528
#include "kernel/sigtools.h"
629
#include "kernel/yosys.h"
730
#include "kernel/modtools.h"

src/rs-dsp-multadd.cc

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,40 @@
11
// Copyright (C) 2022 RapidSilicon
22
//
33

4+
// Awais Abbas
5+
// If the multiplier's input is multiplied by a coefficient/constant, and another input is left-shifted, their results are added together,
6+
// will infer a MULTADD operation for RS_DSP.
7+
// _______ ____________
8+
// | | | |
9+
// Coefficint[19:0] ---->| | | |
10+
// | Mult |-------------> | |
11+
// In_B[17:0] ---->| | | |
12+
// |_______| | |
13+
// _______ | Adder |-------> output
14+
// | | | |
15+
// In_A[19:0] ---->| | | |
16+
// | Shift |-------------> | |
17+
// acc_fir[5:0] ---->| Left | | |
18+
// |_______| |____________|
19+
//
20+
// If the accumulator's output is multiplied by the multiplier's second input, and another input is left-shifted, their results are added together,
21+
// with the adder's output serving as the input to the accumulator, this structure will be infered a MULTADD operation for RS_DSP.
22+
//
23+
// ________________________________________________________________
24+
// | |
25+
// | _______ ____________ |
26+
// | | | | | |
27+
// ACC[19:0] `--->| | | | _________ |
28+
// | Mult |-------------> | | | |___|-----------------------------> output
29+
// In_B[17:0] ---->| | | |------->|D Q|
30+
// |_______| | | | |
31+
// _______ | Adder | | ACC |
32+
// | | | | | |
33+
// In_A[19:0] ---->| | | | clk-->| |
34+
// | Shift |-------------> | | |_________|
35+
// acc_fir[5:0] ---->| Left | | |
36+
// |_______| |____________|
37+
438
#include "kernel/yosys.h"
539
#include "kernel/modtools.h"
640
#include "kernel/ffinit.h"
@@ -74,37 +108,6 @@ struct RsDspMultAddWorker
74108
continue;
75109
}
76110
}
77-
// If the following structure is found in the rtlil model than we can infr a MULTADD for RS-DSP
78-
// _______ ____________
79-
// | | | |
80-
// Coefficint[19:0] ---->| | | |
81-
// | Mult |-------------> | |
82-
// In_B[19:0] ---->| | | |
83-
// |_______| | |
84-
// _______ | Adder |-------> output
85-
// | | | |
86-
// In_A[19:0] ---->| | | |
87-
// | Shift |-------------> | |
88-
// acc_fir[5:0] ---->| Left | | |
89-
// |_______| |____________|
90-
//
91-
//
92-
//
93-
// ________________________________________________________________
94-
// | |
95-
// | _______ ____________ |
96-
// | | | | | |
97-
// ACC[19:0] `--->| | | | _________ |
98-
// | Mult |-------------> | | | |___|-----------------------------> output
99-
// In_B[19:0] ---->| | | |------->|D Q|
100-
// |_______| | | | |
101-
// _______ | Adder | | ACC |
102-
// | | | | | |
103-
// In_A[19:0] ---->| | | | clk-->| |
104-
// | Shift |-------------> | | |_________|
105-
// acc_fir[5:0] ---->| Left | | |
106-
// |_______| |____________|
107-
108111
for (auto &add_cell : add_cells_) {
109112
add_shl = false;
110113
add_mul = false;

src/synth_rapidsilicon.cc

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8782,26 +8782,48 @@ void collect_clocks (RTLIL::Module* module,
87828782
case Technologies::GENESIS_3: {
87838783
#ifdef DEV_BUILD
87848784
run("stat");
8785-
#endif
8785+
#endif
8786+
// rs-dsp-multadd pass will infer multiplier as
8787+
// 1. dsp_t1_20X1864_cfg_ports
8788+
// 2. dsp_t1_10X9X32_cfg_params
8789+
// All the parameters and Ports are configured to support multiply-add (MULTADD) functionality.
8790+
87868791
if (new_dsp19x2) // RUN based on DSP19x2 mapping
87878792
run("rs-dsp-multadd -genesis3 -new_dsp19x2 -max_dsp " + std::to_string(max_dsp));
87888793
else
87898794
run("rs-dsp-multadd -genesis3 -max_dsp " + std::to_string(max_dsp));
87908795

87918796
DSP_COUNTER = DSP_COUNTER + Count_ADD;
87928797
run("wreduce t:$mul");
8798+
8799+
// rs-dsp-multacc pass will infer multiplier as
8800+
// 1. dsp_t1_20X18X64_cfg_ports
8801+
// 2. dsp_t1_10X9X32_cfg_params
8802+
// All the parameters and Ports are configured to support multiply-accumulate (MULTACC) functionality.
8803+
87938804
if (!new_dsp19x2)
87948805
run("rs_dsp_macc" + use_dsp_cfg_params + genesis3 + " -max_dsp " + std::to_string(max_dsp));
87958806
else // RUN based on DSP19x2 mapping
87968807
run("rs_dsp_macc" + use_dsp_cfg_params + genesis3 + " -new_dsp19x2" + " -max_dsp " + std::to_string(max_dsp));
87978808

87988809
check_dsp_device_limit();
87998810

8800-
// Check if mult output is connected with Registers output
8811+
// Check if the multiplier output is connected to a register input before decomposing large multipliers.
8812+
// This function configures the parameters DSP_CLK, DSP_RESET_POL, REGOUT,
8813+
// and DSP_RESET if the corresponding multiplier output Y is connected to a register input.
8814+
// This information is later used during register packing stage of DSP inference.
8815+
88018816
if (tech == Technologies::GENESIS_3)
88028817
check_mult_regout();
8818+
8819+
// Process the large multiplier and decompose it into smaller multipliers optimized for RapidSilicon DSP.
8820+
// The smaller multipliers are then mapped to the following cells.
8821+
// \$__RS_MUL20X18
8822+
// \$__RS_MUL10X9
8823+
88038824
processDsp(cec);
88048825

8826+
// map the processed \$__RS_MUL20X18 and \$__RS_MUL10X9 into dsp_t1_dsp_t1_20X18X64_cfg_ports and dsp_t1_10X9X32_cfg_params.
88058827
if (use_dsp_cfg_params.empty())
88068828
run("techmap -map " + dspMapFile + " -D USE_DSP_CFG_PARAMS=0");
88078829
else
@@ -8827,12 +8849,18 @@ void collect_clocks (RTLIL::Module* module,
88278849
}
88288850
sec_check("after_dsp_map4", true, true);
88298851

8852+
// pack the registers connected to the input and output of multipliers into DSP's
88308853
run("rs-pack-dsp-regs -genesis3");
88318854

88328855
// add register at the remaining decomposed small multiplier that are not packed in DSP cells
88338856
if (tech == Technologies::GENESIS_3)
88348857
add_out_reg();
88358858

8859+
// map the processed DSP cells into following cells based on the mode bits
8860+
// RS_DSP_MULT ,RS_DSP_MULT_REGIN, RS_DSP_MULT_REGOUT, RS_DSP_MULT_REGIN_REGOUT
8861+
// RS_DSP_MULTADD ,RS_DSP_MULTADD_REGIN, RS_DSP_MULTADD_REGOUT, RS_DSP_MULTADD_REGIN_REGOUT
8862+
// RS_DSP_MULTACC ,RS_DSP_MULTACC_REGIN, RS_DSP_MULTACC_REGOUT, RS_DSP_MULTACC_REGIN_REGOUT
8863+
88368864
run("rs_dsp_io_regs -tech genesis3");
88378865

88388866
if (cec) {
@@ -8842,7 +8870,8 @@ void collect_clocks (RTLIL::Module* module,
88428870

88438871

88448872
#if 1
8845-
//run("stat");
8873+
run("stat");
8874+
// finaly mapped above DSP mapped multiplier into DSP38 and DSP19X2
88468875
run("techmap -map " + dsp38MapFile);
88478876
if (new_dsp19x2)
88488877
run("techmap -map " + dsp19x2MapFile);

0 commit comments

Comments
 (0)