Skip to content

Commit

Permalink
[wip] Build wheels with debug info (pytorch#770)
Browse files Browse the repository at this point in the history
Co-authored-by: driazati <[email protected]>
  • Loading branch information
driazati and driazati authored May 24, 2021
1 parent b0f4e2a commit 8786f77
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,4 @@ node_modules

# Analytics cache folder
cache/
.vscode/
28 changes: 28 additions & 0 deletions manywheel/build_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
set -ex
SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"


# Require only one python installation
if [[ -z "$DESIRED_PYTHON" ]]; then
echo "Need to set DESIRED_PYTHON env variable"
Expand Down Expand Up @@ -141,6 +142,7 @@ fi
echo "Calling setup.py bdist at $(date)"
time CMAKE_ARGS=${CMAKE_ARGS[@]} \
EXTRA_CAFFE2_CMAKE_FLAGS=${EXTRA_CAFFE2_CMAKE_FLAGS[@]} \
BUILD_LIBTORCH_CPU_WITH_DEBUG=1 \
python setup.py bdist_wheel -d /tmp/$WHEELHOUSE_DIR
echo "Finished setup.py bdist at $(date)"

Expand Down Expand Up @@ -344,6 +346,32 @@ for pkg in /$WHEELHOUSE_DIR/torch*linux*.whl /$LIBTORCH_HOUSE_DIR/libtorch*.zip;
done
fi

pushd "$PREFIX/lib"

# Duplicate library into debug lib
cp libtorch_cpu.so libtorch_cpu.so.dbg

# Keep debug symbols on debug lib
strip --only-keep-debug libtorch_cpu.so.dbg

# Remove debug info from release lib
strip --strip-debug libtorch_cpu.so

objcopy libtorch_cpu.so --add-gnu-debuglink=libtorch_cpu.so.dbg

# Zip up debug info
mkdir -p /tmp/debug
mv libtorch_cpu.so.dbg /tmp/debug/libtorch_cpu.so.dbg
CRC32=$(objcopy --dump-section .gnu_debuglink=>(tail -c4 | od -t x4 -An | xargs echo) libtorch_cpu.so)

pushd /tmp
PKG_NAME=$(basename "$pkg" | sed 's/\.whl$//g')
zip /tmp/debug-whl-libtorch-"$PKG_NAME"-"$CRC32".zip /tmp/debug/libtorch_cpu.so.dbg
cp /tmp/debug-whl-libtorch-"$PKG_NAME"-"$CRC32".zip "$PYTORCH_FINAL_PACKAGE_DIR"
popd

popd

# zip up the wheel back
zip -rq $(basename $pkg) $PREIX*

Expand Down

0 comments on commit 8786f77

Please sign in to comment.