-
Notifications
You must be signed in to change notification settings - Fork 603
[4/N] Add backend options map #11462
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/24/base
Are you sure you want to change the base?
Changes from 3 commits
d2137c7
bba4c6d
cab5519
5685bf2
ba6f9f9
875fdc4
a3ffbb9
390aed6
601a487
ff6bfd9
6be49e1
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include <executorch/runtime/backend/backend_options.h> | ||
#include <executorch/runtime/core/error.h> | ||
#include <cstring> | ||
|
||
#pragma once | ||
namespace executorch { | ||
namespace runtime { | ||
|
||
struct Entry { | ||
const char* backend_name; | ||
ArrayRef<BackendOption> options; | ||
}; | ||
|
||
template <size_t MaxBackends> | ||
class BackendOptionsMap { | ||
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. why do we need this? 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. This is to manage the mapping between backend_name and backend options. Like 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. Can you not just use set_option and get_option? We discussed this by allowing users to directly set backend options, without having to plumb it through methods/program etc., and I belive you did that? In that case do we still need this? 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. backend options map is for setting multiple backends, users code will be like following
|
||
public: | ||
// Default constructor | ||
BackendOptionsMap() : size_(0) {} | ||
|
||
// Add a new backend configuration | ||
Error add( | ||
const char* backend_name, | ||
::executorch::runtime::ArrayRef<BackendOption> options) { | ||
if (size_ < MaxBackends) { | ||
entries_[size_] = {backend_name, options}; | ||
++size_; | ||
return Error::Ok; | ||
} else { | ||
ET_LOG(Error, "Maximum number of backends %lu reached", MaxBackends); | ||
} | ||
return Error::InvalidArgument; | ||
} | ||
|
||
// Get options for a specific backend | ||
::executorch::runtime::ArrayRef<BackendOption> get( | ||
const char* backend_name) const { | ||
for (size_t i = 0; i < size_; ++i) { | ||
if (std::strcmp(entries_[i].backend_name, backend_name) == 0) { | ||
return entries_[i].options; | ||
} | ||
} | ||
return {}; // Return empty ArrayRef if not found | ||
} | ||
|
||
// Get a view of the entries (const version) | ||
::executorch::runtime::ArrayRef<const Entry> entries() const { | ||
return ::executorch::runtime::ArrayRef<const Entry>(entries_, size_); | ||
} | ||
|
||
// Get a view of the entries (non-const version) | ||
::executorch::runtime::ArrayRef<Entry> entries() { | ||
return ::executorch::runtime::ArrayRef<Entry>(entries_, size_); | ||
} | ||
|
||
// Get number of entries | ||
size_t size() const { | ||
return size_; | ||
} | ||
|
||
private: | ||
Entry entries_[MaxBackends]; // Storage for backend entries | ||
size_t size_ = 0; // Current number of entries | ||
}; | ||
|
||
} // 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.
is this method needed?