Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement GitHub Actions for lint and buildAndTest #49

Merged
merged 5 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
42 changes: 42 additions & 0 deletions .github/actions/setup-build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2022 The StableHLO Authors.

# The setup-build action gets everything needed by buildAndTest into the workspace.
name: "Setup build environment (ninja, ccache, llvm, lld)"

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

runs:
# This is a composite action - has a list of steps to execute.
using: "composite"

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

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

# Get LLD - Improves build speed on Linux
- name: Install LLD
if: "runner.os == 'Linux'"
GleasonK marked this conversation as resolved.
Show resolved Hide resolved
shell: bash
run: |
sudo apt-get install -y lld

# Setup C++ caching using ccache.
# Cache key is a combination of OS arch and LLVM version.
- name: Ccache for C++ compilation
uses: hendrikmuhs/[email protected]
with:
key: ${{ runner.os }}-stablehlo_build_assets-${{ inputs.llvm-version }}
max-size: 4G
60 changes: 60 additions & 0 deletions .github/workflows/buildAndTest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright 2022 The StableHLO Authors.

name: Build and Test

on:
pull_request:
branches: [ main ]
push:
branches: [ main ]
schedule:
# Run buildAndTest workflow once a 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.
jobs:
build-test:
strategy:
fail-fast: false
matrix:
os-arch: [ubuntu-x86_64]
include:
- os-arch: ubuntu-x86_64
os: ubuntu-22.04
runs-on: ${{ matrix.os }}

steps:
- name: Checkout StableHLO
uses: actions/checkout@v2

# Read LLVM version from `build_tools/llvm_version.txt`
- name: Get LLVM Version
id: llvm-version
shell: bash
run: |
echo "::set-output name=version::$(cat ${{ github.workspace }}/build_tools/llvm_version.txt)"

# Check out LLVM, and install tools for compilation
- name: Setup workspace
uses: ./.github/actions/setup-build
with:
llvm-version: ${{ steps.llvm-version.outputs.version }}

- 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/" "$GITHUB_WORKSPACE/llvm-build"

- name: Build and Test StableHLO os-arch='${{ matrix.os-arch }}'
run: |
./build_tools/github_actions/ci_build_stablehlo.sh "$GITHUB_WORKSPACE/llvm-build" "$GITHUB_WORKSPACE/stablehlo-build"
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:
clang-format:
# This job can only be run on pull_request since GITHUB_BASE_REF is only set on PR.
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
GleasonK marked this conversation as resolved.
Show resolved Hide resolved
48 changes: 48 additions & 0 deletions build_tools/github_actions/ci_build_llvm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/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
# caching 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"

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

# Build LLVM/MLIR
cmake --build "$LLVM_BUILD_DIR" --target all --target mlir-cpu-runner
45 changes: 45 additions & 0 deletions build_tools/github_actions/ci_build_stablehlo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/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
# caching 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"

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

# Build and Check StableHLO
cd "$STABLEHLO_BUILD_DIR"
ninja check-stablehlo
GleasonK marked this conversation as resolved.
Show resolved Hide resolved
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