Skip to content

Add a namespace for ATen mode #9894

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

Merged
merged 1 commit into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions codegen/templates/RegisterCodegenUnboxedKernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
// JIT op registry instead of c10 dispatcher. JIT op registry only takes boxed
// kernels, so we are calling unboxing functions in UnboxingFunctions.h to cast
// arguments into C++ types (instead of IValue) and delegate to unboxed kernels.
using KernelSpan =
::executorch::runtime::Span<const ::executorch::runtime::Kernel>;
using KernelSpan = ::executorch::runtime::Span<
const ::executorch::ET_RUNTIME_NAMESPACE::Kernel>;
namespace torch {
namespace executor {
namespace function {
Expand Down
7 changes: 4 additions & 3 deletions devtools/bundled_program/bundled_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ using executorch::aten::ArrayRef;
using executorch::aten::Half;
using executorch::aten::ScalarType;
using executorch::aten::Tensor;
using ::executorch::ET_RUNTIME_NAMESPACE::Method;
using ::executorch::runtime::Error;
using ::executorch::runtime::EValue;
using ::executorch::runtime::Method;
using ::executorch::runtime::Result;

namespace executorch {
Expand Down Expand Up @@ -332,8 +332,9 @@ ET_NODISCARD Error load_bundled_input(
static_cast<uint32_t>(status));
}

::executorch::runtime::internal::event_tracer_set_bundled_input_index(
method.get_event_tracer(), testset_idx);
::executorch::ET_RUNTIME_NAMESPACE::internal::
event_tracer_set_bundled_input_index(
method.get_event_tracer(), testset_idx);

return Error::Ok;
}
Expand Down
10 changes: 5 additions & 5 deletions devtools/bundled_program/bundled_program.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace bundled_program {
* An opaque pointer to a serialized bundled program.
*/
using SerializedBundledProgram = const void;

using ::executorch::ET_RUNTIME_NAMESPACE::Method;
/**
* Load testset_idx-th bundled input of method_idx-th Method test in
* bundled_program_ptr to given Method.
Expand All @@ -31,7 +31,7 @@ using SerializedBundledProgram = const void;
* execution.
*/
ET_NODISCARD ::executorch::runtime::Error load_bundled_input(
::executorch::runtime::Method& method,
Method& method,
SerializedBundledProgram* bundled_program_ptr,
size_t testset_idx);

Expand All @@ -49,7 +49,7 @@ ET_NODISCARD ::executorch::runtime::Error load_bundled_input(
* execution.
*/
ET_NODISCARD ::executorch::runtime::Error verify_method_outputs(
::executorch::runtime::Method& method,
Method& method,
SerializedBundledProgram* bundled_program_ptr,
size_t testset_idx,
double rtol = 1e-5,
Expand Down Expand Up @@ -106,7 +106,7 @@ using serialized_bundled_program =
::executorch::bundled_program::SerializedBundledProgram;

ET_NODISCARD inline ::executorch::runtime::Error LoadBundledInput(
::executorch::runtime::Method& method,
Method& method,
serialized_bundled_program* bundled_program_ptr,
size_t testset_idx) {
return ::executorch::bundled_program::load_bundled_input(
Expand All @@ -115,7 +115,7 @@ ET_NODISCARD inline ::executorch::runtime::Error LoadBundledInput(

ET_NODISCARD inline ::executorch::runtime::Error
VerifyResultWithBundledExpectedOutput(
::executorch::runtime::Method& method,
Method& method,
serialized_bundled_program* bundled_program_ptr,
size_t testset_idx,
double rtol = 1e-5,
Expand Down
2 changes: 1 addition & 1 deletion examples/portable/custom_ops/custom_ops_2_out.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace native {

using executorch::aten::ScalarType;
using executorch::aten::Tensor;
using executorch::runtime::KernelRuntimeContext;
using executorch::ET_RUNTIME_NAMESPACE::KernelRuntimeContext;

namespace {
void check_preconditions(const Tensor& in, Tensor& out) {
Expand Down
2 changes: 1 addition & 1 deletion extension/flat_tensor/flat_tensor_data_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ using executorch::runtime::Result;
using executorch::runtime::Span;

using executorch::aten::ScalarType;
using executorch::ET_RUNTIME_NAMESPACE::TensorLayout;
using executorch::runtime::DataLoader;
using executorch::runtime::TensorLayout;

namespace executorch {
namespace extension {
Expand Down
6 changes: 4 additions & 2 deletions extension/flat_tensor/flat_tensor_data_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ namespace extension {
/**
* A NamedDataMap implementation for FlatTensor-serialized data.
*/
class FlatTensorDataMap final : public executorch::runtime::NamedDataMap {
class FlatTensorDataMap final
: public executorch::ET_RUNTIME_NAMESPACE::NamedDataMap {
public:
/**
* Creates a new DataMap that wraps FlatTensor data.
Expand All @@ -51,7 +52,8 @@ class FlatTensorDataMap final : public executorch::runtime::NamedDataMap {
* @return Error::NotFound if the key is not present.
*/
ET_NODISCARD
executorch::runtime::Result<const executorch::runtime::TensorLayout>
executorch::runtime::Result<
const executorch::ET_RUNTIME_NAMESPACE::TensorLayout>
get_metadata(const char* key) const override;

/**
Expand Down
44 changes: 23 additions & 21 deletions extension/flat_tensor/targets.bzl
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")

def define_common_targets():
runtime.cxx_library(
name = "flat_tensor_data_map",
srcs = [
"flat_tensor_data_map.cpp",
],
exported_headers = ["flat_tensor_data_map.h"],
deps = [
"//executorch/runtime/core:core",
"//executorch/runtime/core:evalue",
"//executorch/runtime/core:named_data_map",
"//executorch/runtime/core/exec_aten:lib",
"//executorch/runtime/core/exec_aten/util:tensor_util",
],
exported_deps = [
"//executorch/extension/flat_tensor/serialize:flat_tensor_header",
"//executorch/extension/flat_tensor/serialize:generated_headers",
],
visibility = [
"//executorch/...",
],
)
for aten_mode in [True, False]:
aten_suffix = "_aten" if aten_mode else ""
runtime.cxx_library(
name = "flat_tensor_data_map" + aten_suffix,
srcs = [
"flat_tensor_data_map.cpp",
],
exported_headers = ["flat_tensor_data_map.h"],
deps = [
"//executorch/runtime/core:core",
"//executorch/runtime/core:evalue",
"//executorch/runtime/core:named_data_map" + aten_suffix,
"//executorch/runtime/core/exec_aten:lib" + aten_suffix,
"//executorch/runtime/core/exec_aten/util:tensor_util",
],
exported_deps = [
"//executorch/extension/flat_tensor/serialize:flat_tensor_header",
"//executorch/extension/flat_tensor/serialize:generated_headers",
],
visibility = [
"//executorch/...",
],
)
17 changes: 10 additions & 7 deletions extension/module/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
namespace executorch {
namespace extension {

using ET_RUNTIME_NAMESPACE::MethodMeta;
using ET_RUNTIME_NAMESPACE::Program;

namespace {
runtime::Result<std::unique_ptr<runtime::DataLoader>> load_file(
const std::string& file_path,
Expand Down Expand Up @@ -113,7 +116,7 @@ Module::Module(
}

Module::Module(
std::shared_ptr<runtime::Program> program,
std::shared_ptr<Program> program,
std::unique_ptr<runtime::MemoryAllocator> memory_allocator,
std::unique_ptr<runtime::MemoryAllocator> temp_allocator,
std::unique_ptr<runtime::EventTracer> event_tracer,
Expand All @@ -131,7 +134,7 @@ Module::Module(
runtime::runtime_init();
}

runtime::Error Module::load(const runtime::Program::Verification verification) {
runtime::Error Module::load(const Program::Verification verification) {
if (!is_loaded()) {
// Load the program
if (!data_loader_) {
Expand All @@ -156,10 +159,10 @@ runtime::Error Module::load(const runtime::Program::Verification verification) {
}
// else: either the map itself was provided or we have no data map, either
// way no work to do.
auto program = ET_UNWRAP_UNIQUE(
runtime::Program::load(data_loader_.get(), verification));
program_ = std::shared_ptr<runtime::Program>(
program.release(), [](runtime::Program* pointer) { delete pointer; });
auto program =
ET_UNWRAP_UNIQUE(Program::load(data_loader_.get(), verification));
program_ = std::shared_ptr<Program>(
program.release(), [](Program* pointer) { delete pointer; });
}
return runtime::Error::Ok;
}
Expand Down Expand Up @@ -224,7 +227,7 @@ runtime::Error Module::load_method(
return runtime::Error::Ok;
}

runtime::Result<runtime::MethodMeta> Module::method_meta(
runtime::Result<MethodMeta> Module::method_meta(
const std::string& method_name) {
ET_CHECK_OK_OR_RETURN_ERROR(load_method(method_name));
return methods_.at(method_name).method->method_meta();
Expand Down
22 changes: 13 additions & 9 deletions extension/module/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
namespace executorch {
namespace extension {

using ET_RUNTIME_NAMESPACE::Method;
using ET_RUNTIME_NAMESPACE::MethodMeta;
using ET_RUNTIME_NAMESPACE::NamedDataMap;
using ET_RUNTIME_NAMESPACE::Program;

/**
* A facade class for loading programs and executing methods within them.
*/
Expand Down Expand Up @@ -95,7 +100,7 @@ class Module {
* @param[in] data_map_loader A DataLoader used for loading external weights.
*/
explicit Module(
std::shared_ptr<runtime::Program> program,
std::shared_ptr<Program> program,
std::unique_ptr<runtime::MemoryAllocator> memory_allocator = nullptr,
std::unique_ptr<runtime::MemoryAllocator> temp_allocator = nullptr,
std::unique_ptr<runtime::EventTracer> event_tracer = nullptr,
Expand All @@ -116,8 +121,8 @@ class Module {
*/
ET_NODISCARD
runtime::Error load(
const runtime::Program::Verification verification =
runtime::Program::Verification::Minimal);
const Program::Verification verification =
Program::Verification::Minimal);

/**
* Checks if the program is loaded.
Expand All @@ -134,7 +139,7 @@ class Module {
*
* @returns Shared pointer to the program or nullptr if it's not yet loaded.
*/
inline std::shared_ptr<runtime::Program> program() const {
inline std::shared_ptr<Program> program() const {
return program_;
}

Expand Down Expand Up @@ -224,8 +229,7 @@ class Module {
* @returns A method metadata, or an error if the program or method failed to
* load.
*/
runtime::Result<runtime::MethodMeta> method_meta(
const std::string& method_name);
runtime::Result<MethodMeta> method_meta(const std::string& method_name);

/**
* Execute a specific method with the given input values and retrieve the
Expand Down Expand Up @@ -473,20 +477,20 @@ class Module {
std::vector<runtime::Span<uint8_t>> planned_spans;
std::unique_ptr<runtime::HierarchicalAllocator> planned_memory;
std::unique_ptr<runtime::MemoryManager> memory_manager;
std::unique_ptr<runtime::Method> method;
std::unique_ptr<Method> method;
std::vector<runtime::EValue> inputs;
};

std::string file_path_;
std::string data_map_path_;
LoadMode load_mode_{LoadMode::MmapUseMlock};
std::shared_ptr<runtime::Program> program_;
std::shared_ptr<Program> program_;
std::unique_ptr<runtime::DataLoader> data_loader_;
std::unique_ptr<runtime::MemoryAllocator> memory_allocator_;
std::unique_ptr<runtime::MemoryAllocator> temp_allocator_;
std::unique_ptr<runtime::EventTracer> event_tracer_;
std::unique_ptr<runtime::DataLoader> data_map_loader_;
std::unique_ptr<runtime::NamedDataMap> data_map_;
std::unique_ptr<NamedDataMap> data_map_;

protected:
std::unordered_map<std::string, MethodHolder> methods_;
Expand Down
2 changes: 1 addition & 1 deletion extension/module/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def define_common_targets():
"//executorch/extension/memory_allocator:malloc_memory_allocator",
"//executorch/extension/data_loader:file_data_loader",
"//executorch/extension/data_loader:mmap_data_loader",
"//executorch/extension/flat_tensor:flat_tensor_data_map",
"//executorch/extension/flat_tensor:flat_tensor_data_map" + aten_suffix,
],
exported_deps = [
"//executorch/runtime/executor:program" + aten_suffix,
Expand Down
16 changes: 8 additions & 8 deletions extension/pybindings/pybindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,26 +85,26 @@ void et_pal_emit_log_message(

namespace py = pybind11;
using executorch::bundled_program::verify_method_outputs;
using ::executorch::ET_RUNTIME_NAMESPACE::BackendInterface;
using ::executorch::ET_RUNTIME_NAMESPACE::get_backend_class;
using ::executorch::ET_RUNTIME_NAMESPACE::get_backend_name;
using ::executorch::ET_RUNTIME_NAMESPACE::get_num_registered_backends;
using ::executorch::ET_RUNTIME_NAMESPACE::get_registered_kernels;
using ::executorch::ET_RUNTIME_NAMESPACE::Kernel;
using ::executorch::ET_RUNTIME_NAMESPACE::Method;
using ::executorch::ET_RUNTIME_NAMESPACE::Program;
using ::executorch::extension::BufferDataLoader;
using ::executorch::extension::MallocMemoryAllocator;
using ::executorch::extension::MmapDataLoader;
using ::executorch::runtime::ArrayRef;
using ::executorch::runtime::BackendInterface;
using ::executorch::runtime::DataLoader;
using ::executorch::runtime::Error;
using ::executorch::runtime::EValue;
using ::executorch::runtime::EventTracerDebugLogLevel;
using ::executorch::runtime::get_backend_class;
using ::executorch::runtime::get_backend_name;
using ::executorch::runtime::get_num_registered_backends;
using ::executorch::runtime::get_registered_kernels;
using ::executorch::runtime::HierarchicalAllocator;
using ::executorch::runtime::Kernel;
using ::executorch::runtime::MemoryAllocator;
using ::executorch::runtime::MemoryManager;
using ::executorch::runtime::Method;
using ::executorch::runtime::prof_result_t;
using ::executorch::runtime::Program;
using ::executorch::runtime::Result;
using ::executorch::runtime::Span;
using ::executorch::runtime::Tag;
Expand Down
6 changes: 3 additions & 3 deletions extension/runner_util/inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
#include <executorch/runtime/executor/method_meta.h>
#include <executorch/runtime/platform/log.h>

using executorch::ET_RUNTIME_NAMESPACE::Method;
using executorch::ET_RUNTIME_NAMESPACE::MethodMeta;
using executorch::ET_RUNTIME_NAMESPACE::TensorInfo;
using executorch::runtime::Error;
using executorch::runtime::Method;
using executorch::runtime::MethodMeta;
using executorch::runtime::Result;
using executorch::runtime::Tag;
using executorch::runtime::TensorInfo;

namespace executorch {
namespace extension {
Expand Down
9 changes: 6 additions & 3 deletions extension/runner_util/inputs.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
namespace executorch {
namespace extension {

using ::executorch::ET_RUNTIME_NAMESPACE::Method;
using ::executorch::ET_RUNTIME_NAMESPACE::TensorInfo;

/**
* RAII helper that frees a set of buffers when destroyed. Movable.
*/
Expand Down Expand Up @@ -80,7 +83,7 @@ struct PrepareInputTensorsOptions {
* @returns An error on failure.
*/
executorch::runtime::Result<BufferCleanup> prepare_input_tensors(
executorch::runtime::Method& method,
Method& method,
PrepareInputTensorsOptions options = {});

namespace internal {
Expand All @@ -89,8 +92,8 @@ namespace internal {
* fills it with ones, and sets the input at `input_index`.
*/
executorch::runtime::Error fill_and_set_input(
executorch::runtime::Method& method,
executorch::runtime::TensorInfo& tensor_meta,
Method& method,
TensorInfo& tensor_meta,
size_t input_index,
void* data_ptr);
} // namespace internal
Expand Down
4 changes: 2 additions & 2 deletions extension/runner_util/inputs_aten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include <executorch/runtime/executor/method_meta.h>

using executorch::runtime::Error;
using executorch::runtime::Method;
using executorch::runtime::TensorInfo;
using executorch::runtime::aten::Method;
using executorch::runtime::aten::TensorInfo;

namespace executorch {
namespace extension {
Expand Down
Loading
Loading