summaryrefslogtreecommitdiffstats
path: root/pkgs/development/cuda-modules/packages/libcudss.nix
blob: 6dc547d592bdc3bb5866315561bf196d16877c6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
{
  buildRedist,
  lib,
  libcublas,
  mpi,
  nccl,
}:
buildRedist {
  redistName = "cudss";
  pname = "libcudss";

  outputs = [
    "out"
    "dev"
    "include"
    "lib"
    "static"
  ];

  buildInputs = [
    libcublas
  ]
  # MPI brings in NCCL dependency by way of UCC/UCX.
  ++ lib.optionals nccl.meta.available [
    mpi
    nccl
  ];

  # Update the CMake configurations
  postFixup = ''
    pushd "''${!outputDev:?}/lib/cmake/cudss" >/dev/null

    nixLog "patching $PWD/cudss-config.cmake to fix relative paths"
    substituteInPlace "$PWD/cudss-config.cmake" \
      --replace-fail \
        'get_filename_component(PACKAGE_PREFIX_DIR "''${CMAKE_CURRENT_LIST_DIR}/../../../../" ABSOLUTE)' \
        "" \
      --replace-fail \
        'file(REAL_PATH "../../" _cudss_search_prefix BASE_DIRECTORY "''${_cudss_cmake_config_realpath}")' \
        "set(_cudss_search_prefix \"''${!outputDev:?}/lib;''${!outputLib:?}/lib;''${!outputInclude:?}/include\")"

    nixLog "patching $PWD/cudss-static-targets.cmake to fix INTERFACE_LINK_DIRECTORIES for cublas"
    sed -Ei \
      's|INTERFACE_LINK_DIRECTORIES "/usr/local/cuda.*/lib64"|INTERFACE_LINK_DIRECTORIES "${lib.getLib libcublas}/lib"|g' \
      "$PWD/cudss-static-targets.cmake"
    if grep -Eq 'INTERFACE_LINK_DIRECTORIES "/usr/local/cuda.*/lib64"' "$PWD/cudss-static-targets.cmake"; then
      nixErrorLog "failed to patch $PWD/cudss-static-targets.cmake"
      exit 1
    fi

    nixLog "patching $PWD/cudss-static-targets-release.cmake to fix the path to the static library"
    substituteInPlace "$PWD/cudss-static-targets-release.cmake" \
      --replace-fail \
        '"''${cudss_LIBRARY_DIR}/libcudss_static.a"' \
        "\"''${!outputStatic:?}/lib/libcudss_static.a\""

    popd >/dev/null
  '';

  meta = {
    description = "Library of GPU-accelerated linear solvers with sparse matrices";
    longDescription = ''
      NVIDIA cuDSS (Preview) is a library of GPU-accelerated linear solvers with sparse matrices.
    '';
    homepage = "https://developer.nvidia.com/cudss";
    changelog = "https://docs.nvidia.com/cuda/cudss/release_notes.html";
  };
}