From 0f4374d4f539c13a355fdee2dea0bbcc753f2827 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Mon, 26 Feb 2024 11:08:16 +0100 Subject: [PATCH] gpu rework --- hardware/gpu/cuda.nix | 26 ++++++++++++++------------ hardware/gpu/rocm.nix | 23 +++++++++-------------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/hardware/gpu/cuda.nix b/hardware/gpu/cuda.nix index 8ba9a66..aa24a12 100644 --- a/hardware/gpu/cuda.nix +++ b/hardware/gpu/cuda.nix @@ -2,12 +2,18 @@ { # assumes common-gpu-nvidia from nixos-hardware is also added # TODO: should we move it from flake.nix to here? + # https://github.com/NixOS/nixos-hardware/blob/master/common/gpu/nvidia/default.nix + # https://github.com/NixOS/nixos-hardware/blob/master/common/gpu/nvidia/prime.nix - # https://nixos.wiki/wiki/Nvidia + hardware.opengl.enable = true; + hardware.opengl.driSupport = true; + hardware.opengl.driSupport32Bit = true; - #https://nixpk.gs/pr-tracker.html?pr=235481 - #nixpkgs.config.cudaSupport = true; # TODO: TOO SLOW, BREAKS - #nixpkgs.config.nvidiaSupport = true; # TODO: slow? used only by zenith + nixpkgs.config.openglSupport = true; # why is this not set by hardware.opengl.enable ? + nixpkgs.config.cudaSupport = true; # TODO: TOO SLOW, BREAKS + nixpkgs.config.vdpauSupport = true; + nixpkgs.config.vaapiSupport = true; + nixpkgs.config.nvidiaSupport = true; # TODO: slow? used only by zenith nixpkgs.config.allowUnfreePredicate = pkg: lib.any (x: x) [ (lib.hasInfix "nvidia" (lib.toLower (lib.getName pkg))) @@ -16,23 +22,21 @@ (lib.hasInfix "cublas" (lib.toLower (lib.getName pkg))) ]; - hardware.opengl.enable = true; - hardware.opengl.driSupport = true; - hardware.opengl.driSupport32Bit = true; + # https://nixos.wiki/wiki/Nvidia + hardware.opengl.extraPackages = [ - #pkgs.vaapiVdpau + #pkgs.vaapiVdpau # added by nixos-hardware #pkgs.libvdpau-va-gl pkgs.nvidia-vaapi-driver ]; - hardware.nvidia.modesetting.enable = lib.mkDefault true; # needed for most wayland compositors hardware.nvidia.nvidiaSettings = lib.mkDefault true; virtualisation.docker.enableNvidia = lib.mkDefault true; virtualisation.podman.enableNvidia = lib.mkDefault true; - # only do this per-host + # only do these per-host #hardware.nvidia.open = lib.mkDefault true; # open source version of kernel module, only on driver 515.43.04+ #hardware.nvidia.powerManagement.enable = lib.mkDefault true; # Fix graphical corruption on suspend/resume @@ -44,7 +48,6 @@ #hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.latest; #hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.beta; - # add this to the host in question: #hardware.nvidia.prime = { # offload.enable = true; # # Bus IDs. You can find them using lspci, grepping for "3D" or "VGA" @@ -52,7 +55,6 @@ # nvidiaBusId = "PCI:1:0:0"; #}; - environment.systemPackages = [ pkgs.nvtop-nvidia ] ++ lib.optionals config.hardware.nvidia.prime.offload.enable [ diff --git a/hardware/gpu/rocm.nix b/hardware/gpu/rocm.nix index f050997..c29642a 100644 --- a/hardware/gpu/rocm.nix +++ b/hardware/gpu/rocm.nix @@ -2,31 +2,26 @@ { # assumes common-gpu-amd from nixos-hardware is also added # TODO: should we move it from flake.nix to here? - - # nixos-hardware common-amd options # https://github.com/NixOS/nixos-hardware/blob/master/common/gpu/amd/default.nix - hardware.amdgpu.opencl = true; - hardware.amdgpu.amdvlk = true; hardware.opengl.enable = true; - # https://libreddit.noximilien.pbsds.net/r/archlinux/comments/nih9c9/amdgpu_vs_modesetting_in_current_510_kernels_xorg/ - services.xserver.videoDrivers = [ "amdgpu" ]; # use gpu, adaptive sync and and hardware page flipping - #services.xserver.videoDrivers = [ "modesetting" ]; # integrated (non-accelerated) framebuffer, KMS hardware.opengl.driSupport = true; hardware.opengl.driSupport32Bit = true; - hardware.opengl.extraPackages = [ - pkgs.rocm-opencl-icd - (if (lib.versionOlder (lib.versions.majorMinor lib.version) "23.11") - then pkgs.rocm-runtime#-ext - else pkgs.rocmPackages.rocm-runtime - ) - ]; nixpkgs.config.openglSupport = true; # why is this not set by hardware.opengl.enable ? nixpkgs.config.rocmSupport = true; nixpkgs.config.vdpauSupport = true; nixpkgs.config.vaapiSupport = true; + # nixos-hardware common-amd options + # https://github.com/NixOS/nixos-hardware/blob/master/common/gpu/amd/default.nix + hardware.amdgpu.opencl = lib.mkDefault true; + hardware.amdgpu.amdvlk = lib.mkDefault false; + + # https://libreddit.noximilien.pbsds.net/r/archlinux/comments/nih9c9/amdgpu_vs_modesetting_in_current_510_kernels_xorg/ + services.xserver.videoDrivers = [ "amdgpu" ]; # use gpu, adaptive sync and and hardware page flipping + #services.xserver.videoDrivers = [ "modesetting" ]; # integrated (non-accelerated) framebuffer, KMS (default in nixos-hardware) + # https://nixos.wiki/wiki/AMD_GPU#HIP systemd.tmpfiles.rules = let hip = if (lib.versionOlder (lib.versions.majorMinor lib.version) "23.11")