Skip to content

Commit

Permalink
Build and test TF integrations (#9927)
Browse files Browse the repository at this point in the history
I've had to disable Vulkan tests due to
#9936

Part of #9855
  • Loading branch information
GMNGeoffrey authored Jul 28, 2022
1 parent 2f48a95 commit 8aa3c3d
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 13 deletions.
94 changes: 88 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,54 @@ jobs:
gcloud alpha storage cp "${BUILD_DIR_ARCHIVE}" "${GCS_ARTIFACT}"
echo "::set-output name=gcs-artifact::${GCS_ARTIFACT}"
host_tools_assertions:
uses: ./.github/workflows/host_tools.yml
with:
host-binary-root: host-tools-assertions
enable-assertions: "ON"

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
outputs:
binaries-dir: ${{ steps.build.outputs.binaries-dir }}
binaries-archive: ${{ steps.archive.outputs.binaries-archive }}
gcs-artifact: ${{ steps.upload.outputs.gcs-artifact }}
steps:
- name: "Checking out repository"
uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2
with:
submodules: true
- name: "Building TF binaries"
id: build
env:
IREE_TF_BINARIES_OUTPUT_DIR: iree-tf-binaries
run: |
./build_tools/github_actions/docker_run.sh \
--env "IREE_TF_BINARIES_OUTPUT_DIR=$(realpath "${IREE_TF_BINARIES_OUTPUT_DIR}")" \
gcr.io/iree-oss/frontends-swiftshader@sha256:41e516b8c1b432e3c02896c4bf4b7f06df6a67371aa167b88767b8d4d2018ea6 \
build_tools/cmake/build_tf_binaries.sh
echo "::set-output name=binaries-dir::${IREE_TF_BINARIES_OUTPUT_DIR}"
- name: "Creating archive of binaries"
id: archive
env:
BINARIES_ARCHIVE: tf-binaries.tar
BINARIES_DIR: ${{ steps.build.outputs.binaries-dir }}
run: |
tar -cf "${BINARIES_ARCHIVE}" "${BINARIES_DIR}"
echo "::set-output name=binaries-archive::${BINARIES_ARCHIVE}"
- name: "Uploading binaries archive"
id: upload
env:
GCS_ARTIFACT: ${{ env.BUCKET }}/${{ github.sha }}/${{ steps.archive.outputs.binaries-archive }}
BINARIES_ARCHIVE: ${{ steps.archive.outputs.binaries-archive }}
run: |
gcloud alpha storage cp "${BINARIES_ARCHIVE}" "${GCS_ARTIFACT}"
echo "::set-output name=gcs-artifact::${GCS_ARTIFACT}"
test_all:
needs: build_all
runs-on:
Expand Down Expand Up @@ -212,6 +260,46 @@ jobs:
bash -c \
"./build_tools/scripts/check_cuda.sh && ./build_tools/scripts/check_vulkan.sh && ./build_tools/cmake/ctest_all.sh ${BUILD_DIR}"
test_tf_integrations:
needs: [build_tf_integrations, build_all]
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}"
- name: "Symlinking TF binaries"
run: |
./integrations/tensorflow/symlink_binaries.sh "$(realpath "${TF_BINARIES_DIR}")"
- name: "Downloading build dir archive"
run: gcloud alpha storage cp "${BUILD_DIR_GCS_ARTIFACT}" "${BUILD_DIR_ARCHIVE}"
- name: "Extracting build dir archive"
run: tar -xf "${BUILD_DIR_ARCHIVE}"
- name: "Running TF integrations tests"
# TODO(#9936): Enable Vulkan
run: |
./build_tools/github_actions/docker_run.sh \
--env IREE_VULKAN_DISABLE=1 \
gcr.io/iree-oss/frontends-swiftshader@sha256:41e516b8c1b432e3c02896c4bf4b7f06df6a67371aa167b88767b8d4d2018ea6 \
build_tools/cmake/run_tf_tests.sh \
"${BUILD_DIR}"
tsan:
runs-on:
# Hacks, and order matters. See the comment at the top of the file.
Expand All @@ -230,12 +318,6 @@ jobs:
gcr.io/iree-oss/base@sha256:9d742e01507c292def852cbfebfae71412cff94df0ab2619f61f9a5a2a98f651 \
./build_tools/cmake/build_and_test_tsan.sh
host_tools_assertions:
uses: ./.github/workflows/host_tools.yml
with:
host-binary-root: host-tools-assertions
enable-assertions: "ON"

riscv32:
needs: host_tools_assertions
runs-on:
Expand Down
72 changes: 72 additions & 0 deletions build_tools/cmake/build_tf_binaries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/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

# Build the IREE TF integration binaries. Despite the name, also runs the few
# lit tests for these that are enabled through Bazel. These take seconds to run
# all of them and it's easiest to just run themm here rather than trying to
# figure out how to pass prebuilt binaries to Bazel tests.

set -xeuo pipefail

ROOT_DIR="${ROOT_DIR:-$(git rev-parse --show-toplevel)}"
IREE_USE_WORKSPACE_RC="${IREE_USE_WORKSPACE_RC:-0}"
IREE_BAZEL_READ_REMOTE_CACHE="${IREE_BAZEL_READ_REMOTE_CACHE:-1}"
IREE_BAZEL_WRITE_REMOTE_CACHE="${IREE_BAZEL_WRITE_REMOTE_CACHE:-0}"
IREE_TF_BINARIES_OUTPUT_DIR="${IREE_TF_BINARIES_OUTPUT_DIR:-}"

