Skip to content

Commit 5444a97

Browse files
committed
Update on "[5/N] Add get_option/set_option APIs"
Expose the API to set/get backend option. We can either pass in {backend_name, backend options} or {backend options map} Differential Revision: [D76825663](https://our.internmc.facebook.com/intern/diff/D76825663/) Differential Revision: [D76825663](https://our.internmc.facebook.com/intern/diff/D76825663) [ghstack-poisoned]
2 parents 19aa8d6 + 17632e6 commit 5444a97

File tree

7 files changed

+29
-236
lines changed

7 files changed

+29
-236
lines changed

runtime/backend/backend_update_context.h renamed to runtime/backend/backend_option_context.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
namespace executorch {
1515
namespace ET_RUNTIME_NAMESPACE {
1616
/**
17-
* BackendUpdateContext will be used to inject runtime info for to initialize
17+
* BackendOptionContext will be used to inject runtime info for to initialize
1818
* delegate.
1919
*/
20-
class BackendUpdateContext final {
20+
class BackendOptionContext final {
2121
public:
22-
explicit BackendUpdateContext(){}
22+
explicit BackendOptionContext(){}
2323
};
2424

2525
} // namespace ET_RUNTIME_NAMESPACE
@@ -29,6 +29,6 @@ namespace torch {
2929
namespace executor {
3030
// TODO(T197294990): Remove these deprecated aliases once all users have moved
3131
// to the new `::executorch` namespaces.
32-
using ::executorch::ET_RUNTIME_NAMESPACE::BackendUpdateContext;
32+
using ::executorch::ET_RUNTIME_NAMESPACE::BackendOptionContext;
3333
} // namespace executor
3434
} // namespace torch

runtime/backend/interface.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <executorch/runtime/backend/backend_execution_context.h>
1414
#include <executorch/runtime/backend/backend_init_context.h>
1515
#include <executorch/runtime/backend/options.h>
16-
#include <executorch/runtime/backend/backend_update_context.h>
16+
#include <executorch/runtime/backend/backend_option_context.h>
1717
#include <executorch/runtime/core/array_ref.h>
1818
#include <executorch/runtime/core/error.h>
1919
#include <executorch/runtime/core/evalue.h>
@@ -111,7 +111,7 @@ class BackendInterface {
111111
* @retval Error::Ok if successful.
112112
*/
113113
ET_NODISCARD virtual Error set_option(
114-
BackendUpdateContext& context,
114+
BackendOptionContext& context,
115115
const executorch::runtime::Span<BackendOption>& backend_options) {
116116
return Error::Ok;
117117
};
@@ -127,7 +127,7 @@ class BackendInterface {
127127
* @retval Error::Ok if successful.
128128
*/
129129
ET_NODISCARD virtual Error get_option(
130-
BackendUpdateContext& context,
130+
BackendOptionContext& context,
131131
executorch::runtime::Span<BackendOption>& backend_options) {
132132
return Error::Ok;
133133
};

runtime/backend/options_map.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <executorch/runtime/backend/options.h>
1212
#include <executorch/runtime/core/error.h>
1313
#include <executorch/runtime/core/span.h>
14-
#include <executorch/runtime/backend/backend_update_context.h>
14+
#include <executorch/runtime/backend/backend_option_context.h>
1515
#include <executorch/runtime/backend/interface.h>
1616
#include <cstring>
1717
namespace executorch {
@@ -102,11 +102,11 @@ auto backend_class = get_backend_class(backend_name);
102102
if (!backend_class) {
103103
return Error::NotFound;
104104
}
105-
executorch::runtime::BackendUpdateContext backend_update_context;
105+
executorch::runtime::BackendOptionContext backend_option_context;
106106
executorch::runtime::Span<BackendOption> backend_options_ref(
107107
backend_options.data(), backend_options.size());
108108
auto result =
109-
backend_class->get_option(backend_update_context, backend_options_ref);
109+
backend_class->get_option(backend_option_context, backend_options_ref);
110110
if (result != Error::Ok) {
111111
return result;
112112
}
@@ -154,9 +154,9 @@ if (!backend_class) {
154154
return Error::NotFound;
155155
}
156156

157-
executorch::runtime::BackendUpdateContext backend_update_context;
157+
executorch::runtime::BackendOptionContext backend_option_context;
158158
Error result =
159-
backend_class->set_option(backend_update_context, backend_options);
159+
backend_class->set_option(backend_option_context, backend_options);
160160
if (result != Error::Ok) {
161161
return result;
162162
}

runtime/backend/targets.bzl

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,6 @@ def define_common_targets():
2828
],
2929
)
3030

31-
runtime.cxx_library(
32-
name = "backend_update" + aten_suffix,
33-
exported_headers = [
34-
"backend_update.h",
35-
],
36-
preprocessor_flags = ["-DUSE_ATEN_LIB"] if aten_mode else [],
37-
visibility = [
38-
"//executorch/...",
39-
"@EXECUTORCH_CLIENTS",
40-
],
41-
exported_deps = [
42-
"//executorch/runtime/core:core",
43-
"//executorch/runtime/core:evalue" + aten_suffix,
44-
"//executorch/runtime/core:event_tracer" + aten_suffix,
45-
":options_map" + aten_suffix,
46-
":interface" + aten_suffix,
47-
],
48-
)
49-
5031
runtime.cxx_library(
5132
name = "interface" + aten_suffix,
5233
srcs = [
@@ -55,7 +36,7 @@ def define_common_targets():
5536
exported_headers = [
5637
"backend_execution_context.h",
5738
"backend_init_context.h",
58-
"backend_update_context.h",
39+
"backend_option_context.h",
5940
"interface.h",
6041
],
6142
preprocessor_flags = ["-DUSE_ATEN_LIB"] if aten_mode else [],

runtime/backend/test/backend_interface_update_test.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ using executorch::runtime::ArrayRef;
2222
using executorch::runtime::Error;
2323
using executorch::runtime::BackendExecutionContext;
2424
using executorch::runtime::EValue;
25-
using executorch::runtime::BackendUpdateContext;
25+
using executorch::runtime::BackendOptionContext;
2626
using executorch::runtime::BackendOption;
2727
using executorch::runtime::BackendOptions;
2828
using executorch::runtime::Backend;
@@ -55,7 +55,7 @@ class MockBackend : public BackendInterface {
5555
}
5656

5757
Error set_option(
58-
BackendUpdateContext& context,
58+
BackendOptionContext& context,
5959
const executorch::runtime::Span<BackendOption>& backend_options) override {
6060
set_option_count++;
6161
int sucess_update = 0;
@@ -111,7 +111,7 @@ class MockBackend : public BackendInterface {
111111
};
112112

113113
TEST_F(BackendInterfaceUpdateTest, HandlesInvalidOption) {
114-
BackendUpdateContext context;
114+
BackendOptionContext context;
115115

116116
// Test invalid key case
117117
BackendOption invalid_option{
@@ -126,7 +126,7 @@ TEST_F(BackendInterfaceUpdateTest, HandlesInvalidOption) {
126126
}
127127

128128
TEST_F(BackendInterfaceUpdateTest, HandlesStringOption) {
129-
BackendUpdateContext context;
129+
BackendOptionContext context;
130130
options.set_option(StrKey("Backend"), "GPU");
131131
// // Create a backend option to pass to update
132132

@@ -143,7 +143,7 @@ TEST_F(BackendInterfaceUpdateTest, HandlesIntOption) {
143143
// Check the default num_threads value is 0
144144
EXPECT_EQ(mock_backend->debug, false);
145145
// Create a mock context (needs to be defined or mocked)
146-
BackendUpdateContext context;
146+
BackendOptionContext context;
147147

148148
int expected_num_threads = 4;
149149

@@ -160,7 +160,7 @@ TEST_F(BackendInterfaceUpdateTest, HandlesBoolOption) {
160160
// Check the default num_threads value is 0
161161
EXPECT_EQ(mock_backend->debug, false);
162162
// Create a mock context (needs to be defined or mocked)
163-
BackendUpdateContext context;
163+
BackendOptionContext context;
164164

165165
options.set_option(BoolKey("Debug"), true);
166166

@@ -175,7 +175,7 @@ TEST_F(BackendInterfaceUpdateTest, HandlesMultipleOptions) {
175175
// Check the default num_threads value is 0
176176
EXPECT_EQ(mock_backend->debug, false);
177177
// Create a mock context (needs to be defined or mocked)
178-
BackendUpdateContext context;
178+
BackendOptionContext context;
179179

180180
options.set_option(BoolKey("Debug"), true);
181181
options.set_option(IntKey("NumberOfThreads"), 4);
@@ -191,7 +191,7 @@ TEST_F(BackendInterfaceUpdateTest, HandlesMultipleOptions) {
191191
}
192192

193193
TEST_F(BackendInterfaceUpdateTest, UpdateBeforeInit) {
194-
BackendUpdateContext update_context;
194+
BackendOptionContext option_context;
195195
MemoryAllocator memory_allocator{MemoryAllocator(0, nullptr)};
196196

197197
BackendInitContext init_context(&memory_allocator);
@@ -200,7 +200,7 @@ TEST_F(BackendInterfaceUpdateTest, UpdateBeforeInit) {
200200
options.set_option(StrKey("Backend"), "GPU");
201201

202202
// Update before init
203-
Error err = mock_backend->set_option(update_context, options.view());
203+
Error err = mock_backend->set_option(option_context, options.view());
204204
EXPECT_EQ(err, Error::Ok);
205205

206206
// Now call init
@@ -218,7 +218,7 @@ TEST_F(BackendInterfaceUpdateTest, UpdateBeforeInit) {
218218
}
219219

220220
TEST_F(BackendInterfaceUpdateTest, UpdateAfterInitBeforeExecute) {
221-
BackendUpdateContext update_context;
221+
BackendOptionContext option_context;
222222
MemoryAllocator init_memory_allocator{MemoryAllocator(0, nullptr)};
223223
BackendInitContext init_context(&init_memory_allocator);
224224
BackendExecutionContext execute_context;
@@ -235,7 +235,7 @@ TEST_F(BackendInterfaceUpdateTest, UpdateAfterInitBeforeExecute) {
235235

236236
// Now update
237237
options.set_option(StrKey("Backend"), "CPU");
238-
Error err = mock_backend->set_option(update_context, options.view());
238+
Error err = mock_backend->set_option(option_context, options.view());
239239
EXPECT_EQ(err, Error::Ok);
240240

241241
// Now execute
@@ -252,7 +252,7 @@ TEST_F(BackendInterfaceUpdateTest, UpdateAfterInitBeforeExecute) {
252252
}
253253

254254
TEST_F(BackendInterfaceUpdateTest, UpdateBetweenExecutes) {
255-
BackendUpdateContext update_context;
255+
BackendOptionContext option_context;
256256
MemoryAllocator init_memory_allocator{MemoryAllocator(0, nullptr)};
257257
BackendInitContext init_context(&init_memory_allocator);
258258
BackendExecutionContext execute_context;
@@ -271,7 +271,7 @@ TEST_F(BackendInterfaceUpdateTest, UpdateBetweenExecutes) {
271271

272272
// Update between executes
273273
options.set_option(StrKey("Backend"), "NPU");
274-
err = mock_backend->set_option(update_context, options.view());
274+
err = mock_backend->set_option(option_context, options.view());
275275
EXPECT_EQ(err, Error::Ok);
276276

277277
// Second execute

runtime/backend/test/backend_options_map_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ using executorch::runtime::StrKey;
2525
using executorch::runtime::BackendInterface;
2626
using executorch::runtime::BackendInitContext;
2727
using executorch::runtime::BackendExecutionContext;
28-
using executorch::runtime::BackendUpdateContext;
28+
using executorch::runtime::BackendOptionContext;
2929
using executorch::runtime::DelegateHandle;
3030
using executorch::runtime::CompileSpec;
3131
using executorch::runtime::Backend;
@@ -185,7 +185,7 @@ class StubBackend : public BackendInterface {
185185
}
186186

187187
Error get_option(
188-
BackendUpdateContext& context,
188+
BackendOptionContext& context,
189189
executorch::runtime::Span<executorch::runtime::BackendOption>&
190190
backend_options) override {
191191
// For testing purposes, just record that get_option was called
@@ -208,7 +208,7 @@ class StubBackend : public BackendInterface {
208208
}
209209

210210
Error set_option(
211-
BackendUpdateContext& context,
211+
BackendOptionContext& context,
212212
const Span<executorch::runtime::BackendOption>& backend_options)
213213
override {
214214
// Store the options for verification

0 commit comments

Comments
 (0)