summaryrefslogtreecommitdiff
path: root/SpMV/host/mram-management.h
blob: a953d6a5ee996a835833ffc7dd5f6da5b6a6ad33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#pragma once

#include "common.h"
#include "utils.h"

#define DPU_CAPACITY (64 << 20)	// A DPU's capacity is 64 MiB

struct mram_heap_allocator_t {
	uint32_t totalAllocated;
};

static void init_allocator(struct mram_heap_allocator_t *allocator)
{
	allocator->totalAllocated = 0;
}

static uint32_t mram_heap_alloc(struct mram_heap_allocator_t *allocator,
				uint32_t size)
{
	uint32_t ret = allocator->totalAllocated;
	allocator->totalAllocated += ROUND_UP_TO_MULTIPLE_OF_8(size);
	if (allocator->totalAllocated > DPU_CAPACITY) {
		PRINT_ERROR
		    ("        Total memory allocated is %d bytes which exceeds the DPU capacity (%d bytes)!",
		     allocator->totalAllocated, DPU_CAPACITY);
		exit(0);
	}
	return ret;
}