Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion backends/vulkan/runtime/api/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <executorch/backends/vulkan/runtime/api/ShaderRegistry.h>

#include <executorch/backends/vulkan/runtime/api/containers/ParamsBuffer.h>
#include <executorch/backends/vulkan/runtime/api/containers/StorageBuffer.h>
#include <executorch/backends/vulkan/runtime/api/containers/StagingBuffer.h>
#include <executorch/backends/vulkan/runtime/api/containers/Tensor.h>

#include <executorch/backends/vulkan/runtime/utils/VecUtils.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace vkcompute {
namespace api {

class StorageBuffer final {
class StagingBuffer final {
private:
Context* context_p_;
vkapi::ScalarType dtype_;
Expand All @@ -26,7 +26,7 @@ class StorageBuffer final {
vkapi::VulkanBuffer vulkan_buffer_;

public:
StorageBuffer(
StagingBuffer(
Context* context_p,
const vkapi::ScalarType dtype,
const size_t numel,
Expand All @@ -39,13 +39,13 @@ class StorageBuffer final {
nbytes_,
gpuonly)) {}

StorageBuffer(const StorageBuffer&) = delete;
StorageBuffer& operator=(const StorageBuffer&) = delete;
StagingBuffer(const StagingBuffer&) = delete;
StagingBuffer& operator=(const StagingBuffer&) = delete;

StorageBuffer(StorageBuffer&&) = default;
StorageBuffer& operator=(StorageBuffer&&) = default;
StagingBuffer(StagingBuffer&&) = default;
StagingBuffer& operator=(StagingBuffer&&) = default;

~StorageBuffer() {
~StagingBuffer() {
context_p_->register_buffer_cleanup(vulkan_buffer_);
}

Expand Down
4 changes: 2 additions & 2 deletions backends/vulkan/runtime/graph/ComputeGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace vkcompute {

VALUE_PTR_CLASS_IMPL(vTensorPtr, api::vTensor, Tensor)
VALUE_PTR_CLASS_IMPL(TensorRefPtr, TensorRef, TensorRef)
VALUE_PTR_CLASS_IMPL(StagingPtr, api::StorageBuffer, Staging)
VALUE_PTR_CLASS_IMPL(StagingPtr, api::StagingBuffer, Staging)
VALUE_PTR_CLASS_IMPL(IntListPtr, std::vector<int64_t>, IntList)
VALUE_PTR_CLASS_IMPL(DoubleListPtr, std::vector<double>, DoubleList)
VALUE_PTR_CLASS_IMPL(BoolListPtr, std::vector<bool>, BoolList)
Expand Down Expand Up @@ -236,7 +236,7 @@ ValueRef ComputeGraph::add_staging(
const size_t numel) {
ValueRef idx(static_cast<int>(values_.size()));
check_no_active_value_ptrs();
values_.emplace_back(api::StorageBuffer(context(), dtype, numel));
values_.emplace_back(api::StagingBuffer(context(), dtype, numel));
return idx;
}

Expand Down
2 changes: 1 addition & 1 deletion backends/vulkan/runtime/graph/ComputeGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ComputeGraph;

DECL_VALUE_PTR_CLASS(vTensorPtr, api::vTensor)
DECL_VALUE_PTR_CLASS(TensorRefPtr, TensorRef)
DECL_VALUE_PTR_CLASS(StagingPtr, api::StorageBuffer)
DECL_VALUE_PTR_CLASS(StagingPtr, api::StagingBuffer)
DECL_VALUE_PTR_CLASS(IntListPtr, std::vector<int64_t>)
DECL_VALUE_PTR_CLASS(DoubleListPtr, std::vector<double>)
DECL_VALUE_PTR_CLASS(BoolListPtr, std::vector<bool>)
Expand Down
8 changes: 4 additions & 4 deletions backends/vulkan/runtime/graph/containers/Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct Value final {
} u;

api::vTensor as_tensor;
api::StorageBuffer as_staging;
api::StagingBuffer as_staging;
TensorRef as_tensorref;

std::vector<int64_t> as_int_list;
Expand Down Expand Up @@ -108,7 +108,7 @@ struct Value final {
CASE_MOVE_MOVEABLE_TYPE(
TypeTag::TENSOR, api::vTensor, as_tensor, vTensor);
CASE_MOVE_MOVEABLE_TYPE(
TypeTag::STAGING, api::StorageBuffer, as_staging, StorageBuffer);
TypeTag::STAGING, api::StagingBuffer, as_staging, StagingBuffer);
CASE_MOVE_MOVEABLE_TYPE(
TypeTag::TENSORREF, TensorRef, as_tensorref, TensorRef);
// Scalar lists
Expand Down Expand Up @@ -152,7 +152,7 @@ struct Value final {
payload.as_tensor.~vTensor();
break;
case TypeTag::STAGING:
payload.as_staging.~StorageBuffer();
payload.as_staging.~StagingBuffer();
break;
case TypeTag::TENSORREF:
payload.as_tensorref.~TensorRef();
Expand Down Expand Up @@ -247,7 +247,7 @@ struct Value final {
as_tensor);

SUPPORT_TRIVIALLY_MOVEABLE_TYPE(
api::StorageBuffer,
api::StagingBuffer,
Staging,
TypeTag::STAGING,
as_staging);
Expand Down
8 changes: 4 additions & 4 deletions backends/vulkan/runtime/graph/ops/PrepackNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,22 @@ PrepackNode::PrepackNode(
graph.update_descriptor_counts(noop_shader_, /*execute = */ false);
}

api::StorageBuffer PrepackNode::create_staging_buffer(ComputeGraph* graph) {
api::StagingBuffer PrepackNode::create_staging_buffer(ComputeGraph* graph) {
vTensorPtr packed = graph->get_tensor(packed_);

// If no TensorRef is provided, create a staging buffer of zeros according to
// the vkapi::vTensor metadata.
if (graph->val_is_none(tref_)) {
size_t numel = utils::multiply_integers(packed->sizes());
api::StorageBuffer staging(graph->context(), packed->dtype(), numel);
api::StagingBuffer staging(graph->context(), packed->dtype(), numel);
size_t nbytes = numel * vkapi::element_size(packed->dtype());
set_staging_zeros(staging, nbytes);
return staging;
}

TensorRefPtr tref = graph->get_tref(tref_);
size_t numel = utils::multiply_integers(tref->sizes);
api::StorageBuffer staging(graph->context(), tref->dtype, numel);
api::StagingBuffer staging(graph->context(), tref->dtype, numel);
size_t nbytes = numel * vkapi::element_size(tref->dtype);
copy_ptr_to_staging(tref->data, staging, nbytes);
return staging;
Expand All @@ -70,7 +70,7 @@ void PrepackNode::encode(ComputeGraph* graph) {
api::Context* const context = graph->context();

vTensorPtr packed = graph->get_tensor(packed_);
api::StorageBuffer staging = create_staging_buffer(graph);
api::StagingBuffer staging = create_staging_buffer(graph);

std::unique_lock<std::mutex> cmd_lock = context->dispatch_lock();

Expand Down
2 changes: 1 addition & 1 deletion backends/vulkan/runtime/graph/ops/PrepackNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class PrepackNode final {
const vkapi::SpecVarList spec_vars_;

private:
api::StorageBuffer create_staging_buffer(ComputeGraph* graph);
api::StagingBuffer create_staging_buffer(ComputeGraph* graph);
};

} // namespace vkcompute
2 changes: 1 addition & 1 deletion backends/vulkan/runtime/graph/ops/utils/BindingUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ uint32_t bind_params_to_descriptor_set(
}

void bind_staging_to_descriptor_set(
api::StorageBuffer& staging,
api::StagingBuffer& staging,
vkapi::DescriptorSet& descriptor_set,
const uint32_t idx) {
descriptor_set.bind(idx, staging.buffer());
Expand Down
2 changes: 1 addition & 1 deletion backends/vulkan/runtime/graph/ops/utils/BindingUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ uint32_t bind_params_to_descriptor_set(
const uint32_t base_idx);

void bind_staging_to_descriptor_set(
api::StorageBuffer& staging,
api::StagingBuffer& staging,
vkapi::DescriptorSet& descriptor_set,
const uint32_t idx);

Expand Down
6 changes: 3 additions & 3 deletions backends/vulkan/runtime/graph/ops/utils/StagingUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,23 @@ void memcpy_from_mapping(

void copy_ptr_to_staging(
const void* src,
api::StorageBuffer& staging,
api::StagingBuffer& staging,
const size_t nbytes) {
vkapi::MemoryMap mapping(staging.buffer(), vkapi::MemoryAccessType::WRITE);
mapping.invalidate();
memcpy_to_mapping(src, mapping, nbytes, staging.dtype());
}

void copy_staging_to_ptr(
api::StorageBuffer& staging,
api::StagingBuffer& staging,
void* dst,
const size_t nbytes) {
vkapi::MemoryMap mapping(staging.buffer(), vkapi::MemoryAccessType::READ);
mapping.invalidate();
memcpy_from_mapping(mapping, dst, nbytes, staging.dtype());
}

void set_staging_zeros(api::StorageBuffer& staging, const size_t nbytes) {
void set_staging_zeros(api::StagingBuffer& staging, const size_t nbytes) {
vkapi::MemoryMap mapping(staging.buffer(), vkapi::MemoryAccessType::WRITE);
uint8_t* data_ptr = mapping.template data<uint8_t>();
memset(data_ptr, 0, staging.nbytes());
Expand Down
6 changes: 3 additions & 3 deletions backends/vulkan/runtime/graph/ops/utils/StagingUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ namespace vkcompute {

void copy_ptr_to_staging(
const void* src,
api::StorageBuffer& staging,
api::StagingBuffer& staging,
const size_t nbytes);
void copy_staging_to_ptr(
api::StorageBuffer& staging,
api::StagingBuffer& staging,
void* dst,
const size_t nbytes);

void set_staging_zeros(api::StorageBuffer& staging, const size_t nbytes);
void set_staging_zeros(api::StagingBuffer& staging, const size_t nbytes);

//
// Functions to get shaders
Expand Down
6 changes: 3 additions & 3 deletions backends/vulkan/test/utils/test_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void record_image_to_nchw_op(
void record_int8_image_to_nchw_noint8_op(
api::Context* const context,
api::vTensor& v_src,
api::StorageBuffer& dst_buffer) {
api::StagingBuffer& dst_buffer) {
vkapi::PipelineBarrier pipeline_barrier{};
uint32_t buffer_len = utils::safe_downcast<uint32_t>(dst_buffer.numel() / 4);
utils::uvec3 global_wg_size = {buffer_len, 1, 1};
Expand Down Expand Up @@ -324,7 +324,7 @@ void record_reference_matmul(
_(int8_t, QInt8)

void fill_vtensor(api::vTensor& vten, std::vector<float>& data) {
api::StorageBuffer staging_buffer(api::context(), vten.dtype(), data.size());
api::StagingBuffer staging_buffer(api::context(), vten.dtype(), data.size());

#define CASE(ctype, name) \
case vkapi::ScalarType::name: { \
Expand Down Expand Up @@ -411,7 +411,7 @@ void fill_vtensor(
}

void extract_vtensor(api::vTensor& vten, std::vector<float>& data) {
api::StorageBuffer staging_buffer(
api::StagingBuffer staging_buffer(
api::context(), vten.dtype(), vten.staging_buffer_numel());

if (vten.storage_type() == utils::StorageType::BUFFER) {
Expand Down
10 changes: 5 additions & 5 deletions backends/vulkan/test/utils/test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ using namespace vkcompute;
allocate_memory);

#define DEFINE_STAGING_BUFFER_AND_RECORD_TO_GPU_FOR(tensor) \
api::StorageBuffer staging_buffer_##tensor( \
api::StagingBuffer staging_buffer_##tensor( \
api::context(), vkapi::kFloat, tensor.staging_buffer_numel()); \
record_nchw_to_image_op( \
api::context(), staging_buffer_##tensor.buffer(), tensor);

#define DEFINE_STAGING_BUFFER_AND_RECORD_FROM_GPU_FOR(tensor) \
api::StorageBuffer staging_buffer_##tensor( \
api::StagingBuffer staging_buffer_##tensor( \
api::context(), vkapi::kFloat, tensor.staging_buffer_numel()); \
record_image_to_nchw_op( \
api::context(), tensor, staging_buffer_##tensor.buffer());
Expand Down Expand Up @@ -85,7 +85,7 @@ void record_image_to_nchw_op(
void record_int8_image_to_nchw_noint8_op(
api::Context* const context,
api::vTensor& v_src,
api::StorageBuffer& dst_buffer);
api::StagingBuffer& dst_buffer);

void record_conv2d_prepack_weights_op(
api::Context* const context,
Expand Down Expand Up @@ -126,7 +126,7 @@ void record_reference_matmul(
//

inline void
fill_staging(api::StorageBuffer& staging, float val, int numel = -1) {
fill_staging(api::StagingBuffer& staging, float val, int numel = -1) {
if (numel < 0) {
numel = staging.numel();
}
Expand Down Expand Up @@ -164,7 +164,7 @@ inline std::vector<float> extract_vtensor(api::vTensor& vten) {
}

inline void
check_staging_buffer(api::StorageBuffer& staging, float val, int numel = -1) {
check_staging_buffer(api::StagingBuffer& staging, float val, int numel = -1) {
if (numel < 0) {
numel = staging.numel();
}
Expand Down
16 changes: 8 additions & 8 deletions backends/vulkan/test/vulkan_compute_api_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ TEST_F(VulkanComputeAPITest, spec_var_classes_test) {

TEST_F(VulkanComputeAPITest, spec_var_shader_test) {
size_t len = 16;
StorageBuffer buffer(context(), vkapi::kFloat, len);
StagingBuffer buffer(context(), vkapi::kFloat, len);

float scale = 3.0f;
float offset = 1.5f;
Expand Down Expand Up @@ -407,7 +407,7 @@ TEST_F(VulkanComputeAPITest, update_params_between_submit) {
params.buffer());
}

StorageBuffer staging_buffer(
StagingBuffer staging_buffer(
context(), vkapi::kFloat, a.staging_buffer_numel());
record_image_to_nchw_op(context(), a, staging_buffer.buffer());

Expand All @@ -428,7 +428,7 @@ TEST_F(VulkanComputeAPITest, update_params_between_submit) {

template <typename T, vkapi::ScalarType dtype>
void test_storage_buffer_type(const size_t len) {
StorageBuffer buffer(context(), dtype, len);
StagingBuffer buffer(context(), dtype, len);

std::string kernel_name("idx_fill_buffer");
switch (dtype) {
Expand Down Expand Up @@ -2040,7 +2040,7 @@ void run_from_gpu_test(
vten.sizes_ubo());
}

StorageBuffer staging_buffer(context(), dtype, vten.staging_buffer_numel());
StagingBuffer staging_buffer(context(), dtype, vten.staging_buffer_numel());

if (dtype == vkapi::kChar &&
!context()->adapter_ptr()->has_full_int8_buffers_support()) {
Expand Down Expand Up @@ -2073,7 +2073,7 @@ void round_trip_test(
vTensor vten = vTensor(context(), sizes, dtype, storage_type, memory_layout);

// Create and fill input staging buffer
StorageBuffer staging_buffer_in(
StagingBuffer staging_buffer_in(
context(), dtype, vten.staging_buffer_numel());

std::vector<T> data_in(staging_buffer_in.numel());
Expand All @@ -2084,7 +2084,7 @@ void round_trip_test(
data_in.data(), staging_buffer_in, vten.staging_buffer_nbytes());

// Output staging buffer
StorageBuffer staging_buffer_out(
StagingBuffer staging_buffer_out(
context(), dtype, vten.staging_buffer_numel());

record_nchw_to_image_op(context(), staging_buffer_in.buffer(), vten);
Expand Down Expand Up @@ -2538,7 +2538,7 @@ void test_conv2d(

// Create and fill input staging buffer
const int64_t in_numel = utils::multiply_integers(original_sizes);
StorageBuffer staging_buffer_in(context(), vkapi::kFloat, in_numel);
StagingBuffer staging_buffer_in(context(), vkapi::kFloat, in_numel);

std::vector<float> data_in(in_numel);
for (int i = 0; i < in_numel; i++) {
Expand All @@ -2550,7 +2550,7 @@ void test_conv2d(
// Output staging buffer
const int64_t out_numel =
padded_sizes[0] * padded_sizes[1] * original_sizes[2] * original_sizes[3];
StorageBuffer staging_buffer_out(context(), vkapi::kFloat, out_numel);
StagingBuffer staging_buffer_out(context(), vkapi::kFloat, out_numel);

// Copy data in and out of the tensor
record_conv2d_prepack_weights_op(
Expand Down
6 changes: 3 additions & 3 deletions backends/vulkan/tools/gpuinfo/include/architecture.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void reg_count(const App& app) {
uint32_t NITER;

auto bench = [&](uint32_t ngrp, uint32_t nreg) {
StorageBuffer buffer(context(), vkapi::kFloat, 1);
StagingBuffer buffer(context(), vkapi::kFloat, 1);
vkapi::PipelineBarrier pipeline_barrier{};

auto shader_name = "reg_count_" + std::to_string(nreg);
Expand Down Expand Up @@ -164,7 +164,7 @@ void warp_size(const App& app, const bool verbose = false) {
uint32_t NITER;

auto bench = [&](uint32_t nthread) {
StorageBuffer out_buf(context(), vkapi::kInt, app.nthread_logic);
StagingBuffer out_buf(context(), vkapi::kInt, app.nthread_logic);
vkapi::PipelineBarrier pipeline_barrier{};

auto shader_name = "warp_size_physical";
Expand Down Expand Up @@ -224,7 +224,7 @@ void warp_size(const App& app, const bool verbose = false) {
// doesn't depend on kernel timing, so the extra wait time doesn't lead to
// inaccuracy.
auto bench_sm = [&](uint32_t nthread) {
StorageBuffer out_buf(context(), vkapi::kInt, app.nthread_logic);
StagingBuffer out_buf(context(), vkapi::kInt, app.nthread_logic);
vkapi::PipelineBarrier pipeline_barrier{};

auto shader_name = "warp_size_scheduler";
Expand Down
Loading
Loading