PDA

View Full Version : usage of OVM scenario generator



Amrutha
01-23-2008, 08:40 PM
Hi All,

I am new to both OVM and AVM. So can some one please tell me the way to effficiently use scenario generator in OVM. Is it possible to write constraints like(the way we do in vmm):

constraint address_c{
items[i].addr = items[i-1].addr*2;
}

using the ovm_scenario* classes without overwritting or adding any new methods in the base classes (except body method of ovm_scenario).

Regards,
Amrutha

Andy
01-24-2008, 12:33 PM
Hi Amrutha:

In the ovm_scenarios, you can add constraints just like anywhere else in SystemVerilog. You can add in-line constraints, or extend the class to include additional constraints. In either case, you won't need to modify any base class methods.

-Andy

Amrutha
01-24-2008, 08:31 PM
Hi Andy,
Thanks fory your reply,
But my issue was in writting interrelated constraints, where fields randomized for one transaction should depend on the previous ones.
In order to do that, Initially I extended ovm_stimulus_scenario class and created a queue(item[$]) of a class extended from ovm_sequence_item in it. The body method in the scenario class was updated as :
task body();
for(int i = 0; i < seq.item.size();i++)begin
apply_send(item[i]);
end
endtask;
but this won't take into consideration the constraints like item[i].addr == item[i-1].addr defined in this class itself. If I pass this entire class to apply_send method like apply_method(this), then the constraints will be met and entire item queue will be randomized. But again this item is fetched by get_next_item method of my driver that is extended from ovm_scenario_driver class which accepts just a single object of ovm_sequence_item and not a queue. so it gives me a fatal error. So the only option that I found to solve this problem was to write my own method that would randomize the entire queue but pass the elements of the queue one by one to my driver..
Is there any other better way to write this type of constraints using methods defined in the base classes itself? Am I missing using some inbuilt methods that will take care of my above requirement?

Thanks & Regards ,
Amrutha

Andy
01-25-2008, 07:11 AM
Hi Amrutha:

Let's see if I'm answering your question - you may need to ask one more time

You have an array of randomized classes. You can certainly do what you described in your first post - where each classs array index is randomized based on a value of the previous array element. From the class that instantiates the items[] (I'm assuming that item is a class) you could do:

class my_items;
rand item_class item[];

constraint addr_double_c { foreach (item[k]) (k < item.size()-1) -> item[k+1].addr == item[k].addr*2; }

...
enclass

However, from your second response, it seems that you would have to randomize the whole thing once before you do an apply on any element, since either side of the == constraint could change using that constraint, so you would not be getting addresses that are doubling for each consecutive item if you call randomize each time you send an element, which is what I'm guessing is what you are looking for.

-Andy

Amrutha
01-28-2008, 12:36 AM
Hi Andy,
From the statement "However, from your second response, it seems that you would have to randomize the whole thing once before you do an apply on any element" in your reply, it seems that
=> I need to have a class (say abc) that contains the queue(item[$]) of the class (transaction class) whose elements are to be randomized along with the constarints of type "item[k+1].addr == item[k].addr*2".
=> Class extended from ovm_stimulus_scenario should have an instance of class abc , which it should randomize. This class should have another user defined method similiar to apply_send which randomize the abc class but pass the elements of the item queue in it one by one to my driver.This method has to be called from body() task of this class.

Does this mean that the default implementation of the ovm_scenario* classes doesn't provide me the methods to directly write inter-related transaction constraints without over writting any of the methods in the base class as in vmm? If no, can you please show me a small example to use the ovm scenario generator for these type of constraints without over-writting any base class method except "body" of ovm_stimulus_scenario (since example directory for ovm doesn't provide any example for using scenario generator)?

Thanks ,
Amrutha

kurts
01-28-2008, 04:35 AM
Hi Amrutha,

If I could jump in, I think your original question is that you would like to send a series of transaction items where the randomized values in each item somehow depends on previous transactions. You also seem to have a requirement that you do not want to override any function except body() to do this.

It also looks like you are taking the approach of pre-generating all your items into an array, then using the body() method to loop through the items and send them. If I recall correctly, this is the kind of approach VMM uses. While this certainly is possible to do in OVM, I think you might be missing one of the design goals of scenarios - the ability to react to the current state of the simulation when building transaction items. When you pre-generate all your items, that kind of defeats their goal of building a transaction "just in time" when it is needed by the driver.

Back to your question, I'm not sure why you don't want to override the other functions, such as pre_apply() and mid_apply(). That is why they exist. They are meant to be user-accessible "hooks" into the process of randomizing and sending items to the driver. By default, they do nothing. They are there for you to take control over the creation of the item before it is sent. pre_apply is called before the item is randomized and mid_apply is called after randomization but before the item is sent. So, you could create variables in the scenario that maintain "state" or "memory" of what has transpired and set the item properties accordingly.

If you really don't want to use these functions, it is also possible to build in the "memory" of previous values right into the item randomization constraints themselves. For example, let's say you want to generate a random series of READ and WRITE transactions, with the constraint that the READ transactions only select values for addr that have already been used by previous WRITE transactions.

You could write something like this in your transaction class, and then you would not need pre_apply() or mid_apply():


class my_txn;
rand op_t mode; // Assume op_t is one of {READ, WRITE}
rand int unsigned addr;

static int unsigned addresses_used[$];

constraint use_prev_addr { mode == READ -> addr inside {addresses_used}; }

function void post_randomize();
if (mode == WRITE) addresses_used.push_back(addr);
endfunction
endclass

Does this help at all? Please forgive me if I misunderstood your question.

-Kurt

Amrutha
01-28-2008, 05:55 AM
Hi Kurt,
You understood my question correctly.Thanks for your reply.
But doesn't the code that you gave as an example correspond to "atomic generator " in vmm rather than "scenario generator" as here I have to store the values of previous fields to generate inter-related transactions. Can't I get the the same result/functionality by using an extension of ovm_random_stimulus rather than scenario generator?

I agree that If I follow the "memory" approach suggested by you, my scenario generator should work even without overwritting any methods in the base class, but I wanted to use it the way scenario generator is used in vmm (so that I don't need to store the fields of transaction in local variables), which I couldn't using the methods already provided.

I could achieve the desired functionality as suggested in my previous reply..but I wanted to know about a better approach ...:confused:


Thanks,
Amrutha