Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
profile_registry.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
11
12#include <algorithm>
13#include <thread>
14
15namespace entropic {
16
17namespace {
18auto logger = entropic::log::get("inference.profile_registry");
19} // anonymous namespace
20
32 std::lock_guard<std::mutex> lock(mutex_);
33 profiles_.clear();
34
35 unsigned int hw_threads = std::thread::hardware_concurrency();
36 int bg_threads = (hw_threads > 0)
37 ? std::max(1u, hw_threads / 2)
38 : 2;
39
40 profiles_["maximum"] = GPUResourceProfile{
41 "maximum", 2048, 0, 0,
42 "Foreground generation, latency-sensitive"};
43
44 profiles_["balanced"] = GPUResourceProfile{
45 "balanced", 512, 0, 0,
46 "Default. Good throughput without monopolizing"};
47
48 profiles_["background"] = GPUResourceProfile{
49 "background", 256, bg_threads, bg_threads,
50 "Background tasks (compaction, scribe)"};
51
52 profiles_["minimal"] = GPUResourceProfile{
53 "minimal", 64, 2, 2,
54 "Lowest resource usage (background NPCs, idle)"};
55
56 logger->info("Loaded 4 bundled GPU resource profiles "
57 "(background n_threads={})", bg_threads);
58}
59
68 std::lock_guard<std::mutex> lock(mutex_);
69 if (profiles_.count(profile.name) > 0) {
70 logger->warn("Profile '{}' already registered", profile.name);
71 return false;
72 }
73
74 profiles_[profile.name] = profile;
75 logger->info("Registered profile '{}' (n_batch={}, n_threads={})",
76 profile.name, profile.n_batch, profile.n_threads);
77 return true;
78}
79
87bool ProfileRegistry::deregister(const std::string& name) {
88 std::lock_guard<std::mutex> lock(mutex_);
89 auto it = profiles_.find(name);
90 if (it == profiles_.end()) {
91 return false;
92 }
93 profiles_.erase(it);
94 logger->info("Deregistered profile '{}'", name);
95 return true;
96}
97
105GPUResourceProfile ProfileRegistry::get(const std::string& name) const {
106 std::lock_guard<std::mutex> lock(mutex_);
107 auto it = profiles_.find(name);
108 if (it != profiles_.end()) {
109 return it->second;
110 }
111
112 logger->warn("Profile '{}' not found, falling back to 'balanced'", name);
113 auto fallback = profiles_.find("balanced");
114 if (fallback != profiles_.end()) {
115 return fallback->second;
116 }
117
118 logger->error("Fallback profile 'balanced' also missing");
119 return GPUResourceProfile{};
120}
121
129bool ProfileRegistry::has(const std::string& name) const {
130 std::lock_guard<std::mutex> lock(mutex_);
131 return profiles_.count(name) > 0;
132}
133
140std::vector<std::string> ProfileRegistry::list() const {
141 std::lock_guard<std::mutex> lock(mutex_);
142 std::vector<std::string> names;
143 names.reserve(profiles_.size());
144 for (const auto& [k, _] : profiles_) {
145 names.push_back(k);
146 }
147 std::sort(names.begin(), names.end());
148 return names;
149}
150
157size_t ProfileRegistry::size() const {
158 std::lock_guard<std::mutex> lock(mutex_);
159 return profiles_.size();
160}
161
162} // namespace entropic
bool register_profile(const GPUResourceProfile &profile)
Register a custom profile.
GPUResourceProfile get(const std::string &name) const
Get a profile by name.
size_t size() const
Number of registered profiles.
bool has(const std::string &name) const
Check if a profile name exists.
std::vector< std::string > list() const
List all registered profile names.
void load_bundled()
Initialize with bundled profiles (maximum, balanced, background, minimal).
bool deregister(const std::string &name)
Remove a profile by name.
spdlog initialization and logger access.
ENTROPIC_EXPORT std::shared_ptr< spdlog::logger > get(const std::string &name)
Get or create a named logger.
Definition logging.cpp:211
Activate model on GPU (WARM → ACTIVE).
ProfileRegistry – named GPU resource profile management.
Named GPU resource profile for controlling inference hardware knobs.
Definition config.h:215
int n_batch
Batch size for prompt processing (1-2048)
Definition config.h:217
std::string name
Profile name ("maximum", "balanced", "background", "minimal")
Definition config.h:216
int n_threads
CPU threads for generation (0 = auto-detect)
Definition config.h:218