Merge pull request #26164 from CSBVision:patch-7

Update haveCUDA() to detect CUDA support at runtime
This commit is contained in:
Alexander Smorkalov 2024-12-26 15:56:03 +03:00 committed by GitHub
commit 707ab39454
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 7 deletions

View File

@ -107,3 +107,18 @@ void Net::Impl::initCUDABackend(const std::vector<LayerPin>& blobsToKeep_)
CV__DNN_INLINE_NS_END
}} // namespace cv::dnn
#endif // HAVE_CUDA
namespace cv { namespace dnn {
bool haveCUDA()
{
#ifdef HAVE_CUDA
int dev = 0;
static bool ret = (cudaGetDevice(&dev) == cudaSuccess);
return ret;
#else
return false;
#endif
}
}} // namespace cv::dnn

View File

@ -29,13 +29,7 @@ namespace cv { namespace dnn {
return id == DNN_TARGET_CUDA_FP16 || id == DNN_TARGET_CUDA;
}
constexpr bool haveCUDA() {
#ifdef HAVE_CUDA
return true;
#else
return false;
#endif
}
bool haveCUDA();
#ifdef HAVE_CUDA
namespace cuda4dnn { namespace csl {