Skip to content

Commit 6feb639

Browse files
authored
Remove all uses of PrepareInputTensors
Differential Revision: D61750837 Pull Request resolved: #4910
1 parent a532d9c commit 6feb639

File tree

5 files changed

+49
-51
lines changed

5 files changed

+49
-51
lines changed

runtime/executor/test/allocation_failure_stress_test.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,28 @@
1111
#include <memory>
1212

1313
#include <executorch/extension/data_loader/file_data_loader.h>
14+
#include <executorch/extension/runner_util/inputs.h>
1415
#include <executorch/runtime/core/exec_aten/exec_aten.h>
1516
#include <executorch/runtime/executor/method.h>
1617
#include <executorch/runtime/executor/program.h>
1718
#include <executorch/runtime/executor/test/managed_memory_manager.h>
1819
#include <executorch/runtime/platform/runtime.h>
19-
#include <executorch/util/util.h>
2020

2121
#include <gtest/gtest.h>
2222

2323
using namespace ::testing;
2424
using exec_aten::ArrayRef;
2525
using exec_aten::Scalar;
2626
using exec_aten::Tensor;
27+
using executorch::extension::FileDataLoader;
28+
using executorch::extension::prepare_input_tensors;
2729
using executorch::runtime::Error;
2830
using executorch::runtime::MemoryAllocator;
2931
using executorch::runtime::MemoryManager;
3032
using executorch::runtime::Method;
3133
using executorch::runtime::Program;
3234
using executorch::runtime::Result;
3335
using executorch::runtime::testing::ManagedMemoryManager;
34-
using torch::executor::util::FileDataLoader;
3536

3637
constexpr size_t kDefaultNonConstMemBytes = 32 * 1024U;
3738
constexpr size_t kDefaultRuntimeMemBytes = 32 * 1024U;
@@ -85,10 +86,9 @@ TEST_F(AllocationFailureStressTest, End2EndIncreaseRuntimeMemUntilSuccess) {
8586

8687
// Execution does not use the runtime allocator, so it should always succeed
8788
// once load was successful.
88-
exec_aten::ArrayRef<void*> inputs =
89-
torch::executor::util::PrepareInputTensors(*method);
89+
auto input_cleanup = prepare_input_tensors(*method);
90+
ASSERT_EQ(input_cleanup.error(), Error::Ok);
9091
err = method->execute();
91-
torch::executor::util::FreeInputs(inputs);
9292
ASSERT_EQ(err, Error::Ok);
9393
}
9494
EXPECT_GT(num_load_failures, 0) << "Expected at least some failures";
@@ -121,10 +121,9 @@ TEST_F(AllocationFailureStressTest, End2EndNonConstantMemUntilSuccess) {
121121

122122
// Execution does not use the runtime allocator, so it should always succeed
123123
// once load was successful.
124-
exec_aten::ArrayRef<void*> inputs =
125-
torch::executor::util::PrepareInputTensors(*method);
124+
auto input_cleanup = prepare_input_tensors(*method);
125+
ASSERT_EQ(input_cleanup.error(), Error::Ok);
126126
err = method->execute();
127-
torch::executor::util::FreeInputs(inputs);
128127
ASSERT_EQ(err, Error::Ok);
129128
}
130129
EXPECT_GT(num_load_failures, 0) << "Expected at least some failures";

runtime/executor/test/backend_integration_test.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include <executorch/extension/data_loader/buffer_data_loader.h>
1616
#include <executorch/extension/data_loader/file_data_loader.h>
17+
#include <executorch/extension/runner_util/inputs.h>
1718
#include <executorch/runtime/backend/interface.h>
1819
#include <executorch/runtime/core/error.h>
1920
#include <executorch/runtime/core/result.h>
@@ -23,7 +24,6 @@
2324
#include <executorch/runtime/platform/runtime.h>
2425
#include <executorch/test/utils/DeathTest.h>
2526
#include <executorch/test/utils/alignment.h>
26-
#include <executorch/util/util.h>
2727

2828
#include <gtest/gtest.h>
2929

