summaryrefslogtreecommitdiffstats
path: root/pkgs/development/cuda-modules/packages/cccl.nix
blob: 181d073c47a9f1a604d697717f5a80b9cc576d6a (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,
  cudaAtLeast,
  cudaOlder,
  lib,
  fetchpatch,
}:
buildRedist {
  redistName = "cuda";
  pname = if cudaAtLeast "13.3" then "cccl" else "cuda_cccl";

  # Restrict header-only packages to a single output.
  # Also, when using multiple outputs (i.e., `out`, `dev`, and `include`), something isn't being patched correctly,
  # so libnvshmem fails to build, complaining about being unable to find the thrust include directory. This is likely
  # because the `dev` output contains the CMake configuration and is written to assume it will share a parent
  # directory with the include directory rather than be in a separate output.
  outputs = [ "out" ];

  prePatch = lib.optionalString (cudaAtLeast "13.0") ''
    nixLog "removing top-level $PWD/include/nv directory"
    rm -rfv "$PWD/include/nv"
    nixLog "un-nesting top-level $PWD/include/cccl directory"
    mv -v "$PWD/include/cccl"/* "$PWD/include/"
    nixLog "removing empty $PWD/include/cccl directory"
    rmdir -v "$PWD/include/cccl"
  '';

  patches =
    lib.optionals (cudaAtLeast "12.9" && cudaOlder "13.0") [
      # Fix missing _CCCL_PP_SPLICE_WITH_IMPL20 in preprocessor.h
      # https://github.com/NVIDIA/cccl/issues/4967
      # https://github.com/NVIDIA/cccl/pull/4972
      (fetchpatch {
        name = "fix-missing-_CCCL_PP_SPLICE_WITH_IMPL20";
        url = "https://github.com/NVIDIA/cccl/commit/2c2276d8b19d737cb16811ce2eb761030f472e60.patch";
        stripLen = 1;
        hash = "sha256-hYfMFsd7Y8CwuNGaPYG6uEB+lg1TmWSIIU5ToVMULKY=";
      })
    ]
    ++ lib.optionals (cudaAtLeast "13.2" && cudaOlder "13.4") [
      # Fix onnxruntime compilation error: https://github.com/microsoft/onnxruntime/issues/28023
      # Backport: https://github.com/NVIDIA/cccl/pull/8771
      (fetchpatch {
        name = "fix-invalid-cpp-syntax";
        url = "https://github.com/NVIDIA/cccl/commit/8e41eeabe54ab9ae48ad5640cfa7153b0a1071af.patch";
        stripLen = 2;
        extraPrefix = "include/";
        hash = "sha256-eko1GSD2NPSLtbQ3diwgKMbuS6wU9lHDOajLJy5lBwM=";
      })
    ];

  # NVIDIA, in their wisdom, expect CCCL to be a directory inside include.
  # https://github.com/NVIDIA/cutlass/blob/087c84df83d254b5fb295a7a408f1a1d554085cf/CMakeLists.txt#L773
  postInstall = lib.optionalString (cudaAtLeast "13.0") ''
    nixLog "creating alias for ''${!outputInclude:?}/include/cccl"
    ln -srv "''${!outputInclude:?}/include" "''${!outputInclude:?}/include/cccl"
  '';

  meta = {
    description = "Building blocks that make it easier to write safe and efficient CUDA C++ code";
    longDescription = ''
      The goal of CCCL is to provide CUDA C++ developers with building blocks that make it easier to write safe and
      efficient code.
    '';
    homepage = "https://github.com/NVIDIA/cccl";
    changelog = "https://github.com/NVIDIA/cccl/releases";
  };
}