1#ifndef HALIDE_RUNTIME_POINTER_TABLE_H
2#define HALIDE_RUNTIME_POINTER_TABLE_H
57 const void **
data()
const;
78 if (initial_capacity) {
86 ptr = static_cast<void **>(allocator.allocate(nullptr, other.capacity * sizeof(void *)));
87 capacity = other.capacity;
89 if (ptr && other.count != 0) {
91 memcpy(this->ptr, other.ptr, count * sizeof(void *));
101 if (ptr !=
nullptr) {
104 capacity = count = 0;
110 capacity = count = 0;
112 if (initial_capacity) {
118 if (&other !=
this) {
119 resize(
nullptr, other.count);
120 if (count != 0 && other.ptr !=
nullptr) {
121 memcpy(ptr, other.ptr, count *
sizeof(
void *));
128 if (count != other.count) {
131 return memcmp(this->ptr, other.ptr, this->size() *
sizeof(
void *)) == 0;
135 return !(*
this == other);
139 if (array_size != 0) {
141 memcpy(this->ptr, array, array_size *
sizeof(
void *));
148 ptr[index] =
const_cast<void *
>(entry_ptr);
174 new_capacity =
max(new_capacity, count);
175 if ((new_capacity < capacity) && !free_existing) {
176 new_capacity = capacity;
182 size_t current_size = capacity;
183 size_t requested_size = entry_count;
185 size_t actual_size = current_size;
186 count = requested_size;
188#ifdef DEBUG_RUNTIME_INTERNAL
190 <<
"requested_size=" << (
int32_t)requested_size <<
" "
191 <<
"current_size=" << (
int32_t)current_size <<
" "
192 <<
"minimum_size=" << (
int32_t)minimum_size <<
" "
193 <<
"sizeof(void*)=" << (
int32_t)
sizeof(
void *) <<
" "
194 <<
"realloc=" << (realloc ?
"true" :
"false") <<
")...\n";
198 if (requested_size > current_size) {
199 actual_size =
max(requested_size,
max(current_size * 3 / 2, minimum_size));
200 }
else if (!realloc) {
208 if (capacity > count) {
209 void *new_ptr =
nullptr;
211 size_t bytes = count *
sizeof(
void *);
213 memcpy(new_ptr, ptr, bytes);
217 ptr =
static_cast<void **
>(new_ptr);
222 const void *addr =
reinterpret_cast<const void *
>(entry_ptr);
232 const size_t last_index =
size();
233 if (index < (last_index - entry_count)) {
234 size_t dst_offset = index *
sizeof(
void *);
235 size_t src_offset = (index + entry_count) *
sizeof(
void *);
236 size_t bytes = (last_index - index - entry_count) *
sizeof(
void *);
238#ifdef DEBUG_RUNTIME_INTERNAL
240 <<
"index=" << (
int32_t)index <<
" "
241 <<
"entry_count=" << (
int32_t)entry_count <<
" "
242 <<
"last_index=" << (
int32_t)last_index <<
" "
243 <<
"src_offset=" << (
int32_t)src_offset <<
" "
244 <<
"dst_offset=" << (
int32_t)dst_offset <<
" "
245 <<
"bytes=" << (
int32_t)bytes <<
")...\n";
247 memmove(ptr + dst_offset, ptr + src_offset, bytes);
254 size_t remaining = count - index;
255 size_t copy_count =
min(remaining, array_size);
257#ifdef DEBUG_RUNTIME_INTERNAL
259 <<
"index=" << (
int32_t)index <<
" "
260 <<
"array_size=" << (
int32_t)array_size <<
" "
261 <<
"remaining=" << (
int32_t)remaining <<
" "
262 <<
"copy_count=" << (
int32_t)copy_count <<
" "
263 <<
"capacity=" << (
int32_t)capacity <<
")...\n";
267 memcpy(ptr + index, array, copy_count *
sizeof(
void *));
268 count =
max(count, index + copy_count);
273 const size_t last_index =
size();
275 if (index < last_index) {
276 size_t src_offset = index *
sizeof(
void *);
277 size_t dst_offset = (index + array_size) *
sizeof(
void *);
278 size_t bytes = (last_index - index) *
sizeof(
void *);
279 memmove(ptr + dst_offset, ptr + src_offset, bytes);
289 const size_t last_index =
size();
322 size_t index = count - 1;
327 return const_cast<const void **
>(ptr);
330void PointerTable::allocate(
void *
user_context,
size_t new_capacity) {
331 if (new_capacity != capacity) {
333 size_t bytes = new_capacity *
sizeof(
void *);
335#ifdef DEBUG_RUNTIME_INTERNAL
336 debug(
user_context) <<
"PointerTable: Allocating (bytes=" << (
int32_t)bytes <<
" allocator=" << (
void *)allocator.
allocate <<
")...\n";
340 if (count != 0 && ptr !=
nullptr && new_ptr !=
nullptr) {
341 memcpy(new_ptr, ptr, count *
sizeof(
void *));
343 if (ptr !=
nullptr) {
347 capacity = new_capacity;
348 ptr =
static_cast<void **
>(new_ptr);
352const SystemMemoryAllocatorFns &
354 return this->allocator;
361 return native_allocator;
This file declares the routines used by Halide internally in its runtime.
const SystemMemoryAllocatorFns & current_allocator() const
void pop_front(void *user_context)
void fill(void *user_context, const void **array, size_t array_size)
PointerTable(void *user_context, size_t initial_capacity=0, const SystemMemoryAllocatorFns &sma=default_allocator())
void remove(void *user_context, size_t index)
void initialize(void *user_context, size_t initial_capacity=0, const SystemMemoryAllocatorFns &sma=default_allocator())
static const SystemMemoryAllocatorFns & default_allocator()
void shrink_to_fit(void *user_context)
bool operator==(const PointerTable &other) const
void clear(void *user_context)
void prepend(void *user_context, const void *entry_ptr)
static constexpr size_t default_capacity
void replace(void *user_context, size_t index, const void **array, size_t array_size)
void reserve(void *user_context, size_t capacity, bool free_existing=false)
PointerTable & operator=(const PointerTable &other)
void * operator[](size_t index)
void pop_back(void *user_context)
void destroy(void *user_context)
void resize(void *user_context, size_t entry_count, bool realloc=true)
void append(void *user_context, const void *entry_ptr)
void insert(void *user_context, size_t index, const void *entry_ptr)
bool operator!=(const PointerTable &other) const
void assign(void *user_context, size_t index, const void *entry_ptr)
ALWAYS_INLINE void * native_system_malloc(void *user_context, size_t bytes)
ALWAYS_INLINE void native_system_free(void *user_context, void *ptr)
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
Expr min(const FuncRef &a, const FuncRef &b)
Explicit overloads of min and max for FuncRef.
Expr max(const FuncRef &a, const FuncRef &b)
void * memmove(void *dest, const void *src, size_t n)
#define halide_debug_assert(user_context, cond)
halide_debug_assert() is like halide_assert(), but only expands into a check when DEBUG_RUNTIME is de...
signed __INT32_TYPE__ int32_t
void * memcpy(void *s1, const void *s2, size_t n)
int memcmp(const void *s1, const void *s2, size_t n)
DeallocateSystemFn deallocate
AllocateSystemFn allocate
VulkanMemoryAllocator * allocator