Skip to content

Commit 0edf83a

Browse files
committed
[ET-VK][EZ] Fix StorageBuffer size in PrepackNode
Fixing a bug I wrote, but in my defense the bug was in the code I copied. 😛 This change decreases the size of our staging `StorageBuffer`s which were previously bigger than necessary. There's a few numbers describing size at play: ``` numel -> CPU buffer nbytes -> numel * cpu_dtype gpu_numel -> GPU texture gpu_nbytes -> gpu_numel * gpu_dtype ``` Firstly, `StorageBuffer`'s ctor takes `numel` not `nbytes`. Secondly, we should use the CPU size not the GPU size which may be aligned up to a multiple of 4. Differential Revision: [D55619076](https://our.internmc.facebook.com/intern/diff/D55619076/) ghstack-source-id: 220995380 Pull Request resolved: #2811
1 parent d612c23 commit 0edf83a

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

backends/vulkan/runtime/graph/ops/PrepackNode.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ void PrepackNode::encode(ComputeGraph* graph) {
3939
TensorRef tref = graph->get_val(tref_).toTensorRef();
4040
vTensor packed = graph->get_val(packed_).toTensor();
4141

42-
// TODO: Extract to standalone function, to support other types of prepacking.
43-
api::StorageBuffer staging(
44-
graph->context(), packed.dtype(), packed.gpu_nbytes());
4542
size_t numel = api::utils::multiply_integers(tref.sizes);
43+
api::StorageBuffer staging(graph->context(), tref.dtype, numel);
4644
size_t nbytes = numel * api::element_size(tref.dtype);
4745
copy_ptr_to_staging(tref.data, staging, nbytes);
4846

0 commit comments

Comments
 (0)