Skip to content

Commit 69cfc91

Browse files
committed
[ET-VK][EZ] Assign trivially moveable values to const-ref variables
The [`toType()` methods return a reference](https://github.com/pytorch/executorch/blob/be618c27ee75fb949f3479115f4ea585ea291451/backends/vulkan/runtime/graph/containers/Value.h#L222) so there's no need to copy the return value. Differential Revision: [D55701570](https://our.internmc.facebook.com/intern/diff/D55701570/) ghstack-source-id: 221145473 Pull Request resolved: pytorch/executorch#2834
1 parent 03ad2bf commit 69cfc91

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ void PrepackNode::encode(ComputeGraph* graph) {
3636
api::Context* const context = graph->context();
3737
api::PipelineBarrier pipeline_barrier{};
3838

39-
TensorRef tref = graph->get_val(tref_).toTensorRef();
40-
vTensor packed = graph->get_val(packed_).toTensor();
39+
TensorRef& tref = graph->get_val(tref_).toTensorRef();
40+
vTensor& packed = graph->get_val(packed_).toTensor();
4141

4242
size_t numel = api::utils::multiply_integers(tref.sizes);
4343
api::StorageBuffer staging(graph->context(), tref.dtype, numel);

backends/vulkan/runtime/graph/ops/impl/Staging.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ ValueRef prepack(
6565
const api::GPUMemoryLayout layout) {
6666
TensorRef& tref = graph.get_val(vref).toTensorRef();
6767
ValueRef v = graph.add_tensor(tref.sizes, tref.dtype, layout);
68-
vTensor t = graph.get_val(v).toTensor();
68+
vTensor& t = graph.get_val(v).toTensor();
6969

7070
api::ShaderInfo shader = get_nchw_to_image_shader(t);
7171

backends/vulkan/runtime/graph/ops/impl/Sum.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void add_sum_dim_IntList(
120120
vTensor& in_tensor = graph.get_val(in).toTensor();
121121

122122
std::set<int64_t> dims_set;
123-
auto dims_to_sum = graph.get_val(opt_dim).toIntList();
123+
const auto& dims_to_sum = graph.get_val(opt_dim).toIntList();
124124
int64_t in_dim = in_tensor.sizes().size();
125125

126126
for (const auto& dim : dims_to_sum) {

backends/vulkan/test/vulkan_compute_api_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ TEST(VulkanComputeGraphTest, test_values_scalar_list_inplace_constructed) {
401401
ComputeGraph graph(config);
402402

403403
ValueRef idx = graph.add_scalar_list<int64_t>({1, 2, 3, 4});
404-
std::vector<int64_t>& arr = graph.get_val(idx).toIntList();
404+
const auto& arr = graph.get_val(idx).toIntList();
405405
EXPECT_TRUE(arr.size() == 4);
406406
for (int i = 0; i < 4; i++) {
407407
EXPECT_TRUE(arr[i] == i + 1);
@@ -417,7 +417,7 @@ TEST(VulkanComputeGraphTest, test_values_scalar_list_outside_constructed) {
417417
std::vector<double> data = {5.0, 4.0, 3.0, 2.0, 1.0};
418418
idx = graph.add_scalar_list(std::move(data));
419419
}
420-
std::vector<double>& arr = graph.get_val(idx).toDoubleList();
420+
const auto& arr = graph.get_val(idx).toDoubleList();
421421
EXPECT_TRUE(arr.size() == 5);
422422
for (int i = 0; i < 5; i++) {
423423
EXPECT_TRUE(arr[i] == (5 - i));

0 commit comments

Comments
 (0)