Associative array of covergroups

Hello,

Is it possible to have an associative array of covergroups? I am not sure whether it is the right way to phrase this question but posting my requirement below

  1. I intend to cover the clock ratios between different clocks in a design.
  2. The clock ratios between different clocks is available as an associative array (int clock_ratios[string]). The string index would be something like “clk1_x_clk2”.
  3. The clock ratios is an associative array because the number of clocks may vary depending on the design configuration.

What i intend to have

covergroup clk_ratios_cg with function sample(int clk_ratio);
  RATIO: coverpoint clk_ratio {
    bins low = {[1 : 5]};
    bins med = {[6 : 19]};
    bins high = {[20 : $]};
  }
endgroup

class my_class extends my_base_class;
  `uvm_component_utils(my_class)

  int clk_ratios[string];
  clk_ratios_cg ratio_cg[string]; // Can we do this?

  virtual task monitor_clk_period(); // called in run_phase
    foreach(config_item[i]) begin // config item from config db from the test top. The test top has some logic to figure out the number of clocks
      automatic string clk_name = i;
      fork begin
        forever begin
          calculate_clk_ratios(clk_name);
          @clk[name].half_clk_period; //clk is an associaive array from my base class having some clock attributes
        end
      end
      join_none
    end
  endtask

  virtual function calculate_clk_ratios(string clk_name);
    foreach(config_item[i]) begin
      if(i == clk_name) continue; // No need of clk_ratio of clock to itself!!
      else begin
        clk_ratios[$sformatf("%s_x_%s", name, i)] = (clk[name].half_clk_period/clk[i].half_clk_period);
        // Can we use sample function of clk_ratios_cg for each ratio_cg[$sformatf("%s_x_%s", name, i]
        // But then do we need to new ratio_cg. new() cannot be done here 
      end
    end
  endfunction  

endclass

From the above snippet, i want to cover the clk_ratio values in associative array clk_ratios[$sformatf(“%s_x_%s”, name, i] for the bins mentioned in clk_ratios_cg

Hi Dave,

Thanks for your reply.
I tried your suggestion, but i am getting the below error

ratio_cg[ratio_name] = new(); // only construct once on first reference
** Error: (vlog-13069) near “ratio_cg”: syntax error, unexpected IDENTIFIER.

We are using QuestaSim 2021.4.
Does this version of questa support newing of the cover group outside of the class constructor?

For the time being, we were able to work around this issue by moving the new() of the cover groups to build phase.

// Build Phase
  virtual function void build_phase (uvm_phase phase);
   super.build_phase(phase);
   foreach(config_item[j]) begin
     foreach(config_item[i]) begin
       if(i == j) continue;
       else begin
         string ratio_name = $sformatf("%s_x_%s", j, i);
         ratio_cg[ratio_name] = new;
       end
     end
   end
  endfunction