Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use process build for GPU command #2632

Merged
merged 4 commits into from Sep 30, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -120,12 +120,25 @@ public String getGpuUsage() {
try {
// TODO : add a generic code to capture gpu details for different devices instead of
// just NVIDIA
process =
Runtime.getRuntime()
.exec(
"nvidia-smi -i "
+ gpuId
+ " --query-gpu=utilization.gpu,utilization.memory,memory.used --format=csv");
// Ensure gpuId is a valid number
int validatedGpuId;
try {
validatedGpuId = Integer.parseInt(gpuId);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid GPU ID");
}
msaroufim marked this conversation as resolved.
Show resolved Hide resolved

// Use an array to pass arguments
String[] cmd = {
"nvidia-smi",
"-i",
String.valueOf(validatedGpuId),
"--query-gpu=utilization.gpu,utilization.memory,memory.used",
"--format=csv"
};

Process process = Runtime.getRuntime().exec(cmd);
process.waitFor();
process.waitFor();
int exitCode = process.exitValue();
if (exitCode != 0) {
Expand Down