Skip to content

Commit 86b15c1

Browse files
Chris Thompsonfacebook-github-bot
Chris Thompson
authored andcommitted
Method_Meta contains_backend check (#8198)
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 1b11e3e commit 86b15c1

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

runtime/executor/method_meta.cpp

+11
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::uses_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

+7
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 true if a backend is used in this method, otherwise false.
199+
*/
200+
ET_EXPERIMENTAL bool uses_backend(const char* backend_name) const;
201+
195202
/**
196203
* DEPRECATED: Use num_memory_planned_buffers() instead.
197204
*/

runtime/executor/test/backend_integration_test.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ TEST_P(BackendIntegrationTest, BasicInitSucceeds) {
338338
Result<Program> program = Program::load(&loader.get());
339339
ASSERT_EQ(program.error(), Error::Ok);
340340

341+
auto method_meta = program->method_meta("forward");
342+
EXPECT_EQ(method_meta->uses_backend(StubBackend::kName), true);
343+
EXPECT_EQ(method_meta->uses_backend("INVALID_BACKEND_NAME"), false);
344+
341345
ManagedMemoryManager mmm(kDefaultNonConstMemBytes, kDefaultRuntimeMemBytes);
342346
Result<Method> method_res = program->load_method("forward", &mmm.get());
343347
EXPECT_EQ(method_res.error(), Error::Ok);

0 commit comments

Comments
 (0)