about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/cuda-modules/cuda-samples
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/cuda-modules/cuda-samples')
-rw-r--r--nixpkgs/pkgs/development/cuda-modules/cuda-samples/extension.nix42
-rw-r--r--nixpkgs/pkgs/development/cuda-modules/cuda-samples/generic.nix79
2 files changed, 121 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/cuda-modules/cuda-samples/extension.nix b/nixpkgs/pkgs/development/cuda-modules/cuda-samples/extension.nix
new file mode 100644
index 000000000000..d41da90cd5d0
--- /dev/null
+++ b/nixpkgs/pkgs/development/cuda-modules/cuda-samples/extension.nix
@@ -0,0 +1,42 @@
+{
+  cudaVersion,
+  hostPlatform,
+  lib,
+}:
+let
+  cudaVersionToHash = {
+    "10.0" = "sha256-XAI6iiPpDVbZtFoRaP1s6VKpu9aV3bwOqqkw33QncP8=";
+    "10.1" = "sha256-DY8E2FKCFj27jPgQEB1qE9HcLn7CfSiVGdFm+yFQE+k=";
+    "10.2" = "sha256-JDW4i7rC2MwIRvKRmUd6UyJZI9bWNHqZijrB962N4QY=";
+    "11.0" = "sha256-BRwQuUvJEVi1mTbVtGODH8Obt7rXFfq6eLH9wxCTe9g=";
+    "11.1" = "sha256-kM8gFItBaTpkoT34vercmQky9qTFtsXjXMGjCMrsUc4=";
+    "11.2" = "sha256-gX6V98dRwdAQIsvru2byDLiMswCW2lrHSBSJutyWONw=";
+    "11.3" = "sha256-34MdMFS2cufNbZVixFdSUDFfLeuKIGFwLBL9d81acU0=";
+    "11.4" = "sha256-Ewu+Qk6GtGXC37CCn1ZXHc0MQAuyXCGf3J6T4cucTSA=";
+    "11.5" = "sha256-AKRZbke0K59lakhTi8dX2cR2aBuWPZkiQxyKaZTvHrI=";
+    "11.6" = "sha256-AsLNmAplfuQbXg9zt09tXAuFJ524EtTYsQuUlV1tPkE=";
+    # The tag 11.7 of cuda-samples does not exist
+    "11.8" = "sha256-7+1P8+wqTKUGbCUBXGMDO9PkxYr2+PLDx9W2hXtXbuc=";
+    "12.0" = "sha256-Lj2kbdVFrJo5xPYPMiE4BS7Z8gpU5JLKXVJhZABUe/g=";
+    "12.1" = "sha256-xE0luOMq46zVsIEWwK4xjLs7NorcTIi9gbfZPVjIlqo=";
+    "12.2" = "sha256-pOy0qfDjA/Nr0T9PNKKefK/63gQnJV2MQsN2g3S2yng=";
+    "12.3" = "sha256-fjVp0G6uRCWxsfe+gOwWTN+esZfk0O5uxS623u0REAk=";
+  };
+
+  # Samples are built around the CUDA Toolkit, which is not available for
+  # aarch64. Check for both CUDA version and platform.
+  cudaVersionIsSupported = cudaVersionToHash ? ${cudaVersion};
+  platformIsSupported = hostPlatform.isx86_64;
+  isSupported = cudaVersionIsSupported && platformIsSupported;
+
+  # Build our extension
+  extension =
+    final: _:
+    lib.attrsets.optionalAttrs isSupported {
+      cuda-samples = final.callPackage ./generic.nix {
+        inherit cudaVersion;
+        hash = cudaVersionToHash.${cudaVersion};
+      };
+    };
+in
+extension
diff --git a/nixpkgs/pkgs/development/cuda-modules/cuda-samples/generic.nix b/nixpkgs/pkgs/development/cuda-modules/cuda-samples/generic.nix
new file mode 100644
index 000000000000..fb3d7cc99da9
--- /dev/null
+++ b/nixpkgs/pkgs/development/cuda-modules/cuda-samples/generic.nix
@@ -0,0 +1,79 @@
+{
+  autoAddOpenGLRunpathHook,
+  backendStdenv,
+  cmake,
+  cudatoolkit,
+  cudaVersion,
+  fetchFromGitHub,
+  fetchpatch,
+  freeimage,
+  glfw3,
+  hash,
+  lib,
+  pkg-config,
+}:
+let
+  inherit (lib) lists strings;
+in
+backendStdenv.mkDerivation (
+  finalAttrs: {
+    strictDeps = true;
+
+    pname = "cuda-samples";
+    version = cudaVersion;
+
+    src = fetchFromGitHub {
+      owner = "NVIDIA";
+      repo = finalAttrs.pname;
+      rev = "v${finalAttrs.version}";
+      inherit hash;
+    };
+
+    nativeBuildInputs =
+      [
+        autoAddOpenGLRunpathHook
+        pkg-config
+      ]
+      # CMake has to run as a native, build-time dependency for libNVVM samples.
+      # However, it's not the primary build tool -- that's still make.
+      # As such, we disable CMake's build system.
+      ++ lists.optionals (strings.versionAtLeast finalAttrs.version "12.2") [cmake];
+
+    dontUseCmakeConfigure = true;
+
+    buildInputs = [
+      cudatoolkit
+      freeimage
+      glfw3
+    ];
+
+    # 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";
+        hash = "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;
+    };
+  }
+)