Skip to content

Commit

Permalink
Implement GitHub Actions for lint and buildAndTest
Browse files Browse the repository at this point in the history
  • Loading branch information
GleasonK committed Aug 26, 2022
1 parent d88d0fe commit 22953ae
Show file tree
Hide file tree
Showing 7 changed files with 260 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BasedOnStyle: LLVM
AlwaysBreakTemplateDeclarations: Yes
45 changes: 45 additions & 0 deletions .github/actions/setup-build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2022 The StableHLO Authors.

# The setup-build action gets everything needed by buildAndTest into the workspace.
# This checks out the proper revision of the LLVM repository, installs ninja, and sets
# up the ccache for faster re-compilation.
name: "Setup build environment (ninja, ccache, llvm, lld)"

inputs:
llvm-ref:
description: |
LLVM Commit Ref for checkout and build. Used for ccache value and checkout.
required: true


runs:
# Based on https://github.com/llvm/torch-mlir/blob/main/.github/actions/setup-build/action.yml
using: "composite"

steps:
# Checkout llvm at revision specified in input argument.
- uses: actions/checkout@v2
with:
repository: llvm/llvm-project
ref: ${{ inputs.llvm-ref }}
path: llvm-project
fetch-depth: 1

# Get ninja for cmake build.
- name: Install Ninja
uses: llvm/actions/install-ninja@55d844821959226fab4911f96f37071c1d4c3268

# Get LLD
- name: Install LLD
if: "runner.os == 'Linux'"
shell: bash
run: |
sudo apt-get install -y lld
# Setup C++ caching using ccache.
# Cache key is a combination of OS arch and LLVM ref.
- name: Ccache for C++ compilation
uses: hendrikmuhs/[email protected]
with:
key: ${{ runner.os }}-stablehlo_build_assets-${{ inputs.llvm-ref }}
max-size: 4G
71 changes: 71 additions & 0 deletions .github/workflows/buildAndTest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright 2022 The StableHLO Authors.

name: Build and Test

on:
pull_request:
branches: [ main ]
push:
branches: [ main ]
schedule:
# Always regenerate once every day
- cron: '* 12 * * *'
workflow_dispatch:

# Ensure that only a single job or workflow using the same
# concurrency group will run at a time. This would cancel
# any in-progress jobs in the same github workflow and github
# ref (e.g. refs/heads/main or refs/pull/<pr_number>/merge).
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

# Build using CMake and run tests.
# Use Cached LLVM to improve build times.
# Current setup only builds on linux.
jobs:
build-test:
strategy:
fail-fast: false
matrix:
os-arch: [maci-x86_64, ubuntu-x86_64]
include:
- os-arch: ubuntu-x86_64
os: ubuntu-22.04
llvm-build-dir: "$GITHUB_WORKSPACE/llvm-build"
stablehlo-build-dir: "$GITHUB_WORKSPACE/build"
- os-arch: maci-x86_64
os: macos-latest
llvm-build-dir: "$GITHUB_WORKSPACE/llvm-build-maci"
stablehlo-build-dir: "$GITHUB_WORKSPACE/build-maci"
runs-on: ${{ matrix.os }}

steps:

# Check out stablehlo repo
- name: Checkout stablehlo
uses: actions/checkout@v2

# Read llvm revision from `build_tools/llvm_version.txt`
- name: Get LLVM Revision
id: llvm-revision
shell: bash
run: |
echo "::set-output name=revision::$(cat ${{ github.workspace }}/build_tools/llvm_version.txt)"
# Check out LLVM, download Ninja, setup ccache
- name: Setup workspace
uses: ./.github/actions/setup-build
with:
llvm-ref: ${{ steps.llvm-revision.outputs.revision }}

# Configuration for linux
- name: Configure and Build LLVM os-arch='${{ matrix.os-arch }}'
shell: bash
run: |
./build_tools/github_actions/ci_build_llvm.sh "$GITHUB_WORKSPACE/llvm-project/" ${{ matrix.llvm-build-dir }}
# Configure for linux
- name: Build and Test StableHLO os-arch='${{ matrix.os-arch }}'
run: |
./build_tools/github_actions/ci_build_stablehlo.sh ${{ matrix.llvm-build-dir }} ${{ matrix.stablehlo-build-dir }}
25 changes: 25 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2022 The StableHLO Authors.

