Correct way of creating dynamic parameterized components in your Test

Hi,

I have a top environment (top_env) which takes in unpacked parameters.

There is an agent (my_agent) array inside. The number of agent instances I need to instantiate is equal to the parameter value ‘NUM_INSTS’.

The agent however is also parameterized (agent and env code below)

class my_agent #(parameter int P1, parameter int P2) extends uvm_agent;
// Agent code
endclass

class top_env #(parameter int NUM_INSTS =  1,
                parameter PARAM1 [NUM_INSTS-1:0] = '{NUM_INSTS{1}},
                parameter PARAM2 [NUM_INSTS-1:0] = '{NUM_INSTS{1}},) extends uvm_env;



endclass

My requirement is instantiate ‘my_agent’ instances in the build phase of the env such that the parameters from the top_env are mapped to the agent_instance while creating.

For example, for parameter value NUM_INSTS = 2, Lets say I specify the value of PARAM1 as '{3,4} and PARAM2 as '{5,6}

For the above configuration, I would like to have instance 0 of the agent with parameters P1 and P2 as ‘3’ and ‘5’ respectively (i.e. PARAM1[0] and PARAM2[0] of the top env)

simlilarly,

instance 1 of the agent with parameters P1 and P2 as ‘4’ and ‘6’ respectively (i.e. PARAM1[1] and PARAM2[1] of the top env).

What is the correct way to dynamically create the agent components in the build phase of the top_env ?.

Thanks
Jayant

Trying to select parameter values procedurally is extremely difficult not even possible in SystemVerilog.

You should consider eliminating parameters as much as possible and using configuration objects instead. NUM_INSTS should be a field in a configuration object, not a parameter.

If you have a fixed set of parameter value combinations, you can assign a code to each combination, and have another field in the configuration object that is an array of codes to select for each agent instance. That requires then env to know all the possible combinations.

If that doesn’t work for you, you can use the factory instance override to select the correct parameterized object for each instance.