Skip to content

Commit

Permalink
Fixed bug with alloc size in sim (Xilinx#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackl-xilinx authored Feb 3, 2023
1 parent c191850 commit 8ba14b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
12 changes: 8 additions & 4 deletions runtime_lib/test_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -983,21 +983,25 @@ void mlir_aie_init_mems(aie_libxaie_ctx_t *ctx, int numBufs) {
#endif
}

/*
* size - size in words (4 bytes)
*/
int *mlir_aie_mem_alloc(aie_libxaie_ctx_t *ctx, int bufIdx, int size) {
#if defined(__AIESIM__)
int size_bytes = size * sizeof(int);
ctx->buffers[bufIdx] = new ext_mem_model_t;
(ctx->buffers[bufIdx])->virtualAddr = std::malloc(size * sizeof(int));
(ctx->buffers[bufIdx])->virtualAddr = std::malloc(size_bytes);
if ((ctx->buffers[bufIdx])->virtualAddr) {
(ctx->buffers[bufIdx])->size = size;
(ctx->buffers[bufIdx])->size = size_bytes;
// assign physical space in SystemC DDR memory controller
(ctx->buffers[bufIdx])->physicalAddr = nextAlignedAddr;
// adjust nextAlignedAddr to the next 128-bit aligned address
nextAlignedAddr = nextAlignedAddr + size;
nextAlignedAddr = nextAlignedAddr + size_bytes;
uint64_t gapToAligned = nextAlignedAddr % 16; // 16byte (128bit)
if (gapToAligned > 0)
nextAlignedAddr += (16 - gapToAligned);
} else {
printf("ExtMemModel: Failed to allocate %d memory.\n", size);
printf("ExtMemModel: Failed to allocate %d memory.\n", size_bytes);
}

std::cout << "ExtMemModel constructor: virutal address " << std::hex
Expand Down
1 change: 1 addition & 0 deletions runtime_lib/test_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#if defined(__AIESIM__)
#include "xioutils.h"
#include <iostream>
#endif

extern "C" {
Expand Down

0 comments on commit 8ba14b9

Please sign in to comment.