Skip to content

Commit 26526cf

Browse files
committed
Update base for Update on "[kernel] Add template based unboxing"
Adding a new feature to allow users to bypass codegen and register their kernels directly. This is very useful for custom kernels for custom ops. Example usage: ``` Tensor& my_op(RuntimeContext& ctx, const Tensor& self, const Tensor& other, Tensor& out) { // ... return out; } Kernel my_kernel = Kernel.make_boxed_kernel("my_ns::my_op",EXECUTORCH_FN(my_op)); register_kernels({my_kernel}); ``` Differential Revision: [D51553099](https://our.internmc.facebook.com/intern/diff/D51553099) [ghstack-poisoned]
2 parents 36e03ce + 7b1ac5d commit 26526cf

File tree

11,549 files changed

+52545
-72765
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

11,549 files changed

+52545
-72765
lines changed

.ci/docker/build.sh

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,49 +14,54 @@ echo "Building ${IMAGE_NAME} Docker image"
1414

1515
OS=ubuntu
1616
OS_VERSION=22.04
17-
CLANG_VERSION=12
17+
CLANG_VERSION=""
18+
GCC_VERSION=""
1819
PYTHON_VERSION=3.10
19-
MINICONDA_VERSION=23.5.1-0
20+
MINICONDA_VERSION=23.10.0-1
2021
BUCK2_VERSION=$(cat ci_commit_pins/buck2.txt)
2122

2223
case "${IMAGE_NAME}" in
24+
executorch-ubuntu-22.04-gcc9)
25+
LINTRUNNER=""
26+
GCC_VERSION=9
27+
;;
2328
executorch-ubuntu-22.04-clang12)
2429
LINTRUNNER=""
30+
CLANG_VERSION=12
2531
;;
2632
executorch-ubuntu-22.04-linter)
2733
LINTRUNNER=yes
34+
CLANG_VERSION=12
2835
;;
2936
executorch-ubuntu-22.04-arm-sdk)
3037
ARM_SDK=yes
38+
CLANG_VERSION=12
3139
;;
3240
*)
3341
echo "Invalid image name ${IMAGE_NAME}"
3442
exit 1
3543
esac
3644

37-
NIGHTLY=$(cat ci_commit_pins/nightly.txt)
3845
TORCH_VERSION=$(cat ci_commit_pins/pytorch.txt)
39-
TORCHAUDIO_VERSION=$(cat ci_commit_pins/audio.txt)
40-
TORCHVISION_VERSION=$(cat ci_commit_pins/vision.txt)
41-
4246
BUILD_DOCS=1
4347

4448
# Copy requirements-lintrunner.txt from root to here
4549
cp ../../requirements-lintrunner.txt ./
4650

4751
# Copy arm setup script from root to here
52+
# TODO(huydhn): Figure out a way to rebuild the Docker image automatically
53+
# with a new image hash when the content here is updated
4854
cp -r ../../examples/arm/ ./arm
4955

5056
docker build \
5157
--no-cache \
5258
--progress=plain \
5359
--build-arg "OS_VERSION=${OS_VERSION}" \
5460
--build-arg "CLANG_VERSION=${CLANG_VERSION}" \
61+
--build-arg "GCC_VERSION=${GCC_VERSION}" \
5562
--build-arg "PYTHON_VERSION=${PYTHON_VERSION}" \
5663
--build-arg "MINICONDA_VERSION=${MINICONDA_VERSION}" \
57-
--build-arg "TORCH_VERSION=${TORCH_VERSION}.${NIGHTLY}" \
58-
--build-arg "TORCHAUDIO_VERSION=${TORCHAUDIO_VERSION}.${NIGHTLY}" \
59-
--build-arg "TORCHVISION_VERSION=${TORCHVISION_VERSION}.${NIGHTLY}" \
64+
--build-arg "TORCH_VERSION=${TORCH_VERSION}" \
6065
--build-arg "BUCK2_VERSION=${BUCK2_VERSION}" \
6166
--build-arg "LINTRUNNER=${LINTRUNNER:-}" \
6267
--build-arg "BUILD_DOCS=${BUILD_DOCS}" \

.ci/docker/ci_commit_pins/audio.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

.ci/docker/ci_commit_pins/nightly.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

