Add CPU/GPU gate and support new ANSALPR using OCR

This commit is contained in:
2026-04-12 17:16:16 +10:00
parent 27083a6530
commit 0a8aaed215
30 changed files with 1870 additions and 2166 deletions

View File

@@ -97,14 +97,33 @@ public:
};
// Determine maxSlotsPerGpu based on GPU topology:
// 1 GPU → 1 (single slot, no round-robin needed)
// >1 GPU, VRAM<24GB → 1 (round-robin: 1 slot per GPU)
// >1 GPU, VRAM24GB → -1 (elastic: on-demand slot growth)
// non-NVIDIA (AMD/Intel/CPU) → 1 (no TensorRT pool, never grows)
// 1 NVIDIA GPU → 1 (single slot, no round-robin needed)
// >1 GPU, VRAM<24GB → 1 (round-robin: 1 slot per GPU)
// >1 GPU, VRAM≥24GB → -1 (elastic: on-demand slot growth)
//
// IMPORTANT: Must be gated on CheckHardwareInformation() first — calling
// cudaGetDeviceCount/cudaSetDevice/cudaMemGetInfo on non-NVIDIA hardware
// wakes up the CUDA runtime unnecessarily and, combined with DirectML on
// AMD, has been observed to trigger amdkmdag instability. Return 1 early
// on anything that isn't a detected NVIDIA GPU so the TRT pool is never
// exercised on those machines.
static int GetPoolMaxSlotsPerGpu() {
static int s_result = INT_MIN;
static std::mutex s_mutex;
std::lock_guard<std::mutex> lk(s_mutex);
if (s_result != INT_MIN) return s_result;
const ANSCENTER::EngineType detected =
ANSCENTER::ANSLicenseHelper::CheckHardwareInformation();
if (detected != ANSCENTER::EngineType::NVIDIA_GPU) {
s_result = 1;
std::cout << "Info [FR GPU]: engineType=" << static_cast<int>(detected)
<< " — not NVIDIA, TRT pool disabled (slot=1), skipping CUDA probe"
<< std::endl;
return s_result;
}
int gpuCount = 0;
cudaGetDeviceCount(&gpuCount);
if (gpuCount <= 1) {
@@ -211,6 +230,26 @@ extern "C" ANSFR_API int CreateANSRFHandle(ANSCENTER::ANSFacialRecognition**
if (!Handle || !licenseKey || !configFilePath || !databaseFilePath || !recogniserFilePath) return -1;
// Log the detected vendor path so field triage between NVIDIA / AMD /
// Intel / CPU machines is trivial from the debug log. Mirrors the
// vendorTag logging already in ANSLPR_OD::LoadEngine and ANSOCR
// CreateANSOCRHandleEx.
{
ANSCENTER::EngineType detected =
ANSCENTER::ANSLicenseHelper::CheckHardwareInformation();
const char* vendorTag =
detected == ANSCENTER::EngineType::NVIDIA_GPU ? "NVIDIA_GPU (TensorRT + CUDA preproc, SCRFD face detector)" :
detected == ANSCENTER::EngineType::AMD_GPU ? "AMD_GPU (ONNX Runtime / DirectML, OV face detector, NV12/CUDA DISABLED)" :
detected == ANSCENTER::EngineType::OPENVINO_GPU ? "OPENVINO_GPU (OpenVINO, OV face detector, NV12/CUDA DISABLED)" :
"CPU (ONNX Runtime / OpenVINO CPU, NV12/CUDA DISABLED)";
char buf[224];
snprintf(buf, sizeof(buf),
"[ANSFR] CreateANSRFHandle: detected engineType=%d [%s]\n",
static_cast<int>(detected), vendorTag);
OutputDebugStringA(buf);
std::cout << buf;
}
// Release existing handle if called twice (prevents leak from LabVIEW)
if (*Handle) {
if (UnregisterFRHandle(*Handle)) {