From cf56ba77e0dc1899d9c2e993594ebc9c51e883d9 Mon Sep 17 00:00:00 2001 From: pytorchbot Date: Fri, 4 Oct 2024 14:49:55 -0700 Subject: [PATCH] MIgrate some random files away from the torch:: namespace (#5866) MIgrate some random files away from the torch:: namespace (#5836) Summary: Pull Request resolved: https://github.com/pytorch/executorch/pull/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 3a25651826012d5f435d192073f32c7d814beced) Co-authored-by: Dave Bort --- .../test/demos/rpc/ExecutorBackend.cpp | 37 +++++++++++++++---- exir/backend/test/demos/rpc/ExecutorBackend.h | 8 ++-- .../demos/rpc/ExecutorBackendRegister.cpp | 9 ++--- runtime/core/test/evalue_test.cpp | 8 +--- test/utils/alignment.h | 14 +++---- 5 files changed, 44 insertions(+), 32 deletions(-) diff --git a/exir/backend/test/demos/rpc/ExecutorBackend.cpp b/exir/backend/test/demos/rpc/ExecutorBackend.cpp index aeef621a27..d398b87123 100644 --- a/exir/backend/test/demos/rpc/ExecutorBackend.cpp +++ b/exir/backend/test/demos/rpc/ExecutorBackend.cpp @@ -21,8 +21,30 @@ #include #include -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 @@ -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. @@ -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); } } @@ -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 diff --git a/exir/backend/test/demos/rpc/ExecutorBackend.h b/exir/backend/test/demos/rpc/ExecutorBackend.h index a7b6bf94eb..747c48265d 100644 --- a/exir/backend/test/demos/rpc/ExecutorBackend.h +++ b/exir/backend/test/demos/rpc/ExecutorBackend.h @@ -10,10 +10,8 @@ #include -namespace torch { -namespace executor { +namespace example { -Error registerExecutorBackend(); +::executorch::runtime::Error register_executor_backend(); -} // namespace executor -} // namespace torch +} // namespace example diff --git a/exir/backend/test/demos/rpc/ExecutorBackendRegister.cpp b/exir/backend/test/demos/rpc/ExecutorBackendRegister.cpp index fdb9fc2d42..b697b24c49 100644 --- a/exir/backend/test/demos/rpc/ExecutorBackendRegister.cpp +++ b/exir/backend/test/demos/rpc/ExecutorBackendRegister.cpp @@ -10,10 +10,9 @@ #include #include -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 diff --git a/runtime/core/test/evalue_test.cpp b/runtime/core/test/evalue_test.cpp index 4c08695dc4..a7eb5c185a 100644 --- a/runtime/core/test/evalue_test.cpp +++ b/runtime/core/test/evalue_test.cpp @@ -16,9 +16,6 @@ using namespace ::testing; -namespace torch { -namespace executor { - using exec_aten::ScalarType; using executorch::runtime::BoxedEvalueList; using executorch::runtime::EValue; @@ -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(); } }; @@ -276,6 +273,3 @@ TEST_F(EValueTest, ConstructFromNullPtrAborts) { ET_EXPECT_DEATH({ EValue evalue(null_ptr); }, ""); } - -} // namespace executor -} // namespace torch diff --git a/test/utils/alignment.h b/test/utils/alignment.h index f8c9b47362..dd3378821f 100644 --- a/test/utils/alignment.h +++ b/test/utils/alignment.h @@ -12,8 +12,8 @@ #include // For MATCHER_P -namespace torch { -namespace executor { +namespace executorch { +namespace runtime { namespace testing { /** @@ -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); @@ -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