简体   繁体   中英

Does vulkan has the maximum number limits of logic device creation?

I wrote the following code to test the maximum logic device number.

#include "vulkan/vulkan.hpp"
#include <cassert>
#include <vector>
#include <iostream>

int main() {

    std::vector<vk::Instance> instances;
    std::vector<vk::Device>   devices;

    try {

        for( ; true; ) {

            vk::InstanceCreateInfo instanceInfo {};
            instances.push_back( vk::createInstance( instanceInfo ) );

            auto physicalDevices = instances.back().enumeratePhysicalDevices();
            if( 0 == physicalDevices.size() )
                return 0;

            vk::DeviceQueueCreateInfo deviceQueueCreateInfo {};
            deviceQueueCreateInfo.queueFamilyIndex = 0;
            deviceQueueCreateInfo.queueCount = 1;

            vk::DeviceCreateInfo deviceCreateInfo {};
            deviceCreateInfo.queueCreateInfoCount = 1;
            deviceCreateInfo.pQueueCreateInfos = &deviceQueueCreateInfo;
            auto device = physicalDevices.front().createDevice( deviceCreateInfo );
            if( !device ) {
                throw 0;
            }
            devices.push_back( device );
        }
    }
    catch( std::system_error e ) {
        std::cout << e.what() << std::endl
            << e.code() << std::endl;
    }
    catch( ... ) {
    }

    for( auto device : devices )
        device.destroy();
    for( auto instance : instances )
        instance.destroy();
    printf( "Maximum device is %d\n", devices.size() );
    return static_cast<int>( devices.size() );
}

The following is my test results: Windows 10 64bit 8G RAM GTX 750Ti: Maximum device is 42, Ubuntu 8G RAM GTX 750Ti: Maximum device is 63, Windows 10 64bit 16G RAM GTX 1080: Maximum device is 42, Ubuntu 64G RAM Titan X: Maximum device is 31,

The test results show that the vulkan has the maximum number limits of logic device creation, and the limits may vary according to the operating system. I don't find any document about the limits, is there any way to get this limits ? Another question, if i want run a large number of vulkan applications on a server, how can i overcome this limits ?

The Vulkan spec only says this:

Multiple logical devices can be created from the same physical device. Logical device creation may fail due to lack of device-specific resources (in addition to the other errors). If that occurs, vkCreateDevice will return VK_ERROR_TOO_MANY_OBJECTS.

So the number of devices you can create is limited (obviously, since each one must use some resources, and all resources are finite), but the number is implementation-dependent.

The Vulkan conformance tests require that you are able to create at least five devices .

It's possible that some of the resources being used are per-process rather than system-wide. Have you tried spawning a bunch of processes, each of which creates a single VkDevice?

But failing that: your only option is to use a different implementation with a higher limit, or lobby the hardware vendor to use less resources per device (or whatever) to support a higher limit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM