m_sequencer vs p_sequencer in UVM: What’s the Difference?
In short: m_sequencer and p_sequencer point to the same sequencer. The difference is the type of the handle. m_sequencer is a uvm_sequencer_base handle that every sequence gets when it starts, and it’s enough to send items. p_sequencer is a handle of your own sequencer class, added by the `uvm_declare_p_sequencer macro, so a sequence can reach fields that only your sequencer has. Both are set when the sequence starts, never before.
When you first see m_sequencer and p_sequencer in the same file, it’s natural to think they are two different objects.
They aren’t.
It’s one sequencer, seen through two handles. One handle only knows “this is some sequencer”. The other knows exactly which class it is.
This lesson runs both on one small bench on Synopsys VCS, prints what each handle points to, and then breaks it two ways so you can see the errors for real.
By the end of this lesson, you’ll be able to:
- Explain what
m_sequencerandp_sequencerare, and why they point to the same object. - Use
`uvm_declare_p_sequencerto read a field from your own sequencer. - Do the same cast by hand, and use
p_sequencerinside a virtual sequence. - Recognise the
DCLPSQfatal and the null object access error, and fix both.
The picture: a universal remote and the brand remote
Think of a TV in your living room.
A universal remote works on any TV. Power, volume, channel up. That’s all it knows, because it has no idea which brand it’s pointed at.
The remote that came in the box has the same buttons, plus the special ones only this TV has: the settings menu, the picture modes.
It’s the same TV either way. Only the remote is different.
| At home | In UVM | What it means |
|---|---|---|
| The TV | Your sequencer object | One object, whichever handle you use |
| The universal remote | m_sequencer | Type uvm_sequencer_base. Enough to send items |
| The brand remote | p_sequencer | Your sequencer’s own class. Reaches its fields |
| Checking the brand before using its remote | $cast inside the macro | Makes sure the sequencer really is that class |
| A brand remote pointed at the wrong TV | Started on the wrong sequencer type | The cast fails, UVM stops with a fatal |
| Pressing buttons before the TV is in the room | Reading p_sequencer before start() | The handle is still null |
| A hub remote holding the TV and soundbar remotes | A virtual sequencer | A sequence reaches real sequencers through it |
Keep this picture in mind. Every run below is one of these rows.
What m_sequencer is
Every sequence has m_sequencer. You don’t declare it. It’s a member of uvm_sequence_item, the base class of every sequence.
When you call seq.start(sqr), UVM stores sqr in m_sequencer. Its type is uvm_sequencer_base, so it knows how to arbitrate and pass items to the driver, and nothing about your own class.
That’s all `uvm_do and start_item() / finish_item() need. Most sequences never touch it directly.
What p_sequencer is
p_sequencer doesn’t exist until you ask for it with one macro:
class burst_seq extends uvm_sequence #(bus_item);
`uvm_object_utils(burst_seq)
`uvm_declare_p_sequencer(bus_sqr) // adds: bus_sqr p_sequencer;
...
task body();
repeat (p_sequencer.max_burst) `uvm_do(req) // a field only bus_sqr has
endtask
endclass
The macro does two things. It declares a handle of your sequencer’s class:
bus_sqr p_sequencer;
And it overrides a small function UVM calls when the sequence starts. That function casts m_sequencer into p_sequencer, and stops the test if the cast fails:
virtual function void m_set_p_sequencer();
super.m_set_p_sequencer();
if (!$cast(p_sequencer, m_sequencer))
`uvm_fatal("DCLPSQ", ... "Error casting p_sequencer, please verify that this sequence/sequence item is intended to execute on this type of sequencer")
endfunction
That’s the whole trick. p_sequencer is m_sequencer, cast to your class, done for you at start.
Side by side
m_sequencer | p_sequencer | |
|---|---|---|
| Declared by | UVM, in every sequence | You, with `uvm_declare_p_sequencer |
| Type | uvm_sequencer_base | Your sequencer class |
| Points to | The sequencer you started on | The same sequencer |
| Set when | start() is called | start() is called, by a $cast |
| Reaches your custom fields | No | Yes |
| Needed to send items | It’s what UVM uses | No |
| Ties the sequence to one sequencer class | No | Yes |
The last row is the trade-off. A sequence that uses p_sequencer can only run on that sequencer class, or a class derived from it. Use it when you need what’s inside the sequencer, not by habit.
Five runs, one bench
The bench is small on purpose. One sequencer class, bus_sqr, has a field called max_burst. The test sets it to 4. A sequence wants to read that field to decide how many items to send.
There’s also a second sequencer class, other_sqr, for the same item type, and a virtual sequencer, top_vsqr, that holds a handle to the real one. The test starts sequences five ways, chosen with +MODE=.
Real output, Synopsys VCS X-2025.06-SP1 with UVM 1.2:
| Run | What it does | Result | Items driven |
|---|---|---|---|
clean | macro, reads p_sequencer.max_burst | both handles name uvm_test_top.sqr, “same object? yes” | 4 |
manual_cast | $cast on m_sequencer by hand | “cast worked: my_sqr.max_burst = 4” | 4 |
vseq | virtual sequence uses p_sequencer.bus | burst runs on the real sequencer | 4 |
wrong_sqr | started on other_sqr | UVM_FATAL [DCLPSQ] at 0 ns | 0 |
too_early | test reads p_sequencer before start() | Error-[NOA] Null object access, simulation stops | 0 |
clean: one sequencer, two handles
UVM_INFO @ 0: uvm_test_top.sqr@@s [SEQ] m_sequencer = uvm_test_top.sqr (type bus_sqr)
UVM_INFO @ 0: uvm_test_top.sqr@@s [SEQ] p_sequencer = uvm_test_top.sqr (type bus_sqr)
UVM_INFO @ 0: uvm_test_top.sqr@@s [SEQ] same object? yes
UVM_INFO @ 0: uvm_test_top.sqr@@s [SEQ] p_sequencer.max_burst = 4, sending that many items
UVM_INFO @ 10: uvm_test_top.drv [DRV] item 1: data='h7f
UVM_INFO @ 20: uvm_test_top.drv [DRV] item 2: data='h18
UVM_INFO @ 30: uvm_test_top.drv [DRV] item 3: data='h2b
UVM_INFO @ 40: uvm_test_top.drv [DRV] item 4: data='hd3
Look at the first two lines. Same name, same type. Even m_sequencer reports bus_sqr, because get_type_name() is virtual and asks the real object. The third line compares the two handles directly, and they’re equal.
So why can’t you just write m_sequencer.max_burst? Because the compiler only looks at the handle’s type, uvm_sequencer_base, and that class has no max_burst. The object has the field. The handle can’t see it. That’s the whole reason p_sequencer exists.
manual_cast: what the macro does for you
UVM_INFO @ 0: uvm_test_top.sqr@@s [SEQ] cast worked: my_sqr.max_burst = 4
No macro, same result, same 4 items. A local bus_sqr handle and one $cast from m_sequencer is all p_sequencer really is. The macro just saves you writing it in every sequence, and does it at start.
vseq: where p_sequencer earns its keep
UVM_INFO @ 0: uvm_test_top.vsqr@@v [VSEQ] running on uvm_test_top.vsqr, starting burst_seq on p_sequencer.bus = uvm_test_top.sqr
UVM_INFO @ 0: uvm_test_top.sqr@@s [SEQ] same object? yes
A virtual sequencer drives nothing. It just holds handles to real sequencers. The virtual sequence uses p_sequencer.bus to find the real one and start a sequence there. This is the most common real use of p_sequencer you’ll see on a project.
For the full pattern on a bench with three agents (the virtual sequencer, the env wiring and the virtual sequences, all in one place), see my UVM virtual sequence guide.
wrong_sqr: the cast fails, UVM stops
UVM_FATAL testbench.sv(65) @ 0: uvm_test_top.osqr@@s [DCLPSQ] $unit::\burst_seq::m_set_p_sequencer uvm_test_top.osqr.s Error casting p_sequencer, please verify that this sequence/sequence item is intended to execute on this type of sequencer
other_sqr handles the same item type, so the sequence could have sent items through it. But burst_seq declared that its p_sequencer is a bus_sqr, and other_sqr isn’t one. The cast inside the macro failed at time 0, before a single item went out. The message even names the function, m_set_p_sequencer, which is the one the macro adds.
too_early: the handle doesn’t exist yet
Error-[NOA] Null object access
testbench.sv, 175
The object at dereference depth 1 is being used before it was
constructed/allocated.
#0 in \sqr_test::run_phase at testbench.sv:175
The test created the sequence and read s.p_sequencer.max_burst before calling start(). At that point p_sequencer is still null. This isn’t a UVM message at all. VCS stopped the simulation, with no UVM report summary. Line 175 is the line that read p_sequencer.
Back to the TV: clean and vseq are the brand remote on the right TV. manual_cast is checking the label on the back of the TV yourself before picking up its remote. wrong_sqr is the brand remote pointed at a different TV. It has the right buttons for some TV, just not this one. And too_early is pressing buttons before the TV is even in the room.
Here’s the whole idea in one picture.
Common mistakes, with fixes
Reading p_sequencer before start(). The handle is null until start() runs, so VCS stops with Error-[NOA] Null object access.
- Fix A: only use
p_sequencerinsidepre_start(),body()or later. - Fix B: if the test needs a sequencer setting, read it from the sequencer itself, not through a sequence that hasn’t started.
Starting the sequence on the wrong sequencer type. UVM_FATAL [DCLPSQ] at time 0.
- Fix: start it on the class named in
`uvm_declare_p_sequencer, or a class derived from it. If the sequence must run on several sequencer types, don’t usep_sequencerin it.
Using p_sequencer when m_sequencer is enough. A sequence that only sends items doesn’t need it, and the macro ties it to one sequencer class for no reason.
- Fix: add the macro only when the sequence reads something that lives in your sequencer.
Turning the sequencer into a junk drawer. Every config value, handle and flag goes into the sequencer so sequences can grab it through p_sequencer.
- Fix: put settings in a config object and pass it with
uvm_config_db. Keep the sequencer for what belongs there, like handles to sub-sequencers in a virtual sequencer.
Expecting m_sequencer.my_field to compile. It won’t, even though the object has the field. The compiler only sees the uvm_sequencer_base handle type.
- Fix: use
p_sequencer, or$castto a local handle of your class and check the result.
How AI helps (and where it doesn’t)
- Explaining a DCLPSQ fatal. Paste the message and your sequence. An assistant will usually spot that the sequence was started on a different sequencer class than the one in the macro.
- Reviewing sequences. Ask: “Which of these sequences use p_sequencer but don’t need it?” It’s a quick way to find sequences that are tied to one sequencer for no reason.
- Writing a virtual sequence. Ask for a virtual sequencer with handles to your real sequencers, and a virtual sequence that uses
p_sequencerto start sub-sequences. Then check every handle is assigned inconnect_phase.
Where to be careful: assistants often add `uvm_declare_p_sequencer to every sequence by habit, and some write m_sequencer.my_field, which doesn’t compile. And only a run shows whether your cast really succeeds.
Don’t paste confidential code or logs into public tools. Use what your company has approved. For the bigger picture, read AI in ASIC verification.
Interview questions
These come up a lot in UVM interviews. Try answering each one before reading the answer.
- Are m_sequencer and p_sequencer different objects? No. They point to the same sequencer. In our run, both printed
uvm_test_top.sqrand the handles compared equal. Only the handle type is different. - What does
uvm_declare_p_sequenceractually do? It declares a handle of your sequencer class calledp_sequencer, and overridesm_set_p_sequencer()to$castm_sequencerinto it when the sequence starts. If the cast fails, it raisesUVM_FATAL [DCLPSQ]. - When is p_sequencer null? Before the sequence starts. It’s set during
start(), so reading it from the test beforestart()gives a null object access. - Why not always use p_sequencer? It ties the sequence to one sequencer class. A sequence that only sends items doesn’t need it, and stays reusable without it.
- Where do you most often see p_sequencer on a real project? In virtual sequences, to reach the real sequencers held by a virtual sequencer.
Practice challenge
Take the full code below and try this:
- Add a second real sequencer class,
irq_sqr, with its own driver. - Add an
irqhandle totop_vsqr, and assign it inconnect_phase. - In
top_vseq, start a sequence onp_sequencer.busand another onp_sequencer.irq, in parallel withfork ... join.
You’ll know it works when both drivers print their items in the same run and there are no errors. Then comment out the vsqr.irq = ... line. What does VCS print, and at which line?
Frequently asked questions
What is the difference between m_sequencer and p_sequencer?
Both point to the same sequencer. m_sequencer is a uvm_sequencer_base handle every sequence has. p_sequencer is a handle of your own sequencer class, so it can reach your sequencer’s fields.
Do I need p_sequencer to send items?
No. `uvm_do and start_item() / finish_item() work through m_sequencer. You only need p_sequencer to read something that only your sequencer has.
What does the DCLPSQ error mean?
The sequence was started on a sequencer that isn’t the class named in `uvm_declare_p_sequencer, so the cast failed. Start it on the right sequencer class.
Why is p_sequencer null?
The sequence hasn’t started yet. p_sequencer is set when start() runs. Read it in body(), not in the test before start().
Can I use p_sequencer in a virtual sequence?
Yes, and that’s its most common use. The virtual sequence’s p_sequencer is the virtual sequencer, which holds handles to the real sequencers.
Is p_sequencer bad practice?
No, but use it only when needed. For settings, a config object passed through uvm_config_db keeps sequences reusable across sequencers.
Full code
One file: two sequencer classes, a virtual sequencer, three sequences, a driver and a test that starts them five ways. On EDA Playground choose Synopsys VCS and UVM 1.2, set the top module to top, and run once per +MODE= option.
// p_sequencer_demo.sv : m_sequencer vs p_sequencer, five runs, one bench
// The Art of Verification | theartofverification.com
//
// Run options (one per run):
// +MODE=clean a sequence with `uvm_declare_p_sequencer reads a field from its sequencer
// +MODE=manual_cast the same, done by hand with $cast on m_sequencer (what the macro does for you)
// +MODE=vseq a virtual sequence uses p_sequencer to reach the real sequencer
// +MODE=wrong_sqr the sequence is started on a sequencer of the wrong type
// +MODE=too_early the test reads p_sequencer before the sequence has started
//
// Run on Synopsys VCS X-2025.06-SP1 with UVM 1.2 (EDA Playground), 23 Nov 2026.
`timescale 1ns/1ns
`include "uvm_macros.svh"
import uvm_pkg::*;
string MODE = "clean";
class bus_item extends uvm_sequence_item;
rand bit [7:0] data;
`uvm_object_utils(bus_item)
function new(string name = "bus_item");
super.new(name);
endfunction
endclass
// Our sequencer carries a field that a sequence wants to read
class bus_sqr extends uvm_sequencer #(bus_item);
`uvm_component_utils(bus_sqr)
int max_burst = 3; // the test changes this to 4
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
endclass
// Another sequencer for the same item type, but a different class
class other_sqr extends uvm_sequencer #(bus_item);
`uvm_component_utils(other_sqr)
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
endclass
// A virtual sequencer: no driver, just handles to the real sequencers
class top_vsqr extends uvm_sequencer;
`uvm_component_utils(top_vsqr)
bus_sqr bus;
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
endclass
// Uses the macro: p_sequencer is a bus_sqr handle
class burst_seq extends uvm_sequence #(bus_item);
`uvm_object_utils(burst_seq)
`uvm_declare_p_sequencer(bus_sqr)
function new(string name = "burst_seq");
super.new(name);
endfunction
task body();
uvm_sequencer_base as_base = p_sequencer;
`uvm_info("SEQ", $sformatf("m_sequencer = %s (type %s)", m_sequencer.get_full_name(), m_sequencer.get_type_name()), UVM_NONE)
`uvm_info("SEQ", $sformatf("p_sequencer = %s (type %s)", p_sequencer.get_full_name(), p_sequencer.get_type_name()), UVM_NONE)
`uvm_info("SEQ", $sformatf("same object? %s", (as_base == m_sequencer) ? "yes" : "no"), UVM_NONE)
`uvm_info("SEQ", $sformatf("p_sequencer.max_burst = %0d, sending that many items", p_sequencer.max_burst), UVM_NONE)
repeat (p_sequencer.max_burst) `uvm_do(req)
endtask
endclass
// No macro: the same thing by hand
class cast_seq extends uvm_sequence #(bus_item);
`uvm_object_utils(cast_seq)
function new(string name = "cast_seq");
super.new(name);
endfunction
task body();
bus_sqr my_sqr;
if (!$cast(my_sqr, m_sequencer))
`uvm_fatal("CAST", "m_sequencer is not a bus_sqr")
`uvm_info("SEQ", $sformatf("cast worked: my_sqr.max_burst = %0d", my_sqr.max_burst), UVM_NONE)
repeat (my_sqr.max_burst) `uvm_do(req)
endtask
endclass
// A virtual sequence: p_sequencer is the virtual sequencer
class top_vseq extends uvm_sequence;
`uvm_object_utils(top_vseq)
`uvm_declare_p_sequencer(top_vsqr)
function new(string name = "top_vseq");
super.new(name);
endfunction
task body();
burst_seq s = burst_seq::type_id::create("s");
`uvm_info("VSEQ", $sformatf("running on %s, starting burst_seq on p_sequencer.bus = %s",
p_sequencer.get_full_name(), p_sequencer.bus.get_full_name()), UVM_NONE)
s.start(p_sequencer.bus);
endtask
endclass
class bus_driver extends uvm_driver #(bus_item);
`uvm_component_utils(bus_driver)
int sent;
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
task run_phase(uvm_phase phase);
forever begin
seq_item_port.get_next_item(req);
#10;
sent++;
`uvm_info("DRV", $sformatf("item %0d: data='h%02h", sent, req.data), UVM_NONE)
seq_item_port.item_done();
end
endtask
endclass
class sqr_test extends uvm_test;
`uvm_component_utils(sqr_test)
bus_sqr sqr;
other_sqr osqr;
top_vsqr vsqr;
bus_driver drv;
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
sqr = bus_sqr::type_id::create("sqr", this);
osqr = other_sqr::type_id::create("osqr", this);
vsqr = top_vsqr::type_id::create("vsqr", this);
drv = bus_driver::type_id::create("drv", this);
sqr.max_burst = 4;
endfunction
function void connect_phase(uvm_phase phase);
drv.seq_item_port.connect(sqr.seq_item_export);
vsqr.bus = sqr; // the virtual sequencer gets its handle here
endfunction
task run_phase(uvm_phase phase);
phase.raise_objection(this);
case (MODE)
"clean": begin
burst_seq s = burst_seq::type_id::create("s");
s.start(sqr);
end
"manual_cast": begin
cast_seq s = cast_seq::type_id::create("s");
s.start(sqr);
end
"vseq": begin
top_vseq v = top_vseq::type_id::create("v");
v.start(vsqr);
end
"wrong_sqr": begin
burst_seq s = burst_seq::type_id::create("s");
s.start(osqr); // other_sqr is not a bus_sqr
end
"too_early": begin
burst_seq s = burst_seq::type_id::create("s");
`uvm_info("TEST", $sformatf("max_burst before start: %0d", s.p_sequencer.max_burst), UVM_NONE)
s.start(sqr);
end
default: `uvm_fatal("MODE", {"unknown +MODE=", MODE})
endcase
phase.drop_objection(this);
endtask
function void report_phase(uvm_phase phase);
`uvm_info("END", $sformatf("MODE=%s items driven=%0d at %0t", MODE, drv.sent, $time), UVM_NONE)
endfunction
endclass
module top;
initial begin
void'($value$plusargs("MODE=%s", MODE));
`uvm_info("TOP", {"Running with MODE=", MODE}, UVM_NONE)
run_test("sqr_test");
end
endmodule
References
- Accellera UVM downloads and class reference
- IEEE 1800.2 standard for UVM (this lesson runs on UVM 1.2)
Read next
- UVM sequencer and driver communication
- UVM Testbench Architecture
- uvm_config_db and uvm_resource_db
- How UVM Phasing Is Triggered (lesson 17)
Part of the learning path UVM methodology
