-
Notifications
You must be signed in to change notification settings - Fork 583
[1/N] Add backend option #11288
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
[1/N] Add backend option #11288
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/11288
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit e91888c with merge base 8e2737c ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This pull request was exported from Phabricator. Differential Revision: D75770142 |
This pull request was exported from Phabricator. Differential Revision: D75770142 |
Summary: Introduce backend option as discussed in pytorch#10216 Step 1: Introducd Backend Option class In later stage, it will be plugged in with the rest of the stack. Differential Revision: D75770142
This pull request was exported from Phabricator. Differential Revision: D75770142 |
Summary: Introduce backend option as discussed in pytorch#10216 Step 1: Introducd Backend Option class In later stage, it will be plugged in with the rest of the stack. Differential Revision: D75770142
This pull request was exported from Phabricator. Differential Revision: D75770142 |
Summary: Introduce backend option as discussed in pytorch#10216 Step 1: Introducd Backend Option class In later stage, it will be plugged in with the rest of the stack. Differential Revision: D75770142
This pull request was exported from Phabricator. Differential Revision: D75770142 |
Summary: Introduce backend option as discussed in pytorch#10216 Step 1: Introducd Backend Option class In later stage, it will be plugged in with the rest of the stack. Differential Revision: D75770142
This pull request was exported from Phabricator. Differential Revision: D75770142 |
Summary: Introduce backend option as discussed in pytorch#10216 Step 1: Introducd Backend Option class In later stage, it will be plugged in with the rest of the stack. Differential Revision: D75770142
This pull request was exported from Phabricator. Differential Revision: D75770142 |
Summary: Introduce backend option as discussed in pytorch#10216 Step 1: Introducd Backend Option class In later stage, it will be plugged in with the rest of the stack. Differential Revision: D75770142
This pull request was exported from Phabricator. Differential Revision: D75770142 |
Summary: Introduce backend option as discussed in pytorch#10216 Step 1: Introducd Backend Option class In later stage, it will be plugged in with the rest of the stack. Differential Revision: D75770142
This pull request was exported from Phabricator. Differential Revision: D75770142 |
Summary: Introduce backend option as discussed in pytorch#10216 Step 1: Introducd Backend Option class In later stage, it will be plugged in with the rest of the stack. Differential Revision: D75770142
This pull request was exported from Phabricator. Differential Revision: D75770142 |
Will review tomorrow |
// Union-like container for option values (only one member is valid per option) | ||
struct OptionValue { | ||
bool bool_value; // Storage for boolean values | ||
int int_value; // Storage for integer values |
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.
int64_t
I don't think we need to define a generic BackendOption that takes arbitrary key value. Each backend owners could define their options instead. Vulkan will define its own config structure, Core ML will define its own config structure. Wdyt? @JacobSzwejbka, @mcr229, @kimishpatel Something like this:
Each individual backends define their own configs
// User code
|
I thought about this idea at the beginning, but it means that users code needs to link to a specific backend, otherwise the runner code will fail to build. Currently the same user code can be backend agnostic, meaning the same code can still run with different backends with/without linking the backend. As the example, the portable runner can work with/without xnnpack https://github.com/pytorch/executorch/blob/main/examples/xnnpack/executor_runner/targets.bzl. It also exposes the backend specific symbol to users, and the contract interface is a bit looser. Previously, The contract is like backend <-> ET <-> backend, and if we change it to this, it can be user <-> backend. And users can pass arbitrary things to backend. Users can run backend->init, backend->execute in their own code too, and it will be out of our control. With the proposed solution (#10216), the user code can still be backend agnostic, and the backend option is still optional. We are still on the hook of the contract. |
Btw I was thinking using ghstack such that I can export a stack of PRs...but it means this PR will be closed and a new PR will be created. I will copy the comments over just so we keep the history. Edit: the new pr is here #11389, I'm closing this PR and please leave comments in the new PR |
enum class OptionType { BOOL, INT, STRING }; | ||
|
||
// Union-like container for option values (only one member is valid per option) | ||
struct OptionValue { |
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.
Why not use a union? Or structure with a template?
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.
or std::variant that can hold only bool, int and char *?
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.
union can be a good option, let me try
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.
Left a few comments
#include <cstring> | ||
|
||
namespace executorch { | ||
namespace ET_RUNTIME_NAMESPACE { |
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.
why this capitalized?
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.
It's used across the whole ExecuTorch stack, but I find now it's not needed so switch to executorch::runtime
namespace
}; | ||
|
||
// Supported option data types | ||
enum class OptionType { BOOL, INT, STRING }; |
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.
Just use std::varaint
|
||
// Represents a single backend configuration option | ||
struct BackendOption { | ||
const char* key; // Name of the option |
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.
you can also do
struct BackendOptions {
const char* key;
std::variant<int, bool, char *> value;
}
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.
It will introduce std library I assume?
/// Sets or updates a boolean option | ||
/// @param key: Typed option key | ||
/// @param value: Boolean value to set | ||
void set_option(OptionKey<bool> key, bool value) { |
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.
Just make this set_option<T>(BackendOption<T> key_value)...
If tomorrow you expand BackendOption to have other types like float or int8 you just have to update allowed types in BackendOpton.
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.
and assert to on allowable types
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.
BackendOptions
is a list of BackendOption
, and each BackendOption
can be different type (Like cpu: {thread: 2, profile: true}
). If we make BackendOption
a template, then BackendOptions
can only hold the same type of BackendOption
, which is not we would like.
enum class OptionType { BOOL, INT, STRING }; | ||
|
||
// Union-like container for option values (only one member is valid per option) | ||
struct OptionValue { |
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.
or std::variant that can hold only bool, int and char *?
|
||
private: | ||
BackendOption options[MaxCapacity]{}; // Storage for options | ||
size_t size; // Current number of options |
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.
size_ for private variables.
executorch::runtime::Error get_option_internal( | ||
const char* key, | ||
OptionType expected_type, | ||
OptionValue& out) const { |
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.
Is it necessary that type is specified? If we use std::variant we can just make this get_optional_internal(const char* key, BackendOption& option);
User can be responsible for type check. Not sure why we need to provide it
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.
std::variant is part of the std library, and this code needs to stay in core
Address comments in #11389, please take a look |
Summary: Introduce backend option as discussed in #10216
Differential Revision: D75770142
Step 1: Introducd Backend Option class
In later stage, it will be plugged in with the rest of the stack.