diff --git a/extensions/inference-nitro-extension/src/node/accelerator.ts b/extensions/inference-nitro-extension/src/node/accelerator.ts index eb4bb7cbd4..235991bf2d 100644 --- a/extensions/inference-nitro-extension/src/node/accelerator.ts +++ b/extensions/inference-nitro-extension/src/node/accelerator.ts @@ -1,7 +1,7 @@ import { writeFileSync, existsSync, readFileSync } from 'fs' -import { exec } from 'child_process' +import { exec, spawn } from 'child_process' import path from 'path' -import { getJanDataFolderPath } from '@janhq/core/node' +import { getJanDataFolderPath, log } from '@janhq/core/node' /** * Default GPU settings @@ -164,42 +164,80 @@ export function updateCudaExistence( * Get GPU information */ export async function updateGpuInfo(): Promise { - exec( - 'nvidia-smi --query-gpu=index,memory.total,name --format=csv,noheader,nounits', - (error, stdout) => { - let data = JSON.parse(readFileSync(GPU_INFO_FILE, 'utf-8')) - - if (!error) { - // Get GPU info and gpu has higher memory first - let highestVram = 0 - let highestVramId = '0' - let gpus = stdout - .trim() - .split('\n') - .map((line) => { - let [id, vram, name] = line.split(', ') - vram = vram.replace(/\r/g, '') - if (parseFloat(vram) > highestVram) { - highestVram = parseFloat(vram) - highestVramId = id - } - return { id, vram, name } - }) - - data.gpus = gpus - data.gpu_highest_vram = highestVramId - } else { - data.gpus = [] - data.gpu_highest_vram = '' + let data = JSON.parse(readFileSync(GPU_INFO_FILE, 'utf-8')) + + // Cuda + if (data['vulkan'] === true) { + // Vulkan + exec( + process.platform === 'win32' + ? `${__dirname}\\..\\bin\\vulkaninfoSDK.exe --summary` + : '', + (error, stdout) => { + if (!error) { + const output = stdout.toString() + log(output) + + const gpuRegex = /GPU(\d+):(?:[\s\S]*?)deviceName\s*=\s*(.*)/g + + let gpus = [] + let match + while ((match = gpuRegex.exec(output)) !== null) { + const id = match[1] + const name = match[2] + console.log(`GPU${id}: ${name}`) + gpus.push({ id, vram: 0, name }) + } + console.log('done', gpus) + + data.gpus = gpus + + if (!data['gpus_in_use'] || data['gpus_in_use'].length === 0) { + data.gpus_in_use = [data.gpus.length > 1 ? '1' : '0'] + } + + data = updateCudaExistence(data) + writeFileSync(GPU_INFO_FILE, JSON.stringify(data, null, 2)) + } + Promise.resolve() } - - if (!data['gpus_in_use'] || data['gpus_in_use'].length === 0) { - data.gpus_in_use = [data['gpu_highest_vram']] + ) + } else { + exec( + 'nvidia-smi --query-gpu=index,memory.total,name --format=csv,noheader,nounits', + (error, stdout) => { + if (!error) { + // Get GPU info and gpu has higher memory first + let highestVram = 0 + let highestVramId = '0' + let gpus = stdout + .trim() + .split('\n') + .map((line) => { + let [id, vram, name] = line.split(', ') + vram = vram.replace(/\r/g, '') + if (parseFloat(vram) > highestVram) { + highestVram = parseFloat(vram) + highestVramId = id + } + return { id, vram, name } + }) + + data.gpus = gpus + data.gpu_highest_vram = highestVramId + } else { + data.gpus = [] + data.gpu_highest_vram = '' + } + + if (!data['gpus_in_use'] || data['gpus_in_use'].length === 0) { + data.gpus_in_use = [data['gpu_highest_vram']] + } + + data = updateCudaExistence(data) + writeFileSync(GPU_INFO_FILE, JSON.stringify(data, null, 2)) + Promise.resolve() } - - data = updateCudaExistence(data) - writeFileSync(GPU_INFO_FILE, JSON.stringify(data, null, 2)) - Promise.resolve() - } - ) + ) + } } diff --git a/extensions/monitoring-extension/src/module.ts b/extensions/monitoring-extension/src/module.ts index 061036f377..27781a5d6f 100644 --- a/extensions/monitoring-extension/src/module.ts +++ b/extensions/monitoring-extension/src/module.ts @@ -40,7 +40,7 @@ const getCurrentLoad = () => if (gpuIds !== '' && data['vulkan'] !== true) { exec( `nvidia-smi --query-gpu=index,name,temperature.gpu,utilization.gpu,memory.total,memory.free,utilization.memory --format=csv,noheader,nounits --id=${gpuIds}`, - (error, stdout, stderr) => { + (error, stdout, _) => { if (error) { console.error(`exec error: ${error}`) reject(error) diff --git a/web/hooks/useSettings.ts b/web/hooks/useSettings.ts index d3f8a7152b..9ff89827e8 100644 --- a/web/hooks/useSettings.ts +++ b/web/hooks/useSettings.ts @@ -60,8 +60,21 @@ export const useSettings = () => { if (runMode != null) settings.run_mode = runMode if (notify != null) settings.notify = notify if (gpusInUse != null) settings.gpus_in_use = gpusInUse - if (vulkan != null) settings.vulkan = vulkan + if (vulkan != null) { + settings.vulkan = vulkan + // GPU enabled, set run_mode to 'gpu' + if (settings.vulkan) { + settings.run_mode = 'gpu' + } else { + settings.run_mode = settings.gpus?.length > 0 ? 'gpu' : 'cpu' + } + } await fs.writeFileSync(settingsFile, JSON.stringify(settings)) + + // Relaunch to apply settings + if (vulkan != null) { + window.location.reload() + } } return { diff --git a/web/screens/Settings/Advanced/DataFolder/index.tsx b/web/screens/Settings/Advanced/DataFolder/index.tsx index f9c2f440aa..c11c49fa4c 100644 --- a/web/screens/Settings/Advanced/DataFolder/index.tsx +++ b/web/screens/Settings/Advanced/DataFolder/index.tsx @@ -83,10 +83,7 @@ const DataFolder = () => { await window.core?.api?.getAppConfigurations() const currentJanDataFolder = appConfiguration.data_folder appConfiguration.data_folder = destinationPath - const { _, err } = await fs.syncFile( - currentJanDataFolder, - destinationPath - ) + const { err } = await fs.syncFile(currentJanDataFolder, destinationPath) if (err) throw err await window.core?.api?.updateAppConfiguration(appConfiguration) console.debug( diff --git a/web/screens/Settings/Advanced/index.tsx b/web/screens/Settings/Advanced/index.tsx index ca284e04d0..3361ceb9fa 100644 --- a/web/screens/Settings/Advanced/index.tsx +++ b/web/screens/Settings/Advanced/index.tsx @@ -99,7 +99,7 @@ const Advanced = () => { } } setUseGpuIfPossible() - }, [readSettings]) + }, [readSettings, setGpuList, setGpuEnabled, setGpusInUse, setVulkanEnabled]) const clearLogs = async () => { if (await fs.existsSync(`file://logs`)) { @@ -172,11 +172,11 @@ const Advanced = () => {
- NVIDIA GPU Acceleration + GPU Acceleration

- Enable to enhance model performance by utilizing your NVIDIA GPU + Enable to enhance model performance by utilizing your GPU devices for acceleration. Read{' '} {' '} @@ -217,7 +217,7 @@ const Advanced = () => { { if (e === true) { @@ -279,12 +279,16 @@ const Advanced = () => { - Nvidia + + {vulkanEnabled ? 'Vulkan Supported GPUs' : 'Nvidia'} +

{gpuList .filter((gpu) => - gpu.name?.toLowerCase().includes('nvidia') + vulkanEnabled + ? gpu.name + : gpu.name?.toLowerCase().includes('nvidia') ) .map((gpu) => (
{ htmlFor={`gpu-${gpu.id}`} > {gpu.name} - {gpu.vram}MB VRAM + {!vulkanEnabled && ( + {gpu.vram}MB VRAM + )}
))} @@ -334,16 +340,17 @@ const Advanced = () => { )} {/* Vulkan for AMD GPU/ APU and Intel Arc GPU */} - {/* TODO: This needs to be set based on user toggle in settings for enabled BOOLEAN and index as INT */} - {!isMac && ( + {!isMac && experimentalFeature && (
-
Vulkan GPU
+
+ Vulkan Support +

Enable Vulkan with AMD GPU/APU and Intel Arc GPU for better model - performance. + performance (relaunch needed).