Verification Academy

Search form

My Account Menu

  • Register
  • Log In
  • Topics
  • Courses
  • Forums
  • Patterns Library
  • Cookbooks
  • Events
  • More
  • All Topics
    The Verification Academy offers users multiple entry points to find the information they need. One of these entry points is through Topic collections. These topics are industry standards that all design and verification engineers should recognize. While we continue to add new topics, users are encourage to further refine collection information to meet their specific interests.
    • Languages & Standards

      • Portable Test and Stimulus
      • Functional Safety
      • Design & Verification Languages
    • Methodologies

      • UVM - Universal Verification Methodology
      • UVM Framework
      • UVM Connect
      • FPGA Verification
      • Coverage
    • Techniques & Tools

      • Verification IQ
      • Verification IP
      • Static-Based Techniques
      • Simulation-Based Techniques
      • Planning, Measurement, and Analysis
      • Formal-Based Techniques
      • Debug
      • Acceleration
  • All Courses
    The Verification Academy is organized into a collection of free online courses, focusing on various key aspects of advanced functional verification. Each course consists of multiple sessions—allowing the participant to pick and choose specific topics of interest, as well as revisit any specific topics for future reference. After completing a specific course, the participant should be armed with enough knowledge to then understand the necessary steps required for maturing their own organization’s skills and infrastructure on the specific topic of interest. The Verification Academy will provide you with a unique opportunity to develop an understanding of how to mature your organization’s processes so that you can then reap the benefits that advanced functional verification offers.
    • Universal Verification Methodology (UVM)

      • Introduction to UVM
      • UVM Basics
      • Advanced UVM
      • UVM Connect
      • UVM Debug
      • UVMF - One Bite at a Time
    • Featured Courses

      • Introduction to ISO 26262
      • Introduction to DO-254
      • Clock-Domain Crossing Verification
      • Portable Stimulus Basics
      • Power Aware CDC Verification
      • Power Aware Verification
      • SystemVerilog OOP for UVM Verification
    • Additional Courses

      • Assertion-Based Verification
      • An Introduction to Unit Testing with SVUnit
      • Evolving FPGA Verification Capabilities
      • Metrics in SoC Verification
      • SystemVerilog Testbench Acceleration
      • Testbench Co-Emulation: SystemC & TLM-2.0
      • Verification Planning and Management
      • VHDL-2008 Why It Matters
    • Formal-Based Techniques

      • Formal Assertion-Based Verification
      • Formal-Based Technology: Automatic Formal Solutions
      • Formal Coverage
      • Getting Started with Formal-Based Technology
      • Handling Inconclusive Assertions in Formal Verification
      • Sequential Logic Equivalence Checking
    • Analog/Mixed Signal

      • AMS Design Configuration Schemes
      • Improve AMS Verification Performance
      • Improve AMS Verification Quality
  • All Forum Topics
    The Verification Community is eager to answer your UVM, SystemVerilog and Coverage related questions. We encourage you to take an active role in the Forums by answering and commenting to any questions that you are able to.
    • UVM Forum

      • Active Questions
      • Solutions
      • Replies
      • No Replies
      • Search
      • UVM Forum
    • SystemVerilog Forum

      • Active Questions
      • Solutions
      • Replies
      • No Replies
      • Search
      • SystemVerilog Forum
    • Coverage Forum

      • Active Questions
      • Solutions
      • Replies
      • No Replies
      • Search
      • Coverage Forum
    • Additional Forums

      • Announcements
      • Downloads
      • OVM Forum
  • Patterns Library
    The Verification Academy Patterns Library contains a collection of solutions to many of today's verification problems. The patterns contained in the library span across the entire domain of verification (i.e., from specification to methodology to implementation—and across multiple verification engines such as formal, simulation, and emulation).
    • Implementation Patterns

      • Environment Patterns
      • Stimulus Patterns
      • Analysis Patterns
      • All Implementation Patterns
    • Specification Patterns

      • Occurrence Property Patterns
      • Order Property Patterns
      • All Specification Patterns
    • Pattern Resources

      • Start Here - Patterns Library Overview
      • Whitepaper - Taking Reuse to the Next Level
      • Verification Horizons - The Verification Academy Patterns Library
      • Contribute a Pattern to the Library
  • All Cookbooks
    Find all the methodology you need in this comprehensive and vast collection. The UVM and Coverage Cookbooks contain dozens of informative, executable articles covering all aspects of UVM and Coverage.
    • UVM Cookbook

      • UVM Basics
      • Testbench Architecture
      • DUT-Testbench Connections
      • Configuring a Test Environment
      • Analysis Components & Techniques
      • End Of Test Mechanisms
      • Sequences
      • The UVM Messaging System
      • Other Stimulus Techniques
      • Register Abstraction Layer
      • Testbench Acceleration through Co-Emulation
      • Debug of SV and UVM
      • UVM Connect - SV-SystemC interoperability
      • UVM Versions and Compatibility
      • UVM Cookbook
    • Coding Guidelines & Deployment

      • Code Examples
      • UVM Verification Component
      • Package/Organization
      • Questa/Compiling UVM
      • SystemVerilog Guidelines
      • SystemVerilog Performance Guidelines
      • UVM Guidelines
      • UVM Performance Guidelines
    • Coverage Cookbook

      • Introduction
      • What is Coverage?
      • Kinds of Coverage
      • Specification to Testplan
      • Testplan to Functional Coverage
      • Bus Protocol Coverage
      • Block Level Coverage
      • Datapath Coverage
      • SoC Coverage Example
      • Requirements Writing Guidelines
      • Coverage Cookbook
  • All Events
    No one argues that the challenges of verification are growing exponentially. What is needed to meet these challenges are tools, methodologies and processes that can help you transform your verification environment. These recorded seminars from Verification Academy trainers and users provide examples for adoption of new technologies and how to evolve your verification process.
    • Featured & On-Demand

      • Continuous Integration - March 28th
      • Questa Verification IQ - April 11th
      • SystemVerilog Assertions
      • SoC Design & Functional Safety Flow
      • 2022 Functional Verification Study
      • Design Solutions as a Sleep Aid
      • CDC and RDC Assist
      • Formal and the Next Normal
      • Protocol and Memory Interface Verification
      • Webinar Calendar
    • On-Demand Library

      • Practical Flows for Continuous Integration
      • Lint vs Formal AutoCheck
      • The Three Pillars of Intent-Focused Insight
      • Formal Verification Made Easy
      • Fix FPGA Failures Faster
      • HPC Protocols & Memories
      • FPGA Design Challenges
      • High Defect Coverage
      • The Dog ate my RTL
      • Questa Lint & CDC
      • Complex Safety Architectures
      • Data Independence and Non-Determinism
      • Hierarchical CDC+RDC
      • All On-Demand Recordings
    • Recording Archive

      • Aerospace & Defense Tech Day
      • Exhaustive Scoreboarding
      • Improving Initial RTL Quality
      • CDC Philosophy
      • Hardware Emulation Productivity
      • Visualizer Debug Environment
      • Preparing for PCIe 6.0: Parts I & II
      • Automotive Functional Safety Forum
      • Siemens EDA Functional Verification
      • Improving Your SystemVerilog & UVM Skills
      • All Webinar Topics
    • Conferences & WRG

      • Industry Data & Surveys
      • DVCon 2023
      • DVCon 2022
      • DVCon 2021
      • Osmosis 2022
      • All Conferences
    • Siemens EDA Learning Center

      • SystemVerilog Fundamentals
      • SystemVerilog UVM
      • EDA Xcelerator Academy(Learning Services) Verification Training, Badging and Certification
      • View all Learning Paths
  • About Verification Academy
    The Verification Academy will provide you with a unique opportunity to develop an understanding of how to mature your organization's processes so that you can then reap the benefits that advanced functional verification offers.
    • Blog & News

      • Verification IQ
      • Verification Horizons Blog
      • Technical Resources
    • Verification Horizons Publication

      • Verification Horizons - March 2023
      • Verification Horizons - December 2022
      • Verification Horizons - July 2022
      • Issue Archive
    • About Us

      • Verification Academy Overview
      • Subject Matter Experts
      • Academy News
      • Contact Us
    • Training

      • Learning @OneGlance (PDF)
      • SystemVerilog & UVM Classes
      • Siemens EDA Classes
