MLIR-AIE
Functions
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 *_xaie, ext_mem_model_t &handle, int size)
 Allocate a buffer in device memory.
 
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 *_xaie, 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 _xaie,
void *  host_address 
)

Return a device address corresponding to the given host address.

Parameters
host_addressA host-side pointer returned from mlir_aie_mem_alloc

Definition at line 51 of file memory_allocator.cpp.

References aie_libxaie_ctx_t::allocations.

◆ mlir_aie_mem_alloc()

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

Allocate a buffer in device memory.

Parameters
bufIdxThe index of the buffer to allocate.
sizeThe number of 32-bit words to allocate
Returns
A host-side pointer that can write into the given buffer.
Todo:
This is at best a quick hack and should be replaced

Allocate a buffer in device memory.

Parameters
handleDevice Instance
sizeSize of the memory
Returns
Pointer to the allocated memory instance.

Definition at line 17 of file memory_allocator.cpp.

References aie_libxaie_ctx_t::allocations, ion_heap_query::cnt, aie_libxaie_ctx_t::DevInst, ion_allocation_data::fd, ext_mem_model_t::fd, ion_heap_data::heap_id, ion_allocation_data::heap_id_mask, ion_heap_query::heaps, ION_HEAP_TYPE_SYSTEM_CONTIG, ION_IOC_ALLOC, ION_IOC_HEAP_QUERY, ion_allocation_data::len, ext_mem_model_t::MemInst, ion_heap_data::name, ext_mem_model_t::physicalAddr, ext_mem_model_t::size, ion_heap_data::type, and ext_mem_model_t::virtualAddr.

◆ 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
bufIdxThe buffer index.

Synchronize the buffer from the device to the host CPU.

Parameters
IOInstLinux IO instance pointer
MemInstLinux Memory instance pointer.
Returns
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. This is the memory function to sync the memory for CPU.
Parameters
MemInstMemory instance pointer.
Returns
XAIE_OK on success, Error code on failure.
Note
Internal only.

Definition at line 43 of file memory_allocator.cpp.

References 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
bufIdxThe buffer index.

Synchronize the buffer from the host CPU to the device.

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

Definition at line 47 of file memory_allocator.cpp.

References ext_mem_model_t::fd, ext_mem_model_t::physicalAddr, ext_mem_model_t::size, and ext_mem_model_t::virtualAddr.