I have some verilog VPI code that I'm porting to use SystemVerilog DPI, to be run in Modelsim and Verilator.

In VPI, I use vpi_printf() for debugging and status information. This doesn't work when running the DPI in Verilator. Should I just be using regular printf() instead?

(This feels like it ought to be a simple question, but good SystemVerilog examples seem to be scarce)


1 Answer 1


DPI doesn't have special print commands. You can use regular C printf() or std::cout << "Your Message Here" << std::end. Some reasonable tutorials can be found with your preferred search engine with [systemverilog dpi] as your search term.

If you want to be lazy, you can keep #include <vpi_user.h> in your DPI files to keep using vpi_printf()

Alternatively, have your DPI call a SV function. With this method, adding the simulator's time-stamp is possible. Example:


// ...
export "DPI-C" function dpi_print;
function void dpi_print(input string msg);
  $display("%t :: %s", $time, msg);
endfunction : dpi_print
// ...

my_dpi.c :

#include <stdlib.h>
#include <stdio.h>
#include "svdpi.h"
extern dpi_print(const char* msg);
int some_c_func( /* ... */ ) {
  // ...
  // ...
  • \$\begingroup\$ When I am using vpi_printf(), the printed message is complete in the terminal, however, when saved as a logfile by Verdi simulator, it is truncated to ~70 characters. Any ideas why? \$\endgroup\$
    – Nazar
    Nov 15, 2021 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.