From c42b8ecda207062dc11ea294df37de21374ed4e7 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Thu, 12 Sep 2024 10:49:18 -0700 Subject: [PATCH] openvino/lxc: fix crashing --- plugins/core/package-lock.json | 4 +- plugins/core/package.json | 2 +- plugins/core/src/platform/lxc.ts | 74 ++++++++++++++++----------- plugins/openvino/package-lock.json | 4 +- plugins/openvino/package.json | 2 +- plugins/openvino/src/ov/__init__.py | 6 +-- plugins/openvino/src/requirements.txt | 5 +- 7 files changed, 56 insertions(+), 41 deletions(-) diff --git a/plugins/core/package-lock.json b/plugins/core/package-lock.json index 190f14f33..a2aed7ddc 100644 --- a/plugins/core/package-lock.json +++ b/plugins/core/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/core", - "version": "0.3.70", + "version": "0.3.71", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/core", - "version": "0.3.70", + "version": "0.3.71", "license": "Apache-2.0", "dependencies": { "@scrypted/common": "file:../../common", diff --git a/plugins/core/package.json b/plugins/core/package.json index 9009ddbec..b1c22601b 100644 --- a/plugins/core/package.json +++ b/plugins/core/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/core", - "version": "0.3.70", + "version": "0.3.71", "description": "Scrypted Core plugin. Provides the UI, websocket, and engine.io APIs.", "author": "Scrypted", "license": "Apache-2.0", diff --git a/plugins/core/src/platform/lxc.ts b/plugins/core/src/platform/lxc.ts index 2a96153a1..8cfc03559 100644 --- a/plugins/core/src/platform/lxc.ts +++ b/plugins/core/src/platform/lxc.ts @@ -1,8 +1,8 @@ -import fs from 'fs'; +import sdk from '@scrypted/sdk'; import child_process from 'child_process'; import { once } from 'events'; -import sdk from '@scrypted/sdk'; -import { stdout } from 'process'; +import fs from 'fs'; +import os from 'os'; export const SCRYPTED_INSTALL_ENVIRONMENT_LXC = 'lxc'; @@ -42,12 +42,52 @@ export async function checkLxcDependencies() { sdk.log.a('Failed to daemon-reload systemd.'); } + try { + const output = await new Promise((r, f) => child_process.exec("sh -c 'apt show versions level-zero'", (err, stdout, stderr) => { + if (err && !stdout && !stderr) + f(err); + else + r(stdout + '\n' + stderr); + })); + + const cpuModel = os.cpus()[0].model; + if (cpuModel.includes('Core') && cpuModel.includes('Ultra')) { + if ( + // apt + output.includes('No packages found') + ) { + const cp = child_process.spawn('sh', ['-c', 'curl https://raw.githubusercontent.com/koush/scrypted/main/install/docker/install-intel-npu.sh | bash']); + const [exitCode] = await once(cp, 'exit'); + if (exitCode !== 0) + sdk.log.a('Failed to install intel-driver-compiler-npu.'); + else + needRestart = true; + } + } + else { + // level-zero crashes openvino on older CPU due to illegal instruction. + // so ensure it is not installed if this is not a core ultra system with npu. + if ( + // apt + !output.includes('No packages found') + ) { + const cp = child_process.spawn('apt', ['-y', 'remove', 'level-zero']); + const [exitCode] = await once(cp, 'exit'); + console.log('level-zero removed', exitCode); + } + } + + } + catch (e) { + sdk.log.a('Failed to verify/install intel-driver-compiler-npu.'); + } + try { // intel opencl icd is broken from their official apt repos on kernel versions 6.8, which ships with ubuntu 24.04 and proxmox 8.2. // the intel apt repo has not been updated yet. // the current workaround is to install the release manually. // https://github.com/intel/compute-runtime/releases/tag/24.13.29138.7 - const output = await new Promise((r,f)=> child_process.exec("sh -c 'apt show versions intel-opencl-icd'", (err, stdout, stderr) => { + const output = await new Promise((r, f) => child_process.exec("sh -c 'apt show versions intel-opencl-icd'", (err, stdout, stderr) => { if (err && !stdout && !stderr) f(err); else @@ -60,7 +100,7 @@ export async function checkLxcDependencies() { // was installed via script at some point || output.includes('Version: 24.13.29138.7') // current script version: 24.17.29377.6 - ) { + ) { const cp = child_process.spawn('sh', ['-c', 'curl https://raw.githubusercontent.com/koush/scrypted/main/install/docker/install-intel-graphics.sh | bash']); const [exitCode] = await once(cp, 'exit'); if (exitCode !== 0) @@ -73,30 +113,6 @@ export async function checkLxcDependencies() { sdk.log.a('Failed to verify/install intel-opencl-icd version.'); } - try { - const output = await new Promise((r,f)=> child_process.exec("sh -c 'apt show versions intel-driver-compiler-npu'", (err, stdout, stderr) => { - if (err && !stdout && !stderr) - f(err); - else - r(stdout + '\n' + stderr); - })); - - if ( - // apt - output.includes('No packages found') - ) { - const cp = child_process.spawn('sh', ['-c', 'curl https://raw.githubusercontent.com/koush/scrypted/main/install/docker/install-intel-npu.sh | bash']); - const [exitCode] = await once(cp, 'exit'); - if (exitCode !== 0) - sdk.log.a('Failed to install intel-driver-compiler-npu.'); - else - needRestart = true; - } - } - catch (e) { - sdk.log.a('Failed to verify/install intel-driver-compiler-npu.'); - } - if (needRestart) sdk.log.a('A system update is pending. Please restart Scrypted to apply changes.'); } diff --git a/plugins/openvino/package-lock.json b/plugins/openvino/package-lock.json index e074f1803..94f6cb43b 100644 --- a/plugins/openvino/package-lock.json +++ b/plugins/openvino/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/openvino", - "version": "0.1.116", + "version": "0.1.117", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/openvino", - "version": "0.1.116", + "version": "0.1.117", "devDependencies": { "@scrypted/sdk": "file:../../sdk" } diff --git a/plugins/openvino/package.json b/plugins/openvino/package.json index 4e11dad73..28e9fb5dc 100644 --- a/plugins/openvino/package.json +++ b/plugins/openvino/package.json @@ -42,5 +42,5 @@ "devDependencies": { "@scrypted/sdk": "file:../../sdk" }, - "version": "0.1.116" + "version": "0.1.117" } diff --git a/plugins/openvino/src/ov/__init__.py b/plugins/openvino/src/ov/__init__.py index da385b402..b27b1a27e 100644 --- a/plugins/openvino/src/ov/__init__.py +++ b/plugins/openvino/src/ov/__init__.py @@ -202,6 +202,9 @@ class OpenVINOPlugin( try: self.compiled_model = self.core.compile_model(xmlFile, mode) except: + import traceback + traceback.print_exc() + if mode == "GPU": try: print("GPU mode failed, reverting to AUTO.") @@ -209,9 +212,6 @@ class OpenVINOPlugin( self.mode = mode self.compiled_model = self.core.compile_model(xmlFile, mode) except: - import traceback - - traceback.print_exc() print("Reverting all settings.") self.storage.removeItem("mode") self.storage.removeItem("model") diff --git a/plugins/openvino/src/requirements.txt b/plugins/openvino/src/requirements.txt index 3b6eaa8ea..c1710dd3a 100644 --- a/plugins/openvino/src/requirements.txt +++ b/plugins/openvino/src/requirements.txt @@ -1,8 +1,7 @@ # must ensure numpy is pinned to prevent dependencies with an unpinned numpy from pulling numpy>=2.0. numpy==1.26.4 -# openvino 2024.3.0 crashes on older CPU -# openvino 2024.2.0 crashes on current CPU. -# older versions unsure about NPU support. +# openvino 2024.3.0 crashes on older CPU (J4105 and older) if level-zero is installed via apt. +# openvino 2024.2.0 and older crashes on arc dGPU. openvino==2024.3.0 Pillow==10.3.0 opencv-python==4.10.0.84