Hello wonderful People :),
I am new to the whole nix ecosystem but super happy that I found it.
For one week now I am stuck with the following problem:
I want to use OpenCV4 with Cuda support in my project.
For the purpose of testing i kept it simple:
int main(){
cuda::GpuMat gpfoo;
Mat test = Mat::eye(Size(600, 600), CV_32FC3);
gpfoo.upload(test);
return 0;
}
My default.nix looks like this:
{ pkgs ? import <nixpkgs> {} } :
with pkgs;
let
opencv4cuda = opencv4.override { enableGtk3 = true;
enableFfmpeg = true;
enableCuda = true;
enableUnfree = true;};
in
stdenv.mkDerivation {
name = "cvCuda_test";
src = ./.;
buildInputs = [ cudatoolkit opencv4cuda ];
nativeBuildInputs = [ pkgconfig libconfig cmake ];
}
I can compile inside a nix-shell with:
nix-shell --pure --command \
"cmake -H. -Bbuild/ -DCMAKE_BUILD_TYPE=$btype && cmake --build build/. -j12"
And it compiles fine - using the “right” version of cv and cuda from the nix-store. Yay! … BUT:
When i start the program it crashes with:
OpenCV(4.3.0) /build/source/modules/core/src/cuda/gpu_mat.cu:116: error: (-217:Gpu API call) CUDA driver version is insufficient for CUDA runtime version in function 'allocate'
The error code is pretty straightforward. If i compile the project “normally” outside the nix-shell, everything works fine (with identical cuda and cv versions!)
So my Idea was, maybe he did not find the necessary drivers for Cuda in the nix-store;
So I read this: CUDA setup on NixOS - #6 by Aeschylus
And this: Nvidia - NixOS Wiki
But any suggested changes to my default.nix resulted in the same error
(in the end i got this abomination:
{ pkgs ? import <nixpkgs> {} } :
with pkgs;
let
opencv4cuda = opencv4.override { enableGtk3 = true;
enableFfmpeg = true;
enableCuda = true;
enableUnfree = true; };
in
stdenv.mkDerivation {
name = "cvCuda_test";
src = ./.;
buildInputs = [ git gitRepo gnupg autoconf curl
procps gnumake utillinux m4 gperf unzip
cudatoolkit linuxPackages.nvidia_x11
xorg.libXi xorg.libXmu freeglut
xorg.libXext xorg.libX11 xorg.libXv xorg.libXrandr zlib
ncurses5 stdenv.cc binutils
opencv4cuda
];
shellHook = ''
export CUDA_PATH=${pkgs.cudatoolkit}
export LD_LIBRARY_PATH=${pkgs.linuxPackages.nvidia_x11}/lib:${pkgs.ncurses5}/lib:/run/opengl-driver/lib
export EXTRA_LDFLAGS="-L/lib -L${pkgs.linuxPackages.nvidia_x11}/lib"
export EXTRA_CCFLAGS="-I/usr/include"
'';
postFixup = ''
addOpenGLRunpath $out/bin/add # i guess this isn't needed but whatever
wrapProgram $out/bin/add --prefix LD_LIBRARY_PATH ":" "/run/opengl-driver/lib"
'';
nativeBuildInputs = [ pkgconfig libconfig cmake ];
}
)
Has anyone some experience with this topic ? Or even uses opencv with cuda ?
I would be happy for any suggestions or links to further reading that get’s me closer to a solution
Just as info: I use nix version 2.3.4 on ArchLinux
Thanks!