Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions backends/native/runtime/engine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,16 @@ std::unique_ptr<EngineExecutable> EngineContext::compile(

EngineHost::~EngineHost() = default;

std::unique_ptr<EngineContext> EngineHost::create_context_with_options(
std::shared_ptr<const Program> program,
std::shared_ptr<const Package> package,
const EngineOptions& options) {
if (!options.empty()) {
throw std::invalid_argument(
name() + ": unsupported context option '" + options.begin()->first +
"'");
}
return create_context(std::move(program), std::move(package));
}

} // namespace ptn
15 changes: 15 additions & 0 deletions backends/native/runtime/engine/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <cstddef>
#include <cstdint>
#include <map>
#include <memory>
#include <string>
#include <vector>
Expand Down Expand Up @@ -105,6 +106,10 @@ class EngineContext {
std::shared_ptr<const Package> package_;
};

// Named load-time settings for one context, such as the registry key of an
// off-graph KV cache the caller installed.
using EngineOptions = std::map<std::string, std::string>;

// Process-wide backend and device resources shared by its contexts. Must
// outlive every context and executable it creates.
// Callers serialize create_context(); distinct contexts may execute
Expand All @@ -129,6 +134,16 @@ class EngineHost {
virtual std::unique_ptr<EngineContext> create_context(
std::shared_ptr<const Program> program,
std::shared_ptr<const Package> package) = 0;

// create_context with `options`. Throws std::invalid_argument on an option
// the engine does not recognize; the default recognizes none. An option may
// bind caller-owned state, such as a KV cache, into the context. Contexts
// bound to the same state are not isolated from each other: the caller must
// serialize their executables as if they shared one context.
virtual std::unique_ptr<EngineContext> create_context_with_options(
std::shared_ptr<const Program> program,
std::shared_ptr<const Package> package,
const EngineOptions& options);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EngineOptions reads like the generic form of GgmlEngineOptions. Maybe EngineContextOptions, to match EngineContext?

};

} // namespace ptn
Loading