diff --git a/Makefile b/Makefile index 9ec93d9..ae645e1 100755 --- a/Makefile +++ b/Makefile @@ -1,8 +1,7 @@ ####### SRC Build Params ####### -CC=/c/Users/axsau/scoop/apps/gcc/current/bin/g++.exe -CF=~/Programming/lib/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang-format +CC="/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuildTaskHost.exe" ####### Shader Build Params ####### @@ -22,7 +21,6 @@ VCPKG=/c/Users/axsau/Programming/lib/vcpkg/vcpkg run_cmake: cmake \ -Bbuild \ - -DKOMPUTE_OPT_INSTALL_PYTHON_REQS=ON \ -DCMAKE_TOOLCHAIN_FILE=C:\\Users\\axsau\\Programming\\lib\\vcpkg\\scripts\\buildsystems\\vcpkg.cmake \ -DCMAKE_EXPORT_COMPILE_COMMANDS=1 \ -G "Visual Studio 16 2019" @@ -30,50 +28,6 @@ run_cmake: clean_cmake: rm -rf build/ -build: clean build_shaders - $(CC) \ - src/* \ - -w \ - -std=c++17 \ - -DDEBUG=1 \ - -DRELEASE=1 \ - -I"./external/" \ - -L"C:\\VulkanSDK\\1.2.141.2\\Lib\\" \ - -lvulkan-1 \ - -o ./bin/main.exe - #\ - #-L"C:\\Users\\axsau\\Programming\\lib\\vcpkg\\installed\\x64-windows\\lib\\" \ - #-lspdlog \ - #\ - #-g -fexceptions -fPIC \ - #-static-libgcc -static-libstdc++ \ - -run_test: - $(CC) \ - test/* \ - -Wall \ - -std=c++17 \ - -DDEBUG=1 \ - -DRELEASE=1 \ - -I"./external/" \ - -I"./src/" \ - -L"C:\\VulkanSDK\\1.2.141.2\\Lib\\" \ - -lvulkan-1 \ - -o ./bin/test.exe && \ - ./bin/test.exe --success - - -build_linux: - g++ \ - -g -shared-libgcc \ - -Wall \ - src/* \ - -std=c++17 \ - -I"./external/" \ - -I"./src" \ - -lvulkan \ - -o ./bin/main - install_python_reqs: python -m pip install -r scripts/requirements.txt @@ -119,7 +73,7 @@ build_single_header: "single_include/kompute/Kompute.hpp" format: - $(CF) -i -style="{BasedOnStyle: mozilla, IndentWidth: 4}" src/*.cpp src/*.hpp src/*.h + clang-format -i -style="{BasedOnStyle: mozilla, IndentWidth: 4}" src/*.cpp src/include/kompute/*.hpp clean: find src -name "*gch" -exec rm {} \; || "No ghc files" diff --git a/src/Algorithm.cpp b/src/Algorithm.cpp index da183f3..1de3df4 100644 --- a/src/Algorithm.cpp +++ b/src/Algorithm.cpp @@ -41,9 +41,9 @@ Algorithm::init(const std::vector& shaderFileData, this->createPipeline(); } -void Algorithm::createDescriptorPool() { - -} +void +Algorithm::createDescriptorPool() +{} void Algorithm::createParameters(std::vector>& tensorParams) @@ -52,9 +52,10 @@ Algorithm::createParameters(std::vector>& tensorParams) // TODO: Explore design for having multiple descriptor pool sizes std::vector descriptorPoolSizes = { - vk::DescriptorPoolSize(vk::DescriptorType::eStorageBuffer, - static_cast(tensorParams.size()) // Descriptor count - ) + vk::DescriptorPoolSize( + vk::DescriptorType::eStorageBuffer, + static_cast(tensorParams.size()) // Descriptor count + ) }; // TODO: Explore design for having more than 1 set configurable @@ -120,11 +121,12 @@ Algorithm::createParameters(std::vector>& tensorParams) nullptr, // Descriptor image info &descriptorBufferInfo)); - this->mDevice->updateDescriptorSets(computeWriteDescriptorSets, nullptr); + this->mDevice->updateDescriptorSets(computeWriteDescriptorSets, + nullptr); } SPDLOG_DEBUG("Kompute Algorithm updating descriptor sets"); - //this->mDevice->updateDescriptorSets(computeWriteDescriptorSets, nullptr); + // this->mDevice->updateDescriptorSets(computeWriteDescriptorSets, nullptr); SPDLOG_DEBUG("Kompue Algorithm successfully run init"); } @@ -135,7 +137,9 @@ Algorithm::createShaderModule(const std::vector& shaderFileData) SPDLOG_DEBUG("Kompute Algorithm createShaderModule started"); vk::ShaderModuleCreateInfo shaderModuleInfo( - vk::ShaderModuleCreateFlags(), shaderFileData.size(), (uint32_t*)shaderFileData.data()); + vk::ShaderModuleCreateFlags(), + shaderFileData.size(), + (uint32_t*)shaderFileData.data()); SPDLOG_DEBUG("Kompute Algorithm Creating shader module. ShaderFileSize: {}", shaderFileData.size()); diff --git a/src/Manager.cpp b/src/Manager.cpp index a44f9d6..3445c60 100644 --- a/src/Manager.cpp +++ b/src/Manager.cpp @@ -66,9 +66,13 @@ Manager::~Manager() } Sequence -Manager::constructSequence() { +Manager::constructSequence() +{ SPDLOG_DEBUG("Kompute Manager creating Sequence object"); - return Sequence(this->mPhysicalDevice, this->mDevice, this->mComputeQueue, this->mComputeQueueFamilyIndex); + return Sequence(this->mPhysicalDevice, + this->mDevice, + this->mComputeQueue, + this->mComputeQueueFamilyIndex); } void diff --git a/src/Tensor.cpp b/src/Tensor.cpp old mode 100755 new mode 100644 index 59c0565..7e51600 --- a/src/Tensor.cpp +++ b/src/Tensor.cpp @@ -15,7 +15,8 @@ Tensor::Tensor() Tensor::Tensor(std::vector data, TensorTypes tensorType) { - SPDLOG_DEBUG("Kompute Tensor constructor data: {}, and type: {}", data, tensorType); + SPDLOG_DEBUG( + "Kompute Tensor constructor data: {}, and type: {}", data, tensorType); this->mData = data; this->mShape = { static_cast(data.size()) }; @@ -60,8 +61,9 @@ Tensor::init(std::shared_ptr physicalDevice, std::shared_ptr device, std::shared_ptr commandBuffer) { - SPDLOG_DEBUG( - "Kompute Tensor running init with Vulkan params and num data elementS: {}", this->mData.size()); + SPDLOG_DEBUG("Kompute Tensor running init with Vulkan params and num data " + "elementS: {}", + this->mData.size()); this->mPhysicalDevice = physicalDevice; this->mDevice = device; @@ -178,8 +180,9 @@ Tensor::mapDataFromHostMemory() SPDLOG_DEBUG("Kompute Tensor mapping data from host buffer"); if (this->mTensorType != TensorTypes::eStaging) { - spdlog::error("Mapping tensor data manually from DEVICE buffer instead of " - "using record GPU command with staging buffer"); + spdlog::error( + "Mapping tensor data manually from DEVICE buffer instead of " + "using record GPU command with staging buffer"); return; } @@ -198,10 +201,12 @@ Tensor::mapDataIntoHostMemory() SPDLOG_DEBUG("Kompute Tensor local mapping tensor data to host buffer"); - // TODO: Verify if there are situations where we want to copy to device memory + // TODO: Verify if there are situations where we want to copy to device + // memory if (this->mTensorType != TensorTypes::eStaging) { - spdlog::error("Mapping tensor data manually to DEVICE memory instead of " - "using record GPU command with staging buffer"); + spdlog::error( + "Mapping tensor data manually to DEVICE memory instead of " + "using record GPU command with staging buffer"); return; } diff --git a/src/include/kompute/Algorithm.hpp b/src/include/kompute/Algorithm.hpp index 98f815d..4bb7e1d 100644 --- a/src/include/kompute/Algorithm.hpp +++ b/src/include/kompute/Algorithm.hpp @@ -52,7 +52,6 @@ class Algorithm // Parameters void createParameters(std::vector>& tensorParams); void createDescriptorPool(); - }; } // End namespace kp diff --git a/src/include/kompute/Core.hpp b/src/include/kompute/Core.hpp index b2615b5..3d196b0 100644 --- a/src/include/kompute/Core.hpp +++ b/src/include/kompute/Core.hpp @@ -8,5 +8,3 @@ #endif #include - - diff --git a/src/include/kompute/OpMult.hpp b/src/include/kompute/OpMult.hpp index 86fd32e..8197e6c 100644 --- a/src/include/kompute/OpMult.hpp +++ b/src/include/kompute/OpMult.hpp @@ -66,8 +66,8 @@ OpMult::OpMult() // TODO: Remove physicalDevice from main initialiser template OpMult::OpMult(std::shared_ptr physicalDevice, - std::shared_ptr device, - std::shared_ptr commandBuffer) + std::shared_ptr device, + std::shared_ptr commandBuffer) : OpBase(physicalDevice, device, commandBuffer) { SPDLOG_DEBUG("Kompute OpMult constructor with params"); @@ -79,7 +79,6 @@ template OpMult::~OpMult() { SPDLOG_DEBUG("Kompute OpMult destructor started"); - } template @@ -99,20 +98,24 @@ OpMult::init(std::vector> tensors) this->mTensorRHS = tensors[1]; this->mTensorOutput = tensors[2]; - // The dispatch size is set up based on either explicitly provided template parameters or by default it would take the shape and size of the tensors + // The dispatch size is set up based on either explicitly provided template + // parameters or by default it would take the shape and size of the tensors if (tX > 0) { - // If at least the x value is provided we use mainly the parameters provided + // If at least the x value is provided we use mainly the parameters + // provided this->mX = tX; this->mY = tY > 0 ? tY : 1; this->mZ = tZ > 0 ? tZ : 1; - } - else { + } else { // TODO: Fully support the full size dispatch using size for the shape this->mX = this->mTensorLHS->size(); this->mY = 1; this->mZ = 1; } - spdlog::info("Kompute OpMult dispatch size X: {}, Y: {}, Z: {}", this->mX, this->mY, this->mZ); + spdlog::info("Kompute OpMult dispatch size X: {}, Y: {}, Z: {}", + this->mX, + this->mY, + this->mZ); // TODO: Explore adding a validate function if (!(this->mTensorLHS->isInit() && this->mTensorRHS->isInit() && @@ -138,16 +141,17 @@ OpMult::init(std::vector> tensors) this->mTensorOutputStaging = std::make_shared( this->mTensorOutput->data(), Tensor::TensorTypes::eStaging); - this->mTensorOutputStaging->init(this->mPhysicalDevice, - this->mDevice, - this->mCommandBuffer); + this->mTensorOutputStaging->init( + this->mPhysicalDevice, this->mDevice, this->mCommandBuffer); #if RELEASE std::vector shaderFileData( - shader_data::shaders_glsl_opmult_comp_spv, - shader_data::shaders_glsl_opmult_comp_spv + kp::shader_data::shaders_glsl_opmult_comp_spv_len); + shader_data::shaders_glsl_opmult_comp_spv, + shader_data::shaders_glsl_opmult_comp_spv + + kp::shader_data::shaders_glsl_opmult_comp_spv_len); #else - SPDLOG_DEBUG("Kompute OpMult Running debug loading shaders directly from spirv file"); + SPDLOG_DEBUG( + "Kompute OpMult Running debug loading shaders directly from spirv file"); // TODO: Move to utility function std::string shaderFilePath = "shaders/glsl/opmult.comp.spv"; @@ -160,7 +164,8 @@ OpMult::init(std::vector> tensors) fileStream.read(shaderDataRaw, shaderFileSize); fileStream.close(); - std::vector shaderFileData(shaderDataRaw, shaderDataRaw + shaderFileSize); + std::vector shaderFileData(shaderDataRaw, + shaderDataRaw + shaderFileSize); #endif SPDLOG_DEBUG("Kompute OpMult Initialising algorithm component"); @@ -176,43 +181,43 @@ OpMult::record() // Barrier to ensure the data is finished writing to buffer memory this->mTensorLHS->recordBufferMemoryBarrier( - vk::AccessFlagBits::eHostWrite, - vk::AccessFlagBits::eShaderRead, - vk::PipelineStageFlagBits::eHost, - vk::PipelineStageFlagBits::eComputeShader); + vk::AccessFlagBits::eHostWrite, + vk::AccessFlagBits::eShaderRead, + vk::PipelineStageFlagBits::eHost, + vk::PipelineStageFlagBits::eComputeShader); this->mTensorRHS->recordBufferMemoryBarrier( - vk::AccessFlagBits::eHostWrite, - vk::AccessFlagBits::eShaderRead, - vk::PipelineStageFlagBits::eHost, - vk::PipelineStageFlagBits::eComputeShader); + vk::AccessFlagBits::eHostWrite, + vk::AccessFlagBits::eShaderRead, + vk::PipelineStageFlagBits::eHost, + vk::PipelineStageFlagBits::eComputeShader); this->mAlgorithm->recordDispatch(this->mX, this->mY, this->mZ); // Barrier to ensure the shader code is executed before buffer read this->mTensorLHS->recordBufferMemoryBarrier( - vk::AccessFlagBits::eShaderWrite, - vk::AccessFlagBits::eTransferRead, - vk::PipelineStageFlagBits::eComputeShader, - vk::PipelineStageFlagBits::eTransfer); + vk::AccessFlagBits::eShaderWrite, + vk::AccessFlagBits::eTransferRead, + vk::PipelineStageFlagBits::eComputeShader, + vk::PipelineStageFlagBits::eTransfer); this->mTensorOutput->recordBufferMemoryBarrier( - vk::AccessFlagBits::eShaderWrite, - vk::AccessFlagBits::eTransferRead, - vk::PipelineStageFlagBits::eComputeShader, - vk::PipelineStageFlagBits::eTransfer); + vk::AccessFlagBits::eShaderWrite, + vk::AccessFlagBits::eTransferRead, + vk::PipelineStageFlagBits::eComputeShader, + vk::PipelineStageFlagBits::eTransfer); this->mTensorOutputStaging->recordCopyFrom(this->mTensorOutput); // Buffer to ensure wait until data is copied to staging buffer this->mTensorLHS->recordBufferMemoryBarrier( - vk::AccessFlagBits::eTransferWrite, - vk::AccessFlagBits::eHostRead, - vk::PipelineStageFlagBits::eTransfer, - vk::PipelineStageFlagBits::eHost); + vk::AccessFlagBits::eTransferWrite, + vk::AccessFlagBits::eHostRead, + vk::PipelineStageFlagBits::eTransfer, + vk::PipelineStageFlagBits::eHost); this->mTensorOutput->recordBufferMemoryBarrier( - vk::AccessFlagBits::eTransferWrite, - vk::AccessFlagBits::eHostRead, - vk::PipelineStageFlagBits::eTransfer, - vk::PipelineStageFlagBits::eHost); + vk::AccessFlagBits::eTransferWrite, + vk::AccessFlagBits::eHostRead, + vk::PipelineStageFlagBits::eTransfer, + vk::PipelineStageFlagBits::eHost); } template @@ -229,5 +234,3 @@ OpMult::postSubmit() } #endif // #ifndef OPMULT_CPP - - diff --git a/src/include/kompute/Sequence.hpp b/src/include/kompute/Sequence.hpp index 6a070ec..16e70af 100644 --- a/src/include/kompute/Sequence.hpp +++ b/src/include/kompute/Sequence.hpp @@ -37,10 +37,12 @@ class Sequence std::unique_ptr baseOpPtr{ baseOp }; - SPDLOG_DEBUG("Kompute Sequence running init on OpBase derived class instance"); + SPDLOG_DEBUG( + "Kompute Sequence running init on OpBase derived class instance"); baseOpPtr->init(tensors); - SPDLOG_DEBUG("Kompute Sequence running record on OpBase derived class instance"); + SPDLOG_DEBUG( + "Kompute Sequence running record on OpBase derived class instance"); baseOpPtr->record(); mOperations.push_back(std::move(baseOpPtr));