From 0417c1b35241394270b3971e5d6370aa9dfcfb86 Mon Sep 17 00:00:00 2001 From: Geoffrey Martin-Noble Date: Mon, 1 Aug 2022 20:47:53 -0700 Subject: [PATCH 1/6] Add Android arm64 build --- .github/workflows/ci.yml | 33 +++++++++++ build_tools/build_android.sh | 55 +++++++++++++++++++ .../cmake/android/arm64-v8a/pipeline.yml | 2 +- ...d_android.sh => build_host_and_android.sh} | 0 4 files changed, 89 insertions(+), 1 deletion(-) create mode 100755 build_tools/build_android.sh rename build_tools/cmake/{build_android.sh => build_host_and_android.sh} (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index adec22d02e65..8cedb726a76e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -502,6 +502,38 @@ jobs: bash -euo pipefail -c \ "./build_tools/cmake/build_riscv.sh && ./tests/riscv64/smoke.sh" + android_arm64: + needs: [host_tools_assertions] + runs-on: + # Hacks, and order matters. See the comment at the top of the file. + - self-hosted + - runner-group=${{ github.event_name == 'pull_request' && 'presubmit' || 'postsubmit' }} + - cpu + - os-family=Linux + env: + BUILD_DIR: "build-android-arm64" + ANDROID_ABI: "arm64-v8a" + HOST_BINARY_ROOT: ${{ needs.host_tools_assertions.outputs.host-binary-root }} + HOST_BINARY_ARCHIVE: ${{ needs.host_tools_assertions.outputs.host-binary-root }}.tar + steps: + - name: "Checking out repository" + uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2 + with: + submodules: true + - name: "Downloading host tools" + uses: actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741 # v3.0.0 + with: + name: "${{ env.HOST_BINARY_ARCHIVE }}" + - name: "Extracting host tools archive" + run: | + tar -xvf ${HOST_BINARY_ARCHIVE} + - name: "Building for Android" + run: | + build_tools/github_actions/docker_run.sh \ + --env "ANDROID_ABI=${ANDROID_ABI}" \ + --env "IREE_HOST_BINARY_ROOT=${HOST_BINARY_ROOT}" \ + gcr.io/iree-oss/android@sha256:9bc723fc707a18bd0c1be9c12e01ea5bb7c7d77f607427879e10ffcffd7d2bb5 \ + build_tools/build_android.sh summary: runs-on: ubuntu-20.04 @@ -519,6 +551,7 @@ jobs: - tsan - riscv32 - riscv64 + - android_arm64 if: always() steps: - name: Getting combined job status diff --git a/build_tools/build_android.sh b/build_tools/build_android.sh new file mode 100755 index 000000000000..96907073fefc --- /dev/null +++ b/build_tools/build_android.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +# Copyright 2022 The IREE Authors +# +# Licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# Cross-compile the IREE project towards Android with CMake. Designed for CI, +# but can be run manually. +# +# Requires pre-compiled IREE and TF integrations host tools. Also requires that +# ANDROID_ABI and ANDROID_NDK variables be set + +set -xeuo pipefail + +ROOT_DIR="${ROOT_DIR:-$(git rev-parse --show-toplevel)}" +cd "${ROOT_DIR}" + +CMAKE_BIN="${CMAKE_BIN:-$(which cmake)}" +IREE_HOST_BINARY_ROOT="$(realpath ${IREE_HOST_BINARY_ROOT})" +BUILD_ANDROID_DIR="${BUILD_ANDROID_DIR:-$ROOT_DIR/build-android}" + + +if [[ -d "${BUILD_ANDROID_DIR}" ]]; then + echo "${BUILD_ANDROID_DIR} directory already exists. Will use cached results there." +else + echo "${BUILD_ANDROID_DIR} directory does not already exist. Creating a new one." + mkdir "${BUILD_ANDROID_DIR}" +fi + +declare -a args=( + -G Ninja + -B "${BUILD_ANDROID_DIR}" + -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" + -DANDROID_ABI="${ANDROID_ABI}" + -DANDROID_PLATFORM=android-29 + -DIREE_HOST_BINARY_ROOT="${IREE_HOST_BINARY_ROOT}" + -DIREE_ENABLE_ASSERTIONS=ON + -DIREE_BUILD_COMPILER=OFF + -DIREE_BUILD_TESTS=ON + -DIREE_BUILD_SAMPLES=OFF +) + +# Configure towards 64-bit Android 10, then build. +"${CMAKE_BIN}" "${args[@]}" + + +echo "Building all for device" +echo "------------" +"${CMAKE_BIN}" --build "${BUILD_ANDROID_DIR}" -- -k 0 + +echo "Building test deps for device" +echo "------------------" +"${CMAKE_BIN}" --build "${BUILD_ANDROID_DIR}" --target iree-test-deps -- -k 0 diff --git a/build_tools/buildkite/cmake/android/arm64-v8a/pipeline.yml b/build_tools/buildkite/cmake/android/arm64-v8a/pipeline.yml index 06b8a61017a9..585f0c849d29 100644 --- a/build_tools/buildkite/cmake/android/arm64-v8a/pipeline.yml +++ b/build_tools/buildkite/cmake/android/arm64-v8a/pipeline.yml @@ -8,7 +8,7 @@ steps: - label: "build" commands: - "git submodule sync && git submodule update --init --jobs 8 --depth 1" - - "docker run --user=$(id -u):$(id -g) --volume=\\$PWD:\\$IREE_DOCKER_WORKDIR --workdir=\\$IREE_DOCKER_WORKDIR --rm gcr.io/iree-oss/android@sha256:9bc723fc707a18bd0c1be9c12e01ea5bb7c7d77f607427879e10ffcffd7d2bb5 build_tools/cmake/build_android.sh arm64-v8a" + - "docker run --user=$(id -u):$(id -g) --volume=\\$PWD:\\$IREE_DOCKER_WORKDIR --workdir=\\$IREE_DOCKER_WORKDIR --rm gcr.io/iree-oss/android@sha256:9bc723fc707a18bd0c1be9c12e01ea5bb7c7d77f607427879e10ffcffd7d2bb5 build_host_and_android.sh arm64-v8a" - "tar --exclude='*.o' --exclude='*.a' -czvf build-artifacts.tgz build-android" agents: - "queue=build" diff --git a/build_tools/cmake/build_android.sh b/build_tools/cmake/build_host_and_android.sh similarity index 100% rename from build_tools/cmake/build_android.sh rename to build_tools/cmake/build_host_and_android.sh From 0b6361534db46e1da2975e1f335de5c10d6b12b3 Mon Sep 17 00:00:00 2001 From: Geoffrey Martin-Noble Date: Mon, 8 Aug 2022 14:39:32 -0700 Subject: [PATCH 2/6] Add job to build all benchmarks --- .github/workflows/ci.yml | 40 +++++++++++++++++++++++++ build_tools/cmake/build_benchmarks.sh | 42 +++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100755 build_tools/cmake/build_benchmarks.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8cedb726a76e..144261e486c1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -535,6 +535,45 @@ jobs: gcr.io/iree-oss/android@sha256:9bc723fc707a18bd0c1be9c12e01ea5bb7c7d77f607427879e10ffcffd7d2bb5 \ build_tools/build_android.sh + build_benchmarks: + needs: [build_all, build_tf_integrations] + runs-on: + # Hacks, and order matters. See the comment at the top of the file. + - self-hosted + - runner-group=${{ github.event_name == 'pull_request' && 'presubmit' || 'postsubmit' }} + - cpu + - os-family=Linux + env: + BUILD_DIR: ${{ needs.build_all.outputs.build-dir }} + BUILD_DIR_ARCHIVE: ${{ needs.build_all.outputs.build-dir-archive }} + BUILD_DIR_GCS_ARTIFACT: ${{ needs.build_all.outputs.gcs-artifact }} + TF_BINARIES_DIR: ${{ needs.build_tf_integrations.outputs.binaries-dir }} + TF_BINARIES_ARCHIVE: ${{ needs.build_tf_integrations.outputs.binaries-archive }} + TF_BINARIES_GCS_ARTIFACT: ${{ needs.build_tf_integrations.outputs.gcs-artifact }} + steps: + - name: "Checking out repository" + uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2 + with: + submodules: true + - name: "Downloading TF binaries archive" + run: gcloud alpha storage cp "${TF_BINARIES_GCS_ARTIFACT}" "${TF_BINARIES_ARCHIVE}" + - name: "Extracting TF binaries archive" + run: tar -xf "${TF_BINARIES_ARCHIVE}" + # TODO(#4662): building the benchmarks currently needs the entire build + # dir archive just to get the host tools. This is silly and we should + # make prebuilt host tools work even when not cross-compiling. + - name: "Downloading build dir archive" + run: gcloud alpha storage cp "${BUILD_DIR_GCS_ARTIFACT}" "${BUILD_DIR_ARCHIVE}" + - name: "Extracting archive" + run: tar -xf "${BUILD_DIR_ARCHIVE}" + - name: "Re-configuring" + run: | + build_tools/github_actions/docker_run.sh \ + --env "IREE_TF_BINARIES_DIR=${TF_BINARIES_DIR}" \ + gcr.io/iree-oss/base@sha256:5d43683c6b50aebe1fca6c85f2012f3b0fa153bf4dd268e8767b619b1891423a \ + build_tools/cmake/build_benchmarks.sh \ + "${BUILD_DIR}" + summary: runs-on: ubuntu-20.04 needs: @@ -552,6 +591,7 @@ jobs: - riscv32 - riscv64 - android_arm64 + - build_benchmarks if: always() steps: - name: Getting combined job status diff --git a/build_tools/cmake/build_benchmarks.sh b/build_tools/cmake/build_benchmarks.sh new file mode 100755 index 000000000000..7ecfda0c9cc7 --- /dev/null +++ b/build_tools/cmake/build_benchmarks.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# Copyright 2019 The IREE Authors +# +# Licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# Build benchmark suites for IREE using an *already built* build directory. +# Designed for CI, but can be run locally. +# TODO(#4662): this should just allow passing in host tools. + +set -xeuo pipefail + +ROOT_DIR="${ROOT_DIR:-$(git rev-parse --show-toplevel)}" +cd "${ROOT_DIR}" + +BUILD_DIR="${1:-${IREE_BUILD_DIR:-build}}" +CMAKE_BIN=${CMAKE_BIN:-$(which cmake)} +IREE_TF_BINARIES_DIR="${IREE_TF_BINARIES_DIR:-integrations/tensorflow/bazel-bin/iree_tf_compiler}" + +"$CMAKE_BIN" --version +ninja --version + +if ! [[ -d "${BUILD_DIR}" ]]; then + echo "Build directory '${BUILD_DIR}' does not exist. Aborting" + exit 1 +fi + +echo "Reconfiguring to enable benchmarks" +# Note that we're relying on CMake caching here +"${CMAKE_BIN}" -B "${BUILD_DIR}" \ + -DIREE_BUILD_BENCHMARKS=ON \ + -DIREE_BUILD_MICROBENCHMARKS=ON \ + -DIREE_IMPORT_TFLITE_PATH="${IREE_TF_BINARIES_DIR}/iree-import-tflite" \ + -DIREE_IMPORT_TF_PATH="${IREE_TF_BINARIES_DIR}/iree-import-tf" + +echo "Building benchmark artifacts" +"${CMAKE_BIN}" --build . --target \ + iree-benchmark-suites \ + iree-microbenchmark-suites \ + -- -k 0 From a008c6e741dab8bd9545f8a3ed37c73c4f4bbc46 Mon Sep 17 00:00:00 2001 From: Geoffrey Martin-Noble Date: Mon, 8 Aug 2022 15:40:23 -0700 Subject: [PATCH 3/6] REVERT ME: Disable other builds --- .github/workflows/ci.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 144261e486c1..4894e6cf20ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,6 +45,7 @@ env: jobs: build_runtime: + if: false runs-on: ubuntu-20.04 env: BUILD_DIR: build-runtime @@ -76,6 +77,7 @@ jobs: test_runtime: needs: build_runtime + if: false runs-on: ubuntu-20.04 env: BUILD_DIR: ${{ needs.build_runtime.outputs.build-dir }} @@ -150,6 +152,7 @@ jobs: echo "::set-output name=gcs-artifact::${GCS_ARTIFACT}" build_test_all_bazel: + if: false runs-on: # Pseudo-ternary hack and order matters. See comment at top of file. - self-hosted @@ -176,6 +179,7 @@ jobs: host_tools_assertions: + if: false uses: ./.github/workflows/host_tools.yml with: host-binary-root: host-tools-assertions @@ -228,6 +232,7 @@ jobs: test_all: needs: build_all + if: false runs-on: # Pseudo-ternary hack and order matters. See comment at top of file. - self-hosted @@ -297,6 +302,7 @@ jobs: test_tf_integrations: needs: [build_tf_integrations, build_all] + if: false runs-on: # Pseudo-ternary hack and order matters. See comment at top of file. - self-hosted @@ -378,6 +384,7 @@ jobs: build_tools/cmake/run_tf_tests.sh ${BUILD_DIR}" asan: + if: false runs-on: # Pseudo-ternary hack and order matters. See comment at top of file. - self-hosted @@ -396,6 +403,7 @@ jobs: ./build_tools/cmake/build_and_test_asan.sh tsan: + if: false runs-on: # Pseudo-ternary hack and order matters. See comment at top of file. - self-hosted @@ -415,6 +423,7 @@ jobs: riscv32: needs: host_tools_assertions + if: false runs-on: # Pseudo-ternary hack and order matters. See comment at top of file. - self-hosted @@ -450,6 +459,7 @@ jobs: riscv64: needs: [build_all, host_tools_assertions, build_tf_integrations] + if: false runs-on: # Pseudo-ternary hack and order matters. See comment at top of file. - self-hosted @@ -504,6 +514,7 @@ jobs: android_arm64: needs: [host_tools_assertions] + if: false runs-on: # Hacks, and order matters. See the comment at the top of the file. - self-hosted From 2483074d14f7a898673a261d2b8bdef36549340f Mon Sep 17 00:00:00 2001 From: Geoffrey Martin-Noble Date: Mon, 8 Aug 2022 16:00:42 -0700 Subject: [PATCH 4/6] Properly specify build dir --- build_tools/cmake/build_benchmarks.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build_tools/cmake/build_benchmarks.sh b/build_tools/cmake/build_benchmarks.sh index 7ecfda0c9cc7..d9897f51f27f 100755 --- a/build_tools/cmake/build_benchmarks.sh +++ b/build_tools/cmake/build_benchmarks.sh @@ -36,7 +36,7 @@ echo "Reconfiguring to enable benchmarks" -DIREE_IMPORT_TF_PATH="${IREE_TF_BINARIES_DIR}/iree-import-tf" echo "Building benchmark artifacts" -"${CMAKE_BIN}" --build . --target \ - iree-benchmark-suites \ - iree-microbenchmark-suites \ +"${CMAKE_BIN}" \ + --build "${BUILD_DIR}" + --target iree-benchmark-suites iree-microbenchmark-suites \ -- -k 0 From 6585abf2f35a2596a134f7d9c759740b4e264ae9 Mon Sep 17 00:00:00 2001 From: Geoffrey Martin-Noble Date: Mon, 8 Aug 2022 17:00:07 -0700 Subject: [PATCH 5/6] The number of times I've wasted 32 CPU hours because of a missing line continuation... --- build_tools/cmake/build_benchmarks.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_tools/cmake/build_benchmarks.sh b/build_tools/cmake/build_benchmarks.sh index d9897f51f27f..b84afd89f0b1 100755 --- a/build_tools/cmake/build_benchmarks.sh +++ b/build_tools/cmake/build_benchmarks.sh @@ -37,6 +37,6 @@ echo "Reconfiguring to enable benchmarks" echo "Building benchmark artifacts" "${CMAKE_BIN}" \ - --build "${BUILD_DIR}" + --build "${BUILD_DIR}" \ --target iree-benchmark-suites iree-microbenchmark-suites \ -- -k 0 From 4d995942af79bc7b17195bfb2827e323ed0c4517 Mon Sep 17 00:00:00 2001 From: Geoffrey Martin-Noble Date: Mon, 8 Aug 2022 19:12:24 -0700 Subject: [PATCH 6/6] Update copyright year --- build_tools/cmake/build_benchmarks.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_tools/cmake/build_benchmarks.sh b/build_tools/cmake/build_benchmarks.sh index b84afd89f0b1..d67f6438f229 100755 --- a/build_tools/cmake/build_benchmarks.sh +++ b/build_tools/cmake/build_benchmarks.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright 2019 The IREE Authors +# Copyright 2022 The IREE Authors # # Licensed under the Apache License v2.0 with LLVM Exceptions. # See https://llvm.org/LICENSE.txt for license information.