Skip to content

Fix crash when running vpr a second time in one process - #2835

Open
ganeshgore wants to merge 2 commits into
gg_python_binding_error_logfrom
gg_vpr_double_run_crash
Open

ganeshgore wants to merge 2 commits into
gg_python_binding_error_logfrom
gg_vpr_double_run_crash

Conversation

@ganeshgore

Copy link
Copy Markdown
Collaborator

Stacked on #2833 (which is stacked on #2832). Review those first; this PR's diff is only the last commit.

Running vpr a second time in one process segfaulted, in the native openfpga binary as well as from Python. vpr keeps its data in the global VPR contexts for the commands that follow (link_openfpga_arch, build_fabric, ...), and never freed it. The second run loaded the architecture on top of the previous one and crashed in link_physical_logical_types, called from xml_read_arch. The same crash followed a vpr run that failed after the architecture was loaded. vpr_standalone was not affected, because it frees its data at the end.

Changes

Everything is in openfpga/src/vpr_wrapper/vpr_main.cpp. VTR is not patched.

  • The architecture, options and setup of the last vpr run are kept in a process-wide holder, like g_vpr_ctx.
  • The previous run is released with vpr_free_all before any new vpr or vpr_standalone.
  • A vpr run that fails frees its data, as vpr_standalone already does. Commands that depend on vpr are already blocked by the fatal status.

Behavior change: running vpr again now replaces the previous VPR state. Because the holder is process-wide, like g_vpr_ctx, a second OpenfpgaShell object in the same process also resets the first one's VPR state.

Testing

  • 8 new pytest tests (36 in total), which pass in repeated runs and in two different file orders:
    • vpr run twice and three times;
    • vpr and vpr_standalone mixed in both orders;
    • a retry after a failed run (missing architecture, and a failure after the architecture is loaded);
    • link_openfpga_arch and build_fabric succeeding after a second vpr.
  • Native binary, run by hand: vpr twice and three times, and vpr mixed with vpr_standalone. Also a stage-by-stage vpr_standalone --pack/--place/--route then vpr --analysis then build_fabric flow, which finished with 0 errors.
  • basic_tests/generate_fabric passes.
  • I could not run the basic_tests/vpr_standalone task here, because its Yosys step needs a Yosys build.

The vpr command keeps its data in the global VPR contexts for the commands
that follow, and never freed it. Running vpr again loaded the architecture
on top of the previous run and crashed in link_physical_logical_types.
The same happened after a run that failed once the architecture was loaded.

- Keep the architecture, options and setup of the last vpr run in a
  process-wide holder
- Free the previous run (vpr_free_all) before any new vpr or vpr_standalone
- Free the data of a vpr run that fails, as vpr_standalone already does
- Add tests for repeated runs, mixed vpr/vpr_standalone runs, retries after
  failures, and commands that follow a second run
vpr_free_all() leaves the packing of the circuit in the clustering context.
Running vpr a second time with another circuit then failed the check of the
clusters against the atoms of the new circuit. Clear it when the data of a run
is freed, and test running vpr with different circuits in one process.
@tangxifan
tangxifan force-pushed the gg_vpr_double_run_crash branch from dc2f7a1 to c39796f Compare December 2, 2026 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant