Bug 1236417 - Consider enabling the opencv gpu module
Summary: Consider enabling the opencv gpu module
Alias: None
Product: Fedora
Classification: Fedora
Component: opencv
Version: 23
Hardware: Unspecified
OS: Unspecified
Target Milestone: ---
Assignee: Nicolas Chauvet (kwizart)
QA Contact: Fedora Extras Quality Assurance
Depends On:
TreeView+ depends on / blocked
Reported: 2015-06-28 20:02 UTC by Rich Mattes
Modified: 2015-07-30 01:10 UTC (History)
6 users (show)

Fixed In Version: opencv-2.4.11-5.fc22
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2015-07-30 01:10:37 UTC
Type: Bug

Attachments (Terms of Use)
Patch to enable gpu module (2.99 KB, patch)
2015-06-28 21:28 UTC, Rich Mattes
no flags Details | Diff

Description Rich Mattes 2015-06-28 20:02:40 UTC
Description of problem:
The Fedora spec for OpenCV currently disables the OpenCV gpu module by default, and only enables it when the with_cuda condition is true.  The gpu module can be built without cuda being present (as not everyone has nvidia gpus), and it allows for detection of gpu support.  From the OpenCV documentation[1]:

> To enable CUDA support, configure OpenCV using CMake with WITH_CUDA=ON . When the flag is set and if CUDA is installed, the full-featured OpenCV GPU module is built. Otherwise, the module is still built but at runtime all functions from the module throw Exception with CV_GpuNotSupported error code, except for gpu::getCudaEnabledDeviceCount(). The latter function returns zero GPU count in this case. Building OpenCV without CUDA support does not perform device code compilation, so it does not require the CUDA Toolkit installed. Therefore, using the gpu::getCudaEnabledDeviceCount() function, you can implement a high-level algorithm that will detect GPU presence at runtime and choose an appropriate implementation (CPU or GPU) accordingly.

I'm trying to build a third-party library that uses the OpenCV gpu module[2].  It currently fails as opencv/gpu/gpu.hpp isn't packaged.  The library does try to do run-time detection of the OpenCV gpu features, so if the gpu module were enabled the library would build, detect that there is no gpu support, and fall back to cpu-based functions.

tl;dr: the opencv gpu module is designed to degrade gracefully when cuda isn't present, so there's no real reason for fedora to disable it.

Version-Release number of selected component (if applicable):

How reproducible:
Build a program that uses opencv's GPU support

Steps to Reproduce:

Actual results:
Compilation fails, gpu headers missing

Expected results:
Compilation successful, and run-time detection of GPU support is active.

Additional info:

[1] http://docs.opencv.org/modules/gpu/doc/introduction.html
[2] https://github.com/introlab/rtabmap/blob/jade-devel/corelib/src/VWDictionary.cpp

Comment 1 Nicolas Chauvet (kwizart) 2015-06-28 20:38:31 UTC
We cannot enable cuda support within fedora as this is non-free item
that been said, there is an option that will allow to enable cuda when the package is rebuilt. rpmbuild -bb opencv*.src.rpm --with cuda

if it doesnt work for you and if you use the cuda packaged toolkit provided by nvidia, please send patch to fix that, but we cannot hold the bug here.

Comment 2 Nicolas Chauvet (kwizart) 2015-06-28 20:41:13 UTC
An alternative would be to submit an opencv-cuda package in a 3rd party repository (with only the missing cuda enabled library).

Comment 3 Rich Mattes 2015-06-28 21:26:19 UTC
I'm not asking for cuda support to be enabled, I'm asking for the gpu module to be built.  The gpu module can be built without cuda support.  The result is a library where one function actually works (getCudaEnabledDeviceCount), and the rest of the functions throw exceptions when called.  This is by design, since not all PCs have nvidia cards, and it allows the library users to detect at runtime whether the GPU features are supported and fall back to alternate code when they're not.

Comment 4 Rich Mattes 2015-06-28 21:28:16 UTC
Created attachment 1044123 [details]
Patch to enable gpu module

This patch contains the changes needed to enable the gpu module.  It works without the nvidia cuda sdk installed

Comment 5 Sergio Basto 2015-06-28 21:38:35 UTC
Hi I'm looking right now to opencv.spec [1]

we don't need add -DBUILD_opencv_gpu=1 ? yeah o delete the line :


this compile without rpmfusion modules ? and licenses are acceptable for Fedora  ? 


[1] http://pkgs.fedoraproject.org/cgit/opencv.git/tree/opencv.spec

Comment 6 Rich Mattes 2015-06-28 21:45:02 UTC
The OpenCV GPU code itself looks to be licensed under the same terms as opencv.  since it's not linking against cuda, there's no license issues.

I have an example of the intended fallback mechanisms that will happen if we enable the gpu module. 

Test Program:
#include <iostream>
#include <opencv2/gpu/gpu.hpp>

int main (int argc, char *argv[])
    int count = cv::gpu::getCudaEnabledDeviceCount();
    std::cout << count << " Cuda Devices" << std::endl;
    try {
    catch (std::exception& e)
        std::cerr << "Caught Exception: " << e.what() << std::endl;
    return 0;

Before attached patch is applied:
$ g++ -o ocv_gpu `pkg-config --cflags --libs opencv` ocv_gpu.cc 
ocv_gpu.cc:2:31: fatal error: opencv2/gpu/gpu.hpp: No such file or directory

After attached patch is applied:
$ g++ -o ocv_gpu `pkg-config --cflags --libs opencv` ocv_gpu.cc 
$ ./ocv_gpu
0 Cuda Devices
OpenCV Error: No GPU support (The library is compiled without CUDA support) in setDevice, file /home/rich/fedora/opencv/opencv-2.4.11/modules/dynamicuda/include/opencv2/dynamicuda/dynamicuda.hpp, line 84
Caught Exception: /home/rich/fedora/opencv/opencv-2.4.11/modules/dynamicuda/include/opencv2/dynamicuda/dynamicuda.hpp:84: error: (-216) The library is compiled without CUDA support in function setDevice

Comment 7 Sergio Basto 2015-06-30 15:39:18 UTC
OK , it seems to me reasonable.
Any thing that block this update ? if not I will proceed soon , just waiting a little bit for an answer.


Comment 8 Fedora Update System 2015-07-06 14:36:15 UTC
opencv-2.4.11-4.fc22 has been submitted as an update for Fedora 22.

Comment 9 Fedora Update System 2015-07-10 19:19:00 UTC
Package opencv-2.4.11-4.fc22:
* should fix your issue,
* was pushed to the Fedora 22 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing opencv-2.4.11-4.fc22'
as soon as you are able to.
Please go to the following url:
then log in and leave karma (feedback).

Comment 10 Fedora Update System 2015-07-15 04:38:35 UTC
opencv-2.4.11-5.fc22 has been submitted as an update for Fedora 22.

Comment 11 Jan Kurik 2015-07-15 13:53:53 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 23 development cycle.
Changing version to '23'.

(As we did not run this process for some time, it could affect also pre-Fedora 23 development
cycle bugs. We are very sorry. It will help us with cleanup during Fedora 23 End Of Life. Thank you.)

More information and reason for this action is here:

Comment 12 Fedora Update System 2015-07-30 01:10:37 UTC
opencv-2.4.11-5.fc22 has been pushed to the Fedora 22 stable repository.  If problems still persist, please make note of it in this bug report.

Note You need to log in before you can comment on or make changes to this bug.