1#ifndef HALIDE_RUNTIME_REGION_ALLOCATOR_H
2#define HALIDE_RUNTIME_REGION_ALLOCATOR_H
4#include "../HalideRuntime.h"
119 if (result ==
nullptr) {
173#ifdef DEBUG_RUNTIME_INTERNAL
174 debug(
user_context) <<
"RegionAllocator: Failed to conform region request! Unable to reserve memory ...\n";
181#ifdef DEBUG_RUNTIME_INTERNAL
182 debug(
user_context) <<
"RegionAllocator: Unable to reserve more memory from block "
191#ifdef DEBUG_RUNTIME_INTERNAL
192 debug(
user_context) <<
"RegionAllocator: Failed to locate region for requested size ("
199#ifdef DEBUG_RUNTIME_INTERNAL
252 return ((region ==
nullptr) || (region == region->
next_ptr) || (region->
next_ptr ==
nullptr));
255bool RegionAllocator::is_block_region_suitable_for_request(
void *
user_context,
const BlockRegion *region,
const MemoryRequest &
request)
const {
256 if (!is_available(region)) {
257#ifdef DEBUG_RUNTIME_INTERNAL
258 debug(
user_context) <<
" skipping block region ... not available! ("
259 <<
" block_region=" << (
void *)region
260 <<
" region_size=" << (
uint32_t)(region->memory.size)
269#ifdef DEBUG_RUNTIME_INTERNAL
270 debug(
user_context) <<
"RegionAllocator: Failed to conform region request! Unable to reserve memory ...\n";
276 if (!is_compatible_block_region(region,
region_request.properties)) {
277#ifdef DEBUG_RUNTIME_INTERNAL
278 debug(
user_context) <<
" skipping block region ... incompatible properties! ("
279 <<
" block_region=" << (
void *)region
280 <<
" region_size=" << (
uint32_t)(region->memory.size)
288#ifdef DEBUG_RUNTIME_INTERNAL
289 debug(
user_context) <<
" skipping block region ... not enough space for adjusted size! ("
290 <<
" block_region=" << (
void *)region
293 <<
" region_size=" << (
uint32_t)(region->memory.size)
301#ifdef DEBUG_RUNTIME_INTERNAL
302 debug(
user_context) <<
" found suitable block region! ("
303 <<
" block_region=" << (
void *)region
306 <<
" region_size=" << (
uint32_t)(region->memory.size)
315BlockRegion *RegionAllocator::find_block_region(
void *
user_context,
const MemoryRequest &
request) {
316#ifdef DEBUG_RUNTIME_INTERNAL
317 debug(
user_context) <<
"RegionAllocator: find block region ( "
320 <<
"requested_is_dedicated=" << (
request.dedicated ?
"true" :
"false") <<
" "
328#ifdef DEBUG_RUNTIME_INTERNAL
329 debug(
user_context) <<
"RegionAllocator: found suitable region ( "
331 <<
"block_resource=" << (
void *)block <<
" "
335 <<
"requested_is_dedicated=" << (
request.dedicated ?
"true" :
"false") <<
" "
351#ifdef DEBUG_RUNTIME_INTERNAL
352 debug(
user_context) <<
"RegionAllocator: couldn't find suitable region! ("
355 <<
"requested_is_dedicated=" << (
request.dedicated ?
"true" :
"false") <<
" "
365bool RegionAllocator::is_available(
const BlockRegion *
block_region)
const {
378bool RegionAllocator::can_coalesce(
const BlockRegion *
block_region)
const {
394#ifdef DEBUG_RUNTIME_INTERNAL
395 debug(
user_context) <<
"RegionAllocator: Freeing unused region to coalesce ("
396 <<
"block_ptr=" << (
void *)
block_region->block_ptr <<
" "
411#ifdef DEBUG_RUNTIME_INTERNAL
429#ifdef DEBUG_RUNTIME_INTERNAL
453#ifdef DEBUG_RUNTIME_INTERNAL
454 debug(
user_context) <<
"RegionAllocator: Split deallocate region ("
455 <<
"block_ptr=" << (
void *)
block_region->block_ptr <<
" "
471#ifdef DEBUG_RUNTIME_INTERNAL
490BlockRegion *RegionAllocator::create_block_region(
void *
user_context,
const MemoryRequest &
request) {
491#ifdef DEBUG_RUNTIME_INTERNAL
492 debug(
user_context) <<
"RegionAllocator: Creating block region request ("
497 <<
"dedicated=" << (
request.dedicated ?
"true" :
"false") <<
" "
506#ifdef DEBUG_RUNTIME_INTERNAL
507 debug(
user_context) <<
"RegionAllocator: Failed to conform request for new block region!\n";
513#ifdef DEBUG_RUNTIME_INTERNAL
514 debug(
user_context) <<
"RegionAllocator: Failed to allocate new block region ... region size was zero!\n";
521#ifdef DEBUG_RUNTIME_INTERNAL
522 debug(
user_context) <<
"RegionAllocator: Failed to allocate new block region!\n";
536#ifdef DEBUG_RUNTIME_INTERNAL
537 debug(
user_context) <<
"RegionAllocator: Created block region allocation ("
539 <<
"block_ptr=" << (
void *)
block_region->block_ptr <<
" "
550#ifdef DEBUG_RUNTIME_INTERNAL
551 debug(
user_context) <<
"RegionAllocator: Releasing block region ("
558 <<
"block_reserved=" << (
uint32_t)(block->reserved) <<
") ... ";
570#ifdef DEBUG_RUNTIME_INTERNAL
572 <<
"block_ptr=" << (
void *)
block_region->block_ptr <<
" "
587#ifdef DEBUG_RUNTIME_INTERNAL
588 debug(
user_context) <<
"RegionAllocator: Destroying block region ("
590 <<
"block_region=" << (
void *)(
block_region) <<
") ...";
601#ifdef DEBUG_RUNTIME_INTERNAL
614#ifdef DEBUG_RUNTIME_INTERNAL
616 <<
"block_ptr=" << (
void *)
block_region->block_ptr <<
" "
626#ifdef DEBUG_RUNTIME_INTERNAL
628 <<
"block_ptr=" << (
void *)
block_region->block_ptr <<
" "
644#ifdef DEBUG_RUNTIME_INTERNAL
645 debug(
user_context) <<
"RegionAllocator: Freeing block region ("
647 <<
"block_ptr=" << (
void *)
block_region->block_ptr <<
" "
656#ifdef DEBUG_RUNTIME_INTERNAL
658 <<
"block_ptr=" << (
void *)
block_region->block_ptr <<
" "
676#ifdef DEBUG_RUNTIME_INTERNAL
677 debug(
user_context) <<
"RegionAllocator: Releasing all regions ("
678 <<
"user_context=" << (
void *)(
user_context) <<
") ...";
693#ifdef DEBUG_RUNTIME_INTERNAL
694 debug(
user_context) <<
"RegionAllocator: Collecting free block regions ("
695 <<
"user_context=" << (
void *)(
user_context) <<
") ...";
703 <<
"block_ptr=" << (
void *)block <<
" "
711#ifdef DEBUG_RUNTIME_INTERNAL
714 <<
"block_ptr=" << (
void *)
block_region->block_ptr <<
" "
724#ifdef DEBUG_RUNTIME_INTERNAL
727 <<
"block_ptr=" << (
void *)
block_region->block_ptr <<
" "
736#ifdef DEBUG_RUNTIME_INTERNAL
740#ifdef DEBUG_RUNTIME_INTERNAL
748#ifdef DEBUG_RUNTIME_INTERNAL
750 <<
"block_ptr=" << (
void *)block <<
" "
759#ifdef DEBUG_RUNTIME_INTERNAL
761 <<
"block_ptr=" << (
void *)block <<
" "
772#ifdef DEBUG_RUNTIME_INTERNAL
773 debug(
user_context) <<
"RegionAllocator: Destroying all block regions ("
774 <<
"user_context=" << (
void *)(
user_context) <<
") ...";
776 if (block->
regions !=
nullptr) {
792 if (arena !=
nullptr) {
821size_t RegionAllocator::region_count(
void *
user_context)
const {
822 if (block ==
nullptr) {
826 for (BlockRegion
const *region = block->
regions; !is_last_block_region(
user_context, region); region = region->next_ptr) {
void * reserve(void *user_context, bool initialize=false)
static MemoryArena * create(void *user_context, const Config &config, const SystemMemoryAllocatorFns &allocator=default_allocator())
static constexpr uint32_t default_capacity
static void destroy(void *user_context, MemoryArena *arena)
void reclaim(void *user_context, void *ptr)
Allocator class interface for sub-allocating a contiguous memory block into smaller regions of memory...
MemoryRegion * reserve(void *user_context, const MemoryRequest &request)
RegionAllocator & operator=(const RegionAllocator &)=delete
RegionAllocator(const RegionAllocator &)=delete
static int destroy(void *user_context, RegionAllocator *region_allocator)
int conform(void *user_context, MemoryRequest *request) const
static RegionAllocator * find_allocator(void *user_context, MemoryRegion *memory_region)
int retain(void *user_context, MemoryRegion *memory_region)
bool collect(void *user_context)
~RegionAllocator()=delete
int reclaim(void *user_context, MemoryRegion *memory_region)
int release(void *user_context, MemoryRegion *memory_region)
BlockResource * block_resource() const
static RegionAllocator * create(void *user_context, BlockResource *block, const MemoryAllocators &ma)
WEAK const char * halide_memory_caching_name(MemoryCaching value)
WEAK const char * halide_memory_usage_name(MemoryUsage value)
WEAK const char * halide_memory_visibility_name(MemoryVisibility value)
ALWAYS_INLINE size_t conform_alignment(size_t requested, size_t required)
ALWAYS_INLINE size_t conform_size(size_t offset, size_t size, size_t alignment, size_t nearest_multiple)
ALWAYS_INLINE size_t aligned_offset(size_t offset, size_t alignment)
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
Internal::ConstantInterval cast(Type t, const Internal::ConstantInterval &a)
Cast operators for ConstantIntervals.
unsigned __INT64_TYPE__ uint64_t
signed __INT32_TYPE__ int32_t
unsigned __INT32_TYPE__ uint32_t
#define halide_abort_if_false(user_context, cond)
RegionAllocator * allocator
MemoryProperties properties
MemoryVisibility visibility
DeallocateRegionFn deallocate
AllocateRegionFn allocate
ConformBlockRegionFn conform
MemoryRegionAllocatorFns region
SystemMemoryAllocatorFns system
DeallocateSystemFn deallocate
AllocateSystemFn allocate