diff --git a/pkgs/development/r-modules/default.nix b/pkgs/development/r-modules/default.nix index 61b155993ecba..85ced5c2a3472 100644 --- a/pkgs/development/r-modules/default.nix +++ b/pkgs/development/r-modules/default.nix @@ -498,6 +498,12 @@ let textshaping = [ pkgs.pkg-config ]; ragg = [ pkgs.pkg-config ]; qqconf = [ pkgs.pkg-config ]; + torch = [ pkgs.cmake + pkgs.autoPatchelfHook + pkgs.addOpenGLRunpath + pkgs.cudaPackages.autoAddOpenGLRunpathHook + pkgs.patchelf + ]; }; packagesWithBuildInputs = { @@ -634,6 +640,11 @@ let ijtiff = [ pkgs.libtiff ]; ragg = with pkgs; [ freetype.dev libpng.dev libtiff.dev zlib.dev libjpeg.dev bzip2.dev ]; qqconf = [ pkgs.fftw.dev ]; + torch = [ + pkgs.cudaPackages_11_7.cudatoolkit.lib + pkgs.cudaPackages_11_7.cuda_nvtx + pkgs.cudaPackages_11_7.cudnn + ]; }; packagesRequiringX = [ @@ -1390,9 +1401,63 @@ let ''; }); - torch = old.torch.overrideAttrs (attrs: { + torch = let + version = "0.11.0"; + libtorch-for-r-torch = fetchurl { + url = "https://download.pytorch.org/libtorch/cu117/libtorch-cxx11-abi-shared-with-deps-1.13.1%2Bcu117.zip"; + sha256 = "sha256-hkLGZXroAnMKwfS0rkrZgO7iUVdlRH5HC4O0jM0ikt4="; + }; + liblantern-for-r-torch = fetchurl { + url = "https://storage.googleapis.com/torch-lantern-builds/binaries/refs/heads/cran/v${version}/latest/lantern-${version}+cu117+x86_64-Linux.zip"; + sha256 = "sha256-tfXRuTs0+IbFRm8SjfY0Rx1E+gnrcQZkUzMderq6hdY="; + }; + in old.torch.overrideAttrs (attrs: { + env = { + TORCH_URL = "${libtorch-for-r-torch}"; + LANTERN_URL = "${liblantern-for-r-torch}"; + CUDA = "11.7"; + }; + autoPatchelfIgnoreMissingDeps = [ + # This is the hardware-dependent userspace driver that comes from + # nvidia_x11 package. It must be deployed at runtime in + # /run/opengl-driver/lib or pointed at by LD_LIBRARY_PATH variable, rather + # than pinned in runpath + "libcuda.so.1" + ]; + dontStrip = true; + postFixup = '' + addAutoPatchelfSearchPath "$out/library/torch/lib" + + patchelf $out/library/torch/lib/libcudnn.so.8 --add-needed libcudnn_cnn_infer.so.8 + + pushd $out/library/torch/lib || exit 1 + for LIBNVRTC in ./libnvrtc* + do + case "$LIBNVRTC" in + ./libnvrtc-builtins*) true;; + ./libnvrtc*) patchelf "$LIBNVRTC" --add-needed libnvrtc-builtins* ;; + esac + done + popd || exit 1 + ''; preConfigure = '' patchShebangs configure + # substituteInPlace configure \ + # --replace "\$R_PACKAGE_DIR" "$out" + ''; + preInstall = '' + # export TORCH_PATH=$(pwd) + echo $TORCH_PATH + pwd + ls -al + ls -al src + echo $installPhase + echo $sourceRoot + ''; + postInstall = '' + $rCommand -e "torch::install_torch()" + # mkdir -p $out/library/torch/bin + # ln -s ${pkgs.libtorch-bin}/lib/lib/libtorch.so $out/library/torch/bin/torch.so ''; }); };