-
Notifications
You must be signed in to change notification settings - Fork 596
[1/N] Add BackendOptions class #11389
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/21/base
Are you sure you want to change the base?
Conversation
Introduce backend option as discussed in #10216 Step 1: Introducd Backend Option class In later stage, it will be plugged in with the rest of the stack. Differential Revision: [D75993712](https://our.internmc.facebook.com/intern/diff/D75993712/) [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/11389
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 2fda6a1 with merge base 57e0765 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Introduce backend option as discussed in #10216 Step 1: Introducd Backend Option class In later stage, it will be plugged in with the rest of the stack. Differential Revision: [D75993712](https://our.internmc.facebook.com/intern/diff/D75993712/) ghstack-source-id: 288273758 Pull Request resolved: #11389
This pull request was exported from Phabricator. Differential Revision: D75993712 |
This PR needs a
|
Previous comment in the old PR: #11288 From @JacobSzwejbka :
|
From @mergennachin:
|
My response:
|
I think what @mergennachin suggested makes sense. If user code is setting backend specific option they already have to know what backend they are talking about, unless some options are backend agnostic. Other piece of the puzzle is how the user will update this. And from #10216 it seems that we will pipe |
Introduce backend option as discussed in #10216 Step 1: Introducd Backend Option class In later stage, it will be plugged in with the rest of the stack. Differential Revision: [D75993712](https://our.internmc.facebook.com/intern/diff/D75993712/) [ghstack-poisoned]
This pull request was exported from Phabricator. Differential Revision: D75993712 |
Introduce backend option as discussed in #10216 Step 1: Introducd Backend Option class In later stage, it will be plugged in with the rest of the stack. Differential Revision: [D75993712](https://our.internmc.facebook.com/intern/diff/D75993712/) [ghstack-poisoned]
This pull request was exported from Phabricator. Differential Revision: D75993712 |
Introduce backend option as discussed in #10216 Step 1: Introducd Backend Option class In later stage, it will be plugged in with the rest of the stack. Differential Revision: [D75993712](https://our.internmc.facebook.com/intern/diff/D75993712/) [ghstack-poisoned]
This pull request was exported from Phabricator. Differential Revision: D75993712 |
runtime/backend/backend_options.h
Outdated
namespace runtime { | ||
|
||
// Strongly-typed option key template | ||
template <typename T> |
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.
this class doesnt need to be templated. No use of T
runtime/backend/backend_options.h
Outdated
OptionValue | ||
value; // value is the value of the backend option, like 4, true, etc |
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.
format?
runtime/backend/backend_options.h
Outdated
using OptionValue = std::variant<bool, int, const char*>; | ||
|
||
struct BackendOption { | ||
const char* key; // key is the name of the backend option, like num_threads, |
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.
I am a bit concerned about storing pointer to the key. Users may do things like
std::string my_key("my_key");
BackendOption().set_option<int>(my_key.c_str(), 10);
When that goes out of scope we have a problem. I suggest instead use something like const char[kMaxKeyLength] key
runtime/backend/backend_options.h
Outdated
// enable_profiling, etc | ||
OptionValue | ||
value; // value is the value of the backend option, like 4, true, etc | ||
}; |
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.
The other thing I realize is why do we need BackendOption as a separate struct?
Can we not just have BackendOptions
class instantiate array of keys and values? The interface there is set_option with key name and value, get_option using key name. User never really needs to get BackendOption
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.
Users don't need get backend option, but the dispatcher needs it and dispatch to the actual backend.
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.
Actually you're right. The backend options map is for dispatching. and each backend will get an array ref of backend options.
runtime/backend/backend_options.h
Outdated
|
||
// Type-safe setters | ||
template <typename T> | ||
void set_option(OptionKey<T> key, T 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.
Bassed on suggestion above
void set_option(OptionKey<T> key, T value) { | |
void set_option(const char [kMaxKeyLength]& key, T value) { |
runtime/backend/backend_options.h
Outdated
if (size_ < MaxCapacity) { | ||
options_[size_++] = BackendOption{k, 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.
set error if no capacity
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.
Yeah good point. Will update
runtime/backend/backend_options.h
Outdated
// Helper functions for creating typed option keys (unchanged) | ||
constexpr OptionKey<bool> BoolKey(const char* k) { | ||
return OptionKey<bool>(k); | ||
} | ||
|
||
constexpr OptionKey<int> IntKey(const char* k) { | ||
return OptionKey<int>(k); | ||
} | ||
|
||
constexpr OptionKey<const char*> StrKey(const char* k) { | ||
return OptionKey<const char*>(k); | ||
} |
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.
Dont think you need these
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 just helper functions to simplify users' code.
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.
made some suggestions
Introduce backend option as discussed in #10216 Step 1: Introducd Backend Option class In later stage, it will be plugged in with the rest of the stack. BackendOptions is pretty much a list of BackendOption, and backend option is a key value pair. The key is a string, and the value can be 3 different types, including bool, string and int. Differential Revision: [D75993712](https://our.internmc.facebook.com/intern/diff/D75993712/) Differential Revision: [D75993712](https://our.internmc.facebook.com/intern/diff/D75993712) [ghstack-poisoned]
This pull request was exported from Phabricator. Differential Revision: D75993712 |
Introduce backend option as discussed in #10216 Step 1: Introducd Backend Option class In later stage, it will be plugged in with the rest of the stack. BackendOptions is pretty much a list of BackendOption, and backend option is a key value pair. The key is a string, and the value can be 3 different types, including bool, string and int. Differential Revision: [D75993712](https://our.internmc.facebook.com/intern/diff/D75993712/) Differential Revision: [D75993712](https://our.internmc.facebook.com/intern/diff/D75993712) [ghstack-poisoned]
This pull request was exported from Phabricator. Differential Revision: D75993712 |
Introduce backend option as discussed in #10216 Step 1: Introducd Backend Option class In later stage, it will be plugged in with the rest of the stack. BackendOptions is pretty much a list of BackendOption, and backend option is a key value pair. The key is a string, and the value can be 3 different types, including bool, string and int. Differential Revision: [D75993712](https://our.internmc.facebook.com/intern/diff/D75993712/) Differential Revision: [D75993712](https://our.internmc.facebook.com/intern/diff/D75993712) [ghstack-poisoned]
This pull request was exported from Phabricator. Differential Revision: D75993712 |
Stack from ghstack (oldest at bottom):
Introduce backend option as discussed in #10216
Step 1: Introducd Backend Option class
In later stage, it will be plugged in with the rest of the stack. BackendOptions is pretty much a list of BackendOption, and backend option is a key value pair. The key is a string, and the value can be 3 different types, including bool, string and int.
Differential Revision: D75993712
Differential Revision: D75993712