-
Notifications
You must be signed in to change notification settings - Fork 603
[5/N] Add get_option/set_option APIs #11758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: gh/cccclai/29/base
Are you sure you want to change the base?
Changes from 6 commits
4e28e5c
82bacde
19aa8d6
5444a97
9b8cb37
8c2dc94
cfb760b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
#include <executorch/runtime/backend/options.h> | ||
#include <executorch/runtime/core/error.h> | ||
#include <executorch/runtime/core/span.h> | ||
#include <executorch/runtime/backend/backend_option_context.h> | ||
#include <executorch/runtime/backend/interface.h> | ||
#include <cstring> | ||
namespace executorch { | ||
namespace runtime { | ||
|
@@ -82,5 +84,106 @@ class BackendOptionsMap { | |
size_t size_ = 0; // Current number of entries | ||
}; | ||
|
||
|
||
/** | ||
* Retrieves backend options for a specific backend. | ||
* | ||
* @param backend_name The name of the backend to get options from | ||
* @param backend_options The backend option objects that will be filled with | ||
* the populated values from the backend | ||
* @return Error::Ok on success, Error::NotFound if backend is not found, or | ||
* other error codes on failure | ||
*/ | ||
Error get_option( | ||
const char* backend_name, | ||
executorch::runtime::Span<executorch::runtime::BackendOption> | ||
backend_options) { | ||
auto backend_class = get_backend_class(backend_name); | ||
if (!backend_class) { | ||
return Error::NotFound; | ||
} | ||
executorch::runtime::BackendOptionContext backend_option_context; | ||
executorch::runtime::Span<BackendOption> backend_options_ref( | ||
backend_options.data(), backend_options.size()); | ||
auto result = | ||
backend_class->get_option(backend_option_context, backend_options_ref); | ||
if (result != Error::Ok) { | ||
return result; | ||
} | ||
return Error::Ok; | ||
} | ||
|
||
/** | ||
* Retrieves backend options for multiple backends using a backend options map. | ||
* | ||
* @param backend_options_map The backend option map containing backend names | ||
* and their associated options, which will be filled with the populated values | ||
* from the backend | ||
* @return Error::Ok on success, or the first error encountered when processing | ||
* the entries | ||
*/ | ||
Error get_option( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont think we need this. If users want something like that, they can implement it or we wait to see if users want options like that and introduce it later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean get_option function or the get_option with backend option map? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with backend options map, is what i meant |
||
executorch::runtime::Span<executorch::runtime::Entry> backend_options_map) { | ||
Error result = Error::Ok; | ||
for (auto& entry : backend_options_map) { | ||
const char* backend_name = entry.backend_name; | ||
auto backend_options = entry.options; | ||
auto result = get_option(backend_name, backend_options); | ||
if (result != Error::Ok) { | ||
return result; | ||
} | ||
} | ||
return Error::Ok; | ||
} | ||
|
||
/** | ||
* Sets backend options for a specific backend. | ||
* | ||
* @param backend_name The name of the backend to set options for | ||
* @param backend_options The backend option list containing the options | ||
* to set | ||
* @return Error::Ok on success, Error::NotFound if backend is not found, or | ||
* other error codes on failure | ||
*/ | ||
Error set_option( | ||
const char* backend_name, | ||
const executorch::runtime::Span<executorch::runtime::BackendOption> | ||
backend_options) { | ||
auto backend_class = get_backend_class(backend_name); | ||
if (!backend_class) { | ||
return Error::NotFound; | ||
} | ||
|
||
executorch::runtime::BackendOptionContext backend_option_context; | ||
Error result = | ||
backend_class->set_option(backend_option_context, backend_options); | ||
if (result != Error::Ok) { | ||
return result; | ||
} | ||
return Error::Ok; | ||
} | ||
|
||
/** | ||
* Sets backend options for multiple backends using a backend options map. | ||
* | ||
* @param backend_options_map The backend option map containing backend names | ||
* and their associated backend options to set | ||
* @return Error::Ok on success, or the first error encountered when processing | ||
*/ | ||
Error set_option(const executorch::runtime::Span<executorch::runtime::Entry> | ||
backend_options_map) { | ||
Error result = Error::Ok; | ||
for (const auto& entry : backend_options_map) { | ||
const char* backend_name = entry.backend_name; | ||
auto backend_options = entry.options; | ||
result = set_option(backend_name, backend_options); | ||
|
||
if (result != Error::Ok) { | ||
return result; | ||
} | ||
} | ||
return Error::Ok; | ||
} | ||
|
||
} // namespace runtime | ||
} // namespace executorch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.