/** * Device Detection Engine * * Detects the best available compute device at runtime. * Enables automatic performance optimization without user configuration. * * Device Priority by Environment: * * **Browser Environment:** * - WebGPU > CPU (WASM) * * **Node.js Environment:** * - Windows: DirectML (dml) > CPU * - macOS: CPU only (CoreML not available in Node.js) * - Linux: CPU only (CUDA not available in standard onnxruntime-node) * * GPU Support Notes: * - WebGPU: Only available in browsers, not in Node.js * - DirectML: Windows GPU acceleration via onnxruntime-node * - CUDA: Requires separate onnxruntime-node-cuda package (not included) * - CoreML: Not available for Node.js bindings * * @example * ```typescript * const deviceInfo = await detectBestDevice(); * console.log(deviceInfo.device); // 'webgpu', 'dml', or 'cpu' * console.log(deviceInfo.gpuName); // 'DirectML GPU' (if available) * ``` */ /** * Available compute devices for embedding generation. * * - 'webgpu': WebGPU acceleration (browser only) * - 'dml': DirectML acceleration (Windows Node.js only) * - 'cpu': CPU computation (always available) */ export type ComputeDevice = 'webgpu' | 'dml' | 'cpu'; /** * Information about the detected compute device */ export interface DeviceInfo { /** The selected compute device */ device: ComputeDevice; /** GPU name/model if WebGPU is available */ gpuName?: string; /** GPU vendor if WebGPU is available */ gpuVendor?: string; /** Reason for falling back to CPU (if device is 'cpu') */ fallbackReason?: string; /** Time taken to detect the device in milliseconds */ detectionTimeMs?: number; } /** * Fallback reasons as constants for consistency */ export declare const FALLBACK_REASONS: { readonly NO_WEBGPU_API: "WebGPU API not available in this environment"; readonly NO_ADAPTER: "No GPU adapter found"; readonly ADAPTER_REQUEST_FAILED: "GPU adapter request failed"; readonly DETECTION_TIMEOUT: "Device detection timed out"; readonly NODE_NOT_WINDOWS: "DirectML only available on Windows"; readonly NODE_DML_DISABLED: "DirectML disabled by configuration"; readonly DML_INIT_FAILED: "DirectML initialization failed"; }; /** * Maximum time allowed for device detection (ms) */ export declare const DETECTION_TIMEOUT_MS = 5000; /** * Check if running in a browser environment. * * @returns True if running in a browser */ export declare function isBrowserEnvironment(): boolean; /** * Check if running in Node.js environment. * * @returns True if running in Node.js */ export declare function isNodeEnvironment(): boolean; /** * Check if running on Windows. * * @returns True if running on Windows */ export declare function isWindows(): boolean; /** * Check if running on macOS. * * @returns True if running on macOS */ export declare function isMacOS(): boolean; /** * Check if running on Linux. * * @returns True if running on Linux */ export declare function isLinux(): boolean; /** * Check if DirectML is available. * DirectML is available on Windows via onnxruntime-node. * * @returns True if DirectML is available */ export declare function isDirectMLAvailable(): boolean; /** * Check if WebGPU API is available in the current environment. * * WebGPU is available in: * - Modern browsers (Chrome 113+, Edge 113+, Firefox behind flag) * - Node.js with native WebGPU bindings (experimental) * * @returns True if navigator.gpu exists */ export declare function isWebGPUAPIAvailable(): boolean; /** * Detect the best available compute device. * * This function checks for GPU availability based on the runtime environment: * * **Browser Environment:** * - Checks for WebGPU API and requests GPU adapter * - Falls back to CPU (WASM) if WebGPU not available * * **Node.js Environment:** * - Windows: Uses DirectML for GPU acceleration * - macOS/Linux: Falls back to CPU (no GPU support in standard onnxruntime-node) * * Results are cached for the session to avoid repeated GPU queries. * * @param forceRefresh - If true, ignore cached result and re-detect * @returns Device information including device type, GPU name (if available), and fallback reason (if CPU) * * @example * ```typescript * const deviceInfo = await detectBestDevice(); * if (deviceInfo.device === 'webgpu' || deviceInfo.device === 'dml') { * console.log(`Using GPU: ${deviceInfo.gpuName}`); * } else { * console.log(`Using CPU: ${deviceInfo.fallbackReason}`); * } * ``` */ export declare function detectBestDevice(forceRefresh?: boolean): Promise; /** * Get the currently cached device info without triggering detection. * * @returns Cached device info or null if not yet detected */ export declare function getCachedDeviceInfo(): DeviceInfo | null; /** * Clear the cached device info. * Mainly used for testing purposes. */ export declare function clearDeviceCache(): void; /** * Format device info for display in logs or status messages. * * @param deviceInfo - The device info to format * @returns Human-readable string describing the compute device * * @example * ```typescript * const deviceInfo = await detectBestDevice(); * console.log(formatDeviceInfo(deviceInfo)); * // "WebGPU (NVIDIA GeForce RTX 3080)" * // or "DirectML (DirectML GPU)" * // or "CPU: WebGPU API not available" * ``` */ export declare function formatDeviceInfo(deviceInfo: DeviceInfo): string; /** * Check if the current device supports WebGPU acceleration. * This is a convenience wrapper around detectBestDevice(). * * @returns True if WebGPU is available */ export declare function supportsWebGPU(): Promise; /** * Check if the current device supports DirectML acceleration. * This is a convenience wrapper around detectBestDevice(). * * @returns True if DirectML is available */ export declare function supportsDirectML(): Promise; /** * Check if any GPU acceleration is available. * Returns true for either WebGPU (browser) or DirectML (Windows Node.js). * * @returns True if GPU acceleration is available */ export declare function supportsGPU(): Promise; //# sourceMappingURL=deviceDetection.d.ts.map