OpenCV DNN strict backend selection without silent CPU fallback
0 reputation · 14 Jan 2025, 05:31 UTC
OpenCV DNN strict backend selection without silent CPU fallback
Goal: configure cv::dnn::Net so that requesting DNN_BACKEND_CUDA with DNN_TARGET_CUDA fails explicitly when CUDA support is absent or no CUDA device is available, instead of silently falling back to the default OpenCV CPU backend.
Constraint: setPreferableBackend and setPreferableTarget currently accept the request and construct the network even when the underlying build lacks CUDA or the runtime has no enabled device. Build-time compile flags, driver availability, and device count determine actual GPU execution, but the API exposes no strict fail-fast mode. On systems with multiple GPUs or OpenCL platforms, availability queries also do not guarantee which device is selected.
Uncertainty: whether any runtime check, build flag, or environment variable can force an exception or error before inference, and how to verify the effective backend without measuring latency.
Specific questions:
- Is there a build configuration or runtime API that makes OpenCV DNN reject an unavailable CUDA backend or target instead of falling back?
- How can an application confirm that CUDA execution was actually accepted before running inference?
- Does OpenCV provide version-specific documentation for strict backend validation behavior?