L2OperationType#

Fully qualified name: cupva::mem::L2OperationType

Defined in src/host/shared/include/install/cupva_host_common.hpp

enum class cupva::mem::L2OperationType : uint32_t#

CmdL2Ops operation types.

Specifies the operation to be performed on an L2SRAM device pointer. These operations control the synchronization of data between L2SRAM and DRAM, which is essential when host code needs to read or write L2 buffers that are also accessed by VPU programs. Proper synchronization ensures data coherency between the host CPU and the VPU programs, preventing race conditions and data corruption. Please refer to the following use cases for selecting the appropriate operation type. These use cases extend the scenarios described in cupva::mem::L2SRAMPolicyType and provide guidance on when to use each operation for optimal data synchronization between L2SRAM and DRAM.

This use case demonstrates how the host processor can read data produced by VPU programs in L2SRAM and then update that data for subsequent VPU operations. This pattern is useful for monitoring intermediate results, adjusting algorithm parameters, or implementing host-driven feedback loops in VPU processing pipelines. Can be seen as an extension of Use Case 2.

See also

CmdL2Ops::Create() for creating L2 operation commands

See also

cupva::mem::L2SRAMPolicyType for related memory access policies

Use Case 8: Bidirectional Data Exchange Between Host and L2SRAM

// FILL_AND_FLUSH ensures state persistence if data is evicted from L2SRAM.
void* l2RW = MapL2(dramPtr, bufferSize, L2SRAMPolicyType::FILL_AND_FLUSH);

// Explicitly flush and invalidate L2SRAM.
// This ensures that:
// 1. Data produced by Prog1 in L2SRAM is flushed to DRAM, making it accessible to the host
// 2. L2SRAM is invalidated, forcing a reload from DRAM when Prog2 accesses it later
//
// Note: If the host only needs to read the L2 data without modifying it, use the FLUSH
// operation instead of FLUSH_AND_INVALIDATE. This preserves the valid data in L2SRAM,
// avoiding unnecessary DRAM-to-L2SRAM fills before Prog2 executes.
auto cmdFlushAndInvalidate = CmdL2Ops::Create(L2OperationType::FLUSH_AND_INVALIDATE, l2RW);

       │   ╭───────╮ ╭───────────────╮ ╭─────────╮                      ╭───────╮
VPU0   │   │ Prog1 │.│ cmdFlush      │.│ Request │                      │ Prog2 │
       │   │       │ │ AndInvalidate │ │ Fences  │                      │       │
       │   ╰───────╯ ╰───────────────╯ ╰─────────╯                      ╰───────╯
       │    │ l2 ▲                                                       │ l2 ▲
       │    │ RW │                                                       │ RW │
       │    ▼    │                                                       ▼    │
L2SRAM ───────────────────────────────────────────────────────────────────────────
                              │                                         ▲
                              │ Explicit                           Fill │
                              │ Flush                                   │
                              ▼                                         │
  DRAM ───────────────────────────────────────────────────────────────────────────
       │                                                        │    ▲
       │                                                        │ RW │
       │                                                        ▼    │
       │                                          ╭─────────╮ ╭────────╮
CPU    │                                          │ Wait On │.│  Host  │
       │                                          │ Fence   │ │ Update │
       │                                          ╰─────────╯ ╰────────╯

This use case shows how to update read-only data (like NN weights) from the host, and ensure VPU programs will reload the updated data from DRAM on next access. Can be seen as an extension of Use Case 5.

Use Case 9: Host Updates to Read-only Data

// Programs only read from L2SRAM, no need to flush data back to DRAM
void* l2R = MapL2(dramPtr, bufferSize, L2SRAMPolicyType::FILL);

// Invalidate L2SRAM to force refill from DRAM on next access by the VPU programs.
auto cmdInvalidate = CmdL2Ops::Create(L2OperationType::INVALIDATE, l2R);

       │   ╭───────╮ ╭─────────╮                      ╭───────────────╮ ╭───────╮
VPU0   │   │ Prog1 │.│ Request │                      │ cmdInvalidate │.│ Prog2 │
       │   │       │ │ Fences  │                      │               │ │       │
       │   ╰───────╯ ╰─────────╯                      ╰───────────────╯ ╰───────╯
       │       ▲                                           │Invalidate      ▲
       │   l2R │                                           │             l2R│
       │       │                                           ▼                │
L2SRAM ───────────────────────────────────────────────────────────────────────────
                                                                        ▲
                                                                   Fill │
                                                                        │
                                                                        │
  DRAM ───────────────────────────────────────────────────────────────────────────
       │                                         ▲
       │                                       W │
       │                                         │
       │                        ╭─────────╮ ╭────────╮
CPU    │                        │ Wait On │.│  Host  │
       │                        │ Fence   │ │ Update │
       │                        ╰─────────╯ ╰────────╯

Values:

enumerator FLUSH#

Flush L2SRAM contents to the mapped DRAM buffer. This operation writes any modified data from L2SRAM back to the corresponding DRAM location. Use this when the host needs to read the most up-to-date data that VPU programs have written to L2SRAM.

enumerator INVALIDATE#

Invalidate L2SRAM contents to force refill from DRAM on next access. This operation marks L2SRAM data as invalid, causing a reload from DRAM when next accessed. Use this after the host has updated DRAM data that needs to be visible to subsequent VPU programs.

enumerator FLUSH_AND_INVALIDATE#

Combined flush and invalidate operation. This performs both operations in sequence: first flushing modified L2SRAM data to DRAM, then invalidating the L2SRAM contents to ensure future reads come from DRAM. Use this when the host needs to both read the current L2SRAM state and provide new data for future operations.