Randomization Flashcards
Why CRT
Why CRT
-With large designs, challenging to write directed tests to cover all features
-Solution : Auto generated constrained-random tests(CRT)
-Pros :
*Efficient
*Detects unanticipated bugs
-Cons :
*Bringup complexity
**Directed tests have defined test suite, known input/output pair
**For CRT, we need to have a reference model, that predicts expected output for a random input)
CRT requirements
-Random variable
-Constraints to control random stimulus
-Reference model
-Seed to PRNG
Coverpoint outside class ??
class transaction;
rand bit[7:0] addr;
rand bit[31:0] data;
endclass
covergroup cg_tran; coverpoint tr.addr; endgroup module top; initial begin transaction tr; tr = new(); cg_tran = new(); for(int i=0;i<100;i++) begin tr.randomize(); cg_trans.sample(); end end endmodule : top
What is to be randomized
-Device configuration
*config combinations
-Environment configuration
*active masters/slaves combinations
-Primary input data
-Encapsulated input data
*Multilayer stimulus, nested simulus classes
-Delays
*Responses,clk jitter
-Protocol exceptions,errors,violations
*Injection of failures
Constraint and use
-If DUT’s valid stimulus cannot be a random value
-Constraints set rules to limit the random values to legal values
-A constraint is set of relational expressions that must be true for the chosen value of the variables.
Sample randomization value
class Packet;
rand bit [31:0] src, dst, data[8];
randc bit [7:0] kind;
constraint c {src > 10;
src < 15;}
endclass
Packet p;
initial begin
p = new();
assert (p.randomize())
else $fatal(0, “Packet::randomize failed”);
transmit(p);
end
Randomization failure
-Returns 0 for FAIL
-Returns 1 for SUCCESS
if(!p.randomize())
$fatal(0, “Packet::randomize failed”);
(or)
assert (p.randomize()) else $fatal(0, “Packet::randomize failed”);
(or)
assert (p.randomize());
How random values are generated?
-User writes constraints
-SV’s PRNG (which takes seed as input) generates random values
-Constraint random solver : Evaluates constraints and picks valid values from generated random values
NOTE : PRNG only generates 2-state values
-So when we declare 4-state random variable, only 2-state values are assigned
Nested random classes
-When we have nested random classes, parent class randomization calls sub-class randomization(if child class obj is declared as rand)
What can be randomized
-Fixed sized : integral/packed array/enum/struct/bit
-Dynamic sized : If len is not constrainted : empty array
If len is constrainted : array/queue is created and randomized
-String : Cannot be randomized
-Handles :
**Randomization cannot create objects. They have to created
-Handle/handle array/queue/Dynmic array
**Each inst has to be created/newed
**If declared rand, parent randomization, applies to handle
Constraint in non-random value
When randomize is called, it fails if var doesnt satisfy constraint condition
If I want add priority of random values
-We can use WEIGHTED DISTRIBUTION to choose few random values more frequently.
- := ( nth member wt == total wt )
- :/ ( nth member wt == total wt/n)
- Randc variables cannot be used with weighted distribution
-
int wt1=11,wt2=22,wt3=22,wt4=44;
constraint c{
val1 dist { 1:=wt1, [2:3]:=wt2; };
}
constraint c{
val2 dist { 1:/wt3, [2:3]:/wt4; };
}
How to generate values of specific value
class v_class;
unsigned int v_arr1[] = ‘{ 6,15,8,12 };
unsigned int v_arr2[] = ‘{ 120,130 };
unsigned int v_val;
constraint c {
v_val inside { [$:2], v_arr1, [100:150] };
!(v_val inside { v_arr2 });
}
endclass
Conditional contraints
- We can use implication/if conditions for enabling constraints
constraint c1{
(unaligned_addr==1) -> addr[1:0] inside {[1:3]};
}
constraint c1{
if(unaligned_addr==1)) {
addr[1:0] inside {[1:3]};
}
}
Prioritize constraints
- Constraints are procedural/bidirectionals
- All are active/evaluated in parallel, no sequential
- We can order them if needed, using :: solve <> before <>;