Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to allow yosys synth-ice40 -dsp switch #552

Closed
iamhuzhe-nia opened this issue Jan 21, 2025 · 15 comments
Closed

how to allow yosys synth-ice40 -dsp switch #552

iamhuzhe-nia opened this issue Jan 21, 2025 · 15 comments

Comments

@iamhuzhe-nia
Copy link

iamhuzhe-nia commented Jan 21, 2025

Currently no multiplier (DSP) resource is used with "apio build -v" command, on ice40 project.

It seems that with "-dsp" switch, it should solve the issue.

But where, how should that switch be invoked?

Currently I've tested manually add "-dsp" in SConstruct file (lib/site-package/apio/resources/ice40) directly. And it does the job. Is there a better way?

@zapta
Copy link
Collaborator

zapta commented Jan 22, 2025

Thanks for the report @iamhuzhe-nia.

  1. To what binary did you add that option? (yosys, nextpnr, etc).

  2. Is it reasonable to have it specified all the time or do you expect that some users will want it on and some off?

@iamhuzhe-nia
Copy link
Author

Here is the line I modified in SConstruct file

original
action='yosys -p \"synth_ice40 {0} -json $TARGET\" {1} $SOURCES'.format(
modified
action='yosys -p \"synth_ice40 {0} -dsp -json $TARGET\" {1} $SOURCES'.format(

Not an expert on yosys, here is where I get my information about multiplier https://projectf.io/posts/multiplication-fpga-dsps/

So I don't understand if "-dsp" switch isn't on, how does yosys "synthesize" a correct multiplier using LUTs only.

@zapta
Copy link
Collaborator

zapta commented Jan 22, 2025

@Obijuan, @cavearr,

We have here a proposal to change the yosys ice40 command as described below. Is it reasonable? I tried it with the dev version and all the tests pass, all the apio-examples build successfuly, and I was able to build and upload to alhambra-ii.

Documentation here https://yosyshq.readthedocs.io/projects/yosys/en/latest/cmd/synth_ice40.html

# From:
yosys  -p "synth_ice40 -top main -json _build/hardware.json" -q main.v

# To (notice the -dsp)
yosys  -p "synth_ice40 -top main -dsp  -json _build/hardware.json" -q main.v

EDIT: Another option is to allow to specify additional yosys flags in apio.ini for advanced users.

@cavearr
Copy link
Member

cavearr commented Jan 22, 2025

Hello @zapta! I think this argument is important and should be able to be configured via celery.ini because in most cases even if the fpga has dsps the developer may not want to use it for some reason.

For me, this powerful argument should be optional and disabled by default.

@zapta
Copy link
Collaborator

zapta commented Jan 22, 2025

@cavearr, something like this?

[env]
board = alhambra-ii
top-module = main

# Extra args to yosys synth
yosys-synth-extra-options = -dpi

# Style preferences for 'apio format'.
format-verible-options =
    --column_limit=80
    --indentation_spaces=4

@cavearr
Copy link
Member

cavearr commented Jan 22, 2025

i like a lot! be careful! -dsp not -dpi! 😄

@zapta
Copy link
Collaborator

zapta commented Jan 22, 2025

Yes, -dsp. ;)

I will implement it.

@cavearr
Copy link
Member

cavearr commented Jan 22, 2025

thanks!

@zapta
Copy link
Collaborator

zapta commented Jan 22, 2025

@iamhuzhe-nia, can you post here a zip file with a small apio project that will benefit from the -dsp? We will use it for testing and may also add it to the apio examples. The smaller and simpler, the better.

@zapta
Copy link
Collaborator

zapta commented Jan 23, 2025

I implemented a small apio (dev) example that demonstrates the -dsp feature. https://github.com/zapta/apio_dev/tree/develop/test-examples/ice40/fomu/dsp

You can see below how the synthesis trades differently ICESTORM_DSP and ICESTORM_LC cells and how it affects the design speed.

Without yosys-synth-extra-options = -dsp:

$ apio report
Setting the envinronment.
[Wed Jan 22 22:07:20 2025] Processing fomu
---------------------------------------------------------------------------------------------------------------------------
yosys -p "synth_ice40 -top top -json _build/hardware.json" -q blink.v
nextpnr-ice40 --up5k --package uwg30 --json _build/hardware.json --asc _build/hardware.asc --report _build/hardware.pnr --pcf pinout.pcf -q
Formatting pnr report.

UTILIZATION:
        ICESTORM_DSP:     0     8     0%
      ICESTORM_HFOSC:     0     1     0%
         ICESTORM_LC:  1131  5280    21%
      ICESTORM_LFOSC:     0     1     0%
        ICESTORM_PLL:     0     1     0%
        ICESTORM_RAM:     0    30     0%
      ICESTORM_SPRAM:     0     4     0%
              IO_I3C:     0     2     0%
               SB_GB:     1     8    12%
              SB_I2C:     0     2     0%
               SB_IO:     6    96     6%
         SB_LEDDA_IP:     0     1     0%
         SB_RGBA_DRV:     0     1     0%
              SB_SPI:     0     2     0%
         SB_WARMBOOT:     0     1     0%

CLOCKS:
                clki:   20.47 Mhz max

With yosys-synth-extra-options = -dsp:

$ apio report
Setting the envinronment.
[Wed Jan 22 22:06:31 2025] Processing fomu
---------------------------------------------------------------------------------------------------------------------------
yosys -p "synth_ice40 -top top -dsp -json _build/hardware.json" -q blink.v
nextpnr-ice40 --up5k --package uwg30 --json _build/hardware.json --asc _build/hardware.asc --report _build/hardware.pnr --pcf pinout.pcf -q
Formatting pnr report.

UTILIZATION:
        ICESTORM_DSP:     3     8    37%
      ICESTORM_HFOSC:     0     1     0%
         ICESTORM_LC:    47  5280     0%
      ICESTORM_LFOSC:     0     1     0%
        ICESTORM_PLL:     0     1     0%
        ICESTORM_RAM:     0    30     0%
      ICESTORM_SPRAM:     0     4     0%
              IO_I3C:     0     2     0%
               SB_GB:     1     8    12%
              SB_I2C:     0     2     0%
               SB_IO:     6    96     6%
         SB_LEDDA_IP:     0     1     0%
         SB_RGBA_DRV:     0     1     0%
              SB_SPI:     0     2     0%
         SB_WARMBOOT:     0     1     0%

CLOCKS:
                clki:   86.85 Mhz max


@zapta
Copy link
Collaborator

zapta commented Jan 23, 2025

@cavearr, the -dsp option seems to have some issues so it was a good call not to hardcode it in the yosys command.

YosysHQ/yosys#4865

@cavearr
Copy link
Member

cavearr commented Jan 23, 2025

I like a lot the enable adhoc in apio.ini solution

@zapta
Copy link
Collaborator

zapta commented Jan 23, 2025 via email

@cavearr
Copy link
Member

cavearr commented Jan 23, 2025

your apio.ini file had been a very great idea! thank @zapta !

@zapta
Copy link
Collaborator

zapta commented Feb 4, 2025

Fixed. Closing.

@zapta zapta closed this as completed Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants