• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Functional Verification
  3. SystemVerilog DPI in NCSim?

Stats

  • Locked Locked
  • Replies 13
  • Subscribers 64
  • Views 25012
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

SystemVerilog DPI in NCSim?

archive
archive over 18 years ago

Hi all, Because it will take some time waiting download IUS583, I tried to use SystemVerilog DPI (mostly imported functions). I heard that Synopsys can simply include C file in file list with SystemVerilog file and run simulation. But Cadence NC seems need C code compile and link to a lib. I have read the NCsim document and find a switch "-sv_lib". But I cannot find a simple example. Is there any step by step tutorial about how to compile, link and run SystemVerilog DPI C file in NCsim? Best regards, Davy


Originally posted in cdnusers.org by davyzhu
  • Cancel
  • archive
    archive over 18 years ago

    Davy

    I believe there are some examples on using DPI in the NC documentation. The essential step you need are:

    1. Compile the c code as usual to .o files.
    2. Link the C code to a shared library. You must make sure that if you have C++ code, the DPI method should be declared under extern "C" {

    } block.
    3. Specify the shared library path to the -sv_lib option in ncsim.

    Nitin


    Originally posted in cdnusers.org by nitin_sharma
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 18 years ago

    Hello Davy.

    Currently you are required to compile the DPI C code yourself, though I believe this will change in the not too distant future.

    Compilation is pretty easy, and if you build a shared library with the name "libdpi.so" then the simulator will automatically load this, so you don't have to specify the library file to ncsim.

    Here's an example:
      gcc my_c_funcs.c -fpic -shared -o libdpi.so
      ncverilog +sv my_testbench.sv


    Clearly if you need to pull in more C code, or merge lots of *.o files there is more to do in the gcc side, but the ncsim invocation remains the same.


    Steve.


    Originally posted in cdnusers.org by stephenh
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 18 years ago

    Here's a small example that you can compile and run.
    The Run.sh shows how to compile the C code.

    Also, in recent versions of IUS, you can find a tutorial on DPI, accessed by either:

    A) Run the "cdsdoc" command, expand the "NC-Verilog" or "Incisive Unified Simulator" hierarchy, and look for the topic "SystemVerilog DPI Engineering Notebook".


    B) cd to `ncroot`/doc/dpiEngrNtbk, then open the PDF file. This directory contains the example designs in the "import" and "export" directories.


    Steve.


    Originally posted in cdnusers.org by stephenh
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 18 years ago

    Hi stephenh,

    Thanks a lot!

    1. You give out a gcc compile and link example. Is the switch listed in the example all gcc original switch or added by Cadence? Is there any recommendation reading about gcc used in IUS SystemVerilog DPI? For I am a Microsoft VC user and not familiar with GNU tools.
    2. Attachment: dpi_example.tar.gz seems cannot be open, can you check it?

    Best regards,
    Davy


    Originally posted in cdnusers.org by davyzhu
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 18 years ago

    Hi Davy.

    Cadence does not modify the gcc tool, so all the options I showed previously are standard gcc ones.
    "gcc --help" will giv you lots of detail.

    The options I used are:
    "-fpic" : create relocatable code
    "-shared" : create a shared lib rather than a statically linked binary
    "-o libdpi.so" : sets the name of the output file

    One other flag you may need is "-m32", which sets the compiled code for 32 bit mode if you compile on a 64 bit machine.

    Regarding the dpi_example.tar.gz, the version I uploaded is OK, but when I download it, the file is corrupted. I'll try uploading it again here, and if that fails, feel free to email me directly and I'll send it to you by email.

    Regards,
    Steve.



    Originally posted in cdnusers.org by stephenh
    dpi_example.tar
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 18 years ago

    Hi stephenh,

    Thanks a lot for the explanations! The new uploaded dpi_example.tar work OK! I will take some time to learn how to write a makefile when I need to include a bunch of C file, do you think so?

    I heard that SV DPI can be used to link SystemC code. Shall I run SystemC code like the normal C file, or shall I add something else? Or is there some reference document from Cadence? Thanks in advance!

    Best regards,
    Davy


    Originally posted in cdnusers.org by davyzhu
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 18 years ago

    Hi,

    You may want to try and use "ncsc_run" utility. This is primarily used for compiling systemc c code and creating a simulator. This utility when used with -dynamic and "-stop link" would create a shared library for you. It takes a list of all your C/C++ files as input, automatically generate the Makefile, compiles all the files as neccesary and than links them.

    This is what we use in our environment and it really simplifies the process as we no longer have to maintain the Makefiles. In our environment we have systemc and DPI both compiled in a same shared library and we use "ncsc_run" to compile it. It works great.

    In order to link systemc and dpi together, compile them using ncsc_run (it takes care of linking systemc and other housekeeping stuff) as I describe above. Then specify the same shared file at -load_sc command line option at ncelab time and -sv_lib option at ncsim time and it should work.

    Nitin

    Nitin


    Originally posted in cdnusers.org by nitin_sharma
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 18 years ago

    Hi Nitin,

    Thanks lot for provide the "ncsc_run" utility information. And I am not familar with SystemC/SystemVerilog co-simulation. Is there any document given by Cadence talk about something like "ncsc_run" utility?

    Best regards,
    Davy


    Originally posted in cdnusers.org by davyzhu
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 18 years ago

    Here’s the basics of creating a simple dpi file and using it from Ncsim.  In this example the simulator gets a real value from dpi and then passes it back to the dpi code.  I have numerous other examples using strings, integers...etc (tmackett@cadence.com)

     

    Here’s the Verilog file (real_test.sv) :

    module real_test ();

     

    // map the C function name to the Verilog function name

    import "DPI-C" context get_real_c = function real get_real_v ();

    import "DPI-C" context put_real_c = function void put_real_v (real x);     

     

    real pi;

     

    initial

    begin

    $display("real_test");

     

    pi = get_real_v();        // get a real number from the C code

    $display("pi = %f", pi);  // display it

     

    put_real_v(pi);           // send the real number back to C code  

      

    end

     

    endmodule

     

     

    Here’s the dpi code (real_dpi.c).  Notice there is NO c main:

     

    #include "svdpi.h"

    // since we are using math functions, include the math library

    #include         

     

    // can use io_printf() instead of printf() to put into ncsim.log file

    double get_real_c() {  // imported SV function

      // exercise DPI function - get calling scope

      printf("Function Calling HDL scope is %s \n", svGetNameFromScope(svGetScope() ) );

      return 3.14159;

    }

     

    void put_real_c(double n) {  // imported SV function

      // exercise DPI function - get calling scope

      printf("Function Calling HDL scope is %s \n", svGetNameFromScope(svGetScope() ) );

      printf("pi + 5.0 = %f\n", n+5.0);      

    }

     

    Here’s the script to compile everything:

    rm -r INCA_libs

    rm -r waves.shm

    rm *.so

     

    # make sure LD_LIBRARY_PATH includes . (or where the real_dpi.so lives)

    # make sure using useful gcc version like 3.2.2, 3.3.3 etc

     

    #create single header file for multiple dpi.c sources

     

    ncvlog real_test.v -sv

     

    # -dpiheader produces nothing for imported functions

    ncelab -dpiheader dpi.h worklib.real_test:module

     

    gcc -m32 -fPIC -g -shared -o real_dpi.so  real_dpi.c  -I/`ncroot`/tools/include

     

    # use the Incisive supplied gdb

    #xterm -e `ncroot`/tools/systemc/bin/gdb `ncroot`/tools/bin/ncsim &

     

    ncsim worklib.real_test:module -sv_lib real_dpi.so  -sv_root .

    Here’s the resulting log file:

     

    ncsim> run

    real_test

    Function Calling HDL scope is real_test

    pi = 3.141590

    Function Calling HDL scope is real_test

    pi + 5.0 = 8.141590

    ncsim: *W,RNQUIE: Simulation is complete.

    ncsim> exit


    Originally posted in cdnusers.org by tmackett
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 17 years ago

    Hi,
    I am seeing following errors while using ncsc_run:
    ncsc: compiling $TESTDIR/adder_sysc_main.cpp
    make: *** [INCA_libs/ncsc_obj/adder_sysc_main.o] Error 1
    ncsc: *W,WRKNMP: Could not obtain library mapping for WORK, no SystemC intermediate form generated.
    ncsc: Error executing: $CDSROOT/tools/systemc/gcc//bin/g++ -o INCA_libs/ncsc_obj/adder_sysc_main.o -DNCSC -I$CDSROOT/tools/systemc/include -I$CDSROOT/tools/tbsc/include -I$CDSROOT/tools/vic/include -I$CDSROOT/tools/systemc/include/tlm -c -x c++ -Wall $TESTDIR/adder_sysc_main.cpp
    ncsc_run: *E,TBBLDF: Failed to generate object INCA_libs/ncsc_obj/adder_sysc_main.o


    Any idea why I am seeing this error?


    Originally posted in cdnusers.org by vikask
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
>

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information