Ask a Question
OVM
  • Home
  • Forums
  • OVM
  • importance of the clone( ) method

importance of the clone( ) method

OVM 2524
ankit1
ankit1
Full Access
40 posts
March 28, 2008 at 4:34 am

Hi ALL,

Can anybody tell me the exact application of the clone methos?
What is the significance of the clone method?

Regards,
Ankit.

Replies

Log In to Reply
kurts
kurts
Full Access
150 posts
March 28, 2008 at 11:56 am

The clone method is used to provide a deep (nested) copy of an object.

clone first allocates new memory for the object, then copies over each field to the new object. If a field is an object handle, then instead of copying the handle (which would do a "shallow" copy) you would call fieldname.clone() to recursively allocate memory for that field (a "deep" copy).

-Kurt

sportsprince
sportsprince
Forum Access
5 posts
March 30, 2008 at 7:34 pm

kurts wrote:
The clone method is used to provide a deep (nested) copy of an object.

clone first allocates new memory for the object, then copies over each field to the new object. If a field is an object handle, then instead of copying the handle (which would do a "shallow" copy) you would call fieldname.clone() to recursively allocate memory for that field (a "deep" copy).

-Kurt


Hi, Kurt:

But it seems equal to .copy(), what additional value this method adds?
Gopi
Gopi
Forum Access
14 posts
March 30, 2008 at 10:47 pm

