Conversation
|
Thanks a lot for the great suggestion! The option looks very promising. I'll check several corner cases and return back with feedback. |
|
Hi I found some issues with this PR:
|
|
@stopmosk Please show your test app code and OpenCv build options pefore and after the patch. |
|
Hi, Thanks for your comment! First, regarding the issue with Ninja: From the link you added, I suspect that Ninja mixes something between the respective import libraries (.lib files) and the delay-loaded DLLs. Unluckily, the /delayload flag requires the DLLs and not the LIBs, as already mentioned above. This can be easily fixed by only allowing MSCV inside the CMake scripts (i.e. adding an 'if not Ninja condition'), but we are open to investigate which additional flags are required for Ninja as well to support the flag there, too. Still, we never used Ninja and a quickly setup of CMake using Ninja with specified C and C++ compilers terminates with the error message for unknown reasoning. The compiler is working fine (e.g. in combination with MSVC CMake builds) and it's unclear how to debug this. Is there a reference on how to compile OpenCV using Ninja on Windows? Unluckily, I found none by myself. Regarding your second comment: This is exactly the expected behavior, only the CUDA DLLs are delay-loaded. Still, the cudaarithm DLL is not a good example for the benefit of this flag because - at least as far as I know - there is nothing inside this DLL that works without CUDA-supported hardware. I think the DNN module is a better example: Here, we can either use the CPU backend (supported on all machines), the OpenVINO backend (supported on machines with an OpenVINO supported CPU or GPU) or the CUDA backend. Obviously, the latter is supported on machines equipped with CUDA-compatible hardware only. Still if CUDA is activated while compiling OpenCV, the CUDA libraries always have to be distributed to all machines at runtime, even though they cannot be used at all. This is where the delay load option shines: Activate it and the whole CUDA functionality is available to devices that can use it, while all non-CUDA functionalities are still available on all machines, without needing a superfluous CUDA installation. |
cmake/OpenCVDetectCUDA.cmake
Outdated
| if(MSVC) | ||
| OCV_OPTION(CUDA_ENABLE_DELAYLOAD "Enable delayed loading of CUDA DLLs" OFF) | ||
| endif() |
There was a problem hiding this comment.
OCV_OPTION has VISIBLE_IF argument for conditions. I propose to replace the "if" with option with single line:
OCV_OPTION(CUDA_ENABLE_DELAYLOAD "Enable delayed loading of CUDA DLLs" OFF VISIBLE_IF MSVC AND (CMAKE_GENERATOR MATCHES "Visual Studio"))
There was a problem hiding this comment.
Yes of course, it's more readable and cleaner.
Maybe it's worth think about defaulting to on? Just though about this option as it does not really change anything if the DLLs are there but avoids runtime errors if they are missing but still unused.
There was a problem hiding this comment.
I prefer to have it optional. It may affect libraries loading order for guys why use other CUDA-based libraries like TensorRT, CuDNN, python code with CUDA.
There was a problem hiding this comment.
Alright, just committed your proposal. So the PR can be merged now?
asmorkalov
left a comment
There was a problem hiding this comment.
👍 Looks good to me! Thanks for the contribution.
|
Great, thanks for approving 👍 |
|
@CSBVision Could you squash the commits to have clear merge history? |
|
Generally yes; however I don't want to mess up something. The right command should be or isn't it? |
|
After where exiting shows |
|
Adds the option to enable delay loading of CUDA DLLs on Windows. This is particularly useful to use the same binary on systems with and without CUDA support without distributing the CUDA DLLs to systems that cannot use them at all due to missing CUDA-supported hardware. Resolves opencv#13509
|
Thanks @alalek , I hope it's correct now. |


Adds the option to enable delay loading of CUDA DLLs on Windows. This is particularly useful to use the same binary on systems with and without CUDA support without distributing the CUDA DLLs to systems that cannot use them at all due to missing CUDA-supported hardware. Resolves #13509
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.