I am having trouble getting cuda support in blender. I have a nvidia gtx970 gpu and have configured my system the following way after looking at various online information.
Can anyone spot where my issue lies?
nixos-version: 19.09.2079.8731aaaf8b3 (Loris)
nvidia-smi:
Sun Feb 16 21:40:40 2020
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.36 Driver Version: 440.36 CUDA Version: 10.2 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 970 Off | 00000000:01:00.0 Off | N/A |
| 30% 30C P8 9W / 180W | 990MiB / 4039MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 1037 G ...bppvdxn86lf8rv-xorg-server-1.20.5/bin/X 420MiB |
| 0 1617 G /run/current-system/sw/bin/kwin_x11 90MiB |
| 0 1619 G /run/current-system/sw/bin/krunner 2MiB |
| 0 1621 G /run/current-system/sw/bin/plasmashell 130MiB |
| 0 2340 G ...AAAAAAAAAAAAAAgAAAAAAAAA --shared-files 72MiB |
| 0 3929 G ...cker-5.16.5/libexec/kscreenlocker_greet 261MiB |
+-----------------------------------------------------------------------------+
configuration.nix:
{ config, pkgs, ... }:
let
unstableTarball =
fetchTarball https://github.com/NixOS/nixpkgs-channels/archive/nixos-unstable.tar.gz;
in
{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
];
boot = {
loader = {
systemd-boot.enable = true;
efi.canTouchEfiVariables = true;
};
kernelParams = [
"amd_iommu=on"
];
kernelModules = [
"kvm-amd"
"vfio-pci"
"nvidia-uvm"
];
extraModprobeConfig = ''
options kvm ignore_msrs=1
options vfio_pci ids=1002:67df,1002:aaf0
'';
blacklistedKernelModules = [
"radeon" "amdgpu"
];
};
networking.hostName = "thorium"; # Define your hostname.
# networking.wireless.enable = true; # Enables wireless support via wpa_supplicant.
# The global useDHCP flag is deprecated, therefore explicitly set to false here.
# Per-interface useDHCP will be mandatory in the future, so this generated config
# replicates the default behaviour.
networking.useDHCP = false;
networking.bridges = {
br0 = { interfaces = [ "enp5s0" ];
};
};
# networking.interfaces.enp5s0.useDHCP = true;
networking.interfaces.br0.useDHCP = true;
## Internationalisation properties.
# i18n = {
# consoleFont = "Lat2-Terminus16";
# consoleKeyMap = "us";
# defaultLocale = "en_US.UTF-8";
# };
time.timeZone = "Europe/Oslo";
# List packages installed in system profile. To search, run:
# $ nix search wget
nixpkgs.config = {
allowUnfree = true;
packageOverrides = pkgs: {
unstable = import unstableTarball {
config = config.nixpkgs.config;
};
};
blender = {
cudaSupport = true;
};
unstable.blender = {
cudaSupport = true;
};
};
environment.systemPackages = with pkgs; [
pciutils
wget
# vim
(import ../../modules/vim.nix)
wireguard
google-chrome
virtmanager-qt
barrier
git
steam
## From unstable
unstable.blender
];
programs = {
vim.defaultEditor = true;
};
## SERVICES ##
nix.gc = {
automatic = true;
dates = "weekly";
options = "--delete-older-than 30d";
};
services.openssh = {
enable = true;
forwardX11 = true;
};
# Security config.
security.sudo.wheelNeedsPassword = false;
# Open ports in the firewall.
# networking.firewall.allowedTCPPorts = [ ... ];
# networking.firewall.allowedUDPPorts = [ ... ];
# Or disable the firewall altogether.
# networking.firewall.enable = false;
virtualisation.libvirtd = {
enable = true;
qemuOvmf = true;
qemuRunAsRoot = false;
onBoot = "ignore";
};
# Enable CUPS to print documents.
# services.printing.enable = true;
# Enable sound.
sound.enable = true;
hardware.pulseaudio.enable = true;
# Enable the X11 windowing system.
services.xserver.enable = true;
services.xserver.videoDrivers = [ "nvidia" ];
hardware.opengl.driSupport32Bit = true;
hardware.opengl.extraPackages32 = with pkgs.pkgsi686Linux; [ libva ];
hardware.pulseaudio.support32Bit = true;
# Enable the KDE Desktop Environment.
services.xserver.displayManager.sddm.enable = true;
services.xserver.desktopManager.plasma5.enable = true;
# Define a user account. Don't forget to set a password with âpasswdâ.
users.users = {
sjakkmarius = {
isNormalUser = true;
extraGroups = [ "wheel" "libvirtd" ];
openssh.authorizedKeys.keys = [ "ssh-rsa ..." ];
};
};
# This value determines the NixOS release with which your system is to be
# compatible, in order to avoid breaking some software such as database
# servers. You should change this only after NixOS release notes say you
# should.
system.stateVersion = "19.09"; # Did you read the comment?
}
Solved by adding the cudatoolkit package to my configuration.nix
edit:
Might have been to quick to celebrate, when I try to render using Cycles and Cuda GPU I get an error and the console shows something missing:
CUDA version 10.2 detected, build may succeed but only CUDA 10.1 is officially supported.
Compiling CUDA kernel âŚ
ânvccâ -arch=sm_52 --cubin â/nix/store/nzci6fzx4v01blhiyfpgqvs8a39kd525-blender-2.82/share/blender/2.82/scripts/addons/cycles/source/kernel/kernels/cuda/kernel.cuâ -o â/home/marius/.cache/cycles/kernels/cycles_kernel_sm52_F80EBC91C56BBBB785E84E2EFB89D785.cubinâ -m64 --ptxas-options=â-vâ --use_fast_math -DNVCC -I"/nix/store/nzci6fzx4v01blhiyfpgqvs8a39kd525-blender-2.82/share/blender/2.82/scripts/addons/cycles/source"
cc1plus: fatal error: cuda_runtime.h: No such file or directory
My thought is that this is some directory or environment not exported due to some misconfiguration in my configuration.nix
If youâre using flakes, you can also use the blender-bin flake, which just wraps the upstream Blender binaries, so it has CUDA support. You can run the most recent stable version using nix run blender-bin, or enable it in a NixOS configuration:
Is there any reason CUDA is not integrated by default? Given how GPU rendering is famous in blender, I guess many people would expect it to be present by default, especially if itâs packed with the official distribution.
The best I could figure was that a bunch of Blenderâs dependencies also needed cuda enabled, and enabling it for the blender package alone didnât propagate to the dependencies.
n.b.: Enabling this will cause a whole bunch of packges to be rebuilt locally from scratch, ignoring the binary cache. blender-bin is easier unless you think you might benefit from whichever other packages on your system end up being gpu-accelerated by this change.
You shouldnât ever need to manually set CUDA_PATH, EXTRA_LDFLAGS, or really any other environment variables in order to use CUDA-enabled packages. If they are configured to use cudatoolkit but canât find it, then thatâs a bug with that package.
Just a question, if after the rebuilt, lets say someday I remove the cudaSupport = true;, will this rebuild the packages from scratch again? Or will I have to take some other steps to revert the packages back without the cuda?
Thanks to the purity of nix, the configuration of your system solely depends on what is written in your configuration. For instance, the blender derivation contains cudaSupport ? config.cudaSupport, so thatâs why enabling nixpkgs.config.cudaSupport = true; will give you cuda support. So if you remove that line, it will revert the system back to use the non-cuda version of blender (since blender is in the cache, it should not really build it, it will just download the package from the cache).
I think I will go the other route with nixpkgs.config.cudaSupport = true; (as I still am not well versed in flakes even though itâs my current system. So I donât know how to implement blender-bin flake yet )