Skip to content

Commit d18c44a

Browse files
Chris Thompsonfacebook-github-bot
Chris Thompson
authored andcommitted
method_meta add uses_backend function (#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. Reviewed By: dbort Differential Revision: D69143825
1 parent 3e64c4e commit d18c44a

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

runtime/executor/method_meta.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,17 @@ Result<int64_t> MethodMeta::memory_planned_buffer_size(size_t index) const {
228228
return s_plan_->non_const_buffer_sizes()->Get(index + 1);
229229
}
230230

231+
bool MethodMeta::uses_backend(const char* backend_name) const {
232+
const auto delegates = s_plan_->delegates();
233+
for (size_t i = 0; i < delegates->size(); i++) {
234+
auto delegate = delegates->Get(i);
235+
if (strcmp(delegate->id()->c_str(), backend_name) == 0) {
236+
return true;
237+
}
238+
}
239+
return false;
240+
}
241+
231242
size_t MethodMeta::num_instructions() const {
232243
const auto chains = s_plan_->chains();
233244
if (chains == nullptr) {

runtime/executor/method_meta.h

+8
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,14 @@ class MethodMeta final {
185185
*/
186186
Result<int64_t> memory_planned_buffer_size(size_t index) const;
187187

188+
/**
189+
* Check to see if a backend is used in this method.
190+
*
191+
* @param[in] backend_name The name of the backend to search for.
192+
* @returns true if a backend is used in this method, otherwise false.
193+
*/
194+
bool uses_backend(const char* backend_name) const;
195+
188196
/**
189197
* Get the number of instructions in this method.
190198
*

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)