Skip to content

Commit f3fde3c

Browse files
authored
[ET-VK] Use shared pointer for vTensorStorage (#11487)
## Changes * In `vTensor`, store the `storage_` member using a shared pointer instead of a direct `vTensorStorage` object * Remove the ability to construct a tensor view with a buffer offset ## Motivation > * In `vTensor`, store the `storage_` member using a shared pointer instead of a direct `vTensorStorage` object Previously, to support the ability to create tensor views I implemented copy constructors for `VulkanImage`, `VulkanBuffer`, and `vTensorStorage`. The idea was that the copied object instance would have the same handles as the original, but would not own the handle (and therefore not be responsible for destroying it). However, the problem with this approach is that in order to construct pipeline barriers and image layout transitions properly, we must know the details of how a resource was last accessed. Since tensor views make copies, accessing the original tensor will not update the access information of any copies it may have. Therefore, if the copy is then accessed, the last access information it stores would then be out of date. I originally tried to solve this problem with crude assumptions in the `transition()` function, but unfortunately the solution was not robust enough. I discovered validation errors such as ``` [ RUN ] VulkanComputeGraphOpsTest.test_transpose_with_mm VUID-VkImageMemoryBarrier-oldLayout-01197(ERROR / SPEC): msgNum: 307231540 - Validation Error: [ VUID-VkImageMemoryBarrier-oldLayout-01197 ] Object 0: handle = 0x21eba07e160, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0x35643f0000000111, type = VK_OBJECT_TYPE_IMAGE; | MessageID = 0x124ffb34 | vkCmdPipelineBarrier(): pImageMemoryBarriers[2].image (VkImage 0x35643f0000000111[]) cannot transition the layout of aspect=1, level=0, layer=0 from VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL when the previous known layout is VK_IMAGE_LAYOUT_GENERAL. The Vulkan spec states: If srcQueueFamilyIndex and dstQueueFamilyIndex define a queue family ownership transfer or oldLayout and newLayout define an image layout transition, oldLayout must be VK_IMAGE_LAYOUT_UNDEFINED or the current layout of the image subresources affected by the barrier (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-VkImageMemoryBarrier-oldLayout-01197) Objects: 2 [0] 0x21eba07e160, type: 6, name: NULL [1] 0x35643f0000000111, type: 10, name: NULL UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout(ERROR / SPEC): msgNum: 1303270965 - Validation Error: [ UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout ] Object 0: handle = 0x21eba07e160, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0x35643f0000000111, type = VK_OBJECT_TYPE_IMAGE; | MessageID = 0x4dae5635 | vkQueueSubmit(): pSubmits[0].pCommandBuffers[0] command buffer VkCommandBuffer 0x21eba07e160[] expects VkImage 0x35643f0000000111[] (subresource: aspectMask VK_IMAGE_ASPECT_COLOR_BIT array layer 0, mip level 0) to be in layout VK_IMAGE_LAYOUT_GENERAL--instead, current layout is VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL. Objects: 2 [0] 0x21eba07e160, type: 6, name: NULL [1] 0x35643f0000000111, type: 10, name: NULL VUID-VkImageMemoryBarrier-oldLayout-01197(ERROR / SPEC): msgNum: 307231540 - Validation Error: [ VUID-VkImageMemoryBarrier-oldLayout-01197 ] Object 0: handle = 0x21eba07e160, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0x35643f0000000111, type = VK_OBJECT_TYPE_IMAGE; | MessageID = 0x124ffb34 | vkCmdPipelineBarrier(): pImageMemoryBarriers[2].image (VkImage 0x35643f0000000111[]) cannot transition the layout of aspect=1, level=0, layer=0 from VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL when the previous known layout is VK_IMAGE_LAYOUT_GENERAL. The Vulkan spec states: If srcQueueFamilyIndex and dstQueueFamilyIndex define a queue family ownership transfer or oldLayout and newLayout define an image layout transition, oldLayout must be VK_IMAGE_LAYOUT_UNDEFINED or the current layout of the image subresources affected by the barrier (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-VkImageMemoryBarrier-oldLayout-01197) Objects: 2 [0] 0x21eba07e160, type: 6, name: NULL [1] 0x35643f0000000111, type: 10, name: NULL UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout(ERROR / SPEC): msgNum: 1303270965 - Validation Error: [ UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout ] Object 0: handle = 0x21eba07e160, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0x35643f0000000111, type = VK_OBJECT_TYPE_IMAGE; | MessageID = 0x4dae5635 | vkQueueSubmit(): pSubmits[0].pCommandBuffers[0] command buffer VkCommandBuffer 0x21eba07e160[] expects VkImage 0x35643f0000000111[] (subresource: aspectMask VK_IMAGE_ASPECT_COLOR_BIT array layer 0, mip level 0) to be in layout VK_IMAGE_LAYOUT_GENERAL--instead, current layout is VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL. Objects: 2 [0] 0x21eba07e160, type: 6, name: NULL [1] 0x35643f0000000111, type: 10, name: NULL VUID-VkImageMemoryBarrier-oldLayout-01197(ERROR / SPEC): msgNum: 307231540 - Validation Error: [ VUID-VkImageMemoryBarrier-oldLayout-01197 ] Object 0: handle = 0x21eba07e160, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0x35643f0000000111, type = VK_OBJECT_TYPE_IMAGE; | MessageID = 0x124ffb34 | vkCmdPipelineBarrier(): pImageMemoryBarriers[2].image (VkImage 0x35643f0000000111[]) cannot transition the layout of aspect=1, level=0, layer=0 from VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL when the previous known layout is VK_IMAGE_LAYOUT_GENERAL. The Vulkan spec states: If srcQueueFamilyIndex and dstQueueFamilyIndex define a queue family ownership transfer or oldLayout and newLayout define an image layout transition, oldLayout must be VK_IMAGE_LAYOUT_UNDEFINED or the current layout of the image subresources affected by the barrier (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-VkImageMemoryBarrier-oldLayout-01197) Objects: 2 [0] 0x21eba07e160, type: 6, name: NULL [1] 0x35643f0000000111, type: 10, name: NULL UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout(ERROR / SPEC): msgNum: 1303270965 - Validation Error: [ UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout ] Object 0: handle = 0x21eba07e160, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0x35643f0000000111, type = VK_OBJECT_TYPE_IMAGE; | MessageID = 0x4dae5635 | vkQueueSubmit(): pSubmits[0].pCommandBuffers[0] command buffer VkCommandBuffer 0x21eba07e160[] expects VkImage 0x35643f0000000111[] (subresource: aspectMask VK_IMAGE_ASPECT_COLOR_BIT array layer 0, mip level 0) to be in layout VK_IMAGE_LAYOUT_GENERAL--instead, current layout is VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL. Objects: 2 [0] 0x21eba07e160, type: 6, name: NULL [1] 0x35643f0000000111, type: 10, name: NULL VUID-VkImageMemoryBarrier-oldLayout-01197(ERROR / SPEC): msgNum: 307231540 - Validation Error: [ VUID-VkImageMemoryBarrier-oldLayout-01197 ] Object 0: handle = 0x21eba07e160, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0x35643f0000000111, type = VK_OBJECT_TYPE_IMAGE; | MessageID = 0x124ffb34 | vkCmdPipelineBarrier(): pImageMemoryBarriers[2].image (VkImage 0x35643f0000000111[]) cannot transition the layout of aspect=1, level=0, layer=0 from VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL when the previous known layout is VK_IMAGE_LAYOUT_GENERAL. The Vulkan spec states: If srcQueueFamilyIndex and dstQueueFamilyIndex define a queue family ownership transfer or oldLayout and newLayout define an image layout transition, oldLayout must be VK_IMAGE_LAYOUT_UNDEFINED or the current layout of the image subresources affected by the barrier (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-VkImageMemoryBarrier-oldLayout-01197) Objects: 2 [0] 0x21eba07e160, type: 6, name: NULL [1] 0x35643f0000000111, type: 10, name: NULL UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout(ERROR / SPEC): msgNum: 1303270965 - Validation Error: [ UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout ] Object 0: handle = 0x21eba07e160, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0x35643f0000000111, type = VK_OBJECT_TYPE_IMAGE; | MessageID = 0x4dae5635 | vkQueueSubmit(): pSubmits[0].pCommandBuffers[0] command buffer VkCommandBuffer 0x21eba07e160[] expects VkImage 0x35643f0000000111[] (subresource: aspectMask VK_IMAGE_ASPECT_COLOR_BIT array layer 0, mip level 0) to be in layout VK_IMAGE_LAYOUT_GENERAL--instead, current layout is VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL. Objects: 2 [0] 0x21eba07e160, type: 6, name: NULL [1] 0x35643f0000000111, type: 10, name: NULL VUID-VkImageMemoryBarrier-oldLayout-01197(ERROR / SPEC): msgNum: 307231540 - Validation Error: [ VUID-VkImageMemoryBarrier-oldLayout-01197 ] Object 0: handle = 0x21eba07e160, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0x35643f0000000111, type = VK_OBJECT_TYPE_IMAGE; | MessageID = 0x124ffb34 | vkCmdPipelineBarrier(): pImageMemoryBarriers[2].image (VkImage 0x35643f0000000111[]) cannot transition the layout of aspect=1, level=0, layer=0 from VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL when the previous known layout is VK_IMAGE_LAYOUT_GENERAL. The Vulkan spec states: If srcQueueFamilyIndex and dstQueueFamilyIndex define a queue family ownership transfer or oldLayout and newLayout define an image layout transition, oldLayout must be VK_IMAGE_LAYOUT_UNDEFINED or the current layout of the image subresources affected by the barrier (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-VkImageMemoryBarrier-oldLayout-01197) Objects: 2 [0] 0x21eba07e160, type: 6, name: NULL [1] 0x35643f0000000111, type: 10, name: NULL UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout(ERROR / SPEC): msgNum: 1303270965 - Validation Error: [ UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout ] Object 0: handle = 0x21eba07e160, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0x35643f0000000111, type = VK_OBJECT_TYPE_IMAGE; | MessageID = 0x4dae5635 | vkQueueSubmit(): pSubmits[0].pCommandBuffers[0] command buffer VkCommandBuffer 0x21eba07e160[] expects VkImage 0x35643f0000000111[] (subresource: aspectMask VK_IMAGE_ASPECT_COLOR_BIT array layer 0, mip level 0) to be in layout VK_IMAGE_LAYOUT_GENERAL--instead, current layout is VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL. Objects: 2 [0] 0x21eba07e160, type: 6, name: NULL [1] 0x35643f0000000111, type: 10, name: NULL [ OK ] VulkanComputeGraphOpsTest.test_transpose_with_mm (26 ms) ``` when using tensor views. The simplest solution is to use a shared pointer to store the tensor storage object, that way tensor views can point to the same underlying object instance, and last access metadata will be consistent among all tensor views. > * Remove the ability to construct a tensor view with a buffer offset Removed this because it turns out that buffer properties cannot have arbitrary offsets; there are restrictions for what offsets can be used. The validation errors say it all: ``` [ RUN ] VulkanComputeGraphTest.test_simple_graph_with_view VUID-VkWriteDescriptorSet-descriptorType-00328(ERROR / SPEC): msgNum: -368569266 - Validation Error: [ VUID-VkWriteDescriptorSet-descriptorType-00328 ] | MessageID = 0xea08144e | vkUpdateDescriptorSets(): pDescriptorWrites[1].pBufferInfo[0].offset (84) must be a multiple of device limit minStorageBufferOffsetAlignment 16 when descriptor type is VK_DESCRIPTOR_TYPE_STORAGE_BUFFER. The Vulkan spec states: If descriptorType is VK_DESCRIPTOR_TYPE_STORAGE_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, the offset member of each element of pBufferInfo must be a multiple of VkPhysicalDeviceLimits::minStorageBufferOffsetAlignment (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-VkWriteDescriptorSet-descriptorType-00328) VUID-VkDescriptorBufferInfo-range-00342(ERROR / SPEC): msgNum: -371195848 - Validation Error: [ VUID-VkDescriptorBufferInfo-range-00342 ] Object 0: handle = 0xee647e0000000009, type = VK_OBJECT_TYPE_BUFFER; | MessageID = 0xe9e00038 | vkUpdateDescriptorSets(): pDescriptorWrites[1].pBufferInfo[0].range (224) is larger than buffer size (224) + offset (84). The Vulkan spec states: If range is not equal to VK_WHOLE_SIZE, range must be less than or equal to the size of buffer minus offset (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-VkDescriptorBufferInfo-range-00342) Objects: 1 [0] 0xee647e0000000009, type: 9, name: NULL VUID-VkBufferMemoryBarrier-size-01189(ERROR / SPEC): msgNum: -1238074894 - Validation Error: [ VUID-VkBufferMemoryBarrier-size-01189 ] Object 0: handle = 0x25d7d900870, type = VK_OBJECT_TYPE_COMMAND_BUFFER; | MessageID = 0xb63479f2 | vkCmdPipelineBarrier(): pBufferMemoryBarriers[0].size VkBuffer 0xee647e0000000009[] has offset 0x54 and size 0xe0 whose sum is greater than total size 0xe0. The Vulkan spec states: If size is not equal to VK_WHOLE_SIZE, size must be less than or equal to than the size of buffer minus offset (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-VkBufferMemoryBarrier-size-01189) Objects: 1 [0] 0x25d7d900870, type: 6, name: NULL [ OK ] VulkanComputeGraphTest.test_simple_graph_with_view (8 ms) ``` ## Impact * Heap allocation upon tensor construction * Increased pointer chasing when accessing `vTensor` members I will validate that the impact of this change does not regress load/inference latency. Differential Revision: [D76047204](https://our.internmc.facebook.com/intern/diff/D76047204/)
1 parent 81303f7 commit f3fde3c

File tree

5 files changed

+44
-238
lines changed

5 files changed

+44
-238
lines changed

backends/vulkan/runtime/api/containers/Tensor.cpp

Lines changed: 33 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,7 @@ vTensorStorage::vTensorStorage(
343343
storage_type_,
344344
dtype,
345345
allocate_memory)),
346-
last_access_{},
347-
has_copies_{false} {}
346+
last_access_{} {}
348347

