worma Posted October 5, 2010 Report Posted October 5, 2010 Hello experts, I am trying to use the uvm_in_order_comparator, inside the scoreboard and looks like the transaction class should have a comp method. Is this comp same as compare?? Any clue how to implement this CLASS: uvm_in_order_comparator #(T,comp_type,convert,pair_type) // // Compares two streams of data objects of type T, a parameter to this class. // These transactions may either be classes or built-in types. To be // successfully compared, the two streams of data must be in the same order. // Apart from that, there are no assumptions made about the relative timing of // the two streams of data. // // Type parameters // // T - Specifies the type of transactions to be compared. // // comp - The type of the comparator to be used to compare the two // transaction streams. // When T is a class, T must implement comp and convert2string, and you must // specify class-based policy classes for comp_type, convert, and pair_type. // In most cases, you can use the convenient subtype, // uvm_in_order_class_comparator #(T). Quote
shail Posted September 19, 2011 Report Posted September 19, 2011 `uvm_field macros implement compare method for you. If you want to do something special, you can implement do_compare method (nicely explained in uvm documentation). Quote
mea1201 Posted September 20, 2011 Report Posted September 20, 2011 If you register the transaction class's attributes that you wish to compare using the factory (i.e. using the field macros), then you do not need to define any other method, and can use the uvm_in_order_comparator as is. If you wish to define a custom comparison for your transaction, then you can override do_compare in your transaction class, and still use the comparator as is. Or, you can pass in a policy class, which includes a static comp method that returns a bit, to the comparator that defines your custom comparison. That is what the comp_type argument is for. Quote
DavidLarson Posted February 14, 2012 Report Posted February 14, 2012 The ovm_field automation macros define a m_field_automation function that is used for comparison (among other things). It does not define a comp() function in the class itself. I am trying to use the ovm_in_order_class_comparator on a child class of ovm_sequence_item that is registered with the factory and it still doesn't compile. I had to manually define a comp() function that simply calls compare() to make the compiler happy. Quote
janick Posted February 14, 2012 Report Posted February 14, 2012 The implementation of the comp() method you are talking about is the comparison policy class. A policy class is a standard OO pattern (see http://en.wikipedia.org/wiki/Policy-based_design) that allows the comparator class to operate using any comparison function. If you want to use the uvm_object::compare() method, use the uvm_in_order_class_comparator which uses a set of predefined policy classes. For more specific help, it would be useful if you showed some of your code. Quote
DavidLarson Posted February 14, 2012 Report Posted February 14, 2012 Hi Janick, I am creating a child class of the ovm_in_order_class_comparator: class scoreboard extends ovm_in_order_class_comparator #(sequence_item); sequence_item is just a generic child class of ovm_sequence_item. The sequence_item class is registered with the factory like other objects: `ovm_object_utils_begin(sequence_item) `ovm_field_int(id, OVM_DEFAULT); `ovm_field_int(delay, OVM_DEFAULT); `ovm_field_int(clone_item, OVM_DEFAULT); `ovm_object_utils_end The code will not compile unless I add a comp() function to the sequence_item class. My implementation of comp() just calls compare(item). Am I not following the intended usage model? Quote
DavidLarson Posted February 15, 2012 Report Posted February 15, 2012 Several other things bother me about this class: The "Comparator match" message does not have a verbosity setting so it is always printed - there is no way to turn it off. It also doesn't use the `ovm_info macro which has better performance. The flush() function clears the internal variables, but doesn't clear the fifos. The comment says "The <tlm_fifo #(T)::flush> takes care of flushing the FIFOs"... but you cannot access the fifos because they are local variables, so there appears to be no way to clear them. A really important place to add EOT objections is in the scoreboard. When one side generates a transaction and the scoreboard is waiting for the other side to send a transaction, I'd expect an objection to be raised. I can't think of an easy way to add my own objections, esp. since the fifos have local scope. Quote
janick Posted February 15, 2012 Report Posted February 15, 2012 Oh! You are using OVM. You do realize this is a *UVM* forum, right? Looks like this is something wrong with OVM's ovm_class_comp() policy class as your code works fine with UVM. Quote
DavidLarson Posted February 15, 2012 Report Posted February 15, 2012 Yes, I know that this is a UVM forum, but the OVM forum seems to be merged with this one.... I did some spot checks (before posting to this thread) and it seemed that both the OVM and UVM versions of this file didn't change much. But you pointed me in the right direction, I think. I found that the ovm_class_comp is implemented like this: //---------------------------------------------------------------------- // CLASS: ovm_class_comp #(T) // // This policy class is used to compare two objects of the same type. // // Provides a comp method that compares two objects of type T. The // class T must implement the comp method, to which this class delegates // the operation. //---------------------------------------------------------------------- class ovm_class_comp #(type T=int); static function bit comp(input T a, input T ; return a.comp(; endfunction endclass While the UVM version is implemented like this: //---------------------------------------------------------------------- // CLASS: uvm_class_comp #(T) // // This policy class is used to compare two objects of the same type. // // Provides a comp method that compares two objects of type T. The // class T must provide the method "function bit compare(T rhs)", // similar to the <uvm_object::compare> method. //---------------------------------------------------------------------- class uvm_class_comp #(type T=int); static function bit comp(input T a, input T ; return a.compare(; endfunction endclass So UVM changed it to use the built-in compare() function (a good thing). But, this class is still a pain (see my 3 point list posted earlier). Quote
janick Posted February 15, 2012 Report Posted February 15, 2012 The comparator classes are really building blocks for a scoreboard, not a scoreboard in and of themselves... There is the intend to provide a proper scoreboard class in UVM but there is no active work going on in that direction. And since everyone's scoreboard is a little different, it is something that is hard to generalize. Quote
DavidLarson Posted February 15, 2012 Report Posted February 15, 2012 Janick, thank you for your comments on this. As I understand it, I am attempting to use the comparator class as a building block for my own scoreboard, but I am finding that the comparator isn't usable even as a building block... or perhaps I have the wrong usage model in mind? If it was never intended to be used as a parent class for a scoreboard, then what is the intended usage model? Quote
janick Posted February 15, 2012 Report Posted February 15, 2012 (edited) They are intended to be used as building blocks. Given the limitations and challenges you have outlined, they may or may not suitable for your application. The functionality they encapsulate is not very complicated and I have always found it more useful to replicate and adapt it rather than reuse it. Edited February 15, 2012 by janick Quote
dave_59 Posted February 15, 2012 Report Posted February 15, 2012 The comparator classes in the UVM came from examples in the AVM, they were never truly intended to be part of the core BCL, just coding templates. They have not kept up with all the features of the OVM/UVM. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.