StarPU Internal Handbook
malloc.h
Go to the documentation of this file.
1/* StarPU --- Runtime system for heterogeneous multicore architectures.
2 *
3 * Copyright (C) 2009-2025 University of Bordeaux, CNRS (LaBRI UMR 5800), Inria
4 * Copyright (C) 2022-2022 Federal University of Rio Grande do Sul (UFRGS)
5 *
6 * StarPU is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or (at
9 * your option) any later version.
10 *
11 * StarPU is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 *
15 * See the GNU Lesser General Public License in COPYING.LGPL for more details.
16 */
17
18#ifndef __ALLOC_H__
19#define __ALLOC_H__
20
21#include <common/list.h>
22#include <common/utils.h>
23
24#pragma GCC visibility push(hidden)
25
28void _starpu_malloc_init(unsigned dst_node);
29void _starpu_malloc_shutdown(unsigned dst_node);
30
31int _starpu_malloc_flags_on_node(unsigned dst_node, void **A, size_t dim, int flags);
32int _starpu_free_flags_on_node(unsigned dst_node, void *A, size_t dim, int flags);
33
39int _starpu_malloc_willpin_on_node(unsigned dst_node) STARPU_ATTRIBUTE_VISIBILITY_DEFAULT;
40
50#ifdef STARPU_USE_MAX_FPGA
51// FIXME: Maxeler FPGAs want 192 byte alignment
52#define CHUNK_SIZE (128*1024*192)
53#define CHUNK_ALLOC_MAX (CHUNK_SIZE / 8)
54#define CHUNK_ALLOC_MIN (128*192)
55#else
56/* Size of each chunk, 32MiB granularity brings 128 chunks to be allocated in
57 * order to fill a 4GiB GPU. */
58#define CHUNK_SIZE (32*1024*1024)
59
60/* Maximum segment size we will allocate in chunks */
61#define CHUNK_ALLOC_MAX (CHUNK_SIZE / 8)
62
63/* Granularity of allocation, i.e. block size, StarPU will never allocate less
64 * than this.
65 * 16KiB (i.e. 64x64 float) granularity eats 2MiB RAM for managing a 4GiB GPU.
66 */
67#define CHUNK_ALLOC_MIN (16*1024)
68#endif
69
70/* Don't really deallocate chunks unless we have more than this many chunks
71 * which are completely free. */
72#define CHUNKS_NFREE 4
73
74/* Number of blocks */
75#define CHUNK_NBLOCKS (CHUNK_SIZE/CHUNK_ALLOC_MIN)
76
77/* Linked list for available segments */
78struct block
79{
80 int length; /* Number of consecutive free blocks */
81 int next; /* next free segment */
82};
83
84/* One chunk */
85LIST_TYPE(_starpu_chunk,
86 uintptr_t base;
87
88 /* Available number of blocks, for debugging */
89 int available;
90
91 /* Overestimation of the maximum size of available segments in this chunk */
92 int available_max;
93
94 /* Bitmap describing availability of the block */
95 /* Block 0 is always empty, and is just the head of the free segments list */
96 struct block bitmap[CHUNK_NBLOCKS+1];
97)
98
99#pragma GCC visibility pop
100
101#endif
int _starpu_malloc_willpin_on_node(unsigned dst_node) STARPU_ATTRIBUTE_VISIBILITY_DEFAULT
Definition: malloc.h:79