summary refs log tree commit diff
path: root/pkgs/test/cuda/cuda-samples/generic.nix
blob: e690f32959f2acf83d397decd02443503beb8c23 (plain) (blame)
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
{ autoAddOpenGLRunpathHook
, backendStdenv
, cmake
, cudatoolkit
, cudaVersion
, fetchFromGitHub
, fetchpatch
, freeimage
, glfw3
, lib
, pkg-config
, sha256
}:
backendStdenv.mkDerivation (finalAttrs: {
  pname = "cuda-samples";
  version = cudaVersion;

  src = fetchFromGitHub {
    owner = "NVIDIA";
    repo = finalAttrs.pname;
    rev = "v${finalAttrs.version}";
    inherit sha256;
  };

  nativeBuildInputs = [
    pkg-config
    autoAddOpenGLRunpathHook
    glfw3
    freeimage
  ]
  # CMake has to run as a native, build-time dependency for libNVVM samples.
  ++ lib.lists.optionals (lib.strings.versionAtLeast finalAttrs.version "12.2") [
    cmake
  ];

  # CMake is not the primary build tool -- that's still make.
  # As such, we disable CMake's build system.
  dontUseCmakeConfigure = true;

  buildInputs = [ cudatoolkit ];

  # See https://github.com/NVIDIA/cuda-samples/issues/75.
  patches = lib.optionals (finalAttrs.version == "11.3") [
    (fetchpatch {
      url = "https://github.com/NVIDIA/cuda-samples/commit/5c3ec60faeb7a3c4ad9372c99114d7bb922fda8d.patch";
      sha256 = "sha256-0XxdmNK9MPpHwv8+qECJTvXGlFxc+fIbta4ynYprfpU=";
    })
  ];

  enableParallelBuilding = true;

  preConfigure = ''
    export CUDA_PATH=${cudatoolkit}
  '';

  installPhase = ''
    runHook preInstall

    install -Dm755 -t $out/bin bin/${backendStdenv.hostPlatform.parsed.cpu.name}/${backendStdenv.hostPlatform.parsed.kernel.name}/release/*

    runHook postInstall
  '';

  meta = {
    description = "Samples for CUDA Developers which demonstrates features in CUDA Toolkit";
    # CUDA itself is proprietary, but these sample apps are not.
    license = lib.licenses.bsd3;
    maintainers = with lib.maintainers; [ obsidian-systems-maintenance ] ++ lib.teams.cuda.members;
  };
})