opentitan icon indicating copy to clipboard operation
opentitan copied to clipboard

BRAM is not inferring for prim_generic_rom.sv

Open rpenugo opened this issue 7 years ago • 18 comments

prim_generic_rom.sv is not inferring BRAM causing splice flow to break.

As there is no write port , Vivado is inferring a constant for the code.

Following can be mitigation options 1.Move back to using "prim_generic_ram" where there is a unused write port 2.Use hard instantiation templates for ROM instances for "Xilinx" target

Any other suggestions

rpenugo avatar Oct 10 '19 19:10 rpenugo

According to the Xilinx synthesis manual, we could try to add the following rom_style attribute to the RTL code in order to force the tool to select block rams for this ROM:

(* rom_style = “block” *) reg [data_size-1:0] myrom [2**addr_size-1:0];

msfschaffner avatar Oct 10 '19 19:10 msfschaffner

ah, that's a good idea! I guess this now requires us to plumb impl=xilinx all the way through. I will do that.

On Thu, Oct 10, 2019 at 12:46 PM msfschaffner [email protected] wrote:

According to the Xilinx synthesis manual https://www.xilinx.com/support/documentation/sw_manuals/xilinx2019_1/ug901-vivado-synthesis.pdf, we could try to add the following rom_style attribute to the RTL code in order to force the tool to select block rams for this ROM:

(* rom_style = “block” *) reg [data_size-1:0] myrom [2**addr_size-1:0];

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/lowRISC/opentitan/issues/422?email_source=notifications&email_token=AAH2RSSBPNBUY5HAQFMCJ33QN6BDDA5CNFSM4I7Q3CBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEA5T6QI#issuecomment-540753729, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAH2RSUMIKD7NMAN5GKOVYLQN6BDDANCNFSM4I7Q3CBA .

tjaychen avatar Oct 10 '19 19:10 tjaychen

yeah that will be needed...

msfschaffner avatar Oct 10 '19 20:10 msfschaffner

According to the Xilinx synthesis manual, we could try to add the following rom_style attribute to the RTL code in order to force the tool to select block rams for this ROM:

(* rom_style = “block” *) reg [data_size-1:0] myrom [2**addr_size-1:0];

I guess when trying to infer from RTL , above style would help with a look up table style implementation of ROM which is not our case.

rpenugo avatar Oct 10 '19 21:10 rpenugo

Yeah maybe. I think we just have to give it a try with (* rom_style = “block” *) logic [Width-1:0] mem [Depth]; to check whether it works for our case...

msfschaffner avatar Oct 10 '19 21:10 msfschaffner

