Skip to content

Commit

Permalink
Fix CPU allocation when there are more GPUs than CPUs. #129, Don't re…
Browse files Browse the repository at this point in the history
…serve a CPU for each disabled GPUs.
  • Loading branch information
jcoffland committed Mar 9, 2023
1 parent d1b7cb7 commit ef88a00
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Folding@home Client Changelog
## v8.1.16
- Fix core download retry logic.
- Only add client executable directory to lib path on Windows.
- Retry WU if core crashes. #127
- Retry WU if core crashes. #127
- Fix CPU allocation when there are more GPUs than CPUs. #129
- Don't reserve a CPU for each disabled GPUs.

## v8.1.15
- Fix CUDA/OpenCL driver mixup from v8.1.14.
Expand Down
2 changes: 1 addition & 1 deletion src/fah/client/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ void App::updateResources() {
uint32_t cpus = min(config.getCPUs(), availableCPUs);

info->insert("cpus", cpus + remainingCPUs);
availableCPUs -= cpus;
availableCPUs -= min(availableCPUs, cpus);
if (cpus < config.getCPUs()) config.insert("cpus", cpus);

JSON::ValuePtr groupGPUs = new JSON::Dict;
Expand Down
14 changes: 4 additions & 10 deletions src/fah/client/Units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,22 +200,18 @@ void Units::update() {
if (unitGPUs.empty()) continue;

uint32_t minCPUs = unit.getMinCPUs();
bool runable = minCPUs <= remainingCPUs;
bool runable = minCPUs <= remainingCPUs || minCPUs < 2;

std::set<string> gpusWithWU = remainingGPUs;
for (auto id: unitGPUs) runable |= gpusWithWU.erase(id);

if (runable) {
remainingGPUs = gpusWithWU;
remainingCPUs -= minCPUs; // Initially allocate only minimum CPUs
remainingCPUs -= min(remainingCPUs, minCPUs); // Allocate minimum CPUs
enabledWUs.insert(i);
}
}

// Reserve one CPU for any unused GPUs
uint32_t reservedCPUs = min(remainingCPUs, (uint32_t)remainingGPUs.size());
remainingCPUs -= reservedCPUs;

// Allocate extra CPUs to enabled GPU WUs
for (unsigned i = 0; i < size(); i++) {
if (!enabledWUs.count(i)) continue; // GPU WUs that were enabled above
Expand All @@ -226,7 +222,8 @@ void Units::update() {
uint32_t cpus = min(maxCPUs, remainingCPUs + minCPUs);

unit.setCPUs(cpus);
remainingCPUs -= cpus - minCPUs; // Minimum CPUs subtracted above
// minCPUs was subtracted above or remainingCPUs is already zero
remainingCPUs -= min(remainingCPUs, cpus - minCPUs);
}

// Allocate remaining CPUs to existing CPU WUs
Expand All @@ -243,9 +240,6 @@ void Units::update() {
enabledWUs.insert(i);
}

// Restore reserved CPUs
remainingCPUs += reservedCPUs;

// Start and stop WUs
for (unsigned i = 0; i < size(); i++)
getUnit(i).setPause(getUnit(i).atRunState() && !enabledWUs.count(i));
Expand Down

0 comments on commit ef88a00

Please sign in to comment.