docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
rpc_context.h
Go to the documentation of this file.
1#pragma once
2
3#include <filesystem>
4#include <memory>
5#include <optional>
6#include <string>
7#include <unordered_map>
8
9namespace sdfg::passes::rpc {
10
12public:
13 virtual std::string get_remote_address() const = 0;
14 virtual std::unordered_map<std::string, std::string> get_auth_headers() const = 0;
15
16 // Open a tuning session and return its server-assigned id.
17 virtual std::optional<std::string> start_session() { return std::nullopt; }
18
19 virtual ~RpcContext() = default;
20};
21
23private:
24 std::string server_;
25 std::string endpoint_;
26 std::string session_endpoint_ = "transfertune_session";
27 std::unordered_map<std::string, std::string> headers_;
28
29protected:
30 void set_server(std::string server) { server_ = std::move(server); }
31
32public:
33 SimpleRpcContext(std::string server, std::string endpoint, std::unordered_map<std::string, std::string> headers = {})
34 : server_(std::move(server)), endpoint_(std::move(endpoint)), headers_(std::move(headers)) {}
35
36 std::string get_remote_address() const override { return server_ + "/" + endpoint_; }
37
38 std::unordered_map<std::string, std::string> get_auth_headers() const override { return headers_; }
39
40 // Default backend convention: POST to `<server>/transfertune_session` and read back `session_id`.
41 std::optional<std::string> start_session() override;
42};
43
45 std::string server;
46 std::string endpoint;
47 std::unordered_map<std::string, std::string> headers;
48
50
52 SimpleRpcContextBuilder& from_file(std::filesystem::path config_file);
53 SimpleRpcContextBuilder& from_header_env(std::string env_var = "RPC_HEADER");
54 SimpleRpcContextBuilder& from_env(std::string env_var = "SDFG_RPC_CONFIG");
55
56 SimpleRpcContextBuilder& add_header(std::string name, std::string value);
57
59
60 std::shared_ptr<SimpleRpcContext> build(bool print = true) const;
61};
62
63inline std::shared_ptr<RpcContext> build_rpc_context_local() {
66}
67
68inline std::shared_ptr<RpcContext> build_rpc_context_from_file(std::filesystem::path config_file) {
70 return b.from_file(std::move(config_file)).build();
71}
72
73inline std::shared_ptr<RpcContext> build_rpc_context_auto() {
76}
77
78} // namespace sdfg::passes::rpc
Definition rpc_context.h:11
virtual ~RpcContext()=default
virtual std::unordered_map< std::string, std::string > get_auth_headers() const =0
virtual std::optional< std::string > start_session()
Definition rpc_context.h:17
virtual std::string get_remote_address() const =0
std::string get_remote_address() const override
Definition rpc_context.h:36
SimpleRpcContext(std::string server, std::string endpoint, std::unordered_map< std::string, std::string > headers={})
Definition rpc_context.h:33
void set_server(std::string server)
Definition rpc_context.h:30
std::optional< std::string > start_session() override
std::unordered_map< std::string, std::string > get_auth_headers() const override
Definition rpc_context.h:38
Definition daisytuner_rpc_context.h:10
std::shared_ptr< RpcContext > build_rpc_context_auto()
Definition rpc_context.h:73
std::shared_ptr< RpcContext > build_rpc_context_local()
Definition rpc_context.h:63
std::shared_ptr< RpcContext > build_rpc_context_from_file(std::filesystem::path config_file)
Definition rpc_context.h:68
std::string endpoint
Definition rpc_context.h:46
std::string server
Definition rpc_context.h:45
SimpleRpcContextBuilder & from_file(std::filesystem::path config_file)
SimpleRpcContextBuilder & from_header_env(std::string env_var="RPC_HEADER")
SimpleRpcContextBuilder & from_env(std::string env_var="SDFG_RPC_CONFIG")
std::shared_ptr< SimpleRpcContext > build(bool print=true) const
std::unordered_map< std::string, std::string > headers
Definition rpc_context.h:47
SimpleRpcContextBuilder & add_header(std::string name, std::string value)
SimpleRpcContextBuilder()
Definition rpc_context.h:49
SimpleRpcContextBuilder & from_docc_config()
SimpleRpcContextBuilder & initialize_local_default()