rom_style=block did not work for me :(

tjaychen avatar Oct 10 '19 23:10 tjaychen

rom_style may not have worked because our fpga.core file was pointing at a stale location where there was no longer a rom file.

I'm guessing this means prim_rom couldn't properly initialize and it was just....blank. I'll fix this and see if rom_style fix helps.

tjaychen avatar Oct 11 '19 23:10 tjaychen

so despite the style being recognized and the ROM contents correctly loaded this time, it seems the tool still won't infer RAM (when the ROM contents weren't loaded correctly, the warning doesn't even show up)

image

tjaychen avatar Oct 12 '19 00:10 tjaychen

Maybe we should rewrite prim_xilinx_rom.sv according to the Xilinx synthesis guide... It is a target dependent prim after all, and it looks like we cannot just reuse prim_generic_ram_1p in this case...

msfschaffner avatar Oct 12 '19 01:10 msfschaffner

O sorry I should have clarified. Switching to using prim_ram_1p does work. What doesn't work is using read only ram+block style+valid ROM contents, for whatever reason.

The reason the tool gives is that it either cannot find size (which I doubt) or that it can't find valid read/write ports.

I'll have a closer what the other recommendations are...I just really prefer to not have to directly instantiate brams

tjaychen avatar Oct 13 '19 18:10 tjaychen

Ok, interesting... One thing I have noticed working with Altera and Xilinx tools is that sometimes when you try to get something very specific (such as byte write enables in RAMs for instance), you have to implement that exactly as specified in the synthesis guide such that the tool correctly infers and places it correctly. I would give a dedicated implementation a try instead of switching to prim_ram_1p... or did you try that already?

msfschaffner avatar Oct 14 '19 17:10 msfschaffner

i really really wanted to avoid direct instantiations of BRAM though...is that what you meant by dedicated implementation?

tjaychen avatar Oct 14 '19 17:10 tjaychen

FYI - this situation you describe also happens for DesignCompiler if trying to infer "exotic" flops (e.g. with clock enables, load enables, etc), you need to get it exactly the way they say or it does something very weird. (Thankfully in DC you really don't have RAM inference, just flops, so it's some smaller subset of things to worry about, but the lesson is the same.)

On Mon, Oct 14, 2019 at 10:14 AM msfschaffner [email protected] wrote:

Ok, interesting... One thing I have noticed working with Altera and Xilinx tools is that sometimes when you try to get something very specific (such as byte write enables in RAMs for instance), you have to implement that exactly as specified in the synthesis guide such that the tool correctly infers and places it correctly. I would give a dedicated implementation a try instead of switching to prim_ram_1p... or did you try that already?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/lowRISC/opentitan/issues/422?email_source=notifications&email_token=AJBZS7D2QKXQWCZDBJT5YBLQOSSFRA5CNFSM4I7Q3CBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBFUFUY#issuecomment-541803219, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJBZS7GJCCX3KRD6SNN3EOTQOSSFRANCNFSM4I7Q3CBA .

cdgori avatar Oct 14 '19 17:10 cdgori

@tjaychen no I didn't mean direct instantiation of the BRAM block, but copy pasting the example from Xilinx's synthesis guide (with minor adaptions for correct ROM size and interface naming).

msfschaffner avatar Oct 14 '19 18:10 msfschaffner

o do you mean pg.174 of this doc? https://www.xilinx.com/support/documentation/sw_manuals/xilinx2019_1/ug901-vivado-synthesis.pdf

The case statements look quite unfriendly... :)

On Mon, Oct 14, 2019 at 11:34 AM msfschaffner [email protected] wrote:

@tjaychen https://github.com/tjaychen no I didn't mean direct instantiation of the BRAM block, but copy pasting the example from Xilinx's synthesis guide (with minor adaptions for correct ROM size and interface naming).

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/lowRISC/opentitan/issues/422?email_source=notifications&email_token=AAH2RSXCQIMAC5TGW6UPSLLQOS3TNA5CNFSM4I7Q3CBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBF6S2Y#issuecomment-541845867, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAH2RSVUEDONOO75BHDTZRLQOS3TNANCNFSM4I7Q3CBA .

tjaychen avatar Oct 14 '19 19:10 tjaychen

well, I do not like the case statements either :D (that would probably need a script to generated). I was rather thinking about reproducing the VHDL example in SV...

msfschaffner avatar Oct 14 '19 20:10 msfschaffner

as far as i can tell, the current prim_generic_rom seems pretty closely matched the to the VHDL array way of doing thing (modulo the entire array content declaration). Do you see any differences? I might just be missing something.

On Mon, Oct 14, 2019 at 1:31 PM msfschaffner [email protected] wrote:

well, I do not like the case statements either :D (that would probably need a script to generated). I was rather thinking about reproducing the VHDL example in SV...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/lowRISC/opentitan/issues/422?email_source=notifications&email_token=AAH2RST3ZW7FZ7AIMUCL5EDQOTJLDA5CNFSM4I7Q3CBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBGM4JA#issuecomment-541904420, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAH2RSWQDIZZX77BMQXHECTQOTJLDANCNFSM4I7Q3CBA .

tjaychen avatar Oct 14 '19 20:10 tjaychen

this is addressed.

tjaychen avatar Oct 22 '19 18:10 tjaychen