PLI, DPI, DirectC,TLI - 2

花了很长的篇幅,才粗略地介绍了VPI。所以,另开一贴继续介绍DPI。

先需要指出的是DPI中关键词"DPI"已经替换为“DPI-C”。

1. DPI的来源 

DPI标准源自两个专有接口,一个来自Synopsys公司的VCS DirectC接口,另一个是来自Co-Design公司(已被Synopsys 公司收购)的SystemSim Cblend接口。这两个专有接口起初是为他们各自的仿真器专门开发的, 而不是一个能够工作在任何仿真器上的标准。Accellera组织的SystemVerilog标准委员会把这两个捐献技术合并在一起,并定义了DPI接口的语义,使得DPI能够与任何Verilog仿真器一起工作。

[1] 中很好地介绍了,PLI, DPI, DirectC之间的关系。

 

[1]中关于DPI和TLI的关系

 

 

2. DPI的局限

If you have a SystemC model that does not consume time, and that you want to connect to SystemVerilog, you can use the DPI. SystemC models with time-consuming methods are best connected with the utilities built into your favorite simulator. --from [2]

和function void与task的区别一样,DPI imported functions也是要求不要消耗时间。

但DPI也支持both task and function,[2]p445也有提到,“VCS declared exported tasks as void functions in C.”,in sum, C side 不能消耗仿真时间。

我猜想这里所指的utilities应该是包括VCS中的TLI的。

补注:Although SystemVerilog provides different methods (PLI, VPI, DPI, etc) to support communications between SystemVerilog and C/C++ domains, it is not so straight forward for SystemC interface methods. One important reason is that these SystemC methods can be “blocking”, i.e. these methods can “consume” time. And these “blocking” SystemC methods can return value as well. Users should build a very elaborate mechanism to maintain synchronization between the simulations running in the SystemVerilog and the SystemC domains. (from [5])
这段话说的很清楚,systemc models 因为blocking的原因,会consume time,然后需要elaborate mechanism来synchronize,我觉得DPI应该是办不到的,但VPI应该是可以通过callbacktf来达到。这里提到的是synopsys的办法,创建两个domains来run。

3. DPI的分类

imported methods classified as pure, context or generic。 

 

Pure C函数. 作为pure函数,函数的结果必须仅仅依赖于通过形参传递进来的数值。Pure函数的优点在于仿真器可以执
行优化以改进仿真性能。Pure函数不能使用全局或者静态变量,不能执行文件I/O操作,不能访问操作系统环境变量,
不能调用来自Verilog PLI 库的函数。只有没有输出或者inout的非void函数可以被指定成pure。Pure函数不能作为
Verilog任务导入。下面的例子声明了一个导入的C函数为pure函数:
import "DPI" pure function real sin(real in); // function in C math library
Context C函数. context C函数明白函数声明所在工作域的Verilog的层次。这使得被导入的C函数能够调用来自PLI TF,
ACC或者VPI库的函数,从而DPI函数可以充分利用PLI的优势特性,比如写仿真器的log文件以及Verilog源代码打开的文
件。context任务声明的样例如下:
import "DPI" context task print(input int file_id, input bit [127:0] data);
Generic C函数. 本文把那些既没有明确声明为pure,也没有声明为context的函数称为generic函数(SystemVerilog标准没
有给除了pure或context之外的函数特定的称呼)。generic C函数可以作为Verilog函数或者Verilog任务导入。任务或者
函数可以由输入、输出以及inout的参数。函数可以有一个返回值,或者声明为void。generic C函数不允许调用Verilog
PLI函数,不能访问除了参数以外的任何数据,只能修改这些参数。
注意! 正确的声明导入的函数为pure还是context是用户的责任。缺省情况下,DPI函数假定是generic函数。调用
一个不正确声明成pure的C函数可能返回不正确或者不一致的结果,导致不可预测的运行时间错误,甚至于让仿真崩溃。
同样,如果一个C函数访问Verilog PLI库或者其他API库,却没有声明为context函数,会导致不可预见的仿真结果甚至仿

真崩溃。 

 

3b 关于context function的补注 from [1]

Export functions/tasks are always context

If an imported task calls an exported task, the import must be context
Class member functions/tasks cannot be exported, but all other SystemVerilog functions/tasks can be exported. 

 An exported task or function declaration has only the routine name. There are no arguments or return type. 这是很容易犯错的地方。

 防止名字冲突

// Map your SystemVerilog function “fread” to “sv_fread” in C

export "DPI-C" sv_fread = function fread;

同样地,在import时,防止名字冲突

// Map the C routine “test” to “c_test” in SystemVerilog.
import "DPI-C" test = task c_test();

 

reference

[1] synopsys DPI ppt,VCS 2006.06-SP2-2

[2] SV for verification 3rd ed

[3] PLI vs DPI, 2004 SNUG, S Sutherland 
[4] http://www.vmmcentral.org/vmartialarts/category/systemc/ 
更多关于systemc与vmm之间关系的讨论

[5] How to connect your SystemC reference model to your verification framework

http://www.vmmcentral.org/vmartialarts/2009/07/how-to-connect-your-systemc-reference-model-to-your-verification-framework/

 

posted on 2012-09-18 05:02  单向度的人  阅读(2009)  评论(0编辑  收藏  举报

导航