Skip to content

Commit c5a6531

Browse files
pytorchbotmansnilszingo
authored
Add support for non tensor inputs to portable executor runner (#14436)
Co-authored-by: Måns Nilsson <[email protected]> Co-authored-by: Zingo Andersen <[email protected]>
1 parent b0294e2 commit c5a6531

File tree

6 files changed

+75
-25
lines changed

6 files changed

+75
-25
lines changed

backends/arm/test/ops/test_acos.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# LICENSE file in the root directory of this source tree.
55
from typing import Tuple
66

7-
import pytest
87
import torch
98

109
from executorch.backends.arm.test import common
@@ -105,10 +104,7 @@ def test_acos_vgf_FP(test_data: Tuple):
105104
tosa_version="TOSA-1.0+FP",
106105
run_on_vulkan_runtime=True,
107106
)
108-
try:
109-
pipeline.run()
110-
except FileNotFoundError as e:
111-
pytest.skip(f"VKML executor_runner not found - not built - skip {e}")
107+
pipeline.run()
112108

113109

114110
@common.parametrize("test_data", test_data_suite)
@@ -122,7 +118,4 @@ def test_acos_vgf_INT(test_data: Tuple):
122118
tosa_version="TOSA-1.0+INT",
123119
run_on_vulkan_runtime=True,
124120
)
125-
try:
126-
pipeline.run()
127-
except FileNotFoundError as e:
128-
pytest.skip(f"VKML executor_runner not found - not built - skip {e}")
121+
pipeline.run()

backends/arm/test/ops/test_add.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,7 @@ def test_add_tensor_vgf_FP(test_data: input_t1):
211211
tosa_version="TOSA-1.0+FP",
212212
run_on_vulkan_runtime=True,
213213
)
214-
try:
215-
pipeline.run()
216-
except FileNotFoundError as e:
217-
pytest.skip(f"VKML executor_runner not found - not built - skip {e}")
214+
pipeline.run()
218215

219216

220217
@common.parametrize("test_data", Add.test_data)
@@ -228,10 +225,7 @@ def test_add_tensor_vgf_INT(test_data: input_t1):
228225
tosa_version="TOSA-1.0+INT",
229226
run_on_vulkan_runtime=True,
230227
)
231-
try:
232-
pipeline.run()
233-
except FileNotFoundError as e:
234-
pytest.skip(f"VKML executor_runner not found - not built - skip {e}")
228+
pipeline.run()
235229

236230

237231
def get_symmetric_a16w8_add_quantizer(per_channel_quantization=False):

backends/arm/test/ops/test_sum.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ def test_view_u85_INT_1_0(test_data: Tuple):
9494
@common.SkipIfNoModelConverter
9595
def test_sum_dim_intlist_vgf_FP(test_data: input_t1):
9696
pipeline = VgfPipeline[input_t1](
97-
Sum(), test_data(), aten_op, tosa_version="TOSA-1.0+FP"
97+
Sum(),
98+
test_data(),
99+
aten_op,
100+
tosa_version="TOSA-1.0+FP",
101+
run_on_vulkan_runtime=True,
98102
)
99103
pipeline.run()
100104

@@ -107,6 +111,7 @@ def test_sum_dim_intlist_vgf_INT(test_data: input_t1):
107111
test_data(),
108112
aten_op,
109113
tosa_version="TOSA-1.0+INT",
114+
run_on_vulkan_runtime=True,
110115
)
111116
pipeline.run()
112117

backends/arm/test/tester/test_pipeline.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ class VgfPipeline(BasePipelineMaker, Generic[T]):
906906
exir_ops: Exir dialect ops expected to be found in the graph after to_edge.
907907
if not using use_edge_to_transform_and_lower.
908908
909-
run_on_vulkan_runtime: Set to true to test VGF output on VKML runtime.
909+
run_on_vulkan_runtime: Whether to test VGF output on VKML runtime.
910910
911911
vgf_compiler_flags: Optional compiler flags.
912912
@@ -1018,3 +1018,16 @@ def __init__(
10181018
qtol=qtol,
10191019
inputs=self.test_data,
10201020
)
1021+
self.run_on_vulkan_runtime = run_on_vulkan_runtime
1022+
1023+
# TODO: Remove once CI fully working
1024+
def run(self):
1025+
import pytest
1026+
1027+
if self.run_on_vulkan_runtime:
1028+
try:
1029+
super().run()
1030+
except FileNotFoundError as e:
1031+
pytest.skip(f"VKML executor_runner not found - not built - skip {e}")
1032+
else:
1033+
super().run()

