Updated to current multiple queue implementation

This commit is contained in:
Alejandro Saucedo 2020-10-15 21:40:31 +01:00
parent 3e5364fc44
commit 4e697bb787
4 changed files with 151 additions and 79 deletions

View file

@ -25,15 +25,15 @@ debugMessageCallback(VkDebugReportFlagsEXT flags,
#endif
Manager::Manager()
: Manager(0)
: Manager(0, 1)
{}
Manager::Manager(uint32_t physicalDeviceIndex)
Manager::Manager(uint32_t physicalDeviceIndex, uint32_t totalComputeQueues)
{
this->mPhysicalDeviceIndex = physicalDeviceIndex;
this->createInstance();
this->createDevice();
this->createDevice(totalComputeQueues);
}
Manager::Manager(std::shared_ptr<vk::Instance> instance,
@ -98,19 +98,27 @@ Manager::getOrCreateManagedSequence(std::string sequenceName)
this->mManagedSequences.find(sequenceName);
if (found == this->mManagedSequences.end()) {
std::shared_ptr<Sequence> sq =
std::make_shared<Sequence>(this->mPhysicalDevice,
this->mDevice,
this->mComputeQueue,
this->mComputeQueueFamilyIndex);
sq->init();
this->mManagedSequences.insert({ sequenceName, sq });
return sq;
return this->createManagedSequence(sequenceName);
} else {
return found->second;
}
}
std::weak_ptr<Sequence>
Manager::createManagedSequence(std::string sequenceName, uint32_t queueIndex) {
SPDLOG_DEBUG("Kompute Manager createManagedSequence with sequenceName: {} and queueIndex: {}", sequenceName, queueIndex);
std::shared_ptr<Sequence> sq =
std::make_shared<Sequence>(this->mPhysicalDevice,
this->mDevice,
this->mComputeQueues[queueIndex],
this->mComputeQueueFamilyIndex);
sq->init();
this->mManagedSequences.insert({ sequenceName, sq });
return sq;
}
void
Manager::createInstance()
{
@ -197,7 +205,7 @@ Manager::createInstance()
}
void
Manager::createDevice()
Manager::createDevice(uint32_t totalComputeQueues)
{
SPDLOG_DEBUG("Kompute Manager creating Device");
@ -248,7 +256,7 @@ Manager::createDevice()
}
const float defaultQueuePriority(0.0f);
const uint32_t defaultQueueCount(1);
const uint32_t defaultQueueCount(totalComputeQueues);
vk::DeviceQueueCreateInfo deviceQueueCreateInfo(
vk::DeviceQueueCreateFlags(),
this->mComputeQueueFamilyIndex,
@ -264,9 +272,16 @@ Manager::createDevice()
&deviceCreateInfo, nullptr, this->mDevice.get());
SPDLOG_DEBUG("Kompute Manager device created");
this->mComputeQueue = std::make_shared<vk::Queue>();
this->mDevice->getQueue(
this->mComputeQueueFamilyIndex, 0, this->mComputeQueue.get());
for (uint32_t i = 0; i < totalComputeQueues; i++)
{
std::shared_ptr<vk::Queue> currQueue = std::make_shared<vk::Queue>();
this->mDevice->getQueue(
this->mComputeQueueFamilyIndex, i, currQueue.get());
this->mComputeQueues.push_back(currQueue);
}
SPDLOG_DEBUG("Kompute Manager compute queue obtained");
}

View file

@ -25,19 +25,22 @@ class Manager
Manager();
/**
Similar to base constructor but allows the user to provide the device
they would like to create the resources on.
* Similar to base constructor but allows the user to provide the device
* they would like to create the resources on.
*
* @param physicalDeviceIndex The index of the physical device to use
* @param totalQueues The total number of compute queues to create.
*/
Manager(uint32_t physicalDeviceIndex);
Manager(uint32_t physicalDeviceIndex, uint32_t totalComputeQueues = 1);
/**
* Manager constructor which allows your own vulkan application to integrate
* with the vulkan kompute use.
*
* @param instance Vulkan compute instance to base this application
* @physicalDevice Vulkan physical device to use for application
* @device Vulkan logical device to use for all base resources
* @physicalDeviceIndex Index for vulkan physical device used
* @param physicalDevice Vulkan physical device to use for application
* @param device Vulkan logical device to use for all base resources
* @param physicalDeviceIndex Index for vulkan physical device used
*/
Manager(std::shared_ptr<vk::Instance> instance,
std::shared_ptr<vk::PhysicalDevice> physicalDevice,
@ -62,6 +65,16 @@ class Manager
std::weak_ptr<Sequence> getOrCreateManagedSequence(
std::string sequenceName);
/**
* Create a new managed Kompute sequence so it's available within the manager.
*
* @param sequenceName The name for the named sequence to be created
* @param queueIndex The queue to use from the available queues
* @return Weak pointer to the manager owned sequence resource
*/
std::weak_ptr<Sequence> createManagedSequence(
std::string sequenceName, uint32_t queueIndex = 0);
/**
* Operation that adds extra operations to existing or new created
* sequences.
@ -114,7 +127,12 @@ class Manager
std::weak_ptr<Sequence> sqWeakPtr =
this->getOrCreateManagedSequence(sequenceName);
if (std::shared_ptr<kp::Sequence> sq = sqWeakPtr.lock()) {
std::unordered_map<std::string, std::shared_ptr<Sequence>>::iterator found =
this->mManagedSequences.find(sequenceName);
if (found == this->mManagedSequences.end()) {
std::shared_ptr<Sequence> sq = found->second;
SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence BEGIN");
sq->begin();
@ -127,6 +145,9 @@ class Manager
SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence EVAL");
sq->evalAsync();
}
else {
SPDLOG_ERROR("Kompute Manager evalOpAsync sequence [{}] not found", sequenceName);
}
SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence SUCCESS");
}
@ -154,7 +175,7 @@ class Manager
SPDLOG_DEBUG("Kompute Manager evalOpAwait running sequence SUCCESS");
}
else {
SPDLOG_ERROR("Sequence not found");
SPDLOG_ERROR("Kompute Manager evalOpAwait Sequence not found");
}
}
@ -209,7 +230,7 @@ class Manager
std::shared_ptr<vk::Device> mDevice = nullptr;
bool mFreeDevice = false;
uint32_t mComputeQueueFamilyIndex = -1;
std::shared_ptr<vk::Queue> mComputeQueue = nullptr;
std::vector<std::shared_ptr<vk::Queue>> mComputeQueues;
// -------------- ALWAYS OWNED RESOURCES
std::unordered_map<std::string, std::shared_ptr<Sequence>>
@ -224,7 +245,7 @@ class Manager
// Create functions
void createInstance();
void createDevice();
void createDevice(uint32_t totalComputeQueues);
};
} // End namespace kp