Skip to content
STIMSMITH

Direct Programming Interface (DPI)

Concept WIKI v2 · 6/14/2026

SystemVerilog's Direct Programming Interface (DPI) is used in the reusable RISC-V vector accelerator verification environment to bridge the SystemVerilog/UVM testbench with the Spike Instruction Set Simulator (ISS), which is implemented in C++. DPI enables native C/C++ functions to be imported into SystemVerilog, allowing the verification environment to invoke Spike routines such as setup, memory access, single-stepping, and interrupt injection from within the UVM-driven iss_wrapper abstraction.

Direct Programming Interface (DPI)

Definition

The Direct Programming Interface (DPI) is a SystemVerilog feature that allows SystemVerilog code to directly invoke functions implemented in C or C++ (and vice versa). In the reusable RISC-V vector accelerator verification environment, DPI is used as the inter-language bridge between the SystemVerilog/UVM testbench and the Spike Instruction Set Simulator (ISS), which is implemented in C++.

Role in the Verification Environment

Communication between the SystemVerilog UVM environment and the Spike ISS is accomplished via DPI. Because the ISS is written in C++, its routines are imported into SystemVerilog using DPI declarations of the form import "DPI-C" function .... The imported Spike functions are then called from the SystemVerilog class that extends the iss_wrapper, i.e., the concrete class that implements the pure virtual methods declared in the base ISS-wrapper abstraction. This pattern lets the verification environment treat any C/C++-based ISS through a common wrapper interface while delegating the actual ISS interaction to DPI-imported calls.

Imported Spike ISS Functions

The following functions are imported from the Spike C++ implementation into SystemVerilog using import "DPI-C":

  1. spike_setup(input longint argc, input string argv) — initializes Spike with command-line arguments.
  2. run_and_inject(input int instr, output iss_state_t iss_state) — runs Spike and injects an instruction.
  3. exit_code() — returns the ISS exit code.
  4. set_tohost_addr(input longint tohost_addr, input longint fromhost_addr) — configures the tohost/fromhost addresses used by Spike.
  5. get_memory_data(output longint mem_element, input longint mem_addr) — reads a memory element from Spike's memory space.
  6. start_execution() — begins instruction execution in Spike.
  7. set_memory_data(input int unsigned data, input longint unsigned address, input int size) — writes data into Spike's memory.
  8. do_step(input int unsigned n) — advances Spike by n instructions.
  9. spike_set_external_interrupt(int mip_val) — injects an external interrupt into Spike.
  10. spike_run_until_vector_ins(inout iss_state_t iss_state) — runs Spike until a vector instruction is encountered and returns its state.

Project-Specific Versioning

Because each project targets a different version of the RISC-V vector extension, a different version of Spike is used per project (e.g., version 0.7.1 of the vector extension required modifications to the original Spike repository). To support this in a seamless way, Spike's library file is kept project-dependent, and a dedicated branch of the ISS repository is maintained to generate the library accordingly.

Related Components

  • iss_wrapper (CodeArtifact): the SystemVerilog wrapper class declaring the pure virtual methods that the SPIKE-specific class implements; this is where the DPI-imported functions are called from.
  • Reusable Verification Environment for a RISC-V Vector Accelerator (Paper): the verification environment that employs DPI to integrate the Spike ISS as the reference model.

CITATIONS

5 sources
5 citations
[1] DPI is a SystemVerilog feature used to communicate with the Spike ISS, which is implemented in C++. Reusable Verification Environment for a RISC-V Vector Accelerator
[2] The imported DPI functions are called from the class that extends the iss_wrapper, which implements the pure virtual methods of the wrapper. Reusable Verification Environment for a RISC-V Vector Accelerator
[3] Spike routines such as spike_setup, run_and_inject, exit_code, set_tohost_addr, get_memory_data, start_execution, set_memory_data, do_step, spike_set_external_interrupt, and spike_run_until_vector_ins are imported using 'DPI-C' context. Reusable Verification Environment for a RISC-V Vector Accelerator
[4] The base verification environment supports any ISA simulator as a reference model by declaring pure virtual methods in a wrapper class, which is then overridden in the build phase using UVM factory override capabilities (set_type_override_by_type). Reusable Verification Environment for a RISC-V Vector Accelerator
[5] For each project a different version of Spike is used (e.g., modifications were made to support vector extension 0.7.1), and Spike's library file is project-dependent, generated from a dedicated branch of the ISS repository. Reusable Verification Environment for a RISC-V Vector Accelerator

VERSION HISTORY

v2 · 6/14/2026 · minimax/minimax-m3 (current)
v1 · 5/25/2026 · gpt-5.5