Randomization Flashcards

1
Q

Why CRT

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

CRT requirements

A

-Random variable
-Constraints to control random stimulus
-Reference model
-Seed to PRNG

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Coverpoint outside class ??

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is to be randomized

A

-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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Constraint and use

A

-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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Sample randomization value

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Randomization failure

A

-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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How random values are generated?

A

-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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Nested random classes

A

-When we have nested random classes, parent class randomization calls sub-class randomization(if child class obj is declared as rand)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What can be randomized

A

-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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Constraint in non-random value

A

When randomize is called, it fails if var doesnt satisfy constraint condition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

If I want add priority of random values

A

-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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How to generate values of specific value

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Conditional contraints

A
  • 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]};
}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Prioritize constraints

A
  • Constraints are procedural/bidirectionals
  • All are active/evaluated in parallel, no sequential
  • We can order them if needed, using :: solve <> before <>;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Probability of each value
rand bit x;
rand bit[1:0] y;
constraint c { (x==0) -> (y==0); }

A
  • (x,y) :
    (0,0) = 1/2
    (1,0) = 1/8
    (1,1) = 1/8
    (1,2) = 1/8
    (1,3) = 1/8
17
Q

Probability of each value
rand bit x;
rand bit[1:0] y;
constraint c {
y > 0;
(x==0) -> (y==0);
}

A
  • (x,y) :
    (1,1) = 1/3
    (1,2) = 1/3
    (1,3) = 1/3
18
Q

Probability of each value
rand bit x;
rand bit[1:0] y;
constraint c {
(x==0) -> (y==0);
solve x before y;
}

A
  • (x,y) :
    (0,0) = 1/2
    (1,0) = 1/8
    (1,1) = 1/8
    (1,2) = 1/8
19
Q

Probability of each value
rand bit x;
rand bit[1:0] y;
constraint c {
(x==0) -> (y==0);
solve y before x;
}

A
  • (x,y) :
    (0,0) = 1/8
    (1,0) = 1/8
    (1,1) = 1/4
    (1,2) = 1/4
    (1,3) = 1/4
20
Q

Controlling randomness

A

-Enable/disable constraints
handle.constraint_mode(0); : OFF
handle.constraint_mode(1); : ON

handle.constraint.constraint_mode(0); : OFF
handle.constraint.constraint_mode(1); : ON

Randomization here ignored rules

-Disable variable randomness
obj.var.rand_mode(0) : OFF
obj.var.rand_mode(1) : ON

-Selective randomization
obj.randomize(var); // doesnt randomize remaining rand variables

-Check correctness of override
obj.randomize(null);
//doesnt randomize whole obj. Just check if rules hold good for current var values

21
Q

Inline constraints

A
  • Variables use scope of callee, not the caller

p.randomize() with { addr[1:0] == 0; ; data!=0; };

22
Q

Pre/Post randomize

A
  • function void pre_randomize() {};
  • function void post_randomize() {};
23
Q

Random number funcions

A

$random : 32-bit signed
$urandom : 32-bit unsigned
$urandom_range : number over range/max value if one is providedl
here min,max is inclusive. If no mix mentioned, 0 is default min

24
Q

External constraint

A

-Like extern functions, we declare constraint name in cls
-User can define constraint on need basis
-If undefined, SV behavior based on compiler

class pkt;
logic[7:0] addr;
constraint ext_addr;
endclass

module top;
constraint pkt::ext_addr {
addr[1:0] == 0;
}
inital begin
pkt p1=new();
assert(p1.randomize());
end
endmodule

25
Q

Inline vs external

A

-Inline : Pros
** Every invokation rules can be unique
** Flexible
-Inline : Cons
** No reusability, every randomization needs full inline constraint definition

-External : Pros
** Helps in extending exisiting constraint
** Reusable for all objs, post definition

26
Q

Extended class constraints

A

-Incase constraint name matches parent class constraint name, base version is overwritten

27
Q

Program to generate rand int list, whose sum does not exceed 1024
(recheck)

A

class d_class;
rand int unsigned d_arr[];

constraint cnt_c {
d_addr.size == 5;
(d_addr.sum < 35’d1024);
}
endclass

28
Q

Program to generate a dyn arry, which has only 4 strbs

A
29
Q

Generate a array on ascending numbers

A

class asc_num;
unsigned int u_arr[];

constraint u_arr_c {
u_arr.size() inside {[2:10]};
foreach(u_arr[i]) {
if(i>0) {
u_arr[i] > u_arr[i-1];
}
}
}

30
Q

Generate a array of unique values

A
31
Q

Generate a random configuration sequence

A

-Consider a case, where we want to generate a sequence as W/R/R/W/R/W
-Here we have to call same seq multuple times with different orderining.
-randc is not applicable as we do not want to sweep all values before repeatation

-Maintain history
**In post_randomization, capture the current handomization history
**Subsquent calls show randomize based on prev history

-Use randsequence:
**This doesnt even need class randomization
**We mention a scnerio in BNF

32
Q

Example of random BNF sequence

A
initial begin

  randsequence(any_stream);
    any_stream :  p1:=10 | p2:=30;
	p1 :  { func_p1(); } | { func_p1();} | p1;
	p2 :  { func_p2(); } | { func_p2();} | p2;
  endsequence

end
33
Q

Example of randcase

A

initial begin
int i;
randcase
10 : len=10;
20 : len=50;
endcase
end

34
Q

Randcase vs Randsequence

A

-Randsequence : It supports re-entry., branches can loop
-Randcase : It doesnt support re-entry. Thrds do not overlap randsame

35
Q

Explain a TB env whcih has rand config class

A