vulkan persistent pipeline cache and shader spirv code cache implementation#6248
Open
CLV-Iclucia wants to merge 22 commits intoTencent:masterfrom
Open
vulkan persistent pipeline cache and shader spirv code cache implementation#6248CLV-Iclucia wants to merge 22 commits intoTencent:masterfrom
CLV-Iclucia wants to merge 22 commits intoTencent:masterfrom
Conversation
…test in test_pipeline_cache
…he.h/cpp, reformat code
Member
|
The binary size change of libncnn.so (bytes)
|
Member
|
感谢你的工作,请将你在实现中的笔记和心得,遇到的困难和解决方法等,记录成文章,发表在discussion分区,这将作为知识总结 https://github.com/Tencent/ncnn/discussions Thank you for your work. Please record your notes and experience in the implementation, difficulties encountered and solutions, etc. into an article and publish it in the discussion section. This will serve as a knowledge summary. https://github.com/Tencent/ncnn/discussions |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6248 +/- ##
==========================================
- Coverage 95.89% 95.85% -0.04%
==========================================
Files 837 836 -1
Lines 264994 265053 +59
==========================================
- Hits 254105 254076 -29
- Misses 10889 10977 +88 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add Persistent Vulkan Pipeline Cache and Persistent Shader SPIR-V Cache
Changes
PipelineCache, enabling serialization ofVkPipelineCachedata to disk and reuse across application runs.Design Considerations
Testing
Performance
In a single pipeline creation test, the time taken for creating a pipeline is reduced from 90ms to 0.4ms using the two caches across runs (mocked by creating and destroying GPU repeatedly) on my PC and this is mainly contributed by spirv code cache.
The CPU is AMD Ryzen 7 5800H and the GPU is Nvidia RTX 3060.
Impact
ncnn_versionin spirv cache header.Questions for Review
1. Cross-platform file operations
The project currently lacks a unified cross-platform file API due to using C++11 (like renaming file). I implemented platform-specific file handling within the relevant
pipelinecache.cppfiles.Would it be better to extract these into a cross-platform file module? Any recommendations or existing patterns in the project?
2. SPIR-V cache invalidation strategy
Multiple factors affect the generated SPIR-V, such as shader source,
glslangversion, and howncnnhandles device extensions and options.I combined these into a single
ncnn_versionfield in the spirv code cache header to invalidate caches on changes.Is this approach sufficient? Are there better versioning or change-tracking strategies you recommend?
3. Testing and API exposure for SPIR-V cache
Exposing many interfaces to manipulate the SPIR-V cache risks complexity, yet hiding them makes thorough testing difficult.
What is the best practice here? Controlled internal APIs for testing, or relying on integration tests?
4. Security of SPIR-V cache files
If a cached SPIR-V file is maliciously altered (content and hash), there's a risk of running compromised shaders when loading the cache.
Do you have suggestions on mitigating this risk?