From 9a64339e953c8eb23c7a2a1d39fb7f0f5a4a4e67 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sat, 17 Oct 2020 11:19:25 +0100 Subject: [PATCH] Reformatted --- src/Algorithm.cpp | 3 +- src/Manager.cpp | 39 ++++++++++--------- src/Sequence.cpp | 9 +++-- src/include/kompute/Core.hpp | 17 ++++++--- src/include/kompute/Manager.hpp | 58 +++++++++++++++-------------- src/include/kompute/Sequence.hpp | 10 +++-- test/TestAsyncOperations.cpp | 19 ++++++---- test/TestMultipleAlgoExecutions.cpp | 12 +++--- 8 files changed, 95 insertions(+), 72 deletions(-) mode change 100755 => 100644 src/Manager.cpp mode change 100755 => 100644 test/TestAsyncOperations.cpp diff --git a/src/Algorithm.cpp b/src/Algorithm.cpp index 0138201c7..845036475 100644 --- a/src/Algorithm.cpp +++ b/src/Algorithm.cpp @@ -266,8 +266,7 @@ Algorithm::createPipeline(std::vector specializationData) #ifdef KOMPUTE_CREATE_PIPELINE_RESULT_VALUE vk::ResultValue pipelineResult = - this->mDevice->createComputePipeline(*this->mPipelineCache, -pipelineInfo); + this->mDevice->createComputePipeline(*this->mPipelineCache, pipelineInfo); if (pipelineResult.result != vk::Result::eSuccess) { throw std::runtime_error("Failed to create pipeline result: " + diff --git a/src/Manager.cpp b/src/Manager.cpp old mode 100755 new mode 100644 index 7e5cc831a..b2739d6be --- a/src/Manager.cpp +++ b/src/Manager.cpp @@ -28,7 +28,8 @@ Manager::Manager() : Manager(0) {} -Manager::Manager(uint32_t physicalDeviceIndex, const std::vector & familyQueueIndeces) +Manager::Manager(uint32_t physicalDeviceIndex, + const std::vector& familyQueueIndeces) { this->mPhysicalDeviceIndex = physicalDeviceIndex; @@ -105,9 +106,13 @@ Manager::getOrCreateManagedSequence(std::string sequenceName) } std::weak_ptr -Manager::createManagedSequence(std::string sequenceName, uint32_t queueIndex) { +Manager::createManagedSequence(std::string sequenceName, uint32_t queueIndex) +{ - SPDLOG_DEBUG("Kompute Manager createManagedSequence with sequenceName: {} and queueIndex: {}", sequenceName, queueIndex); + SPDLOG_DEBUG("Kompute Manager createManagedSequence with sequenceName: {} " + "and queueIndex: {}", + sequenceName, + queueIndex); std::shared_ptr sq = std::make_shared(this->mPhysicalDevice, @@ -205,7 +210,7 @@ Manager::createInstance() } void -Manager::createDevice(const std::vector & familyQueueIndeces) +Manager::createDevice(const std::vector& familyQueueIndeces) { SPDLOG_DEBUG("Kompute Manager creating Device"); @@ -246,7 +251,8 @@ Manager::createDevice(const std::vector & familyQueueIndeces) vk::QueueFamilyProperties queueFamilyProperties = allQueueFamilyProperties[i]; - if (queueFamilyProperties.queueFlags & vk::QueueFlagBits::eCompute) { + if (queueFamilyProperties.queueFlags & + vk::QueueFlagBits::eCompute) { computeQueueFamilyIndex = i; break; } @@ -257,8 +263,7 @@ Manager::createDevice(const std::vector & familyQueueIndeces) } this->mComputeQueueFamilyIndeces.push_back(computeQueueFamilyIndex); - } - else { + } else { this->mComputeQueueFamilyIndeces = familyQueueIndeces; } @@ -277,28 +282,28 @@ Manager::createDevice(const std::vector & familyQueueIndeces) // Creating the respective device queue vk::DeviceQueueCreateInfo deviceQueueCreateInfo( - vk::DeviceQueueCreateFlags(), - familyQueueInfo.first, - familyQueueInfo.second, - familyQueuePriorities[familyQueueInfo.first].data()); + vk::DeviceQueueCreateFlags(), + familyQueueInfo.first, + familyQueueInfo.second, + familyQueuePriorities[familyQueueInfo.first].data()); deviceQueueCreateInfos.push_back(deviceQueueCreateInfo); } vk::DeviceCreateInfo deviceCreateInfo(vk::DeviceCreateFlags(), - deviceQueueCreateInfos.size(), - deviceQueueCreateInfos.data()); + deviceQueueCreateInfos.size(), + deviceQueueCreateInfos.data()); this->mDevice = std::make_shared(); physicalDevice.createDevice( &deviceCreateInfo, nullptr, this->mDevice.get()); SPDLOG_DEBUG("Kompute Manager device created"); - for (const uint32_t & familyQueueIndex : this->mComputeQueueFamilyIndeces) - { + for (const uint32_t& familyQueueIndex : this->mComputeQueueFamilyIndeces) { std::shared_ptr currQueue = std::make_shared(); - this->mDevice->getQueue( - familyQueueIndex, familyQueueIndexCount[familyQueueIndex], currQueue.get()); + this->mDevice->getQueue(familyQueueIndex, + familyQueueIndexCount[familyQueueIndex], + currQueue.get()); familyQueueIndexCount[familyQueueIndex]++; diff --git a/src/Sequence.cpp b/src/Sequence.cpp index 1496e67d9..a03a34afe 100644 --- a/src/Sequence.cpp +++ b/src/Sequence.cpp @@ -141,7 +141,8 @@ Sequence::evalAsync() return false; } if (this->mIsRunning) { - SPDLOG_WARN("Kompute Sequence evalAsync called when an eval async was called without successful wait"); + SPDLOG_WARN("Kompute Sequence evalAsync called when an eval async was " + "called without successful wait"); return false; } @@ -172,7 +173,8 @@ Sequence::evalAwait(uint64_t waitFor) return false; } - vk::Result result = this->mDevice->waitForFences(1, &this->mFence, VK_TRUE, waitFor); + vk::Result result = + this->mDevice->waitForFences(1, &this->mFence, VK_TRUE, waitFor); this->mDevice->destroy(this->mFence); if (result == vk::Result::eTimeout) { @@ -191,7 +193,8 @@ Sequence::evalAwait(uint64_t waitFor) } bool -Sequence::isRunning() { +Sequence::isRunning() +{ return this->mIsRunning; } diff --git a/src/include/kompute/Core.hpp b/src/include/kompute/Core.hpp index dfa83d7a5..72ffa5346 100644 --- a/src/include/kompute/Core.hpp +++ b/src/include/kompute/Core.hpp @@ -18,10 +18,11 @@ static const char* KOMPUTE_LOG_TAG = "KomputeLog"; #ifndef KOMPUTE_VK_API_MINOR_VERSION #define KOMPUTE_VK_API_MINOR_VERSION 1 #endif // KOMPUTE_VK_API_MINOR_VERSION -#define KOMPUTE_VK_API_VERSION VK_MAKE_VERSION(KOMPUTE_VK_API_MAJOR_VERSION, KOMPUTE_VK_API_MINOR_VERSION, 0) +#define KOMPUTE_VK_API_VERSION \ + VK_MAKE_VERSION( \ + KOMPUTE_VK_API_MAJOR_VERSION, KOMPUTE_VK_API_MINOR_VERSION, 0) #endif // KOMPUTE_VK_API_VERSION - // SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import #if !defined(SPDLOG_ACTIVE_LEVEL) #if DEBUG @@ -40,7 +41,8 @@ static const char* KOMPUTE_LOG_TAG = "KomputeLog"; #define SPDLOG_DEBUG(message, ...) #else #if defined(VK_USE_PLATFORM_ANDROID_KHR) -#define SPDLOG_DEBUG(message, ...) ((void)__android_log_print(ANDROID_LOG_DEBUG, KOMPUTE_LOG_TAG, message)) +#define SPDLOG_DEBUG(message, ...) \ + ((void)__android_log_print(ANDROID_LOG_DEBUG, KOMPUTE_LOG_TAG, message)) #else #define SPDLOG_DEBUG(message, ...) \ std::cout << "DEBUG: " << message << std::endl @@ -50,7 +52,8 @@ static const char* KOMPUTE_LOG_TAG = "KomputeLog"; #define SPDLOG_INFO(message, ...) #else #if defined(VK_USE_PLATFORM_ANDROID_KHR) -#define SPDLOG_INFO(message, ...) ((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, message)) +#define SPDLOG_INFO(message, ...) \ + ((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, message)) #else #define SPDLOG_INFO(message, ...) std::cout << "INFO: " << message << std::endl #endif // VK_USE_PLATFORM_ANDROID_KHR @@ -59,7 +62,8 @@ static const char* KOMPUTE_LOG_TAG = "KomputeLog"; #define SPDLOG_WARN(message, ...) #else #if defined(VK_USE_PLATFORM_ANDROID_KHR) -#define SPDLOG_WARN(message, ...) ((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, message)) +#define SPDLOG_WARN(message, ...) \ + ((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, message)) #else #define SPDLOG_WARN(message, ...) \ std::cout << "WARNING: " << message << std::endl @@ -69,7 +73,8 @@ static const char* KOMPUTE_LOG_TAG = "KomputeLog"; #define SPDLOG_ERROR(message, ...) #else #if defined(VK_USE_PLATFORM_ANDROID_KHR) -#define SPDLOG_ERROR(message, ...) ((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, message)) +#define SPDLOG_ERROR(message, ...) \ + ((void)__android_log_print(ANDROID_LOG_INFO, KOMPUTE_LOG_TAG, message)) #else #define SPDLOG_ERROR(message, ...) \ std::cout << "ERROR: " << message << std::endl diff --git a/src/include/kompute/Manager.hpp b/src/include/kompute/Manager.hpp index 2581139d9..650da5ca0 100644 --- a/src/include/kompute/Manager.hpp +++ b/src/include/kompute/Manager.hpp @@ -17,7 +17,7 @@ namespace kp { */ class Manager { -public: + public: /** Base constructor and default used which creates the base resources including choosing the device 0 by default. @@ -25,14 +25,16 @@ public: Manager(); /** - * 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 familyQueueIndeces (Optional) List of queue indeces to add for explicit allocation - * @param totalQueues The total number of compute queues to create. - */ - Manager(uint32_t physicalDeviceIndex, const std::vector & familyQueueIndeces = {}); + * 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 familyQueueIndeces (Optional) List of queue indeces to add for + * explicit allocation + * @param totalQueues The total number of compute queues to create. + */ + Manager(uint32_t physicalDeviceIndex, + const std::vector& familyQueueIndeces = {}); /** * Manager constructor which allows your own vulkan application to integrate @@ -67,14 +69,15 @@ public: std::string sequenceName); /** - * Create a new managed Kompute sequence so it's available within the manager. + * 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 createManagedSequence( - std::string sequenceName, uint32_t queueIndex = 0); + std::weak_ptr createManagedSequence(std::string sequenceName, + uint32_t queueIndex = 0); /** * Operation that adds extra operations to existing or new created @@ -121,15 +124,15 @@ public: */ template void evalOpAsync(std::vector> tensors, - std::string sequenceName, - TArgs&&... params) + std::string sequenceName, + TArgs&&... params) { SPDLOG_DEBUG("Kompute Manager evalOpAsync triggered"); std::weak_ptr sqWeakPtr = this->getOrCreateManagedSequence(sequenceName); - std::unordered_map>::iterator found = - this->mManagedSequences.find(sequenceName); + std::unordered_map>::iterator + found = this->mManagedSequences.find(sequenceName); if (found != this->mManagedSequences.end()) { std::shared_ptr sq = found->second; @@ -145,9 +148,9 @@ public: SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence EVAL"); sq->evalAsync(); - } - else { - SPDLOG_ERROR("Kompute Manager evalOpAsync sequence [{}] not found", sequenceName); + } else { + SPDLOG_ERROR("Kompute Manager evalOpAsync sequence [{}] not found", + sequenceName); } SPDLOG_DEBUG("Kompute Manager evalOpAsync running sequence SUCCESS"); } @@ -163,21 +166,22 @@ public: void evalOpAwait(std::string sequenceName, uint64_t waitFor = UINT64_MAX) { SPDLOG_DEBUG("Kompute Manager evalOpAwait triggered"); - std::unordered_map>::iterator found = - this->mManagedSequences.find(sequenceName); + std::unordered_map>::iterator + found = this->mManagedSequences.find(sequenceName); if (found != this->mManagedSequences.end()) { if (std::shared_ptr sq = found->second) { - SPDLOG_DEBUG("Kompute Manager evalOpAwait running sequence Sequence EVAL AWAIT"); + SPDLOG_DEBUG("Kompute Manager evalOpAwait running sequence " + "Sequence EVAL AWAIT"); if (sq->isRunning()) { sq->evalAwait(waitFor); } } - SPDLOG_DEBUG("Kompute Manager evalOpAwait running sequence SUCCESS"); - } - else { + SPDLOG_DEBUG( + "Kompute Manager evalOpAwait running sequence SUCCESS"); + } else { SPDLOG_ERROR("Kompute Manager evalOpAwait Sequence not found"); - } + } } /** @@ -247,7 +251,7 @@ public: // Create functions void createInstance(); - void createDevice(const std::vector & familyQueueIndeces = {}); + void createDevice(const std::vector& familyQueueIndeces = {}); }; } // End namespace kp diff --git a/src/include/kompute/Sequence.hpp b/src/include/kompute/Sequence.hpp index 2d9ef8e51..314de6657 100644 --- a/src/include/kompute/Sequence.hpp +++ b/src/include/kompute/Sequence.hpp @@ -67,14 +67,17 @@ class Sequence bool eval(); /** - * Eval Async sends all the recorded and stored operations in the vector of operations into the gpu as a submit job with a barrier. EvalAwait() must be called after to ensure the sequence is terminated correctly. + * Eval Async sends all the recorded and stored operations in the vector of + * operations into the gpu as a submit job with a barrier. EvalAwait() must + * be called after to ensure the sequence is terminated correctly. * * @return Boolean stating whether execution was successful. */ bool evalAsync(); /** - * Eval Await waits for the fence to finish processing and then once it finishes, it runs the postEval of all operations. + * Eval Await waits for the fence to finish processing and then once it + * finishes, it runs the postEval of all operations. * * @param waitFor Number of milliseconds to wait before timing out. * @return Boolean stating whether execution was successful. @@ -89,7 +92,8 @@ class Sequence bool isRecording(); /** - * Returns true if the sequence is currently running - mostly used for async workloads. + * Returns true if the sequence is currently running - mostly used for async + * workloads. * * @return Boolean stating if currently running. */ diff --git a/test/TestAsyncOperations.cpp b/test/TestAsyncOperations.cpp old mode 100755 new mode 100644 index b9e84e1b5..28dd8c144 --- a/test/TestAsyncOperations.cpp +++ b/test/TestAsyncOperations.cpp @@ -72,13 +72,14 @@ TEST(TestAsyncOperations, TestManagerAsync) for (uint32_t i = 0; i < numParallel; i++) { mgr.evalOpDefault>( - { inputsSyncA[i], inputsSyncB[i] }, + { inputsSyncA[i], inputsSyncB[i] }, std::vector(shader.begin(), shader.end())); - } auto endSync = std::chrono::high_resolution_clock::now(); - auto durationSync = std::chrono::duration_cast(endSync - startSync).count(); + auto durationSync = + std::chrono::duration_cast(endSync - startSync) + .count(); mgr.evalOpDefault(inputsSyncB); @@ -86,7 +87,7 @@ TEST(TestAsyncOperations, TestManagerAsync) EXPECT_EQ(inputsSyncB[i]->data(), resultSync); } - kp::Manager mgrAsync(0, {0, 2}); + kp::Manager mgrAsync(0, { 0, 2 }); std::vector> inputsAsyncA; std::vector> inputsAsyncB; @@ -107,8 +108,8 @@ TEST(TestAsyncOperations, TestManagerAsync) for (uint32_t i = 0; i < numParallel; i++) { mgrAsync.evalOpAsync>( - { inputsAsyncA[i], inputsAsyncB[i] }, - "async" + std::to_string(i), + { inputsAsyncA[i], inputsAsyncB[i] }, + "async" + std::to_string(i), std::vector(shader.begin(), shader.end())); } @@ -117,7 +118,9 @@ TEST(TestAsyncOperations, TestManagerAsync) } auto endAsync = std::chrono::high_resolution_clock::now(); - auto durationAsync = std::chrono::duration_cast(endAsync - startAsync).count(); + auto durationAsync = std::chrono::duration_cast( + endAsync - startAsync) + .count(); mgrAsync.evalOpDefault({ inputsAsyncB }); @@ -128,6 +131,6 @@ TEST(TestAsyncOperations, TestManagerAsync) SPDLOG_ERROR("sync {}", durationSync); SPDLOG_ERROR("async {}", durationAsync); - // The speedup should be at least 40% + // The speedup should be at least 40% EXPECT_LT(durationAsync, durationSync * 0.6); } diff --git a/test/TestMultipleAlgoExecutions.cpp b/test/TestMultipleAlgoExecutions.cpp index fb0803690..1b59d3516 100644 --- a/test/TestMultipleAlgoExecutions.cpp +++ b/test/TestMultipleAlgoExecutions.cpp @@ -258,10 +258,10 @@ TEST(TestMultipleAlgoExecutions, ManagerEvalMultSourceStrOpCreate) )"); mgr.evalOpDefault>( - { tensorInA, tensorInB, tensorOut }, - std::vector(shader.begin(), shader.end())); + { tensorInA, tensorInB, tensorOut }, + std::vector(shader.begin(), shader.end())); - mgr.evalOpDefault({tensorOut}); + mgr.evalOpDefault({ tensorOut }); EXPECT_EQ(tensorOut->data(), std::vector({ 0.0, 4.0, 12.0 })); } @@ -295,10 +295,10 @@ TEST(TestMultipleAlgoExecutions, ManagerEvalMultSourceStrMgrCreate) )"); mgr.evalOpDefault>( - { tensorInA, tensorInB, tensorOut }, - std::vector(shader.begin(), shader.end())); + { tensorInA, tensorInB, tensorOut }, + std::vector(shader.begin(), shader.end())); - mgr.evalOpDefault({tensorOut}); + mgr.evalOpDefault({ tensorOut }); EXPECT_EQ(tensorOut->data(), std::vector({ 0.0, 4.0, 12.0 })); }