Skip to content

vulkan persistent pipeline cache and shader spirv code cache implementation #6248

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

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
20201fd
add persistent vulkan pipeline cache prototype
CLV-Iclucia Aug 1, 2025
e7070f3
Merge branch 'Tencent:master' into vulkan-persistent-pipeline-cache-dev
CLV-Iclucia Aug 2, 2025
f93d840
finish persistent pipeline cache and add test
CLV-Iclucia Aug 8, 2025
cb2c27e
add persistent spirv code cache in pipelinecache.h/cpp
CLV-Iclucia Aug 9, 2025
bda1eaa
Merge branch 'master' into vulkan-persistent-pipeline-cache-dev
CLV-Iclucia Aug 9, 2025
3e6438e
finish shader spirv cache in pipelinecache.cpp/h
CLV-Iclucia Aug 10, 2025
664eb0c
Reverted tools/pnnx
CLV-Iclucia Aug 10, 2025
2074b59
add interface for user to clear cache in pipelinecache.cpp/h, refine …
CLV-Iclucia Aug 11, 2025
ee63525
reformat code pipelinecache.cpp and test_pipeline_cache.cpp
CLV-Iclucia Aug 11, 2025
68e3a20
remove unnecessary headers in pipelinecache.cpp
CLV-Iclucia Aug 11, 2025
213e290
fix lock in pipelinecache.cpp, add multithread tests in test_pipeline…
CLV-Iclucia Aug 11, 2025
780af83
make unnecessary protected methods invisible in header in pipelinecac…
CLV-Iclucia Aug 11, 2025
834741f
revert unnecessary code format
CLV-Iclucia Aug 11, 2025
d364052
add accidentally deleted files back
CLV-Iclucia Aug 11, 2025
aaaf1db
add accidentally removed pybind11_mat.h back
CLV-Iclucia Aug 11, 2025
f9ab7c2
add pipeline cache flag bits in simplevk.h
CLV-Iclucia Aug 11, 2025
82f93ba
fix compilation error on linux
CLV-Iclucia Aug 11, 2025
a04c2e4
fix compilation error on linux
CLV-Iclucia Aug 11, 2025
a954b48
fixing compilation error on linux in pipelinecache.cpp
CLV-Iclucia Aug 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions src/gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3734,7 +3734,7 @@ int VulkanDevice::create_pipeline_layout(int push_constant_count, VkDescriptorSe
return 0;
}

int VulkanDevice::create_pipeline(VkShaderModule shader_module, VkPipelineLayout pipeline_layout, const std::vector<vk_specialization_type>& specializations, uint32_t subgroup_size, VkPipeline* pipeline) const
int VulkanDevice::create_pipeline(VkShaderModule shader_module, VkPipelineLayout pipeline_layout, const std::vector<vk_specialization_type>& specializations, uint32_t subgroup_size, VkPipelineCache* vk_pipeline_cache, VkPipeline* pipeline) const
{
const int specialization_count = specializations.size();

Expand Down Expand Up @@ -3792,7 +3792,11 @@ int VulkanDevice::create_pipeline(VkShaderModule shader_module, VkPipelineLayout
computePipelineCreateInfo.basePipelineHandle = 0;
computePipelineCreateInfo.basePipelineIndex = 0;

VkResult ret = vkCreateComputePipelines(d->device, 0, 1, &computePipelineCreateInfo, 0, pipeline);
VkResult ret;
if (vk_pipeline_cache != VK_NULL_HANDLE)
ret = vkCreateComputePipelines(d->device, *vk_pipeline_cache, 1, &computePipelineCreateInfo, 0, pipeline);
else
ret = vkCreateComputePipelines(d->device, VK_NULL_HANDLE, 1, &computePipelineCreateInfo, 0, pipeline);
if (ret != VK_SUCCESS)
{
NCNN_LOGE("vkCreateComputePipelines failed %d", ret);
Expand All @@ -3801,6 +3805,40 @@ int VulkanDevice::create_pipeline(VkShaderModule shader_module, VkPipelineLayout

return 0;
}
int VulkanDevice::create_empty_pipeline_cache(VkPipelineCache* vk_pipeline_cache) const
{
VkPipelineCacheCreateInfo info;
info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
info.pNext = 0;
info.flags = VK_PIPELINE_CACHE_CREATE_EXTERNALLY_SYNCHRONIZED_BIT;
info.initialDataSize = 0;
info.pInitialData = 0;
VkResult ret = vkCreatePipelineCache(d->device, &info, 0, vk_pipeline_cache);
if (ret != VK_SUCCESS)
{
NCNN_LOGE("vkCreatePipelineCache failed %d", ret);
return -1;
}

return 0;
}
int VulkanDevice::create_pipeline_cache_with_data(const void* initial_data, size_t data_size, VkPipelineCache* vk_pipeline_cache) const
{
VkPipelineCacheCreateInfo info;
info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
info.pNext = 0;
info.flags = VK_PIPELINE_CACHE_CREATE_EXTERNALLY_SYNCHRONIZED_BIT;
info.initialDataSize = data_size;
info.pInitialData = initial_data;
VkResult ret = vkCreatePipelineCache(d->device, &info, 0, vk_pipeline_cache);
if (ret != VK_SUCCESS)
{
NCNN_LOGE("vkCreatePipelineCache failed %d", ret);
return -1;
}

return 0;
}

int VulkanDevice::create_descriptor_update_template(int binding_count, const int* binding_types, VkDescriptorSetLayout descriptorset_layout, VkPipelineLayout pipeline_layout, VkDescriptorUpdateTemplateKHR* descriptor_update_template) const
{
Expand Down
5 changes: 4 additions & 1 deletion src/gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,10 @@ class NCNN_EXPORT VulkanDevice
// helper for creating pipeline
int create_descriptorset_layout(int binding_count, const int* binding_types, VkDescriptorSetLayout* descriptorset_layout) const;
int create_pipeline_layout(int push_constant_count, VkDescriptorSetLayout descriptorset_layout, VkPipelineLayout* pipeline_layout) const;
int create_pipeline(VkShaderModule shader_module, VkPipelineLayout pipeline_layout, const std::vector<vk_specialization_type>& specializations, uint32_t subgroup_size, VkPipeline* pipeline) const;
int create_pipeline(VkShaderModule shader_module, VkPipelineLayout pipeline_layout, const std::vector<vk_specialization_type>& specializations, uint32_t subgroup_size, VkPipelineCache* vk_pipeline_cache, VkPipeline* pipeline) const;
int create_empty_pipeline_cache(VkPipelineCache* vk_pipeline_cache) const;
int create_pipeline_cache_with_data(const void* initial_data, size_t data_size, VkPipelineCache* vk_pipeline_cache) const;

int create_descriptor_update_template(int binding_count, const int* binding_types, VkDescriptorSetLayout descriptorset_layout, VkPipelineLayout pipeline_layout, VkDescriptorUpdateTemplateKHR* descriptor_update_template) const;

uint32_t find_memory_index(uint32_t memory_type_bits, VkFlags required, VkFlags preferred, VkFlags preferred_not) const;
Expand Down
Loading