Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 637078 - <media-libs/opencv-3.3.1: unable to build with cuda 9
Summary: <media-libs/opencv-3.3.1: unable to build with cuda 9
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Amy Liffey
URL:
Whiteboard:
Keywords:
: 637254 643846 (view as bug list)
Depends on:
Blocks:
 
Reported: 2017-11-10 18:18 UTC by Daniel M. Weeks
Modified: 2018-01-21 08:36 UTC (History)
9 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Patch for includes in saturate_cast.hpp (saturate_cast_hpp.patch,1.05 KB, patch)
2018-01-02 18:42 UTC, Todd Walter
Details | Diff
Remove reference to compute_20 in CMake file if version >8 (OpenCVDetectCUDA_cmake.patch,441 bytes, patch)
2018-01-02 18:43 UTC, Todd Walter
Details | Diff
Patch for CMake and CUDA > 9 (FindCUDA_cmake.patch,5.23 KB, patch)
2018-01-02 18:43 UTC, Todd Walter
Details | Diff
Remove reference to compute_20 in CMake file if version >8 (OpenCVDetectCUDA_cmake.patch,775 bytes, patch)
2018-01-03 15:44 UTC, Todd Walter
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel M. Weeks 2017-11-10 18:18:11 UTC
opencv versions <3.3.1 do not appears to be compatible with the recently added dev-util/nvidia-cuda-toolkit-9.0.176. Building media-libs/opencv-3.3.0-r4 results in the following error early in the build process:

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CUDA_nppi_LIBRARY (ADVANCED)

[list of files using CUDA_nppi_LIBRARY]

See also: https://github.com/opencv/opencv/commit/c48807c383094cd240a4a36b53317988f6beabc5

Reproducible: Always
Comment 1 Amy Liffey gentoo-dev 2017-11-19 13:20:43 UTC
*** Bug 637254 has been marked as a duplicate of this bug. ***
Comment 2 Daniel M. Weeks 2017-12-12 05:38:04 UTC
This issue has been further complicated. Anything older than cuda 9 does not support gcc > 5 and fails with the following error:

#error -- unsupported GNU version! gcc versions later than 5 are not supported!

