Skip to content

[AIROCMLIR-798] Add LDS usage estimate CAPI function #3870

[AIROCMLIR-798] Add LDS usage estimate CAPI function

[AIROCMLIR-798] Add LDS usage estimate CAPI function #3870

Workflow file for this run

name: rocMLIR GitHub Actions
on:
pull_request:
branches:
- develop
- 'release/**'
paths:
- "mlir/**"
- "external/**"
- "!external/llvm-project/**"
- "CMakeLists.txt"
- "cmake/**"
- ".github/workflows/**"
- "pip_requirements.txt"
- ".clang-format"
- ".clang-tidy"
push:
branches:
- develop
- 'release/**'
paths:
- "mlir/**"
- "external/**"
- "!external/llvm-project/**"
- "CMakeLists.txt"
- "cmake/**"
- ".github/workflows/**"
- "pip_requirements.txt"
- ".clang-format"
- ".clang-tidy"
jobs:
cpp-static-checks:
name: C/C++ premerge checks
runs-on: ubuntu-latest
container:
image: rocm/mlir:rocm7.2-latest
options: --user root
steps:
- uses: actions/checkout@v4
with:
# Full history is required for git-restore-mtime below (mtimes
# are computed from the last commit touching each file).
fetch-depth: 0
- name: Fix git ownership
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Determine base branch ref
id: base
if: github.event_name == 'pull_request'
shell: bash
run: |
BASE_REF="origin/${{ github.base_ref }}"
BASE_BRANCH="${{ github.base_ref }}"
git fetch origin "$BASE_BRANCH:refs/remotes/origin/$BASE_BRANCH" || \
git fetch origin "$BASE_BRANCH" || true
if ! git rev-parse --verify "$BASE_REF" >/dev/null 2>&1; then
echo "Error: Base ref '$BASE_REF' does not exist locally. Fetch may have failed." >&2
exit 1
fi
echo "ref=$BASE_REF" >> "$GITHUB_OUTPUT"
echo "Base ref: $BASE_REF"
- name: Restore source mtimes
shell: bash
run: |
set -euo pipefail
# checkout sets all mtimes to "now". Pretouch to a floor, then restore
# real commit mtimes for everything except external/llvm-project
# (covered by external/ tree SHA in the cache key). --merge closes
# the merge-commit blind spot. Runs on both push (seed) and PR.
apt-get update -qq
apt-get install -y -qq git-restore-mtime
git ls-files -z | xargs -0r touch -d "2000-01-01T00:00:00Z"
mapfile -t SCOPE < <(
git ls-tree --name-only HEAD | grep -v '^external$'
git ls-tree --name-only HEAD external/ | grep -v '^external/llvm-project$'
)
git restore-mtime --skip-missing --merge --quiet -- "${SCOPE[@]}"
- name: Force-touch PR-modified files
if: github.event_name == 'pull_request'
shell: bash
run: |
set -euo pipefail
# Force-touch files modified by this PR so ninja regenerates anything
# affected (e.g. .td -> .inc) even when restored cache artifacts look
# newer by mtime. Deleted files (D) are excluded; NUL-delimited to
# handle paths with spaces.
git diff -z --name-only --diff-filter=ACMR \
"${{ steps.base.outputs.ref }}"...HEAD \
| xargs -0r touch || true
- name: Install Python dependencies for premerge checks
if: github.event_name == 'pull_request'
shell: bash
run: |
python3 -m pip install --upgrade pip
python3 -m pip install pathspec==0.12.1 unidiff==0.7.5 GitPython==3.1.44
- name: Compute external/ tree SHA (for cache key)
id: ext
shell: bash
run: |
# external/ tree SHA in the cache key invalidates the cache on
# any LLVM subtree pull, [EXTERNAL] patch, or mlir-hal edit.
echo "hash=$(git rev-parse HEAD:external | cut -c1-12)" >> "$GITHUB_OUTPUT"
- name: Cache CMake build directory (compile_commands.json generation)
uses: actions/cache@v4
with:
path: build
# ext SHA prefix locks the cache to the current external/ state.
# Any LLVM/mlir-hal change forces a cold rebuild instead of
# restoring a build/ that ninja would treat as up-to-date by mtime.
key: cpp-static-checks-${{ runner.os }}-ext${{ steps.ext.outputs.hash }}-${{ hashFiles('CMakeLists.txt', 'cmake/**', 'mlir/**/CMakeLists.txt') }}
restore-keys: |
cpp-static-checks-${{ runner.os }}-ext${{ steps.ext.outputs.hash }}-
- name: Generate compile_commands.json (CMake configure)
shell: bash
run: |
set -euo pipefail
# Always remove CMakeCache.txt before configuring. A stale cache
# (e.g. restored from a run where MLIR_ENABLE_ROCM_RUNNER=OFF) causes
# LLVM_TARGETS_TO_BUILD to stay as "AMDGPU" (set without FORCE), which
# prevents mlir_rocm_runtime from being created even when
# MLIR_ENABLE_ROCM_RUNNER=1 is passed on the command line.
rm -f build/CMakeCache.txt
# MLIR_ENABLE_ROCM_RUNNER=1: includes ROCm runner source files in
# compile_commands.json for full clang-tidy coverage matching Jenkins.
# ROCM_TEST_CHIPSET=gfx90a: bypasses rocm_agent_enumerator (which fails
# on CPU-only runners) so mlir_rocm_runtime target is always created.
# No physical GPU is needed — configure only requires ROCm libraries,
# which are present in the rocm/mlir container.
cmake -S . -B build -G Ninja \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON \
-DCMAKE_C_COMPILER=/opt/rocm/llvm/bin/clang \
-DCMAKE_CXX_COMPILER=/opt/rocm/llvm/bin/clang++ \
-DMLIR_ENABLE_ROCM_RUNNER=1 \
-DROCM_TEST_CHIPSET=gfx90a \
-DMLIR_INCLUDE_INTEGRATION_TESTS=OFF \
-DROCMLIR_DRIVER_PR_E2E_TEST_ENABLED=0 \
|| (echo "CMake configure failed. Dumping logs:"; \
(test -f build/CMakeFiles/CMakeError.log && cat build/CMakeFiles/CMakeError.log) || true; \
(test -f build/CMakeFiles/CMakeOutput.log && cat build/CMakeFiles/CMakeOutput.log) || true; \
exit 1)
if [[ ! -f build/compile_commands.json ]]; then
echo "Error: build/compile_commands.json was not generated."
echo "Dumping build directory summary and relevant cache entries..."
ls -la build || true
(test -f build/CMakeCache.txt && (grep -E 'CMAKE_EXPORT_COMPILE_COMMANDS|CMAKE_GENERATOR|CMAKE_CXX_COMPILER|CMAKE_C_COMPILER' build/CMakeCache.txt || true)) || true
exit 1
fi
ln -sf build/compile_commands.json compile_commands.json
- name: Build TableGen-generated headers
shell: bash
run: |
set -euo pipefail
# mlir-headers covers upstream MLIR + everything chained into it.
# The targets below are mlir-hal and rocMLIR orphan tablegen
# targets not hooked into mlir-headers. Any new orphan
# add_public_tablegen_target() declared in this repo must be
# added to the list below.
cmake --build build --target \
mlir-headers \
MHALConversionPassIncGen \
MLIRMHALAttrDefsIncGen \
MLIRMHALPassIncGen \
MLIRRockAttrDefsIncGen \
MLIRRockTuningParamAttrInterfaceIncGen \
MLIRRockAccelTuningParamAttrInterfaceIncGen \
MLIRRockPassIncGen \
RocMLIRConversionPassIncGen \
MLIRMIGraphXTypeIncGen \
MLIRMIGraphXPassIncGen
- name: Run premerge static checks (format + tidy)
if: github.event_name == 'pull_request'
shell: bash
run: |
set -euo pipefail
export PATH="/opt/rocm/llvm/bin:$PATH"
# premerge-checks.py invokes `git-clang-format`; ensure it's on PATH.
git_clang_format="$GITHUB_WORKSPACE/external/llvm-project/clang/tools/clang-format/git-clang-format"
if [[ ! -f "$git_clang_format" ]]; then
echo "Error: git-clang-format not found at $git_clang_format"
echo "Ensure submodules are initialized (git submodule update --init)."
exit 1
fi
chmod +x "$git_clang_format"
export PATH="$GITHUB_WORKSPACE/external/llvm-project/clang/tools/clang-format:$PATH"
python3 ./mlir/utils/jenkins/static-checks/premerge-checks.py \
--base-commit="${{ steps.base.outputs.ref }}"
format-and-lint-checks:
name: Python format and lint checks
runs-on: ubuntu-latest
container:
image: python:3.10
options: --user root
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fix git ownership
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r pip_requirements.txt
- name: Get changed Python files under mlir/
id: changes
shell: bash
run: |
echo "Determining merge base..."
if [ "${{ github.event_name }}" = "pull_request" ]; then
BASE_REF="origin/${{ github.base_ref }}"
BASE_BRANCH="${{ github.base_ref }}"
else
BASE_REF="origin/${{ github.ref_name }}"
BASE_BRANCH="${{ github.ref_name }}"
fi
echo "BASE_REF=$BASE_REF"
echo "BASE_BRANCH=$BASE_BRANCH"
# Fetch the base branch explicitly
git fetch origin "$BASE_BRANCH:refs/remotes/origin/$BASE_BRANCH" || \
git fetch origin "$BASE_BRANCH" || true
# Verify that BASE_REF exists locally
if ! git rev-parse --verify "$BASE_REF" >/dev/null 2>&1; then
echo "Error: Base ref '$BASE_REF' does not exist locally. Fetch may have failed." >&2
exit 1
fi
BASE_SHA=$(git merge-base HEAD "$BASE_REF")
echo "BASE_SHA=$BASE_SHA"
# Get added/modified Python files under mlir/ (space-separated)
files=$(git diff --name-only --diff-filter=AM "$BASE_SHA"...HEAD \
| grep -E '^mlir/.*\.py$' | tr '\n' ' ' || true)
echo "files=$files" >> $GITHUB_OUTPUT
echo "Changed Python files:"
echo "$files"
- name: Run flake8
if: steps.changes.outputs.files != ''
run: |
files="${{ steps.changes.outputs.files }}"
if [ -n "$files" ]; then
flake8 --ignore=E501,E251,E124,W605,W504,E131,E126,W503,E123 $files
fi
- name: Run YAPF check
if: steps.changes.outputs.files != ''
run: |
files="${{ steps.changes.outputs.files }}"
if [ -n "$files" ]; then
yapf --diff $files \
|| (echo "Format issues found. Fix locally with: yapf -i <files>"; exit 1)
fi
- name: No Python changes in mlir/
if: steps.changes.outputs.files == ''
run: echo "No changed *.py files under mlir/ – skipping."
python-tests:
name: Python performance script tests
runs-on: ubuntu-latest
container:
image: python:3.10
options: --user root
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fix git ownership
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r pip_requirements.txt
- name: Run performance script tests (no GPU)
run: |
cd mlir/utils/performance && python -m pytest tests/ -v
env:
# Tests mock HIP/GPU; no ROCm or GPU required
PYTHONPATH: ${{ github.workspace }}/mlir/utils/performance