Date: Wednesday, June 12, 2019 @ 08:16:49 Author: svenstaro Revision: 480628
upgpkg: python-pytorch 1.1.0-2 Modified: python-pytorch/trunk/PKGBUILD ----------+ PKGBUILD | 119 +++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 73 insertions(+), 46 deletions(-) Modified: PKGBUILD =================================================================== --- PKGBUILD 2019-06-12 08:06:22 UTC (rev 480627) +++ PKGBUILD 2019-06-12 08:16:49 UTC (rev 480628) @@ -2,10 +2,10 @@ # Contributor: Stephen Zhang <zsrkmyn at gmail dot com> pkgbase="python-pytorch" -pkgname=("python-pytorch" "python-pytorch-cuda") +pkgname=("python-pytorch" "python-pytorch-opt" "python-pytorch-cuda" "python-pytorch-opt-cuda") _pkgname="pytorch" pkgver=1.1.0 -pkgrel=1 +pkgrel=2 pkgdesc="Tensors and Dynamic neural networks in Python with strong GPU acceleration" arch=('x86_64') url="https://pytorch.org" @@ -12,10 +12,8 @@ license=('BSD') depends=('google-glog' 'gflags' 'opencv' 'openmp' 'nccl' 'pybind11' 'python' 'python-yaml' 'python-numpy' 'protobuf') makedepends=('python' 'python-setuptools' 'python-yaml' 'python-numpy' 'cmake' 'cuda' 'cudnn' 'git') -source=("${_pkgname}-${pkgver}::git+https://github.com/pytorch/pytorch.git#tag=v$pkgver" - 'change_default_config.patch') -sha256sums=('SKIP' - '36fa08167c5a54c2ae7e5b67b750d35f7a1b3812fa90153d66f6aa2fce71f2b4') +source=("${_pkgname}-${pkgver}::git+https://github.com/pytorch/pytorch.git#tag=v$pkgver") +sha256sums=('SKIP') get_pyver () { python -c 'import sys; print(str(sys.version_info[0]) + "." + str(sys.version_info[1]))' @@ -24,9 +22,6 @@ prepare() { cd "${_pkgname}-${pkgver}" - # Change default config manually, as setup.py filters some flags - patch -Np1 -i "${srcdir}/change_default_config.patch" - # This is the lazy way since pytorch has sooo many submodules and they keep # changing them around but we've run into more problems so far doing it the # manual than the lazy way. This lazy way (not explicitly specifying all @@ -36,26 +31,44 @@ cd .. + cp -a "${_pkgname}-${pkgver}" "${_pkgname}-${pkgver}-opt" cp -a "${_pkgname}-${pkgver}" "${_pkgname}-${pkgver}-cuda" -} + cp -a "${_pkgname}-${pkgver}" "${_pkgname}-${pkgver}-opt-cuda" -build() { export CC=gcc export CXX=g++ export PYTORCH_BUILD_VERSION="${pkgver}" export PYTORCH_BUILD_NUMBER=1 export USE_MKLDNN=0 + # export BUILD_CUSTOM_PROTOBUF=0 + # export BUILD_SHARED_LIBS=0 + export USE_GFLAGS=1 + export USE_GLOG=1 + export BUILD_BINARY=1 + export USE_OPENCV=1 + export USE_SYSTEM_NCCL=1 +} - echo "Building without cuda" +build() { + echo "Building without cuda and without non-x86-64 optimizations" export NO_CUDA=1 export WITH_CUDNN=0 - export USE_OPENCV=1 - export BUILD_BINARY=1 cd "${srcdir}/${_pkgname}-${pkgver}" + sed -i "s/march=native/march=x86-64/g" cmake/MiscCheck.cmake python setup.py build - echo "Building with cuda" + + echo "Building without cuda and with non-x86-64 optimizations" + export NO_CUDA=1 + export WITH_CUDNN=0 + + cd "${srcdir}/${_pkgname}-${pkgver}-opt" + sed -i "s/march=native/march=haswell/g" cmake/MiscCheck.cmake + python setup.py build + + + echo "Building with cuda and without non-x86-64 optimizations" export NO_CUDA=0 export WITH_CUDNN=1 export CUDAHOSTCXX=g++ @@ -66,25 +79,45 @@ export TORCH_CUDA_ARCH_LIST="3.0;3.2;3.5;3.7;5.0;5.2;5.3;6.0;6.1;6.2;7.0;7.2;7.5" cd "${srcdir}/${_pkgname}-${pkgver}-cuda" + sed -i "s/march=native/march=x86-64/g" cmake/MiscCheck.cmake python setup.py build + + + echo "Building with cuda and without non-x86-64 optimizations" + export NO_CUDA=0 + export WITH_CUDNN=1 + export CUDAHOSTCXX=g++ + export CUDA_HOME=/opt/cuda + export CUDNN_LIB_DIR=/usr/lib + export CUDNN_INCLUDE_DIR=/usr/include + export TORCH_NVCC_FLAGS="-Xfatbin -compress-all" + export TORCH_CUDA_ARCH_LIST="3.0;3.2;3.5;3.7;5.0;5.2;5.3;6.0;6.1;6.2;7.0;7.2;7.5" + + cd "${srcdir}/${_pkgname}-${pkgver}-opt-cuda" + sed -i "s/march=native/march=haswell/g" cmake/MiscCheck.cmake + python setup.py build } -package_python-pytorch() { - cd "${srcdir}/${_pkgname}-${pkgver}" +_package() { # Prevent setup.py from re-running CMake and rebuilding sed -e 's/RUN_BUILD_DEPS = True/RUN_BUILD_DEPS = False/g' -i setup.py + python setup.py install --root="${pkgdir}"/ --optimize=1 --skip-build + install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE.txt" + # put CMake files in correct place install -d "${pkgdir}/usr/lib/cmake" pytorchpath="usr/lib/python$(get_pyver)/site-packages/torch" mv "${pkgdir}/${pytorchpath}/share/cmake"/* \ "${pkgdir}/usr/lib/cmake/" + # put C++ API in correct place install -d "${pkgdir}/usr/include" install -d "${pkgdir}/usr/lib/pytorch" mv "${pkgdir}/${pytorchpath}/include"/* "${pkgdir}/usr/include/" mv "${pkgdir}/${pytorchpath}/lib"/*.so* "${pkgdir}/usr/lib/pytorch/" + # clean up duplicates # TODO: move towards direct shared library dependecy of: # c10, caffe2, libcpuinfo, CUDA RT, gloo, GTest, Intel MKL, @@ -92,50 +125,44 @@ rm -rf "${pkgdir}/${pytorchpath}/share/cmake" rm -rf "${pkgdir}/${pytorchpath}/include" rm -rf "${pkgdir}/usr/include/pybind11" + # python module is hardcoded to look there at runtime ln -s /usr/include "${pkgdir}/${pytorchpath}/include" find "${pkgdir}"/usr/lib/pytorch -type f -name "*.so*" -print0 | while read -rd $'\0' _lib; do ln -s ${_lib#"$pkgdir"} "${pkgdir}/${pytorchpath}/lib/" done + # ldconfig install -d "${pkgdir}/etc/ld.so.conf.d" echo '/usr/lib/pytorch' > "${pkgdir}/etc/ld.so.conf.d/pytorch.conf" } +package_python-pytorch() { + cd "${srcdir}/${_pkgname}-${pkgver}" + _package +} + +package_python-pytorch-opt() { + cd "${srcdir}/${_pkgname}-${pkgver}-opt" + _package +} + package_python-pytorch-cuda() { depends+=('cuda' 'cudnn') provides=('python-pytorch') conflicts=('python-pytorch') + cd "${srcdir}/${_pkgname}-${pkgver}-cuda" - # Prevent setup.py from re-running CMake and rebuilding - sed -e 's/RUN_BUILD_DEPS = True/RUN_BUILD_DEPS = False/g' -i setup.py - python setup.py install --root="${pkgdir}"/ --optimize=1 --skip-build - install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE.txt" - # put CMake files in correct place - install -d "${pkgdir}/usr/lib/cmake" - pytorchpath="usr/lib/python$(get_pyver)/site-packages/torch" - mv "${pkgdir}/${pytorchpath}/share/cmake"/* \ - "${pkgdir}/usr/lib/cmake/" - # put C++ API in correct place - install -d "${pkgdir}/usr/include" - install -d "${pkgdir}/usr/lib/pytorch" - mv "${pkgdir}/${pytorchpath}/include"/* "${pkgdir}/usr/include/" - mv "${pkgdir}/${pytorchpath}/lib"/*.so* "${pkgdir}/usr/lib/pytorch/" - # clean up duplicates - # TODO: move towards direct shared library dependecy of: - # c10, caffe2, libcpuinfo, CUDA RT, gloo, GTest, Intel MKL, - # NVRTC, ONNX, protobuf, libthreadpool, QNNPACK - rm -rf "${pkgdir}/${pytorchpath}/share/cmake" - rm -rf "${pkgdir}/${pytorchpath}/include" - rm -rf "${pkgdir}/usr/include/pybind11" - # python module is hardcoded to look there at runtime - ln -s /usr/include "${pkgdir}/${pytorchpath}/include" - find "${pkgdir}"/usr/lib/pytorch -type f -name "*.so*" -print0 | while read -rd $'\0' _lib; do - ln -s ${_lib#"$pkgdir"} "${pkgdir}/${pytorchpath}/lib/" - done - # ldconfig - install -d "${pkgdir}/etc/ld.so.conf.d" - echo '/usr/lib/pytorch' > "${pkgdir}/etc/ld.so.conf.d/pytorch.conf" + _package } +package_python-pytorch-opt-cuda() { + depends+=('cuda' 'cudnn') + provides=('python-pytorch') + conflicts=('python-pytorch') + + cd "${srcdir}/${_pkgname}-${pkgver}-opt-cuda" + _package +} + # vim:set ts=2 sw=2 et: