Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing CUDA .pc files #54395

Closed
nh2 opened this issue Jan 21, 2019 · 3 comments
Closed

Missing CUDA .pc files #54395

nh2 opened this issue Jan 21, 2019 · 3 comments
Labels
2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: cuda

Comments

@nh2
Copy link
Contributor

nh2 commented Jan 21, 2019

Issue description

On my Ubuntu with CUDA installed I have:

/usr/lib/pkgconfig/cuda-8.0.pc
/usr/lib/pkgconfig/cudart-8.0.pc

There seems to be no nixpkgs equivalent of those.

That apparently makes packaging support for CUDA-capabale applications hard, e.g. I cannot manage to add a flag to gstreamer's gst-plugins-bad because its Meson build system cannot find e.g. cuda-9.2.so and cudart-9.2.so in https://github.com/GStreamer/gst-plugins-bad/blob/f710b36ac4935bd6123df15a191c1fe089c4c233/sys/meson.build#L63-L84

Possible solution

  • libcuda.so is provided by the nvidia driver in linuxPackages.nvidia_x11
  • libcudart.so is provided by cudatoolkit.lib see here

We could generate .pc files ourselves, rough sketch:

  cuda-pc = writeTextFile {
    name = "cuda-9.2.pc"; # TODO unhardcode
    text = ''
      cudaroot=${cudatoolkit}
      libdir=''${cudaroot}/lib64
      includedir=''${cudaroot}/include

      Name: cuda
      Description: CUDA Driver Library
      Version: ${cudaPkgconfigVersionString}
      Libs: -L''${libdir} -lcuda
      Cflags: -I''${includedir}
    '';
  };

  cudart-pc = writeTextFile {
    name = "cudart-9.2.pc"; # TODO unhardcode
    text = ''
      cudaroot=${linuxPackages.nvidia_x11}
      libdir=''${cudaroot}/lib64
      includedir=''${cudaroot}/include

      Name: cudart
      Description: CUDA Runtime Library
      Version: ${cudaPkgconfigVersionString}
      Libs: -L''${libdir} -lcudart
      Cflags: -I''${includedir}
    '';
  };

or e.g. for the case of installPhase in cudatoolkit/default.nix:

        # Generate cudart-*.pc
        mkdir -p $lib/lib/pkgconfig
        cat > $lib/lib/pkgconfig/cudart-${cudaPkgconfigVersionString}.pc <<EOF
        cudaroot=$out
        libdir=''${cudaroot}/lib64
        includedir=''${cudaroot}/include

        Name: cudart
        Description: CUDA Runtime Library
        Version: ${cudaPkgconfigVersionString}
        Libs: -L''${libdir} -lcudart
        Cflags: -I''${includedir}
        EOF

with helper functions:

    let
      # Compute version for .pc file, like `cuda-9.2.pc`
      versionComponents = stdenv.lib.splitString "." version;
      major = builtins.elemAt versionComponents 0;
      minor = builtins.elemAt versionComponents 1;
      cudaPkgconfigVersionString = "${major}.${minor}";
@stale
Copy link

stale bot commented Jun 3, 2020

Thank you for your contributions.

This has been automatically marked as stale because it has had no activity for 180 days.

If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.

Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse.
  3. Ask on the #nixos channel on irc.freenode.net.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 3, 2020
@r-burns
Copy link
Contributor

r-burns commented Sep 22, 2021

It looks like these .pc files are only introduced by downstream packagers, like Arch (https://aur.archlinux.org/cgit/aur.git/tree/cuda.pc?h=cuda-11.1) and Debian (https://salsa.debian.org/nvidia-team/nvidia-cuda-toolkit/-/blob/master/debian/cuda.pc.in). If that's enough to consider them a de facto standard, we can certainly do the same. However, I'd also say that gstreamer should be more distro-agnostic here.

Note that libcuda.so should be linked using the toolkit stub at compile-time, and rpath-patched using addOpenGLRunpath so it picks up the correct cuda driver from the running system. So I think the correct libdir for cuda.pc would be more like ${cudatoolkit}/lib/stubs

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Sep 22, 2021
@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Oct 1, 2022
@SomeoneSerge
Copy link
Contributor

The new redist packages (everything under cudaPackages that begins with cuda_ or lib) ships .pc files. There's another issue with them, we do not yet patch the FHS paths out: tracking in #224119

Didn't check the old run-file based cudatoolkit, feel free to re-open

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: cuda
Projects
Status: Done
Development

No branches or pull requests

3 participants