clone() returns a handle of newly created object which is copy of original object.

If you want to use copy(), New objected has to be created explicitly.

Look at page number 267, 284 of AVM cook book.

devangamoneesh
devangamoneesh
Full Access
16 posts
March 30, 2008 at 11:40 pm

Hi Ankit,

you can simply remember as clone = create and (+) copy
That is, it first creates a new object and then copies all the data to the newly created object.

Regards,
Moneesh

dave_59
dave_59
Forum Moderator
10658 posts
March 31, 2008 at 1:10 am

Another key difference is that clone() is virtual; copy() is non-virtual. And clone() is a method of the original object; copy() is a method of the target object.
That means clone() creates a copy an object of the same class type as the original. With copy(), the original object could be a subclass of the target object's type with additional class properties that will not get copied.

Dave

— Dave Rich, Verification Architect, Siemens EDA

mseyunni
mseyunni
Full Access
194 posts
February 24, 2014 at 11:06 am

In reply to dave_59:

Hi Dave,

With copy(), the original object could be a subclass of the target object's type with additional class properties that will not get copied.

I haven't understood why "additional class properties will not get copied" for copy() as the subclass (child) is inherited from a base class (parent), which means it has all the properties and methods of the parent. Could you explain what you meant by additional class properties not getting copied.

Thanks,
Madhu

dave_59
dave_59
Forum Moderator
10658 posts
February 24, 2014 at 1:16 pm

In reply to mseyunni:

class base;
int p1;
  function void copy(base orig);
    this.p1 = orig.p1;
  endfunction
endclass
class ex_base;
  int p2;
  function void copy(base orig);
    super.copy(b);
    this.p2 = orig.p2;
  endfunction
endclass
 
base b1,b2;
ex_base eb1, eb2;
initial begin
   eb1 = new; eb2 = new();
   eb2.p2 = 5;
   b1 = eb1; b2 = eb2;
   b1.copy(b2); // p2 is not copied
   eb1.copy(eb2); // p2 is copied
end

Since copy() is not virtual, calling b1.copy() calls base::copy(), and the additional property p2 is not copied even though it exists in object referenced by b1.

— Dave Rich, Verification Architect, Siemens EDA

ranjithkumar d
ranjithkumar d
Forum Access
28 posts
January 06, 2015 at 1:57 am

In reply to dave_59:

p2 will copy if we write b1.copy(eb2)?

Nico75
Nico75
Full Access
163 posts
October 22, 2015 at 1:54 am

I do not understand the claims about copy() here. I agree with the example code, but in UVM the non-virtual copy() method calls the virtual do_copy() method. So the do_copy of the derived class gets called, and hence its members do get copied?

For example:

class base extends uvm_object;
    `uvm_object_utils(base)
 
    int f1=0;
 
    function void do_copy(uvm_object rhs);
        base rhs_;
        $display("do_copy of base");
        super.do_copy(rhs);
        $cast(rhs_,rhs);
        f1=rhs_.f1;
    endfunction
endclass
 
class ex extends base;
    `uvm_object_utils(ex)
 
    int f2=0;
 
    function void do_copy(uvm_object rhs);
        ex rhs_;
        $display("do_copy of ex");
        super.do_copy(rhs);
        $cast(rhs_,rhs);
        f2=rhs_.f2;
    endfunction
endclass
 
module automatic Top();
 
function void doit();
    base B1,B2;
    ex E1,E2;
 
    E1=new;
    E1.f1=123;
    E1.f2=456;
    B1=E1;
    E2=new;
    B2=E2;
    B2.copy(B1);
    $display("E2.f1=%0d",E2.f1);
    $display("E2.f2=%0d",E2.f2);
 
endfunction

calls the copy() on base class handles and still succesfully copies the correct derived class members:

# do_copy of ex
# do_copy of base
# E2.f1=123
# E2.f2=456

edit: I see this was actually an OVM topic, maybe this changed in UVM?

swetha ss
swetha ss
Forum Access
11 posts
January 05, 2016 at 11:05 pm

