2026-01-30 03:16:57 +00:00
/**
* Intel Driver Management
*
* Handles Intel Arc GPU driver detection, installation, and oneAPI setup.
*/
import type { IDriverStatus } from '../interfaces/gpu.ts' ;
import { logger } from '../logger.ts' ;
import { BaseDriver , type IDriverInstallOptions } from './base-driver.ts' ;
/**
* Intel Arc/oneAPI Driver Manager
*/
export class IntelDriver extends BaseDriver {
public readonly vendor = 'intel' as const ;
public readonly displayName = 'Intel Arc' ;
/**
* Check if Intel GPU driver is installed
*/
public async isInstalled ( ) : Promise < boolean > {
try {
// Check for xpu-smi or intel_gpu_top
const { stdout } = await this . execCommand (
'xpu-smi discovery 2>/dev/null || intel_gpu_top -l 2>/dev/null || ls /dev/dri/renderD* 2>/dev/null | grep -c renderD' ,
{ timeout : 5000 , ignoreErrors : true } ,
) ;
return stdout . trim ( ) . length > 0 && ! stdout . includes ( 'not found' ) ;
} catch {
return false ;
}
}
/**
* Get Intel GPU driver status
*/
public async getStatus ( ) : Promise < IDriverStatus > {
const status : IDriverStatus = {
vendor : 'intel' ,
installed : false ,
containerSupport : false ,
issues : [ ] ,
} ;
// Check for i915 driver (Intel integrated/Arc)
try {
const { stdout : driverInfo } = await this . execCommand (
'modinfo i915 2>/dev/null | grep "^version:"' ,
{ timeout : 5000 , ignoreErrors : true } ,
) ;
if ( driverInfo . includes ( 'version' ) ) {
status . installed = true ;
const match = driverInfo . match ( /version:\s*(\S+)/i ) ;
if ( match ) {
status . version = match [ 1 ] ;
}
}
} catch {
// i915 module info not available
}
// Check for xpu-smi (Intel Arc specific)
try {
const { stdout : xpuVersion } = await this . execCommand (
'xpu-smi --version 2>/dev/null' ,
{ timeout : 5000 , ignoreErrors : true } ,
) ;
if ( xpuVersion . includes ( 'xpu-smi' ) ) {
status . installed = true ;
const match = xpuVersion . match ( /(\d+\.\d+(?:\.\d+)?)/ ) ;
if ( match ) {
status . version = match [ 1 ] ;
}
}
} catch {
// xpu-smi not available
}
// Check oneAPI toolkit
try {
const { stdout : oneApiVersion } = await this . execCommand (
'ls /opt/intel/oneapi/compiler/*/env/vars.sh 2>/dev/null | head -1 | xargs dirname | xargs dirname | xargs basename' ,
{ timeout : 5000 , ignoreErrors : true } ,
) ;
if ( oneApiVersion . trim ( ) ) {
status . toolkitVersion = oneApiVersion . trim ( ) ;
}
} catch {
// oneAPI not installed
}
// Check container support
try {
const { stdout : renderDevices } = await this . execCommand (
'ls /dev/dri/renderD* 2>/dev/null' ,
{ timeout : 5000 , ignoreErrors : true } ,
) ;
if ( renderDevices . includes ( 'renderD' ) ) {
status . containerSupport = true ;
} else {
status . issues . push ( 'Intel GPU render devices not available' ) ;
}
} catch {
status . issues . push ( 'Could not check Intel GPU device availability' ) ;
}
if ( ! status . installed ) {
status . issues . push ( 'Intel GPU driver not detected' ) ;
}
return status ;
}
/**
* Install Intel GPU drivers and optionally oneAPI
*/
public async install ( options : IDriverInstallOptions ) : Promise < boolean > {
if ( ! await this . isRoot ( ) ) {
logger . error ( 'Root privileges required to install Intel GPU drivers' ) ;
return false ;
}
const distro = await this . getLinuxDistro ( ) ;
logger . info ( ` Detected Linux distribution: ${ distro . id } ${ distro . version } ` ) ;
try {
if ( distro . id === 'ubuntu' ) {
return await this . installOnUbuntu ( options ) ;
} else if ( distro . id === 'fedora' ) {
return await this . installOnFedora ( options ) ;
} else {
logger . error ( ` Unsupported distribution for Intel Arc: ${ distro . id } ` ) ;
logger . info ( 'Please install Intel drivers manually from https://dgpu-docs.intel.com/' ) ;
return false ;
}
} catch ( error ) {
2026-04-20 23:00:50 +00:00
logger . error (
` Failed to install Intel drivers: ${
error instanceof Error ? error.message : String ( error )
} ` ,
) ;
2026-01-30 03:16:57 +00:00
return false ;
}
}
/**
* Install on Ubuntu
*/
private async installOnUbuntu ( options : IDriverInstallOptions ) : Promise < boolean > {
logger . info ( 'Installing Intel GPU drivers on Ubuntu...' ) ;
// Install prerequisites
await this . aptUpdate ( ) ;
await this . aptInstall ( [ 'wget' , 'gpg' ] ) ;
// Add Intel graphics repository
await this . execCommand (
'wget -qO - https://repositories.intel.com/graphics/intel-graphics.key | gpg --dearmor --output /usr/share/keyrings/intel-graphics.gpg' ,
) ;
const distro = await this . getLinuxDistro ( ) ;
2026-04-20 23:00:50 +00:00
const ubuntuCodename = distro . version === '22.04'
? 'jammy'
: distro . version === '24.04'
? 'noble'
: 'jammy' ;
2026-01-30 03:16:57 +00:00
await this . execCommand (
` echo "deb [arch=amd64 signed-by=/usr/share/keyrings/intel-graphics.gpg] https://repositories.intel.com/graphics/ubuntu ${ ubuntuCodename } arc" > /etc/apt/sources.list.d/intel-graphics.list ` ,
) ;
await this . aptUpdate ( ) ;
// Install Intel GPU packages
await this . aptInstall ( [
'intel-opencl-icd' ,
'intel-level-zero-gpu' ,
'level-zero' ,
'intel-media-va-driver-non-free' ,
'libmfx1' ,
'libmfxgen1' ,
'libvpl2' ,
'libegl-mesa0' ,
'libegl1-mesa' ,
'libegl1-mesa-dev' ,
'libgbm1' ,
'libgl1-mesa-dev' ,
'libgl1-mesa-dri' ,
'libglapi-mesa' ,
'libgles2-mesa-dev' ,
'libglx-mesa0' ,
'libigdgmm12' ,
'libxatracker2' ,
'mesa-va-drivers' ,
'mesa-vdpau-drivers' ,
'mesa-vulkan-drivers' ,
'va-driver-all' ,
] ) ;
// Install xpu-smi for monitoring
await this . aptInstall ( 'xpu-smi' ) ;
// Install oneAPI toolkit if requested
if ( options . installToolkit ) {
await this . installOneApi ( ) ;
}
// Add user to video and render groups
await this . execCommand ( 'usermod -a -G video,render $SUDO_USER || true' ) ;
// Install container support if requested
if ( options . installContainerSupport ) {
await this . installContainerSupport ( ) ;
}
logger . success ( 'Intel GPU driver installation completed' ) ;
logger . info ( 'Verify installation with: xpu-smi discovery' ) ;
return true ;
}
/**
* Install on Fedora
*/
private async installOnFedora ( options : IDriverInstallOptions ) : Promise < boolean > {
logger . info ( 'Installing Intel GPU drivers on Fedora...' ) ;
// Intel GPU support is included in newer Fedora kernels
// We just need to install the user-space components
await this . dnfInstall ( [
'intel-media-driver' ,
'libva-intel-driver' ,
'intel-compute-runtime' ,
'level-zero' ,
'oneapi-level-zero' ,
] ) ;
// Try to install xpu-smi from Intel repo
try {
await this . execCommand (
'dnf copr enable -y intel/oneapi || true' ,
) ;
await this . dnfInstall ( 'xpu-smi' ) ;
} catch {
logger . warn ( 'Could not install xpu-smi. Intel Arc monitoring may be limited.' ) ;
}
// Add user to video and render groups
await this . execCommand ( 'usermod -a -G video,render $SUDO_USER || true' ) ;
// Install oneAPI if requested
if ( options . installToolkit ) {
await this . installOneApi ( ) ;
}
// Install container support if requested
if ( options . installContainerSupport ) {
await this . installContainerSupport ( ) ;
}
logger . success ( 'Intel GPU driver installation completed' ) ;
return true ;
}
/**
* Install Intel oneAPI toolkit
*/
private async installOneApi ( ) : Promise < void > {
logger . info ( 'Installing Intel oneAPI toolkit...' ) ;
const distro = await this . getLinuxDistro ( ) ;
if ( distro . id === 'ubuntu' || distro . id === 'debian' ) {
// Add Intel oneAPI repository
await this . execCommand (
'wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB | gpg --dearmor | tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null' ,
) ;
await this . execCommand (
'echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | tee /etc/apt/sources.list.d/oneAPI.list' ,
) ;
await this . aptUpdate ( ) ;
await this . aptInstall ( 'intel-basekit' ) ;
} else if ( distro . id === 'fedora' ) {
// Add Intel oneAPI repository
await this . execCommand (
` cat <<EOF > /etc/yum.repos.d/oneAPI.repo
[oneAPI]
name=Intel oneAPI repository
baseurl=https://yum.repos.intel.com/oneapi
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://yum.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
EOF ` ,
) ;
await this . dnfInstall ( 'intel-basekit' ) ;
}
logger . success ( 'Intel oneAPI toolkit installed' ) ;
logger . info ( 'Source the environment with: source /opt/intel/oneapi/setvars.sh' ) ;
}
/**
* Install container support for Intel GPUs
*/
public async installContainerSupport ( ) : Promise < boolean > {
logger . info ( 'Configuring Docker for Intel GPUs...' ) ;
try {
// Intel GPUs work by passing through device files
// Verify render devices exist
2026-04-20 23:00:50 +00:00
const { stdout : devices } = await this . execCommand (
'ls -la /dev/dri/renderD* 2>/dev/null || true' ,
) ;
2026-01-30 03:16:57 +00:00
if ( ! devices . includes ( 'renderD' ) ) {
logger . warn ( '/dev/dri/renderD* not found. Intel GPU driver may not be properly loaded.' ) ;
return false ;
}
// Set permissions
await this . execCommand ( 'chmod 666 /dev/dri/renderD* || true' ) ;
logger . success ( 'Intel GPU container support configured' ) ;
logger . info ( 'Use the following Docker flags for Intel GPU containers:' ) ;
logger . info ( ' --device=/dev/dri --group-add render' ) ;
return true ;
} catch ( error ) {
2026-04-20 23:00:50 +00:00
logger . error (
` Failed to configure Intel container support: ${
error instanceof Error ? error.message : String ( error )
} ` ,
) ;
2026-01-30 03:16:57 +00:00
return false ;
}
}
/**
* Get available driver versions
*/
public async getAvailableVersions ( ) : Promise < string [ ] > {
// Intel Arc drivers are typically tied to kernel versions
// Return oneAPI versions as reference
return [ '2024.0' , '2023.2' , '2023.1' , '2023.0' ] ;
}
}