Now that gcc 6.4.0 is the latest stable, there are no usable versions of opencv if one tries to build with USE=cuda.
Comment 3 Todd Walter 2018-01-02 18:42:34 UTC
Created attachment 512878 [details, diff]
Patch for includes in saturate_cast.hpp
Comment 4 Todd Walter 2018-01-02 18:43:18 UTC
Created attachment 512880 [details, diff]
Remove reference to compute_20 in CMake file if version >8
Comment 5 Todd Walter 2018-01-02 18:43:54 UTC
Created attachment 512882 [details, diff]
Patch for CMake and CUDA > 9
Comment 6 Todd Walter 2018-01-02 18:45:22 UTC
Posted patches that help, cribbed from the git branch.  Compilation fails at 31% for reasons I've yet to dig into.
Comment 7 Todd Walter 2018-01-02 18:46:57 UTC
(In reply to Todd Walter from comment #6)
> Posted patches that help, cribbed from the git branch.  Compilation fails at
> 31% for reasons I've yet to dig into.

Forget to mention this is against 3.3.0-r4 which is the most recent version in portage.
Comment 8 Todd Walter 2018-01-02 18:51:37 UTC
Error is as follows:

[ 33%] Building NVCC (Device) object modules/cudabgsegm/CMakeFiles/cuda_compile.dir/src/cuda/cuda_compile_generated_mog2.cu.o
/var/tmp/portage/media-libs/opencv-3.3.0-r4/work/opencv-3.3.0/modules/core/include/opencv2/core/cuda/vec_math.hpp(203): error: calling a constexpr __host__ function("abs") from a __device__ function("abs") is not allowed. The experimental flag '--expt-relaxed-constexpr' can be used to allow this.

I do not know the consequences of enabling this flag.
Comment 9 Daniel M. Weeks 2018-01-02 19:49:47 UTC
(In reply to Todd Walter from comment #6)
> Posted patches that help, cribbed from the git branch.  Compilation fails at
> 31% for reasons I've yet to dig into.

I think it makes more sense to create a version 3.3.1 reusing applicable Gentoo patches from 3.3.0 rather than the reverse. That's why I opened this as "<media-libs/opencv-3.3.1" as 3.3.1 specifically support CUDA 9.
Comment 10 Todd Walter 2018-01-03 15:44:41 UTC
Created attachment 513090 [details, diff]
Remove reference to compute_20 in CMake file if version >8

Also add required flag to prevent related compile error.
Comment 11 Todd Walter 2018-01-03 15:49:58 UTC
(In reply to Daniel M. Weeks from comment #9)
> (In reply to Todd Walter from comment #6)
> > Posted patches that help, cribbed from the git branch.  Compilation fails at
> > 31% for reasons I've yet to dig into.
> 
> I think it makes more sense to create a version 3.3.1 reusing applicable
> Gentoo patches from 3.3.0 rather than the reverse. That's why I opened this
> as "<media-libs/opencv-3.3.1" as 3.3.1 specifically support CUDA 9.

That as a may be, but the patches supplied should fix the problem for what's in tree now.  Blender compiles successfully against this, FWIW.
Comment 12 Amy Liffey gentoo-dev 2018-01-16 09:42:35 UTC
*** Bug 643846 has been marked as a duplicate of this bug. ***
Comment 13 Samuel Bernardo 2018-01-18 01:01:37 UTC
Applying all referenced patches I receive the following error:

2 errors detected in the compilation of "/var/tmp/portage/media-libs/opencv-3.3.0-r4/temp/tmpxft_000043d0_00000000-12_gpu_mat.compute_61.cpp1.ii".
-- Removing /var/tmp/portage/media-libs/opencv-3.3.0-r4/work/opencv-3.3.0-abi_x86_64.amd64/modules/core/CMakeFiles/cuda_compile.dir/src/cuda/./cuda_compile_generated_gpu_mat.cu.o
/usr/bin/cmake -E remove /var/tmp/portage/media-libs/opencv-3.3.0-r4/work/opencv-3.3.0-abi_x86_64.amd64/modules/core/CMakeFiles/cuda_compile.dir/src/cuda/./cuda_compile_generated_gpu_mat.cu.o
CMake Error at cuda_compile_generated_gpu_mat.cu.o.cmake:266 (message):
  Error generating file
  /var/tmp/portage/media-libs/opencv-3.3.0-r4/work/opencv-3.3.0-abi_x86_64.amd64/modules/core/CMakeFiles/cuda_compile.dir/src/cuda/./cuda_compile_generated_gpu_mat.cu.o
Comment 14 Samuel Bernardo 2018-01-18 01:04:58 UTC
(In reply to Samuel Bernardo from comment #13)
> Applying all referenced patches I receive the following error:
> 
> 2 errors detected in the compilation of
> "/var/tmp/portage/media-libs/opencv-3.3.0-r4/temp/tmpxft_000043d0_00000000-
> 12_gpu_mat.compute_61.cpp1.ii".
> -- Removing
> /var/tmp/portage/media-libs/opencv-3.3.0-r4/work/opencv-3.3.0-abi_x86_64.
> amd64/modules/core/CMakeFiles/cuda_compile.dir/src/cuda/./
> cuda_compile_generated_gpu_mat.cu.o
> /usr/bin/cmake -E remove
> /var/tmp/portage/media-libs/opencv-3.3.0-r4/work/opencv-3.3.0-abi_x86_64.
> amd64/modules/core/CMakeFiles/cuda_compile.dir/src/cuda/./
> cuda_compile_generated_gpu_mat.cu.o
> CMake Error at cuda_compile_generated_gpu_mat.cu.o.cmake:266 (message):
>   Error generating file
>  
> /var/tmp/portage/media-libs/opencv-3.3.0-r4/work/opencv-3.3.0-abi_x86_64.
> amd64/modules/core/CMakeFiles/cuda_compile.dir/src/cuda/./
> cuda_compile_generated_gpu_mat.cu.o

Forget to mention the errors:

/usr/include/bits/floatn.h(61): error: invalid argument to attribute "__mode__"

/usr/include/bits/floatn.h(73): error: identifier "__float128" is undefined
Comment 15 Todd Walter 2018-01-19 15:39:41 UTC
Those include files are from the masked glibc 2.26; I think reverting to 2.25 will fix your problem.
Comment 16 Samuel Bernardo 2018-01-20 11:13:06 UTC
(In reply to Todd Walter from comment #15)
> Those include files are from the masked glibc 2.26; I think reverting to
> 2.25 will fix your problem.

Hi Todd,

Thanks for your feedback.

I'm using profile "default/linux/amd64/17.0 (stable)" with some ebuild keyword unmasked.
You're right, I thought that glibc-2.26 was keyword unmasked in profile 17, but actually I'm the responsible to install the new version. I think that I needed to keyword unmasked it in a previous world emerge. When I search for glibc dependencies I can't find now any software depending on it.

Since downgrading glibc can turn system unstable, I'll wait for opencv update to glibc-2.26.
Comment 17 Larry the Git Cow gentoo-dev 2018-01-21 08:36:34 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=b311829f28929c5dd15402b395365ccffb85ecd1

commit b311829f28929c5dd15402b395365ccffb85ecd1
Author:     Amy Liffey <amynka@gentoo.org>
AuthorDate: 2018-01-21 08:35:52 +0000
Commit:     Amy Liffey <amynka@gentoo.org>
CommitDate: 2018-01-21 08:36:21 +0000

    media-libs/opencv: fix cuda9 and autodownload
    
    - Fix cuda 9 compatibility
    Submitted-by: Todd Walter <twalter@rogers.com>
    
    - Remove autodownload tiny_dnn from contrib
    Submitted-by: Jonathan Scruggs <j.scruggs@gmail.com>
    
    - Add PYTHON_COMPAT 3_6
    
    Closes: https://bugs.gentoo.org/637078
    Closes: https://bugs.gentoo.org/633844
    Closes: https://bugs.gentoo.org/632116
    Package-Manager: Portage-2.3.13, Repoman-2.3.3

 media-libs/opencv/Manifest                         |   1 +
 .../opencv/files/opencv-3.3.0-cuda9-cmake.patch    |  87 ++++
 .../files/opencv-3.3.0-cuda9-compute20.patch       |  21 +
 .../opencv/files/opencv-3.3.0-cuda9-saturate.patch |  41 ++
 media-libs/opencv/metadata.xml                     |   1 +
 media-libs/opencv/opencv-3.3.0-r5.ebuild           | 466 +++++++++++++++++++++
 6 files changed, 617 insertions(+)