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

[prim] Remove primgen and replace with virtual cores #23555

Draft
wants to merge 24 commits into
base: master
Choose a base branch
from

Conversation

a-will
Copy link
Contributor

@a-will a-will commented Jun 7, 2024

Add back prim_pkg enum for legacy support, and mention that it is deprecated. Some IPs reference the enums directly.

@a-will a-will force-pushed the fusesoc-compat branch 2 times, most recently from 65eb0ec to 19af483 Compare June 7, 2024 07:04
@marnovandermaas marnovandermaas added the Type:Enhancement Feature requests, enhancements label Jun 7, 2024
@a-will a-will force-pushed the fusesoc-compat branch 2 times, most recently from 458c9e4 to 4009fe6 Compare June 9, 2024 23:45
@a-will
Copy link
Contributor Author

a-will commented Jun 9, 2024

Interesting, it looks like mixing with a newer fusesoc might require at least Python 3.9 to work with the other dependencies.

ERROR: Ignored the following versions that require a different python version: 1.0.0 Requires-Python >=3.9,<4.0; 1.1.0 Requires-Python >=3.9
ERROR: Could not find a version that satisfies the requirement jsonschema2md==1.1.0 (from versions: 0.1.0, 0.1.1, 0.2.0.post1, 0.2.1, 0.3.0, 0.4.0, 0.9.0)
ERROR: No matching distribution found for jsonschema2md==1.1.0

@a-will a-will force-pushed the fusesoc-compat branch 2 times, most recently from e7dd88c to b2b9aab Compare June 10, 2024 06:02
@a-will
Copy link
Contributor Author

a-will commented Jun 10, 2024

Newer fusesoc also has a different directory layout compared to the OT fork. This was the OT fork's layout:

  • {--build-root}/
    • sim-vcs/
      • fusesoc-created metadata, Makefile, and file list
    • src/
      • Exported source files

But newer fusesoc has this directory layout:

  • {--work-root}/
    • Contains fusesoc-created metadata, Makefile, and file list
    • src/
      • Exported source files

Accommodating the new tree needed fixes to various paths, including CFLAGS definitions in hjson files. In the current example, {work-root} is set to dvsim's {build_dir}/fusesoc-work.

In addition, for ralgen, the position field was needed to be set to prepend for generated cores, else the files would come after the *_env_pkg.sv that would depend on them.

Now, some simulations work, but there is still a gap...

@a-will a-will force-pushed the fusesoc-compat branch 4 times, most recently from 787aca8 to 5344016 Compare June 17, 2024 04:34
@a-will
Copy link
Contributor Author

a-will commented Oct 31, 2024

This PR is way out of date now, but since @olofk has released fusesoc 2.4, I think we don't need my random development tag anymore. 2.4 should be able to handle virtual cores as needed.

@olofk
Copy link
Contributor

olofk commented Oct 31, 2024

@a-will I think that depends on the OT requirements. If you are fine with pulling in cores from one vendor during a build, then virtual cores should do the trick.

However, as I understand it, OT wants to be able to select implementation at compile-time, and in that case you still need something like primgen.

With that said, I believe FuseSoC 2.4 should have all the functionality needed to implement what you need. I have done some experimenting implementing the equivalent to primgen as a FuseSoC filter instead of a generator and it looks promising.

Happy to discuss this further.

@a-will
Copy link
Contributor Author

a-will commented Oct 31, 2024

@a-will I think that depends on the OT requirements. If you are fine with pulling in cores from one vendor during a build, then virtual cores should do the trick.

However, as I understand it, OT wants to be able to select implementation at compile-time, and in that case you still need something like primgen.

With that said, I believe FuseSoC 2.4 should have all the functionality needed to implement what you need. I have done some experimenting implementing the equivalent to primgen as a FuseSoC filter instead of a generator and it looks promising.

Happy to discuss this further.

It's unclear to me if OT actually needs that, though. All of our in-tree top-level fusesoc cores end up binding a specific prim library, and an out-of-tree integrator would almost certainly do the same for their actual chip. The build recipes for synthesis often can't be reused across technologies, and across integrations for the same opentitan IP, the top-level generally uses different RTL, so we end up with independent top-level cores anyway. We'd end up with different YAML for each real target, so sharing that core file across implementations doesn't seem to provide a benefit.

There may be a bit of a rub with gate-level simulation applications, though, especially if you just want to redo the existing block-level simulations with your own prim library. I'd guess that the full integration level still uses its own core file for GLS, but is doing block-level simulation with a different prim library a supported activity? I'm not sure.

We'd probably achieve the original setup's capabilities if only we could provide fusesoc (as a parameter to its invocation) which implementations of virtual cores to include for the specified top-level core file. For example, it could be arguments to provide additional VLNVs to add to the build (using their default target). Then the top-level core file wouldn't need to explicitly pull them in.

@a-will
Copy link
Contributor Author

a-will commented Nov 1, 2024

For example, it could be arguments to provide additional VLNVs to add to the build (using their default target). Then the top-level core file wouldn't need to explicitly pull them in.

