summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/warp-lang/libmathdx.nix
blob: 1de70997fd66ab656973bdac7e3258fb10468653 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
{
  _cuda,
  cudaPackages,
  fetchurl,
  lib,
  stdenvNoCC,
}:

stdenvNoCC.mkDerivation (finalAttrs: {
  # NOTE: The version used should match the version Warp requires:
  # https://github.com/NVIDIA/warp/blob/${version}/deps/libmathdx-deps.packman.xml
  pname = "libmathdx";
  version = "0.2.3";

  outputs = [
    "out"
    "static"
  ];

  src =
    let
      baseURL = "https://developer.nvidia.com/downloads/compute/cublasdx/redist/cublasdx";
      cudaMajorVersion = cudaPackages.cudaMajorVersion; # only 12, 13 supported
      cudaVersion = "${cudaMajorVersion}.0"; # URL example: ${baseURL}/cuda12/${name}-${version}-cuda12.0.zip
      name = lib.concatStringsSep "-" [
        finalAttrs.pname
        "Linux"
        stdenvNoCC.hostPlatform.parsed.cpu.name
        finalAttrs.version
        "cuda${cudaVersion}"
      ];

      # nix-hash --type sha256 --to-sri $(nix-prefetch-url "https://...")
      hashes = {
        "12" = {
          aarch64-linux = "sha256-d/aBC+zU2ciaw3isv33iuviXYaLGLdVDdzynGk9SFck=";
          x86_64-linux = "sha256-CHIH0s4SnA67COtHBkwVCajW/3f0VxNBmuDLXy4LFIg=";
        };
        "13" = {
          aarch64-linux = "sha256-TetJbMts8tpmj5PV4+jpnUHMcooDrXUEKL3aGWqilKI=";
          x86_64-linux = "sha256-wLJLbRpQWa6QEm8ibm1gxt3mXvkWvu0vEzpnqTIvE1M=";
        };
      };
    in
    lib.mapNullable (
      hash:
      fetchurl {
        inherit hash name;
        url = "${baseURL}/cuda${cudaMajorVersion}/${name}.tar.gz";
      }
    ) (hashes.${cudaMajorVersion}.${stdenvNoCC.hostPlatform.system} or null);

  dontUnpack = true;
  dontConfigure = true;
  dontBuild = true;

  installPhase = ''
    runHook preInstall

    mkdir -p "$out"
    tar -xzf "$src" -C "$out"

    mkdir -p "$static"
    moveToOutput "lib/libmathdx_static.a" "$static"

    runHook postInstall
  '';

  meta = {
    description = "Library used to integrate cuBLASDx and cuFFTDx into Warp";
    homepage = "https://developer.nvidia.com/cublasdx-downloads";
    sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
    license = with lib.licenses; [
      # By downloading and using the software, you agree to fully
      # comply with the terms and conditions of the NVIDIA Software
      # License Agreement.
      _cuda.lib.licenses.math_sdk_sla

      # Some of the libmathdx routines were written by or derived
      # from code written by Meta Platforms, Inc. and affiliates and
      # are subject to the BSD License.
      bsd3

      # Some of the libmathdx routines were written by or derived from
      # code written by Victor Zverovich and are subject to the following
      # license:
      mit
    ];
    platforms = [
      "aarch64-linux"
      "x86_64-linux"
    ];
    maintainers = with lib.maintainers; [ yzx9 ];
  };
})