uboot: (firmwareOdroidC2/C4) don't invoke patch tool, use patches = [] instead
https://github.com/NixOS/nixpkgs/blob/master/pkgs/stdenv/generic/setup.sh#L948 this can do it nicely. Signed-off-by: Anton Arapov <anton@deadbeef.mx>
This commit is contained in:
commit
56de2bcd43
30691 changed files with 3076956 additions and 0 deletions
103
pkgs/development/libraries/science/math/libtorch/bin.nix
Normal file
103
pkgs/development/libraries/science/math/libtorch/bin.nix
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
{ callPackage
|
||||
, stdenv
|
||||
, fetchzip
|
||||
, lib
|
||||
, libcxx
|
||||
|
||||
, addOpenGLRunpath
|
||||
, patchelf
|
||||
, fixDarwinDylibNames
|
||||
|
||||
, cudaSupport
|
||||
}:
|
||||
|
||||
let
|
||||
# The binary libtorch distribution statically links the CUDA
|
||||
# toolkit. This means that we do not need to provide CUDA to
|
||||
# this derivation. However, we should ensure on version bumps
|
||||
# that the CUDA toolkit for `passthru.tests` is still
|
||||
# up-to-date.
|
||||
version = "1.10.0";
|
||||
device = if cudaSupport then "cuda" else "cpu";
|
||||
srcs = import ./binary-hashes.nix version;
|
||||
unavailable = throw "libtorch is not available for this platform";
|
||||
libcxx-for-libtorch = if stdenv.hostPlatform.system == "x86_64-darwin" then libcxx else stdenv.cc.cc.lib;
|
||||
in stdenv.mkDerivation {
|
||||
inherit version;
|
||||
pname = "libtorch";
|
||||
|
||||
src = fetchzip srcs."${stdenv.targetPlatform.system}-${device}" or unavailable;
|
||||
|
||||
nativeBuildInputs =
|
||||
if stdenv.isDarwin then [ fixDarwinDylibNames ]
|
||||
else [ patchelf ] ++ lib.optionals cudaSupport [ addOpenGLRunpath ];
|
||||
|
||||
dontBuild = true;
|
||||
dontConfigure = true;
|
||||
dontStrip = true;
|
||||
|
||||
installPhase = ''
|
||||
# Copy headers and CMake files.
|
||||
mkdir -p $dev
|
||||
cp -r include $dev
|
||||
cp -r share $dev
|
||||
|
||||
install -Dm755 -t $out/lib lib/*${stdenv.hostPlatform.extensions.sharedLibrary}*
|
||||
|
||||
# We do not care about Java support...
|
||||
rm -f $out/lib/lib*jni* 2> /dev/null || true
|
||||
|
||||
# Fix up library paths for split outputs
|
||||
substituteInPlace $dev/share/cmake/Torch/TorchConfig.cmake \
|
||||
--replace \''${TORCH_INSTALL_PREFIX}/lib "$out/lib" \
|
||||
|
||||
substituteInPlace \
|
||||
$dev/share/cmake/Caffe2/Caffe2Targets-release.cmake \
|
||||
--replace \''${_IMPORT_PREFIX}/lib "$out/lib" \
|
||||
'';
|
||||
|
||||
postFixup = let
|
||||
rpath = lib.makeLibraryPath [ stdenv.cc.cc.lib ];
|
||||
in lib.optionalString stdenv.isLinux ''
|
||||
find $out/lib -type f \( -name '*.so' -or -name '*.so.*' \) | while read lib; do
|
||||
echo "setting rpath for $lib..."
|
||||
patchelf --set-rpath "${rpath}:$out/lib" "$lib"
|
||||
${lib.optionalString cudaSupport ''
|
||||
addOpenGLRunpath "$lib"
|
||||
''}
|
||||
done
|
||||
'' + lib.optionalString stdenv.isDarwin ''
|
||||
for f in $out/lib/*.dylib; do
|
||||
otool -L $f
|
||||
done
|
||||
for f in $out/lib/*.dylib; do
|
||||
install_name_tool -id $out/lib/$(basename $f) $f || true
|
||||
for rpath in $(otool -L $f | grep rpath | awk '{print $1}');do
|
||||
install_name_tool -change $rpath $out/lib/$(basename $rpath) $f
|
||||
done
|
||||
if otool -L $f | grep /usr/lib/libc++ >& /dev/null; then
|
||||
install_name_tool -change /usr/lib/libc++.1.dylib ${libcxx-for-libtorch.outPath}/lib/libc++.1.0.dylib $f
|
||||
fi
|
||||
done
|
||||
for f in $out/lib/*.dylib; do
|
||||
otool -L $f
|
||||
done
|
||||
'';
|
||||
|
||||
outputs = [ "out" "dev" ];
|
||||
|
||||
passthru.tests.cmake = callPackage ./test {
|
||||
inherit cudaSupport;
|
||||
};
|
||||
|
||||
meta = with lib; {
|
||||
description = "C++ API of the PyTorch machine learning framework";
|
||||
homepage = "https://pytorch.org/";
|
||||
# Includes CUDA and Intel MKL, but redistributions of the binary are not limited.
|
||||
# https://docs.nvidia.com/cuda/eula/index.html
|
||||
# https://www.intel.com/content/www/us/en/developer/articles/license/onemkl-license-faq.html
|
||||
license = licenses.bsd3;
|
||||
maintainers = with maintainers; [ junjihashimoto ];
|
||||
platforms = platforms.unix;
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
version : builtins.getAttr version {
|
||||
"1.10.0" = {
|
||||
x86_64-darwin-cpu = {
|
||||
name = "libtorch-macos-1.10.0.zip";
|
||||
url = "https://download.pytorch.org/libtorch/cpu/libtorch-macos-1.10.0.zip";
|
||||
hash = "sha256-HSisxHs466c6XwvZEbkV/1kVNBzJOy3uVw9Bh497Vk8=";
|
||||
};
|
||||
x86_64-linux-cpu = {
|
||||
name = "libtorch-cxx11-abi-shared-with-deps-1.10.0-cpu.zip";
|
||||
url = "https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-1.10.0%2Bcpu.zip";
|
||||
hash = "sha256-wAtA+AZx3HjaFbsrbyfkSXjYM0BP8H5HwCgyHbgJXJ0=";
|
||||
};
|
||||
x86_64-linux-cuda = {
|
||||
name = "libtorch-cxx11-abi-shared-with-deps-1.10.0-cu113.zip";
|
||||
url = "https://download.pytorch.org/libtorch/cu113/libtorch-cxx11-abi-shared-with-deps-1.10.0%2Bcu113.zip";
|
||||
hash = "sha256-jPylK4j0V8SEQ8cZU+O22P7kQ28wanIB0GkBzRGyTj8=";
|
||||
};
|
||||
};
|
||||
}
|
||||
38
pkgs/development/libraries/science/math/libtorch/prefetch.sh
Executable file
38
pkgs/development/libraries/science/math/libtorch/prefetch.sh
Executable file
|
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env nix-shell
|
||||
#!nix-shell -i bash -p nix-prefetch-scripts
|
||||
|
||||
set -eou pipefail
|
||||
|
||||
version=$1
|
||||
|
||||
bucket="https://download.pytorch.org/libtorch"
|
||||
CUDA_VERSION=cu113
|
||||
|
||||
url_and_key_list=(
|
||||
"x86_64-darwin-cpu $bucket/cpu/libtorch-macos-${version}.zip libtorch-macos-${version}.zip"
|
||||
"x86_64-linux-cpu $bucket/cpu/libtorch-cxx11-abi-shared-with-deps-${version}%2Bcpu.zip libtorch-cxx11-abi-shared-with-deps-${version}-cpu.zip"
|
||||
"x86_64-linux-cuda $bucket/${CUDA_VERSION}/libtorch-cxx11-abi-shared-with-deps-${version}%2B${CUDA_VERSION}.zip libtorch-cxx11-abi-shared-with-deps-${version}-${CUDA_VERSION}.zip"
|
||||
)
|
||||
|
||||
hashfile="binary-hashes-$version.nix"
|
||||
echo " \"$version\" = {" >> $hashfile
|
||||
|
||||
for url_and_key in "${url_and_key_list[@]}"; do
|
||||
key=$(echo "$url_and_key" | cut -d' ' -f1)
|
||||
url=$(echo "$url_and_key" | cut -d' ' -f2)
|
||||
name=$(echo "$url_and_key" | cut -d' ' -f3)
|
||||
|
||||
echo "prefetching ${url}..."
|
||||
hash=$(nix hash to-sri --type sha256 $(nix-prefetch-url --unpack "$url" --name "$name"))
|
||||
|
||||
echo " $key = {" >> $hashfile
|
||||
echo " name = \"$name\";" >> $hashfile
|
||||
echo " url = \"$url\";" >> $hashfile
|
||||
echo " hash = \"$hash\";" >> $hashfile
|
||||
echo " };" >> $hashfile
|
||||
|
||||
echo
|
||||
done
|
||||
|
||||
echo " };" >> $hashfile
|
||||
echo "done."
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
cmake_minimum_required(VERSION 3.0)
|
||||
find_package(Torch REQUIRED)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
|
||||
add_executable(test test.cpp)
|
||||
target_link_libraries(test "${TORCH_LIBRARIES}")
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
{ lib
|
||||
, stdenv
|
||||
, cmake
|
||||
, libtorch-bin
|
||||
, linkFarm
|
||||
, symlinkJoin
|
||||
|
||||
, cudaSupport
|
||||
, cudaPackages ? {}
|
||||
}:
|
||||
let
|
||||
inherit (cudaPackages) cudatoolkit cudnn;
|
||||
|
||||
cudatoolkit_joined = symlinkJoin {
|
||||
name = "${cudatoolkit.name}-unsplit";
|
||||
paths = [ cudatoolkit.out cudatoolkit.lib ];
|
||||
};
|
||||
|
||||
# We do not have access to /run/opengl-driver/lib in the sandbox,
|
||||
# so use a stub instead.
|
||||
cudaStub = linkFarm "cuda-stub" [{
|
||||
name = "libcuda.so.1";
|
||||
path = "${cudatoolkit}/lib/stubs/libcuda.so";
|
||||
}];
|
||||
|
||||
in stdenv.mkDerivation {
|
||||
pname = "libtorch-test";
|
||||
version = libtorch-bin.version;
|
||||
|
||||
src = ./.;
|
||||
|
||||
nativeBuildInputs = [ cmake ];
|
||||
|
||||
buildInputs = [ libtorch-bin ] ++
|
||||
lib.optionals cudaSupport [ cudnn ];
|
||||
|
||||
cmakeFlags = lib.optionals cudaSupport
|
||||
[ "-DCUDA_TOOLKIT_ROOT_DIR=${cudatoolkit_joined}" ];
|
||||
|
||||
doCheck = true;
|
||||
|
||||
installPhase = ''
|
||||
touch $out
|
||||
'';
|
||||
|
||||
checkPhase = lib.optionalString cudaSupport ''
|
||||
LD_LIBRARY_PATH=${cudaStub}''${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH \
|
||||
'' + ''
|
||||
./test
|
||||
'';
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
#undef NDEBUG
|
||||
#include <cassert>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <torch/torch.h>
|
||||
|
||||
int main() {
|
||||
torch::Tensor tensor = torch::eye(3);
|
||||
|
||||
float checkData[] = {
|
||||
1, 0, 0,
|
||||
0, 1, 0,
|
||||
0, 0, 1
|
||||
};
|
||||
|
||||
torch::Tensor check = torch::from_blob(checkData, {3, 3});
|
||||
|
||||
assert(tensor.allclose(check));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue