P_sequencer query

How the connection will be established between virtual sequence and sequence with p_sequencer(without using start method) in the task body and also how to constraint the values from virtual sequencer. Anyone please explain with some example if possible. Thanks in advance.

In reply to Chinnamunaiah:

It is recommended that you don’t use p_sequencer as this limits reuse of your code. Instead, assign sequencer handles directly to your virtual_sequence.

You can randomize and constrain values in a virtual_sequence the same as any other sequence. You will likely call randomize() on the sub-sequences as part of the body of the virtual_sequence.

In reply to cgales:

Thanks cgales for your reply. I have some doubts related to my code, I want to constraint values in sequence from the virtual sequence. But I am unable to constraint the values. If anyone knows how to do please explain me with an example. Thanks


//THIS IS MY SEQUENCE CLASS

class seq1 extends uvm_sequence#(transaction);
  `uvm_object_utils(seq1)
  
  //constructor
  
  task body;
    transaction req = transaction::type_id::create("req");
    repeat(10) begin
      `uvm_do_with(req,{req.a == a; req.b == b;})
    end
  endtask
endclass 


 //VIRTUAL SEQUENCE CLASS
  
  class virtual_seq extends uvm_sequence#(transaction);
     `uvm_object_utils(virtual_seq)
     `uvm_declare_p_sequencer(virtual_sequencer)
    
    seq1 s1;
    
    //constructor
    
    task body;
     s1 = seq1::type_id::create("s1"); 
      `uvm_do_on_with(s1, seqr_h.p_sequencer,{s1.a == 5; s1.b == 10; } )
    endtask
  endclass 

In reply to Chinnamunaiah:

Please use code tags. I have added them for you.

It is also helpful to provide a complete example which demonstrates your issues.

You don’t mention what problem you are seeing in a clear manner. Being “unable to constrain the values” isn’t clear. Do you have a syntax error? Are the values not randomized correctly? What values do you expect and what values are you getting?

There are several issues which likely contribute to your difficulties.

  • Don’t use `uvm_do_* macros. They mask issues and can make debugging difficult.
  • When you randomize a class which has variables with the same name as the parent class, scoping is critical. See section 18.7.1 of the LRM.

See if the following helps:


// Transaction class
class transaction extends uvm_sequence_item;
  rand int a;
  rand int b;
endclass

//THIS IS MY SEQUENCE CLASS
class seq1 extends uvm_sequence#(transaction);
  `uvm_object_utils(seq1)
  rand int a;
  rand int b;

  //constructor
 
  task body;
    repeat(10) begin
      req = transaction::type_id::create("req");
      start_item(req);
      if (!req.randomize() with {a == local::a; b == local::b;}) begin
        `uvm_error(get_name(), "Error randomizing req");
      end
      finish_item(req);
    end
  endtask
endclass

//VIRTUAL SEQUENCE CLASS
class virtual_seq extends uvm_sequence#(uvm_sequence_item);
  `uvm_object_utils(virtual_seq)

  seq1 s1;
  seq1_sequencer s1_sqr; // NOTE: Assign handle prior to starting sequence

  //constructor
 
  task body;
    if (s1_sqr == null) begin
      `uvm_fatal(get_name(), "s1_sqr is null");
    end
    s1 = seq1::type_id::create("s1");
    if (!s1.randomize() with {a == 5; b == 10;}) begin
      `uvm_error(get_name(), "Unable to randomize sequence seq1");
    end
    s1.start(s1_sqr);
  endtask
endclass

In reply to cgales:

Thanks for your reply cgales. I followed the same steps as you mentioned above and also created memory for s1_sqr inside the task body. But I am getting fatal error showing “s1_sqr is null”. could you please guide me how to proceed further. Thanks.

In reply to Chinnamunaiah:

You need to assign the appropriate sequencer handle after creating the virtual sequence and prior to starting it. This is likely done in your test, and the sequencer handle assigned is from the appropriate agent associated with ‘transaction’.