Faisal Amir daa7c0ca21
feat: better hardware setting (#4471)
* feat: better hardware setting

* chore: update layout

* feat: better hardware setting

* chore: fix title section

* chore: added hardware engine management

* chore: integrate gpus and enable set gpu activate

* chore: update calculate ram and vram

* chore: update calulate vram and ram used

* fix: set active gpus

* chore: fix progress bar spacing

* chore: always update cache vram gpu

* chore: update cpu usage percentage

* chore: fix type usage cpu

* chore: update ram cpus usage getsystemmonitor from new api harware engine management system

* test: update test case data using hardware management extension

* chore: resolve conflict lock json

* chore: cleanup app services

* chore: update type OperationSystemInfo

* chore: update app service

* chore: show list gpus on system monitor

* chore: remove monitoring extension

* chore: update test case app service

* chore: remove unused hooks useGpusSetting

* chore: remove monitor from shource index

* chore: fix test core

* chore: update gpu and cpu info on engine management ext

* chore: fix app service test

* chore: update test appService include cpu info

* chore: filter gpus show or hide on system monitor based activated gpu

* chore: remove unused run_mode

* chore: remove tensort

* chore: update check gpu run_mode

* chore: handle undefined gpus

* chore: cleanup PR

* chore: cleanup process node error

* chore: fix type
2025-02-03 22:01:08 +07:00

82 lines
2.0 KiB
TypeScript

import {
GpuSetting,
log,
} from '@janhq/core'
/**
* The GPU runMode that will be set - either 'vulkan', 'cuda', or empty for cpu.
* @param settings
* @returns
*/
const gpuRunMode = (settings?: GpuSetting): string => {
if (!settings) return ''
return settings.vulkan === true ||
settings.gpus?.some((gpu) => gpu.activated !== true)
? ''
: 'cuda'
}
/**
* The OS & architecture that the current process is running on.
* @returns win, mac-x64, mac-arm64, or linux
*/
const os = (settings?: GpuSetting): string => {
return PLATFORM === 'win32'
? 'windows-amd64'
: PLATFORM === 'darwin'
? settings?.cpu?.arch === 'arm64'
? 'mac-arm64'
: 'mac-amd64'
: 'linux-amd64'
}
/**
* The CUDA version that will be set - either '11-7' or '12-0'.
* @param settings
* @returns
*/
const cudaVersion = (settings?: GpuSetting): '12-0' | '11-7' | undefined => {
const isUsingCuda =
settings?.vulkan !== true &&
settings?.gpus?.some((gpu) => (gpu.activated === true ? 'gpu' : 'cpu')) &&
!os().includes('mac')
if (!isUsingCuda) return undefined
// return settings?.cuda?.version === '11' ? '11-7' : '12-0'
return settings.gpus?.some((gpu) => gpu.version.includes('12'))
? '12-0'
: '11-7'
}
/**
* The CPU instructions that will be set - either 'avx512', 'avx2', 'avx', or 'noavx'.
* @returns
*/
/**
* Find which variant to run based on the current platform.
*/
export const engineVariant = async (gpuSetting?: GpuSetting): Promise<string> => {
let engineVariant = [
os(gpuSetting),
gpuSetting?.vulkan
? 'vulkan'
: (gpuRunMode(gpuSetting) === 'cuda' && // GPU mode - packaged CUDA variants of avx2 and noavx
gpuSetting.cpu.instructions.some((inst) => inst === 'avx2')) ||
gpuSetting.cpu.instructions.some((inst) => inst === 'avx512')
? 'avx2'
: 'noavx',
gpuRunMode(gpuSetting),
cudaVersion(gpuSetting),
]
.filter((e) => !!e)
.join('-')
log(`[CORTEX]: Engine variant: ${engineVariant}`)
return engineVariant
}