Files
ANSCORE/engines/ONNXEngine/OpenVINODeviceConfig.h

39 lines
1.3 KiB
C++

#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;
}
}