def test_vk_blob_allocator(): if not hasattr(ncnn, "get_gpu_count"): return vkdev = ncnn.get_gpu_device(0) assert vkdev is not None allocator = ncnn.VkBlobAllocator(vkdev) assert allocator.buffer_memory_type_index >= 0 assert allocator.image_memory_type_index >= 0 mappable = allocator.mappable allocator.mappable = not mappable assert allocator.mappable == (not mappable) coherent = allocator.coherent allocator.coherent = not coherent assert allocator.coherent == (not coherent) bufmem = allocator.fastMalloc(10 * 1024) assert bufmem is not None allocator.fastFree(bufmem) imgmem = allocator.fastMalloc(4, 4, 3, 4, 1) assert imgmem is not None allocator.fastFree(imgmem)
use_vulkan_compute = gpu_device != -1 g_enable_cooling_down = cooling_down != 0 g_loop_count = loop_count g_blob_pool_allocator.set_size_compare_ratio(0.0) g_workspace_pool_allocator.set_size_compare_ratio(0.5) if use_vulkan_compute: g_warmup_loop_count = 10 g_vkdev = ncnn.get_gpu_device(gpu_device) g_blob_vkallocator = ncnn.VkBlobAllocator(g_vkdev) g_staging_vkallocator = ncnn.VkStagingAllocator(g_vkdev) opt = ncnn.Option() opt.lightmode = True opt.num_threads = num_threads opt.blob_allocator = g_blob_pool_allocator opt.workspace_allocator = g_workspace_pool_allocator if use_vulkan_compute: opt.blob_vkallocator = g_blob_vkallocator opt.workspace_vkallocator = g_blob_vkallocator opt.staging_vkallocator = g_staging_vkallocator opt.use_winograd_convolution = True opt.use_sgemm_convolution = True opt.use_int8_inference = True opt.use_vulkan_compute = use_vulkan_compute