name: Lint

on: [pull_request]

jobs:
# Based on https://github.com/iree-org/iree/blob/main/.github/workflows/lint.yml
clang-format:
if: "github.event_name == 'pull_request'"
runs-on: ubuntu-latest
steps:
- name: Installing dependencies
run: |
wget https://raw.githubusercontent.com/llvm-mirror/clang/master/tools/clang-format/git-clang-format -O /tmp/git-clang-format
chmod +x /tmp/git-clang-format
- name: Checking out repository
uses: actions/checkout@v2
- name: Fetching Base Branch
# We have to explicitly fetch the base branch as well
run: git fetch --no-tags --prune --depth=1 origin "${GITHUB_BASE_REF?}:${GITHUB_BASE_REF?}"
- name: Running clang-format on changed source files
run: |
/tmp/git-clang-format "${GITHUB_BASE_REF?}" --style=google
git diff --exit-code
61 changes: 61 additions & 0 deletions build_tools/github_actions/ci_build_llvm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
# Copyright 2022 The StableHLO Authors.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This file is similar to build_mlir.sh, but passes different flags for
# cacheing in GitHub Actions to improve build speeds.

if [[ $# -ne 2 ]] ; then
echo "Usage: $0 <path/to/llvm> <build_dir>"
exit 1
fi

# LLVM source
LLVM_SRC_DIR="$1"
LLVM_BUILD_DIR="$2"

# Check for LLD
FLAGS=""
LLD_FLAG="-DLLVM_ENABLE_LLD=ON"
if command -v lld &> /dev/null
then
echo "lld found, appending flag '$LLD_FLAG'"
FLAGS="$LLD_FLAG"
else
echo "lld not found, using default linker"
fi

# Call cmake
echo "Using additional flags: '$FLAGS'"

cmake -GNinja \
"$FLAGS" \
"-B$LLVM_BUILD_DIR" \
"-H$LLVM_SRC_DIR/llvm" \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DLLVM_BUILD_TOOLS=OFF \
-DLLVM_ENABLE_ASSERTIONS=On \
-DLLVM_ENABLE_BINDINGS=OFF \
-DLLVM_ENABLE_PROJECTS=mlir \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_INCLUDE_TOOLS=ON \
-DLLVM_INSTALL_UTILS=ON \
-DLLVM_TARGETS_TO_BUILD="X86;NVPTX;AMDGPU"

# Build LLVM/MLIR
cmake --build "$LLVM_BUILD_DIR" --target all --target mlir-cpu-runner
55 changes: 55 additions & 0 deletions build_tools/github_actions/ci_build_stablehlo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
# Copyright 2022 The StableHLO Authors.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This file is similar to build_mlir.sh, but passes different flags for
# cacheing in GitHub Actions.

# This file gets called on build directory where resources are placed
# during `ci_configure`, and builds stablehlo in the directory specified
# by the second argument.

if [[ $# -ne 2 ]] ; then
echo "Usage: $0 <llvm_build_dir> <stablehlo_build_dir>"
exit 1
fi

LLVM_BUILD_DIR="$1"
STABLEHLO_BUILD_DIR="$2"

# Check for LLD
FLAGS=""
LLD_FLAG="-DLLVM_ENABLE_LLD=ON"
if command -v lld &> /dev/null
then
echo "lld found, appending flag '$LLD_FLAG'"
FLAGS="$LLD_FLAG"
else
echo "lld not found, using default linker"
fi

# Build StableHLO
cmake -GNinja \
"$FLAGS" \
-B"$STABLEHLO_BUILD_DIR" \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=On \
-DMLIR_DIR="$LLVM_BUILD_DIR/lib/cmake/mlir"

cd "$STABLEHLO_BUILD_DIR"
ninja check-stablehlo
3 changes: 1 addition & 2 deletions stablehlo/dialect/StablehloOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1855,8 +1855,7 @@ LogicalResult verifyCollectivePermuteSourceTargetPairs(
}

LogicalResult CollectivePermuteOp::verify() {
return verifyCollectivePermuteSourceTargetPairs(*this,
source_target_pairs());
return verifyCollectivePermuteSourceTargetPairs(*this, source_target_pairs());
}

//===----------------------------------------------------------------------===//
Expand Down

0 comments on commit 22953ae

Please sign in to comment.