Enable log information. Disable NPU in U9

This commit is contained in:
2026-04-21 15:48:27 +10:00
parent 00f6e2f852
commit 97d814936d
18 changed files with 301 additions and 54 deletions

View File

@@ -1,8 +1,10 @@
#include "ONNXEngine.h"
#include "EPLoader.h"
#include "OpenVINODeviceConfig.h"
#include "Utility.h"
#include <algorithm>
#include <cctype>
#include <limits>
#include <filesystem>
#include <fstream>
@@ -318,8 +320,9 @@ namespace ANSCENTER {
std::vector<std::unordered_map<std::string, std::string>> try_configs;
// Only try NPU if it hasn't been probed yet or was previously available
if (!s_npuProbed || s_npuAvailable) {
// NPU is disabled by default — see OpenVINODeviceConfig.h. Opt in via
// OPENVINO_ENABLE_NPU=1. Even when enabled, skip if a prior probe failed.
if (IsOpenVINONpuEnabled() && (!s_npuProbed || s_npuAvailable)) {
try_configs.push_back(makeConfig("AUTO:NPU,GPU"));
}
try_configs.push_back(makeConfig("GPU.0"));

View File

@@ -1,5 +1,6 @@
#include "ONNXSAM3.h"
#include "ONNXEngine.h" // OrtCompatiableGetInputName/OutputName helpers
#include "OpenVINODeviceConfig.h"
#include <iostream>
#include <fstream>
@@ -73,11 +74,13 @@ namespace ANSCENTER
bool ONNXSAM3::TryAppendOpenVINO(Ort::SessionOptions& session_options)
{
std::vector<std::unordered_map<std::string, std::string>> configs = {
{{"device_type","AUTO:NPU,GPU"},{"precision","FP16"},{"num_of_threads","4"},{"num_streams","4"}},
{{"device_type","GPU.0"}, {"precision","FP16"},{"num_of_threads","4"},{"num_streams","4"}},
{{"device_type","AUTO:GPU,CPU"},{"precision","FP16"},{"num_of_threads","4"},{"num_streams","4"}}
};
// NPU gated by OPENVINO_ENABLE_NPU — see OpenVINODeviceConfig.h
std::vector<std::unordered_map<std::string, std::string>> configs;
if (IsOpenVINONpuEnabled()) {
configs.push_back({{"device_type","AUTO:NPU,GPU"},{"precision","FP16"},{"num_of_threads","4"},{"num_streams","4"}});
}
configs.push_back({{"device_type","GPU.0"}, {"precision","FP16"},{"num_of_threads","4"},{"num_streams","4"}});
configs.push_back({{"device_type","AUTO:GPU,CPU"},{"precision","FP16"},{"num_of_threads","4"},{"num_streams","4"}});
for (const auto& config : configs) {
try {
session_options.AppendExecutionProvider_OpenVINO_V2(config);

View File

@@ -0,0 +1,38 @@
#pragma once
// Shared runtime switch for enabling the Intel NPU in OpenVINO code paths.
//
// NPU is DISABLED BY DEFAULT because the NPU plugin on some Intel platforms
// (observed: Core Ultra 9 285K / Arrow Lake) crashes inside
// ov::Core::compile_model or Ort::Session construction when compiling
// multiple ONNX models in quick succession. That failure mode cannot be
// caught by the surrounding try/catch (it fires on a plugin worker thread)
// and takes down the host process.
//
// To opt into NPU (e.g. on a machine with a known-good NPU driver), set the
// environment variable OPENVINO_ENABLE_NPU to 1 / true / yes / on before
// launching the host process.
//
// Every OpenVINO device-selection site in this codebase consults this helper
// rather than probing NPU unconditionally.
#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <string>
namespace ANSCENTER {
inline bool IsOpenVINONpuEnabled() {
static const bool enabled = [] {
const char* v = std::getenv("OPENVINO_ENABLE_NPU");
if (!v || !*v) return false;
std::string s(v);
std::transform(s.begin(), s.end(), s.begin(),
[](unsigned char c) { return static_cast<char>(std::tolower(c)); });
return s == "1" || s == "true" || s == "yes" || s == "on";
}();
return enabled;
}
}