Skip to content

Commit ad6f5ee

Browse files
authored
Add a namespace for ATen mode
Differential Revision: D72440313 Pull Request resolved: #9894
1 parent 0bc52fe commit ad6f5ee

File tree

93 files changed

+517
-411
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+517
-411
lines changed

codegen/templates/RegisterCodegenUnboxedKernels.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
// JIT op registry instead of c10 dispatcher. JIT op registry only takes boxed
2323
// kernels, so we are calling unboxing functions in UnboxingFunctions.h to cast
2424
// arguments into C++ types (instead of IValue) and delegate to unboxed kernels.
25-
using KernelSpan =
26-
::executorch::runtime::Span<const ::executorch::runtime::Kernel>;
25+
using KernelSpan = ::executorch::runtime::Span<
26+
const ::executorch::ET_RUNTIME_NAMESPACE::Kernel>;
2727
namespace torch {
2828
namespace executor {
2929
namespace function {

devtools/bundled_program/bundled_program.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ using executorch::aten::ArrayRef;
2727
using executorch::aten::Half;
2828
using executorch::aten::ScalarType;
2929
using executorch::aten::Tensor;
30+
using ::executorch::ET_RUNTIME_NAMESPACE::Method;
3031
using ::executorch::runtime::Error;
3132
using ::executorch::runtime::EValue;
32-
using ::executorch::runtime::Method;
3333
using ::executorch::runtime::Result;
3434

3535
namespace executorch {
@@ -332,8 +332,9 @@ ET_NODISCARD Error load_bundled_input(
332332
static_cast<uint32_t>(status));
333333
}
334334

335-
::executorch::runtime::internal::event_tracer_set_bundled_input_index(
336-
method.get_event_tracer(), testset_idx);
335+
::executorch::ET_RUNTIME_NAMESPACE::internal::
336+
event_tracer_set_bundled_input_index(
337+
method.get_event_tracer(), testset_idx);
337338

338339
return Error::Ok;
339340
}

devtools/bundled_program/bundled_program.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace bundled_program {
1818
* An opaque pointer to a serialized bundled program.
1919
*/
2020
using SerializedBundledProgram = const void;
21-
21+
using ::executorch::ET_RUNTIME_NAMESPACE::Method;
2222
/**
2323
* Load testset_idx-th bundled input of method_idx-th Method test in
2424
* bundled_program_ptr to given Method.
@@ -31,7 +31,7 @@ using SerializedBundledProgram = const void;
3131
* execution.
3232
*/
3333
ET_NODISCARD ::executorch::runtime::Error load_bundled_input(
34-
::executorch::runtime::Method& method,
34+
Method& method,
3535
SerializedBundledProgram* bundled_program_ptr,
3636
size_t testset_idx);
3737

@@ -49,7 +49,7 @@ ET_NODISCARD ::executorch::runtime::Error load_bundled_input(
4949
* execution.
5050
*/
5151
ET_NODISCARD ::executorch::runtime::Error verify_method_outputs(
52-
::executorch::runtime::Method& method,
52+
Method& method,
5353
SerializedBundledProgram* bundled_program_ptr,
5454
size_t testset_idx,
5555
double rtol = 1e-5,
@@ -106,7 +106,7 @@ using serialized_bundled_program =
106106
::executorch::bundled_program::SerializedBundledProgram;
107107

108108
ET_NODISCARD inline ::executorch::runtime::Error LoadBundledInput(
109-
::executorch::runtime::Method& method,
109+
Method& method,
110110
serialized_bundled_program* bundled_program_ptr,
111111
size_t testset_idx) {
112112
return ::executorch::bundled_program::load_bundled_input(
@@ -115,7 +115,7 @@ ET_NODISCARD inline ::executorch::runtime::Error LoadBundledInput(
115115

116116
ET_NODISCARD inline ::executorch::runtime::Error
117117
VerifyResultWithBundledExpectedOutput(
118-
::executorch::runtime::Method& method,
118+
Method& method,
119119
serialized_bundled_program* bundled_program_ptr,
120120
size_t testset_idx,
121121
double rtol = 1e-5,

examples/portable/custom_ops/custom_ops_2_out.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace native {
1313

1414
using executorch::aten::ScalarType;
1515
using executorch::aten::Tensor;
16-
using executorch::runtime::KernelRuntimeContext;
16+
using executorch::ET_RUNTIME_NAMESPACE::KernelRuntimeContext;
1717

1818
namespace {
1919
void check_preconditions(const Tensor& in, Tensor& out) {

extension/flat_tensor/flat_tensor_data_map.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ using executorch::runtime::Result;
2525
using executorch::runtime::Span;
2626

2727
using executorch::aten::ScalarType;
28+
using executorch::ET_RUNTIME_NAMESPACE::TensorLayout;
2829
using executorch::runtime::DataLoader;
29-
using executorch::runtime::TensorLayout;
3030

3131
namespace executorch {
3232
namespace extension {

extension/flat_tensor/flat_tensor_data_map.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ namespace extension {
3232
/**
3333
* A NamedDataMap implementation for FlatTensor-serialized data.
3434
*/
35-
class FlatTensorDataMap final : public executorch::runtime::NamedDataMap {
35+
class FlatTensorDataMap final
36+
: public executorch::ET_RUNTIME_NAMESPACE::NamedDataMap {
3637
public:
3738
/**
3839
* Creates a new DataMap that wraps FlatTensor data.
@@ -51,7 +52,8 @@ class FlatTensorDataMap final : public executorch::runtime::NamedDataMap {
5152
* @return Error::NotFound if the key is not present.
5253
*/
5354
ET_NODISCARD
54-
executorch::runtime::Result<const executorch::runtime::TensorLayout>
55+
executorch::runtime::Result<
56+
const executorch::ET_RUNTIME_NAMESPACE::TensorLayout>
5557
get_metadata(const char* key) const override;
5658

5759
/**

extension/flat_tensor/targets.bzl

+23-21
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
22

33
def define_common_targets():
4-
runtime.cxx_library(
5-
name = "flat_tensor_data_map",
6-
srcs = [
7-
"flat_tensor_data_map.cpp",
8-
],
9-
exported_headers = ["flat_tensor_data_map.h"],
10-
deps = [
11-
"//executorch/runtime/core:core",
12-
"//executorch/runtime/core:evalue",
13-
"//executorch/runtime/core:named_data_map",
14-
"//executorch/runtime/core/exec_aten:lib",
15-
"//executorch/runtime/core/exec_aten/util:tensor_util",
16-
],
17-
exported_deps = [
18-
"//executorch/extension/flat_tensor/serialize:flat_tensor_header",
19-
"//executorch/extension/flat_tensor/serialize:generated_headers",
20-
],
21-
visibility = [
22-
"//executorch/...",
23-
],
24-
)
4+
for aten_mode in [True, False]:
5+
aten_suffix = "_aten" if aten_mode else ""
6+
runtime.cxx_library(
7+
name = "flat_tensor_data_map" + aten_suffix,
8+
srcs = [
9+
"flat_tensor_data_map.cpp",
10+
],
11+
exported_headers = ["flat_tensor_data_map.h"],
12+
deps = [
13+
"//executorch/runtime/core:core",
14+
"//executorch/runtime/core:evalue",
15+
"//executorch/runtime/core:named_data_map" + aten_suffix,
16+
"//executorch/runtime/core/exec_aten:lib" + aten_suffix,
17+
"//executorch/runtime/core/exec_aten/util:tensor_util",
18+
],
19+
exported_deps = [
20+
"//executorch/extension/flat_tensor/serialize:flat_tensor_header",
21+
"//executorch/extension/flat_tensor/serialize:generated_headers",
22+
],
23+
visibility = [
24+
"//executorch/...",
25+
],
26+
)

extension/module/module.cpp

+10-7
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
namespace executorch {
3838
namespace extension {
3939

40+
using ET_RUNTIME_NAMESPACE::MethodMeta;
41+
using ET_RUNTIME_NAMESPACE::Program;
42+
4043
namespace {
4144
runtime::Result<std::unique_ptr<runtime::DataLoader>> load_file(
4245
const std::string& file_path,
@@ -113,7 +116,7 @@ Module::Module(
113116
}
114117

115118
Module::Module(
116-
std::shared_ptr<runtime::Program> program,
119+
std::shared_ptr<Program> program,
117120
std::unique_ptr<runtime::MemoryAllocator> memory_allocator,
118121
std::unique_ptr<runtime::MemoryAllocator> temp_allocator,
119122
std::unique_ptr<runtime::EventTracer> event_tracer,
@@ -131,7 +134,7 @@ Module::Module(
131134
runtime::runtime_init();
132135
}
133136

134-
runtime::Error Module::load(const runtime::Program::Verification verification) {
137+
runtime::Error Module::load(const Program::Verification verification) {
135138
if (!is_loaded()) {
136139
// Load the program
137140
if (!data_loader_) {
@@ -156,10 +159,10 @@ runtime::Error Module::load(const runtime::Program::Verification verification) {
156159
}
157160
// else: either the map itself was provided or we have no data map, either
158161
// way no work to do.
159-
auto program = ET_UNWRAP_UNIQUE(
160-
runtime::Program::load(data_loader_.get(), verification));
161-
program_ = std::shared_ptr<runtime::Program>(
162-
program.release(), [](runtime::Program* pointer) { delete pointer; });
162+
auto program =
163+
ET_UNWRAP_UNIQUE(Program::load(data_loader_.get(), verification));
164+
program_ = std::shared_ptr<Program>(
165+
program.release(), [](Program* pointer) { delete pointer; });
163166
}
164167
return runtime::Error::Ok;
165168
}
@@ -224,7 +227,7 @@ runtime::Error Module::load_method(
224227
return runtime::Error::Ok;
225228
}
226229

227-
runtime::Result<runtime::MethodMeta> Module::method_meta(
230+
runtime::Result<MethodMeta> Module::method_meta(
228231
const std::string& method_name) {
229232
ET_CHECK_OK_OR_RETURN_ERROR(load_method(method_name));
230233
return methods_.at(method_name).method->method_meta();

extension/module/module.h

+13-9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
namespace executorch {
2020
namespace extension {
2121

22+
using ET_RUNTIME_NAMESPACE::Method;
23+
using ET_RUNTIME_NAMESPACE::MethodMeta;
24+
using ET_RUNTIME_NAMESPACE::NamedDataMap;
25+
using ET_RUNTIME_NAMESPACE::Program;
26+
2227
/**
2328
* A facade class for loading programs and executing methods within them.
2429
*/
@@ -95,7 +100,7 @@ class Module {
95100
* @param[in] data_map_loader A DataLoader used for loading external weights.
96101
*/
97102
explicit Module(
98-
std::shared_ptr<runtime::Program> program,
103+
std::shared_ptr<Program> program,
99104
std::unique_ptr<runtime::MemoryAllocator> memory_allocator = nullptr,
100105
std::unique_ptr<runtime::MemoryAllocator> temp_allocator = nullptr,
101106
std::unique_ptr<runtime::EventTracer> event_tracer = nullptr,
@@ -116,8 +121,8 @@ class Module {
116121
*/
117122
ET_NODISCARD
118123
runtime::Error load(
119-
const runtime::Program::Verification verification =
120-
runtime::Program::Verification::Minimal);
124+
const Program::Verification verification =
125+
Program::Verification::Minimal);
121126

122127
/**
123128
* Checks if the program is loaded.
@@ -134,7 +139,7 @@ class Module {
134139
*
135140
* @returns Shared pointer to the program or nullptr if it's not yet loaded.
136141
*/
137-
inline std::shared_ptr<runtime::Program> program() const {
142+
inline std::shared_ptr<Program> program() const {
138143
return program_;
139144
}
140145

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

230234
/**
231235
* Execute a specific method with the given input values and retrieve the
@@ -473,20 +477,20 @@ class Module {
473477
std::vector<runtime::Span<uint8_t>> planned_spans;
474478
std::unique_ptr<runtime::HierarchicalAllocator> planned_memory;
475479
std::unique_ptr<runtime::MemoryManager> memory_manager;
476-
std::unique_ptr<runtime::Method> method;
480+
std::unique_ptr<Method> method;
477481
std::vector<runtime::EValue> inputs;
478482
};
479483

480484
std::string file_path_;
481485
std::string data_map_path_;
482486
LoadMode load_mode_{LoadMode::MmapUseMlock};
483-
std::shared_ptr<runtime::Program> program_;
487+
std::shared_ptr<Program> program_;
484488
std::unique_ptr<runtime::DataLoader> data_loader_;
485489
std::unique_ptr<runtime::MemoryAllocator> memory_allocator_;
486490
std::unique_ptr<runtime::MemoryAllocator> temp_allocator_;
487491
std::unique_ptr<runtime::EventTracer> event_tracer_;
488492
std::unique_ptr<runtime::DataLoader> data_map_loader_;
489-
std::unique_ptr<runtime::NamedDataMap> data_map_;
493+
std::unique_ptr<NamedDataMap> data_map_;
490494

491495
protected:
492496
std::unordered_map<std::string, MethodHolder> methods_;

extension/module/targets.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def define_common_targets():
2525
"//executorch/extension/memory_allocator:malloc_memory_allocator",
2626
"//executorch/extension/data_loader:file_data_loader",
2727
"//executorch/extension/data_loader:mmap_data_loader",
28-
"//executorch/extension/flat_tensor:flat_tensor_data_map",
28+
"//executorch/extension/flat_tensor:flat_tensor_data_map" + aten_suffix,
2929
],
3030
exported_deps = [
3131
"//executorch/runtime/executor:program" + aten_suffix,

extension/pybindings/pybindings.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -85,26 +85,26 @@ void et_pal_emit_log_message(
8585

8686
namespace py = pybind11;
8787
using executorch::bundled_program::verify_method_outputs;
88+
using ::executorch::ET_RUNTIME_NAMESPACE::BackendInterface;
89+
using ::executorch::ET_RUNTIME_NAMESPACE::get_backend_class;
90+
using ::executorch::ET_RUNTIME_NAMESPACE::get_backend_name;
91+
using ::executorch::ET_RUNTIME_NAMESPACE::get_num_registered_backends;
92+
using ::executorch::ET_RUNTIME_NAMESPACE::get_registered_kernels;
93+
using ::executorch::ET_RUNTIME_NAMESPACE::Kernel;
94+
using ::executorch::ET_RUNTIME_NAMESPACE::Method;
95+
using ::executorch::ET_RUNTIME_NAMESPACE::Program;
8896
using ::executorch::extension::BufferDataLoader;
8997
using ::executorch::extension::MallocMemoryAllocator;
9098
using ::executorch::extension::MmapDataLoader;
9199
using ::executorch::runtime::ArrayRef;
92-
using ::executorch::runtime::BackendInterface;
93100
using ::executorch::runtime::DataLoader;
94101
using ::executorch::runtime::Error;
95102
using ::executorch::runtime::EValue;
96103
using ::executorch::runtime::EventTracerDebugLogLevel;
97-
using ::executorch::runtime::get_backend_class;
98-
using ::executorch::runtime::get_backend_name;
99-
using ::executorch::runtime::get_num_registered_backends;
100-
using ::executorch::runtime::get_registered_kernels;
101104
using ::executorch::runtime::HierarchicalAllocator;
102-
using ::executorch::runtime::Kernel;
103105
using ::executorch::runtime::MemoryAllocator;
104106
using ::executorch::runtime::MemoryManager;
105-
using ::executorch::runtime::Method;
106107
using ::executorch::runtime::prof_result_t;
107-
using ::executorch::runtime::Program;
108108
using ::executorch::runtime::Result;
109109
using ::executorch::runtime::Span;
110110
using ::executorch::runtime::Tag;

extension/runner_util/inputs.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
#include <executorch/runtime/executor/method_meta.h>
1313
#include <executorch/runtime/platform/log.h>
1414

15+
using executorch::ET_RUNTIME_NAMESPACE::Method;
16+
using executorch::ET_RUNTIME_NAMESPACE::MethodMeta;
17+
using executorch::ET_RUNTIME_NAMESPACE::TensorInfo;
1518
using executorch::runtime::Error;
16-
using executorch::runtime::Method;
17-
using executorch::runtime::MethodMeta;
1819
using executorch::runtime::Result;
1920
using executorch::runtime::Tag;
20-
using executorch::runtime::TensorInfo;
2121

2222
namespace executorch {
2323
namespace extension {

extension/runner_util/inputs.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
namespace executorch {
1616
namespace extension {
1717

18+
using ::executorch::ET_RUNTIME_NAMESPACE::Method;
19+
using ::executorch::ET_RUNTIME_NAMESPACE::TensorInfo;
20+
1821
/**
1922
* RAII helper that frees a set of buffers when destroyed. Movable.
2023
*/
@@ -80,7 +83,7 @@ struct PrepareInputTensorsOptions {
8083
* @returns An error on failure.
8184
*/
8285
executorch::runtime::Result<BufferCleanup> prepare_input_tensors(
83-
executorch::runtime::Method& method,
86+
Method& method,
8487
PrepareInputTensorsOptions options = {});
8588

8689
namespace internal {
@@ -89,8 +92,8 @@ namespace internal {
8992
* fills it with ones, and sets the input at `input_index`.
9093
*/
9194
executorch::runtime::Error fill_and_set_input(
92-
executorch::runtime::Method& method,
93-
executorch::runtime::TensorInfo& tensor_meta,
95+
Method& method,
96+
TensorInfo& tensor_meta,
9497
size_t input_index,
9598
void* data_ptr);
9699
} // namespace internal

extension/runner_util/inputs_aten.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#include <executorch/runtime/executor/method_meta.h>
1616

1717
using executorch::runtime::Error;
18-
using executorch::runtime::Method;
19-
using executorch::runtime::TensorInfo;
18+
using executorch::runtime::aten::Method;
19+
using executorch::runtime::aten::TensorInfo;
2020

2121
namespace executorch {
2222
namespace extension {

0 commit comments

Comments
 (0)