Monday, August 28, 2017

uvm_factory


1. What is uvm_factory?
 uvm_factory is a class that manufacture (create) uvm_component and object during run time.


2. Why use it?
ability to modify the types and no of objects that make up the testbench hierarchy.


3. Factory_Registration items :
  • An uvm_component_registry wrapper, typedef-ed to type_id.
  • A static id to get the type_id.
  • A function to get the type_name.
4. Only one instance of the factory is present in a given simulation (termed a singleton)


5. Register the class type to the factory using macros:
`uvm_component_utils //for component
`uvm_object_utils // for stimulus and sequences

above 2 macros are used to register components and objects in the factory:
i) declares typedef of wrapper type named type_id
ii) defines get_type and get_type_name function


6. Factory registration of parametrized class:
`uvm_component_param_utils //components
`uvm_object_param_utils //stimulus and sequence

Example:
class write_xtn #(Type T = int) extends uvm_sequence_item;
`uvm_object_param_utils (write xtn #(T))
endclass


class bus_wr_driver #(Type T= int, width W=32) extends uvm_driver;
`uvm_component_param_utils (bus_wr_driver) #(T W))
endclass



7. Constructor Defaults
  • uvm_component and uvm_objects constructors are virtual methods
  • the defaults are different for components and objects

8. Constructor Defaults for a component

class my_component extends uvm_component;
function new (string name = "my_component", uvm_component parent = null)
super.new (name, parent);
endfunction


9. Constructor Defaults for an object

class my_item extends uvm_sequence_item
function new(string name = "my_item");
super.new(name);
endfunction



10. Creating Components:
  • During the build phase using the top-down approach.
  • Using the create method of the uvm_component_registry.

Virtual function uvm_object create (String name = "", uvm_component, parent )




11. Creating Components in the build phase

Class bus_wr_agent extends uvm_components;
bus_wr_driver drvh ;
function build_phase (uvm_phase phase);
super.build_phase (uvm_phase phase);
drvh = bus_wr_driver :: type_id :: create ("drvh", this);
....
endfunction
endclass



12. Note :
do not use new() to allocate the memory, use create()
drvh = new (drvh, this) //no to this

WHY:-  when you do new to create an object, you will be restricted with that type of object, it is highly desirable to change the type of the object being constructed without having to modify the existing code

13. uvm_factory has two kind of registry :
classtype_registry - whenever we register something it goes to classtype_registry
override registry


14.  uvm_factory provides four different methods to override a particular instance or all instances of a particular class. 
i) set_inst_override_by_type  - when we want to overwrite all the instance of a class 

ii) set_inst_override_by_name - when we want to override all the instance of a data type or method or variable


i) set_type_override_by_type : A convenience function for uvm_factory::set_type_override_by_type, this method registers a factory override for components and objects created at this level of hierarchy or below.


ii) set_inst_override_by_type : A convenience function for uvm_factory::set_inst_override_by_type, this method registers a factory override for components and objects created at this level of hierarchy or below
factory.set_inst_override_by_type(B::get_type(), B_override::get_type(), "path2.b2"); 

iii) set_inst_override_by_type configure factory to create an object of override type when request made to create an object for original type using context that matches the full_inst_path string argument.

iv) set_type_override_by_type configure factory to create an object of override type when request made to create an object for original type.



15. Question: how to get a handle to the UVM factory so as to use a function such as set_type_override_by_name().


An instance named factory is automatically created internally in UVM. You can use it directly. Directly use factory.set_type_override_by_name("original_type_name","override_type_name");

16. It uses the concept of polymorphism.



















No comments:

Post a Comment

Ethernet and more

Ethernet is a protocol under IEEE 802.33 standard User Datagram Protocol (UDP) UDP is a connectionless transport protocol. I...