MLIR-AIE 1.4.6.dev
memory_allocator.h File Reference
#include "target.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
Include dependency graph for memory_allocator.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int * mlir_aie_mem_alloc (aie_libxaie_ctx_t *ctx, ext_mem_model_t &handle, int size)
 Depending on the model of a particular device, this API supports several different scenarios for device memory allocation and reference.
void mlir_aie_sync_mem_cpu (ext_mem_model_t &handle)
 Synchronize the buffer from the device to the host CPU.
void mlir_aie_sync_mem_dev (ext_mem_model_t &handle)
 Synchronize the buffer from the host CPU to the device.
u64 mlir_aie_get_device_address (aie_libxaie_ctx_t *ctx, void *host_address)
 Return a device address corresponding to the given host address.

Function Documentation

◆ mlir_aie_get_device_address()

u64 mlir_aie_get_device_address ( aie_libxaie_ctx_t * ctx,
void * host_address )

Return a device address corresponding to the given host address.

Parameters
ctxThe AIE context
host_addressA host-side pointer returned from mlir_aie_mem_alloc
Returns
The device physical address corresponding to the host pointer

Definition at line 56 of file memory_allocator.cpp.

References aie_libxaie_ctx_t::allocations.

◆ mlir_aie_mem_alloc()

int * mlir_aie_mem_alloc ( aie_libxaie_ctx_t * ctx,
ext_mem_model_t & handle,
int size )

Depending on the model of a particular device, this API supports several different scenarios for device memory allocation and reference.

For instance, on the VCK190 with ARM host programmed through libXAIE, mlir_aie_mem_alloc() might allocate data in device DDR and return a cacheable mapping to it. mlir_aie_sync_mem_cpu() and mlir_aie_sync_mem_dev() would flush and invalidate caches. A device address would correspond to a DDR physical address. Alternatively in the AIESIM environment, mlir_aie_mem_alloc() allocates a duplicate buffer in the host memory and in the simulator memory for each allocation. mlir_aie_sync_mem_cpu() and mlir_aie_sync_mem_dev() make an explicit copy between these two buffers and device addresses are modeled in a simulator-specific way. Other combinations are also possible, largely representing different tradeoffs between efficiency of host data access vs. efficiency of accelerator access.

Allocate a buffer in device memory

Parameters
ctxThe AIE context
handleExternal memory model handle for tracking the allocation
sizeThe number of 32-bit words to allocate
Returns
A host-side pointer that can write into the allocated buffer
Note
This is a minimal allocator intended for test use.

Definition at line 22 of file memory_allocator.cpp.

References aie_libxaie_ctx_t::allocations, ext_mem_model_t::fd, ext_mem_model_t::MemInst, ext_mem_model_t::physicalAddr, ext_mem_model_t::size, ext_mem_model_t::virtualAddr, and aie_libxaie_ctx_t::XAieDevInst.

◆ mlir_aie_sync_mem_cpu()

void mlir_aie_sync_mem_cpu ( ext_mem_model_t & handle)

Synchronize the buffer from the device to the host CPU.

This is expected to be called after the device writes data into device memory, so that the data can be read by the CPU. In a non-cache coherent system, this implies invalidating the processor cache associated with the buffer.

Parameters
handleExternal memory model handle identifying the buffer to synchronize

Synchronize the buffer from the device to the host CPU.

  @param  IOInst: Linux IO instance pointer
  @param  MemInst: Linux Memory instance pointer.

  @return XAIE_OK on success, Error code on failure.

  @note   Internal only.

This is the memory function to free the memory

Parameters
MemInstMemory instance pointer.
Returns
XAIE_OK on success, Error code on failure.
Note
Internal only.

Definition at line 48 of file memory_allocator.cpp.

References ess_ReadGM(), ext_mem_model_t::fd, ext_mem_model_t::physicalAddr, ext_mem_model_t::size, and ext_mem_model_t::virtualAddr.

◆ mlir_aie_sync_mem_dev()

void mlir_aie_sync_mem_dev ( ext_mem_model_t & handle)

Synchronize the buffer from the host CPU to the device.

This is expected to be called after the host writes data into device memory, so that the data can be read by the device. In a non-cache coherent system, this implies flushing the processor cache associated with the buffer.

Parameters
handleExternal memory model handle identifying the buffer to synchronize

Definition at line 52 of file memory_allocator.cpp.

References ess_WriteGM(), ext_mem_model_t::fd, ext_mem_model_t::physicalAddr, ext_mem_model_t::size, and ext_mem_model_t::virtualAddr.