diff --git a/Makefile b/Makefile index 6583f0b55..44e3196d5 100644 --- a/Makefile +++ b/Makefile @@ -67,7 +67,7 @@ push_vulkan_docker: docker push axsauze/vulkan-sum:0.1 format: - $(CF) -i -style="{BasedOnStyle: mozilla, IndentWidth: 4}" src/*.cpp src/*.h src/*.hpp + $(CF) -i -style="{BasedOnStyle: mozilla, IndentWidth: 4}" src/*.cpp src/*.hpp src/*.h clean: rm ./bin/main.exe; diff --git a/src/Algorithm.hpp b/src/Algorithm.hpp index a340d76cb..4e697d878 100644 --- a/src/Algorithm.hpp +++ b/src/Algorithm.hpp @@ -4,14 +4,10 @@ namespace kp { class Algorithm { -private: - - -public: + private: + public: Algorithm(); virtual ~Algorithm(); }; } // End namespace kp - - diff --git a/src/BaseOp.cpp b/src/BaseOp.cpp index 922331b3c..c9421512f 100644 --- a/src/BaseOp.cpp +++ b/src/BaseOp.cpp @@ -10,29 +10,29 @@ namespace kp { -BaseOp::BaseOp() { +BaseOp::BaseOp() {} -} - -BaseOp::BaseOp(std::shared_ptr commandBuffer) { +BaseOp::BaseOp(std::shared_ptr commandBuffer) +{ SPDLOG_DEBUG("Compute BaseOp constructor started"); this->mCommandBuffer = commandBuffer; } -BaseOp::~BaseOp() { +BaseOp::~BaseOp() +{ SPDLOG_DEBUG("Compute BaseOp destructor started"); - } -void BaseOp::init(std::string one, std::string two) { +void +BaseOp::init(std::string one, std::string two) +{ SPDLOG_DEBUG("Compute BaseOp init started"); - } -void BaseOp::record() { +void +BaseOp::record() +{ SPDLOG_DEBUG("Compute BaseOp record started"); - } } - diff --git a/src/BaseOp.hpp b/src/BaseOp.hpp index 5e5cce439..b13e1f677 100644 --- a/src/BaseOp.hpp +++ b/src/BaseOp.hpp @@ -9,10 +9,8 @@ namespace kp { class BaseOp { -private: - - -public: + private: + public: BaseOp(); BaseOp(std::shared_ptr commandBuffer); virtual ~BaseOp(); @@ -20,11 +18,9 @@ public: void init(std::string one, std::string two); void record(); -private: + private: std::shared_ptr mDevice; std::shared_ptr mCommandBuffer; - }; } // End namespace kp - diff --git a/src/Manager.cpp b/src/Manager.cpp index c850213b8..857d5d68e 100644 --- a/src/Manager.cpp +++ b/src/Manager.cpp @@ -34,7 +34,8 @@ Manager::~Manager() SPDLOG_DEBUG("Kompute Manager Destructor started"); if (this->mDevice == nullptr) { - spdlog::error("Kompute Manager destructor reached with null Device pointer"); + spdlog::error( + "Kompute Manager destructor reached with null Device pointer"); return; } @@ -45,7 +46,8 @@ Manager::~Manager() } if (this->mInstance == nullptr) { - spdlog::error("Kompute Manager destructor reached with null Instance pointer"); + spdlog::error( + "Kompute Manager destructor reached with null Instance pointer"); return; } @@ -63,7 +65,9 @@ Manager::~Manager() } } -void Manager::createInstance() { +void +Manager::createInstance() +{ SPDLOG_DEBUG("Kompute Manager creating instance"); @@ -91,16 +95,14 @@ void Manager::createInstance() { // We'll identify the layers that are supported std::vector validLayerNames; std::vector desiredLayerNames = { - "VK_LAYER_LUNARG_assistant_layer", - "VK_LAYER_LUNARG_standard_validation" + "VK_LAYER_LUNARG_assistant_layer", "VK_LAYER_LUNARG_standard_validation" }; // Identify the valid layer names based on the desiredLayerNames { std::set uniqueLayerNames; std::vector availableLayerProperties = vk::enumerateInstanceLayerProperties(); - for (vk::LayerProperties layerProperties : - availableLayerProperties) { + for (vk::LayerProperties layerProperties : availableLayerProperties) { std::string layerName(layerProperties.layerName); uniqueLayerNames.insert(layerName); } @@ -114,13 +116,13 @@ void Manager::createInstance() { if (validLayerNames.size() > 0) { computeInstanceCreateInfo.enabledLayerCount = (uint32_t)validLayerNames.size(); - computeInstanceCreateInfo.ppEnabledLayerNames = - validLayerNames.data(); + computeInstanceCreateInfo.ppEnabledLayerNames = validLayerNames.data(); } #endif this->mInstance = std::make_shared(); - vk::createInstance(&computeInstanceCreateInfo, nullptr, this->mInstance.get()); + vk::createInstance( + &computeInstanceCreateInfo, nullptr, this->mInstance.get()); SPDLOG_DEBUG("Kompute Manager Instance Created"); #if DEBUG @@ -134,8 +136,7 @@ void Manager::createInstance() { (PFN_vkDebugReportCallbackEXT)debugMessageCallback; debugCreateInfo.flags = debugFlags; - this->mDebugDispatcher.init(*this->mInstance, - &vkGetInstanceProcAddr); + this->mDebugDispatcher.init(*this->mInstance, &vkGetInstanceProcAddr); this->mDebugReportCallback = this->mInstance->createDebugReportCallbackEXT( debugCreateInfo, nullptr, this->mDebugDispatcher); @@ -143,7 +144,9 @@ void Manager::createInstance() { #endif } -void Manager::createDevice() { +void +Manager::createDevice() +{ SPDLOG_DEBUG("Kompute Manager creating Device"); @@ -151,7 +154,8 @@ void Manager::createDevice() { throw std::runtime_error("Kompute Manager instance is null"); } if (this->mPhysicalDeviceIndex < 0) { - throw std::runtime_error("Kompute Manager physical device index not provided"); + throw std::runtime_error( + "Kompute Manager physical device index not provided"); } this->mFreeDevice = true; @@ -159,12 +163,15 @@ void Manager::createDevice() { std::vector physicalDevices = this->mInstance->enumeratePhysicalDevices(); - vk::PhysicalDevice physicalDevice = physicalDevices[this->mPhysicalDeviceIndex]; + vk::PhysicalDevice physicalDevice = + physicalDevices[this->mPhysicalDeviceIndex]; vk::PhysicalDeviceProperties physicalDeviceProperties = physicalDevice.getProperties(); - spdlog::info("Using physical device index {} found {}", this->mPhysicalDeviceIndex, physicalDeviceProperties.deviceName); + spdlog::info("Using physical device index {} found {}", + this->mPhysicalDeviceIndex, + physicalDeviceProperties.deviceName); // Find compute queue std::vector allQueueFamilyProperties = @@ -175,8 +182,7 @@ void Manager::createDevice() { vk::QueueFamilyProperties queueFamilyProperties = allQueueFamilyProperties[i]; - if (queueFamilyProperties.queueFlags & - vk::QueueFlagBits::eCompute) { + if (queueFamilyProperties.queueFlags & vk::QueueFlagBits::eCompute) { this->mComputeQueueFamilyIndex = i; break; } @@ -194,17 +200,18 @@ void Manager::createDevice() { defaultQueueCount, &defaultQueuePriority); - vk::DeviceCreateInfo deviceCreateInfo( - vk::DeviceCreateFlags(), - 1, // Number of deviceQueueCreateInfo - &deviceQueueCreateInfo); + vk::DeviceCreateInfo deviceCreateInfo(vk::DeviceCreateFlags(), + 1, // Number of deviceQueueCreateInfo + &deviceQueueCreateInfo); this->mDevice = std::make_shared(); - physicalDevice.createDevice(&deviceCreateInfo, nullptr, this->mDevice.get()); + physicalDevice.createDevice( + &deviceCreateInfo, nullptr, this->mDevice.get()); SPDLOG_DEBUG("Kompute Manager device created"); this->mComputeQueue = std::make_shared(); - this->mDevice->getQueue(this->mComputeQueueFamilyIndex, 0, this->mComputeQueue.get()); + this->mDevice->getQueue( + this->mComputeQueueFamilyIndex, 0, this->mComputeQueue.get()); SPDLOG_DEBUG("Kompute Manager compute queue obtained"); } diff --git a/src/Manager.hpp b/src/Manager.hpp index 7bee55acc..351754ec8 100644 --- a/src/Manager.hpp +++ b/src/Manager.hpp @@ -16,20 +16,22 @@ namespace kp { class Manager { -private: - -public: + private: + public: Manager(); - //Manager(std::shared_ptr instance, std::shared_ptr, uint32_t queueIndex); + // Manager(std::shared_ptr instance, + // std::shared_ptr, uint32_t queueIndex); ~Manager(); // Evaluate actions - template - void eval(TArgs&&... args) { + template + void eval(TArgs&&... args) + { SPDLOG_DEBUG("Kompute Manager eval triggered"); - Sequence sq(this->mDevice, this->mComputeQueue, this->mComputeQueueFamilyIndex); + Sequence sq( + this->mDevice, this->mComputeQueue, this->mComputeQueueFamilyIndex); SPDLOG_DEBUG("Kompute Manager created sequence"); sq.begin(); SPDLOG_DEBUG("Kompute Manager sequence begin"); @@ -41,8 +43,7 @@ public: SPDLOG_DEBUG("Kompute Manager sequence done"); } - -private: + private: std::shared_ptr mInstance = nullptr; bool mFreeInstance = false; uint32_t mPhysicalDeviceIndex = -1; @@ -62,4 +63,3 @@ private: }; } // End namespace kp - diff --git a/src/OpCreateTensor.cpp b/src/OpCreateTensor.cpp index 3d0583259..2d5354321 100644 --- a/src/OpCreateTensor.cpp +++ b/src/OpCreateTensor.cpp @@ -3,16 +3,13 @@ namespace kp { -OpCreateTensor::OpCreateTensor() { +OpCreateTensor::OpCreateTensor() {} -} - -OpCreateTensor::OpCreateTensor(std::shared_ptr commandBuffer) { +OpCreateTensor::OpCreateTensor(std::shared_ptr commandBuffer) +{ this->mCommandBuffer = commandBuffer; } -OpCreateTensor::~OpCreateTensor() { - -} +OpCreateTensor::~OpCreateTensor() {} } diff --git a/src/OpCreateTensor.hpp b/src/OpCreateTensor.hpp index dc3d01f86..f736f5b0d 100644 --- a/src/OpCreateTensor.hpp +++ b/src/OpCreateTensor.hpp @@ -14,22 +14,18 @@ namespace kp { -class OpCreateTensor: BaseOp +class OpCreateTensor : BaseOp { -private: - - -public: + private: + public: OpCreateTensor(); OpCreateTensor(std::shared_ptr commandBuffer); ~OpCreateTensor(); -private: - + private: std::shared_ptr mCommandBuffer; }; } // End namespace kp - diff --git a/src/OpMult.hpp b/src/OpMult.hpp index cfe1411c6..87c6b55b9 100644 --- a/src/OpMult.hpp +++ b/src/OpMult.hpp @@ -4,12 +4,10 @@ namespace kp { -class OpMult: BaseOp +class OpMult : BaseOp { -private: - - -public: + private: + public: OpMult(); virtual ~OpMult(); }; diff --git a/src/Parameter.hpp b/src/Parameter.hpp index ff1189682..a01a44a6c 100644 --- a/src/Parameter.hpp +++ b/src/Parameter.hpp @@ -4,10 +4,8 @@ namespace kp { class Parameter { -private: - - -public: + private: + public: Parameter(); virtual ~Parameter(); }; diff --git a/src/Sequence.cpp b/src/Sequence.cpp index aa1ed8d50..abb119195 100644 --- a/src/Sequence.cpp +++ b/src/Sequence.cpp @@ -3,12 +3,14 @@ namespace kp { -Sequence::Sequence() +Sequence::Sequence() { SPDLOG_DEBUG("Kompute Sequence base constructor"); } -Sequence::Sequence(std::shared_ptr device, std::shared_ptr computeQueue, uint32_t queueIndex) +Sequence::Sequence(std::shared_ptr device, + std::shared_ptr computeQueue, + uint32_t queueIndex) { SPDLOG_DEBUG("Kompute Sequence Constructor with existing device & queue"); @@ -20,27 +22,32 @@ Sequence::Sequence(std::shared_ptr device, std::shared_ptrcreateCommandBuffer(); } -Sequence::~Sequence() { +Sequence::~Sequence() +{ SPDLOG_DEBUG("Kompute Sequence Destructor started"); if (this->mDevice == nullptr) { - spdlog::error("Kompute Sequence destructor reached with null Device pointer"); + spdlog::error( + "Kompute Sequence destructor reached with null Device pointer"); return; } if (this->mCommandBuffer == nullptr) { - spdlog::error("Kompute Sequence destructor reached with null CommandPool pointer"); + spdlog::error( + "Kompute Sequence destructor reached with null CommandPool pointer"); return; } if (this->mFreeCommandBuffer) { spdlog::info("Freeing CommandBuffer"); - this->mDevice->freeCommandBuffers(*this->mCommandPool, 1, this->mCommandBuffer.get()); + this->mDevice->freeCommandBuffers( + *this->mCommandPool, 1, this->mCommandBuffer.get()); SPDLOG_DEBUG("Kompute Manager Freed CommandBuffer"); } if (this->mCommandPool == nullptr) { - spdlog::error("Kompute Sequence destructor reached with null CommandPool pointer"); + spdlog::error( + "Kompute Sequence destructor reached with null CommandPool pointer"); return; } @@ -49,10 +56,11 @@ Sequence::~Sequence() { this->mDevice->destroy(*this->mCommandPool); SPDLOG_DEBUG("Kompute Manager Destroyed CommandPool"); } - } -void Sequence::begin() { +void +Sequence::begin() +{ if (this->mCommandPool == nullptr) { throw std::runtime_error("Kompute Sequence command pool is null"); } @@ -61,13 +69,15 @@ void Sequence::begin() { spdlog::info("Kompute Sequence starting command recording"); this->mCommandBuffer->begin(vk::CommandBufferBeginInfo()); this->mRecording = true; - } - else { - spdlog::warn("Kompute Sequence attempted to start command recording but recording already started"); + } else { + spdlog::warn("Kompute Sequence attempted to start command recording " + "but recording already started"); } } -void Sequence::end() { +void +Sequence::end() +{ if (this->mCommandPool == nullptr) { throw std::runtime_error("Kompute Sequence command pool is null"); } @@ -76,20 +86,24 @@ void Sequence::end() { spdlog::info("Kompute Sequence ending command recording"); this->mCommandBuffer->end(); this->mRecording = false; - } - else { - spdlog::warn("Kompute Sequence attempted to end command recording but recording not started"); + } else { + spdlog::warn("Kompute Sequence attempted to end command recording but " + "recording not started"); } } -void Sequence::eval() { +void +Sequence::eval() +{ bool toggleSingleRecording = !this->mRecording; if (toggleSingleRecording) { this->begin(); } - const vk::PipelineStageFlags waitStageMask = vk::PipelineStageFlagBits::eTransfer; - vk::SubmitInfo submitInfo(0, nullptr, &waitStageMask, 1, this->mCommandBuffer.get()); + const vk::PipelineStageFlags waitStageMask = + vk::PipelineStageFlagBits::eTransfer; + vk::SubmitInfo submitInfo( + 0, nullptr, &waitStageMask, 1, this->mCommandBuffer.get()); vk::Fence fence = this->mDevice->createFence(vk::FenceCreateInfo()); this->mComputeQueue->submit(1, &submitInfo, fence); @@ -101,7 +115,9 @@ void Sequence::eval() { } } -void Sequence::createCommandPool() { +void +Sequence::createCommandPool() +{ SPDLOG_DEBUG("Kompute Sequence creating command pool"); if (this->mDevice == nullptr) { spdlog::info("cmdpoolinfo"); @@ -114,13 +130,17 @@ void Sequence::createCommandPool() { this->mFreeCommandPool = true; - vk::CommandPoolCreateInfo commandPoolInfo(vk::CommandPoolCreateFlags(), this->mQueueIndex); + vk::CommandPoolCreateInfo commandPoolInfo(vk::CommandPoolCreateFlags(), + this->mQueueIndex); this->mCommandPool = std::make_shared(); - this->mDevice->createCommandPool(&commandPoolInfo, nullptr, this->mCommandPool.get()); + this->mDevice->createCommandPool( + &commandPoolInfo, nullptr, this->mCommandPool.get()); SPDLOG_DEBUG("Kompute Manager Command Pool Created"); } -void Sequence::createCommandBuffer() { +void +Sequence::createCommandBuffer() +{ SPDLOG_DEBUG("Kompute Sequence creating command buffer"); if (this->mDevice == nullptr) { throw std::runtime_error("Kompute Sequence device is null"); @@ -131,10 +151,12 @@ void Sequence::createCommandBuffer() { this->mFreeCommandBuffer = true; - vk::CommandBufferAllocateInfo commandBufferAllocateInfo(*this->mCommandPool, vk::CommandBufferLevel::ePrimary, 1); + vk::CommandBufferAllocateInfo commandBufferAllocateInfo( + *this->mCommandPool, vk::CommandBufferLevel::ePrimary, 1); this->mCommandBuffer = std::make_shared(); - this->mDevice->allocateCommandBuffers(&commandBufferAllocateInfo, this->mCommandBuffer.get()); + this->mDevice->allocateCommandBuffers(&commandBufferAllocateInfo, + this->mCommandBuffer.get()); SPDLOG_DEBUG("Kompute Manager Command Buffer Created"); } diff --git a/src/Sequence.hpp b/src/Sequence.hpp index e88894864..bb68fac8e 100644 --- a/src/Sequence.hpp +++ b/src/Sequence.hpp @@ -14,11 +14,12 @@ namespace kp { class Sequence { -private: - -public: + private: + public: Sequence(); - Sequence(std::shared_ptr device, std::shared_ptr computeQueue, uint32_t queueIndex); + Sequence(std::shared_ptr device, + std::shared_ptr computeQueue, + uint32_t queueIndex); ~Sequence(); // Record command functions @@ -26,16 +27,16 @@ public: void end(); void eval(); - template - void record(TArgs&&... args) { + template + void record(TArgs&&... args) + { SPDLOG_DEBUG("Kompute Sequence record"); T op(this->mCommandBuffer); op.init(std::forward(args)...); op.record(); } - -private: + private: std::shared_ptr mDevice = nullptr; std::shared_ptr mComputeQueue = nullptr; uint32_t mQueueIndex = -1; @@ -50,8 +51,6 @@ private: // Create functions void createCommandPool(); void createCommandBuffer(); - }; } // End namespace kp - diff --git a/src/Tensor.hpp b/src/Tensor.hpp index b6880b913..88eb720e4 100644 --- a/src/Tensor.hpp +++ b/src/Tensor.hpp @@ -4,13 +4,10 @@ namespace kp { class Tensor { -private: - - -public: + private: + public: Tensor(); virtual ~Tensor(); }; } // End namespace kp - diff --git a/src/main.cpp b/src/main.cpp index 185a5a1ba..35ea7c747 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,8 +20,8 @@ #include #include -#include "Manager.hpp" #include "BaseOp.hpp" +#include "Manager.hpp" #define BUFFER_ELEMENTS 32 @@ -612,9 +612,9 @@ main() #endif try { - //VulkanCompute* vulkanExample = new VulkanCompute(); - //spdlog::info("Finished."); - //delete (vulkanExample); + // VulkanCompute* vulkanExample = new VulkanCompute(); + // spdlog::info("Finished."); + // delete (vulkanExample); // Run Kompute spdlog::info("Creating manager");