Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[executorch] Migrate most of extension/... to new namespace #4617

Merged
merged 27 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8769faa
[executorch] Migrate runtime/platform to new namespace
dbort Aug 9, 2024
cf4955d
[executorch] Migrate runtime/platform tests to new namespace
dbort Aug 9, 2024
d93a4f9
[executorch] Migrate runtime/core to new namespace
dbort Aug 9, 2024
ecf8941
[executorch] Migrate runtime/core tests to new namespace
dbort Aug 9, 2024
13097cf
[executorch] Migrate exec_aten utils to new namespace
dbort Aug 9, 2024
c7cf226
[executorch] Migrate exec_aten util tests to new namespace
dbort Aug 9, 2024
347749c
[executorch] Migrate runtime/kernel to new namespace
dbort Aug 9, 2024
1700bba
[executorch] Migrate runtime/kernel tests to new namespace
dbort Aug 9, 2024
457b947
[executorch] Migrate runtime/backend to new namespace
dbort Aug 9, 2024
fb05f4e
[executorch] Migrate extended_header to new namespace
dbort Aug 9, 2024
dee7d22
[executorch] Migrate runtime/executor to new namespace
dbort Aug 9, 2024
f5bf1b2
[executorch] Migrate runtime/executor tests to new namespace
dbort Aug 9, 2024
2aee207
[executorch] Migrate extension/test_utils to new namespace
dbort Aug 9, 2024
3bfb314
Update base for Update on "[executorch] Migrate extension/test_utils …
dbort Aug 9, 2024
c27291c
Update on "[executorch] Migrate extension/test_utils to new namespace"
dbort Aug 9, 2024
434052a
Update base for Update on "[executorch] Migrate extension/test_utils …
dbort Aug 9, 2024
2b1cd87
Update on "[executorch] Migrate extension/test_utils to new namespace"
dbort Aug 9, 2024
05fd8a6
Update base for Update on "[executorch] Migrate extension/test_utils …
dbort Aug 9, 2024
a984b30
Update on "[executorch] Migrate extension/test_utils to new namespace"
dbort Aug 9, 2024
c1a4d38
Update base for Update on "[executorch] Migrate extension/test_utils …
dbort Aug 14, 2024
95d0b3c
Update on "[executorch] Migrate extension/test_utils to new namespace"
dbort Aug 14, 2024
6844410
Update base for Update on "[executorch] Migrate extension/test_utils …
dbort Aug 16, 2024
768052d
Update on "[executorch] Migrate extension/test_utils to new namespace"
dbort Aug 16, 2024
a2f1bbb
Update base for Update on "[executorch] Migrate extension/test_utils …
dbort Aug 20, 2024
a41d36d
Update on "[executorch] Migrate extension/test_utils to new namespace"
dbort Aug 20, 2024
602be10
Update base for Update on " [executorch] Migrate most of extension/..…
dbort Aug 21, 2024
b484ea9
Update on " [executorch] Migrate most of extension/... to new namespace"
dbort Aug 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions backends/apple/coreml/runtime/sdk/model_event_logger_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import <CoreML/CoreML.h>
#import <model_event_logger.h>

