• 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. C++ Object life cycle through SV DPI

Stats

  • Locked Locked
  • Replies 11
  • Subscribers 64
  • Views 18973
  • 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

C++ Object life cycle through SV DPI

archive
archive over 18 years ago

Hi all,

I have a C++ Object life cycle through SV DPI problem.

For example, I have a C++ reference model class named ALU.  Only one public function revealed to client (e.g. ALU::ALU_EXEC) and was encapsulated in DPI(ALU_EXEC_DPI) . And there are two types of ALU commands was entered to ALU::ALU_EXEC. One is setup ALU parameters (i.e. setup the ALU class private member) , the other is calculating the result.
 
The question is when I leave DPI, the ALU object is eliminated and all the setup parameter is cleared, right? So can I keep a C++ Object even after I leave DPI (i.e. is the C++ Object life cycle only as long as DPI call life cycle).

My friend suggest me to return all the ALU parameter out to SV and re-enter these parameters to ALU through ALU_EXEC_DPI when I call the ALU reference model. But it may break the model encapsulation :(

May be my question is not very clear and any suggestions are welcome!
Davy




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

    Hi Vivek,

    I will try to describe the situation I encounter comprehensively. Please point it out if you think it is ambiguous.

    First, I want to re-use a C++ model as the reference model. It contains a class, ALU. The ALU class have one public function ALU_exec (opcode,src,result). I will keep them untouched.

    Then, if I encapsulate the class ALU with DPI function like
    ALU_exec_DPI (opcode,src, result) {
    ALU::ALU();
    ALU::ALU_exec (opcode,src,result).
    ALU::~ALU();
    }

    But as you see, when the DPI function return, the ALU object is eliminated (But I want to keep the ALU object alive until the simulation end for there are some status information stored in the ALU object), and there will be a new ALU object when I re-enter the DPI function.

    At last, I turn to youi for help, and you suggest to use DPI task.
    I guess if I use DPI task, I can generate the ALU object ALU::ALU(); when I enter the simulation ( or I get the first instruction)
    , while ALU::ALU_exec (opcode,src,result) is always running on the same ALU object through the whole simulation time
    , and ALU::~ALU(); to eliminate the ALU object when I exit the simulation.

    And what do you mean by call task in always loop?
    //---SV file
    import “DPI” task alu_run(...);
    always @(clk, a, b, opcode)
    alu_run(clk, opcode,a, b, result,$realtime);
    //---

    BTW, "$realtime" is copied from Sutherland's example and I don't think it is a must :)

    Any suggestions are welcome!

    Best regards,
    Davy


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

    Hi Vivek,

    I will try to describe the situation I encounter comprehensively. Please point it out if you think it is ambiguous.

    First, I want to re-use a C++ model as the reference model. It contains a class, ALU. The ALU class have one public function ALU_exec (opcode,src,result). I will keep them untouched.

    Then, if I encapsulate the class ALU with DPI function like
    ALU_exec_DPI (opcode,src, result) {
    ALU::ALU();
    ALU::ALU_exec (opcode,src,result).
    ALU::~ALU();
    }

    But as you see, when the DPI function return, the ALU object is eliminated (But I want to keep the ALU object alive until the simulation end for there are some status information stored in the ALU object), and there will be a new ALU object when I re-enter the DPI function.

    At last, I turn to youi for help, and you suggest to use DPI task.
    I guess if I use DPI task, I can generate the ALU object ALU::ALU(); when I enter the simulation ( or I get the first instruction)
    , while ALU::ALU_exec (opcode,src,result) is always running on the same ALU object through the whole simulation time
    , and ALU::~ALU(); to eliminate the ALU object when I exit the simulation.

    And what do you mean by call task in always loop?
    //---SV file
    import “DPI” task alu_run(...);
    always @(clk, a, b, opcode)
    alu_run(clk, opcode,a, b, result,$realtime);
    //---

    BTW, "$realtime" is copied from Sutherland's example and I don't think it is a must :)

    Any suggestions are welcome!

    Best regards,
    Davy


    Originally posted in cdnusers.org by davyzhu
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

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