if (( ${IREE_BAZEL_WRITE_REMOTE_CACHE} == 1 && ${IREE_BAZEL_READ_REMOTE_CACHE} != 1 )); then
echo "Can't have 'IREE_BAZEL_WRITE_REMOTE_CACHE' (${IREE_BAZEL_WRITE_REMOTE_CACHE}) set without 'IREE_BAZEL_READ_REMOTE_CACHE' (${IREE_BAZEL_READ_REMOTE_CACHE})"
fi

cd "${ROOT_DIR}/integrations/tensorflow"

BAZEL_BIN=${BAZEL_BIN:-$(which bazel)}

BAZEL_STARTUP_CMD=("${BAZEL_BIN}")

if [[ "${IREE_USE_WORKSPACE_RC}" == 0 ]]; then
BAZEL_STARTUP_CMD+=(--noworkspace_rc --bazelrc=build_tools/bazel/iree-tf.bazelrc)
fi

if [[ "${IREE_BAZEL_OUTPUT_BASE:-}" != "" ]]; then
BAZEL_STARTUP_CMD+=("--output_base=${IREE_BAZEL_OUTPUT_BASE}")
mkdir -p "${IREE_BAZEL_OUTPUT_BASE}"
fi

BAZEL_TEST_CMD=("${BAZEL_STARTUP_CMD[@]}" test)

if (( IREE_BAZEL_READ_REMOTE_CACHE == 1 )); then
BAZEL_TEST_CMD+=(--config=remote_cache_bazel_ci)
fi

if (( IREE_BAZEL_WRITE_REMOTE_CACHE != 1 )); then
BAZEL_TEST_CMD+=(--noremote_upload_local_results)
fi

BAZEL_TEST_CMD+=(
--config=generic_clang
--test_tag_filters="-nokokoro"
--build_tag_filters="-nokokoro"
)

# xargs is set to high arg limits to avoid multiple Bazel invocations and will
# hard fail if the limits are exceeded.
# See https://github.com/bazelbuild/bazel/issues/12479
"${BAZEL_STARTUP_CMD[@]}" query //iree_tf_compiler/... | \
xargs --max-args 1000000 --max-chars 1000000 --exit \
"${BAZEL_TEST_CMD[@]}"


if [[ "${IREE_TF_BINARIES_OUTPUT_DIR}" != "" ]]; then
mkdir -p "${IREE_TF_BINARIES_OUTPUT_DIR}"
cp \
bazel-bin/iree_tf_compiler/iree-import-tf \
bazel-bin/iree_tf_compiler/iree-import-tflite \
bazel-bin/iree_tf_compiler/iree-import-xla \
"${IREE_TF_BINARIES_OUTPUT_DIR}"
fi
44 changes: 44 additions & 0 deletions build_tools/cmake/run_tf_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/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

set -xeuo pipefail

ROOT_DIR="${ROOT_DIR:-$(git rev-parse --show-toplevel)}"
cd "${ROOT_DIR}"

BUILD_DIR="$1"
IREE_VULKAN_DISABLE="${IREE_VULKAN_DISABLE:-0}"

source "${BUILD_DIR}/.env" && export PYTHONPATH

echo "***** Running TensorFlow integration tests *****"
# TODO: Use "--timeout 900" instead of --max-time below. Requires that
# `psutil` python package be installed in the VM for per test timeout.
LIT_SCRIPT="${ROOT_DIR}/third_party/llvm-project/llvm/utils/lit/lit.py"

CMD=(
python3
"${LIT_SCRIPT}"
-v integrations/tensorflow/test
--max-time 1800
)

if (( ${IREE_VULKAN_DISABLE} != 1 )); then
CMD+=(-D FEATURES=vulkan)
fi

if "${CMD[@]}"; then
tests_passed=1
else
tests_passed=0
fi

if (( ${tests_passed} != 1 )); then
echo "Some tests failed!!!"
exit 1
fi
17 changes: 10 additions & 7 deletions integrations/tensorflow/symlink_binaries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@
# Symlinks built binaries from the bazel-bin/ directory into the corresponding
# python packages.

set -e
set -euo pipefail

cd "$(dirname $0)"
if [ -f bazel-bin/iree_tf_compiler/iree-import-tf ]; then
ln -sf $PWD/bazel-bin/iree_tf_compiler/iree-import-tf python_projects/iree_tf/iree/tools/tf/

BINARIES_DIR="${1:-${PWD}/bazel-bin/iree_tf_compiler}"

if [ -f "${BINARIES_DIR}/iree-import-tf" ]; then
ln -sf "${BINARIES_DIR}/iree-import-tf" python_projects/iree_tf/iree/tools/tf/
fi
if [ -f bazel-bin/iree_tf_compiler/iree-import-tflite ]; then
ln -sf $PWD/bazel-bin/iree_tf_compiler/iree-import-tflite python_projects/iree_tflite/iree/tools/tflite/
if [ -f "${BINARIES_DIR}/iree-import-tflite" ]; then
ln -sf "${BINARIES_DIR}/iree-import-tflite" python_projects/iree_tflite/iree/tools/tflite/
fi
if [ -f bazel-bin/iree_tf_compiler/iree-import-xla ]; then
ln -sf $PWD/bazel-bin/iree_tf_compiler/iree-import-xla python_projects/iree_xla/iree/tools/xla/
if [ -f "${BINARIES_DIR}/iree-import-xla" ]; then
ln -sf "${BINARIES_DIR}/iree-import-xla" python_projects/iree_xla/iree/tools/xla/
fi

0 comments on commit 8aa3c3d

Please sign in to comment.