namespace torch::executor {
namespace executorch::runtime {
class EventTracer;
}

Expand All @@ -21,7 +21,7 @@ namespace executorchcoreml {
class ModelEventLoggerImpl final : public ModelEventLogger {
public:
/// Construct a `ModelEventLoggerImpl` from the `EventTracer`.
explicit ModelEventLoggerImpl(torch::executor::EventTracer* tracer) : tracer_(tracer) { }
explicit ModelEventLoggerImpl(::executorch::runtime::EventTracer* tracer) : tracer_(tracer) { }

/// Logs profiling infos.
///
Expand All @@ -44,6 +44,6 @@ class ModelEventLoggerImpl final : public ModelEventLogger {
NSDictionary<ETCoreMLModelStructurePath*, NSString*>* op_path_to_debug_symbol_name_map) const noexcept override;

private:
torch::executor::EventTracer* tracer_;
::executorch::runtime::EventTracer* tracer_;
};
} // namespace executorchcoreml
3 changes: 0 additions & 3 deletions extension/aten_util/make_aten_functor_from_et_functor.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
namespace torch {
namespace executor {

class KernelRuntimeContext; // Forward declaration
using RuntimeContext = KernelRuntimeContext; // TODO(T147221312): Remove

// Map types from ETen to ATen.
// This is used to convert ETen arguments into ATen.
template <typename T>
Expand Down
46 changes: 27 additions & 19 deletions extension/evalue_util/print_evalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
#include <ostream>
#include <sstream>

namespace torch {
namespace executor {
using exec_aten::ScalarType;

namespace executorch {
namespace extension {

namespace {

Expand Down Expand Up @@ -102,7 +104,7 @@ void print_scalar_list(
// We've printed a full line, so wrap and begin a new one.
os << "\n ";
}
os << EValue(exec_aten::Scalar(list[i]));
os << executorch::runtime::EValue(exec_aten::Scalar(list[i]));
if (wrapping || i < list.size() - 1) {
// No trailing comma when not wrapping. Always a trailing comma when
// wrapping. This will leave a trailing space at the end of every wrapped
Expand Down Expand Up @@ -149,12 +151,13 @@ void print_tensor(std::ostream& os, exec_aten::Tensor tensor) {
//
// TODO(T159700776): Format multidimensional data like numpy/PyTorch does.
// https://github.com/pytorch/pytorch/blob/main/torch/_tensor_str.py
#define PRINT_TENSOR_DATA(ctype, dtype) \
case ScalarType::dtype: \
print_scalar_list( \
os, \
ArrayRef<ctype>(tensor.const_data_ptr<ctype>(), tensor.numel()), \
/*print_length=*/false); \
#define PRINT_TENSOR_DATA(ctype, dtype) \
case ScalarType::dtype: \
print_scalar_list( \
os, \
exec_aten::ArrayRef<ctype>( \
tensor.const_data_ptr<ctype>(), tensor.numel()), \
/*print_length=*/false); \
break;

switch (tensor.scalar_type()) {
Expand Down Expand Up @@ -211,7 +214,20 @@ void print_list_optional_tensor(

} // namespace

void evalue_edge_items::set_edge_items(std::ostream& os, long edge_items) {
os.iword(get_edge_items_xalloc()) = edge_items;
}

} // namespace extension
} // namespace executorch

namespace executorch {
namespace runtime {

// This needs to live in the same namespace as EValue.
std::ostream& operator<<(std::ostream& os, const EValue& value) {
using namespace executorch::extension;

switch (value.tag) {
case Tag::None:
os << "None";
Expand Down Expand Up @@ -258,13 +274,5 @@ std::ostream& operator<<(std::ostream& os, const EValue& value) {
return os;
}

namespace util {

void evalue_edge_items::set_edge_items(std::ostream& os, long edge_items) {
os.iword(get_edge_items_xalloc()) = edge_items;
}

} // namespace util

} // namespace executor
} // namespace torch
} // namespace runtime
} // namespace executorch
19 changes: 15 additions & 4 deletions extension/evalue_util/print_evalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@

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

namespace torch {
namespace executor {

namespace executorch {
namespace runtime {
/**
* Prints an Evalue to a stream.
*/
std::ostream& operator<<(std::ostream& os, const EValue& value);
// Note that this must be declared in the same namespace as EValue.
} // namespace runtime
} // namespace executorch

namespace util {
namespace executorch {
namespace extension {

/**
* Sets the number of "edge items" when printing EValue lists to a stream.
Expand Down Expand Up @@ -67,6 +69,15 @@ class evalue_edge_items final {
const long edge_items_;
};

} // namespace extension
} // namespace executorch

namespace torch {
namespace executor {
namespace util {
// TODO(T197294990): Remove these deprecated aliases once all users have moved
// to the new `::executorch` namespaces.
using ::executorch::extension::evalue_edge_items;
} // namespace util
} // namespace executor
} // namespace torch
24 changes: 15 additions & 9 deletions extension/kernel_util/make_boxed_from_unboxed_functor.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
/// Example usage:
/// ```
/// Tensor&
/// my_op(RuntimeContext& ctx, const Tensor& self, const Tensor& other, Tensor&
/// out) {
/// my_op(KernelRuntimeContext& ctx, const Tensor& self, const Tensor& other,
/// Tensor& out)
/// {
/// // ...
/// return out;
/// }
Expand Down Expand Up @@ -47,12 +48,15 @@
#include <type_traits>
#include <typeinfo>

namespace executorch {
namespace runtime {
class KernelRuntimeContext; // Forward declaration
} // namespace runtime
} // namespace executorch

namespace torch {
namespace executor {

class KernelRuntimeContext; // Forward declaration
using RuntimeContext = KernelRuntimeContext; // TODO(T147221312): Remove

// evalue_to_arg
template <class T>
struct decay_if_not_tensor final {
Expand Down Expand Up @@ -106,7 +110,7 @@ struct evalue_to_arg<exec_aten::ArrayRef<exec_aten::optional<T>>> final {

template <class Functor, size_t... evalue_arg_indices, typename... ArgTypes>
void call_functor_with_args_from_stack_(
RuntimeContext& ctx,
::executorch::runtime::KernelRuntimeContext& ctx,
EValue** stack,
std::index_sequence<evalue_arg_indices...>,
typelist<ArgTypes...>*) {
Expand All @@ -129,16 +133,18 @@ struct WrapUnboxedIntoFunctor {
using TrueType = typename FuncType::FuncType;
using ReturnType = typename infer_function_traits_t<TrueType>::return_type;
using ArgsType = typename infer_function_traits_t<TrueType>::parameter_types;
// check if the first argument is RuntimeContext, if so, remove it
// check if the first argument is KernelRuntimeContext, if so, remove it
static constexpr bool first_arg_is_context = std::is_same<
RuntimeContext,
::executorch::runtime::KernelRuntimeContext,
std::remove_reference_t<head_with_default_t<void, ArgsType>>>::value;
using ContextRemovedArgsType = std::conditional_t<
first_arg_is_context,
drop_if_nonempty_t<ArgsType, 1>,
ArgsType>;

static void call(RuntimeContext& ctx, EValue** stack) {
static void call(
::executorch::runtime::KernelRuntimeContext& ctx,
EValue** stack) {
constexpr size_t num_inputs = size<ContextRemovedArgsType>::value;
return call_functor_with_args_from_stack_<FuncType>(
ctx,
Expand Down
16 changes: 13 additions & 3 deletions extension/testing_util/temp_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

#include <gtest/gtest.h>

namespace torch {
namespace executor {
namespace testing {
namespace executorch {
namespace extension {
namespace testing { // Test-only helpers belong in a "testing" sub-namespace.

/**
* Creates and manages a named temporary file in the file system. Deletes the
Expand Down Expand Up @@ -98,6 +98,16 @@ class TempFile {
std::string path_;
};

} // namespace testing
} // namespace extension
} // namespace executorch

namespace torch {
namespace executor {
namespace testing {
// TODO(T197294990): Remove these deprecated aliases once all users have moved
// to the new `::executorch` namespaces.
using ::executorch::extension::testing::TempFile;
} // namespace testing
} // namespace executor
} // namespace torch
2 changes: 1 addition & 1 deletion extension/testing_util/test/temp_file_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <gtest/gtest.h>

using namespace ::testing;
using torch::executor::testing::TempFile;
using executorch::extension::testing::TempFile;

TEST(TempFileTest, Smoke) {
std::string path;
Expand Down
12 changes: 10 additions & 2 deletions runtime/backend/backend_execution_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#include <executorch/runtime/core/event_tracer.h>
#include <executorch/runtime/core/memory_allocator.h>

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

/**
* BackendExecutionContext will be used to inject run time context.
Expand Down Expand Up @@ -57,5 +57,13 @@ class BackendExecutionContext final {
MemoryAllocator* temp_allocator_ = nullptr;
};

} // namespace runtime
} // namespace executorch

namespace torch {
namespace executor {
// TODO(T197294990): Remove these deprecated aliases once all users have moved
// to the new `::executorch` namespaces.
using ::executorch::runtime::BackendExecutionContext;
} // namespace executor
} // namespace torch
12 changes: 10 additions & 2 deletions runtime/backend/backend_init_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#pragma once
#include <executorch/runtime/core/memory_allocator.h>

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

/**
* BackendInitContext will be used to inject runtime info for to initialize
Expand All @@ -33,5 +33,13 @@ class BackendInitContext final {
MemoryAllocator* runtime_allocator_ = nullptr;
};

} // namespace runtime
} // namespace executorch

namespace torch {
namespace executor {
// TODO(T197294990): Remove these deprecated aliases once all users have moved
// to the new `::executorch` namespaces.
using ::executorch::runtime::BackendInitContext;
} // namespace executor
} // namespace torch
10 changes: 5 additions & 5 deletions runtime/backend/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
#include <executorch/runtime/backend/interface.h>
#include <executorch/runtime/platform/assert.h>

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

PyTorchBackendInterface::~PyTorchBackendInterface() {}

// Task t128866626: Remove global static variables.
// TODO(T128866626): Remove global static variables.
// We want to be able to run multiple Executor instances
// and having a global registration isn't a viable solution
// in the long term.
Expand Down Expand Up @@ -56,5 +56,5 @@ Error BackendRegistry::register_backend(const Backend& backend) {
return Error::Ok;
}

} // namespace executor
} // namespace torch
} // namespace runtime
} // namespace executorch
20 changes: 18 additions & 2 deletions runtime/backend/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#include <executorch/runtime/core/result.h>
#include <executorch/runtime/platform/compiler.h>

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

struct SizedBuffer {
void* buffer;
Expand Down Expand Up @@ -170,5 +170,21 @@ PyTorchBackendInterface* get_backend_class(const char* name);
*/
__ET_NODISCARD Error register_backend(const Backend& backend);

} // namespace runtime
} // namespace executorch

namespace torch {
namespace executor {
// TODO(T197294990): Remove these deprecated aliases once all users have moved
// to the new `::executorch` namespaces.
using ::executorch::runtime::Backend;
using ::executorch::runtime::BackendRegistry;
using ::executorch::runtime::CompileSpec;
using ::executorch::runtime::DelegateHandle;
using ::executorch::runtime::get_backend_class;
// using ::executorch::runtime::kRegistrationTableMaxSize;
using ::executorch::runtime::PyTorchBackendInterface;
using ::executorch::runtime::register_backend;
using ::executorch::runtime::SizedBuffer;
} // namespace executor
} // namespace torch
14 changes: 12 additions & 2 deletions runtime/core/array_ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

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

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

/**
* Represents a constant reference to an array (0 or more elements
Expand Down Expand Up @@ -236,5 +236,15 @@ bool operator!=(ArrayRef<T> a1, ArrayRef<T> a2) {

using IntArrayRef = ArrayRef<int64_t>;

} // namespace runtime
} // namespace executorch

namespace torch {
namespace executor {
// TODO(T197294990): Remove these deprecated aliases once all users have moved
// to the new `::executorch` namespaces.
using ::executorch::runtime::ArrayRef;
using ::executorch::runtime::IntArrayRef;
using ::executorch::runtime::makeArrayRef;
} // namespace executor
} // namespace torch
Loading
Loading