Skip to main content

A CXXRTL (Yosys) cocotb simulator for SiliconCompiler — installed, not patched in

Project description

sc-cxxrtl

PyPI License: ISC

A CXXRTL cocotb simulator for SiliconCompiler — installed, not patched in.

pip install sc-cxxrtl adds the Yosys CXXRTL engine as a cocotb simulator to SiliconCompiler without modifying SiliconCompiler. SC executes whatever Task/Flowgraph subclasses a flow contains, and those live in this package — so no SC source change is needed.

Built on:

  • cxxrtl-vpi — the engine adapter that makes cocotb drive a CXXRTL model (an IEEE-1364 VPI implementation over cxxrtl_capi),
  • cocotb ≥ 2.0 — the Python testbench framework,
  • Yosyswrite_cxxrtl + a C++ compiler (external, like every SC simulator).

Install

pip install sc-cxxrtl

This pulls in cxxrtl-vpi, cocotb, and siliconcompiler. Requires Python ≤ 3.13 (cocotb's cap), plus Yosys (yosys / yosys-config) and a C++ compiler on PATH — the same external precondition as every SiliconCompiler simulator. (Latest from git: pip install git+https://github.com/lanserge/sc-cxxrtl.)

Use

from siliconcompiler import Design, Project
from sc_cxxrtl import CxxrtlDVFlow

design = Design("counter")
with design.active_fileset("rtl"):
    design.set_topmodule("counter")
    design.add_file("counter.v")
with design.active_fileset("tb"):
    design.add_file("test_counter.py")   # a cocotb test (filetype: python)

proj = Project(design)
proj.add_fileset("rtl")
proj.add_fileset("tb")
proj.set_flow(CxxrtlDVFlow())             # <- the only line that mentions cxxrtl
proj.run()

The flow is two nodes:

compile   (cxxrtl/cocotb_compile)  RTL -> CXXRTL model -> link cxxrtl-vpi + cocotb -> outputs/<top>.vexe
   │
simulate  (cxxrtl/exec_cocotb)     run the executable under cocotb -> results.xml

Tool-named fileset

Like SiliconCompiler's built-in verilator/icarus tasks, the compile task is tool-fileset-aware: if the design defines a fileset named after the tool (cxxrtl), RTL is sourced from that fileset's subtree. Give it add_depfileset(self, "rtl") to pull in the base RTL, and put any CXXRTL-specific includes/defines there:

with design.active_fileset("rtl"):
    design.set_topmodule("dut")
    design.add_file("dut.v")
with design.active_fileset("cxxrtl"):
    design.add_depfileset(design, "rtl")  # cxxrtl depends on rtl

This keeps a sibling verilator fileset (e.g. one carrying DPI/switchboard shims) out of the CXXRTL build — the same fileset convention used across the SC ecosystem. When the design has no cxxrtl fileset, all active filesets are used (unchanged behavior).

Init fuzzing (X-dependence detection)

CXXRTL is 2-state and inits flop state to 0, so a design that secretly relies on uninitialized state passes silently. The compile task exposes Verilator-style --x-initial unique fuzzing:

from sc_cxxrtl import CxxrtlCocotbCompileTask
CxxrtlCocotbCompileTask.find_task(proj).set_randomize_init(True, seed=42)

This seeds uninitialized flops with setundef -init -random; vary the seed across runs to expose X-dependence.

Waveform tracing

Enable a VCD dump (written to reports/<design>.vcd) on the exec task:

from sc_cxxrtl import CxxrtlCocotbExecTask
CxxrtlCocotbExecTask.find_task(proj).set_trace(True)

A complete, runnable example is in examples/counter/ (python make.py). It passes:

test_counter.test_count_up     PASS
TESTS=1 PASS=1 FAIL=0 SKIP=0
PASS: cocotb test ran on CXXRTL via SiliconCompiler

Why no SC patch is needed

SC's flow/task model is open by composition: a flow instantiates Task subclasses, which may live in any installed package. CxxrtlDVFlow wires CxxrtlCocotbCompileTask + CxxrtlCocotbExecTask (the latter reuses SC's own CocotbTask for environment setup, exactly like the built-in verilator-cocotb tasks). The only thing SC's built-in DVFlow(tool=…) can't do is grow a "cxxrtl" branch on its own — which is why this package ships its own flow. (Making the built-in DVFlow auto-discover plugins via a siliconcompiler.flows entry-point group would be a small, generic upstream contribution.)

License

ISC.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sc_cxxrtl-0.0.2.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sc_cxxrtl-0.0.2-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file sc_cxxrtl-0.0.2.tar.gz.

File metadata

  • Download URL: sc_cxxrtl-0.0.2.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sc_cxxrtl-0.0.2.tar.gz
Algorithm Hash digest
SHA256 e2594ae90d2f131e6bb00147fc0c489b9c1d094a86e6200152619a07e36b1d86
MD5 b8681e2e9a95e8b3e8743449aa3d79b2
BLAKE2b-256 c1a4a188f357b3c79c1feba86a6e9dfb7f48ead8719148714e01e544a04cb8eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for sc_cxxrtl-0.0.2.tar.gz:

Publisher: release.yml on lanserge/sc-cxxrtl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sc_cxxrtl-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: sc_cxxrtl-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sc_cxxrtl-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0fda116c2bca0e774b6ba70496f5cd42d4218145108f35aad4ae0a11e0729075
MD5 4fba585e4ede9297497253145dd9ef3c
BLAKE2b-256 02259ff5b433c665fdcb54d115fcc617cf45aa0da53bbe57b47be7e5399cc36e

See more details on using hashes here.

Provenance

The following attestation bundles were made for sc_cxxrtl-0.0.2-py3-none-any.whl:

Publisher: release.yml on lanserge/sc-cxxrtl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page