Skip to content

Commit 23f03b9

Browse files
authored
Rename PyTorchBackendInterface to BackendInterface
Differential Revision: D61925076 Pull Request resolved: #5022
1 parent 83c8a16 commit 23f03b9

File tree

6 files changed

+30
-31
lines changed

6 files changed

+30
-31
lines changed

runtime/backend/interface.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
*/
88

99
#include <executorch/runtime/backend/interface.h>
10-
#include <executorch/runtime/platform/assert.h>
1110

1211
namespace executorch {
1312
namespace runtime {
1413

15-
PyTorchBackendInterface::~PyTorchBackendInterface() {}
14+
// Pure-virtual dtors still need an implementation.
15+
BackendInterface::~BackendInterface() {}
1616

1717
namespace {
1818

@@ -31,7 +31,7 @@ size_t num_registered_backends = 0;
3131

3232
} // namespace
3333

34-
PyTorchBackendInterface* get_backend_class(const char* name) {
34+
BackendInterface* get_backend_class(const char* name) {
3535
for (size_t i = 0; i < num_registered_backends; i++) {
3636
Backend backend = registered_backends[i];
3737
if (strcmp(backend.name, name) == 0) {

runtime/backend/interface.h

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ struct CompileSpec {
3939
*/
4040
using DelegateHandle = void;
4141

42-
class PyTorchBackendInterface {
42+
class BackendInterface {
4343
public:
44-
virtual ~PyTorchBackendInterface() = 0;
44+
virtual ~BackendInterface() = 0;
4545

4646
/**
4747
* Returns true if the backend is available to process delegation calls.
@@ -52,19 +52,19 @@ class PyTorchBackendInterface {
5252
* Responsible to further process (compile/transform/optimize) the compiled
5353
* unit that was produced, ahead-of-time, as well as perform any backend
5454
* initialization to ready it for execution. This method is called every time
55-
* the PyTorch program is initialized. Consequently, this is the place to
55+
* the ExecuTorch program is initialized. Consequently, this is the place to
5656
* perform any backend initialization as well as transformations,
5757
* optimizations, and even compilation that depend on the target device. As
5858
* such, it is strongly encouraged to push as much processing as possible to
5959
* the ahead-of-time processing.
6060
*
61-
* @param[in] processed An opaque (to PyTorch) compiled unit from the
62-
* preprocessor. Can contain anything the backend needs to execute the
63-
* equivalent semantics of the passed-in Module and its method. Often
64-
* passed unmodified to `execute()` as a `DelegateHandle`, unless it needs
65-
* further processing at init time to be fully executable. If the data is
66-
* not needed after init(), calling processed->Free() can reclaim its
67-
* memory.
61+
* @param[in] processed An opaque (to ExecuTorch) backend-specific compiled
62+
* unit from the preprocessor. Can contain anything the backend needs to
63+
* execute the equivalent semantics of the passed-in Module and its
64+
* method. Often passed unmodified to `execute()` as a `DelegateHandle`,
65+
* unless it needs further processing at init time to be fully executable.
66+
* If the data is not needed after init(), calling processed->Free() can
67+
* reclaim its memory.
6868
* @param[in] compile_specs The exact same compiler specification that
6969
* was used ahead-of-time to produce `processed`.
7070
*
@@ -115,11 +115,10 @@ class PyTorchBackendInterface {
115115
* The mapping is populated using register_backend method.
116116
*
117117
* @param[in] name Name of the user-defined backend delegate.
118-
* @retval Pointer to the appropriate object that implements
119-
* PyTorchBackendInterface. Nullptr if it can't find anything
120-
* with the given name.
118+
* @retval Pointer to the appropriate object that implements BackendInterface.
119+
* Nullptr if it can't find anything with the given name.
121120
*/
122-
PyTorchBackendInterface* get_backend_class(const char* name);
121+
BackendInterface* get_backend_class(const char* name);
123122

124123
/**
125124
* A named instance of a backend.
@@ -128,12 +127,12 @@ struct Backend {
128127
/// The name of the backend. Must match the string used in the PTE file.
129128
const char* name;
130129
/// The instance of the backend to use when loading and executing programs.
131-
PyTorchBackendInterface* backend;
130+
BackendInterface* backend;
132131
};
133132

134133
/**
135-
* Registers the Backend object (i.e. string name and PyTorchBackendInterface
136-
* pair) so that it could be called via the name during the runtime.
134+
* Registers the Backend object (i.e. string name and BackendInterface pair) so
135+
* that it could be called via the name during the runtime.
137136
*
138137
* @param[in] backend Backend object
139138
* @retval Error code representing whether registration was successful.
@@ -151,8 +150,8 @@ using ::executorch::runtime::Backend;
151150
using ::executorch::runtime::CompileSpec;
152151
using ::executorch::runtime::DelegateHandle;
153152
using ::executorch::runtime::get_backend_class;
154-
using ::executorch::runtime::PyTorchBackendInterface;
155153
using ::executorch::runtime::register_backend;
156154
using ::executorch::runtime::SizedBuffer;
155+
using PyTorchBackendInterface = ::executorch::runtime::BackendInterface;
157156
} // namespace executor
158157
} // namespace torch

runtime/executor/method.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class BackendDelegate final {
5858
ET_CHECK_OR_RETURN_ERROR(
5959
delegate.id() != nullptr, InvalidProgram, "Missing backend id");
6060
const char* backend_id = delegate.id()->c_str();
61-
PyTorchBackendInterface* backend = get_backend_class(backend_id);
61+
BackendInterface* backend = get_backend_class(backend_id);
6262
ET_CHECK_OR_RETURN_ERROR(
6363
backend != nullptr,
6464
NotFound,
@@ -198,7 +198,7 @@ class BackendDelegate final {
198198
}
199199

200200
FreeableBuffer segment_;
201-
const PyTorchBackendInterface* backend_;
201+
const BackendInterface* backend_;
202202
DelegateHandle* handle_;
203203
};
204204

runtime/executor/test/backend_integration_test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ using namespace ::testing;
3131
using exec_aten::ArrayRef;
3232
using executorch::runtime::BackendExecutionContext;
3333
using executorch::runtime::BackendInitContext;
34+
using executorch::runtime::BackendInterface;
3435
using executorch::runtime::CompileSpec;
3536
using executorch::runtime::DataLoader;
3637
using executorch::runtime::DelegateHandle;
@@ -40,17 +41,16 @@ using executorch::runtime::FreeableBuffer;
4041
using executorch::runtime::MemoryAllocator;
4142
using executorch::runtime::Method;
4243
using executorch::runtime::Program;
43-
using executorch::runtime::PyTorchBackendInterface;
4444
using executorch::runtime::Result;
4545
using executorch::runtime::testing::ManagedMemoryManager;
4646
using torch::executor::util::FileDataLoader;
4747

4848
/**
4949
* A backend class whose methods can be overridden individually.
5050
*/
51-
class StubBackend final : public PyTorchBackendInterface {
51+
class StubBackend final : public BackendInterface {
5252
public:
53-
// Function signature types that match the PyTorchBackendInterface methods.
53+
// Function signature types that match the BackendInterface methods.
5454
using IsAvailableFn = std::function<bool()>;
5555
using InitFn = std::function<Result<DelegateHandle*>(
5656
FreeableBuffer*,
@@ -325,7 +325,7 @@ class BackendIntegrationTest : public ::testing::TestWithParam<bool> {
325325
};
326326

327327
TEST_P(BackendIntegrationTest, BackendIsPresent) {
328-
PyTorchBackendInterface* backend =
328+
BackendInterface* backend =
329329
executorch::runtime::get_backend_class(StubBackend::kName);
330330
ASSERT_EQ(backend, &StubBackend::singleton());
331331
}

runtime/executor/test/test_backend_compiler_lib.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ using executorch::runtime::ArrayRef;
1717
using executorch::runtime::Backend;
1818
using executorch::runtime::BackendExecutionContext;
1919
using executorch::runtime::BackendInitContext;
20+
using executorch::runtime::BackendInterface;
2021
using executorch::runtime::CompileSpec;
2122
using executorch::runtime::DelegateHandle;
2223
using executorch::runtime::Error;
2324
using executorch::runtime::EValue;
2425
using executorch::runtime::FreeableBuffer;
2526
using executorch::runtime::MemoryAllocator;
26-
using executorch::runtime::PyTorchBackendInterface;
2727
using executorch::runtime::Result;
2828

2929
struct DemoOp {
@@ -38,7 +38,7 @@ struct DemoOpList {
3838
size_t numops;
3939
};
4040

41-
class BackendWithCompiler final : public PyTorchBackendInterface {
41+
class BackendWithCompiler final : public BackendInterface {
4242
int max_shape = 4;
4343

4444
public:

runtime/executor/test/test_backend_with_delegate_mapping.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ using executorch::runtime::ArrayRef;
1818
using executorch::runtime::Backend;
1919
using executorch::runtime::BackendExecutionContext;
2020
using executorch::runtime::BackendInitContext;
21+
using executorch::runtime::BackendInterface;
2122
using executorch::runtime::CompileSpec;
2223
using executorch::runtime::DelegateHandle;
2324
using executorch::runtime::Error;
2425
using executorch::runtime::EValue;
2526
using executorch::runtime::FreeableBuffer;
2627
using executorch::runtime::MemoryAllocator;
27-
using executorch::runtime::PyTorchBackendInterface;
2828
using executorch::runtime::Result;
2929

3030
struct DemoOp {
@@ -37,7 +37,7 @@ struct DemoOpList {
3737
size_t numops;
3838
};
3939

40-
class BackendWithDelegateMapping final : public PyTorchBackendInterface {
40+
class BackendWithDelegateMapping final : public BackendInterface {
4141
public:
4242
~BackendWithDelegateMapping() override = default;
4343

0 commit comments

Comments
 (0)