Last active
April 6, 2021 05:08
-
-
Save notwa/89bd855b05270de85b59de28865fd5d0 to your computer and use it in GitHub Desktop.
ad-hoc build script for pytorch 1.8.1 on alpine linux 3.13.4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- a/c10/macros/Macros.h | |
+++ b/c10/macros/Macros.h | |
@@ -287,12 +287,12 @@ | |
defined(__HIP_ARCH__) || defined(__HIP__) | |
__host__ __device__ | |
#endif // __CUDA_ARCH__ | |
- void | |
+ _Noreturn void | |
__assert_fail( | |
const char* assertion, | |
const char* file, | |
- unsigned int line, | |
- const char* function) throw(); | |
+ int line, | |
+ const char* function); | |
} | |
#endif // NDEBUG | |
#define CUDA_KERNEL_ASSERT(cond) \ | |
--- a/c10/util/Type.cpp | |
+++ b/c10/util/Type.cpp | |
@@ -10,7 +10,12 @@ | |
(TARGET_IPHONE_SIMULATOR || TARGET_OS_SIMULATOR || TARGET_OS_IPHONE) | |
#define HAS_DEMANGLE 0 | |
#else | |
+#include <features.h> | |
+#if defined(__GLIBC__) | |
#define HAS_DEMANGLE 1 | |
+#else | |
+#define HAS_DEMANGLE 0 | |
+#endif | |
#endif | |
#if HAS_DEMANGLE | |
--- a/torch/lib/libshm/core.cpp | |
+++ b/torch/lib/libshm/core.cpp | |
@@ -32,7 +32,7 @@ | |
SYSCHECK_ERR_RETURN_NEG1(close(pipe_ends[0])); | |
SYSCHECK_ERR_RETURN_NEG1(dup2(pipe_ends[1], 1)); // Replace stdout | |
SYSCHECK_ERR_RETURN_NEG1(close(pipe_ends[1])); | |
- execl(manager_executable_path.c_str(), "torch_shm_manager", NULL); | |
+ execl(manager_executable_path.c_str(), "torch_shm_manager", (char*)NULL); | |
exit(1); | |
} | |
SYSCHECK_ERR_RETURN_NEG1(close(pipe_ends[1])); | |
--- a/third_party/tensorpipe/tensorpipe/channel/cma/context_impl.cc | |
+++ b/third_party/tensorpipe/tensorpipe/channel/cma/context_impl.cc | |
@@ -8,7 +8,6 @@ | |
#include <tensorpipe/channel/cma/context_impl.h> | |
-#include <linux/prctl.h> | |
#include <sys/prctl.h> | |
#include <sys/uio.h> | |
#include <unistd.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
set -e | |
cd "$(readlink -f "$(dirname "$0")" )" | |
for dependency in cmake g++ git linux-headers musl-dev openblas-dev patch py3-numpy py3-pip py3-requests py3-typing-extensions py3-wheel py3-yaml; do | |
if ! apk info -e "$dependency" >/dev/null; then | |
printf "\e[31m%s\e[0m%s\n" "Missing dependency, try:" " apk add $dependency" >&2 | |
exit 1 | |
fi | |
done | |
if which ccache >/dev/null; then | |
mkdir -p bin | |
[ -h bin/cc ] || ln -s "$(which ccache)" bin/cc | |
[ -h bin/c++ ] || ln -s "$(which ccache)" bin/c++ | |
[ -h bin/gcc ] || ln -s "$(which ccache)" bin/gcc | |
[ -h bin/g++ ] || ln -s "$(which ccache)" bin/g++ | |
PATH="$(readlink -f bin):$PATH" | |
export PATH | |
else | |
# i'm not sure if ccache actually helps here. | |
#printf "\e[93m%s\e[0m\n" "Warning: ccache is not installed." >&2 | |
fi | |
mkdir -p pytorch | |
cd pytorch | |
get_commit() { | |
# prints the hash of the specified ref, or nothing. | |
git rev-parse -q "$1" -- 2>/dev/null | head -n1 | |
} | |
# do some git magic to save tons of bandwidth and disk space | |
[ -d .git ] || git init | |
[ "$(git remote)" = "origin" ] || git remote add origin https://github.com/pytorch/pytorch | |
# this commit corresponds to the tag v1.8.1 | |
commit=56b43f4fec1f76953f15a627694d4bba34588969 | |
# specifying FETCH_HEAD doesn't work well with get_commit, so... | |
[ "$(get_commit HEAD)" = $commit ] || git fetch --depth 1 origin $commit | |
# magic part 2 | |
[ "$(get_commit HEAD)" = $commit ] || git checkout FETCH_HEAD | |
# --force git to check out the files instead of just fetching | |
[ -e third_party/zstd/NEWS ] || git submodule update --init --recursive --depth=1 --force | |
# undo all changes so the patch has something clean to work with: | |
#git reset --hard | |
#git submodule foreach --recursive git reset --hard | |
# the -q shorthand doesn't exist for diff-index, for some reason. | |
if git diff-index --quiet HEAD --; then | |
patch -p1 -i ../alpine.patch | |
fi | |
python3 setup.py build | |
python3 setup.py bdist_wheel | |
# install the most recent wheel (presumably the one we just built) | |
pip install "dist/$(ls -t dist | head -n1)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment