Skip to content

Commit

Permalink
MIgrate some random files away from the torch:: namespace (#5836)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #5836

A couple tests and helpers that my previous passes didn't catch.

After this, the only remaining `//executorch/...` code under the `torch::` namespace is under `backends/...` and `kernels/...` (and in some other places that define kernels).

Reviewed By: cccclai

Differential Revision: D63797660

fbshipit-source-id: f4075d670c6b7f083c8c3ab1e9c465da32e8b3ac
(cherry picked from commit 3a25651)
  • Loading branch information
dbort authored and pytorchbot committed Oct 4, 2024
1 parent 3dd1b98 commit dc5b211
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 32 deletions.
37 changes: 29 additions & 8 deletions exir/backend/test/demos/rpc/ExecutorBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,30 @@
#include <executorch/runtime/executor/method.h>
#include <executorch/runtime/executor/program.h>

namespace torch {
namespace executor {
using ::executorch::aten::Tensor;
using ::executorch::extension::BufferDataLoader;
using ::executorch::runtime::ArrayRef;
using ::executorch::runtime::Backend;
using ::executorch::runtime::BackendExecutionContext;
using ::executorch::runtime::BackendInitContext;
using ::executorch::runtime::CompileSpec;
using ::executorch::runtime::DelegateHandle;
using ::executorch::runtime::Error;
using ::executorch::runtime::EValue;
using ::executorch::runtime::FreeableBuffer;
using ::executorch::runtime::HierarchicalAllocator;
using ::executorch::runtime::MemoryAllocator;
using ::executorch::runtime::MemoryManager;
using ::executorch::runtime::Method;
using ::executorch::runtime::MethodMeta;
using ::executorch::runtime::Program;
using ::executorch::runtime::Result;
using ::executorch::runtime::Span;
using ::executorch::runtime::Tag;
using ::executorch::runtime::internal::copy_tensor_data;

namespace example {

/**
* ExecutorBackend is a backend to execute an executorch program via delegate.
* In preprocess, the preprocesed bytes (delegate blob) is an executorch
Expand Down Expand Up @@ -51,8 +73,8 @@ class ExecutorBackend final : public ::executorch::runtime::BackendInterface {
// will return the data directly without copying it.
MemoryAllocator* runtime_allocator = context.get_runtime_allocator();
auto loader = ET_ALLOCATE_INSTANCE_OR_RETURN_ERROR(
runtime_allocator, util::BufferDataLoader);
new (loader) util::BufferDataLoader(processed->data(), processed->size());
runtime_allocator, BufferDataLoader);
new (loader) BufferDataLoader(processed->data(), processed->size());
// Can't free `processed` because the program will point into that memory.

// Try loading the program.
Expand Down Expand Up @@ -150,7 +172,7 @@ class ExecutorBackend final : public ::executorch::runtime::BackendInterface {
if (output.tag == Tag::Tensor) {
Tensor t_src = output.toTensor();
Tensor t_dst = args[num_inputs + i]->toTensor();
status = internal::copy_tensor_data(t_dst, t_src);
status = copy_tensor_data(t_dst, t_src);
}
}

Expand All @@ -165,12 +187,11 @@ class ExecutorBackend final : public ::executorch::runtime::BackendInterface {
}
};

Error registerExecutorBackend() {
Error register_executor_backend() {
static auto cls = ExecutorBackend();
static Backend backend{"ExecutorBackend", &cls};
static auto success_with_compiler = register_backend(backend);
return success_with_compiler;
}

} // namespace executor
} // namespace torch
} // namespace example
8 changes: 3 additions & 5 deletions exir/backend/test/demos/rpc/ExecutorBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@

#include <executorch/runtime/core/error.h>

namespace torch {
namespace executor {
namespace example {

Error registerExecutorBackend();
::executorch::runtime::Error register_executor_backend();

} // namespace executor
} // namespace torch
} // namespace example
9 changes: 4 additions & 5 deletions exir/backend/test/demos/rpc/ExecutorBackendRegister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
#include <executorch/runtime/backend/interface.h>
#include <executorch/runtime/core/error.h>

namespace torch {
namespace executor {
namespace example {
namespace {
static Error register_success = registerExecutorBackend();
static ::executorch::runtime::Error register_success =
register_executor_backend();
} // namespace
} // namespace executor
} // namespace torch
} // namespace example
8 changes: 1 addition & 7 deletions runtime/core/test/evalue_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

using namespace ::testing;

namespace torch {
namespace executor {

using exec_aten::ScalarType;
using executorch::runtime::BoxedEvalueList;
using executorch::runtime::EValue;
Expand All @@ -30,7 +27,7 @@ class EValueTest : public ::testing::Test {
void SetUp() override {
// Since these tests cause ET_LOG to be called, the PAL must be initialized
// first.
runtime_init();
executorch::runtime::runtime_init();
}
};

Expand Down Expand Up @@ -276,6 +273,3 @@ TEST_F(EValueTest, ConstructFromNullPtrAborts) {

ET_EXPECT_DEATH({ EValue evalue(null_ptr); }, "");
}

} // namespace executor
} // namespace torch
14 changes: 7 additions & 7 deletions test/utils/alignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

#include <gmock/gmock.h> // For MATCHER_P

namespace torch {
namespace executor {
namespace executorch {
namespace runtime {
namespace testing {

/**
Expand All @@ -28,7 +28,7 @@ inline bool is_aligned(const void* ptr, size_t alignment) {
* Lets gtest users write `EXPECT_THAT(ptr, IsAlignedTo(alignment))` or
* `EXPECT_THAT(ptr, Not(IsAlignedTo(alignment)))`.
*
* See also `EXPECT_POINTER_IS_ALIGNED_TO()`.
* See also `EXPECT_ALIGNED()`.
*/
MATCHER_P(IsAlignedTo, other, "") {
return is_aligned(arg, other);
Expand All @@ -39,10 +39,10 @@ MATCHER_P(IsAlignedTo, other, "") {
*/

#define EXPECT_ALIGNED(ptr, alignment) \
EXPECT_THAT((ptr), torch::executor::testing::IsAlignedTo((alignment)))
EXPECT_THAT((ptr), executorch::runtime::testing::IsAlignedTo((alignment)))
#define ASSERT_ALIGNED(ptr, alignment) \
ASSERT_THAT((ptr), torch::executor::testing::IsAlignedTo((alignment)))
ASSERT_THAT((ptr), executorch::runtime::testing::IsAlignedTo((alignment)))

} // namespace testing
} // namespace executor
} // namespace torch
} // namespace runtime
} // namespace executorch

0 comments on commit dc5b211

Please sign in to comment.