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

[RFC + PR] Use TCP for {LLVM / Torch-MLIR / StableHLO} Green Commit Sync #11

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 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
# Also available under a BSD-style license. See LICENSE.

third_party/
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is where local repos may be cloned

82 changes: 82 additions & 0 deletions .github/workflows/bazelBuildAndTestLlvm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# 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
# Also available under a BSD-style license. See LICENSE.

name: Bazel Build and Test (llvm-project)

# Only run when llvm-project hash changes (deps.bzl)
on:
pull_request:
branches:
- main
paths:
- 'deps.bzl'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is so the workflow is triggered only when change is made to deps.bzl, as otherwise we shouldn't have to re-run a workflow (3p test status shouldn't change)

push:
branches:
- main
paths:
- 'deps.bzl'
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


jobs:
ubuntu-build:
name: ubuntu-x86_64 / llvm-project
runs-on: ubuntu-latest

steps:
- name: Checkout mlir-tcp
uses: actions/checkout@v3

# Continually update cache even if there's a "hit" during
# restore to avoid the cache going stale over time
# https://github.com/actions/cache/blob/main/tips-and-workarounds.md#update-a-cache
- name: Setup cache for bazel
uses: actions/cache@v3
with:
path: ~/.cache/bazel
key: llvm-project-bazel-build-cache-${{ runner.os }}-${{ github.sha }}
restore-keys: |
llvm-project-bazel-build-cache-${{ runner.os }}

# Change bazel cache directory to root ownership
# to allow writing to it from within the docker container.
# If no cache hits, this directory is not present
# so don't run chown (will error otherwise).
- name: Set bazel cache permissions
run: |
if [ -d "${HOME}/.cache/bazel" ]; then
sudo chown -R root:root "${HOME}/.cache/bazel"
fi

- name: Build docker image
run: |
docker build -f docker/Dockerfile \
-t mlir-tcp:ci \
.

- name: Bazel build and test llvm-project
run: |
docker run --rm \
-v "$(pwd)":"/opt/src/mlir-tcp" \
-v "${HOME}/.cache/bazel":"/root/.cache/bazel" \
mlir-tcp:ci \
bazel test --config=clang_linux @llvm-project//mlir/...

# Switch back bazel cache directory to user ownership
# to allow GHA post-cache step to save cache without
# permissions issue.
- name: Switch bazel cache permissions
run: |
if [ -d "${HOME}/.cache/bazel" ]; then
sudo chown -R "$USER":"$USER" "${HOME}/.cache/bazel"
fi
82 changes: 82 additions & 0 deletions .github/workflows/bazelBuildAndTestStablehlo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# 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
# Also available under a BSD-style license. See LICENSE.

name: Bazel Build and Test (stablehlo)

# Only run when stablehlo hash changes (deps.bzl)
on:
pull_request:
branches:
- main
paths:
- 'deps.bzl'
push:
branches:
- main
paths:
- 'deps.bzl'
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


jobs:
ubuntu-build:
name: ubuntu-x86_64 / stablehlo
runs-on: ubuntu-latest

steps:
- name: Checkout mlir-tcp
uses: actions/checkout@v3

# Continually update cache even if there's a "hit" during
# restore to avoid the cache going stale over time
# https://github.com/actions/cache/blob/main/tips-and-workarounds.md#update-a-cache
- name: Setup cache for bazel
uses: actions/cache@v3
with:
path: ~/.cache/bazel
key: stablehlo-bazel-build-cache-${{ runner.os }}-${{ github.sha }}
restore-keys: |
stablehlo-bazel-build-cache-${{ runner.os }}

# Change bazel cache directory to root ownership
# to allow writing to it from within the docker container.
# If no cache hits, this directory is not present
# so don't run chown (will error otherwise).
- name: Set bazel cache permissions
run: |
if [ -d "${HOME}/.cache/bazel" ]; then
sudo chown -R root:root "${HOME}/.cache/bazel"
fi

- name: Build docker image
run: |
docker build -f docker/Dockerfile \
-t mlir-tcp:ci \
.

- name: Bazel build and test stablehlo
run: |
docker run --rm \
-v "$(pwd)":"/opt/src/mlir-tcp" \
-v "${HOME}/.cache/bazel":"/root/.cache/bazel" \
mlir-tcp:ci \
bazel test --config=clang_linux @stablehlo//...

# Switch back bazel cache directory to user ownership
# to allow GHA post-cache step to save cache without
# permissions issue.
- name: Switch bazel cache permissions
run: |
if [ -d "${HOME}/.cache/bazel" ]; then
sudo chown -R "$USER":"$USER" "${HOME}/.cache/bazel"
fi
12 changes: 7 additions & 5 deletions .github/workflows/bazelBuildAndTestTcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# Also available under a BSD-style license. See LICENSE.

name: Bazel Build and Test
name: Bazel Build and Test (mlir-tcp)

on:
pull_request:
branches: [ main ]
branches:
- main
push:
branches: [ main ]
branches:
- main
workflow_dispatch:

# Ensure that only a single job or workflow using the same
Expand All @@ -23,7 +25,7 @@ concurrency:

