fvutils / pyvsc

Python packages providing a library for Verification Stimulus and Coverage
https://fvutils.github.io/pyvsc
Apache License 2.0
113 stars 26 forks source link

Value not randomizing with solve_order constraint #49

Closed ShraddhaDevaiya closed 3 years ago

ShraddhaDevaiya commented 3 years ago

Hello @mballance , I am using solve_order for our following use-case, but with this it is not randomizing value of num_of_nested_loop variable.

import vsc
from enum import Enum,auto

@vsc.randobj
class riscv_instr:
    def __init__(self):
        self.temp = vsc.rand_uint8_t()

class my_e(Enum):
    A = 0
    B = auto()
    C = auto()
    D = auto()
    E = auto()
    F = auto()
    G = auto()

@vsc.randobj
class riscv_loop_instr:
    def __init__(self):
        self.loop_cnt_reg = vsc.randsz_list_t(vsc.enum_t(my_e))
        self.loop_limit_reg = vsc.randsz_list_t(vsc.enum_t(my_e))
        self.loop_init_val = vsc.randsz_list_t(vsc.uint32_t())
        self.loop_step_val = vsc.randsz_list_t(vsc.uint32_t())
        self.loop_limit_val = vsc.randsz_list_t(vsc.uint32_t())
        self.num_of_nested_loop = vsc.rand_bit_t(3)
        self.num_of_instr_in_loop = vsc.rand_uint32_t()
        self.branch_type = vsc.randsz_list_t(vsc.enum_t(my_e))

    @vsc.constraint
    def legal_loop_regs_c(self):
        vsc.solve_order(self.num_of_nested_loop, self.loop_init_val)
        vsc.solve_order(self.num_of_nested_loop, self.loop_step_val)
        vsc.solve_order(self.num_of_nested_loop, self.loop_limit_val)
        vsc.solve_order(self.loop_limit_val, self.loop_limit_reg)
        vsc.solve_order(self.branch_type, self.loop_init_val)
        vsc.solve_order(self.branch_type, self.loop_step_val)
        vsc.solve_order(self.branch_type, self.loop_limit_val)
        self.num_of_instr_in_loop.inside(vsc.rangelist((1, 25)))
        self.num_of_nested_loop.inside(vsc.rangelist(1, 2))
        self.loop_init_val.size == self.num_of_nested_loop
        self.loop_step_val.size == self.num_of_nested_loop
        self.loop_limit_val.size == self.num_of_nested_loop
        self.loop_init_val.size == self.num_of_nested_loop
        self.branch_type.size == self.num_of_nested_loop
        self.loop_step_val.size == self.num_of_nested_loop
        self.loop_limit_val.size == self.num_of_nested_loop
        self.branch_type.size == self.num_of_nested_loop

    @vsc.constraint
    def loop_c(self):
        vsc.solve_order(self.num_of_nested_loop, self.loop_cnt_reg)
        vsc.solve_order(self.num_of_nested_loop, self.loop_limit_reg)
        self.loop_cnt_reg.size == self.num_of_nested_loop
        self.loop_limit_reg.size == self.num_of_nested_loop

obj = riscv_loop_instr()
for i in range(5):
    obj.randomize()
    print(obj.num_of_nested_loop)

For this code, it is giving an output like following:

-- push_constraint_stmt
-- push_constraint_stmt
-- push_constraint_stmt
-- push_constraint_stmt
-- push_constraint_stmt
-- push_constraint_stmt
-- push_constraint_stmt
-- push_constraint_stmt
0
0
0
0
0

As we can see, it is giving num_of_nested_loop = 0 every time. Can you please help, if I missed something in this? And if I comment following lines:

vsc.solve_order(self.num_of_nested_loop, self.loop_init_val)
vsc.solve_order(self.num_of_nested_loop, self.loop_step_val)
vsc.solve_order(self.num_of_nested_loop, self.loop_limit_val)

vsc.solve_order(self.num_of_nested_loop, self.loop_cnt_reg)
vsc.solve_order(self.num_of_nested_loop, self.loop_limit_reg)

then it is randomizing value of num_of_nested_loop. Can you please take a look into this?

mballance commented 3 years ago

Hi @ShraddhaDevaiya, Just wanted to give you a status update on this. I can see that the problem relates to solve order on arrays. Specifically, constraints on array elements (eg .size) are not being properly incorporated in the solve-order calculations. I don't have a solution yet, but an working in that direction.

Best Regards, Matthew

ShraddhaDevaiya commented 3 years ago

Hi @mballance , Thanks for the update.

ShraddhaDevaiya commented 3 years ago

Hi @mballance , did you get a chance to look into this issue?

Thanks & Regards, Shraddha Devaiya.

ShraddhaDevaiya commented 3 years ago

Hello @mballance, did you get a chance to look into this issue?

Thanks & Regards, Shraddha Devaiya.

mballance commented 3 years ago

Hi @ShraddhaDevaiya, Apologies for the delay on this one. After taking a fresh look, I believe I have a solution. Please have a look at the latest PyVSC release/source. Please note that you'll need to have the 'toposort' Python package installed in order to use this release.

Best Regards, Matthew

ShraddhaDevaiya commented 3 years ago

Yeah, it is working now. Thanks!

Best Regards, Shraddha Devaiya.