mirror of https://github.com/llvm/torch-mlir
Dockerize and Cache Bazel {Local, CI} Builds (#1240)
This PR adds: - A minimal docker wrapper to the bazel GHA workflow to make it reproducible locally - Bazel cache to speed up GHA workflows (down to ~5 minutes from ~40+minutes) This is a no-op for non-bazel workflows and an incremental improvement.pull/1241/head
parent
9be8997536
commit
9c8b962720
|
@ -20,20 +20,38 @@ jobs:
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Set up Python
|
|
||||||
uses: actions/setup-python@v2
|
|
||||||
with:
|
|
||||||
python-version: 3.9
|
|
||||||
|
|
||||||
- name: Checkout torch-mlir
|
- name: Checkout torch-mlir
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
submodules: 'true'
|
submodules: 'true'
|
||||||
|
|
||||||
- name: Build with bazel
|
- name: Setup cache for bazel
|
||||||
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: ~/.cache/bazel
|
||||||
|
key: ubuntu_x86_64_torch_mlir_bazel_build_cache
|
||||||
|
|
||||||
|
- name: Set bazel cache permissions
|
||||||
run: |
|
run: |
|
||||||
cd $GITHUB_WORKSPACE/utils/bazel
|
sudo chown -R root:root "${HOME}/.cache/bazel"
|
||||||
bazel build @torch-mlir//...
|
|
||||||
|
- name: Build docker image
|
||||||
|
run: |
|
||||||
|
docker build -f utils/bazel/docker/Dockerfile \
|
||||||
|
-t torch-mlir:ci \
|
||||||
|
.
|
||||||
|
|
||||||
|
- name: Bazel build torch-mlir
|
||||||
|
run: |
|
||||||
|
docker run --rm \
|
||||||
|
-v "$(pwd)":"/opt/src/torch-mlir" \
|
||||||
|
-v "${HOME}/.cache/bazel":"/root/.cache/bazel" \
|
||||||
|
torch-mlir:ci \
|
||||||
|
./utils/bazel/docker/run_bazel_build.sh
|
||||||
|
|
||||||
|
- name: Switch bazel cache permissions
|
||||||
|
run: |
|
||||||
|
sudo chown -R "$USER":"$USER" "${HOME}/.cache/bazel"
|
||||||
|
|
||||||
- name: Send mail
|
- name: Send mail
|
||||||
if: failure()
|
if: failure()
|
||||||
|
|
|
@ -175,14 +175,15 @@ manually `source`'d in a shell.
|
||||||
|
|
||||||
Torch-MLIR can also be built using Bazel (apart from the official CMake build) for users that depend on Bazel in their workflows. To build `torch-mlir-opt` using Bazel, follow these steps:
|
Torch-MLIR can also be built using Bazel (apart from the official CMake build) for users that depend on Bazel in their workflows. To build `torch-mlir-opt` using Bazel, follow these steps:
|
||||||
|
|
||||||
1. Install [Bazel](https://docs.bazel.build/versions/main/install.html) if you don't already have it
|
1. Launch an interactive docker container with the required deps installed:
|
||||||
2. Install a relatively new release of [Clang](https://releases.llvm.org/download.html)
|
|
||||||
3. Build:
|
|
||||||
```shell
|
```shell
|
||||||
cd utils/bazel
|
./utils/bazel/docker/run_docker.sh
|
||||||
bazel build @torch-mlir//...
|
|
||||||
```
|
```
|
||||||
4. Find the built binary at `bazel-bin/external/torch-mlir/torch-mlir-opt`.
|
2. Build torch-mlir using bazel (from container):
|
||||||
|
```shell
|
||||||
|
./utils/bazel/docker/run_bazel_build.sh
|
||||||
|
```
|
||||||
|
3. Find the built binary at `utils/bazel/bazel-bin/external/torch-mlir/torch-mlir-opt`.
|
||||||
|
|
||||||
|
|
||||||
# Testing
|
# Testing
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
ARG BASE_IMG=ubuntu:18.04
|
||||||
|
FROM ${BASE_IMG} as dev-base
|
||||||
|
|
||||||
|
ARG ARCH="x86_64"
|
||||||
|
ARG BAZEL_VERSION=5.2.0
|
||||||
|
|
||||||
|
# Install basic packages
|
||||||
|
RUN apt-get update && \
|
||||||
|
apt-get install -y \
|
||||||
|
clang-10 \
|
||||||
|
curl \
|
||||||
|
git \
|
||||||
|
python3-pip \
|
||||||
|
python3.8 \
|
||||||
|
python3.8-dev \
|
||||||
|
wget \
|
||||||
|
unzip
|
||||||
|
|
||||||
|
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.8 10
|
||||||
|
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 10
|
||||||
|
|
||||||
|
RUN update-alternatives --install /usr/bin/clang clang /usr/bin/clang-10 10
|
||||||
|
RUN update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-10 10
|
||||||
|
|
||||||
|
# Install bazel
|
||||||
|
RUN wget -q https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-linux-${ARCH} -O /usr/bin/bazel \
|
||||||
|
&& chmod a+x /usr/bin/bazel
|
||||||
|
|
||||||
|
COPY requirements.txt /opt/app/requirements.txt
|
||||||
|
WORKDIR /opt/app
|
||||||
|
RUN python -m pip install --upgrade pip
|
||||||
|
RUN python -m pip install --ignore-installed -r requirements.txt
|
||||||
|
|
||||||
|
WORKDIR /opt/src/torch-mlir
|
|
@ -0,0 +1,3 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
cd "$(pwd)/utils/bazel" && bazel build @torch-mlir//...
|
|
@ -0,0 +1,10 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
docker build -f utils/bazel/docker/Dockerfile \
|
||||||
|
-t torch-mlir:dev \
|
||||||
|
.
|
||||||
|
|
||||||
|
docker run -it \
|
||||||
|
-v "$(pwd)":"/opt/src/torch-mlir" \
|
||||||
|
-v "${HOME}/.cache/bazel":"/root/.cache/bazel" \
|
||||||
|
torch-mlir:dev
|
Loading…
Reference in New Issue