jobs:
ubuntu-build:
name: ubuntu-x86_64
name: ubuntu-x86_64 / mlir-tcp
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name change allows selectively making certain workflows merge gating

runs-on: ubuntu-latest

steps:
Expand All @@ -32,7 +34,7 @@ jobs:

# Continually update cache even if there's a "hit" during
# restore to avoid the cache going stale over time
# https://github.com/actions/cache/blob/main/workarounds.md#update-a-cache
# https://github.com/actions/cache/blob/main/tips-and-workarounds.md#update-a-cache
- name: Setup cache for bazel
uses: actions/cache@v3
with:
Expand Down
82 changes: 82 additions & 0 deletions .github/workflows/bazelBuildAndTestTorchmlir.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# 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
# Also available under a BSD-style license. See LICENSE.

name: Bazel Build and Test (torch-mlir)

# Only run when torch-mlir hash changes (deps.bzl)
on:
pull_request:
branches:
- main
paths:
- 'deps.bzl'
push:
branches:
- main
paths:
- 'deps.bzl'
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


jobs:
ubuntu-build:
name: ubuntu-x86_64 / torch-mlir
runs-on: ubuntu-latest

steps:
- name: Checkout mlir-tcp
uses: actions/checkout@v3

# Continually update cache even if there's a "hit" during
# restore to avoid the cache going stale over time
# https://github.com/actions/cache/blob/main/tips-and-workarounds.md#update-a-cache
- name: Setup cache for bazel
uses: actions/cache@v3
with:
path: ~/.cache/bazel
key: torch-mlir-bazel-build-cache-${{ runner.os }}-${{ github.sha }}
restore-keys: |
torch-mlir-bazel-build-cache-${{ runner.os }}

# Change bazel cache directory to root ownership
# to allow writing to it from within the docker container.
# If no cache hits, this directory is not present
# so don't run chown (will error otherwise).
- name: Set bazel cache permissions
run: |
if [ -d "${HOME}/.cache/bazel" ]; then
sudo chown -R root:root "${HOME}/.cache/bazel"
fi

- name: Build docker image
run: |
docker build -f docker/Dockerfile \
-t mlir-tcp:ci \
.

- name: Bazel build and test torch-mlir
run: |
docker run --rm \
-v "$(pwd)":"/opt/src/mlir-tcp" \
-v "${HOME}/.cache/bazel":"/root/.cache/bazel" \
mlir-tcp:ci \
bazel test --config=clang_linux @torch-mlir//...

# Switch back bazel cache directory to user ownership
# to allow GHA post-cache step to save cache without
# permissions issue.
- name: Switch bazel cache permissions
run: |
if [ -d "${HOME}/.cache/bazel" ]; then
sudo chown -R "$USER":"$USER" "${HOME}/.cache/bazel"
fi
14 changes: 10 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
/bazel-bin
/bazel-out
/bazel-mlir-tcp
/bazel-testlogs
# 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
# Also available under a BSD-style license. See LICENSE.

bazel-bin
bazel-out
bazel-mlir-tcp
bazel-testlogs
third_party/
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Tensor Compute Primitives

Mid-level intermediate representation for machine learning programs.

![Bazel Build](https://github.com/cruise-automation/mlir-tcp/actions/workflows/bazelBuildAndTestTcp.yml/badge.svg)
[![Bazel Build and Test (mlir-tcp)](https://github.com/cruise-automation/mlir-tcp/actions/workflows/bazelBuildAndTestTcp.yml/badge.svg)](https://github.com/cruise-automation/mlir-tcp/actions/workflows/bazelBuildAndTestTcp.yml)

:construction: **This project is under active development (WIP).**

Expand Down Expand Up @@ -40,3 +40,15 @@ find . -type f -name "*.cpp" -o -name "*.h" | xargs clang-format -i
# buildifer
bazel run --config=clang_linux //:buildifier
```

When bumping upstream dependencies (LLVM, Torch-MLIR, StableHLO), you may validate the set of "green commits" by running the corresponding third-party tests:
```shell
bazel test --config=clang_linux @llvm-project//mlir/...
bazel test --config=clang_linux @torch-mlir//...
bazel test --config=clang_linux @stablehlo//...
```

The following CI workflows are automatically triggered anytime upstream dependencies (`deps.bzl`) are updated:
- [![Bazel Build and Test (llvm-project)](https://github.com/cruise-automation/mlir-tcp/actions/workflows/bazelBuildAndTestLlvm.yml/badge.svg)](https://github.com/cruise-automation/mlir-tcp/actions/workflows/bazelBuildAndTestLlvm.yml)
- [![Bazel Build and Test (torch-mlir)](https://github.com/cruise-automation/mlir-tcp/actions/workflows/bazelBuildAndTestTorchmlir.yml/badge.svg)](https://github.com/cruise-automation/mlir-tcp/actions/workflows/bazelBuildAndTestTorchmlir.yml)
- [![Bazel Build and Test (stablehlo)](https://github.com/cruise-automation/mlir-tcp/actions/workflows/bazelBuildAndTestStablehlo.yml/badge.svg)](https://github.com/cruise-automation/mlir-tcp/actions/workflows/bazelBuildAndTestStablehlo.yml)
Loading