@olofk If that bit above is interesting, the specifying of additional VLNVs would be akin to how hierarchical synthesis flows work. The top-level (and other sub-cores) may have dangling references, but the missing netlists would get specified as additional sources, then linked in during the build. For fusesoc, this would mean writing in a "depends" arrow from the top-level VLNV to the additional VLNVs, and the solver should handle them as though they were written in the core file Edit: Actually, this might be just additional cores thrown into the Requirement, with no need to modify the dependency graph.

@HU90m HU90m force-pushed the fusesoc-compat branch 2 times, most recently from 980f9e1 to 90f83e5 Compare November 25, 2024 18:19
@a-will
Copy link
Contributor Author

a-will commented Nov 26, 2024

Looks like fusesoc 2.4 isn't being used in the sim runs in CI, and something broke with the CI file changes. I guess the API is a bit different for github actions. Maybe s/parameters/inputs?

Copy link
Contributor

@marnovandermaas marnovandermaas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing PR! Left a few comments from looking at the code.

Comment on lines 18 to 19
# TODO: prim_pkg_legacy is deprecated
- lowrisc:prim:prim_pkg_legacy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe good to put this in a separate commit, just to separate it from the prepend changes.

@@ -73,6 +73,7 @@ generate:
parameters:
name: otbn
ip_hjson: ../../../data/otbn.hjson
position: prepend
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this go in the previous commit?

Comment on lines +28 to +29
# TODO: prim_pkg is deprecated
- lowrisc:prim:prim_pkg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we create an issue to track this?

Comment on lines 24 to 25
# TODO: prim_pkg_legacy is deprecated
- lowrisc:prim:prim_pkg_legacy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is similar to a change made in an earlier commit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these CDC waivers tested in CI? If not, have we tested this ourselves?

@@ -14,6 +14,8 @@ filesets:
- "fileset_partner ? (partner:systems:scan_role_pkg)"
- "!fileset_partner ? (lowrisc:systems:ast)"
- "!fileset_partner ? (lowrisc:systems:scan_role_pkg)"
- "!fileset_partner ? (lowrisc:prim:prim_pkg_legacy)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this have a todo that this will be removed in the future?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also true for other core files in top_earlgrey

@@ -12,6 +12,8 @@ filesets:
- lowrisc:systems:ast
- lowrisc:systems:topgen
- lowrisc:systems:padring
- lowrisc:prim:prim_pkg_legacy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add todo?

@olofk
Copy link
Contributor

olofk commented Nov 26, 2024

Regarding paths, I haven't checked exactly what the problem is, but I would recommend using --work-root instead of --build-root since that gives you more deterministic behaviour. You might also want to use --system-name to get a fixed name for the build artifacts.

@a-will
Copy link
Contributor Author

a-will commented Nov 26, 2024

Regarding paths, I haven't checked exactly what the problem is, but I would recommend using --work-root instead of --build-root since that gives you more deterministic behaviour.

That is what I did in this PR: https://github.com/lowRISC/opentitan/pull/23555/files#diff-8ed9c1256f9282d31ab3a7f150e2e95eaae62a546151c7203117aaa70451129e

@a-will
Copy link
Contributor Author

a-will commented Dec 22, 2024

If FuseSoC uses padring, physical_pads, and top_pkg from Englishbreakfast instead of Earlgrey, that can be ignored because the former symlink to the latter.

I think we should get rid of those symlinks, though. We ought to eliminate duplicate real VLNVs inside the repo. Virtual VLNVs can define common interfaces, and otherwise, englishbreakfast should become a proper top of its own.

The warnings in which FuseSoC uses cores under bazel-opentitan instead of those in the repo is a bit weird; maybe a FUSESOC_IGNORE in bazel-opentitan is missing?

No, the bazel-opentitan symlink is pointing to a directory of symlinks that point to exactly the same set of files. That is a link to bazel's execroot, which includes all the files from the repo + the external repos pulled in and/or generated + the output directory. We cannot create a FUSESOC_IGNORE file there, and it also wouldn't have any practical effect.

If we really wanted to get rid of the confusion, though, we could play with where the symlinks get created. We could create a directory with this structure:

${REPO_TOP}/
    .bazel/
        FUSESOC_IGNORE

Commit that to the repo, then add --symlink_prefix=.bazel/ to the common options. Then, all the symlinks will be created in the .bazel/ folder alongside that FUSESOC_IGNORE, so non-bazel calls to fusesoc won't exhibit these warnings. (bazel calls do not exhibit these warnings, since fusesoc is run in a sandbox, not in the source directory)

In scripts, we probably foolishly use uncontrolled symlink locations to get to output files, though, so those would have to be fixed up.

While I agree that it doesn't make a difference for Earlgrey and Englishbreakfast (for the mentioned reason), I am more concerned that the wrong packages are selected in general.

Is there a general issue here?

