Skip to content

Commit 3d68bd5

Browse files
committed
Update base for Update on "[4/N] Add backend options map"
This is to manage the backend <-> BackendOptions map. Users will create the bakcend options map, and ET runtime will read the backend name, and dispatch the list of backend options to each backend. exported-using-ghexport Differential Revision: [D76149466](https://our.internmc.facebook.com/intern/diff/D76149466/) Differential Revision: [D76149466](https://our.internmc.facebook.com/intern/diff/D76149466) [ghstack-poisoned]
1 parent af165df commit 3d68bd5

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
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/targets.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def define_common_targets():
1717
exported_headers = [
1818
"backend_execution_context.h",
1919
"backend_init_context.h",
20-
"backend_update_context.h",
20+
"backend_option_context.h",
2121
"options.h",
2222
"interface.h",
2323
],

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

0 commit comments

Comments
 (0)