In reply to dave_59:
Hi Dave,
I can understand which you gave the example of copy but i need the example for clone() also.You said copy() is virtual in that thing i just confused what is virtual will you please clear my doudt i am new learner of SV.
thanks in advance.

dave_59
dave_59
Forum Moderator
10658 posts
January 11, 2016 at 10:14 am

In reply to NiLu:

The OVM and UVM mechanisms are the same. The OVM added the virtual do_copy() methods as a hook to the non-virtual copy() methods. This might be to get their field automation macros to work.

In reply to swethasundararaj:

class base;
int p1;
  function void copy(base orig);
    this.p1 = orig.p1;
  endfunction
  virtual function base clone(base orig);
    base h;
    h  = new;
    h.copy(orig);
    return h;
  endfunction
endclass
class ex_base;
  int p2;
  function void copy(base orig);
    super.copy(b);
    this.p2 = orig.p2;
  endfunction
   virtual function base clone(base orig);
    ex_base h, h_orig
    h  = new;
    $cast(h_orig, orig)
    h.copy(h_orig);
    return h;
  endfunction
endclass
 
base b1,b2;
ex_base eb1, eb2;
initial begin
   eb1 = new; eb2 = new();
   eb2.p2 = 5;
   b1 = eb1; b2 = eb2;
   b1.copy(b2); // p2 is not copied
   eb1.copy(eb2); // p2 is copied
end

— Dave Rich, Verification Architect, Siemens EDA

scottj97
scottj97
Forum Access
8 posts
August 01, 2016 at 9:50 am

In reply to NiLu:

Quote:
I do not understand the claims about copy() here. I agree with the example code, but in UVM the non-virtual copy() method calls the virtual do_copy() method. So the do_copy of the derived class gets called, and hence its members do get copied?

For example:

function void doit();
    base B1,B2;
    ex E1,E2;
 
    E1=new;
    E1.f1=123;
    E1.f2=456;
    B1=E1;
    E2=new;
    B2=E2;
    B2.copy(B1);
    $display("E2.f1=%0d",E2.f1);
    $display("E2.f2=%0d",E2.f2);
 
endfunction

There is quite a bit of confusion in this thread on copy vs clone.

The problem with the quoted example is that the child class type must be known at compile time. Doing "E2=new; B2=E2;" means that B2 is pointing to type ex, so ex::do_copy() will get run as intended.

But what if we don't know the child class type? After all, that is the whole point. We have only a handle to an object whose specific subclass is not known at compile time. The copy() method does not work in this case. Here's a few examples:

///// option 1: no good because you must know type of rhs  
//    E2=new;                                                    
//    B2=E2;                                         
///// option 2: no good because B2 remains of type base
//    B2=new;
//    B2.copy(B1);
///// option 3: works
    void'($cast(B2, B1.clone()));
///// end options                                    
    $display("B2 type is %s", B2.get_type_name());
ankitjain
ankitjain
Full Access
3 posts
March 06, 2019 at 8:00 pm

In reply to dave_59:

Quote:
In reply to NiLu:

The OVM and UVM mechanisms are the same. The OVM added the virtual do_copy() methods as a hook to the non-virtual copy() methods. This might be to get their field automation macros to work.

In reply to swethasundararaj:

class base;
int p1;
  function void copy(base orig);
    this.p1 = orig.p1;
  endfunction
  virtual function base clone(base orig);
    base h;
    h  = new;
    h.copy(orig);
    return h;
  endfunction
endclass
[b]class ex_base;
  int p2;
  function void copy(base orig);
    super.copy(b);
    this.p2 = orig.p2;
  endfunction
   virtual function base clone(base orig);
    ex_base h, h_orig
    h  = new;
    $cast(h_orig, orig)
    h.copy(h_orig);
    return h;
  endfunction
endclass[/b]
 
base b1,b2;
ex_base eb1, eb2;
initial begin
   eb1 = new; eb2 = new();
   eb2.p2 = 5;
   b1 = eb1; b2 = eb2;
   b1.copy(b2); // p2 is not copied
   eb1.copy(eb2); // p2 is copied
end

Hi dave,
I am trying to copy an extended class object, randomized multiple times having single handle.
It is to be copied to the same type of class object based on certain conditions, thus using cloning method.

I am trying to implement it like this:

class mcs_data_packet extends mcs_inst_packet;
 
  rand logic w1r0;
 
  int mcs_core=0; 
  int count =0;   
 
  function new ();
  endfunction:new
 
  function void copy(mcs_data_packet ext);
    super.copy(ext);
    this.w1r0 = ext.w1r0; 
  endfunction
 
  virtual function mcs_data_packet clone(mcs_data_packet ext);
    mcs_data_packet h;
    h=new();
    h.copy(ext);
    return h;
  endfunction