So far, nothing raised points to a general issue (except, arguably, that ascentlint should only be used in sign-off flows, since contributors get very low visibility into what's happening in CI with that tool).

HU90m and others added 17 commits December 22, 2024 18:01
`uv pip compile` currently doesn't appear to adhere to the minimum
python version set in `pyproject.toml` even when set with to `=3.8`,
so the `--python-version` argument was used.

Signed-off-by: Hugo McNally <[email protected]>
Co-authored-by: Alexander Williams <[email protected]>
Signed-off-by: Hugo McNally <[email protected]>
In addition to changing to virtual prim cores, quite a few paths had to
be updated for FuseSoC's new build directory layout.

Note, prim_pkg still exists as prim_pkg_legacy because some RTL beyond
the old primitive wrappers depends on the implementation enum.
prim_pkg_legacy has been labelled as legacy.

Co-authored-by: Alexander Williams <[email protected]>
Signed-off-by: Hugo McNally <[email protected]>
Because the prim hierarchy has changed, reusing the path would target
the flop directly for forcing. This meant that the forcing would delay
u_state_flop from snapping back to the FsmError state that should've
been held by the flop. Instead, the original path caused the flop in the
new hierarchy to be targeted *directly*, delaying update until the next
posedge, instead of the negedge when forcing is released.

Retarget forcing to prim_sparse_fsm_flop's state_o output.

Signed-off-by: Alexander Williams <[email protected]>
Adjust the paths to fusesoc FPGA outputs to accommodate the extra layer
of hierarchy for --build-root. We might want to consider using
--work-root to shorten these long paths in the future.

Co-authored-by: Alexander Williams <[email protected]>
Signed-off-by: Hugo McNally <[email protected]>
We expect file names to match module names. Now that the IPs are virtual
cores, rename the files to match the module names that are the new "ABI"
(so to speak).

Adjust prim_generic, prim_xilinx, and prim_xilinx_ultrascale libraries.

Co-authored-by: Hugo McNally <[email protected]>
Signed-off-by: Alexander Williams <[email protected]>
Adjust the Verilator public module configuration for the new prim
hierarchy. All prim implementations now have the same module name
for the same specific prim ABI, so the config targeting the
prim_generic_flop module needed to change to prim_flop.

Signed-off-by: Alexander Williams <[email protected]>
Switched ascent lint over to use FuseSoC's `--work-root` as oppose to
`--build-root`.

Signed-off-by: Hugo McNally <[email protected]>
a-will and others added 5 commits December 23, 2024 00:41
Make many lint targets depend on the generic prims.

Co-authored-by: Hugo McNally <[email protected]>
Signed-off-by: Alexander Williams <[email protected]>
Ensure packages with constants are at the leaves of the dependency tree,
so other cores may depend on them without creating cycles. Adjust the
pwrmgr_reg core to depend on the pwrmgr_pkg core, with pwrmgr_reg_pkg
moved to the pwrmgr_pkg core.

Also split the mubi RTL implementations from the package with
declarations and standalone utility functions.

Signed-off-by: Alexander Williams <[email protected]>
Since englishbreakfast on the CW305 shares an MMI script with earlgrey,
add the same memory breakdown so info pages may be spliced.

Signed-off-by: Alexander Williams <[email protected]>
They were all missing prim_subreg_pkg in their dependencies.

Signed-off-by: Alexander Williams <[email protected]>
This commit is purely to test changes to fusesoc's uncached
generator handling. It uses a "release" from my repo that can go
away at any time.

Signed-off-by: Alexander Williams <[email protected]>
@a-will
Copy link
Contributor Author

a-will commented Dec 23, 2024

I got this this PR to address the problem. olofk/fusesoc#713 This always builds non-cached generators in work_root which seems to be a reasonable solution to me. Intend to follow up with another fix to lock the directory of cached generators before trying to write those, but wanted to get this to you first for comments.

@olofk Thanks for writing that! I created a test release for it (with wrong version numbers, surely) at https://github.com/a-will/fusesoc/releases/tag/2.4.1.dev0%2Ba-will , and the results look good here. 🙂

@a-will
Copy link
Contributor Author

a-will commented Dec 23, 2024

The ascentlint issues were just more of the missing changes from prim_generic_* to prim_* (in a couple waiver files).

For CI, we're probably very close now. I'll have to check what's happening with the CW305 bitstream--It seems to be failing somehow on the MMI generation, this time in the search for BRAM cells for otp_ctrl.

Even once we get CI to be all green, there will still be issues with the flows that are only activated for sign-off activities (e.g. FPV, CDC, RDC, UNR, coverage collection / waivers, etc.). At least some docs will need to be updated as well.

@olofk
Copy link
Contributor

olofk commented Jan 8, 2025

I got this this PR to address the problem. olofk/fusesoc#713 This always builds non-cached generators in work_root which seems to be a reasonable solution to me. Intend to follow up with another fix to lock the directory of cached generators before trying to write those, but wanted to get this to you first for comments.

@olofk Thanks for writing that! I created a test release for it (with wrong version numbers, surely) at https://github.com/a-will/fusesoc/releases/tag/2.4.1.dev0%2Ba-will , and the results look good here. 🙂

I released FuseSoC 2.4.2 yesterday with this as well as the warning about non-deterministic virtual cores. Could it be that we have now reached the point where you can use a released version of upstream FuseSoC?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type:Enhancement Feature requests, enhancements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants