Naming different covergroup instances with different names

Hii,

I wanted to name different names for different covergroups.

covergroup cg with function sample(int min, int max, int value);
  bins range = {[min:max]};
endgroup

class a extends uvm_subscriber(txn);
 `uvm_component_utils(a)
  assoc_arr values[str];
  cg cg_inst[];
  int j=0;
string str="";

function build_phase()
cg_inst = values.size();
foreach(cg_inst[i])
cg_inst[i] = new();
endfunction
foreach(values[i]) begin
str = {"CG_",i}
cg_inst[j].option.name = str;
end
j++;

endfunction

task run_phase();
int temp =0;
foreach(values[i]) begin
  cg_inst[temp].sample(0,500,values[i]);
  temp++;
end
endtask

endclass

I have a single covergroup which has to cover some set of parameters(which are the string names in assoc array), which has fixed min and max values. I wrote a single covegroup. I wanted to reuse it. The total number of parameters are stored in assoc array and they are fixed parameters. SO I wanted that parameter name itself with some modification to be assigned to the instances.
For example, if a parameter name is “TIME”, I want my cg_inst[0] should have name as “CG_TIME”. When Iam trying to do that, its giving that "No coverage data is available as a result.

**** Error: (vsim-8783) Covergroup instance has a duplicate name: ‘CG_’.**. Please help me out in coding this

In reply to kranthi445:

What difference Would I get?

In reply to Anudeep J:

I think we have to format integer i to string. Check the output of attached code.

Regards
Kranthi

In reply to kranthi445:

In the above code which I mentioned, variable i in values[i] will not be a integer. That assoc array will loop over strings.

In reply to Anudeep J:
There are many problems with the code you have shown. I think min and max should be covergroup arguments, not sample arguments. You cannot change bins per sample. Also you did not show a coverpoint. And finally, you should create an associative array of covergroups index by the same string index as value

covergroup cg(int min, max) with function sample(int value);
  option.per_instance = 1;
  coverpoint value {
  bins range = {[min:max]};
}
endgroup
 
class a extends uvm_subscriber(txn);
 `uvm_component_utils(a)
  assoc_arr values[string];
  cg cg_inst[string];
 
 
function build_phase()
  // assuming values is already initialized
  foreach (values[str]) begin
       cg_inst[str] = new(0,500);
       cg_inst[str].option.name = {"CG_",str};
    end
endfunction

 
task run_phase();
foreach(values[i]) begin
  cg_inst[i].sample(values[i]);
end
endtask
 
endclass

In reply to dave_59:

Thanks for the reply, Dave.

  1. As I pass arguments from the sample function, it was working fine.I felt there was no issue with that.
  2. I am not changing the bins per sample but Iam trying to sample different covergroups with same set of bins corresponding to that and also min and max may vary from parameter to parameter.
  3. My Assoc array does not have same string, the strings are all different which will be initialized in the build phase.
  4. And also I tried your method, it was working but it was creating many instances. I wanted only the number of instances is equal to the number of elements(parameters) initialized in the assoc_array.

The exact scenario is like this, my assoc array is storing a class object with index as strings. Each class object(is a parameter) has different min and max values. I want to have a single covergroup(which is re-usable) because it has the same structure for all the parameters.I wanted to have different covergroup names for all the parameters stored in assoc_array. Based on that names, the sampling has to be done. Whenever I call with that name, the sampling has to be done to the covergroup with that name. I hope the scenario is clear. Please let me know if still some queries exist. An also help me out on this

Thanks
Anudeep