Skip to content

Commit

Permalink
fix: correct vulkan settings
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-menlo committed Feb 20, 2024
1 parent b52ce26 commit dcdebbd
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
16 changes: 10 additions & 6 deletions extensions/inference-nitro-extension/src/node/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { GPU_INFO_FILE } from './accelerator'
export interface NitroExecutableOptions {
executablePath: string
cudaVisibleDevices: string
vkVisibleDevices: string
}
/**
* Find which executable file to run based on the current platform.
Expand All @@ -13,6 +14,7 @@ export interface NitroExecutableOptions {
export const executableNitroFile = (): NitroExecutableOptions => {
let binaryFolder = path.join(__dirname, '..', 'bin') // Current directory by default
let cudaVisibleDevices = ''
let vkVisibleDevices = ''
let binaryName = 'nitro'
/**
* The binary folder is different for each platform.
Expand All @@ -25,17 +27,17 @@ export const executableNitroFile = (): NitroExecutableOptions => {
if (gpuInfo['run_mode'] === 'cpu') {
binaryFolder = path.join(binaryFolder, 'win-cpu')
} else {
if (gpuInfo['cuda'].version === '11') {
if (gpuInfo['cuda']?.version === '11') {
binaryFolder = path.join(binaryFolder, 'win-cuda-11-7')
} else {
binaryFolder = path.join(binaryFolder, 'win-cuda-12-0')
}
cudaVisibleDevices = gpuInfo['gpus_in_use'].join(',')
}
if (gpuInfo['vulkan'].enabled) {
if (gpuInfo['vulkan'] === true) {
binaryFolder = path.join(__dirname, '..', 'bin')
binaryFolder = path.join(binaryFolder, 'win-vulkan')
process.env.VULKAN_DEVICE_INDEX = gpuInfo['vulkan'].gpu_in_use.toString()
vkVisibleDevices = gpuInfo['gpus_in_use'].toString()
}
binaryName = 'nitro.exe'
} else if (process.platform === 'darwin') {
Expand All @@ -55,21 +57,23 @@ export const executableNitroFile = (): NitroExecutableOptions => {
if (gpuInfo['run_mode'] === 'cpu') {
binaryFolder = path.join(binaryFolder, 'linux-cpu')
} else {
if (gpuInfo['cuda'].version === '11') {
if (gpuInfo['cuda']?.version === '11') {
binaryFolder = path.join(binaryFolder, 'linux-cuda-11-7')
} else {
binaryFolder = path.join(binaryFolder, 'linux-cuda-12-0')
}
cudaVisibleDevices = gpuInfo['gpus_in_use'].join(',')
}
if (gpuInfo['vulkan'].enabled) {

if (gpuInfo['vulkan'] === true) {
binaryFolder = path.join(__dirname, '..', 'bin')
binaryFolder = path.join(binaryFolder, 'win-vulkan')
process.env.VULKAN_DEVICE_INDEX = gpuInfo['vulkan'].gpu_in_use.toString()
vkVisibleDevices = gpuInfo['gpus_in_use'].toString()
}
}
return {
executablePath: path.join(binaryFolder, binaryName),
cudaVisibleDevices,
vkVisibleDevices,
}
}
4 changes: 4 additions & 0 deletions extensions/inference-nitro-extension/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ function spawnNitroProcess(): Promise<any> {
env: {
...process.env,
CUDA_VISIBLE_DEVICES: executableOptions.cudaVisibleDevices,
// Vulkan - Support 1 device at a time for now
...(executableOptions.vkVisibleDevices?.length > 0 && {
GGML_VULKAN_DEVICE: executableOptions.vkVisibleDevices[0],
}),
},
}
)
Expand Down
2 changes: 1 addition & 1 deletion extensions/monitoring-extension/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const getCurrentLoad = () =>
}
if (data.run_mode === 'gpu' && data.gpus_in_use.length > 0) {
const gpuIds = data['gpus_in_use'].join(',')
if (gpuIds !== '') {
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) => {
Expand Down
3 changes: 3 additions & 0 deletions web/hooks/useSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,19 @@ export const useSettings = () => {
runMode,
notify,
gpusInUse,
vulkan,
}: {
runMode?: string | undefined
notify?: boolean | undefined
gpusInUse?: string[] | undefined
vulkan?: boolean | undefined
}) => {
const settingsFile = await joinPath(['file://settings', 'settings.json'])
const settings = await readSettings()
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
await fs.writeFileSync(settingsFile, JSON.stringify(settings))
}

Expand Down
16 changes: 11 additions & 5 deletions web/screens/Settings/Advanced/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const Advanced = () => {
const settings = await readSettings()
setGpuEnabled(settings.run_mode === 'gpu' && settings.gpus?.length > 0)
setGpusInUse(settings.gpus_in_use || [])
setVulkanEnabled(settings.vulkan || false)
if (settings.gpus) {
setGpuList(settings.gpus)
}
Expand Down Expand Up @@ -342,13 +343,18 @@ const Advanced = () => {
</div>
<p className="text-xs leading-relaxed">
Enable Vulkan with AMD GPU/APU and Intel Arc GPU for better model
performance. 0 - iGPU, n positive - eGPU
performance.
</p>
</div>
{vulkanEnabled && (
<Input value={vulkanEnabled ? 1 : 0} className="w-[60px] pr-8" />
)}
<Switch checked={vulkanEnabled} onCheckedChange={setVulkanEnabled} />

<Switch
checked={vulkanEnabled}
onCheckedChange={(e) => {
stopModel()
saveSettings({ vulkan: e, gpusInUse: [] })
setVulkanEnabled(e)
}}
/>
</div>
)}

Expand Down

0 comments on commit dcdebbd

Please sign in to comment.