349348
vTensorStorage::vTensorStorage(
350349
Context* const context,
@@ -361,21 +360,6 @@ vTensorStorage::vTensorStorage(
361360
buffer_(vkapi::VulkanBuffer()),
362361
last_access_{} {}
363362

364-
vTensorStorage::vTensorStorage(
365-
vTensorStorage& other,
366-
const int64_t buffer_offset)
367-
: context_(other.context_),
368-
storage_type_{other.storage_type_},
369-
image_extents_(other.image_extents_),
370-
buffer_length_{other.buffer_length_},
371-
buffer_offset_{buffer_offset},
372-
image_(other.image_),
373-
buffer_(other.buffer_, buffer_offset),
374-
last_access_{other.last_access_},
375-
has_copies_{false} {
376-
other.has_copies_ = true;
377-
}
378-
379363
vTensorStorage::~vTensorStorage() {
380364
flush();
381365
}
@@ -397,21 +381,6 @@ void vTensorStorage::transition(
397381
vkapi::PipelineStageFlags prev_stage = last_access_.stage;
398382
vkapi::MemoryAccessFlags prev_access = last_access_.access;
399383

400-
// If the underlying resource is a copy of another tensor's resource the
401-
// last_access may not be accurate, since the original storage may have been
402-
// written to as part of the original tensor. Likewise, if the underlying
403-
// resource has copies, then the resource may have been updated as part of the
404-
// view tensors.
405-
//
406-
// If the resource is a copy, or has copies of it, then cowardly assume that
407-
// it has previously been written to as part of a compute shader before the
408-
// current access event so that the appropriate memory barriers may be
409-
// inserted.
410-
if (is_copy() || has_copies_) {
411-
prev_stage = vkapi::PipelineStage::COMPUTE;
412-
prev_access = vkapi::kWrite;
413-
}
414-
415384
const bool prev_written = (prev_access & vkapi::MemoryAccessType::WRITE) != 0;
416385

417386
VkImageLayout cur_layout = VK_IMAGE_LAYOUT_UNDEFINED;
@@ -458,20 +427,6 @@ void vTensorStorage::transition(
458427
last_access_.access = cur_access;
459428
}
460429

461-
bool vTensorStorage::is_copy() const {
462-
if (storage_type_ == utils::kBuffer) {
463-
return buffer_.is_copy();
464-
}
465-
return image_.is_copy();
466-
}
467-
468-
bool vTensorStorage::is_copy_of(const vTensorStorage& other) const {
469-
if (storage_type_ == utils::kBuffer) {
470-
return buffer_.is_copy_of(other.buffer_);
471-
}
472-
return image_.is_copy_of(other.image_);
473-
}
474-
475430
//
476431
// vTensor
477432
//
@@ -503,14 +458,14 @@ vTensor::vTensor(
503458
numel_uniform_offset_(kUniformOffsetUnset),
504459
logical_limits_uniform_offset_(kUniformOffsetUnset),
505460
// Construct Tensor storage
506-
storage_(
461+
storage_(std::make_shared<vTensorStorage>(
507462
context,
508463
storage_type,
509464
axis_map_,
510465
packed_dim_,
511466
padded_sizes_,
512467
dtype_,
513-
allocate_memory) {
468+
allocate_memory)) {
514469
uniform_data_ = std::make_shared<UniformData>(UniformData{
515470
sizes_,
516471
unsqueezed_strides_,
@@ -519,7 +474,7 @@ vTensor::vTensor(
519474
VK_CHECK_COND(
520475
dim_order_is_valid(dim_order_), "computed dim order is invalid");
521476

522-
set_logical_limits(storage_.image_extents_);
477+
set_logical_limits(storage_->image_extents_);
523478
}
524479

525480
// NOLINTNEXTLINE
@@ -546,13 +501,13 @@ vTensor::vTensor(
546501
numel_uniform_offset_(kUniformOffsetUnset),
547502
logical_limits_uniform_offset_(kUniformOffsetUnset),
548503
// Construct Tensor storage
549-
storage_(context, image) {
504+
storage_(std::make_shared<vTensorStorage>(context, image)) {
550505
uniform_data_ = std::make_shared<UniformData>(UniformData{
551506
sizes_,
552507
{0, 0, 0, 0},
553508
{{0, 0, 0}},
554509
static_cast<size_t>(utils::multiply_integers(sizes_))});
555-
set_logical_limits(storage_.image_extents_);
510+
set_logical_limits(storage_->image_extents_);
556511
}
557512

558513
vTensor::vTensor(vTensor& other)
@@ -583,8 +538,7 @@ vTensor::vTensor(vTensor& other)
583538
vTensor::vTensor(
584539
vTensor& other,
585540
const std::vector<int64_t>& sizes,
586-
const std::vector<int64_t>& dim_order,
587-
const int64_t offset_numel)
541+
const std::vector<int64_t>& dim_order)
588542
: dtype_(other.dtype_),
589543
// Copy tensor size metadata
590544
sizes_(sizes.begin(), sizes.end()),
@@ -604,7 +558,7 @@ vTensor::vTensor(
604558
numel_uniform_offset_(kUniformOffsetUnset),
605559
logical_limits_uniform_offset_(kUniformOffsetUnset),
606560
// Copy Tensor storage
607-
storage_(other.storage_, vkapi::element_size(dtype_) * offset_numel) {
561+
storage_(other.storage_) {
608562
uniform_data_ = std::make_shared<UniformData>(UniformData{
609563
sizes_,
610564
unsqueezed_strides_,
@@ -613,10 +567,6 @@ vTensor::vTensor(
613567

614568
VK_CHECK_COND(
615569
dim_order_is_valid(dim_order_), "new dim order provided is invalid");
616-
VK_CHECK_COND(
617-
offset_numel + numel() <= other.numel(),
618-
"Tensor alias cannot access more elements than available in the original"
619-
"tensor");
620570
}
621571

622572
uint32_t vTensor::UniformData::write_attribute(
@@ -647,31 +597,31 @@ uint32_t vTensor::UniformData::write_attribute(
647597
vkapi::VulkanImage& vTensor::image(
648598
vkapi::PipelineBarrier& pipeline_barrier,
649599
const vkapi::PipelineStageFlags stage) & {
650-
storage_.transition(pipeline_barrier, stage, vkapi::MemoryAccessType::READ);
651-
return storage_.image_;
600+
storage_->transition(pipeline_barrier, stage, vkapi::MemoryAccessType::READ);
601+
return storage_->image_;
652602
}
653603

654604
vkapi::VulkanImage& vTensor::image(
655605
vkapi::PipelineBarrier& pipeline_barrier,
656606
const vkapi::PipelineStageFlags stage,
657607
const vkapi::MemoryAccessFlags access) & {
658-
storage_.transition(pipeline_barrier, stage, access);
659-
return storage_.image_;
608+
storage_->transition(pipeline_barrier, stage, access);
609+
return storage_->image_;
660610
}
661611

662612
vkapi::VulkanBuffer& vTensor::buffer(
663613
vkapi::PipelineBarrier& pipeline_barrier,
664614
const vkapi::PipelineStageFlags stage) & {
665-
storage_.transition(pipeline_barrier, stage, vkapi::MemoryAccessType::READ);
666-
return storage_.buffer_;
615+
storage_->transition(pipeline_barrier, stage, vkapi::MemoryAccessType::READ);
616+
return storage_->buffer_;
667617
}
668618

669619
vkapi::VulkanBuffer& vTensor::buffer(
670620
vkapi::PipelineBarrier& pipeline_barrier,
671621
const vkapi::PipelineStageFlags stage,
672622
const vkapi::MemoryAccessFlags access) & {
673-
storage_.transition(pipeline_barrier, stage, access);
674-
return storage_.buffer_;
623+
storage_->transition(pipeline_barrier, stage, access);
624+
return storage_->buffer_;
675625
}
676626

677627
void vTensor::set_logical_limits(const utils::uvec3& image_extents) {
@@ -695,10 +645,10 @@ utils::GPUMemoryLayout vTensor::estimate_memory_layout() const {
695645

696646
const vkapi::BufferBindInfo vTensor::sizes_ubo() {
697647
const size_t size_per_ubo =
698-
storage_.context_->adapter_ptr()->min_ubo_alignment();
648+
storage_->context_->adapter_ptr()->min_ubo_alignment();
699649
const size_t max_ubo_size = kMaxMetadataFieldCount * size_per_ubo;
700650
if (!uniforms_.buffer()) {
701-
uniforms_ = ParamsBuffer(storage_.context_, max_ubo_size, true);
651+
uniforms_ = ParamsBuffer(storage_->context_, max_ubo_size, true);
702652
}
703653
if (sizes_uniform_offset_ == kUniformOffsetUnset) {
704654
VK_CHECK_COND(
@@ -714,10 +664,10 @@ const vkapi::BufferBindInfo vTensor::sizes_ubo() {
714664

715665
const vkapi::BufferBindInfo vTensor::strides_ubo() {
716666
const size_t size_per_ubo =
717-
storage_.context_->adapter_ptr()->min_ubo_alignment();
667+
storage_->context_->adapter_ptr()->min_ubo_alignment();
718668
const size_t max_ubo_size = kMaxMetadataFieldCount * size_per_ubo;
719669
if (!uniforms_.buffer()) {
720-
uniforms_ = ParamsBuffer(storage_.context_, max_ubo_size, true);
670+
uniforms_ = ParamsBuffer(storage_->context_, max_ubo_size, true);
721671
}
722672
if (unsqueezed_strides_offset_ == kUniformOffsetUnset) {
723673
VK_CHECK_COND(
@@ -735,10 +685,10 @@ const vkapi::BufferBindInfo vTensor::strides_ubo() {
735685

736686
const vkapi::BufferBindInfo vTensor::logical_limits_ubo() {
737687
const size_t size_per_ubo =
738-
storage_.context_->adapter_ptr()->min_ubo_alignment();
688+
storage_->context_->adapter_ptr()->min_ubo_alignment();
739689
const size_t max_ubo_size = kMaxMetadataFieldCount * size_per_ubo;
740690
if (!uniforms_.buffer()) {
741-
uniforms_ = ParamsBuffer(storage_.context_, max_ubo_size, true);
691+
uniforms_ = ParamsBuffer(storage_->context_, max_ubo_size, true);
742692
}
743693
if (logical_limits_uniform_offset_ == kUniformOffsetUnset) {
744694
VK_CHECK_COND(
@@ -754,10 +704,10 @@ const vkapi::BufferBindInfo vTensor::logical_limits_ubo() {
754704

755705
const vkapi::BufferBindInfo vTensor::numel_ubo() {
756706
const size_t size_per_ubo =
757-
storage_.context_->adapter_ptr()->min_ubo_alignment();
707+
storage_->context_->adapter_ptr()->min_ubo_alignment();
758708
const size_t max_ubo_size = kMaxMetadataFieldCount * size_per_ubo;
759709
if (!uniforms_.buffer()) {
760-
uniforms_ = ParamsBuffer(storage_.context_, max_ubo_size, true);
710+
uniforms_ = ParamsBuffer(storage_->context_, max_ubo_size, true);
761711
}
762712
if (numel_uniform_offset_ == kUniformOffsetUnset) {
763713
VK_CHECK_COND(
@@ -774,7 +724,7 @@ const vkapi::BufferBindInfo vTensor::numel_ubo() {
774724
size_t vTensor::staging_buffer_numel() const {
775725
const bool is_int8 = dtype_ == vkapi::kChar;
776726
const bool int8_supported =
777-
storage_.context_->adapter_ptr()->has_full_int8_buffers_support();
727+
storage_->context_->adapter_ptr()->has_full_int8_buffers_support();
778728
if (is_int8 && !int8_supported) {
779729
return utils::align_up_4(numel());
780730
}
@@ -787,22 +737,22 @@ size_t vTensor::staging_buffer_numel() const {
787737
VkMemoryRequirements vTensor::get_memory_requirements() const {
788738
switch (storage_type()) {
789739
case utils::kBuffer:
790-
return storage_.buffer_.get_memory_requirements();
740+
return storage_->buffer_.get_memory_requirements();
791741
case utils::kTexture2D:
792742
case utils::kTexture3D:
793-
return storage_.image_.get_memory_requirements();
743+
return storage_->image_.get_memory_requirements();
794744
}
795745
return {};
796746
}
797747

798748
void vTensor::bind_allocation(const vkapi::Allocation& allocation) {
799749
switch (storage_type()) {
800750
case utils::kBuffer:
801-
storage_.buffer_.bind_allocation(allocation);
751+
storage_->buffer_.bind_allocation(allocation);
802752
break;
803753
case utils::kTexture2D:
804754
case utils::kTexture3D:
805-
storage_.image_.bind_allocation(allocation);
755+
storage_->image_.bind_allocation(allocation);
806756
break;
807757
}
808758
}
@@ -845,11 +795,11 @@ void vTensor::check_sizes(const std::vector<int64_t>& sizes) const {
845795
utils::uvec3 virtual_extents =
846796
calculate_image_extents(padded_sizes_, axis_map_, packed_dim_);
847797

848-
bool valid_resize = virtual_extents[0] <= storage_.image_extents_[0];
798+
bool valid_resize = virtual_extents[0] <= storage_->image_extents_[0];
849799
valid_resize =
850-
valid_resize && virtual_extents[1] <= storage_.image_extents_[1];
800+
valid_resize && virtual_extents[1] <= storage_->image_extents_[1];
851801
valid_resize =
852-
valid_resize && virtual_extents[2] <= storage_.image_extents_[2];
802+
valid_resize && virtual_extents[2] <= storage_->image_extents_[2];
853803

854804
VK_CHECK_COND(
855805
valid_resize,
@@ -859,7 +809,7 @@ void vTensor::check_sizes(const std::vector<int64_t>& sizes) const {
859809
// new sizes of the tensor.
860810
int64_t numel = utils::multiply_integers(sizes);
861811
bool valid_resize =
862-
numel + storage_.buffer_offset_ <= storage_.buffer_length_;
812+
numel + storage_->buffer_offset_ <= storage_->buffer_length_;
863813
VK_CHECK_COND(
864814
valid_resize,
865815
"tensor sizes requires a larger buffer than the current one.");

0 commit comments

Comments
 (0)