From 333e7f2841bedba3c9b2b80b37d682a842ffea01 Mon Sep 17 00:00:00 2001 From: Andrew Marshall Date: Tue, 26 Mar 2024 18:45:42 -0400 Subject: [PATCH] openimagedenoise: Support building with CUDA It also has HIP, Metal, and SYCL support, but I do not have hardware to test any of those actually work. Further, Blender 4.1.0 does not enable GPU OIDN on AMD (HIP), but may in 4.2.0 it seems. --- .../libraries/openimagedenoise/cuda.patch | 32 +++++++++++++++++++ .../libraries/openimagedenoise/default.nix | 16 ++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 pkgs/development/libraries/openimagedenoise/cuda.patch diff --git a/pkgs/development/libraries/openimagedenoise/cuda.patch b/pkgs/development/libraries/openimagedenoise/cuda.patch new file mode 100644 index 000000000000..4bc5172d8830 --- /dev/null +++ b/pkgs/development/libraries/openimagedenoise/cuda.patch @@ -0,0 +1,32 @@ +Remove upstream workarounds for CMake "limitations" that do not appear to exist +in nixpkgs build environment, but rather break the build, presumably because +CMAKE_INSTALL_{BIN,LIB}DIR is an absolute path in our build so +CMAKE_INSTALL_PREFIX has no effect. + +diff --git a/devices/CMakeLists.txt b/devices/CMakeLists.txt +index d5111cd..43986ad 100644 +--- a/devices/CMakeLists.txt ++++ b/devices/CMakeLists.txt +@@ -53,7 +53,6 @@ if(OIDN_DEVICE_CUDA) + -DCMAKE_CXX_COMPILER:FILEPATH=${_host_compiler} + -DCMAKE_TOOLCHAIN_FILE:FILEPATH=${CMAKE_TOOLCHAIN_FILE} + -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} +- -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/cuda/preinstall + -DCMAKE_INSTALL_BINDIR:PATH=${CMAKE_INSTALL_BINDIR} + -DCMAKE_INSTALL_LIBDIR:PATH=${CMAKE_INSTALL_LIBDIR} + -DCUDAToolkit_ROOT:PATH=${CUDAToolkit_ROOT} +@@ -69,14 +68,6 @@ if(OIDN_DEVICE_CUDA) + DEPENDS + OpenImageDenoise_core + ) +- +- # Due to limitations of CMake, the module is pre-installed at build time to a temporary location, +- # and then copied to the real install location at install time. +- install(DIRECTORY +- ${CMAKE_CURRENT_BINARY_DIR}/cuda/preinstall/ +- DESTINATION "." +- USE_SOURCE_PERMISSIONS +- ) + endif() + + if(OIDN_DEVICE_HIP) diff --git a/pkgs/development/libraries/openimagedenoise/default.nix b/pkgs/development/libraries/openimagedenoise/default.nix index 136143468783..e2d9b66004ed 100644 --- a/pkgs/development/libraries/openimagedenoise/default.nix +++ b/pkgs/development/libraries/openimagedenoise/default.nix @@ -1,5 +1,8 @@ { cmake, + config, + cudaPackages, + cudaSupport ? config.cudaSupport, fetchzip, ispc, lib, @@ -18,14 +21,23 @@ stdenv.mkDerivation rec { sha256 = "sha256-ZIrs4oEb+PzdMh2x2BUFXKyu/HBlFb3CJX24ciEHy3Q="; }; + patches = lib.optional cudaSupport ./cuda.patch; + nativeBuildInputs = [ cmake python3 ispc - ]; - buildInputs = [ tbb ]; + ] ++ lib.optional cudaSupport cudaPackages.cuda_nvcc; + + buildInputs = + [ tbb ] + ++ lib.optionals cudaSupport [ + cudaPackages.cuda_cudart + cudaPackages.cuda_cccl + ]; cmakeFlags = [ + (lib.cmakeBool "OIDN_DEVICE_CUDA" cudaSupport) (lib.cmakeFeature "TBB_INCLUDE_DIR" "${tbb.dev}/include") (lib.cmakeFeature "TBB_ROOT" "${tbb}") ];