Randomizing an array of transactions

Hi,
I am a newbie with UVM/SV. I have a simple sequence_item with 2 random int variables. I am instantiating a dynamic array of the sequence_item in my sequence. Now I want to constrain the sequence_item in such a way that the random variables inside should not be the same. Below code gives run time Fatal error when it reaches the mentioned line. Solutions appreciated.

class my_transaction extends uvm_sequence_item;
rand int a;
rand int b;
– registered with factory and added field macros here –
endclass

class my_sequence extends uvm_sequence_item;
rand my_transaction items;
constraint c_txn {
items.size>0 && items.size<=10;
foreach(items[i]) {
items[i].ina != items[i].inb[1]; // FATAL ERROR on this line
}
}
endclass

=================================================

Transcript of log:

    items[i].ina != items[i].inb[1];
        |

ncsim: *E,RNDCNSTE (…/…my_seq_lib.sv,34|12): Randomization constraint has this error, which will cause the randomize function to return 0 and no new rand values will be set:
Null handle references in constraints are not supported.
if (!seq.do_not_randomize && !seq.randomize()) begin
|
ncsim: *W,SVRNDF (/tools/cadence/INCISIV14.10-s014/Linux/tools/methodology/UVM/CDNS-1.1d/sv/src/seq/uvm_sequencer_base.svh,1398|46): The randomize method call failed.
Observed simulation time : 0 FS + 99
UVM_FATAL /tools/cadence/INCISIV14.10-s014/Linux/tools/methodology/UVM/CDNS-1.1d/sv/src/seq/uvm_sequencer_base.svh(1400) @ 0: uvm_test_top.sa_env.sa_agent.sequencer [STRDEFSEQ] Randomization failed for default sequence ‘my_sequence’ for phase ‘main’

=======================================================

thanks
myashu

The randomize method will never construct class objects for you. You need to construct your array of items before calling randomize() or using the pre_randomize() method. The array needs to be as large as your constraints will allow, and the array size will get trimmed down to the size determined during randomization.

In reply to dave_59:

Thanks Dave,
Yes I need to add a pre_randomize() and create all the transactions in a foreach loop such that the number of created transactions are not less than the items.size() mentioned in the constraint block. I was able to contrain the variables of the transaction class with this.

thanks
Myashu

In reply to dave_59:

Can you help me with an example to implement an array of transactions?

In reply to Mohammed Essam Abd El Samee:

my_transaction tr[];
 
tr = new[5];
foreach(tr[ii]) begin 
    tr[ii] = my_transaction::type_id::create("tr");
    if (!tr[ii].randomize) `uvm_error()
   end

In reply to dave_59:

Thanks very much.

Hi Dave,

can you please let me know what will be the order of solving this array of objects. is it sequential? or parallel or random.

For example :-

typedef uvm_object temp1;
rand temp1 tr[10];

Will tr[0] solved first and then tr[1] solved later?

Thank you,
Sasi kiran

Without any constraints between the elements, the order does not matter. When there is a constraint connecting the elements, they are solved simultaniously. This is true for all random variables as well as elements of an unpacked array.