MLIR-AIE
Macros | Functions
memory_allocator_ion.cpp File Reference
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <linux/dma-buf.h>
#include <pthread.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "ion.h"
#include "memory_allocator.h"
+ Include dependency graph for memory_allocator_ion.cpp:

Go to the source code of this file.

Macros

#define XAIE_128BIT_ALIGN_MASK   0xFF
 

Functions

int * mlir_aie_mem_alloc (struct aie_libxaie_ctx_t *ctx, 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 (struct aie_libxaie_ctx_t *_xaie, void *VA)
 Return a device address corresponding to the given host address.
 

Macro Definition Documentation

◆ XAIE_128BIT_ALIGN_MASK

#define XAIE_128BIT_ALIGN_MASK   0xFF

Definition at line 35 of file memory_allocator_ion.cpp.

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 228 of file memory_allocator_ion.cpp.

◆ mlir_aie_mem_alloc()

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

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
Todo:
This is at best a quick hack and should be replaced

Definition at line 38 of file memory_allocator_ion.cpp.

References ion_heap_query::cnt, 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::size, ion_heap_data::type, 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

Definition at line 196 of file memory_allocator_ion.cpp.

References ext_mem_model_t::fd.

◆ 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 212 of file memory_allocator_ion.cpp.

References ext_mem_model_t::fd.