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

feat: User Selectable GPUs and GPU-based Model Recommendations #1730

Merged
merged 9 commits into from
Feb 6, 2024
Next Next commit
Add a field to settings.json to help manage selected GPUs
  • Loading branch information
hientominh authored and hiro-v committed Feb 5, 2024
commit f07f5e5b56016f2cb3094de6910019ce747d5deb
12 changes: 6 additions & 6 deletions extensions/inference-nitro-extension/src/node/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 26,11 @@ export const executableNitroFile = (): NitroExecutableOptions => {
binaryFolder = path.join(binaryFolder, "win-cpu");
} else {
if (nvidiaInfo["cuda"].version === "12") {
binaryFolder = path.join(binaryFolder, "win-cuda-12-0");
} else {
binaryFolder = path.join(binaryFolder, "win-cuda-11-7");
} else {
binaryFolder = path.join(binaryFolder, "win-cuda-12-0");
}
cudaVisibleDevices = nvidiaInfo["gpu_highest_vram"];
cudaVisibleDevices = nvidiaInfo["gpus_in_use"];
}
binaryName = "nitro.exe";
} else if (process.platform === "darwin") {
Expand All @@ -51,11 51,11 @@ export const executableNitroFile = (): NitroExecutableOptions => {
binaryFolder = path.join(binaryFolder, "linux-cpu");
} else {
if (nvidiaInfo["cuda"].version === "12") {
binaryFolder = path.join(binaryFolder, "linux-cuda-12-0");
} else {
binaryFolder = path.join(binaryFolder, "linux-cuda-11-7");
} else {
binaryFolder = path.join(binaryFolder, "linux-cuda-12-0");
}
cudaVisibleDevices = nvidiaInfo["gpu_highest_vram"];
cudaVisibleDevices = nvidiaInfo["gpus_in_use"];
}
}
return {
Expand Down
57 changes: 27 additions & 30 deletions extensions/inference-nitro-extension/src/node/nvidia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 19,8 @@ const DEFALT_SETTINGS = {
},
gpus: [],
gpu_highest_vram: "",
gpus_in_use: "",
is_initial: true,
};

/**
Expand Down Expand Up @@ -48,11 50,15 @@ export interface NitroProcessInfo {
*/
export async function updateNvidiaInfo() {
if (process.platform !== "darwin") {
await Promise.all([
updateNvidiaDriverInfo(),
updateCudaExistence(),
updateGpuInfo(),
]);
let data;
try {
data = JSON.parse(readFileSync(NVIDIA_INFO_FILE, "utf-8"));
} catch (error) {
data = DEFALT_SETTINGS;
writeFileSync(NVIDIA_INFO_FILE, JSON.stringify(data, null, 2));
}
updateNvidiaDriverInfo();
updateGpuInfo();
}
}

Expand All @@ -73,12 79,7 @@ export async function updateNvidiaDriverInfo(): Promise<void> {
exec(
"nvidia-smi --query-gpu=driver_version --format=csv,noheader",
(error, stdout) => {
let data;
try {
data = JSON.parse(readFileSync(NVIDIA_INFO_FILE, "utf-8"));
} catch (error) {
data = DEFALT_SETTINGS;
}
let data = JSON.parse(readFileSync(NVIDIA_INFO_FILE, "utf-8"));

if (!error) {
const firstLine = stdout.split("\n")[0].trim();
Expand Down Expand Up @@ -107,7 108,7 @@ export function checkFileExistenceInPaths(
/**
* Validate cuda for linux and windows
*/
export function updateCudaExistence() {
export function updateCudaExistence(data: Record<string, any> = DEFALT_SETTINGS): Record<string, any> {
let filesCuda12: string[];
let filesCuda11: string[];
let paths: string[];
Expand Down Expand Up @@ -141,19 142,14 @@ export function updateCudaExistence() {
cudaVersion = "12";
}

let data;
try {
data = JSON.parse(readFileSync(NVIDIA_INFO_FILE, "utf-8"));
} catch (error) {
data = DEFALT_SETTINGS;
}

data["cuda"].exist = cudaExists;
data["cuda"].version = cudaVersion;
if (cudaExists) {
console.log(data["is_initial"], data["gpus_in_use"]);
if (cudaExists && data["is_initial"] && data["gpus_in_use"] !== "") {
data.run_mode = "gpu";
}
writeFileSync(NVIDIA_INFO_FILE, JSON.stringify(data, null, 2));
data.is_initial = false;
return data;
}

/**
Expand All @@ -163,12 159,7 @@ export async function updateGpuInfo(): Promise<void> {
exec(
"nvidia-smi --query-gpu=index,memory.total --format=csv,noheader,nounits",
(error, stdout) => {
let data;
try {
data = JSON.parse(readFileSync(NVIDIA_INFO_FILE, "utf-8"));
} catch (error) {
data = DEFALT_SETTINGS;
}
let data = JSON.parse(readFileSync(NVIDIA_INFO_FILE, "utf-8"));

if (!error) {
// Get GPU info and gpu has higher memory first
Expand All @@ -187,12 178,18 @@ export async function updateGpuInfo(): Promise<void> {
return { id, vram };
});

data["gpus"] = gpus;
data["gpu_highest_vram"] = highestVramId;
data.gpus = gpus;
data.gpu_highest_vram = highestVramId;
} else {
data["gpus"] = [];
data.gpus = [];
data.gpu_highest_vram = "";
}

if (!data["gpus_in_use"] || data["gpus_in_use"] === "") {
data.gpus_in_use = data["gpu_highest_vram"];
}

data = updateCudaExistence(data);
writeFileSync(NVIDIA_INFO_FILE, JSON.stringify(data, null, 2));
Promise.resolve();
}
Expand Down