Skip to content

Commit 38277da

Browse files
cccclaifacebook-github-bot
authored andcommitted
Add init context
Summary: Similar to other places we use context to inject runtime related information. The `BackendInitContext` will wrap `runtime_allocator` for `backend.init`. Reviewed By: dbort Differential Revision: D48872101 fbshipit-source-id: a8c35317db94077f470aa2063e5b6f81dd85f64f
1 parent 32acb60 commit 38277da

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
#pragma once
10+
#include <executorch/runtime/core/memory_allocator.h>
11+
12+
namespace torch {
13+
namespace executor {
14+
15+
/**
16+
* BackendInitContext will be used to inject runtime info for to initialize
17+
* delegate.
18+
*/
19+
class BackendInitContext final {
20+
public:
21+
BackendInitContext(MemoryAllocator* runtime_allocator)
22+
: runtime_allocator_(runtime_allocator) {}
23+
24+
/** Get the runtime allocator passed from Method. It's the same runtime
25+
* executor used by the standard executor runtime and the life span is the
26+
* same as the model.
27+
*/
28+
MemoryAllocator* get_runtime_allocator() {
29+
return runtime_allocator_;
30+
}
31+
32+
private:
33+
MemoryAllocator* runtime_allocator_;
34+
};
35+
36+
} // namespace executor
37+
} // namespace torch

runtime/backend/targets.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def define_common_targets():
1616
],
1717
exported_headers = [
1818
"backend_execution_context.h",
19+
"backend_init_context.h",
1920
"backend_registry.h",
2021
],
2122
preprocessor_flags = ["-DUSE_ATEN_LIB"] if aten_mode else [],

0 commit comments

Comments
 (0)