I have a question regarding the CUDA modules in OpenCV 3. Formerly in OpenCV 2 there was the opencv_gpu module and there was always a opencv2/gpu/gpu.hpp file in the include folder. It would be moved there during install whether OpenCV was built with CUDA or without. In the latter case however, CUDA functions would not be usable later in the code, which could be checked by invoking cv::gpu::getCudaEnabledDeviceCount() which would then always return 0. This way a program that used CUDA could be compiled with versions of OpenCV that were built with CUDA, as well as with ones built without CUDA.
In Opencv 3.0 the CUDA functions have been moved to the modules cudaarithm, cudaimgproc, cudafilters, cudawarping and so on. They are only available if you add the opencv contrib repository.
Now, I was creating a program that uses cuda. Then I realized, that when building and installing OpenCV without CUDA, meaining the machine does not support CUDA and the NVIDIA cuda toolkit is not installed, the header files for the CUDA modules are not copied into the include folder when installing. This way the program doesn't compile. How do you compile a program using the OpenCV CUDA modules with a build that was built without CUDA in OpenCV 3?
Previous Version OpenCV upto 2.3 default build was with CUDA from that onwards if you want to run Opencv with cuda support you have build OpenCV from source with CUDA Check This Guide.
You must have a CUDA enabled GPU to run Opencv with CUDA. NVIDIA CUDA enabled GPU List
Ok, at least for OpenCV 3.1 it appears not to be a problem. The cuda modules have also been moved back to the main repository.
It is necessary to have a version of OpenCV compiled with CUDA. That can be done also on a machine without an Nvidia GPU. The Nvidia CUDA toolkit has to be installed (just ignore the warning message about the GPU). The graphics driver, however, is not required. This way compiling OpenCV with CUDA should not be a problem also on a machine that is not CUDA-enabled.
In your project you can then just include the cudaarithm etc. modules and perform the check if any CUDA devices are available at runtime, just like before.
Related
I need to do fast image processing so I decide to go for OpenCV with CUDA support. Now I'm trying to build OpenCV as dll to use it in my project, but I am not even able to generate the VS project since CMake keeps giving me this error:
CMakeError. I am on Windows 10, CMake 3.11 with VS 15 2017 x64 generator, OpenCV 3.4 (the last release).
I have installed CUDA 9.2, 9.1 and 8.0 and set CUDA_HOME environment variable as the CUDA toolkit directory. Nothing seems to work.
Then I try to set the CUDA_SDK_ROOT_DIR through the CMake GUI, but the CUDA toolkit directory seems to be not the right one and I'm not able to find the CUDA sample directory anywhere.
I have googled a lot, but I found nothing that had been able to help me. Did someone face this very same issue? How can I solve it?
PS: I have successfully created the dll with TBB and IPP (without CUDA) and it is still not fast enough, so I really need to use Cuda.
I have solved using Cuda 9.1 and VS 15.45. To install CUDA in a correct way you need to use custom installation and delete the VS integration, since it seems to have some problems. Once installation is complete, CMake should detect it.
This is a guide that could help.
I'm trying to build a simple application with CUDA and I've been trying for hours on end and I just can't make it work on windows. nvcc absolutely refuses to compile without Visual Studio's compiler which doesn't support things I need. I tried building using nvcc with clang but It just asks me to use Visual Studio's compiler. I've also tried using clang directly since it now supports CUDA but I receive this error:
clang++.exe: error: Unsupported CUDA gpu architecture: compute_52
This makes no sense to me because I have the CUDA toolkit version 7.5 and my graphics card is a GTX 970 (two of them). I have googled this extensively and everywhere I come across the error the person always has is their CUDA toolkit is < 7.5. I'm on the brink of tears right now trying to get something as simple as VLA to work on this CUDA application and I just can't achieve it...
The CUDA windows toolchain requires the Visual Studio C++ compiler. You cannot use anything else on that platform. If the VS compiler doesn't support the language features you need within CUDA host code, you have no choice but to change platforms, or your expectations.
You can still potentially compile non-CUDA host code using another compiler and then link that code using NVCC and the VS toolchain.
Try to use clang-cl, --cubin=clang-cl.exe
It may be worth to work on a Linux VM or WSL2 within windows. As per the CUDA docs.
To compile new CUDA applications, a CUDA Toolkit for Linux x86 is
needed. CUDA Toolkit support for WSL is still in preview stage as
developer tools such as profilers are not available yet. However, CUDA
application development is fully supported in the WSL2 environment, as
a result, users should be able to compile new CUDA Linux applications
with the latest CUDA Toolkit for x86 Linux.
https://docs.nvidia.com/cuda/wsl-user-guide/index.html#:~:text=However%2C%20CUDA%20application%20development%20is,becomes%20available%20within%20WSL%202.
I am trying to install OpenCV on Mac OSX. I had previously installed CUDA 5.0 but no longer have an NVIDIA GPU and thought I had uninstalled the CUDA drivers. However when I run cmake on the OpenCV source it says it detects CUDA and configures the installation to use it, which then causes the installation to crash due to said lack of GPU or nvcc. How do I turn off this option in the configuration? How can I completely scrub any last trace of CUDA from my system, so that it's not erroneously detected?
Basicly you have only to be sure that the flag WITH_CUDA is deselected. While autoconfiguration during cmake process, OpenCV search for CUDA on the system, for example through references in the environment variables.
To disable CUDA support, add following commandline option:
cmake -DWITH_CUDA:BOOL="0"
Alternatively if you uses a gui for cmake, just search for the WITH_CUDA option and deselect it or set it to OFF
I am using visual studio 2010.
Before starting my project, I installed cuda SDK 4.2.
After that, I installed opencv 2.4.2. In my project, I'm using only opencv and it works correctly. However, when I try to run my program on another computer it tells me that cuda dll (like cudart32_42_9.dll, npp32_42_9.dll and nvcuda.dll) are needed. I don't use at all cuda and do no reference in my project property to cuda. I would like to know how to remove those dependency. I don't understand why visual studio add dll I don't use.
The pre-built OpenCV 2.2 onwards, comes with 2 versions of the binaries (dlls).
The dlls in the \build\gpu directory are the superset and are built with CUDA support. Therefore, to use them you require the CUDA Runtime dlls (cudart, npp etc). These binaries are required if you want to use the GPU functionality of OpenCV. These may also be used to check if you have a GPU present in your system or not.
The other version of dlls which are present in the x86 or x64 folder in the build directory of OpenCV, are built without CUDA support (although a gpu dll is also present in that directory). You don't need cuda dlls to use these binaries.
Both of these versions are built with Intel Thread Building Blocks support, and so require tbb_debug.dll and tbb.dll for Debug and Release configurations respectively. So if you use the CPU functions of OpenCV, they will be TBB Accelerated.
I installed CUDA Toolkit 3.2, CUDA SDK and MS Visual Studio 2008 (not necessarily in this order) on my Windows 7 that does not have an nvidia graphics card.
But when I try running my CUDA code, the CUDA keywords are'nt identified.
I am a beginner. Pls tell me what I am doing wrong here.
Thanks
Are you building using nvcc? If not, Visual C++ will choke on the CUDA-specific syntax.
You should be able to build the SDK samples with your setup, but you won't be able to run since you do not have a CUDA capable GPU. Emulation is no longer supported, so you have a couple of options available:
gpuocelot
PGI CUDA x86
Check out this stackoverflow post for details of syntax highlighting and more in VS2008.
Incidentally, if you installed the Toolkit before VS2008 then the rules files will not have been copied to the VS directories (clearly, since they didn't exist). You can find them and instructions in the CUDA Toolkit in the extras directory.
You if are trying to execute cuda programs on non gpu machines, I would suggest you to try mCUDA. It doesn't need GPU or Graphics card for CUDA execution.
The installation of CUDA development tools on a system running the appropriate version
Verify the system has a CUDA‐enabled GPU and a supported version of OS.
Many [NVIDIA products today contain CUDA‐enabled GPUs][1]. These include:
NVIDIA GeForce® 8, 9, 200, and 400 series GPUs
NVIDIA Tesla™ computing solutions
Many of the NVIDIA Quadro® products
Verify the NVIDIA driver and the CUDA software.
Update the NVIDIA driver.
Install the CUDA software.
Verify the the CUDA software linking With VS2008/VS2010
For that you can check my Blog Also http://hemprasad.wordpress.com/2012/10/12/cuda-installation-on-vs-2010/
Test your installation by compiling and running one of the sample programs in the
CUDA software to validate that the hardware and software are running correctly and
communicating with each other.
If you don't have a NVIDIA card, you can still use the emulator but you need to install the SDK and the toolkit. Try to fix your problem by adding in your Visual Studio project settings the include and library path of CUDA.
CUDA is only supported on machines with nVidia video cards. That is likely an issue.
Furthermore, you need to install drivers (dev or otherwise) that is new enough to support the CUDA Toolkit version.
Third, what do you mean by the keywords aren't identified? Do you mean there's no syntax highlighting in your IDE? If so, try [this][1]http://codereflect.com/2008/09/04/how-to-enable-syntax-highlighting-for-cuda-files-in-visual-studio-2005/