-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Matmul vulkan shader #6470
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?
Matmul vulkan shader #6470
Conversation
# Conflicts: # src/layer/vulkan/matmul_vulkan.cpp
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6470 +/- ##
========================================
Coverage 95.90% 95.91%
========================================
Files 845 846 +1
Lines 265399 265600 +201
========================================
+ Hits 254531 254741 +210
+ Misses 10868 10859 -9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds Vulkan shader support for matrix multiplication operations to the ncnn framework. The implementation provides GPU acceleration for matmul operations using Vulkan compute shaders.
- Implements a new Vulkan compute shader for matrix multiplication with support for transposed matrices and batched operations
- Adds MatMul_vulkan class following the established pattern for Vulkan layer implementations
- Handles multiple input dimensions (1D through 4D tensors) with appropriate broadcasting
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
| src/layer/vulkan/shader/matmul.comp | New Vulkan compute shader implementing matrix multiplication with local memory optimization and support for various tensor dimensions |
| src/layer/vulkan/matmul_vulkan.h | Header file declaring the MatMul_vulkan class with standard Vulkan layer interface |
| src/layer/vulkan/matmul_vulkan.cpp | Implementation of MatMul_vulkan class handling dimension calculations, tensor broadcasting, and pipeline dispatch |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/layer/vulkan/shader/matmul.comp
Outdated
| if (in_m0) | ||
| a0 = lfp(buffer_ld1(a_blob_data, a_base + m0 * p.a_w + ak)); | ||
| if (in_m1) | ||
| a1 = lfp(buffer_ld1(a_blob_data, a_base + (m0 + 1) * p.a_w + ak)); |
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The statements inside these if blocks are missing proper indentation. They should be indented to match the code style used elsewhere in the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
solve
src/layer/vulkan/shader/matmul.comp
Outdated
| if (transB == 0) | ||
| b_idx0 = b_base + bk * p.b_w + n0; | ||
| else | ||
| b_idx0 = b_base + n0 * p.b_w + bk; |
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The statements inside these if blocks are missing proper indentation. They should be indented to match the code style used elsewhere in the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
solve
src/layer/vulkan/matmul_vulkan.h
Outdated
| @@ -0,0 +1,28 @@ | |||
| // Copyright 2025 pchar.cn | |||
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The copyright format is inconsistent with other files by the same author. Other files in this directory use "Copyright 2025 Futz12 <pchar.cn>" (e.g., layernorm_vulkan.h, rmsnorm_vulkan.h). Consider using the same format for consistency.
| // Copyright 2025 pchar.cn | |
| // Copyright 2025 Futz12 <pchar.cn> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
solve
src/layer/vulkan/matmul_vulkan.cpp
Outdated
| @@ -0,0 +1,411 @@ | |||
| // Copyright 2025 pchar.cn | |||
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The copyright format is inconsistent with other files by the same author. Other files in this directory use "Copyright 2025 Futz12 <pchar.cn>" (e.g., layernorm_vulkan.cpp, rmsnorm_vulkan.cpp). Consider using the same format for consistency.
| // Copyright 2025 pchar.cn | |
| // Copyright 2025 Futz12 <pchar.cn> |
src/layer/vulkan/shader/matmul.comp
Outdated
| @@ -0,0 +1,384 @@ | |||
| // Copyright 2025 pchar.cn | |||
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The copyright format is inconsistent with other shader files by the same author. Other shader files in this directory use "Copyright 2025 Futz12 <pchar.cn>" (e.g., layernorm_.comp, rmsnorm_.comp). Consider using the same format for consistency.
| // Copyright 2025 pchar.cn | |
| // Copyright 2025 Futz12 <pchar.cn> |
src/layer/vulkan/shader/matmul.comp
Outdated
| bool in_m0; // = (m0 < p.out_h); | ||
| bool in_m1; // = (m0 + 1 < p.out_h); | ||
| bool in_n0; // = (n0 < p.out_w); | ||
| bool in_n1; // = (n0 + 1 < p.out_w); | ||
|
|
||
| if (m0 < p.out_h) | ||
| in_m0 = true; | ||
| else | ||
| in_m0 = false; | ||
|
|
||
| if (m0 + 1 < p.out_h) | ||
| in_m1 = true; | ||
| else | ||
| in_m1 = false; | ||
|
|
||
| if (n0 < p.out_w) | ||
| in_n0 = true; | ||
| else | ||
| in_n0 = false; | ||
|
|
||
| if (n0 + 1 < p.out_w) | ||
| in_n1 = true; | ||
| else | ||
| in_n1 = false; | ||
|
|
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The boolean assignments can be simplified. Instead of using if-else statements to assign true/false, directly use the comparison result.
| bool in_m0; // = (m0 < p.out_h); | |
| bool in_m1; // = (m0 + 1 < p.out_h); | |
| bool in_n0; // = (n0 < p.out_w); | |
| bool in_n1; // = (n0 + 1 < p.out_w); | |
| if (m0 < p.out_h) | |
| in_m0 = true; | |
| else | |
| in_m0 = false; | |
| if (m0 + 1 < p.out_h) | |
| in_m1 = true; | |
| else | |
| in_m1 = false; | |
| if (n0 < p.out_w) | |
| in_n0 = true; | |
| else | |
| in_n0 = false; | |
| if (n0 + 1 < p.out_w) | |
| in_n1 = true; | |
| else | |
| in_n1 = false; | |
| bool in_m0 = (m0 < p.out_h); | |
| bool in_m1 = (m0 + 1 < p.out_h); | |
| bool in_n0 = (n0 < p.out_w); | |
| bool in_n1 = (n0 + 1 < p.out_w); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
solve
src/layer/vulkan/shader/matmul.comp
Outdated
| if (transB == 0) | ||
| b_idx1 = b_base + bk * p.b_w + (n0 + 1); | ||
| else | ||
| b_idx1 = b_base + (n0 + 1) * p.b_w + bk; |
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The statements inside these if blocks are missing proper indentation. They should be indented to match the code style used elsewhere in the file.
|
|
No description provided.