examples/portable/executor_runner/executor_runner.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,21 +175,33 @@ int main(int argc, char** argv) {
175175
std::vector<std::pair<char*, size_t>> input_buffers;
176176

177177
std::stringstream list_of_input_files(FLAGS_inputs);
178-
std::string token;
178+
std::string path;
179+
180+
// First reserve memory for number of vector elements to avoid vector
181+
// reallocations when emplacing back.
182+
std::vector<std::string> file_paths;
183+
while (std::getline(list_of_input_files, path, ',')) {
184+
file_paths.push_back(std::move(path));
185+
}
186+
inputs_storage.reserve(file_paths.size());
187+
188+
for (const auto& file_path : file_paths) {
189+
std::ifstream input_file_handle(
190+
file_path, std::ios::binary | std::ios::ate);
179191

180-
while (std::getline(list_of_input_files, token, ',')) {
181-
std::ifstream input_file_handle(token, std::ios::binary | std::ios::ate);
182192
if (!input_file_handle) {
183-
ET_LOG(Error, "Failed to open input file: %s\n", token.c_str());
193+
ET_LOG(Error, "Failed to open input file: %s\n", file_path.c_str());
184194
return 1;
185195
}
186196

187197
std::streamsize file_size = input_file_handle.tellg();
188198
input_file_handle.seekg(0, std::ios::beg);
189199

200+
// Reserve memory for actual file contents.
190201
inputs_storage.emplace_back(file_size, '\0');
202+
191203
if (!input_file_handle.read(&inputs_storage.back()[0], file_size)) {
192-
ET_LOG(Error, "Failed to read input file: %s\n", token.c_str());
204+
ET_LOG(Error, "Failed to read input file: %s\n", file_path.c_str());
193205
return 1;
194206
}
195207

extension/runner_util/inputs.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,40 @@ Result<BufferCleanup> prepare_input_tensors(
7878
continue;
7979
}
8080
if (tag.get() != Tag::Tensor) {
81-
ET_LOG(Debug, "Skipping non-tensor input %zu", i);
81+
if (!hard_code_inputs_to_ones) {
82+
Error err = Error::Ok;
83+
auto [buffer, buffer_size] = input_buffers.at(i);
84+
85+
ET_LOG(
86+
Debug, "Verifying and setting input for non-tensor input %zu", i);
87+
88+
if (tag.get() == Tag::Int) {
89+
int64_t int_input;
90+
std::memcpy(&int_input, buffer, buffer_size);
91+
err = method.set_input(runtime::EValue(int_input), i);
92+
} else if (tag.get() == Tag::Double) {
93+
double double_input;
94+
std::memcpy(&double_input, buffer, buffer_size);
95+
err = method.set_input(runtime::EValue(double_input), i);
96+
} else if (tag.get() == Tag::Bool) {
97+
bool bool_input;
98+
std::memcpy(&bool_input, buffer, buffer_size);
99+
err = method.set_input(runtime::EValue(bool_input), i);
100+
} else {
101+
ET_LOG(
102+
Error,
103+
"Input %zu of type %zu not supported",
104+
i,
105+
static_cast<size_t>(tag.get()));
106+
err = Error::InvalidArgument;
107+
}
108+
if (err != Error::Ok) {
109+
BufferCleanup cleanup({inputs, num_allocated});
110+
return err;
111+
}
112+
} else {
113+
ET_LOG(Debug, "Skipping non-tensor input %zu", i);
114+
}
82115
continue;
83116
}
84117
Result<TensorInfo> tensor_meta = method_meta.input_tensor_meta(i);

0 commit comments

Comments
 (0)