1#ifndef HALIDE_RUNTIME_MEMORY_RESOURCES_H
2#define HALIDE_RUNTIME_MEMORY_RESOURCES_H
123 return (x & (x - 1)) == 0;
130 return (alignment == 0) ? (offset) : (offset + (alignment - 1)) & ~(alignment - 1);
136 size_t alignment =
max(requested, required);
137 return ((required > 0) && (alignment > required)) ? (required * ((alignment / required) + 1)) : alignment;
144 size_t padding = actual_offset - offset;
145 size_t actual_size = padding + size;
152 size_t adjusted_size =
aligned_size(offset, size, alignment);
153 adjusted_size = (alignment > adjusted_size) ? alignment : adjusted_size;
154 if (nearest_multiple > 0) {
155 size_t rounded_size = (((adjusted_size + nearest_multiple - 1) / nearest_multiple) * nearest_multiple);
158 return adjusted_size;
164 size_t result = (value < min_value) ? min_value : value;
165 return (result > max_value) ? max_value : result;
171 return reinterpret_cast<const void *
>(base + byte_offset);
177 return reinterpret_cast<void *
>(base + byte_offset);
182typedef void *(*AllocateSystemFn)(
void *,
size_t);
235 case MemoryVisibility::InvalidVisibility: {
236 return "InvalidVisibility";
238 case MemoryVisibility::DefaultVisibility: {
239 return "DefaultVisibility";
241 case MemoryVisibility::HostOnly: {
244 case MemoryVisibility::DeviceOnly: {
247 case MemoryVisibility::HostToDevice: {
248 return "HostToDevice";
250 case MemoryVisibility::DeviceToHost: {
251 return "DeviceToHost";
254 return "<unknown memory visibility value>";
257 return "<unknown memory visibility value>";
262 case MemoryUsage::InvalidUsage: {
263 return "InvalidUsage";
265 case MemoryUsage::DefaultUsage: {
266 return "DefaultUsage";
268 case MemoryUsage::StaticStorage: {
269 return "StaticStorage";
271 case MemoryUsage::DynamicStorage: {
272 return "DynamicStorage";
274 case MemoryUsage::UniformStorage: {
275 return "UniformStorage";
277 case MemoryUsage::TransferSrc: {
278 return "TransferSrc";
280 case MemoryUsage::TransferDst: {
281 return "TransferDst";
283 case MemoryUsage::TransferSrcDst: {
284 return "TransferSrcDst";
287 return "<unknown memory usage value>";
290 return "<unknown memory usage value>";
295 case MemoryCaching::InvalidCaching: {
296 return "InvalidCaching";
298 case MemoryCaching::DefaultCaching: {
299 return "DefaultCaching";
301 case MemoryCaching::Cached: {
304 case MemoryCaching::Uncached: {
307 case MemoryCaching::CachedCoherent: {
308 return "CachedCoherent";
310 case MemoryCaching::UncachedCoherent: {
311 return "UncachedCoherent";
314 return "<unknown memory visibility value>";
317 return "<unknown memory visibility value>";
This file declares the routines used by Halide internally in its runtime.
void * halide_malloc(void *user_context, size_t x)
Halide calls these functions to allocate and free memory.
void halide_free(void *user_context, void *ptr)
Allocator class interface for sub-allocating a contiguous memory block into smaller regions of memory...
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)
void *(* AllocateSystemFn)(void *, size_t)
int(* AllocateBlockFn)(void *, MemoryBlock *)
int(* ConformBlockRegionFn)(void *, MemoryRequest *)
int(* ConformBlockRequestFn)(void *, MemoryRequest *)
ALWAYS_INLINE void * native_system_malloc(void *user_context, size_t bytes)
int(* AllocateRegionFn)(void *, MemoryRegion *)
ALWAYS_INLINE size_t conform_alignment(size_t requested, size_t required)
ALWAYS_INLINE bool is_power_of_two_alignment(size_t x)
ALWAYS_INLINE size_t conform_size(size_t offset, size_t size, size_t alignment, size_t nearest_multiple)
ALWAYS_INLINE void native_system_free(void *user_context, void *ptr)
ALWAYS_INLINE size_t clamped_size(size_t value, size_t min_value, size_t max_value)
ALWAYS_INLINE size_t aligned_size(size_t offset, size_t size, size_t alignment)
void(* DeallocateSystemFn)(void *, void *)
int(* DeallocateBlockFn)(void *, MemoryBlock *)
int(* DeallocateRegionFn)(void *, MemoryRegion *)
ALWAYS_INLINE const void * offset_address(const void *address, size_t byte_offset)
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.
Expr max(const FuncRef &a, const FuncRef &b)
__UINTPTR_TYPE__ uintptr_t
unsigned __INT32_TYPE__ uint32_t
#define halide_abort_if_false(user_context, cond)
BlockResource * block_ptr
RegionAllocator * allocator
DeallocateSystemFn deallocate
AllocateSystemFn allocate
DeallocateBlockFn deallocate
ConformBlockRequestFn conform
MemoryProperties properties
MemoryVisibility visibility
DeallocateRegionFn deallocate
AllocateRegionFn allocate
ConformBlockRegionFn conform
MemoryProperties properties
MemoryProperties properties
DeallocateSystemFn deallocate
AllocateSystemFn allocate