Skip to content

Commit

Permalink
Rename PyTorchBackendInterface to BackendInterface
Browse files Browse the repository at this point in the history
Differential Revision: D61925076

Pull Request resolved: pytorch#5022
  • Loading branch information
dbort authored Sep 4, 2024
1 parent 83c8a16 commit 23f03b9
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 31 deletions.
6 changes: 3 additions & 3 deletions runtime/backend/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
*/

#include <executorch/runtime/backend/interface.h>
#include <executorch/runtime/platform/assert.h>

namespace executorch {
namespace runtime {

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

namespace {

Expand All @@ -31,7 +31,7 @@ size_t num_registered_backends = 0;

} // namespace

PyTorchBackendInterface* get_backend_class(const char* name) {
BackendInterface* get_backend_class(const char* name) {
for (size_t i = 0; i < num_registered_backends; i++) {
Backend backend = registered_backends[i];
if (strcmp(backend.name, name) == 0) {
Expand Down
35 changes: 17 additions & 18 deletions runtime/backend/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ struct CompileSpec {
*/
using DelegateHandle = void;

class PyTorchBackendInterface {
class BackendInterface {
public:
virtual ~PyTorchBackendInterface() = 0;
virtual ~BackendInterface() = 0;

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

/**
* A named instance of a backend.
Expand All @@ -128,12 +127,12 @@ struct Backend {
/// The name of the backend. Must match the string used in the PTE file.
const char* name;
/// The instance of the backend to use when loading and executing programs.
PyTorchBackendInterface* backend;
BackendInterface* backend;
};

/**
* Registers the Backend object (i.e. string name and PyTorchBackendInterface
* pair) so that it could be called via the name during the runtime.
* Registers the Backend object (i.e. string name and BackendInterface pair) so
* that it could be called via the name during the runtime.
*
* @param[in] backend Backend object
* @retval Error code representing whether registration was successful.
Expand All @@ -151,8 +150,8 @@ using ::executorch::runtime::Backend;
using ::executorch::runtime::CompileSpec;
using ::executorch::runtime::DelegateHandle;
using ::executorch::runtime::get_backend_class;
using ::executorch::runtime::PyTorchBackendInterface;
using ::executorch::runtime::register_backend;
using ::executorch::runtime::SizedBuffer;
using PyTorchBackendInterface = ::executorch::runtime::BackendInterface;
} // namespace executor
} // namespace torch
4 changes: 2 additions & 2 deletions runtime/executor/method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class BackendDelegate final {
ET_CHECK_OR_RETURN_ERROR(
delegate.id() != nullptr, InvalidProgram, "Missing backend id");
const char* backend_id = delegate.id()->c_str();
PyTorchBackendInterface* backend = get_backend_class(backend_id);
BackendInterface* backend = get_backend_class(backend_id);
ET_CHECK_OR_RETURN_ERROR(
backend != nullptr,
NotFound,
Expand Down Expand Up @@ -198,7 +198,7 @@ class BackendDelegate final {
}

FreeableBuffer segment_;
const PyTorchBackendInterface* backend_;
const BackendInterface* backend_;
DelegateHandle* handle_;
};

Expand Down
8 changes: 4 additions & 4 deletions runtime/executor/test/backend_integration_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ using namespace ::testing;
using exec_aten::ArrayRef;
using executorch::runtime::BackendExecutionContext;
using executorch::runtime::BackendInitContext;
using executorch::runtime::BackendInterface;
using executorch::runtime::CompileSpec;
using executorch::runtime::DataLoader;
using executorch::runtime::DelegateHandle;
Expand All @@ -40,17 +41,16 @@ using executorch::runtime::FreeableBuffer;
using executorch::runtime::MemoryAllocator;
using executorch::runtime::Method;
using executorch::runtime::Program;
using executorch::runtime::PyTorchBackendInterface;
using executorch::runtime::Result;
using executorch::runtime::testing::ManagedMemoryManager;
using torch::executor::util::FileDataLoader;

/**
* A backend class whose methods can be overridden individually.
*/
class StubBackend final : public PyTorchBackendInterface {
class StubBackend final : public BackendInterface {
public:
// Function signature types that match the PyTorchBackendInterface methods.
// Function signature types that match the BackendInterface methods.
using IsAvailableFn = std::function<bool()>;
using InitFn = std::function<Result<DelegateHandle*>(
FreeableBuffer*,
Expand Down Expand Up @@ -325,7 +325,7 @@ class BackendIntegrationTest : public ::testing::TestWithParam<bool> {
};

TEST_P(BackendIntegrationTest, BackendIsPresent) {
PyTorchBackendInterface* backend =
BackendInterface* backend =
executorch::runtime::get_backend_class(StubBackend::kName);
ASSERT_EQ(backend, &StubBackend::singleton());
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/executor/test/test_backend_compiler_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ using executorch::runtime::ArrayRef;
using executorch::runtime::Backend;
using executorch::runtime::BackendExecutionContext;
using executorch::runtime::BackendInitContext;
using executorch::runtime::BackendInterface;
using executorch::runtime::CompileSpec;
using executorch::runtime::DelegateHandle;
using executorch::runtime::Error;
using executorch::runtime::EValue;
using executorch::runtime::FreeableBuffer;
using executorch::runtime::MemoryAllocator;
using executorch::runtime::PyTorchBackendInterface;
using executorch::runtime::Result;

struct DemoOp {
Expand All @@ -38,7 +38,7 @@ struct DemoOpList {
size_t numops;
};

class BackendWithCompiler final : public PyTorchBackendInterface {
class BackendWithCompiler final : public BackendInterface {
int max_shape = 4;

public:
Expand Down
4 changes: 2 additions & 2 deletions runtime/executor/test/test_backend_with_delegate_mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ using executorch::runtime::ArrayRef;
using executorch::runtime::Backend;
using executorch::runtime::BackendExecutionContext;
using executorch::runtime::BackendInitContext;
using executorch::runtime::BackendInterface;
using executorch::runtime::CompileSpec;
using executorch::runtime::DelegateHandle;
using executorch::runtime::Error;
using executorch::runtime::EValue;
using executorch::runtime::FreeableBuffer;
using executorch::runtime::MemoryAllocator;
using executorch::runtime::PyTorchBackendInterface;
using executorch::runtime::Result;

struct DemoOp {
Expand All @@ -37,7 +37,7 @@ struct DemoOpList {
size_t numops;
};

class BackendWithDelegateMapping final : public PyTorchBackendInterface {
class BackendWithDelegateMapping final : public BackendInterface {
public:
~BackendWithDelegateMapping() override = default;

Expand Down

0 comments on commit 23f03b9

Please sign in to comment.