|
8 | 8 | #include "kompute/logger/Logger.hpp" |
9 | 9 | #include "shaders/Utils.hpp" |
10 | 10 |
|
| 11 | +namespace { |
| 12 | +std::vector<uint32_t> |
| 13 | +distinctFamilyQueueIndices(const vk::PhysicalDevice& device) |
| 14 | +{ |
| 15 | + const std::vector<vk::QueueFamilyProperties> allQueueFamilyProperties = |
| 16 | + device.getQueueFamilyProperties(); |
| 17 | + std::vector<uint32_t> distinctQueuesIndices; |
| 18 | + |
| 19 | + for (uint32_t i = 0; i < allQueueFamilyProperties.size(); i++) { |
| 20 | + if (allQueueFamilyProperties[i].queueFlags & |
| 21 | + (vk::QueueFlagBits::eCompute)) { |
| 22 | + distinctQueuesIndices.push_back(i); |
| 23 | + } |
| 24 | + } |
| 25 | + return distinctQueuesIndices; |
| 26 | +} |
| 27 | +} |
| 28 | + |
11 | 29 | TEST(TestAsyncOperations, TestManagerParallelExecution) |
12 | 30 | { |
13 | | - // This test is built for NVIDIA 1650. It assumes: |
14 | | - // * Queue family 0 and 2 have compute capabilities |
| 31 | + // This test assumes: |
| 32 | + // * There are at least 2 different Queue families with compute capabilities |
15 | 33 | // * GPU is able to process parallel shader code across different families |
16 | | - uint32_t size = 10; |
| 34 | + constexpr uint32_t size = 10; |
17 | 35 |
|
18 | | - uint32_t numParallel = 2; |
| 36 | + constexpr uint32_t numParallel = 2; |
19 | 37 |
|
20 | 38 | std::string shader(R"( |
21 | 39 | #version 450 |
@@ -79,7 +97,18 @@ TEST(TestAsyncOperations, TestManagerParallelExecution) |
79 | 97 | EXPECT_EQ(inputsSyncB[i]->vector<float>(), resultSync); |
80 | 98 | } |
81 | 99 |
|
82 | | - kp::Manager mgrAsync(0, { 0, 2 }); |
| 100 | + constexpr uint32_t deviceId = |
| 101 | + 0u; // device 0 exists, because "mgr" could be created already |
| 102 | + auto queues = distinctFamilyQueueIndices( |
| 103 | + mgr.getVkInstance()->enumeratePhysicalDevices().at(deviceId)); |
| 104 | + if (queues.size() < numParallel) { |
| 105 | + GTEST_SKIP() << "GPU does not support multiple compute queues. Only " |
| 106 | + << queues.size() << " are supported. Skipping test."; |
| 107 | + } |
| 108 | + |
| 109 | + queues.resize(numParallel); |
| 110 | + |
| 111 | + kp::Manager mgrAsync(deviceId, std::move(queues)); |
83 | 112 |
|
84 | 113 | std::vector<std::shared_ptr<kp::Memory>> inputsAsyncB; |
85 | 114 |
|
|
0 commit comments