@@ -454,10 +454,9 @@ TEST_P(BackendIntegrationTest, EndToEndTestWithProcessedAsHandle) {
454454
EXPECT_FALSE(spy_loader.WasFreed(init_processed->data()));
455455
auto method(std::move(method_res.get()));
456456
// Execute the model.
457-
exec_aten::ArrayRef<void*> inputs =
458-
torch::executor::util::PrepareInputTensors(method);
457+
auto input_cleanup = executorch::extension::prepare_input_tensors(method);
458+
ASSERT_EQ(input_cleanup.error(), Error::Ok);
459459
auto err = method.execute();
460-
torch::executor::util::FreeInputs(inputs);
461460
EXPECT_EQ(err, Error::Ok);
462461

463462
// Check that the processed buffer was passed to execute() as the handle.

runtime/executor/test/kernel_integration_test.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <memory>
1414

1515
#include <executorch/extension/data_loader/file_data_loader.h>
16+
#include <executorch/extension/runner_util/inputs.h>
1617
#include <executorch/runtime/core/error.h>
1718
#include <executorch/runtime/core/result.h>
1819
#include <executorch/runtime/executor/method.h>
@@ -22,7 +23,6 @@
2223
#include <executorch/runtime/kernel/operator_registry.h>
2324
#include <executorch/runtime/platform/compiler.h>
2425
#include <executorch/runtime/platform/runtime.h>
25-
#include <executorch/util/util.h>
2626

2727
#include <gtest/gtest.h>
2828

@@ -158,12 +158,15 @@ class KernelIntegrationTest : public ::testing::Test {
158158
method_ = std::make_unique<Method>(std::move(method.get()));
159159

160160
// Set up its inputs.
161-
inputs_ = torch::executor::util::PrepareInputTensors(*method_);
161+
auto inputs_cleanup =
162+
executorch::extension::prepare_input_tensors(*method_);
163+
ASSERT_EQ(inputs_cleanup.error(), Error::Ok);
164+
inputs_cleanup_ = std::make_unique<executorch::extension::BufferCleanup>(
165+
std::move(*inputs_cleanup));
162166
}
163167

164168
void TearDown() override {
165-
torch::executor::util::FreeInputs(inputs_);
166-
inputs_ = {};
169+
inputs_cleanup_.reset();
167170
}
168171

169172
private:
@@ -173,7 +176,7 @@ class KernelIntegrationTest : public ::testing::Test {
173176
// Must outlive method_
174177
std::unique_ptr<Program> program_;
175178
std::unique_ptr<ManagedMemoryManager> mmm_;
176-
ArrayRef<void*> inputs_;
179+
std::unique_ptr<executorch::extension::BufferCleanup> inputs_cleanup_;
177180

178181
protected:
179182
// An executable method that will call the kernel associated with control_.

runtime/executor/test/method_test.cpp

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@
1010
#include <filesystem>
1111

1212
#include <executorch/extension/data_loader/file_data_loader.h>
13+
#include <executorch/extension/runner_util/inputs.h>
1314
#include <executorch/runtime/core/exec_aten/exec_aten.h>
1415
#include <executorch/runtime/executor/method.h>
1516
#include <executorch/runtime/executor/program.h>
1617
#include <executorch/runtime/executor/test/managed_memory_manager.h>
1718
#include <executorch/runtime/platform/runtime.h>
1819
#include <executorch/test/utils/DeathTest.h>
19-
#include <executorch/util/util.h>
2020
#include <gtest/gtest.h>
2121

2222
using namespace ::testing;
2323
using exec_aten::ArrayRef;
24+
using executorch::extension::prepare_input_tensors;
2425
using executorch::runtime::Error;
2526
using executorch::runtime::EValue;
2627
using executorch::runtime::Method;
@@ -80,8 +81,8 @@ TEST_F(MethodTest, MoveTest) {
8081
ASSERT_EQ(method.error(), Error::Ok);
8182

8283
// Can execute the method.
83-
exec_aten::ArrayRef<void*> inputs =
84-
torch::executor::util::PrepareInputTensors(*method);
84+
auto input_cleanup = prepare_input_tensors(*method);
85+
ASSERT_EQ(input_cleanup.error(), Error::Ok);
8586
Error err = method->execute();
8687
ASSERT_EQ(err, Error::Ok);
8788

@@ -95,8 +96,6 @@ TEST_F(MethodTest, MoveTest) {
9596
// Can execute the new method.
9697
err = new_method.execute();
9798
ASSERT_EQ(err, Error::Ok);
98-
99-
torch::executor::util::FreeInputs(inputs);
10099
}
101100

102101
TEST_F(MethodTest, GetInputTests) {
@@ -173,8 +172,8 @@ TEST_F(MethodTest, SetPrimInputTest) {
173172
ASSERT_EQ(method.error(), Error::Ok);
174173

175174
// Can execute the method.
176-
exec_aten::ArrayRef<void*> inputs =
177-
torch::executor::util::PrepareInputTensors(*method);
175+
auto input_cleanup = prepare_input_tensors(*method);
176+
ASSERT_EQ(input_cleanup.error(), Error::Ok);
178177

179178
// The args to the method are x, y, alpha. x and y are tensors handled above
180179
// alpha is a prim.
@@ -189,8 +188,6 @@ TEST_F(MethodTest, SetPrimInputTest) {
189188

190189
Error err = method->execute();
191190
EXPECT_EQ(err, Error::Ok);
192-
193-
torch::executor::util::FreeInputs(inputs);
194191
}
195192

196193
TEST_F(MethodTest, MethodMetaTest) {
@@ -297,28 +294,28 @@ TEST_F(MethodTest, ConstantBufferTest) {
297294
ASSERT_EQ(err, Error::Ok);
298295
}
299296

300-
// TODO(T161163608): Test is disabled due to a resize bug in tensor_index_out of
301-
// the portable op lib
302-
303-
// TEST_F(MethodTest, OptionalTensorListDeserialization) {
304-
// ManagedMemoryManager mmm(kDefaultNonConstMemBytes,
305-
// kDefaultRuntimeMemBytes); Result<Method> method =
306-
// index_program_->load_method("forward", &mmm.get());
307-
// ASSERT_EQ(method.error(), Error::Ok);
297+
/*
298+
* TODO(T161163608): Test is disabled due to a resize bug in tensor_index_out of
299+
* the portable op lib
308300
309-
// // Can execute the method.
310-
// exec_aten::ArrayRef<void*> inputs =
311-
// executorch::runtime::util::PrepareInputTensors(*method);
312-
// Error err = method->execute();
313-
// ASSERT_EQ(err, Error::Ok);
301+
TEST_F(MethodTest, OptionalTensorListDeserialization) {
302+
ManagedMemoryManager mmm(kDefaultNonConstMemBytes,
303+
kDefaultRuntimeMemBytes); Result<Method> method =
304+
index_program_->load_method("forward", &mmm.get());
305+
ASSERT_EQ(method.error(), Error::Ok);
314306
315-
// EXPECT_EQ(method->inputs_size(), 1);
307+
// Can execute the method.
308+
auto input_cleanup = prepare_input_tensors(*method);
309+
ASSERT_EQ(input_cleanup.error(), Error::Ok);
310+
Error err = method->execute();
311+
ASSERT_EQ(err, Error::Ok);
316312
317-
// auto outputs = method->get_output(0);
318-
// EXPECT_EQ(outputs.toTensor().dim(), 3);
319-
// EXPECT_EQ(outputs.toTensor().size(0), 5);
320-
// EXPECT_EQ(outputs.toTensor().size(1), 2);
321-
// EXPECT_EQ(outputs.toTensor().size(2), 10);
313+
EXPECT_EQ(method->inputs_size(), 1);
322314
323-
// executorch::runtime::util::FreeInputs(inputs);
324-
// }
315+
auto outputs = method->get_output(0);
316+
EXPECT_EQ(outputs.toTensor().dim(), 3);
317+
EXPECT_EQ(outputs.toTensor().size(0), 5);
318+
EXPECT_EQ(outputs.toTensor().size(1), 2);
319+
EXPECT_EQ(outputs.toTensor().size(2), 10);
320+
}
321+
*/

runtime/executor/test/targets.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def define_common_targets(is_fbcode = False):
120120
"//executorch/runtime/executor:program",
121121
"//executorch/kernels/portable:generated_lib",
122122
"//executorch/extension/data_loader:file_data_loader",
123-
"//executorch/util:util",
123+
"//executorch/extension/runner_util:inputs",
124124
],
125125
env = modules_env,
126126
)
@@ -133,8 +133,8 @@ def define_common_targets(is_fbcode = False):
133133
deps = [
134134
":managed_memory_manager",
135135
"//executorch/runtime/executor:program",
136-
"//executorch/util:util",
137136
"//executorch/extension/data_loader:file_data_loader",
137+
"//executorch/extension/runner_util:inputs",
138138
"//executorch/kernels/portable:generated_lib",
139139
],
140140
env = modules_env,
@@ -189,12 +189,12 @@ def define_common_targets(is_fbcode = False):
189189
deps = [
190190
":managed_memory_manager",
191191
"//executorch/extension/data_loader:file_data_loader",
192+
"//executorch/extension/runner_util:inputs",
192193
"//executorch/runtime/core:core",
193194
"//executorch/runtime/executor:program",
194195
"//executorch/runtime/kernel:kernel_runtime_context",
195196
"//executorch/runtime/kernel:operator_registry",
196197
"//executorch/runtime/platform:platform",
197-
"//executorch/util:util",
198198
],
199199
env = modules_env,
200200
)
@@ -210,7 +210,7 @@ def define_common_targets(is_fbcode = False):
210210
"//executorch/runtime/executor:program",
211211
"//executorch/extension/data_loader:buffer_data_loader",
212212
"//executorch/extension/data_loader:file_data_loader",
213-
"//executorch/util:util",
213+
"//executorch/extension/runner_util:inputs",
214214
],
215215
env = {
216216
# The tests use these vars to find the program files to load.

0 commit comments

Comments
 (0)