NCNN的内存显存分配器ncnn::Allocator & ncnn::VkAllocator翻译及其差异对比的学习笔记(nihui亲审过滴)
NCNN的内存分配器
ncnn::Allocator 通用内存分配器
ncnn::PoolAllocator 内存池分配器
可以设置池大小,减少分配内存和析构内存次数,空间换时间
ncnn::UnlockedPoolAllocator 无锁内存池分配器
同上,只是需在外部保证不会同时访问内存资源
NCNN的显存分配器
ncnn::VkAllocator 通用显存分配器(基类)
ncnn::VkBlobAllocator 特征显存分配器
vkCreateBuffer(): VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT
集成显卡:
required: VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
preferred: VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
preferred_not: 0
独立显卡:
required: VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
preferred: 0
preferred_not: VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
ncnn::VkWeightAllocator 权重显存分配器
vkCreateBuffer(): VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT
vkAllocateMemory():
集成显卡:
required: VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
preferred: VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
preferred_not: 0
独立显卡:
required: VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
preferred: 0
preferred_not: VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
ncnn::VkStagingAllocator 临时缓冲区显存分配器
vkCreateBuffer(): VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT
vkAllocateMemory():
required: VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
preferred: VK_MEMORY_PROPERTY_HOST_CACHED_BIT
preferred_not: VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
ncnn::VkWeightStagingAllocator 权重+临时缓冲区显存分配器
vkCreateBuffer(): VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT
vkAllocateMemory():
required: VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
preferred: VK_MEMORY_PROPERTY_HOST_CACHED_BIT
preferred_not: VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
ncnn::VkAndroidHardwareBufferImageAllocator 专门为Android优化显存分配器