But getting error as below:
virtual function mcs_data_packet clone(mcs_data_packet ext);
|
ncvlog: *E,CVMNMM (mcs_data_packet.svh,23|59): Virtual method 'mcs_data_packet::clone' formal argument name does not match base class 'mcs_inst_packet'.
virtual function mcs_data_packet clone(mcs_data_packet ext);
|
ncvlog: *E,CVMTMM (mcs_data_packet.svh,23|59): Virtual method 'mcs_data_packet::clone' formal argument type does not match base class 'mcs_inst_packet'.
Total errors/warnings found outside modules and primitives:
errors: 2, warnings: 0

But modifying the code:

class mcs_data_packet extends mcs_inst_packet;
 
  rand logic w1r0;
 
  int mcs_core=0; 
  int count =0;   
 
  function new ();
  endfunction:new
 
  function void copy(mcs_data_packet ext);
    super.copy(ext);
    this.w1r0 = ext.w1r0;
  endfunction
 
  virtual function mcs_inst_packet clone(mcs_inst_packet ext);
    mcs_data_packet h,h_orig;
    h=new();
    $cast(h_orig,ext);
    h.copy(h_orig);
    return h;
  endfunction

Getting error as while cloning I am passing the extended class type to clone function while it is expecting base class type.

mcs_data_rec[0]=mcs_data.clone(mcs_data);
|
ncvlog: *E,TYCMPAT (tb.sv,1131|30): assignment operator type check failed (expecting datatype compatible with 'class $unit::mcs_data_packet' but found 'class $unit::mcs_inst_packet' instead).

Can you please explain how to clone an extended class.

cgales
cgales
Forum Moderator
1951 posts
March 07, 2019 at 5:50 am

In reply to ankitjain:

Both copy() and clone() are already defined as part of the uvm_object class, and you don't want to override them.

Instead, you want to implement do_copy() instead. The clone() and copy() functions will utilize your do_copy() method.

Refer to the Transaction Methods page for more information.

svq
svq
Full Access
28 posts
December 30, 2019 at 1:46 pm

I am still confused about the virtual/non virtual aspect of copy/clone after reading the thread. Can anyone please correct me if the following conclusion is wrong. do copy and do clone are virtual methods while copy and clone are not. However since there are hooks to do_copy and do_clone in copy and clone method. Hence calling copy and clone on the object will call the function implemented in the extended class object.

dave_59
dave_59
Forum Moderator
10658 posts
December 30, 2019 at 3:49 pm

In reply to svq:

Unfortunately, the UVM is much more complicated than it needs to be due to its history. It is expecting that everyone is using the macros to register the class with the factory. You are not supposed to override clone() or copy(), so it really doesn't matter if they are virtual or not in that case.

uvm_object::clone() calls the virtual create() method that get inserted by the `uvm_object_utils macro in each derived class. There is no do_clone() method; the create() method is taking the place of that.

You are correct about do_copy(). After calling create(), uvm_object::clone(), calls uvm_object::copy, which then calls the virtual do_copy().

— Dave Rich, Verification Architect, Siemens EDA

svq
svq
Full Access
28 posts
January 05, 2020 at 11:13 am

In reply to dave_59:

Thanks Dave for the explanation. Makes sense now

Have_A_Doubt
Have_A_Doubt
Forum Access
173 posts
September 25, 2021 at 10:20 am

In reply to dave_59:

Dave , I believe there's a few typos

class ex_base ;   
  should  be 
class ex_base extends  base ;        // Should  extend  base 
 int p2;
  function void copy(base orig);
    super.copy(orig);                //  Arg.  name  should  be   'orig'
    this.p2 = orig.p2;
  endfunction
Siemens Digital Industries Software

Siemens Digital Industries Software

#TodayMeetsTomorrow

Portfolio

  • Cloud
  • Mendix
  • Electronic Design Automation
  • MindSphere
  • Design, Manufacturing and PLM Software
  • View all Portfolio

Explore

  • Community
  • Blog
  • Online Store

Siemens

  • About Us
  • Careers
  • Events
  • News and Press
  • Customer Stories
  • Partners
  • Trust Center

Contact

  • VA - Contact Us
  • PLM - Contact Us
  • EDA - Contact Us
  • Worldwide Offices
  • Support Center
  • Give us Feedback
© Siemens 2023
Terms of Use Privacy Statement Cookie Statement DMCA