# Testbench access to modify an associative array (used as a model for DUT memory)

**URL:** <https://verificationacademy.com/forums/t/testbench-access-to-modify-an-associative-array-used-as-a-model-for-dut-memory/49549>\
**Category:** UVM\
**Created:** [February 3, 2025, 7:14pm UTC](https://verificationacademy.com/forums/t/testbench-access-to-modify-an-associative-array-used-as-a-model-for-dut-memory/49549 "2025-02-03T19:14:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jnbkeller](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/j/ea5d25/32.png) [@jnbkeller](https://verificationacademy.com/forums/u/jnbkeller)\
**Post date:** [February 3, 2025, 7:14pm UTC](https://verificationacademy.com/forums/t/testbench-access-to-modify-an-associative-array-used-as-a-model-for-dut-memory/49549/1 "2025-02-03T19:14:40Z")

</div>

Hi all, thanks in advance for suggestions/insights.

I have a DUT with an internal module that allows access to an external 4GB memory. For simulation, I swap it out with a system verilog model. The model uses an associative array:  
**logic [7:0] memory [logic [32:0]];**

This works fine when the DUT is reading/writing it. However, In my testbench I want to save time by pre-filling this memory array with data in my test (in the **run\_phase** )  
I have tried several things: Conceptual code is below:

**top\_tb.top\_dut.ddr\_inst.u\_ddr\_model.memory[addr]** = data;  
However, I get an error saying this is not found in the scope

I’ve also tried  
**uvm\_hdl\_deposit** /force(path, data) but the path is not found.  
**adding a update\_memory task** to the model, but **root access** from within packages is not allowed so I don’t know how to call it. ($root.top\_tb…u\_ddr\_axi\_model.update\_memory(addr, data) )

I’ve checked the path and believe it is correct.  
Unable to force value to ‘top\_tb.top\_dut.ddr\_inst.u\_ddr\_axi\_model.memory[0]’ Either the path is incorrect, or you may not have PLI/ACC visibility to that object.

I’m using questa and specified the **+acc** option to vsim to allow access. ( I realized this is intended to be a vendor agnostic forum), just wanted to include details.

**Here’s the interesting part** : If I change the model to a **fixed (smaller) sized array** instead of an associative array, **everything works fine** , so my paths must be correct and simulation visibility seems right. (But is not a solution since I can’t make a 4GB fixed array due to memory issues in simulation)

**Now the question** : How can a test add elements to an **associative** array in this scenario?

thanks

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [February 4, 2025, 1:20am UTC](https://verificationacademy.com/forums/t/testbench-access-to-modify-an-associative-array-used-as-a-model-for-dut-memory/49549/2 "2025-02-04T01:20:57Z")

</div>

I’m guessing this is because the UVM’s backdoor access was never designed to handle associative arrays.

You can create an abstract/concrete class interface to access the memory. Use the factory or uvm\_config\_db to get handle of the concrete class to your test.

```auto
package memory_interface;

interface class abstract_mem_intf;
  typedef logic [31:0] addr_t;
  typedef logic [7:0] data_t;

  pure virtual function void mem_write(input addr_t addr, input data_t data);
  pure virtual function data_t mem_read(input addr_t addr);
  // other methods like readmem/writemem
    pure virtual function void mem_dump();
endclass
endpackage
`include "uvm_macros.svh"
import uvm_pkg::*;
module behavioral_memory(/* ports */);
      logic [7:0] memory [logic [32:0]];
      
  class concrete_mem_intf extends uvm_object 
    implements memory_interface::abstract_mem_intf;
    typedef logic [31:0] addr_t;
    typedef logic [7:0] data_t;

    `uvm_object_utils(concrete_mem_intf)
    function new(string name="");
      super.new(name);
    endfunction
        virtual function void mem_write(input addr_t addr, input data_t data);
          memory[addr] = data;
        endfunction
        virtual function data_t mem_read(addr_t addr);
          if (memory.exists(addr))
            return memory[addr];
              else
                /* some error or return default pattern */;
        endfunction
       virtual function void mem_dump;
         $display("Dumping memory");
         foreach(memory[i]) $displayh(i,,memory[i]);
       endfunction
      endclass
      
endmodule
    
    class test extends uvm_test;
      `uvm_component_utils(test)
      function new(string name, uvm_component parent);
        super.new(name,parent);
      endfunction
      
      memory_interface::abstract_mem_intf mem_intf;
     
      function void build_phase(uvm_phase phase);
        $cast(mem_intf, create_object("concrete_mem_intf"));
        for(int i=0;i<10;i++) mem_intf.mem_write(i*4,$urandom);
        mem_intf.mem_dump();
      endfunction
    endclass
         
  
  
module top;
  behavioral_memory bm();
  
  initial run_test("test");
endmodule

```

---

<div class="post-metadata">

**Author:** ![jnbkeller](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/j/ea5d25/32.png) [@jnbkeller](https://verificationacademy.com/forums/u/jnbkeller)\
**Post date:** [February 6, 2025, 10:01pm UTC](https://verificationacademy.com/forums/t/testbench-access-to-modify-an-associative-array-used-as-a-model-for-dut-memory/49549/3 "2025-02-06T22:01:16Z")

</div>

Hi Dave,  
Sorry for the delay; I’ve been out sick.  
I will definitely give this a try.

It’s challenging to know what’s available - e.g., abstract classes, etc… Are you aware of any training resources that cover some of these more advanced UVM and OOP topics. I’ve got enough experience to figure it out if I know about things, but otherwise it’s pretty difficult to figure these things out.

Thanks for any suggestions, I appreciate as always, your shared insights and expertise.  
Brian

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [February 7, 2025, 12:10am UTC](https://verificationacademy.com/forums/t/testbench-access-to-modify-an-associative-array-used-as-a-model-for-dut-memory/49549/4 "2025-02-07T00:10:42Z")

</div>

My signature has a link to the trainings I offer.

There’s a DVCon paper I wrote specifically about abstract/concrete classes.

> [@Updated Example Code from DVCon Paper: The Missing Link: The Testbench to DUT Connection](https://verificationacademy.com/forums/t/updated-example-code-from-dvcon-paper-the-missing-link-the-testbench-to-dut-connection/35249):
>
> I’ve attached an updated version of code from my DVCon paper: [The Missing Link: The Testbench to DUT Connection](https://verificationacademy.com/resources/technical-papers/the-missing-link-the-testbench-to-dut-connection) that works with both UVM 1.1d and UVM 1.2 // $Id: probe.sv,v 1.4 2018/04/01 14:34:38 drich Exp $ //---------------------------------------------------------------------- // Dave Rich dave\_rich@mentor.com // Copyright 2007-2018 Mentor Graphics Corporation // All Rights Reserved Worldwide // // Licensed under the Apache License, Version 2.0 (the // "License"); you may not use this …

---

<div class="post-metadata">

**Author:** ![jnbkeller](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/j/ea5d25/32.png) [@jnbkeller](https://verificationacademy.com/forums/u/jnbkeller)\
**Post date:** [February 7, 2025, 12:38am UTC](https://verificationacademy.com/forums/t/testbench-access-to-modify-an-associative-array-used-as-a-model-for-dut-memory/49549/5 "2025-02-07T00:38:26Z")

</div>

Thanks Dave, for the solution option and other material - you’re the best!
