Skip to content

Commit ff6bfd9

Browse files
committed
Update on "[4/N] Add backend options map"
This is to manage the backend <-> BackendOptions map. Users will create the bakcend options map, and ET runtime will read the backend name, and dispatch the list of backend options to each backend. exported-using-ghexport Differential Revision: [D76149466](https://our.internmc.facebook.com/intern/diff/D76149466/) Differential Revision: [D76149466](https://our.internmc.facebook.com/intern/diff/D76149466) [ghstack-poisoned]
2 parents 601a487 + 8300d24 commit ff6bfd9

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

runtime/backend/options.h

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ struct BackendOption {
3939
};
4040

4141
/**
42-
* A template class for storing and managing backend-specific configuration options.
43-
*
44-
* This class provides a type-safe way to store key-value pairs for backend configuration,
45-
* with compile-time capacity limits and runtime type checking. It supports bool, int, and
46-
* const char* value types.
47-
*
42+
* A template class for storing and managing backend-specific configuration
43+
* options.
44+
*
45+
* This class provides a type-safe way to store key-value pairs for backend
46+
* configuration, with compile-time capacity limits and runtime type checking.
47+
* It supports bool, int, and const char* value types.
48+
*
4849
* @tparam MaxCapacity The maximum number of options that can be stored
4950
*/
5051
template <size_t MaxCapacity>
@@ -57,7 +58,7 @@ class BackendOptions {
5758

5859
/**
5960
* Returns a const view of all stored options as a Span.
60-
*
61+
*
6162
* @return A const Span containing all BackendOption entries
6263
*/
6364
executorch::runtime::Span<BackendOption> view() const {
@@ -66,7 +67,7 @@ class BackendOptions {
6667

6768
/**
6869
* Returns a mutable view of all stored options as a Span.
69-
*
70+
*
7071
* @return A mutable Span containing all BackendOption entries
7172
*/
7273
executorch::runtime::Span<BackendOption> view() {
@@ -76,64 +77,64 @@ class BackendOptions {
7677
/**
7778
* Sets a boolean option value for the given key.
7879
* If the key already exists, updates its value. Otherwise, adds a new option.
79-
*
80+
*
8081
* @tparam N The length of the key string (automatically deduced)
8182
* @param key The option key (must be a string literal or array)
8283
* @param value The boolean value to set
8384
* @return Error::Ok on success, Error::InvalidArgument if storage is full
8485
*/
8586
template <size_t N>
8687
Error set_option(const char (&key)[N], bool value) noexcept {
87-
static_assert(N <= kMaxOptionKeyLength, "Option key is too long");
88+
ET_CHECK_MSG(N <= kMaxOptionKeyLength, "Option key is too long");
8889
return set_option_impl(key, value);
8990
}
9091

9192
/**
9293
* Sets an integer option value for the given key.
9394
* If the key already exists, updates its value. Otherwise, adds a new option.
94-
*
95+
*
9596
* @tparam N The length of the key string (automatically deduced)
9697
* @param key The option key (must be a string literal or array)
9798
* @param value The integer value to set
9899
* @return Error::Ok on success, Error::InvalidArgument if storage is full
99100
*/
100101
template <size_t N>
101102
Error set_option(const char (&key)[N], int value) noexcept {
102-
static_assert(N <= kMaxOptionKeyLength, "Option key is too long");
103+
ET_CHECK_MSG(N <= kMaxOptionKeyLength, "Option key is too long");
103104
return set_option_impl(key, value);
104105
}
105106

106107
/**
107108
* Sets a string option value for the given key.
108109
* If the key already exists, updates its value. Otherwise, adds a new option.
109-
*
110-
* Note: The string value must have static storage duration. This class does NOT
111-
* take ownership of the string - it only stores the pointer.
112-
*
110+
*
111+
* Note: The string value must have static storage duration. This class does
112+
* NOT take ownership of the string - it only stores the pointer.
113+
*
113114
* @tparam N The length of the key string (automatically deduced)
114115
* @param key The option key (must be a string literal or array)
115116
* @param value The string value to set (must have static storage duration)
116117
* @return Error::Ok on success, Error::InvalidArgument if storage is full
117118
*/
118119
template <size_t N>
119120
Error set_option(const char (&key)[N], const char* value) noexcept {
120-
static_assert(N <= kMaxOptionKeyLength, "Option key is too long");
121+
ET_CHECK_MSG(N <= kMaxOptionKeyLength, "Option key is too long");
121122
return set_option_impl(key, value);
122123
}
123124

124125
/**
125126
* Retrieves an option value by key and type.
126-
*
127+
*
127128
* @tparam T The expected type of the option value (bool, int, or const char*)
128129
* @tparam KeyLen The length of the key string (automatically deduced)
129130
* @param key The option key to look up
130131
* @param out Reference to store the retrieved value
131-
* @return Error::Ok if found and type matches, Error::NotFound if key doesn't exist,
132-
* Error::InvalidArgument if type doesn't match
132+
* @return Error::Ok if found and type matches, Error::NotFound if key doesn't
133+
* exist, Error::InvalidArgument if type doesn't match
133134
*/
134135
template <typename T, size_t KeyLen>
135136
Error get_option(const char (&key)[KeyLen], T& out) const {
136-
static_assert(KeyLen <= kMaxOptionKeyLength, "Option key is too long");
137+
ET_CHECK_MSG(KeyLen <= kMaxOptionKeyLength, "Option key is too long");
137138

138139
for (size_t i = 0; i < size_; ++i) {
139140
if (std::strcmp(options_[i].key, key) == 0) {
@@ -154,7 +155,7 @@ class BackendOptions {
154155
/**
155156
* Internal implementation for setting option values.
156157
* Handles both updating existing options and adding new ones.
157-
*
158+
*
158159
* @tparam T The type of the value (bool, int, or const char*)
159160
* @param key The option key
160161
* @param value The value to set

0 commit comments

Comments
 (0)