diff --git a/src/Algorithm.cpp b/src/Algorithm.cpp index 11447ca8..f5d10727 100644 --- a/src/Algorithm.cpp +++ b/src/Algorithm.cpp @@ -134,31 +134,26 @@ Algorithm::createParameters() KP_LOG_DEBUG("Kompute Algorithm createParameters started"); for (const std::shared_ptr& mem : this->mMemObjects) { - if (mem->type() == Memory::Type::eImage) { - numImages++; - } - else { - numTensors++; - } + if (mem->type() == Memory::Type::eImage) { + numImages++; + } else { + numTensors++; + } } std::vector descriptorPoolSizes; - - if (numTensors > 0) - { - descriptorPoolSizes.push_back( - vk::DescriptorPoolSize( + + if (numTensors > 0) { + descriptorPoolSizes.push_back(vk::DescriptorPoolSize( vk::DescriptorType::eStorageBuffer, static_cast(numTensors) // Descriptor count )); } - if (numImages > 0) - { - descriptorPoolSizes.push_back( - vk::DescriptorPoolSize( - vk::DescriptorType::eStorageImage, - static_cast(numImages) // Descriptor count + if (numImages > 0) { + descriptorPoolSizes.push_back(vk::DescriptorPoolSize( + vk::DescriptorType::eStorageImage, + static_cast(numImages) // Descriptor count )); }; diff --git a/src/Image.cpp b/src/Image.cpp index 132026b0..0fbe7392 100644 --- a/src/Image.cpp +++ b/src/Image.cpp @@ -21,14 +21,16 @@ Image::init(void* data, "Kompute Image attempted to create an image with no channels"); } - if (data != nullptr && dataSize < this->getX() * this->getY() * numChannels) { + if (data != nullptr && + dataSize < this->getX() * this->getY() * numChannels) { throw std::runtime_error( "Kompute Image data is smaller than the requested image size"); } if (numChannels > 4 || numChannels == 3) { - // We don't support 3-channel images because they are not supported by Metal or Mesa (llvmpipe) - // See comment here: https://github.com/KomputeProject/kompute/pull/388#discussion_r1720959531 + // We don't support 3-channel images because they are not supported by + // Metal or Mesa (llvmpipe) See comment here: + // https://github.com/KomputeProject/kompute/pull/388#discussion_r1720959531 throw std::runtime_error( "Kompute Images can only have up to 1, 2 or 4 channels"); } @@ -92,9 +94,9 @@ Image::recordCopyFrom(const vk::CommandBuffer& commandBuffer, vk::Offset3D offset = { 0, 0, 0 }; if (this->getX() != copyFromImage->getX() || - this->getY() != copyFromImage->getY()) - { - throw std::runtime_error("Kompute Image recordCopyFrom image sizes do not match"); + this->getY() != copyFromImage->getY()) { + throw std::runtime_error( + "Kompute Image recordCopyFrom image sizes do not match"); } vk::Extent3D size = { this->getX(), this->getY(), 1 }; @@ -105,12 +107,12 @@ Image::recordCopyFrom(const vk::CommandBuffer& commandBuffer, "Kompute Image recordCopyFrom size {},{}.", size.width, size.height); copyFromImage->recordPrimaryImageBarrier( - commandBuffer, - vk::AccessFlagBits::eMemoryRead, - vk::AccessFlagBits::eMemoryWrite, - vk::PipelineStageFlagBits::eTransfer, - vk::PipelineStageFlagBits::eTransfer, - vk::ImageLayout::eTransferSrcOptimal); + commandBuffer, + vk::AccessFlagBits::eMemoryRead, + vk::AccessFlagBits::eMemoryWrite, + vk::PipelineStageFlagBits::eTransfer, + vk::PipelineStageFlagBits::eTransfer, + vk::ImageLayout::eTransferSrcOptimal); this->recordPrimaryImageBarrier(commandBuffer, vk::AccessFlagBits::eMemoryRead, @@ -172,21 +174,25 @@ Image::recordCopyFromStagingToDevice(const vk::CommandBuffer& commandBuffer) KP_LOG_DEBUG("Kompute Image copying size {},{}.", size.width, size.height); this->recordStagingImageBarrier(commandBuffer, - vk::AccessFlagBits::eMemoryRead, - vk::AccessFlagBits::eMemoryWrite, - vk::PipelineStageFlagBits::eTransfer, - vk::PipelineStageFlagBits::eTransfer, - vk::ImageLayout::eTransferSrcOptimal); + vk::AccessFlagBits::eMemoryRead, + vk::AccessFlagBits::eMemoryWrite, + vk::PipelineStageFlagBits::eTransfer, + vk::PipelineStageFlagBits::eTransfer, + vk::ImageLayout::eTransferSrcOptimal); this->recordPrimaryImageBarrier(commandBuffer, - vk::AccessFlagBits::eMemoryRead, - vk::AccessFlagBits::eMemoryWrite, - vk::PipelineStageFlagBits::eTransfer, - vk::PipelineStageFlagBits::eTransfer, - vk::ImageLayout::eTransferDstOptimal); - - this->recordCopyImage( - commandBuffer, this->mStagingImage, this->mPrimaryImage, this->mStagingImageLayout, this->mPrimaryImageLayout, copyRegion); + vk::AccessFlagBits::eMemoryRead, + vk::AccessFlagBits::eMemoryWrite, + vk::PipelineStageFlagBits::eTransfer, + vk::PipelineStageFlagBits::eTransfer, + vk::ImageLayout::eTransferDstOptimal); + + this->recordCopyImage(commandBuffer, + this->mStagingImage, + this->mPrimaryImage, + this->mStagingImageLayout, + this->mPrimaryImageLayout, + copyRegion); } void @@ -217,8 +223,12 @@ Image::recordCopyFromDeviceToStaging(const vk::CommandBuffer& commandBuffer) vk::PipelineStageFlagBits::eTransfer, vk::ImageLayout::eTransferDstOptimal); - this->recordCopyImage( - commandBuffer, this->mPrimaryImage, this->mStagingImage, this->mPrimaryImageLayout, this->mStagingImageLayout, copyRegion); + this->recordCopyImage(commandBuffer, + this->mPrimaryImage, + this->mStagingImage, + this->mPrimaryImageLayout, + this->mStagingImageLayout, + copyRegion); } void @@ -229,12 +239,8 @@ Image::recordCopyImage(const vk::CommandBuffer& commandBuffer, vk::ImageLayout dstLayout, vk::ImageCopy copyRegion) { - commandBuffer.copyImage(*srcImage, - srcLayout, - *dstImage, - dstLayout, - 1, - ©Region); + commandBuffer.copyImage( + *srcImage, srcLayout, *dstImage, dstLayout, 1, ©Region); } void @@ -254,7 +260,7 @@ Image::recordPrimaryMemoryBarrier(const vk::CommandBuffer& commandBuffer, vk::AccessFlagBits dstAccessMask, vk::PipelineStageFlagBits srcStageMask, vk::PipelineStageFlagBits dstStageMask) -{ +{ vk::ImageLayout dstImageLayout; // Ideally the image would be set to eGeneral as soon as it was created @@ -267,11 +273,11 @@ Image::recordPrimaryMemoryBarrier(const vk::CommandBuffer& commandBuffer, dstImageLayout = this->mPrimaryImageLayout; this->recordPrimaryImageBarrier(commandBuffer, - srcAccessMask, - dstAccessMask, - srcStageMask, - dstStageMask, - dstImageLayout); + srcAccessMask, + dstAccessMask, + srcStageMask, + dstStageMask, + dstImageLayout); } void @@ -293,20 +299,20 @@ Image::recordStagingMemoryBarrier(const vk::CommandBuffer& commandBuffer, dstImageLayout = this->mStagingImageLayout; this->recordStagingImageBarrier(commandBuffer, - srcAccessMask, - dstAccessMask, - srcStageMask, - dstStageMask, - dstImageLayout); + srcAccessMask, + dstAccessMask, + srcStageMask, + dstStageMask, + dstImageLayout); } void Image::recordPrimaryImageBarrier(const vk::CommandBuffer& commandBuffer, - vk::AccessFlagBits srcAccessMask, - vk::AccessFlagBits dstAccessMask, - vk::PipelineStageFlagBits srcStageMask, - vk::PipelineStageFlagBits dstStageMask, - vk::ImageLayout dstLayout) + vk::AccessFlagBits srcAccessMask, + vk::AccessFlagBits dstAccessMask, + vk::PipelineStageFlagBits srcStageMask, + vk::PipelineStageFlagBits dstStageMask, + vk::ImageLayout dstLayout) { KP_LOG_DEBUG("Kompute Image recording PRIMARY image memory barrier"); @@ -324,11 +330,11 @@ Image::recordPrimaryImageBarrier(const vk::CommandBuffer& commandBuffer, void Image::recordStagingImageBarrier(const vk::CommandBuffer& commandBuffer, - vk::AccessFlagBits srcAccessMask, - vk::AccessFlagBits dstAccessMask, - vk::PipelineStageFlagBits srcStageMask, - vk::PipelineStageFlagBits dstStageMask, - vk::ImageLayout dstLayout) + vk::AccessFlagBits srcAccessMask, + vk::AccessFlagBits dstAccessMask, + vk::PipelineStageFlagBits srcStageMask, + vk::PipelineStageFlagBits dstStageMask, + vk::ImageLayout dstLayout) { KP_LOG_DEBUG("Kompute Image recording STAGING image memory barrier"); diff --git a/src/Manager.cpp b/src/Manager.cpp index f33ae39e..32577db1 100644 --- a/src/Manager.cpp +++ b/src/Manager.cpp @@ -112,7 +112,8 @@ Manager::destroy() if (this->mManageResources && this->mManagedMemObjects.size()) { KP_LOG_DEBUG("Kompute Manager explicitly freeing memory objects"); - for (const std::weak_ptr& weakMemory : this->mManagedMemObjects) { + for (const std::weak_ptr& weakMemory : + this->mManagedMemObjects) { if (std::shared_ptr memory = weakMemory.lock()) { memory->destroy(); } diff --git a/src/Memory.cpp b/src/Memory.cpp index 337b4d68..46a7bcbd 100644 --- a/src/Memory.cpp +++ b/src/Memory.cpp @@ -1,9 +1,9 @@ // SPDX-License-Identifier: Apache-2.0 -#include #include "kompute/Memory.hpp" -#include "kompute/Tensor.hpp" #include "kompute/Image.hpp" +#include "kompute/Tensor.hpp" +#include namespace kp { @@ -249,30 +249,29 @@ Memory::getStagingMemoryPropertyFlags() void Memory::recordCopyFrom(const vk::CommandBuffer& commandBuffer, - std::shared_ptr copyFromMemory) + std::shared_ptr copyFromMemory) { if (copyFromMemory->dataType() != this->dataType()) { throw std::runtime_error(fmt::format( - "Attempting to copy memory of different types from {} to {}", - Memory::toString(copyFromMemory->dataType()), - Memory::toString(this->dataType()))); + "Attempting to copy memory of different types from {} to {}", + Memory::toString(copyFromMemory->dataType()), + Memory::toString(this->dataType()))); } if (copyFromMemory->size() != this->size()) { throw std::runtime_error(fmt::format( - "Attempting to copy tensors of different sizes from {} to {}", - copyFromMemory->size(), - this->size())); + "Attempting to copy tensors of different sizes from {} to {}", + copyFromMemory->size(), + this->size())); } if (copyFromMemory->type() == Memory::Type::eTensor) { - this->recordCopyFrom(commandBuffer, std::static_pointer_cast(copyFromMemory)); - } - else if (copyFromMemory->type() == Memory::Type::eImage) { - this->recordCopyFrom(commandBuffer, std::static_pointer_cast(copyFromMemory)); - } - else - { + this->recordCopyFrom(commandBuffer, + std::static_pointer_cast(copyFromMemory)); + } else if (copyFromMemory->type() == Memory::Type::eImage) { + this->recordCopyFrom(commandBuffer, + std::static_pointer_cast(copyFromMemory)); + } else { throw std::runtime_error("Kompute Memory unsupported memory type"); } } diff --git a/src/OpAlgoDispatch.cpp b/src/OpAlgoDispatch.cpp index acedc643..def8d462 100644 --- a/src/OpAlgoDispatch.cpp +++ b/src/OpAlgoDispatch.cpp @@ -23,25 +23,25 @@ OpAlgoDispatch::record(const vk::CommandBuffer& commandBuffer) for (const std::shared_ptr& mem : this->mAlgorithm->getMemObjects()) { - // For images the image layout needs to be set to eGeneral before using it for imageLoad/imageStore in a shader. + // For images the image layout needs to be set to eGeneral before using + // it for imageLoad/imageStore in a shader. if (mem->type() == Memory::Type::eImage) { - std::shared_ptr image = std::static_pointer_cast(mem); - - image->recordPrimaryImageBarrier( - commandBuffer, - vk::AccessFlagBits::eTransferWrite, - vk::AccessFlagBits::eShaderRead, - vk::PipelineStageFlagBits::eTransfer, - vk::PipelineStageFlagBits::eComputeShader, - vk::ImageLayout::eGeneral); - } - else { + std::shared_ptr image = std::static_pointer_cast(mem); + + image->recordPrimaryImageBarrier( + commandBuffer, + vk::AccessFlagBits::eTransferWrite, + vk::AccessFlagBits::eShaderRead, + vk::PipelineStageFlagBits::eTransfer, + vk::PipelineStageFlagBits::eComputeShader, + vk::ImageLayout::eGeneral); + } else { mem->recordPrimaryMemoryBarrier( - commandBuffer, - vk::AccessFlagBits::eTransferWrite, - vk::AccessFlagBits::eShaderRead, - vk::PipelineStageFlagBits::eTransfer, - vk::PipelineStageFlagBits::eComputeShader); + commandBuffer, + vk::AccessFlagBits::eTransferWrite, + vk::AccessFlagBits::eShaderRead, + vk::PipelineStageFlagBits::eTransfer, + vk::PipelineStageFlagBits::eComputeShader); } } diff --git a/src/OpCopy.cpp b/src/OpCopy.cpp index 87df17e5..d6f3803c 100644 --- a/src/OpCopy.cpp +++ b/src/OpCopy.cpp @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 #include "kompute/operations/OpCopy.hpp" -#include "kompute/Tensor.hpp" #include "kompute/Image.hpp" +#include "kompute/Tensor.hpp" namespace kp { @@ -30,7 +30,8 @@ OpCopy::record(const vk::CommandBuffer& commandBuffer) // We iterate from the second memory object onwards and record a copy to all for (size_t i = 1; i < this->mMemObjects.size(); i++) { - this->mMemObjects[i]->recordCopyFrom(commandBuffer, this->mMemObjects[0]); + this->mMemObjects[i]->recordCopyFrom(commandBuffer, + this->mMemObjects[0]); } } @@ -46,7 +47,8 @@ OpCopy::postEval(const vk::CommandBuffer& /*commandBuffer*/) KP_LOG_DEBUG("Kompute OpCopy postEval called"); // Do not copy on CPU side if source is storage memory - if (this->mMemObjects[0]->memoryType() == kp::Memory::MemoryTypes::eStorage) { + if (this->mMemObjects[0]->memoryType() == + kp::Memory::MemoryTypes::eStorage) { KP_LOG_DEBUG("Kompute OpCopy not copying tensor source given " "it's of eStorage type"); return; @@ -60,7 +62,8 @@ OpCopy::postEval(const vk::CommandBuffer& /*commandBuffer*/) "given it's of eStorage type"); continue; } - this->mMemObjects[i]->setData(this->mMemObjects[0]->rawData(),this->mMemObjects[0]->memorySize()); + this->mMemObjects[i]->setData(this->mMemObjects[0]->rawData(), + this->mMemObjects[0]->memorySize()); } } diff --git a/src/OpSyncDevice.cpp b/src/OpSyncDevice.cpp index 26f64594..28e02e9b 100644 --- a/src/OpSyncDevice.cpp +++ b/src/OpSyncDevice.cpp @@ -30,7 +30,8 @@ OpSyncDevice::record(const vk::CommandBuffer& commandBuffer) KP_LOG_DEBUG("Kompute OpSyncDevice record called"); for (size_t i = 0; i < this->mMemObjects.size(); i++) { - if (this->mMemObjects[i]->memoryType() == Tensor::MemoryTypes::eDevice) { + if (this->mMemObjects[i]->memoryType() == + Tensor::MemoryTypes::eDevice) { this->mMemObjects[i]->recordCopyFromStagingToDevice(commandBuffer); } } diff --git a/src/OpSyncLocal.cpp b/src/OpSyncLocal.cpp index df73e500..de9f501f 100644 --- a/src/OpSyncLocal.cpp +++ b/src/OpSyncLocal.cpp @@ -6,8 +6,7 @@ namespace kp { -OpSyncLocal::OpSyncLocal( - const std::vector>& memObjects) +OpSyncLocal::OpSyncLocal(const std::vector>& memObjects) { KP_LOG_DEBUG("Kompute OpSyncLocal constructor with params"); @@ -30,7 +29,8 @@ OpSyncLocal::record(const vk::CommandBuffer& commandBuffer) KP_LOG_DEBUG("Kompute OpSyncLocal record called"); for (size_t i = 0; i < this->mMemObjects.size(); i++) { - if (this->mMemObjects[i]->memoryType() == Memory::MemoryTypes::eDevice) { + if (this->mMemObjects[i]->memoryType() == + Memory::MemoryTypes::eDevice) { this->mMemObjects[i]->recordPrimaryMemoryBarrier( commandBuffer, diff --git a/src/Sequence.cpp b/src/Sequence.cpp index 9a08d11a..ca96dffb 100644 --- a/src/Sequence.cpp +++ b/src/Sequence.cpp @@ -312,8 +312,8 @@ Sequence::createCommandPool() this->mFreeCommandPool = true; - vk::CommandPoolCreateInfo commandPoolInfo(vk::CommandPoolCreateFlagBits::eResetCommandBuffer, - this->mQueueIndex); + vk::CommandPoolCreateInfo commandPoolInfo( + vk::CommandPoolCreateFlagBits::eResetCommandBuffer, this->mQueueIndex); this->mCommandPool = std::make_shared(); this->mDevice->createCommandPool( &commandPoolInfo, nullptr, this->mCommandPool.get()); diff --git a/src/Tensor.cpp b/src/Tensor.cpp index 86e3a6a1..3553aa4e 100644 --- a/src/Tensor.cpp +++ b/src/Tensor.cpp @@ -113,20 +113,19 @@ Tensor::recordCopyFrom(const vk::CommandBuffer& commandBuffer, layer.layerCount = 1; vk::Offset3D offset = { 0, 0, 0 }; - vk::Extent3D size = { copyFromImage->getX(), - copyFromImage->getY(), - 1 }; + vk::Extent3D size = { copyFromImage->getX(), copyFromImage->getY(), 1 }; vk::BufferImageCopy copyRegion(0, 0, 0, layer, offset, size); KP_LOG_DEBUG("Kompute Tensor recordCopyFrom data size {}.", bufferSize); - copyFromImage->recordPrimaryImageBarrier(commandBuffer, - vk::AccessFlagBits::eMemoryRead, - vk::AccessFlagBits::eMemoryWrite, - vk::PipelineStageFlagBits::eTransfer, - vk::PipelineStageFlagBits::eTransfer, - vk::ImageLayout::eTransferSrcOptimal); + copyFromImage->recordPrimaryImageBarrier( + commandBuffer, + vk::AccessFlagBits::eMemoryRead, + vk::AccessFlagBits::eMemoryWrite, + vk::PipelineStageFlagBits::eTransfer, + vk::PipelineStageFlagBits::eTransfer, + vk::ImageLayout::eTransferSrcOptimal); this->recordCopyBufferFromImage(commandBuffer, copyFromImage->getPrimaryImage(), diff --git a/src/include/kompute/Image.hpp b/src/include/kompute/Image.hpp index 0da2d3f1..e15742c6 100644 --- a/src/include/kompute/Image.hpp +++ b/src/include/kompute/Image.hpp @@ -47,9 +47,9 @@ class Image : public Memory const MemoryTypes& memoryType = MemoryTypes::eDevice) : Memory(physicalDevice, device, dataType, memoryType, x, y) { - if (dataType == DataTypes::eCustom) - { - throw std::runtime_error("Custom data types are not supported for Kompute Images"); + if (dataType == DataTypes::eCustom) { + throw std::runtime_error( + "Custom data types are not supported for Kompute Images"); } init(data, dataSize, numChannels, tiling); @@ -115,9 +115,9 @@ class Image : public Memory { vk::ImageTiling tiling; - if (dataType == DataTypes::eCustom) - { - throw std::runtime_error("Custom data types are not supported for Kompute Images"); + if (dataType == DataTypes::eCustom) { + throw std::runtime_error( + "Custom data types are not supported for Kompute Images"); } if (memoryType == MemoryTypes::eHost) { @@ -210,7 +210,8 @@ class Image : public Memory * * @param commandBuffer Vulkan Command Buffer to record the commands into */ - void recordCopyFromStagingToDevice(const vk::CommandBuffer& commandBuffer) override; + void recordCopyFromStagingToDevice( + const vk::CommandBuffer& commandBuffer) override; /** * Records a copy from the internal device memory to the staging memory @@ -219,7 +220,8 @@ class Image : public Memory * * @param commandBuffer Vulkan Command Buffer to record the commands into */ - void recordCopyFromDeviceToStaging(const vk::CommandBuffer& commandBuffer) override; + void recordCopyFromDeviceToStaging( + const vk::CommandBuffer& commandBuffer) override; /** * Records the image memory barrier into the primary image and command @@ -232,11 +234,12 @@ class Image : public Memory * @param scrStageMask Pipeline stage flags for source stage mask * @param dstStageMask Pipeline stage flags for destination stage mask */ - void recordPrimaryMemoryBarrier(const vk::CommandBuffer& commandBuffer, - vk::AccessFlagBits srcAccessMask, - vk::AccessFlagBits dstAccessMask, - vk::PipelineStageFlagBits srcStageMask, - vk::PipelineStageFlagBits dstStageMask) override; + void recordPrimaryMemoryBarrier( + const vk::CommandBuffer& commandBuffer, + vk::AccessFlagBits srcAccessMask, + vk::AccessFlagBits dstAccessMask, + vk::PipelineStageFlagBits srcStageMask, + vk::PipelineStageFlagBits dstStageMask) override; /** * Records the image memory barrier into the staging image and command * buffer which ensures that relevant data transfers are carried out @@ -248,11 +251,12 @@ class Image : public Memory * @param scrStageMask Pipeline stage flags for source stage mask * @param dstStageMask Pipeline stage flags for destination stage mask */ - void recordStagingMemoryBarrier(const vk::CommandBuffer& commandBuffer, - vk::AccessFlagBits srcAccessMask, - vk::AccessFlagBits dstAccessMask, - vk::PipelineStageFlagBits srcStageMask, - vk::PipelineStageFlagBits dstStageMask) override; + void recordStagingMemoryBarrier( + const vk::CommandBuffer& commandBuffer, + vk::AccessFlagBits srcAccessMask, + vk::AccessFlagBits dstAccessMask, + vk::PipelineStageFlagBits srcStageMask, + vk::PipelineStageFlagBits dstStageMask) override; /** * Records the image memory barrier into the primary image and command @@ -267,11 +271,11 @@ class Image : public Memory * @param dstLayout Image layout for the image after the barrier completes */ void recordPrimaryImageBarrier(const vk::CommandBuffer& commandBuffer, - vk::AccessFlagBits srcAccessMask, - vk::AccessFlagBits dstAccessMask, - vk::PipelineStageFlagBits srcStageMask, - vk::PipelineStageFlagBits dstStageMask, - vk::ImageLayout dstLayout); + vk::AccessFlagBits srcAccessMask, + vk::AccessFlagBits dstAccessMask, + vk::PipelineStageFlagBits srcStageMask, + vk::PipelineStageFlagBits dstStageMask, + vk::ImageLayout dstLayout); /** * Adds this object to a Vulkan descriptor set at \p binding. @@ -344,11 +348,11 @@ class Image : public Memory * @param dstLayout Image layout for the image after the barrier completes */ void recordStagingImageBarrier(const vk::CommandBuffer& commandBuffer, - vk::AccessFlagBits srcAccessMask, - vk::AccessFlagBits dstAccessMask, - vk::PipelineStageFlagBits srcStageMask, - vk::PipelineStageFlagBits dstStageMask, - vk::ImageLayout dstLayout); + vk::AccessFlagBits srcAccessMask, + vk::AccessFlagBits dstAccessMask, + vk::PipelineStageFlagBits srcStageMask, + vk::PipelineStageFlagBits dstStageMask, + vk::ImageLayout dstLayout); void recordImageMemoryBarrier(const vk::CommandBuffer& commandBuffer, const vk::Image& image, @@ -403,7 +407,8 @@ class ImageT : public Image imageType) { // Images cannot be created with custom types - static_assert(Memory::dataType() != DataTypes::eCustom, "Custom data types are not supported for Kompute Images"); + static_assert(Memory::dataType() != DataTypes::eCustom, + "Custom data types are not supported for Kompute Images"); KP_LOG_DEBUG("Kompute imageT constructor with data size {}, x {}, " "y {}, and num channels {}", @@ -431,7 +436,8 @@ class ImageT : public Image imageType) { // Images cannot be created with custom types - static_assert(Memory::dataType() != DataTypes::eCustom, "Custom data types are not supported for Kompute Images"); + static_assert(Memory::dataType() != DataTypes::eCustom, + "Custom data types are not supported for Kompute Images"); KP_LOG_DEBUG("Kompute imageT constructor with data size {}, x {}, " "y {}, and num channels {}", @@ -458,7 +464,8 @@ class ImageT : public Image imageType) { // Images cannot be created with custom types - static_assert(Memory::dataType() != DataTypes::eCustom, "Custom data types are not supported for Kompute Images"); + static_assert(Memory::dataType() != DataTypes::eCustom, + "Custom data types are not supported for Kompute Images"); KP_LOG_DEBUG("Kompute imageT constructor with no data, x {}, " "y {}, and num channels {}", @@ -482,7 +489,8 @@ class ImageT : public Image imageType) { // Images cannot be created with custom types - static_assert(Memory::dataType() != DataTypes::eCustom, "Custom data types are not supported for Kompute Images"); + static_assert(Memory::dataType() != DataTypes::eCustom, + "Custom data types are not supported for Kompute Images"); KP_LOG_DEBUG("Kompute imageT constructor with no data, x {}, " "y {}, and num channels {}", diff --git a/src/include/kompute/Memory.hpp b/src/include/kompute/Memory.hpp index 12f37b71..7acbb939 100644 --- a/src/include/kompute/Memory.hpp +++ b/src/include/kompute/Memory.hpp @@ -47,8 +47,8 @@ class Memory enum class Type { - eTensor = 0, - eImage = 1 + eTensor = 0, + eImage = 1 }; static std::string toString(MemoryTypes dt); @@ -165,7 +165,7 @@ class Memory * @param copyFromMemory Memory to copy the data from */ void recordCopyFrom(const vk::CommandBuffer& commandBuffer, - std::shared_ptr copyFromMemory); + std::shared_ptr copyFromMemory); /** * Adds this object to a Vulkan descriptor set at \p binding. @@ -292,7 +292,7 @@ class Memory /** * Return the object type of this Memory object. - * + * * @return The object type of the Memory object. */ virtual Type type() = 0; @@ -327,9 +327,9 @@ class Memory vk::MemoryPropertyFlags getStagingMemoryPropertyFlags(); virtual void recordCopyFrom(const vk::CommandBuffer& commandBuffer, - std::shared_ptr copyFromMemory) = 0; + std::shared_ptr copyFromMemory) = 0; virtual void recordCopyFrom(const vk::CommandBuffer& commandBuffer, - std::shared_ptr copyFromMemory) = 0; + std::shared_ptr copyFromMemory) = 0; }; template<> diff --git a/src/include/kompute/Tensor.hpp b/src/include/kompute/Tensor.hpp index 77d618d4..2334651a 100644 --- a/src/include/kompute/Tensor.hpp +++ b/src/include/kompute/Tensor.hpp @@ -104,7 +104,8 @@ class Tensor : public Memory * * @param commandBuffer Vulkan Command Buffer to record the commands into */ - void recordCopyFromStagingToDevice(const vk::CommandBuffer& commandBuffer) override; + void recordCopyFromStagingToDevice( + const vk::CommandBuffer& commandBuffer) override; /** * Records a copy from the internal device memory to the staging memory @@ -113,7 +114,8 @@ class Tensor : public Memory * * @param commandBuffer Vulkan Command Buffer to record the commands into */ - void recordCopyFromDeviceToStaging(const vk::CommandBuffer& commandBuffer) override; + void recordCopyFromDeviceToStaging( + const vk::CommandBuffer& commandBuffer) override; /** * Records the memory barrier into the primary buffer and command @@ -126,11 +128,12 @@ class Tensor : public Memory * @param scrStageMask Pipeline stage flags for source stage mask * @param dstStageMask Pipeline stage flags for destination stage mask */ - void recordPrimaryMemoryBarrier(const vk::CommandBuffer& commandBuffer, - vk::AccessFlagBits srcAccessMask, - vk::AccessFlagBits dstAccessMask, - vk::PipelineStageFlagBits srcStageMask, - vk::PipelineStageFlagBits dstStageMask) override; + void recordPrimaryMemoryBarrier( + const vk::CommandBuffer& commandBuffer, + vk::AccessFlagBits srcAccessMask, + vk::AccessFlagBits dstAccessMask, + vk::PipelineStageFlagBits srcStageMask, + vk::PipelineStageFlagBits dstStageMask) override; /** * Records the memory barrier into the staging buffer and command * buffer which ensures that relevant data transfers are carried out @@ -142,11 +145,12 @@ class Tensor : public Memory * @param scrStageMask Pipeline stage flags for source stage mask * @param dstStageMask Pipeline stage flags for destination stage mask */ - void recordStagingMemoryBarrier(const vk::CommandBuffer& commandBuffer, - vk::AccessFlagBits srcAccessMask, - vk::AccessFlagBits dstAccessMask, - vk::PipelineStageFlagBits srcStageMask, - vk::PipelineStageFlagBits dstStageMask) override; + void recordStagingMemoryBarrier( + const vk::CommandBuffer& commandBuffer, + vk::AccessFlagBits srcAccessMask, + vk::AccessFlagBits dstAccessMask, + vk::PipelineStageFlagBits srcStageMask, + vk::PipelineStageFlagBits dstStageMask) override; /** * Adds this object to a Vulkan descriptor set at \p binding. diff --git a/src/include/kompute/operations/OpCopy.hpp b/src/include/kompute/operations/OpCopy.hpp index 5e92c3f7..593e2d32 100644 --- a/src/include/kompute/operations/OpCopy.hpp +++ b/src/include/kompute/operations/OpCopy.hpp @@ -10,9 +10,9 @@ namespace kp { /** - * Operation that copies the data from the first memory object to the rest of the - * memory objects provided, using a record command for all the vectors. This operation - * does not own/manage the memory of the memory objects passed to it. + * Operation that copies the data from the first memory object to the rest of + * the memory objects provided, using a record command for all the vectors. This + * operation does not own/manage the memory of the memory objects passed to it. */ class OpCopy : public OpBase { @@ -21,7 +21,8 @@ class OpCopy : public OpBase * Default constructor with parameters that provides the core vulkan * resources and the memory objects that will be used in the operation. * - * @param memObjects memory objects that will be used to create in operation. + * @param memObjects memory objects that will be used to create in + * operation. */ OpCopy(const std::vector>& memObjects); @@ -47,8 +48,8 @@ class OpCopy : public OpBase virtual void preEval(const vk::CommandBuffer& commandBuffer) override; /** - * Copies the local vectors for all the memory objects to sync the data with the - * gpu. + * Copies the local vectors for all the memory objects to sync the data with + * the gpu. * * @param commandBuffer The command buffer to record the command into. */ diff --git a/src/include/kompute/operations/OpSyncDevice.hpp b/src/include/kompute/operations/OpSyncDevice.hpp index 3b2f3c25..ff3aa09c 100644 --- a/src/include/kompute/operations/OpSyncDevice.hpp +++ b/src/include/kompute/operations/OpSyncDevice.hpp @@ -8,22 +8,23 @@ namespace kp { /** - * Operation that syncs mem object's device memory by mapping local data into the device - * memory. For MemoryTypes::eDevice it will use a record operation for the - * memory to be syncd into GPU memory which means that the operation will be - * done in sync with GPU commands. For MemoryTypes::eHost it will only map the - * data into host memory which will happen during preEval before the recorded - * commands are dispatched. + * Operation that syncs mem object's device memory by mapping local data into + * the device memory. For MemoryTypes::eDevice it will use a record operation + * for the memory to be syncd into GPU memory which means that the operation + * will be done in sync with GPU commands. For MemoryTypes::eHost it will only + * map the data into host memory which will happen during preEval before the + * recorded commands are dispatched. */ class OpSyncDevice : public OpBase { public: /** * Default constructor with parameters that provides the core vulkan - * resources and the memory objects that will be used in the operation. The memory objects - * provided cannot be of type MemoryTypes::eStorage. + * resources and the memory objects that will be used in the operation. The + * memory objects provided cannot be of type MemoryTypes::eStorage. * - * @param memObjects Memory objects that will be used to create in operation. + * @param memObjects Memory objects that will be used to create in + * operation. */ OpSyncDevice(const std::vector>& memObjects); @@ -34,8 +35,8 @@ class OpSyncDevice : public OpBase ~OpSyncDevice() override; /** - * For device memory objects, it records the copy command for the memory object to copy - * the data from its staging to device memory. + * For device memory objects, it records the copy command for the memory + * object to copy the data from its staging to device memory. * * @param commandBuffer The command buffer to record the command into. */ diff --git a/src/include/kompute/operations/OpSyncLocal.hpp b/src/include/kompute/operations/OpSyncLocal.hpp index 58d02f42..6304d70e 100644 --- a/src/include/kompute/operations/OpSyncLocal.hpp +++ b/src/include/kompute/operations/OpSyncLocal.hpp @@ -25,7 +25,8 @@ class OpSyncLocal : public OpBase * resources and the memory that will be used in the operation. The memory * provided cannot be of type MemoryTypes::eStorage. * - * @param memObjects Memory objects that will be used to create in operation. + * @param memObjects Memory objects that will be used to create in + * operation. */ OpSyncLocal(const std::vector>& memObjects); @@ -36,8 +37,8 @@ class OpSyncLocal : public OpBase ~OpSyncLocal() override; /** - * For device memory objects, it records the copy command for the tensor to copy - * the data from its device to staging memory. + * For device memory objects, it records the copy command for the tensor to + * copy the data from its device to staging memory. * * @param commandBuffer The command buffer to record the command into. */ @@ -51,8 +52,8 @@ class OpSyncLocal : public OpBase virtual void preEval(const vk::CommandBuffer& commandBuffer) override; /** - * For host memory objects it performs the map command from the host memory into - * local memory. + * For host memory objects it performs the map command from the host memory + * into local memory. * * @param commandBuffer The command buffer to record the command into. */ diff --git a/test/TestImage.cpp b/test/TestImage.cpp index dad919ef..d13c6fd4 100644 --- a/test/TestImage.cpp +++ b/test/TestImage.cpp @@ -45,15 +45,15 @@ TEST(TestImage, DataTypes) for (int numChannels = 1; numChannels <= 4; numChannels++) { - // 3-channel images are not supported and should throw an exception. - // This is tested by a different test. - - // We don't support 3-channel images because they are not supported by Metal or Mesa (llvmpipe) - // See comment here: https://github.com/KomputeProject/kompute/pull/388#discussion_r1720959531 - if (numChannels == 3) - { - continue; - } + // 3-channel images are not supported and should throw an exception. + // This is tested by a different test. + + // We don't support 3-channel images because they are not supported by + // Metal or Mesa (llvmpipe) See comment here: + // https://github.com/KomputeProject/kompute/pull/388#discussion_r1720959531 + if (numChannels == 3) { + continue; + } { std::vector vec(width * height * numChannels); @@ -152,7 +152,8 @@ TEST(TestImage, Tiling) std::vector vec{ 0, 1, 2, 3 }; // Test explitly setting the tiling - std::shared_ptr> image = mgr.imageT(vec, 2, 2, 1, vk::ImageTiling::eOptimal); + std::shared_ptr> image = + mgr.imageT(vec, 2, 2, 1, vk::ImageTiling::eOptimal); // The output should be equal to the input vector EXPECT_EQ(image->vector(), vec); @@ -164,7 +165,8 @@ TEST(TestImage, GetNumChannels) std::vector vec{ 0, 1, 2, 3 }; // Test explitly setting the tiling - std::shared_ptr> image = mgr.imageT(vec, 2, 2, 1, vk::ImageTiling::eOptimal); + std::shared_ptr> image = + mgr.imageT(vec, 2, 2, 1, vk::ImageTiling::eOptimal); // Check the number of channels matches EXPECT_EQ(image->getNumChannels(), 1); @@ -175,6 +177,10 @@ TEST(TestImage, InvalidDataType) kp::Manager mgr; // Custom data types are not supported for images. - EXPECT_THROW(mgr.image(3, 3, 1, kp::Memory::DataTypes::eCustom), std::runtime_error); - EXPECT_THROW(mgr.image(3, 3, 1, kp::Memory::DataTypes::eCustom, vk::ImageTiling::eOptimal), std::runtime_error); + EXPECT_THROW(mgr.image(3, 3, 1, kp::Memory::DataTypes::eCustom), + std::runtime_error); + EXPECT_THROW( + mgr.image( + 3, 3, 1, kp::Memory::DataTypes::eCustom, vk::ImageTiling::eOptimal), + std::runtime_error); } diff --git a/test/TestManager.cpp b/test/TestManager.cpp index 5baa2920..625b4743 100644 --- a/test/TestManager.cpp +++ b/test/TestManager.cpp @@ -55,12 +55,11 @@ TEST(TestManager, OpMultInvalidArgs) std::shared_ptr> tensorOutput = mgr.tensor({ 0, 0, 0 }); // Only give two paramters instead of three. - std::vector> params = { tensorLHS, - tensorRHS }; + std::vector> params = { tensorLHS, tensorRHS }; - EXPECT_THROW(mgr.sequence() - ->record(params, mgr.algorithm()) - ->eval(), std::runtime_error); + EXPECT_THROW( + mgr.sequence()->record(params, mgr.algorithm())->eval(), + std::runtime_error); } TEST(TestManager, TestMultipleSequences) diff --git a/test/TestOpCopyImage.cpp b/test/TestOpCopyImage.cpp index 33731090..e4cc87c0 100644 --- a/test/TestOpCopyImage.cpp +++ b/test/TestOpCopyImage.cpp @@ -189,7 +189,8 @@ TEST(TestOpCopyImage, CopyThroughStorageImage) std::vector testVecOut{ 0, 0, 0 }; std::shared_ptr> ImageIn = mgr.image(testVecIn, 3, 1, 1); - std::shared_ptr> ImageOut = mgr.image(testVecOut, 3, 1, 1); + std::shared_ptr> ImageOut = + mgr.image(testVecOut, 3, 1, 1); // Image storage requires a vector to be passed only to reflect size std::shared_ptr> tensorStorage = mgr.image({ 0, 0, 0 }, 3, 1, 1, kp::Memory::MemoryTypes::eStorage); @@ -212,7 +213,8 @@ TEST(TestOpCopyImage, CopyImageThroughStorageViaAlgorithms) std::vector testVecOut{ 0, 0, 0 }; std::shared_ptr> ImageIn = mgr.image(testVecIn, 3, 1, 1); - std::shared_ptr> ImageOut = mgr.image(testVecOut, 3, 1, 1); + std::shared_ptr> ImageOut = + mgr.image(testVecOut, 3, 1, 1); // Image storage requires a vector to be passed only to reflect size std::shared_ptr tensorStorage = mgr.image({ 0, 0, 0 }, 3, 1, 1, kp::Memory::MemoryTypes::eStorage); @@ -369,5 +371,6 @@ TEST(TestOpCopyImage, CopyDeviceToDeviceImage2DMismatchedSizes) EXPECT_TRUE(imageA->isInit()); EXPECT_TRUE(imageB->isInit()); - EXPECT_THROW(mgr.sequence()->eval({ imageA, imageB }), std::runtime_error); + EXPECT_THROW(mgr.sequence()->eval({ imageA, imageB }), + std::runtime_error); } diff --git a/test/TestOpCopyImageToTensor.cpp b/test/TestOpCopyImageToTensor.cpp index ec6a19d1..130b19cc 100644 --- a/test/TestOpCopyImageToTensor.cpp +++ b/test/TestOpCopyImageToTensor.cpp @@ -194,7 +194,8 @@ TEST(TestOpCopyImageToTensor, CopyDeviceToDeviceImageUninitialised) std::shared_ptr> imageA = mgr.image(testVecA, testVecA.size(), 1, 1); - std::shared_ptr> tensorB = mgr.tensorT(testVecA.size()); + std::shared_ptr> tensorB = + mgr.tensorT(testVecA.size()); EXPECT_TRUE(imageA->isInit()); EXPECT_TRUE(tensorB->isInit()); diff --git a/test/TestOpCopyTensor.cpp b/test/TestOpCopyTensor.cpp index fdb5aff4..d0694f38 100644 --- a/test/TestOpCopyTensor.cpp +++ b/test/TestOpCopyTensor.cpp @@ -166,7 +166,8 @@ TEST(TestOpCopyTensor, MismatchedTensorSizesShouldFail) EXPECT_TRUE(tensorA->isInit()); EXPECT_TRUE(tensorB->isInit()); - EXPECT_THROW(mgr.sequence()->eval({ tensorA, tensorB }), std::runtime_error); + EXPECT_THROW(mgr.sequence()->eval({ tensorA, tensorB }), + std::runtime_error); } TEST(TestOpCopyTensor, MismatchedDataTypesShouldFail) @@ -182,7 +183,8 @@ TEST(TestOpCopyTensor, MismatchedDataTypesShouldFail) EXPECT_TRUE(tensorA->isInit()); EXPECT_TRUE(tensorB->isInit()); - EXPECT_THROW(mgr.sequence()->eval({ tensorA, tensorB }), std::runtime_error); + EXPECT_THROW(mgr.sequence()->eval({ tensorA, tensorB }), + std::runtime_error); } TEST(TestOpCopyTensor, CopyThroughStorageTensor) @@ -278,7 +280,8 @@ TEST(TestOpCopyTensor, CopyDeviceToDeviceTensorUninitialised) std::vector testVecA{ 1, 2, 3 }; std::shared_ptr> tensorA = mgr.tensor(testVecA); - std::shared_ptr> tensorB = mgr.tensorT(testVecA.size()); + std::shared_ptr> tensorB = + mgr.tensorT(testVecA.size()); EXPECT_TRUE(tensorA->isInit()); EXPECT_TRUE(tensorB->isInit()); diff --git a/test/TestOpSync.cpp b/test/TestOpSync.cpp index 9718fb26..87e32ded 100644 --- a/test/TestOpSync.cpp +++ b/test/TestOpSync.cpp @@ -107,7 +107,8 @@ TEST(TestOpSync, NegativeUnrelatedImageSync) std::vector testVecOut{ 0, 0, 0 }; std::shared_ptr> ImageIn = mgr.image(testVecIn, 3, 1, 1); - std::shared_ptr> ImageOut = mgr.image(testVecOut, 3, 1, 1); + std::shared_ptr> ImageOut = + mgr.image(testVecOut, 3, 1, 1); EXPECT_TRUE(ImageIn->isInit()); EXPECT_TRUE(ImageOut->isInit()); diff --git a/test/TestTensor.cpp b/test/TestTensor.cpp index bf0b8128..9f7265d6 100644 --- a/test/TestTensor.cpp +++ b/test/TestTensor.cpp @@ -39,8 +39,8 @@ TEST(TestTensor, ConstructorData) TEST(TestTensor, ReserveData) { kp::Manager mgr; - std::shared_ptr tensor = mgr.tensor( - nullptr, 3, sizeof(float), kp::Memory::DataTypes::eFloat); + std::shared_ptr tensor = + mgr.tensor(nullptr, 3, sizeof(float), kp::Memory::DataTypes::eFloat); EXPECT_EQ(tensor->size(), 3); EXPECT_EQ(tensor->dataTypeMemorySize(), sizeof(float)); @@ -53,7 +53,8 @@ TEST(TestTensor, ReserveData) EXPECT_EQ(tensor3->size(), 3); EXPECT_EQ(tensor3->dataTypeMemorySize(), sizeof(float)); - std::shared_ptr> tensor4 = mgr.tensorT(3); + std::shared_ptr> tensor4 = + mgr.tensorT(3); EXPECT_EQ(tensor4->size(), 3); EXPECT_EQ(tensor4->dataTypeMemorySize(), sizeof(TensorTestStruct)); }