







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An in-depth analysis of hdl/c interfaces, focusing on efficiency issues between vhdl-cli and verilog-pli using a finite state machine (fsm) datapath system model as an example. The report covers the background of hdl/c interfaces, interface issues, available interfaces, and a comparison of synopsys vhdl-cli and verilog-pli.
Typology: Assignments
1 / 13
This page cannot be seen from the preview
Don't miss anything!








The basic differences observed during the modeling and simulation here, as detailed later in the report were two fold.
The system hardware was modelled in both VHDL and Verilog. While the software was implemented in C.
The VHDL simulator used was VHDL Synopsys Simulator (VSS) and the verilog simulator was Verilog Compiler and Simulator (VCS).
VSS supports C interfacing through its “C language interface (CLI)” and VCS supports the same through the standard verilog “programming language interface (PLI)”. Both the interfaces are detailed in subsequent sections later in the report.
Both the VSS and VCS versions used were from the Synopsys 2000.06 – SIM package.
“The C-Language Interface (CLI) enables … to describe component models in C and interface them in VHDL source files for simulation on VSS” as stated in [2].
As per the VHDL design methodology each hardware component modelled has an entity which defines its ports that connect the component with the outside world and it also allows for passing any generic values that might be set at run time. This entity is linked to an architecture with the help of a configuration file. By modifying the configuration the entity could be linked to any other architecture. Where the architecture defines the internal functionality of the component.
Through CLI the functionality of the component can be specified in C and needs to include a header file <cli.h> kept in the “include” directory parallel to the “bin” directory. The architecture in this case is dummy and needs to contain five attributes and is constrained to be named CLI. Of which three define the C routines that specify the architecture while the fifth is used to specify the sensitivity on the input pins of the component.
The five attributes are:
attribute CLI_ELABORATE of CLI : architecture is “ elaborate_routine_name ” ; attribute CLI_EVALUATE of CLI : architecture is “ evaluate_routine_name ” ; attribute CLI_ERROR of CLI : architecture is “ error_routine_name ” ;
attribute CLI_CLOSE of CLI : architecture is “ close_routine_name ” ; attribute CLI_PIN of signal is sensitivity ;
Where the routine names are the names of the corresponding C routines.
Elaborate routine: The elaborate routine is used to set up the basic data structure for exchange of signals across the HDL/C interface. CLI implements structs in C that combine VHDL data types with some enumeration data types on the C side. This is done to solve the data type differences on either side of the boundary and to incorporate the missing physical data type of time. There are limitations to the interface data exchange as define in [2]. The basic elaborate step is to define a structure in C which is similar to the VHDL entity.
Evaluate routine: The evaluation routine carries the real functionality of the component and requires an instantiation of the struct defined above.
Error and Close routines: The error routine provides exception handling and procedures for debugging. While the close routine provides procedures for database cleanup and memory restoration, post execution.
CLI data types and CLI functions: Predefined CLI composite data types provide the missing link between data types on either side of the interface.
e.g. CLI type C type VHDL type Usable C values
Bit BIT BIT BIT_0, BIT_ Std_logic STD_LOGIC STD_U/LOGIC STD_LOGIC_X STD_LOGIC_Z Time TIME TIME
The CLI functions use CLI data types to provide the required functionality across the interface. The four most important functions are described below:
The system defined for the exploration in question is a small incremental average computing system [9]. Here the average is computed online as new values keep coming in, instead of waiting for all and then providing the average at the end.
A system like this is usually employed in DSP and GPS systems where a few parameters need to be averaged on an online basis. The flowchart below captures the system assuming the stream of incoming numbers is provided by a memory.
The above system can be implemented as a finite state machine controlling a datapath. To speedup a given software implementation of the given system, a choice is made to
Figure1: System flowchart
implement the datapath in hardware. Also the number of data elements to be averaged over, though online was limited to N (=2,5,9). Thus the hardware (HDL) implements:
The decision to move memory to hardware was due to the CLI interface issues as described later.
The C portion contains:
The datapath for the system is shown in the diagram below. In the implementation the lowest structural models are the regs.x, compa.x, pe.x (x = vhd & v). These are instantiated in a bigger module, datapath.x. The datapath had problems during the initialisation portion on the start of the simulation. Remedies are discussed in the observations and constraints section.
Avg I
A, I: Registers
PE: Processing Element
LA, LI: Load regs
S(I) : Memory data
Add: Memory address
Avg: Final average
Done: N values done
C: Clear
Memory not shown!
Figure 2 : Datapath
The memory was originally moved to hardware as it was required to be a two dimensional array of bits. One dimension for the bit_vector and the other for addressing. As the CLI had a limitation of passing only one dimensional arrays across the interface, it constrained to keep the memory in hardware. But later to speed up the design process of the processing element (pe) the memory had to be moved to handle real data instead of bit vectors.
The average computation formula utilised the memory address and thus required to be of the same data type as the data and is thus modelled as real. This constrained to use only an if-then-else construct for the memory function.
CLI routines: In the fsm block the error and close attributes and their corresponding routines where not implemented. This was left to the default settings. Only the clk and done signal of type bit move to the C side and all the datapath control signals move out of the C side along with the memory read signal (rd) of type bit.
Datapath: To enable the average to be made available in the fifth state (s4) a new pin en was added. It goes high in s4 to enable the dataout on the average port.
The part of the compilation sequence is given below:
Assuming that all the other modules have been compiled before. For the cli first
cli –nc –add –cv fsmc fsm cli –nc build vhdlan –nc fsm.vhd vhdlan –nc testbench.vhd
vhdldbx ctop
First the implementation in VSS was explored and thus some of the decisions taken during that phase were carried forward in this phase as well. Thus the memory was kept in hardware and the data and address in real. It was later modified to the verilog memory representation.
VCS execution: The VCS PLI requires the C compiler to be in its path and thus the below mentioned flags and environment variables had to be set.
setenv VCS_CC /opt/local/bin/gcc
vcs –CFLAGS “-I /opt/synopsys/vcs5.2/include” +incdir+/opt/synopsys/vcs5.2/include/ -P mypli.tab
The functions defined also required the use of access routines not provided in the Open Verilog Initiative (OVI) but added in the vcs simulator. This made the implementation vcs simulator dependent. The access routines used were acc_fetch_tfarg, acc_clearmem_int, acc_handle_tfarg, acc_fetch_tfarg_int, acc_get_mem_int.
The functions were:
They were defined in the pli table. And the vcs compilation used the –Mupdate option.
vcs +acc+4 –Mupdate –P mypli.tab at_croutines.c testbench.v
The results are discussed in the following section.
Observations:
Both VCS and VSS have their pros and cons with the data exchange across the interface. VHDL requires a robust structure to be put in place first while verlog requires a handle to be instantiated on the data structure accessed.
The CPU time was logged in the PLI implementation and is as shown in the log below while cpu time in the vhdlsim could not be extracted.
The simulation time cannot be used to make the comparison as both the simulations could be made to run for the same time duration. Moreover the implementations in vhdl and veilog differ in the memory definition.
Although accessing and setting data is a lot more easier in the PLI than in CLI as the functions are better defined and do not require any intermediate data structures to be implemented.
Secondly, PLI functions and tasks are implemented and linked with the simulator they can be used across a larger variety of designs and can also be used for simulator modification which is not feasible with CLI.
Also the PLI being an IEEE standard allows porting PLI routines across simulators.
In both tweaking and debugging the C side is challenging.
Log portions:
[1] http://www.ics.uci.edu/~rgupta/ics212/w2002/models.pdf [2] Chapter 3, VSS C Language Interface, VHDL Simulation Interfaces Manual [3] Chapter 7, Using the PLI, VCS user’s guide [4] A Brief Introduction to PLI (Programming Language Interface), Celia Clause www.europa.com/~celiac/pli.htm [5] Transitioning to the New PLI Standard, Stuart Sutherland, www.sutherland- hdl.com [6] Chapter 13, Programming Language Interface, Verilog HDL : A Guide to Digital Design and Synthesis, Palnitkar. [7] Appendix B, List of PLI routines, Verilog HDL : A Guide to Digital Design and Synthesis, Palnitkar. [8] IEEE PLI Reference Manual [9] http://www.ics.uci.edu/~givargis/courses/253/notes/lecture3.pdf [10] Using Global Code Motions to Improve the Quality of Results for Higher-Level Synthesis, Sumit Gupta et. al. [11] VHDL & Verilog Compared & Contrasted Plus Modeled Example Written in VHDL, Verilog and C, Douglas j Smith, http://www.angelfire.com/in/rajesh52/verilogvhdl.html [12] Dive Into System-Level Hardware/Software Codesign, David Park et.al. http://www.planetee.com/planetee/servlet/DisplayDocument?ArticleID= [13] Synthesis From Mixed Specification, Vincent J Mooney et.al. IEEE [14] DATE99: C-to-HDL translation tools emerge, EETimes [15] The Simulation Semantics of SystemC