Skip to content

Commit 3cfca44

Browse files
committed
Update on "[ExecuTorch][#10447] Extend PyBundledModule with extension.BundledModule"
# Context This issue is a step of #9638. In #9638, we want to have `extension.Module` as the single source of implementation in `pybindings`, which means that `pybindings.PyModule` should use `extension.Module` rather than its own `pybindings.Module`. # Proposal Now that we have `extension.BundledModule` ready, we want to test it out by having our existing `PyBundledModule` to extend it, and let `verify_result_with_bundled_expected_output` to use it, so that we can test out the whole thing with https://github.com/pytorch/executorch/blob/fb45e19055a92d2a91a4d4b7008e135232cbb14b/devtools/bundled_program/test/test_end2end.py Differential Revision: [D73564127](https://our.internmc.facebook.com/intern/diff/D73564127/) [ghstack-poisoned]
2 parents 188c3db + 8ce661c commit 3cfca44

File tree

6 files changed

+43
-5
lines changed

6 files changed

+43
-5
lines changed

extension/module/bundled_module.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <executorch/extension/data_loader/buffer_data_loader.h>
1414
#include <executorch/extension/data_loader/file_data_loader.h>
1515

16+
1617
namespace executorch {
1718
namespace extension {
1819

@@ -27,6 +28,9 @@ std::unique_ptr<BufferDataLoader> program_data_loader(
2728
}
2829
} // namespace
2930

31+
32+
namespace ET_BUNDLED_MODULE_NAMESPACE {
33+
3034
BundledModule::BundledModule(
3135
const void* bundled_program_ptr,
3236
std::unique_ptr<runtime::MemoryAllocator> memory_allocator,
@@ -107,6 +111,6 @@ runtime::Error BundledModule::verify_method_outputs(
107111
return executorch::BUNDLED_PROGRAM_NAMESPACE::verify_method_outputs(
108112
*method, bundled_program_ptr_, testset_idx, rtol, atol);
109113
}
110-
114+
} // namespace ET_BUNDLED_MODULE_NAMESPACE
111115
} // namespace extension
112116
} // namespace executorch

extension/module/bundled_module.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,20 @@
1010

1111
#include <executorch/extension/module/module.h>
1212

13+
14+
#ifdef USE_ATEN_LIB
15+
#define ET_BUNDLED_MODULE_NAMESPACE bundled_module::aten
16+
#else // !USE_ATEN_LIB
17+
#define ET_BUNDLED_MODULE_NAMESPACE bundled_module
18+
#endif // USE_ATEN_LIB
19+
1320
namespace executorch {
1421
namespace extension {
1522

23+
using ET_MODULE_NAMESPACE::Module;
24+
25+
namespace ET_BUNDLED_MODULE_NAMESPACE {
26+
1627
/**
1728
* A facade class for loading bundled programs and executing methods within
1829
* them.
@@ -119,5 +130,6 @@ class BundledModule : public Module {
119130
bool is_loaded_from_file_ = false;
120131
};
121132

133+
} // namespace ET_BUNDLED_MODULE_NAMESPACE
122134
} // namespace extension
123135
} // namespace executorch

extension/module/module.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
namespace executorch {
3838
namespace extension {
39+
namespace ET_MODULE_NAMESPACE {
40+
3941

4042
using ET_RUNTIME_NAMESPACE::MethodMeta;
4143
using ET_RUNTIME_NAMESPACE::Program;
@@ -308,5 +310,6 @@ runtime::Error Module::set_output(
308310
output_tensor.mutable_data_ptr(), output_tensor.nbytes(), output_index);
309311
}
310312

313+
} // namespace ET_MODULE_NAMESPACE
311314
} // namespace extension
312315
} // namespace executorch

extension/module/module.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616

1717
#include <executorch/runtime/executor/program.h>
1818

19+
20+
#ifdef USE_ATEN_LIB
21+
#define ET_MODULE_NAMESPACE module::aten
22+
#else // !USE_ATEN_LIB
23+
#define ET_MODULE_NAMESPACE module
24+
#endif // USE_ATEN_LIB
25+
1926
namespace executorch {
2027
namespace extension {
2128

@@ -24,6 +31,9 @@ using ET_RUNTIME_NAMESPACE::MethodMeta;
2431
using ET_RUNTIME_NAMESPACE::NamedDataMap;
2532
using ET_RUNTIME_NAMESPACE::Program;
2633

34+
class ExecuTorchJni;
35+
36+
namespace ET_MODULE_NAMESPACE {
2737
/**
2838
* A facade class for loading programs and executing methods within them.
2939
*/
@@ -493,16 +503,24 @@ class Module {
493503
protected:
494504
std::unordered_map<std::string, MethodHolder> methods_;
495505

496-
friend class ExecuTorchJni;
506+
friend class executorch::extension::ExecuTorchJni;
497507
};
498508

509+
} // namespace ET_MODULE_NAMESPACE
499510
} // namespace extension
500511
} // namespace executorch
501512

502513
namespace torch {
503514
namespace executor {
504515
// TODO(T197294990): Remove these deprecated aliases once all users have moved
505516
// to the new `::executorch` namespaces.
506-
using ::executorch::extension::Module;
507-
} // namespace executor
517+
using ::executorch::extension::ET_MODULE_NAMESPACE::Module;
518+
} // namespace executorch
508519
} // namespace torch
520+
521+
namespace executorch {
522+
namespace extension {
523+
// backward compatible namespace alias
524+
using ::executorch::extension::ET_MODULE_NAMESPACE::Module;
525+
} // namespace extension
526+
} // namespace executorch

extension/module/test/bundled_module_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <executorch/extension/module/bundled_module.h>
1010
#include <gtest/gtest.h>
1111

12-
using namespace ::executorch::extension;
12+
using namespace ::executorch::extension::ET_BUNDLED_MODULE_NAMESPACE;
1313
using namespace ::executorch::runtime;
1414

1515
class BundledModuleTest : public ::testing::Test {

extension/pybindings/pybindings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ using ::executorch::ET_RUNTIME_NAMESPACE::get_registered_kernels;
9494
using ::executorch::ET_RUNTIME_NAMESPACE::Kernel;
9595
using ::executorch::ET_RUNTIME_NAMESPACE::Method;
9696
using ::executorch::ET_RUNTIME_NAMESPACE::Program;
97+
using ::executorch::extension::ET_BUNDLED_MODULE_NAMESPACE::BundledModule;
9798
using ::executorch::extension::BufferDataLoader;
9899
using ::executorch::extension::MallocMemoryAllocator;
99100
using ::executorch::extension::MmapDataLoader;

0 commit comments

Comments
 (0)