-
Notifications
You must be signed in to change notification settings - Fork 181
Moved management of shader module creation and lifetime to its own class. #444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
c75c161
74841ce
5d737b9
6fdc886
acba5b8
64edc39
8eb39d5
97a6ea1
ea0889a
47d3a41
30b2277
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| #include "kompute/Shader.hpp" | ||
|
|
||
| namespace kp { | ||
|
|
||
| Shader::Shader(const std::shared_ptr<vk::Device>& device, | ||
| const std::vector<uint32_t>& spv) : | ||
| mDevice(device) | ||
| { | ||
| KP_LOG_DEBUG("Kompute Module constructor started"); | ||
| KP_LOG_DEBUG("Kompute Module Creating shader module. ShaderFileSize: {}", | ||
| spv.size()); | ||
| vk::ShaderModuleCreateInfo shaderModuleInfo(vk::ShaderModuleCreateFlags(), | ||
| sizeof(uint32_t) * spv.size(), spv.data()); | ||
| this->mDevice->createShaderModule( | ||
| &shaderModuleInfo, nullptr, &(this->mShaderModule) ); | ||
| KP_LOG_DEBUG("Kompute Module constructor success"); | ||
| } | ||
|
|
||
| const vk::ShaderModule& Shader::getShaderModule() | ||
axsaucedo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| if (this->mDestroyed) | ||
| throw std::runtime_error("Attempting to get vk::ShaderModule from destroyed kp::Shader instance"); | ||
| return this->mShaderModule; | ||
| } | ||
|
|
||
| void Shader::destroy() | ||
| { | ||
| KP_LOG_DEBUG("Kompute Module destructor started"); | ||
| KP_LOG_DEBUG("Kompute Module Destroying shader module"); | ||
| if (!this->mDestroyed) | ||
| { | ||
| this->mDestroyed = true; | ||
| this->mDevice->destroyShaderModule(this->mShaderModule); | ||
| } | ||
| KP_LOG_DEBUG("Kompute Module destructor success"); | ||
| } | ||
|
|
||
| Shader::~Shader() | ||
| { | ||
| this->destroy(); | ||
| } | ||
|
|
||
| } // end namespace kp | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| #pragma once | ||
|
|
||
| #include "kompute/Core.hpp" | ||
| #include "logger/Logger.hpp" | ||
| #include <memory> | ||
|
|
||
| namespace kp { | ||
|
|
||
| // forward declarations for std::shared_from_this | ||
| class Shader; | ||
|
|
||
| /* | ||
| * Wrapper for Vulkan's shader modules. | ||
| */ | ||
| class Shader | ||
| { | ||
| // not-owned resources | ||
| std::shared_ptr<vk::Device> mDevice; | ||
|
|
||
| // owned resources | ||
| vk::ShaderModule mShaderModule; | ||
| bool mDestroyed = false; | ||
|
|
||
| public: | ||
|
|
||
| /** | ||
| * Constructor accepting a device and a SPIR-V binary | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment conventions should align to rest of codebase - see manager.hpp |
||
| * @param device The vk::Device for the shader module to be compiled for | ||
| * @param spv The SPIR-V binary | ||
| **/ | ||
| Shader(const std::shared_ptr<vk::Device>& device, | ||
| const std::vector<uint32_t>& spv); | ||
|
|
||
| /** | ||
| * getter for mShaderModule | ||
| **/ | ||
| const vk::ShaderModule& getShaderModule(); | ||
|
|
||
| void destroy(); | ||
|
|
||
| ~Shader(); | ||
| }; | ||
|
|
||
| } // End namespace kp | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,8 +86,8 @@ TEST(TestAsyncOperations, TestManagerParallelExecution) | |
| std::vector<std::shared_ptr<kp::Algorithm>> algosAsync; | ||
|
|
||
| for (uint32_t i = 0; i < numParallel; i++) { | ||
| inputsAsyncB.push_back(mgr.tensor(data)); | ||
| algosAsync.push_back(mgr.algorithm({ inputsAsyncB[i] }, spirv)); | ||
| inputsAsyncB.push_back(mgrAsync.tensor(data)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you changing this?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test was wrong and was causing my driver to crash. It was trying to use different My change here fixes this.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It still isn't completely fixed; see here for details: #445 (comment)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But this is not "fixing" anything. This is a test that is currently set up on specific hardware, which is testing parallel execution. What you are doing is just not running the test. This is not "fixing" something.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It still crashes, but the validation error in my message no longer appears when I attempt to run the test. So it is a step in the right direction towards compliant API usage, but not a complete fix.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need to see what this validation error may be, but your change basically makes this test redundant, so it's not correct. If you read through the test you are making it to not compare anything; the test is profiling a parallel queue with a non-parallel queue on a specific GPU that actually supports parallel processing (not async, parallel). Here's more info: https://medium.com/data-science/parallelizing-heavy-gpu-workloads-via-multi-queue-operations-50a38b15a1dc
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The simplified reasoning is that you are taking an underlying What do these resources look like? It really depends on the driver. NVIDIA drivers (which given your comments, it seems you have) are more robust in this regard, while AMD drivers (which I am using right now) are quite a bit more unforgiving about things like this. So when you try to use memory and pipelines allocated with As for why the test is redundant now, I am really not sure; both |
||
| algosAsync.push_back(mgrAsync.algorithm({ inputsAsyncB[i] }, spirv)); | ||
| } | ||
|
|
||
| std::vector<std::shared_ptr<kp::Sequence>> sqs; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.