Example #1
0
def test_vk_staging_allocator():
    if not hasattr(ncnn, "get_gpu_count"):
        return

    vkdev = ncnn.get_gpu_device(0)
    assert vkdev is not None
    allocator = ncnn.VkStagingAllocator(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)
Example #2
0
def test_vulkan_device_vkdev():
    if not hasattr(ncnn, "get_gpu_count"):
        return

    net = ncnn.Net()
    assert net.vulkan_device() is None

    vkdev = ncnn.get_gpu_device(0)
    net.set_vulkan_device(vkdev)
    assert net.vulkan_device() is not None
Example #3
0
def test_gpu_api():
    if not hasattr(ncnn, "get_gpu_count"):
        return

    assert ncnn.create_gpu_instance() == 0
    assert ncnn.get_gpu_count() > 0
    assert ncnn.get_default_gpu_index() >= 0

    gpuinfo = ncnn.get_gpu_info(0)
    check_gpuinfo(gpuinfo)

    vkdev = ncnn.get_gpu_device(0)
    assert vkdev is not None
    gpuinfo = vkdev.info()
    check_gpuinfo(gpuinfo)

    ncnn.destroy_gpu_instance()
Example #4
0
    if argc >= 6:
        cooling_down = int(sys.argv[5])

    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