.ci/docker/ci_commit_pins/pytorch.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.2.0
1+
930b60f5aa7e17402491900a545d96822796b638

.ci/docker/ci_commit_pins/vision.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

.ci/docker/common/install_base.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ install_ubuntu() {
2222
vim \
2323
unzip \
2424
gdb \
25-
rsync
25+
rsync \
26+
libssl-dev
2627

2728
# Cleanup package manager
2829
apt-get autoclean && apt-get clean

.ci/docker/common/install_cache.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
# NB: This script is adopted from PyTorch core repo at
9+
# https://github.com/pytorch/pytorch/blob/main/.ci/docker/common/install_cache.sh
10+
set -ex
11+
12+
# shellcheck source=/dev/null
13+
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
14+
15+
install_binary() {
16+
echo "Downloading sccache binary from S3 repo"
17+
curl --retry 3 https://s3.amazonaws.com/ossci-linux/sccache -o /opt/cache/bin/sccache
18+
chmod +x /opt/cache/bin/sccache
19+
}
20+
21+
mkdir -p /opt/cache/bin
22+
sed -e 's|PATH="\(.*\)"|PATH="/opt/cache/bin:\1"|g' -i /etc/environment
23+
export PATH="/opt/cache/bin:$PATH"
24+
25+
# NB: Install the pre-built binary from S3 as building from source
26+
# https://github.com/pytorch/sccache has started failing mysteriously
27+
# in which sccache server couldn't start with the following error:
28+
# sccache: error: Invalid argument (os error 22)
29+
install_binary
30+
31+
function write_sccache_stub() {
32+
BINARY=$1
33+
printf "#!/bin/sh\nif [ \$(env -u LD_PRELOAD ps -p \$PPID -o comm=) != sccache ]; then\n exec sccache %s \"\$@\"\nelse\n exec %s \"\$@\"\nfi" "$(which "${BINARY}")" "$(which "${BINARY}")" > "/opt/cache/bin/${BINARY}"
34+
chmod a+x "/opt/cache/bin/${BINARY}"
35+
}
36+
37+
init_sccache() {
38+
# This is the remote cache bucket
39+
export SCCACHE_BUCKET=ossci-compiler-cache-circleci-v2
40+
export SCCACHE_S3_KEY_PREFIX=executorch
41+
export SCCACHE_IDLE_TIMEOUT=0
42+
export SCCACHE_ERROR_LOG=/tmp/sccache_error.log
43+
export RUST_LOG=sccache::server=error
44+
45+
# NB: This function is adopted from PyTorch core at
46+
# https://github.com/pytorch/pytorch/blob/main/.ci/pytorch/common-build.sh
47+
as_ci_user sccache --stop-server > /dev/null 2>&1 || true
48+
rm -f "${SCCACHE_ERROR_LOG}" || true
49+
50+
# Clear sccache stats before using it
51+
as_ci_user sccache --zero-stats || true
52+
}
53+
54+
write_sccache_stub cc
55+
write_sccache_stub c++
56+
write_sccache_stub gcc
57+
write_sccache_stub g++
58+
write_sccache_stub clang
59+
write_sccache_stub clang++
60+
init_sccache

.ci/docker/common/install_clang.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ install_ubuntu() {
1212

1313
apt-get install -y --no-install-recommends clang-"$CLANG_VERSION"
1414
apt-get install -y --no-install-recommends llvm-"$CLANG_VERSION"
15-
# Also require LLD linker from llvm
16-
apt-get install -y lld
15+
# Also require LLD linker from llvm and libomp to build PyTorch from source
16+
apt-get install -y lld "libomp-${CLANG_VERSION}-dev"
1717

1818
# Use update-alternatives to make this version the default
1919
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-"$CLANG_VERSION" 50

.ci/docker/common/install_conda.sh

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,22 @@ install_pip_dependencies() {
4040
pushd /opt/conda
4141
# Install all Python dependencies, including PyTorch
4242
pip_install -r /opt/conda/requirements-ci.txt
43-
pip_install --pre \
44-
torch=="${TORCH_VERSION}" \
45-
torchaudio=="${TORCHAUDIO_VERSION}" \
46-
torchvision=="${TORCHVISION_VERSION}" \
47-
--index-url https://download.pytorch.org/whl/nightly/cpu
4843
popd
4944
}
5045

46+
fix_conda_ubuntu_libstdcxx() {
47+
# WARNING: This is a HACK from PyTorch core to be able to build PyTorch on 22.04.
48+
# The issue still exists with the latest conda 23.10.0-1 at the time of writing
49+
# (2023/11/16).
50+
#
51+
# PyTorch sev: https://github.com/pytorch/pytorch/issues/105248
52+
# Ref: https://github.com/pytorch/pytorch/blob/main/.ci/docker/common/install_conda.sh
53+
if grep -e "[12][82].04.[623]" /etc/issue >/dev/null; then
54+
rm "/opt/conda/envs/py_${PYTHON_VERSION}/lib/libstdc++.so.6"
55+
fi
56+
}
57+
5158
install_miniconda
5259
install_python
5360
install_pip_dependencies
61+
fix_conda_ubuntu_libstdcxx

.ci/docker/common/install_docs_reqs.sh

100644100755
File mode changed.

.ci/docker/common/install_gcc.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
set -ex
9+
10+
if [ -n "$GCC_VERSION" ]; then
11+
12+
apt-get update
13+
apt-get install -y g++-"$GCC_VERSION"
14+
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-"$GCC_VERSION" 50
15+
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-"$GCC_VERSION" 50
16+
update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-"$GCC_VERSION" 50
17+
18+
19+
# Cleanup package manager
20+
apt-get autoclean && apt-get clean
21+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
22+
23+
fi

.ci/docker/common/install_openssl.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
# NB: This script is needed for sccache and is adopted from PyTorch core repo at
9+
# https://github.com/pytorch/pytorch/blob/main/.ci/docker/common/install_openssl.sh
10+
set -ex
11+
12+
OPENSSL=openssl-1.1.1k
13+
14+
wget -q -O "${OPENSSL}.tar.gz" "https://ossci-linux.s3.amazonaws.com/${OPENSSL}.tar.gz"
15+
tar xf "${OPENSSL}.tar.gz"
16+
17+
pushd "${OPENSSL}" || true
18+
./config --prefix=/opt/openssl -d "-Wl,--enable-new-dtags,-rpath,$(LIBRPATH)"
19+
# NOTE: openssl install errors out when built with the -j option
20+
make -j6; make install_sw
21+
# Link the ssl libraries to the /usr/lib folder.
22+
ln -s /opt/openssl/lib/lib* /usr/lib
23+
popd || true
24+
25+
rm -rf "${OPENSSL}"

.ci/docker/common/install_pytorch.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
set -ex
9+
10+
# shellcheck source=/dev/null
11+
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
12+
13+
install_domains() {
14+
echo "Install torchvision and torchaudio"
15+
pip_install --no-use-pep517 --user "git+https://github.com/pytorch/audio.git@${TORCHAUDIO_VERSION}"
16+
pip_install --no-use-pep517 --user "git+https://github.com/pytorch/vision.git@${TORCHVISION_VERSION}"
17+
}
18+
19+
install_pytorch_and_domains() {
20+
git clone https://github.com/pytorch/pytorch.git
21+
22+
# Fetch the target commit
23+
pushd pytorch || true
24+
git checkout "${TORCH_VERSION}"
25+
git submodule update --init --recursive
26+
27+
chown -R ci-user .
28+
29+
export _GLIBCXX_USE_CXX11_ABI=0
30+
# Then build and install PyTorch
31+
conda_run python setup.py bdist_wheel
32+
pip_install "$(echo dist/*.whl)"
33+
34+
# Grab the pinned audio and vision commits from PyTorch
35+
TORCHAUDIO_VERSION=$(cat .github/ci_commit_pins/audio.txt)
36+
export TORCHAUDIO_VERSION
37+
TORCHVISION_VERSION=$(cat .github/ci_commit_pins/vision.txt)
38+
export TORCHVISION_VERSION
39+
40+
install_domains
41+
42+
popd || true
43+
# Clean up the cloned PyTorch repo to reduce the Docker image size
44+
rm -rf pytorch
45+
46+
# Print sccache stats for debugging
47+
as_ci_user sccache --show-stats
48+
}
49+
50+
install_pytorch_and_domains

.ci/docker/conda-env-ci.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
cmake=3.22.1
2+
ninja=1.10.2

.ci/docker/requirements-ci.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ sympy==1.12
66
timm==0.6.13
77
tomli==2.0.1
88
torchsr==1.0.4
9-
transformers==4.34.0
9+
transformers==4.36.0
1010
zstd==1.5.5.1
1111
pytest==7.2.0
1212
pytest-cov==4.1.0
1313
expecttest==0.1.6
1414
hypothesis==6.84.2
1515
parameterized==0.9.0
1616

17-
# Doc build requirements
18-
sphinx==4.5.0
19-
sphinx-gallery
20-
breathe==4.35.0
21-
exhale==0.3.6
17+
# Doc build requirements, same as https://github.com/pytorch/pytorch/blob/main/.ci/docker/requirements-docs.txt
18+
sphinx==5.3.0
19+
sphinx-gallery==0.14.0
20+
breathe==4.34.0
21+
exhale==0.2.3
2222
docutils==0.16
23-
matplotlib
23+
matplotlib==3.7.2
2424
# PyTorch Theme
2525
-e git+https://github.com/pytorch/pytorch_sphinx_theme.git#egg=pytorch_sphinx_theme
26-
myst-parser
27-
sphinx_design
28-
sphinx-copybutton
26+
myst-parser==0.18.1
27+
sphinx_design==0.4.1
28+
sphinx-copybutton==0.5.0

.ci/docker/ubuntu/Dockerfile

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,21 @@ ENV DEBIAN_FRONTEND noninteractive
1010
COPY ./common/install_base.sh install_base.sh
1111
RUN bash ./install_base.sh && rm install_base.sh
1212

13+
COPY ./common/install_openssl.sh install_openssl.sh
14+
RUN bash ./install_openssl.sh && rm install_openssl.sh
15+
ENV OPENSSL_ROOT_DIR /opt/openssl
16+
ENV OPENSSL_DIR /opt/openssl
17+
1318
# Install clang
1419
ARG CLANG_VERSION
1520
COPY ./common/install_clang.sh install_clang.sh
1621
RUN bash ./install_clang.sh && rm install_clang.sh
1722

23+
# Install gcc
24+
ARG GCC_VERSION
25+
COPY ./common/install_gcc.sh install_gcc.sh
26+
RUN bash ./install_gcc.sh && rm install_gcc.sh
27+
1828
# Setup buck
1929
ARG BUCK2_VERSION
2030
COPY ./common/install_buck.sh install_buck.sh
@@ -32,9 +42,6 @@ RUN bash ./install_docs_reqs.sh && rm install_docs_reqs.sh
3242
# Install conda and other dependencies
3343
ARG MINICONDA_VERSION
3444
ARG PYTHON_VERSION
35-
ARG TORCH_VERSION
36-
ARG TORCHAUDIO_VERSION
37-
ARG TORCHVISION_VERSION
3845
ENV PYTHON_VERSION=$PYTHON_VERSION
3946
ENV PATH /opt/conda/envs/py_$PYTHON_VERSION/bin:/opt/conda/bin:$PATH
4047
COPY requirements-ci.txt /opt/conda/
@@ -43,6 +50,19 @@ COPY ./common/install_conda.sh install_conda.sh
4350
COPY ./common/utils.sh utils.sh
4451
RUN bash ./install_conda.sh && rm install_conda.sh utils.sh /opt/conda/requirements-ci.txt /opt/conda/conda-env-ci.txt
4552

53+
# Install sccache before building torch
54+
COPY ./common/install_cache.sh install_cache.sh
55+
ENV PATH /opt/cache/bin:$PATH
56+
COPY ./common/utils.sh utils.sh
57+
RUN bash ./install_cache.sh && rm install_cache.sh utils.sh
58+
ENV SCCACHE_BUCKET ossci-compiler-cache-circleci-v2
59+
ENV SCCACHE_S3_KEY_PREFIX executorch
60+
61+
ARG TORCH_VERSION
62+
COPY ./common/install_pytorch.sh install_pytorch.sh
63+
COPY ./common/utils.sh utils.sh
64+
RUN bash ./install_pytorch.sh && rm install_pytorch.sh utils.sh
65+
4666
ARG LINTRUNNER
4767
# Install lintrunner if needed
4868
COPY ./common/install_linter.sh install_linter.sh

0 commit comments

Comments
 (0)