1#ifndef HALIDE_RUNTIME_VULKAN_MEMORY_H
2#define HALIDE_RUNTIME_VULKAN_MEMORY_H
66 bool collect(
void *user_context);
67 int release(
void *user_context);
68 int destroy(
void *user_context);
80 return this->physical_device;
83 return this->alloc_callbacks;
114 uint32_t select_memory_type(
void *user_context,
121 size_t block_byte_count = 0;
122 size_t block_count = 0;
123 size_t region_byte_count = 0;
124 size_t region_count = 0;
125 void *owner_context =
nullptr;
140 error(user_context) <<
"VulkanBlockAllocator: Unable to create instance! Missing system allocator interface!\n";
147 if (result ==
nullptr) {
148 error(user_context) <<
"VulkanMemoryAllocator: Failed to create instance! Out of memory!\n";
157 if (instance ==
nullptr) {
158 error(user_context) <<
"VulkanBlockAllocator: Unable to destroy instance! Invalide instance pointer!\n";
162 instance->
destroy(user_context);
165 error(user_context) <<
"VulkanBlockAllocator: Unable to destroy instance! Missing system allocator interface!\n";
172int VulkanMemoryAllocator::initialize(
void *user_context,
177 owner_context = user_context;
183 region_byte_count = 0;
185 block_byte_count = 0;
197 if (block_allocator ==
nullptr) {
198 error(user_context) <<
"VulkanMemoryAllocator: Failed to create BlockAllocator! Out of memory?!\n";
211#if defined(HL_VK_DEBUG_MEM)
212 debug(
nullptr) <<
"VulkanMemoryAllocator: Reserving memory ("
213 <<
"user_context=" << user_context <<
" "
214 <<
"block_allocator=" << (
void *)(block_allocator) <<
" "
216 <<
"device=" << (
void *)(device) <<
" "
217 <<
"physical_device=" << (
void *)(physical_device) <<
") ...\n";
220 if ((device ==
nullptr) || (physical_device ==
nullptr)) {
221 error(user_context) <<
"VulkanMemoryAllocator: Unable to reserve memory! Invalid device handle!\n";
225 if (block_allocator ==
nullptr) {
226 error(user_context) <<
"VulkanMemoryAllocator: Unable to reserve memory! Invalid block allocator!\n";
234#if defined(HL_VK_DEBUG_MEM)
235 debug(
nullptr) <<
"VulkanMemoryAllocator: Mapping region ("
236 <<
"user_context=" << user_context <<
" "
237 <<
"device=" << (
void *)(device) <<
" "
238 <<
"physical_device=" << (
void *)(physical_device) <<
" "
239 <<
"region=" << (
void *)(region) <<
" "
244 if ((device ==
nullptr) || (physical_device ==
nullptr)) {
245 error(user_context) <<
"VulkanMemoryAllocator: Unable to map memory! Invalid device handle!\n";
249 if (block_allocator ==
nullptr) {
250 error(user_context) <<
"VulkanMemoryAllocator: Unable to map memory! Invalid block allocator!\n";
257 error(user_context) <<
"VulkanMemoryAllocator: Unable to map region! Invalid region allocator handle!\n";
262 if (block_resource ==
nullptr) {
263 error(user_context) <<
"VulkanMemoryAllocator: Unable to map region! Invalid block resource handle!\n";
269 error(user_context) <<
"VulkanMemoryAllocator: Unable to map region! Invalid device memory handle!\n";
277 error(user_context) <<
"VulkanMemoryAllocator: Unable to map region! Invalid memory range !\n";
280#if defined(HL_VK_DEBUG_MEM)
281 debug(
nullptr) <<
"VulkanMemoryAllocator: MapMemory ("
282 <<
"user_context=" << user_context <<
"\n"
292 error(user_context) <<
"VulkanMemoryAllocator: Mapping region failed! vkMapMemory returned error code: " <<
vk_get_error_name(result) <<
"\n";
300#if defined(HL_VK_DEBUG_MEM)
301 debug(
nullptr) <<
"VulkanMemoryAllocator: Unmapping region ("
302 <<
"user_context=" << user_context <<
" "
303 <<
"device=" << (
void *)(device) <<
" "
304 <<
"physical_device=" << (
void *)(physical_device) <<
" "
305 <<
"region=" << (
void *)(region) <<
" "
310 if ((device ==
nullptr) || (physical_device ==
nullptr)) {
311 error(user_context) <<
"VulkanMemoryAllocator: Unable to unmap region! Invalid device handle!\n";
318 error(user_context) <<
"VulkanMemoryAllocator: Unable to unmap region! Invalid region allocator handle!\n";
323 if (block_resource ==
nullptr) {
324 error(user_context) <<
"VulkanMemoryAllocator: Unable to unmap region! Invalid block resource handle!\n";
330 error(user_context) <<
"VulkanMemoryAllocator: Unable to unmap region! Invalid device memory handle!\n";
339#if defined(HL_VK_DEBUG_MEM)
340 debug(
nullptr) <<
"VulkanMemoryAllocator: Cropping region ("
341 <<
"user_context=" << user_context <<
" "
342 <<
"device=" << (
void *)(device) <<
" "
343 <<
"physical_device=" << (
void *)(physical_device) <<
" "
344 <<
"region=" << (
void *)(region) <<
" "
347 <<
"crop_offset=" << (
int64_t)offset <<
") ...\n";
349 if ((device ==
nullptr) || (physical_device ==
nullptr)) {
350 error(user_context) <<
"VulkanMemoryAllocator: Unable to crop region! Invalid device handle!\n";
357 error(user_context) <<
"VulkanMemoryAllocator: Unable to unmap region! Invalid region allocator handle!\n";
364 error(user_context) <<
"VulkanMemoryAllocator: Unable to crop region! Failed to retain memory region!\n";
371 error(user_context) <<
"VulkanMemoryAllocator: Unable to create crop! Missing system allocator interface!\n";
379 error(user_context) <<
"VulkanMemoryAllocator: Failed to allocate memory region! Out of memory!\n";
392 if (region ==
nullptr) {
393 error(user_context) <<
"VulkanMemoryAllocator: Failed to destroy crop! Invalid memory region!\n";
400 error(user_context) <<
"VulkanMemoryAllocator: Unable to destroy crop region! Invalid region allocator handle!\n";
407 error(user_context) <<
"VulkanBlockAllocator: Unable to destroy crop region! Region allocator failed to release memory region!\n";
414 error(user_context) <<
"VulkanBlockAllocator: Unable to destroy crop region! Missing system allocator interface!\n";
431#if defined(HL_VK_DEBUG_MEM)
432 debug(
nullptr) <<
"VulkanMemoryAllocator: Releasing region ("
433 <<
"user_context=" << user_context <<
" "
434 <<
"region=" << (
void *)(region) <<
" "
438 if ((device ==
nullptr) || (physical_device ==
nullptr)) {
439 error(user_context) <<
"VulkanMemoryAllocator: Unable to release region! Invalid device handle!\n";
442 if (block_allocator ==
nullptr) {
443 error(user_context) <<
"VulkanMemoryAllocator: Unable to release region! Invalid block allocator!\n";
446 return block_allocator->
release(
this, region);
450#if defined(HL_VK_DEBUG_MEM)
451 debug(
nullptr) <<
"VulkanMemoryAllocator: Reclaiming region ("
452 <<
"user_context=" << user_context <<
" "
453 <<
"region=" << (
void *)(region) <<
" "
457 if ((device ==
nullptr) || (physical_device ==
nullptr)) {
458 error(user_context) <<
"VulkanMemoryAllocator: Unable to reclaim region! Invalid device handle!\n";
461 if (block_allocator ==
nullptr) {
462 error(user_context) <<
"VulkanMemoryAllocator: Unable to reclaim region! Invalid block allocator!\n";
465 return block_allocator->
reclaim(
this, region);
469#if defined(HL_VK_DEBUG_MEM)
470 debug(
nullptr) <<
"VulkanMemoryAllocator: Retaining region ("
471 <<
"user_context=" << user_context <<
" "
472 <<
"region=" << (
void *)(region) <<
" "
476 if ((device ==
nullptr) || (physical_device ==
nullptr)) {
477 error(user_context) <<
"VulkanMemoryAllocator: Unable to retain region! Invalid device handle!\n";
480 if (block_allocator ==
nullptr) {
481 error(user_context) <<
"VulkanMemoryAllocator: Unable to retain region! Invalid block allocator!\n";
484 return block_allocator->
retain(
this, region);
488#if defined(HL_VK_DEBUG_MEM)
489 debug(
nullptr) <<
"VulkanMemoryAllocator: Collecting unused memory ("
490 <<
"user_context=" << user_context <<
") ... \n";
492 if ((device ==
nullptr) || (physical_device ==
nullptr) || (block_allocator ==
nullptr)) {
495 return block_allocator->
collect(
this);
499#if defined(HL_VK_DEBUG_MEM)
500 debug(
nullptr) <<
"VulkanMemoryAllocator: Releasing block allocator ("
501 <<
"user_context=" << user_context <<
") ... \n";
503 if ((device ==
nullptr) || (physical_device ==
nullptr)) {
504 error(user_context) <<
"VulkanMemoryAllocator: Unable to release allocator! Invalid device handle!\n";
507 if (block_allocator ==
nullptr) {
508 error(user_context) <<
"VulkanMemoryAllocator: Unable to release allocator! Invalid block allocator!\n";
512 return block_allocator->
release(
this);
516#if defined(HL_VK_DEBUG_MEM)
517 debug(
nullptr) <<
"VulkanMemoryAllocator: Destroying allocator ("
518 <<
"user_context=" << user_context <<
") ... \n";
520 if (block_allocator !=
nullptr) {
521 block_allocator->
destroy(
this);
524 region_byte_count = 0;
526 block_byte_count = 0;
538#if defined(HL_VK_DEBUG_MEM)
539 debug(
nullptr) <<
"VulkanMemoryAllocator: Looking up requirements ("
540 <<
"user_context=" << user_context <<
" "
541 <<
"size=" << (
uint32_t)block->size <<
", "
557#if defined(HL_VK_DEBUG_MEM)
558 debug(
nullptr) <<
"VulkanMemoryAllocator: Failed to create buffer to find requirements!\n\t"
572 if (instance ==
nullptr) {
576 void *user_context = instance->owner_context;
577#if defined(HL_VK_DEBUG_MEM)
578 debug(
nullptr) <<
"VulkanMemoryAllocator: Conforming block request ("
579 <<
"user_context=" << user_context <<
" "
580 <<
"request=" << (
void *)(
request) <<
") ... \n";
583 if ((instance->device ==
nullptr) || (instance->physical_device ==
nullptr)) {
584 error(user_context) <<
"VulkanRegionAllocator: Unable to conform block request! Invalid device handle!\n";
592 error(user_context) <<
"VulkanRegionAllocator: Failed to conform block request! Unable to lookup requirements!\n";
596#if defined(HL_VK_DEBUG_MEM)
597 debug(
nullptr) <<
"VulkanMemoryAllocator: Block allocated ("
603 <<
"dedicated=" << (
request->dedicated ?
"true" :
"false") <<
")\n";
613 if (instance ==
nullptr) {
617 void *user_context = instance->owner_context;
618 if ((instance->device ==
nullptr) || (instance->physical_device ==
nullptr)) {
619 error(user_context) <<
"VulkanBlockAllocator: Unable to deallocate block! Invalid device handle!\n";
623 if (block ==
nullptr) {
624 error(user_context) <<
"VulkanBlockAllocator: Unable to deallocate block! Invalid pointer!\n";
628#if defined(HL_VK_DEBUG_MEM)
629 debug(
nullptr) <<
"VulkanMemoryAllocator: Allocating block ("
630 <<
"user_context=" << user_context <<
" "
631 <<
"block=" << (
void *)(block) <<
" "
633 <<
"dedicated=" << (block->
dedicated ?
"true" :
"false") <<
" "
640 uint32_t memory_type = instance->select_memory_type(user_context, instance->physical_device, block->
properties, 0);
641 if (memory_type == invalid_memory_type) {
642 error(user_context) <<
"VulkanMemoryAllocator: Unable to find appropriate memory type for device!\n";
656 debug(
nullptr) <<
"VulkanBlockAllocator: Unable to allocate block! Failed to allocate device memory handle!\n";
662 debug(
nullptr) <<
"VulkanMemoryAllocator: Allocation failed! vkAllocateMemory returned: " <<
vk_get_error_name(result) <<
"\n";
666 debug(
nullptr) <<
"vkAllocateMemory: Allocated memory for device region (" << (
uint64_t)block->
size <<
" bytes) ...\n";
670 instance->block_byte_count += block->
size;
671 instance->block_count++;
677 if (instance ==
nullptr) {
681 void *user_context = instance->owner_context;
682#if defined(HL_VK_DEBUG_MEM)
683 debug(
nullptr) <<
"VulkanMemoryAllocator: Deallocating block ("
684 <<
"user_context=" << user_context <<
" "
685 <<
"block=" << (
void *)(block) <<
") ... \n";
688 if ((instance->device ==
nullptr) || (instance->physical_device ==
nullptr)) {
689 error(user_context) <<
"VulkanBlockAllocator: Unable to deallocate block! Invalid device handle!\n";
693 if (block ==
nullptr) {
694 error(user_context) <<
"VulkanBlockAllocator: Unable to deallocate block! Invalid pointer!\n";
698#if defined(HL_VK_DEBUG_MEM)
699 debug(
nullptr) <<
"VulkanBlockAllocator: deallocating block ("
701 <<
"dedicated=" << (block->
dedicated ?
"true" :
"false") <<
" "
707 if (block->
handle ==
nullptr) {
708 error(user_context) <<
"VulkanBlockAllocator: Unable to deallocate block! Invalid handle!\n";
714 error(user_context) <<
"VulkanBlockAllocator: Unable to deallocate block! Invalid device memory handle!\n";
720 debug(
nullptr) <<
"vkFreeMemory: Deallocated memory for device region (" << (
uint64_t)block->
size <<
" bytes) ...\n";
723 if (instance->block_count > 0) {
724 instance->block_count--;
726 error(
nullptr) <<
"VulkanRegionAllocator: Block counter invalid ... reseting to zero!\n";
727 instance->block_count = 0;
731 instance->block_byte_count -= block->
size;
733 error(
nullptr) <<
"VulkanRegionAllocator: Block byte counter invalid ... reseting to zero!\n";
734 instance->block_byte_count = 0;
748 return block_byte_count;
751uint32_t VulkanMemoryAllocator::select_memory_type(
void *user_context,
775 error(
nullptr) <<
"VulkanMemoryAllocator: Unable to convert type! Invalid memory visibility request!\n\t"
777 return invalid_memory_type;
801 error(user_context) <<
"VulkanMemoryAllocator: Unable to convert type! Invalid memory caching request!\n\t"
803 return invalid_memory_type;
809 uint32_t result = invalid_memory_type;
836 if (result == invalid_memory_type) {
837 error(user_context) <<
"VulkanBlockAllocator: Failed to find appropriate memory type for given properties:\n\t"
841 return invalid_memory_type;
861 error(user_context) <<
"VulkanRegionAllocator: Failed to conform block request! Unable to lookup requirements!\n";
865#if defined(HL_VK_DEBUG_MEM)
866 debug(
nullptr) <<
"VulkanMemoryAllocator: Buffer requirements ("
867 <<
"requested_size=" << (
uint32_t)region->size <<
", "
874 if ((
request->alignment %
this->physical_device_limits.minStorageBufferOffsetAlignment) != 0) {
878 if ((
request->alignment %
this->physical_device_limits.minUniformBufferOffsetAlignment) != 0) {
892#if defined(HL_VK_DEBUG_MEM)
894 debug(
nullptr) <<
"VulkanMemoryAllocator: Adjusting request to match requirements (\n"
912 if (instance ==
nullptr) {
916 void *user_context = instance->owner_context;
917#if defined(HL_VK_DEBUG_MEM)
918 debug(
nullptr) <<
"VulkanMemoryAllocator: Conforming region request ("
919 <<
"user_context=" << user_context <<
" "
920 <<
"request=" << (
void *)(region) <<
") ... \n";
923 if ((instance->device ==
nullptr) || (instance->physical_device ==
nullptr)) {
924 error(user_context) <<
"VulkanRegionAllocator: Unable to conform region request! Invalid device handle!\n";
928#if defined(HL_VK_DEBUG_MEM)
929 debug(
nullptr) <<
"VulkanRegionAllocator: Conforming region request ("
932 <<
"dedicated=" << (
request->dedicated ?
"true" :
"false") <<
" "
944 if (instance ==
nullptr) {
948 void *user_context = instance->owner_context;
949#if defined(HL_VK_DEBUG_MEM)
950 debug(
nullptr) <<
"VulkanMemoryAllocator: Allocating region ("
951 <<
"user_context=" << user_context <<
" "
952 <<
"region=" << (
void *)(region) <<
") ... \n";
955 if ((instance->device ==
nullptr) || (instance->physical_device ==
nullptr)) {
956 error(user_context) <<
"VulkanRegionAllocator: Unable to allocate region! Invalid device handle!\n";
960 if (region ==
nullptr) {
961 error(user_context) <<
"VulkanRegionAllocator: Unable to allocate region! Invalid pointer!\n";
965#if defined(HL_VK_DEBUG_MEM)
966 debug(
nullptr) <<
"VulkanRegionAllocator: Allocating region ("
969 <<
"dedicated=" << (region->
dedicated ?
"true" :
"false") <<
" "
987 if (buffer ==
nullptr) {
988 error(user_context) <<
"VulkanRegionAllocator: Unable to allocate region! Failed to allocate buffer handle!\n";
994 error(user_context) <<
"VulkanRegionAllocator: Failed to create buffer!\n\t"
1007#if defined(HL_VK_DEBUG_MEM)
1008 debug(
nullptr) <<
"VulkanMemoryAllocator: Buffer requirements ("
1015 vkDestroyBuffer(instance->device, *buffer, instance->alloc_callbacks);
1017 debug(
nullptr) <<
"VulkanMemoryAllocator: Reallocating buffer to match required size ("
1023 error(user_context) <<
"VulkanRegionAllocator: Failed to recreate buffer!\n\t"
1030 debug(
nullptr) <<
"vkCreateBuffer: Created buffer for device region (" << (
uint64_t)region->
size <<
" bytes) ...\n";
1035 error(user_context) <<
"VulkanBlockAllocator: Unable to allocate region! Invalid region allocator!\n";
1040 if (block_resource ==
nullptr) {
1041 error(user_context) <<
"VulkanBlockAllocator: Unable to allocate region! Invalid block resource handle!\n";
1047 error(user_context) <<
"VulkanBlockAllocator: Unable to allocate region! Invalid device memory handle!\n";
1054 error(user_context) <<
"VulkanRegionAllocator: Failed to bind buffer!\n\t"
1059 region->
handle = (
void *)buffer;
1061 instance->region_byte_count += region->
size;
1062 instance->region_count++;
1068 if (instance ==
nullptr) {
1072 void *user_context = instance->owner_context;
1073#if defined(HL_VK_DEBUG_MEM)
1074 debug(
nullptr) <<
"VulkanMemoryAllocator: Deallocating region ("
1075 <<
"user_context=" << user_context <<
" "
1076 <<
"region=" << (
void *)(region) <<
") ... \n";
1079 if ((instance->device ==
nullptr) || (instance->physical_device ==
nullptr)) {
1080 error(user_context) <<
"VulkanRegionAllocator: Unable to deallocate region! Invalid device handle!\n";
1084 if (region ==
nullptr) {
1085 error(user_context) <<
"VulkanRegionAllocator: Unable to deallocate region! Invalid pointer!\n";
1089#if defined(HL_VK_DEBUG_MEM)
1090 debug(
nullptr) <<
"VulkanRegionAllocator: Deallocating region ("
1093 <<
"dedicated=" << (region->
dedicated ?
"true" :
"false") <<
" "
1099 if (region->
handle ==
nullptr) {
1100 error(user_context) <<
"VulkanRegionAllocator: Unable to deallocate region! Invalid handle!\n";
1105 if (buffer ==
nullptr) {
1106 error(user_context) <<
"VulkanRegionAllocator: Unable to deallocate region! Invalid buffer handle!\n";
1110 vkDestroyBuffer(instance->device, *buffer, instance->alloc_callbacks);
1112 debug(
nullptr) <<
"vkDestroyBuffer: Destroyed buffer for device region (" << (
uint64_t)region->
size <<
" bytes) ...\n";
1114 region->
handle =
nullptr;
1115 if (instance->region_count > 0) {
1116 instance->region_count--;
1118 error(
nullptr) <<
"VulkanRegionAllocator: Region counter invalid ... reseting to zero!\n";
1119 instance->region_count = 0;
1124 instance->region_byte_count -= region->
size;
1126 error(
nullptr) <<
"VulkanRegionAllocator: Region byte counter invalid ... reseting to zero!\n";
1127 instance->region_byte_count = 0;
1130 vk_host_free(
nullptr, buffer, instance->alloc_callbacks);
1136 return region_count;
1140 return region_byte_count;
1145 switch (properties.
usage) {
1165 error(user_context) <<
"VulkanRegionAllocator: Unable to convert type! Invalid memory usage request!\n\t"
1167 return invalid_usage_flags;
1170 if (result == invalid_usage_flags) {
1171 error(user_context) <<
"VulkanRegionAllocator: Failed to find appropriate memory usage for given properties:\n\t"
1175 return invalid_usage_flags;
1198 return callbacks->
pfnAllocation(user_context, size, alignment, scope);
1206 return callbacks->
pfnFree(user_context, ptr);
1233 print(user_context) <<
"Vulkan: Configuring allocator with " << (
uint32_t)config.maximum_pool_size <<
" for maximum pool size (in bytes)\n";
1237 print(user_context) <<
"Vulkan: Configuring allocator with " << (
uint32_t)config.minimum_block_size <<
" for minimum block size (in bytes)\n";
1241 print(user_context) <<
"Vulkan: Configuring allocator with " << (
uint32_t)config.maximum_block_size <<
" for maximum block size (in bytes)\n";
1245 print(user_context) <<
"Vulkan: Configuring allocator with " << (
uint32_t)config.maximum_block_count <<
" for maximum block count\n";
1249 print(user_context) <<
"Vulkan: Configuring allocator with " << (
uint32_t)config.nearest_multiple <<
" for nearest multiple\n";
1254 config, device, physical_device,
1259 if (allocator !=
nullptr) {
1261 allocator =
nullptr;
1269 VulkanMemoryAllocator *allocator,
1276 <<
" vk_clear_device_buffer (user_context: " << user_context <<
", "
1277 <<
"allocator: " << (
void *)allocator <<
", "
1278 <<
"command_pool: " << (
void *)command_pool <<
", "
1287 error(user_context) <<
"Vulkan: Failed to create command buffer!\n";
1302 error(user_context) <<
"Vulkan: vkBeginCommandBuffer returned " <<
vk_get_error_name(result) <<
"\n";
1312 error(user_context) <<
"Vulkan: vkEndCommandBuffer returned " <<
vk_get_error_name(result) <<
"\n";
1332 error(user_context) <<
"Vulkan: vkQueueSubmit returned " <<
vk_get_error_name(result) <<
"\n";
1339 error(user_context) <<
"Vulkan: vkQueueWaitIdle returned " <<
vk_get_error_name(result) <<
"\n";
1345 error(user_context) <<
"Vulkan: Failed to destroy command buffer!\n";
1369 custom_allocation_callbacks = callbacks;
1375 return custom_allocation_callbacks;
@ halide_error_code_internal_error
There is a bug in the Halide compiler.
@ halide_error_code_generic_error
An uncategorized error occurred.
@ halide_error_code_success
There was no error.
@ halide_error_code_device_malloc_failed
The Halide runtime encountered an error while trying to allocate memory on device.
@ halide_error_code_out_of_memory
A call to halide_malloc returned NULL.
Allocator class interface for managing large contiguous blocks of memory, which are then sub-allocate...
bool collect(void *user_context)
MemoryRegion * reserve(void *user_context, const MemoryRequest &request)
int release(void *user_context, MemoryRegion *region)
int retain(void *user_context, MemoryRegion *region)
static void destroy(void *user_context, BlockAllocator *block_allocator)
static BlockAllocator * create(void *user_context, const Config &config, const MemoryAllocators &allocators)
int reclaim(void *user_context, MemoryRegion *region)
const MemoryAllocators & current_allocators() const
Allocator class interface for sub-allocating a contiguous memory block into smaller regions of memory...
static RegionAllocator * find_allocator(void *user_context, MemoryRegion *memory_region)
Vulkan Memory Allocator class interface for managing large memory requests stored as contiguous block...
int reclaim(void *user_context, MemoryRegion *region)
static const VulkanMemoryConfig & default_config()
MemoryRegion * reserve(void *user_context, const MemoryRequest &request)
VulkanMemoryAllocator(const VulkanMemoryAllocator &)=delete
int release(void *user_context, MemoryRegion *region)
static int allocate_block(void *instance_ptr, MemoryBlock *block)
int conform(void *user_context, MemoryRequest *request)
static int deallocate_region(void *instance_ptr, MemoryRegion *region)
VulkanMemoryAllocator & operator=(const VulkanMemoryAllocator &)=delete
static int destroy(void *user_context, VulkanMemoryAllocator *allocator)
int unmap(void *user_context, MemoryRegion *region)
static int conform_region_request(void *instance_ptr, MemoryRequest *request)
~VulkanMemoryAllocator()=delete
MemoryRegion * create_crop(void *user_context, MemoryRegion *region, uint64_t offset)
int destroy_crop(void *user_context, MemoryRegion *region)
size_t regions_allocated() const
size_t blocks_allocated() const
static int allocate_region(void *instance_ptr, MemoryRegion *region)
static int conform_block_request(void *instance_ptr, MemoryRequest *request)
MemoryRegion * owner_of(void *user_context, MemoryRegion *region)
VkDevice current_device() const
bool collect(void *user_context)
size_t bytes_allocated_for_blocks() const
const VkAllocationCallbacks * callbacks() const
static int deallocate_block(void *instance_ptr, MemoryBlock *block)
VulkanMemoryAllocator()=delete
void * map(void *user_context, MemoryRegion *region)
VkPhysicalDevice current_physical_device() const
size_t bytes_allocated_for_regions() const
int retain(void *user_context, MemoryRegion *region)
static VulkanMemoryAllocator * create(void *user_context, const VulkanMemoryConfig &config, VkDevice dev, VkPhysicalDevice phys_dev, const SystemMemoryAllocatorFns &system_allocator, const VkAllocationCallbacks *alloc_callbacks=nullptr)
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)
VKAPI_ATTR VkResult VKAPI_CALL vkBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory memory, VkDeviceSize memoryOffset)
VkFlags VkMemoryPropertyFlags
VKAPI_ATTR void VKAPI_CALL vkCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size, uint32_t data)
VKAPI_ATTR VkResult VKAPI_CALL vkAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo, const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory)
#define VK_MAX_MEMORY_TYPES
@ VK_SHARING_MODE_EXCLUSIVE
@ VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
@ VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
@ VK_MEMORY_PROPERTY_HOST_CACHED_BIT
@ VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
VKAPI_ATTR void VKAPI_CALL vkGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer, VkMemoryRequirements *pMemoryRequirements)
@ VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
VKAPI_ATTR VkResult VKAPI_CALL vkQueueWaitIdle(VkQueue queue)
VKAPI_ATTR void VKAPI_CALL vkFreeMemory(VkDevice device, VkDeviceMemory memory, const VkAllocationCallbacks *pAllocator)
@ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT
VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties *pProperties)
VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties *pMemoryProperties)
VKAPI_ATTR VkResult VKAPI_CALL vkCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer)
VKAPI_ATTR VkResult VKAPI_CALL vkQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits, VkFence fence)
VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory(VkDevice device, VkDeviceMemory memory, VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags, void **ppData)
@ VK_BUFFER_USAGE_TRANSFER_DST_BIT
@ VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
@ VK_BUFFER_USAGE_STORAGE_BUFFER_BIT
@ VK_BUFFER_USAGE_TRANSFER_SRC_BIT
VKAPI_ATTR void VKAPI_CALL vkUnmapMemory(VkDevice device, VkDeviceMemory memory)
VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer(VkCommandBuffer commandBuffer)
VKAPI_ATTR void VKAPI_CALL vkDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator)
@ VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
@ VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO
@ VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
@ VK_STRUCTURE_TYPE_SUBMIT_INFO
VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo)
WEAK VulkanMemoryConfig memory_allocator_config
WEAK const VkAllocationCallbacks * custom_allocation_callbacks
WEAK ScopedSpinLock::AtomicFlag custom_allocation_callbacks_lock
WEAK char alloc_config[1024]
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.
Expr cast(Expr a)
Cast an expression to the halide type corresponding to the C++ type T.
Expr print(const std::vector< Expr > &values)
Create an Expr that prints out its value whenever it is evaluated.
unsigned __INT64_TYPE__ uint64_t
signed __INT64_TYPE__ int64_t
void * memcpy(void *s1, const void *s2, size_t n)
void * memset(void *s, int val, size_t n)
unsigned __INT32_TYPE__ uint32_t
MemoryRegionAllocatorFns region
MemoryBlockAllocatorFns block
SystemMemoryAllocatorFns system
MemoryProperties properties
MemoryVisibility visibility
MemoryProperties properties
static bool is_empty(const char *str)
DeallocateSystemFn deallocate
AllocateSystemFn allocate
size_t maximum_block_size
size_t minimum_block_size
size_t maximum_block_count
PFN_vkAllocationFunction pfnAllocation
PFN_vkFreeFunction pfnFree
VkDeviceSize minStorageBufferOffsetAlignment
VkDeviceSize minUniformBufferOffsetAlignment
WEAK void halide_vulkan_set_allocation_callbacks(const VkAllocationCallbacks *callbacks)
WEAK const VkAllocationCallbacks * halide_vulkan_get_allocation_callbacks(void *user_context)