Skip to content

Commit

Permalink
Fix frontend crash when gpu data is missing (#53)
Browse files Browse the repository at this point in the history
* fix frontend crash when gpu data is missing

also remove hardcoded case for 2 gpus

* update test reference file

* comments
  • Loading branch information
conradtchan authored Sep 19, 2024
1 parent 3fe67d7 commit e1bd7df
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
2 changes: 1 addition & 1 deletion frontend/src/__tests__/reference_jobUsage.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion frontend/src/__tests__/reference_nodeUsage.json

Large diffs are not rendered by default.

15 changes: 4 additions & 11 deletions frontend/src/usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,20 @@ export function getNodeUsage(jid, job, node, host) {
}
}

// If thif is a GPU job
// If this is a GPU job
let gpuNumbers = [];
if (job.nGpus > 0) {
if (job.nGpus > 0 && node.gpus) {
// Zero if unknown
usage.gpu.total = 0;

// TODO: currently hardcoded to 2,
// but can make this general from the API
const nGpuMax = 2;

// If the GPU mapping is known
if (Object.prototype.hasOwnProperty.call(job.gpuLayout, host)) {
if (job.gpuLayout[host].length > 0) {
gpuNumbers = job.gpuLayout[host];
}
// If both GPUs are used in a 2 GPU job, then mapping doesn't matter
} else if (job.nGpus === nGpuMax) {
for (let j = 0; j < nGpuMax; j += 1) {
gpuNumbers.push(j);
}
}

// If the mapping is not known, then the usage will remain zero
for (let j = 0; j < gpuNumbers.length; j += 1) {
const iGpu = gpuNumbers[j];
usage.gpu.total += node.gpus["gpu".concat(iGpu.toString())];
Expand Down

0 comments on commit e1bd7df

Please sign in to comment.