Skip to content

Commit 9b2eba3

Browse files
Esther Onemafacebook-github-bot
authored andcommitted
- Move register backend logic to its own file (#13014)
Summary: Pull Request resolved: #13014 **Context**: https://fb.workplace.com/groups/pytorch.edge2.team/permalink/1233607881228395/ We want to no longer statically initialize a coreml function on app start during compile time. see CoreML static initializer is called, contributing 293ms+ to app init time: https://pxl.cl/7JmKW **What this diff accomplishes:** Introduces a separate file (namespace) so that we can QE removing this static initalizer during compile time and instead execute its logic when we absolutely need it (app start on startup). We also export the headers as they will be accessed/used in later diffs/files within this stack :) Reviewed By: metascroy Differential Revision: D77910822
1 parent 3e70463 commit 9b2eba3

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
namespace executorch::core_ml_backend_delegate {
4+
void register_backend_coreml();
5+
} // namespace executorch::core_ml_backend_delegate
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#pragma once
2+
3+
#include "executorch_operations.h"
4+
#import <coreml_backend/delegate.h>
5+
#import "ETCoreMLStrings.h"
6+
#import "backend_delegate.h"
7+
8+
#import <executorch/runtime/core/evalue.h>
9+
#import <executorch/runtime/platform/log.h>
10+
#import <executorch/runtime/backend/interface.h>
11+
12+
#include <array>
13+
#import <memory>
14+
15+
namespace executorch::core_ml_backend_delegate {
16+
using executorch::runtime::get_backend_class;
17+
18+
static std::unique_ptr<executorch::backends::coreml::CoreMLBackendDelegate> backendInterfaceLazy_;
19+
20+
void register_backend_coreml() {
21+
auto backendInterface = executorch::runtime::get_backend_class(ETCoreMLStrings.delegateIdentifier.UTF8String);
22+
if (backendInterface == nullptr) {
23+
backendInterfaceLazy_ = std::make_unique<executorch::backends::coreml::CoreMLBackendDelegate>();
24+
executorch::runtime::Backend backend{ETCoreMLStrings.delegateIdentifier.UTF8String, backendInterfaceLazy_.get()};
25+
std::ignore = register_backend(backend);
26+
}
27+
}
28+
29+
} // namespace executorch::core_ml_backend_delegate

0 commit comments

Comments
 (0)