I try to compile Opencv with cuda, but I have an error
Running with:
nvidia-driver-525.60.13
CUDA 12.0
OpenCV 3.4.16
I don't know where it comes from...
[ 7%] Building CXX object 3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc.o
/home/totar/cv2/opencv-3.4.16/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp(61): error: texture is not a template
/home/totar/cv2/opencv-3.4.16/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp(83): error: identifier "cudaUnbindTexture" is undefined
/home/totar/cv2/opencv-3.4.16/modules/core/include/opencv2/core/cuda/common.hpp(99): error: identifier "textureReference" is undefined
3 errors detected in the compilation of "/home/totar/cv2/opencv-3.4.16/modules/core/src/cuda/gpu_mat.cu".
CMake Error at cuda_compile_1_generated_gpu_mat.cu.o.Release.cmake:279 (message):
Error generating file
/home/totar/cv2/opencv-3.4.16/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/./cuda_compile_1_generated_gpu_mat.cu.o
modules/core/CMakeFiles/opencv_core.dir/build.make:63: recipe for target 'modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_gpu_mat.cu.o' failed
make[2]: *** [modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_gpu_mat.cu.o] Error 1
CMakeFiles/Makefile2:1889: recipe for target 'modules/core/CMakeFiles/opencv_core.dir/all' failed
make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
Output of nvcc --version
totar#totar:~/cv2/opencv-3.4.16/build$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Mon_Oct_24_19:12:58_PDT_2022
Cuda compilation tools, release 12.0, V12.0.76
Build cuda_12.0.r12.0/compiler.31968024_0
Has anyone ever had this problem?
CUDA 12.0 dropped support for legacy texture references. Therefore, any code that uses legacy texture references can no longer be properly compiled with CUDA 12.0 or beyond.
Legacy texture reference usage has been deprecated for some time now.
As indicated in the comments, by reverting to CUDA 11.x where legacy texture references are still supported (albeit deprecated) you won't run into this issue.
The other option may happen some day when OpenCV converts usage of legacy texture references to texture object methods. In that case, it may then be possible to use CUDA 12.0 or a newer CUDA toolkit to compile OpenCV/CUDA functionality.
There is no work around to somehow allow texture reference usage to be compiled properly with CUDA 12.0 and beyond.
Likewise, this limitation is not unique or specific to OpenCV. Any CUDA code that uses texture references can no longer be compiled properly with CUDA 12.0 and beyond. The options are to refactor that code with texture object usage instead, or revert to a previous CUDA toolkit that still has the deprecated support for texture reference usage.
Following from Robert Crovella's answer, another solution (for many people) would be to build OpenCV-4x instead, where the backend uses OpenCL for GPU access, and the Cuda modules are optional (found in the separate https://github.com/opencv/opencv_contrib repository).
Obviously this depends on whether you have a lot of code using the Cuda gpuMat class, which you would need to migrate to the UMat class for the OpenCV-4 "Transparent API" (aka TAPI). This probably worth doing for code that you intend to keep using for the long term.
Related
I followed the instructions at the below website to test DPC++ on my computer.
https://github.com/intel/llvm/blob/sycl/sycl/doc/GetStartedGuide.md#build-dpc-toolchain
$ ./simple-sycle-app.exe
The results are correct!
I then modified line 23 to target my gpu
// Creating SYCL queue
sycl::queue Queue( sycl::gpu_selector{} );
[18:49]ec2-user$ ./simple-sycl-app-gpu.exe
terminate called after throwing an instance of 'cl::sycl::runtime_error' what(): No device of requested type available. -1 (PI_ERROR_DEVICE_NOT_FOUND) Aborted (core dumped)
did i need to build my dpc environment with CUDA enabled to access my K80 Nvidia GPU? I didn't enable it because CUDA support is apparently still experimental. I thought the whole point of using DPC++ was for me not to need to use CUDA. Should i be able to use my Nvidia gpu with just an nvidia driver and not CUDA?
You need to build llvm compiler with CUDA support. Brief instruction is to
install CUDA development kit, e.g. from here
Build and install Intel's llvm compiler from sources: https://github.com/intel/llvm passing --cuda param to configure command (see instructions on project's README)
use compiler according to this instruction, e.g. like this:
export DPCPP_HOME=~/sycl_workspace
export PATH=$DPCPP_HOME/llvm/build/bin:$PATH
export LD_LIBRARY_PATH=$DPCPP_HOME/llvm/build/lib:$LD_LIBRARY_PATH
clang++ -fsycl -fsycl-targets=nvptx64-nvidia-cuda \
simple-sycl-app.cpp -o simple-sycl-app-cuda.exe
An OpenCL program I originally wrote for an AMD GPU (RX 570) fails the runtime compilation on the Nvidia card (RTX 3060, latest drivers) with the message <kernel>:28:5: error: use of unknown builtin '__builtin_mul_overflow'.
Through the preprocessor macros I found the OpenCL code now gets compiled with Clang 3.4. According to the documentation, this version did not yet support __builtin_mul_overflow(), which was introduced in Clang 3.8.
Is it possible to specify OpenCL to use a newer Clang version?
Or are the latest Nvidia drivers indeed limited to such an old compiler?
Unfortunately you can't control which compiler the OpenCL driver uses. You could try conditionally compiling the code to account for different compilers, but that's about it.
I am using ubuntu 17.04 to compile tensorflow c++ program related to alexnet that use libpng.
libpng warning: Application was compiled with png.h from libpng-1.6.23
libpng warning: Application is running with png.c from libpng-1.2.53
libpng error: Incompatible libpng version in application and library
When I run the program I get error of uncompatible libpng error and the program halts with segmentation fault.
What is the reason behind it and how can I solve it.
It sounds like you compiled your application with libpng-1.6.23 and at runtime your app tried to use libpng-1.2.53. The two versions are not compatible, so you get a segfault.
There are two possibilities here:
If you're running your program on the same machine you're building on, you have two versions of libpng installed. Use a tool (like slocate) to find the versions and uninstall one of them.
If you're running your program on a different machine(s) than the one you built on. Upgrade libpng to 1.6.23 on those machines.
I want to build a custom Linux using the Yocto Project for a system using the nvidia tegra k1 processor, which has an arm cortex A 15 (32bit) and a GPU. Furthermore, OpenCV (version >= 3.0) with CUDA support needs to be installed.
Now when Bitbake tries to compile OpenCV with CUDA it crashes because nvcc throws an error Syntax error: word unexpected (expecting ")") which I learned is usually the case if you try to run an nvcc binary that is for the wrong system (e.g. 32bit-nvcc on 64bit-system). So I guess it just runs the nvcc that is suppost for the target system and therefore crashes.
I don't know whether I need to compile using the usual x86-64bit-nvcc of the host system or (if this exists) some cross-compilation-nvcc.
I need to know how I can involve said compiler into bitbake's process that builds OpenCV.
I figured it out:
One needs to use an nvcc binary that supports the host architecture. To specify the target architecture on can pass it cross compilation flags (see http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/#cross-compilation). These are passed via the the cmake flag -DCUDA_NVCC_FLAGS
EXTRA_OECMAKE_append = "-DCUDA_NVCC_EXECUTABLE=${PATH_TO_THE_NVCC_BINARY}"
The whole statement in the bbappend file could look like this
EXTRA_OECMAKE_append = " \
-DCUDA_NVCC_EXECUTABLE=${NVCC_BINARY} \
-DCUDA_NVCC_FLAGS="--compiler-bindir ${GCC_BINARY}" \
"
In the post OpenCV 2.4.3rc and CUDA 4.2: "OpenCV Error: No GPU support" , it is said that C:\opencv\build\gpu\x86... libs must be added instead of C:\opencv\build\x86... ones. But there is no gpu folder for 2.4.4 realese. I added opencv_gpu244.lib lib file for release and opencv_gpu244d.lib for debug modes on vs 2010 conf. which are reside in C:\opencv\build\x64\vc10\lib. But i get opencv error ( no gpu support ): the library is compiled without cuda support. By the way i!'m using cuda toolkit 5.0.
The procedure described in the given answer, still applies to the current distribution of OpenCV. There is just 1 small difference. The pre-built distribution of OpenCV 2.4.4 does not contain GPU binaries. To add GPU support, you have to build the library yourself using CMake.
OpenCV 2.4.4 is optimized for Kepler architecture GPUs. In version 2.4.3, only the GPU binaries are approximately 1.4 GB. So you can guess, that adding the code for Compute capabilty 3.0 and 3.5 would make this even larger. So it is not feasible to ship these binaries, and that is why the gpu folder is not present in version 2.4.4 prebuilt distribution.
You should compile OpenCV libraries using CMake with CUDA support ( there is a checkbox ). Before releases include pre-compiled gpu files.