Skip to content

Commit 0993897

Browse files
cmt0facebook-github-bot
authored andcommitted
Method_Meta contains_backend check
Summary: For a runtime that supports models of a couple different types it helps to be able to check ahead of time whether certain backend types are present. In our case, there are processors that can use this information to make scheduling decisions without having the actual required backend implementations present. Differential Revision: D69143825
1 parent ee6f2d9 commit 0993897

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

runtime/executor/method_meta.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,5 +248,16 @@ size_t MethodMeta::num_instructions() const {
248248
return num_instructions;
249249
}
250250

251+
bool MethodMeta::contains_backend(const char* backend_name) const {
252+
const auto delegates = s_plan_->delegates();
253+
for (size_t i = 0; i < delegates->size(); i++) {
254+
auto delegate = delegates->Get(i);
255+
if (strcmp(delegate->id()->c_str(), backend_name) == 0) {
256+
return true;
257+
}
258+
}
259+
return false;
260+
}
261+
251262
} // namespace runtime
252263
} // namespace executorch

runtime/executor/method_meta.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,13 @@ class MethodMeta final {
192192
*/
193193
ET_EXPERIMENTAL size_t num_instructions() const;
194194

195+
/**
196+
* Check to see if a backend is used in this method.
197+
*
198+
* @returns Whether a backend is used in this method.
199+
*/
200+
ET_EXPERIMENTAL bool contains_backend(const char* backend_name) const;
201+
195202
/**
196203
* DEPRECATED: Use num_memory_planned_buffers() instead.
197204
*/

0 commit comments

Comments
 (0)