Reformatted

This commit is contained in:
Alejandro Saucedo 2020-08-17 07:58:23 +01:00
parent 49b436f490
commit 93041b4519
14 changed files with 133 additions and 127 deletions

View file

@ -4,14 +4,10 @@ namespace kp {
class Algorithm
{
private:
public:
private:
public:
Algorithm();
virtual ~Algorithm();
};
} // End namespace kp

View file

@ -10,29 +10,29 @@
namespace kp {
BaseOp::BaseOp() {
BaseOp::BaseOp() {}
}
BaseOp::BaseOp(std::shared_ptr<vk::CommandBuffer> commandBuffer) {
BaseOp::BaseOp(std::shared_ptr<vk::CommandBuffer> 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");
}
}

View file

@ -9,10 +9,8 @@ namespace kp {
class BaseOp
{
private:
public:
private:
public:
BaseOp();
BaseOp(std::shared_ptr<vk::CommandBuffer> commandBuffer);
virtual ~BaseOp();
@ -20,11 +18,9 @@ public:
void init(std::string one, std::string two);
void record();
private:
private:
std::shared_ptr<vk::Device> mDevice;
std::shared_ptr<vk::CommandBuffer> mCommandBuffer;
};
} // End namespace kp

View file

@ -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<const char*> validLayerNames;
std::vector<const char*> 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<std::string> uniqueLayerNames;
std::vector<vk::LayerProperties> 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::Instance>();
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<vk::PhysicalDevice> 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<vk::QueueFamilyProperties> 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<vk::Device>();
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<vk::Queue>();
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");
}

View file

@ -16,20 +16,22 @@ namespace kp {
class Manager
{
private:
public:
private:
public:
Manager();
//Manager(std::shared_ptr<vk::Instance> instance, std::shared_ptr<vk::Device>, uint32_t queueIndex);
// Manager(std::shared_ptr<vk::Instance> instance,
// std::shared_ptr<vk::Device>, uint32_t queueIndex);
~Manager();
// Evaluate actions
template <typename T, typename... TArgs>
void eval(TArgs&&... args) {
template<typename T, typename... TArgs>
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<vk::Instance> mInstance = nullptr;
bool mFreeInstance = false;
uint32_t mPhysicalDeviceIndex = -1;
@ -62,4 +63,3 @@ private:
};
} // End namespace kp

View file

@ -3,16 +3,13 @@
namespace kp {
OpCreateTensor::OpCreateTensor() {
OpCreateTensor::OpCreateTensor() {}
}
OpCreateTensor::OpCreateTensor(std::shared_ptr<vk::CommandBuffer> commandBuffer) {
OpCreateTensor::OpCreateTensor(std::shared_ptr<vk::CommandBuffer> commandBuffer)
{
this->mCommandBuffer = commandBuffer;
}
OpCreateTensor::~OpCreateTensor() {
}
OpCreateTensor::~OpCreateTensor() {}
}

View file

@ -14,22 +14,18 @@
namespace kp {
class OpCreateTensor: BaseOp
class OpCreateTensor : BaseOp
{
private:
public:
private:
public:
OpCreateTensor();
OpCreateTensor(std::shared_ptr<vk::CommandBuffer> commandBuffer);
~OpCreateTensor();
private:
private:
std::shared_ptr<vk::CommandBuffer> mCommandBuffer;
};
} // End namespace kp

View file

@ -4,12 +4,10 @@
namespace kp {
class OpMult: BaseOp
class OpMult : BaseOp
{
private:
public:
private:
public:
OpMult();
virtual ~OpMult();
};

View file

@ -4,10 +4,8 @@ namespace kp {
class Parameter
{
private:
public:
private:
public:
Parameter();
virtual ~Parameter();
};

View file

@ -3,12 +3,14 @@
namespace kp {
Sequence::Sequence()
Sequence::Sequence()
{
SPDLOG_DEBUG("Kompute Sequence base constructor");
}
Sequence::Sequence(std::shared_ptr<vk::Device> device, std::shared_ptr<vk::Queue> computeQueue, uint32_t queueIndex)
Sequence::Sequence(std::shared_ptr<vk::Device> device,
std::shared_ptr<vk::Queue> computeQueue,
uint32_t queueIndex)
{
SPDLOG_DEBUG("Kompute Sequence Constructor with existing device & queue");
@ -20,27 +22,32 @@ Sequence::Sequence(std::shared_ptr<vk::Device> device, std::shared_ptr<vk::Queue
this->createCommandBuffer();
}
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<vk::CommandPool>();
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<vk::CommandBuffer>();
this->mDevice->allocateCommandBuffers(&commandBufferAllocateInfo, this->mCommandBuffer.get());
this->mDevice->allocateCommandBuffers(&commandBufferAllocateInfo,
this->mCommandBuffer.get());
SPDLOG_DEBUG("Kompute Manager Command Buffer Created");
}

View file

@ -14,11 +14,12 @@ namespace kp {
class Sequence
{
private:
public:
private:
public:
Sequence();
Sequence(std::shared_ptr<vk::Device> device, std::shared_ptr<vk::Queue> computeQueue, uint32_t queueIndex);
Sequence(std::shared_ptr<vk::Device> device,
std::shared_ptr<vk::Queue> computeQueue,
uint32_t queueIndex);
~Sequence();
// Record command functions
@ -26,16 +27,16 @@ public:
void end();
void eval();
template <typename T, typename...TArgs>
void record(TArgs&&... args) {
template<typename T, typename... TArgs>
void record(TArgs&&... args)
{
SPDLOG_DEBUG("Kompute Sequence record");
T op(this->mCommandBuffer);
op.init(std::forward<TArgs>(args)...);
op.record();
}
private:
private:
std::shared_ptr<vk::Device> mDevice = nullptr;
std::shared_ptr<vk::Queue> mComputeQueue = nullptr;
uint32_t mQueueIndex = -1;
@ -50,8 +51,6 @@ private:
// Create functions
void createCommandPool();
void createCommandBuffer();
};
} // End namespace kp

View file

@ -4,13 +4,10 @@ namespace kp {
class Tensor
{
private:
public:
private:
public:
Tensor();
virtual ~Tensor();
};
} // End namespace kp

View file

@ -20,8 +20,8 @@
#include <vulkan/vulkan.h>
#include <vulkan/vulkan.hpp>
#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");