Files
nixpkgs/pkgs/development/cuda-modules/packages/libcusparse.nix
Connor Baker 67e5bee8a6 cudaPackages: account for dlopen'd runtime dependencies
autoPatchelfHook only resolves DT_NEEDED entries, so a library reached
only through dlopen never lands in any RUNPATH -- listing its provider
in buildInputs contributes nothing. Several components dlopen by bare
soname and so silently lose those libraries at runtime.

Add the missing paths with appendRunpaths for the redists, and an
explicit postFixup for the two source builds, which do not go through
buildRedist:

- cudnn, libcublas, libcufft, libcusparse, libcusparse_lt: NVRTC and
  nvJitLink, dlopen'd to compile kernels at runtime. libcublas gained
  the dlopen in 12.8 and libcusparse_lt in 0.8, so both are
  version-gated. libcusparse's libnvJitLink moved from DT_NEEDED to
  dlopen at 12.7.3.1; the entry is left unconditional because it is a
  no-op before that.
- libcufile: libudev, libmount, liburcu and libnuma.
- nccl, libnvshmem: libibverbs, libmlx5 and libgdrapi. NCCL builds
  with RDMA_CORE=0 and MLX5DV=0, so none of these are DT_NEEDED;
  without this NCCL logs at INFO and silently falls back to the socket
  transport. Both also gain autoAddDriverRunpath, which nothing was
  supplying -- libnccl dlopens libnvidia-ml.so.1, and the statically
  linked CUDA runtime dlopens libcuda.so.1.

Also:

- cuda_cupti: ship the static archives as their own output on
  linux-sbsa, where they were previously left in the propagated lib
  output. Gate on hostRedistSystem, since linux-aarch64 ships no
  archives at all and declaring an empty output fails the build.
- libcuobjclient: declare rdma-core, which had been resolved only by
  accident through libcufile's runpath.
- libcusolver: note the vendored METIS in meta.license.

Verified across cudaPackages_12_6 through _13_3 on linux-x86_64 and
linux-sbsa, and on linux-aarch64 for the CUDA 12 releases where that
redist system exists. nccl is unavailable on linux-aarch64, since
pre-Thor Jetsons are unsupported upstream, so libnvshmem builds there
with withNccl disabled.

Known and deliberately left alone: appendRunpaths is applied to every
ELF in every output, so it also writes into stubs outputs, where the
entries are inert. Nothing in-tree consumes the affected stubs
outputs.

Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-07 07:38:38 +00:00

43 lines
1.3 KiB
Nix

{
buildRedist,
cudaAtLeast,
lib,
libnvjitlink,
}:
buildRedist {
redistName = "cuda";
pname = "libcusparse";
outputs = [
"out"
"dev"
"include"
"lib"
"static"
"stubs"
];
# Through 12.6.3.3 libnvJitLink is DT_NEEDED and the buildInputs entry below covers it; from
# 12.7.3.1 it is dlopen'd instead, so it needs a runpath. Unconditional from 12.0 because the
# entry is a no-op on the releases which already resolve it. 12.7.x asks for the unversioned
# soname, so the providing output must carry the .so symlink. Gated like the buildInputs entry:
# libnvjitlink does not exist before CUDA 12.0, and libcusparse does not reference it there.
appendRunpaths = lib.optionals (cudaAtLeast "12.0") [
"${lib.getLib libnvjitlink}/lib" # libnvJitLink.so, libnvJitLink.so.%s
];
buildInputs =
# Dependency from 12.0 and on
lib.optionals (cudaAtLeast "12.0") [ libnvjitlink ];
meta = {
description = "GPU-accelerated basic linear algebra subroutines for sparse matrix computations for unstructured sparsity";
longDescription = ''
The cuSPARSE APIs provides GPU-accelerated basic linear algebra subroutines for sparse matrix computations for
unstructured sparsity.
'';
homepage = "https://developer.nvidia.com/cusparse";
changelog = "https://docs.nvidia.com/cuda/cusparse";
};
}