Home > Community > Forums > Functional Verification > SystemVerilog DPI in NCSim?

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 SystemVerilog DPI in NCSim? 

Last post Tue, Dec 12 2006 5:28 PM by archive. 13 replies.
Started by archive 12 Dec 2006 05:28 PM. Topic has 13 replies and 6708 views
Page 1 of 1 (14 items)
Sort Posts:
  • Tue, Dec 12 2006 5:28 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    SystemVerilog DPI in NCSim? Reply

    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
    • Post Points: 0
  • Tue, Dec 12 2006 5:37 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: SystemVerilog DPI in NCSim? Reply

    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
    • Post Points: 0
  • Wed, Dec 13 2006 6:02 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: SystemVerilog DPI in NCSim? Reply

    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
    • Post Points: 0
  • Wed, Dec 13 2006 6:46 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: SystemVerilog DPI in NCSim? Reply

    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
    • Post Points: 0
  • Wed, Dec 13 2006 5:31 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: SystemVerilog DPI in NCSim? Reply

    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
    • Post Points: 0
  • Thu, Dec 14 2006 1:57 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: SystemVerilog DPI in NCSim? Reply

    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
    • Post Points: 0
  • Thu, Dec 14 2006 5:31 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: SystemVerilog DPI in NCSim? Reply

    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
    • Post Points: 0
  • Fri, Dec 15 2006 9:19 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: SystemVerilog DPI in NCSim? Reply

    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
    • Post Points: 0
  • Sun, Dec 17 2006 6:14 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: SystemVerilog DPI in NCSim? Reply

    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
    • Post Points: 0
  • Mon, Jan 15 2007 5:06 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: SystemVerilog DPI in NCSim? Reply

    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
    • Post Points: 0
  • Sun, Sep 16 2007 11:55 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: SystemVerilog DPI in NCSim? Reply

    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
    • Post Points: 0
  • Mon, Sep 17 2007 12:48 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: SystemVerilog DPI in NCSim? Reply

    Hi vikask,

    Some suggestions listed below:
    1. Please restart another thread to describe your problem.
    2. If the command and environment file can be open to public, please paste it in the post.

    Regards,
    Davy


    Originally posted in cdnusers.org by davyzhu
    • Post Points: 0
  • Mon, Sep 17 2007 9:50 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: SystemVerilog DPI in NCSim? Reply

    Since this thread has been re-opened, I'd like to mention that Cadence has created a utility called 'irun' (i for Incisive) that is superceding ncsc_run, ncverilog, etc. This utility will allow you to pass in any combination of files that will get compiled correctly based on file name extension, i.e. .vhd, .v, .sv, .c, .cpp. You can also give it command line options either from the 3-step process or the +args from ncverilog.

    So, irun will answer the original question in this thread about being able to pass your DPI code and SV code with one command and have it take care of all the housekeeping.

    Tim


    Originally posted in cdnusers.org by tpylant
    • Post Points: 0
  • Mon, Sep 24 2007 12:20 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: SystemVerilog DPI in NCSim? Reply

    I have to plan a verification environment where I can use some existing C++ ref Model code.I want to use System C libraries for that purpose. Only confusion I have is that, How can I drive and monitor HDl signals from System C? I saw some posting in cdnusers mentioning SC_MODULE signals being connected to Verilog signals, however, i don't know where to get more on this. A pointer for documentation will be helpful. Also, does this SystemC connectivity comes in NC verilog license? Is this free i.e. comes with NC verilog or need to buy a separate license for doing this. Also, earlier we had testbuilder which worked well with C++ in my earlier company but now I dont see testbuilder anymore. Please help me out in this. Thanks,
    vikas


    Originally posted in cdnusers.org by vikask
    • Post Points: 0
Page 1 of 1 (14 items)
Sort Posts:
Started by archive at 12 Dec 2006 05:28 PM. Topic has 13 replies.