Skip to content

[ET-VK] Introduce add_tensor overloads consuming TensorRef #2835

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

Closed
wants to merge 3 commits into from
Closed
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
21 changes: 16 additions & 5 deletions backends/vulkan/runtime/graph/ComputeGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,27 @@ ValueRef ComputeGraph::add_tensor(
sizes, dtype, suggested_storage_type(), memory_layout, shared_object_idx);
}

ValueRef ComputeGraph::add_tensor_like(
const ValueRef vref,
const api::StorageType storage_type,
const api::GPUMemoryLayout memory_layout) {
TensorRef& tref = get_val(vref).toTensorRef();
return add_tensor(tref.sizes, tref.dtype, storage_type, memory_layout);
}

ValueRef ComputeGraph::add_tensor_like(
const ValueRef vref,
const api::GPUMemoryLayout memory_layout) {
TensorRef& tref = get_val(vref).toTensorRef();
return add_tensor(tref.sizes, tref.dtype, memory_layout);
}

ValueRef ComputeGraph::add_tensor(
const std::vector<int64_t>& sizes,
const api::ScalarType dtype,
const int64_t shared_object_idx) {
return add_tensor(
sizes,
dtype,
suggested_storage_type(),
suggested_memory_layout(sizes),
shared_object_idx);
sizes, dtype, suggested_memory_layout(sizes), shared_object_idx);
}

ValueRef ComputeGraph::add_tensorref(
Expand Down
20 changes: 18 additions & 2 deletions backends/vulkan/runtime/graph/ComputeGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class ComputeGraph final {
const api::ScalarType dtype,
const api::StorageType storage_type,
const api::GPUMemoryLayout memory_layout,
const int64_t shared_object_idx);
const int64_t shared_object_idx = -1);

/*
* Add a `vTensor` value to the graph with the specified properties. The
Expand All @@ -191,9 +191,25 @@ class ComputeGraph final {
*/
ValueRef add_tensor(
const std::vector<int64_t>& sizes,
const api::ScalarType dtype = api::ScalarType::Float,
const api::ScalarType dtype,
const int64_t shared_object_idx = -1);

/*
* Add a `vTensor` value to the graph with the properties of `vref`.
*/
ValueRef add_tensor_like(
const ValueRef vref,
const api::StorageType storage_type,
const api::GPUMemoryLayout memory_layout);

/*
* Add a `vTensor` value to the graph with the properties of `vref`. The
* suggested storage type will be used to construct the `vTensor`.
*/
ValueRef add_tensor_like(
const ValueRef vref,
const api::GPUMemoryLayout memory_layout);

/*
* Add a `TensorRef` value to the graph with the specific properties. A
* `TensorRef` is a reference to a `vTensor` whose data is stored in an
Expand Down
3 changes: 1 addition & 2 deletions backends/vulkan/runtime/graph/ops/impl/Staging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ ValueRef prepack(
ComputeGraph& graph,
const ValueRef vref,
const api::GPUMemoryLayout layout) {
TensorRef& tref = graph.get_val(vref).toTensorRef();
ValueRef v = graph.add_tensor(tref.sizes, tref.dtype, layout);
ValueRef v = graph.add_tensor_like(vref, layout);
vTensor& t = graph.get_val(v).toTensor();

api::ShaderInfo shader = get_nchw_to_image_shader(t);
Expand Down