Is there any function to create cuda context in opencv similar to what cuCtxCreate does from cuda library?
I am developing an app which requires to use cuda functions like cuInit, cuCtxCreate etc. If i use these functions from cuda library then i get the following error which i mentioned in this issue https://github.com/opencv/opencv/issu...
I got this solved by modifying CMakeLists.txt and linking CUDA_CUDA_LIBRARY which is path to cuda.lib. My question here is Are there any alternatives available in opencv for doing the same? Like i see cuSetDevice cuGetDevice which sets and gets cuda devices but i am not able to find a function in opencv for creating a cuda context similar to what cuCtrCreate does.
Are you are getting errors when you link to both opencv_worldxxx.lib and cuda.lib? And because of this you can't directly call cuCtxCreate() so you want to see if there is an OpenCV function which does the same thing?
Yes. I get link errors "unresolved external symbol cuCtxCreate" .So in windows, since the opencv solution file is created, i opened solution file and in opencv_world project->projectProperties->linker->input i added cuda.lib and it worked. But i was not able to compile with linux using cmake and hence i found that solution which is mentioned on git.
Suppose i dont want to have that solution. And still want to use cuCtxCreate. So i want an alternative function (may be present in opencv) which does exact same thing.
The reason of searching for alternative is there are cuda based sample apps which doesn't have cuInit or cuCtxCreate but still they work. But i believe internally they somewhere might be having a cuda context created.
I don't understand why needing to include calls to the cuda driver api in your own code has anything to do with the compilation of the OpenCV library itself? As you said in windows you just need to link to cuda.lib. In linux you should just be able to pass -lcuda to nvcc when you compile your own source.
Regarding the context, OpenCV uses the cuda runtime and not the driver api so the contexts are automatically created if they do not exist, as per the documentaion.
If i push my code into opencv repo then cuda.lib needs to be automatically linked rather than i adding -lcuda or adding to project properties. Regarding the context, How can i get that context which is automatically created?
Why are you pushing to the OpenCV repo, are you adding functionality to the library?
Why do you need the context?
Yes. i am adding a functionality in opencv_contrib in optical flow section. For my code to work, i need the cuda context and hence i am using cuCtxCreate for creating one and now i need an alternative for the same
Interesting what are you trying to do that requires a CUDA context?
Are you going to call cuCtxCreate() before calling any runtime api functions which require a context? If its after you should just be able to grab the context that has been created with cuCtxGetCurrent().
I can initially call runtime API's and then call cuCtxGetCurrent() But cuCtxGetCurrent() is again a driver API which will lead to unresolved symbol error.
Hi, I understand that, I am suggesting that it would be better once you have the driver api available to you to grab the current context instead of creating a new one. Because if you do create a new context when one exists for the runtime api and then apply it, your runtime api calls and driver api could get confused. But this depends what you are trying to achieve, why do you nee the context, is there an alternative?
Sounds fine. But at the end, anyway i need to link cuda.lib. I dont have any other choice.
Thanks @cudawarped for helping. Appreciated :-)