Skip to content

Commit

Permalink
Refactor common steps and add python release.
Browse files Browse the repository at this point in the history
  • Loading branch information
stellaraccident authored Mar 13, 2024
1 parent a9ee7bc commit f51da82
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 48 deletions.
18 changes: 2 additions & 16 deletions .github/workflows/build_linux_packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,18 @@ jobs:
- name: Install Deps
run: |
curl https://storage.googleapis.com/git-repo-downloads/repo > /usr/local/bin/repo
chmod a+x /usr/local/bin/repo
yum install -y numactl-devel elfutils-libelf-devel vim-common git-lfs
pip install CppHeaderParser
./build_tools/ci_install_build_deps.sh
- name: Fetch sources
run: |
./fetch_sources.sh
- name: Apply patches
run: |
./apply_patches.sh
./build_tools/fetch_sources.py
# The full checkout is very large: ~16GB, 9 of which is GIT stuff.
# So we delete the latter. This must be done after getting any git
# stamps or such things.
- name: Trim Disk Space
run: |
rm -Rf sources/.repo
# Delete some things that we aren't building.
# TODO: Would be better to have repo only fetch a smaller working set.
rm -Rf sources/MIVisionX # ~200M
rm -Rf sources/MIOpen # ~400M
rm -Rf sources/hipBLASLt # ~750M
rm -Rf sources/rocBLAS # ~900M
rm -Rf sources/ROCK-Kernel-Driver # ~1.5G
df -h
- name: Build Projects
Expand Down
111 changes: 111 additions & 0 deletions .github/workflows/build_python_packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Build Linux Packages

on:
pull_request:
push:
branches:
- main
paths:
- .github/workflows/build_python_packages.yml
- python_projects/*

workflow_dispatch:
inputs:
package_version:
required: false
type: string
package_suffix:
required: false
type: string

workflow_call:
inputs:
package_version:
required: false
type: string
package_suffix:
required: false
type: string

jobs:
build_python_packages:
name: Build Python Packages
runs-on: nod-ai-shared-cpubuilder-manylinux-x86_64
strategy:
fail-fast: true
env:
CACHE_DIR: ${{ github.workspace }}/.container-cache
CCACHE_DIR: "${{ github.workspace }}/.container-cache/ccache"
CCACHE_MAXSIZE: "700M"
steps:
- name: "Checking out repository"
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0

- name: Report Runner Health
run: |
echo "CCACHE_DIR=${CCACHE_DIR}"
df -h
ccache -z
mkdir -p $CCACHE_DIR
cmake --version
# TODO: We shouldn't be using a cache on actual release branches, but it
# really helps for iteration time.
- name: Enable cache
uses: actions/cache/restore@v3
with:
path: ${{ env.CACHE_DIR }}
key: build-python-manylinux-v2-${{ github.sha }}
restore-keys: |
build-python-manylinux-v2-
- name: Install Deps
run: |
./build_tools/ci_install_build_deps.sh
- name: Fetch sources
run: |
./build_tools/fetch_sources.py
# The full checkout is very large: ~16GB, 9 of which is GIT stuff.
# So we delete the latter. This must be done after getting any git
# stamps or such things.
- name: Trim Disk Space
run: |
rm -Rf sources/.repo
df -h
- name: Build Projects
run: |
cd python_projects/runtime
export THEROCK_PY_VERSION="${{ inputs.package_version }}"
export THEROCK_PY_SUFFIX="${{ inputs.package_suffix }}"
export CMAKE_C_COMPILER_LAUNCHER=ccache
export CMAKE_CXX_COMPILER_LAUNCHER=ccache
echo "Building package ${THEROCK_PY_VERSION}"
pip wheel -v .
auditwheel TheRock_runtime*.whl
- name: Report
if: ${{ !cancelled() }}
run: |
ls -lh build build/wheelhouse
ccache -s
- name: Upload artifacts
uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: TheRock-python-runtime-linux-x86_64
path: |
python_projects/runtime/wheelhouse/*.whl
if-no-files-found: warn

- name: Save cache
uses: actions/cache/save@v3
if: always()
with:
path: ${{ env.CACHE_DIR }}
key: build-python-manylinux-v2-${{ github.sha }}


18 changes: 17 additions & 1 deletion .github/workflows/nightly_staging_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ jobs:
with:
package_version: ${{ needs.setup.outputs.package_version }}

build_python_packages:
name: Build Python Packages
needs: setup
uses: ./.github/workflows/build_python_packages.yml
with:
package_version: ${{ needs.setup.outputs.package_version }}

upload_release_assets:
name: Upload Release Assets
needs: [setup, build_linux_packages]
Expand All @@ -86,14 +93,23 @@ jobs:
path: linux-x86_64
pattern: TheRock-*-linux-x86_64-*
merge-multiple: true
- name: Download Python Artifacts
uses: actions/download-artifact@v4
with:
path: python
pattern: TheRock-python-runtime-linux-x86_64
merge-multiple: true
- name: List Files
run: |
ls -l linux-x86_64
ls -l python
- name: Upload Release Assets
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload ${{ needs.setup.outputs.tag_name }} linux-x86_64/*
gh release upload ${{ needs.setup.outputs.tag_name }} \
linux-x86_64/* \
python/*
finalize_release:
name: Finalise Release
Expand Down
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ We want ROCm sources checked out into the sources/ directory or if you check it
## Via script

```
./fetch_sources.sh
./build_tools/fetch_sources.sh
```

## Manually
Expand Down Expand Up @@ -49,14 +49,6 @@ cd TheRock
ln -s </path/to/rocm> sources
```

## Applying hacks/patches

Here are current patch topics that we are maintaining.

```
./apply_patches.sh
```

# Build

```
Expand Down
11 changes: 8 additions & 3 deletions apply_patches.sh → build_tools/apply_patches.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
#!/bin/bash
# Applies patches that we are maintaining on the ROCM sources.
# These are developed against HEAD.
# Must be run from the repo checkout dir.
set -euxo pipefail

repo_dir="$(pwd)"
this_dir="$(cd $(dirname $0) && pwd)"
root_dir="$(cd $this_dir/.. && pwd)"

function stash_changes() {
local repo_name="$1"
cd $this_dir/sources/$repo_name
cd $repo_dir/$repo_name
git add -A
git stash
}

function apply_patch() {
local repo_name="$1"
local patch_file="$2"
cd $this_dir/sources/$repo_name
cd $repo_dir/$repo_name
echo "Applying $patch_file to $repo_name"
patch -p1 < $this_dir/patches/$patch_file
patch -p1 < $root_dir/patches/$patch_file
}

echo "Running from $PWD"

stash_changes clr
apply_patch clr clr-disable-hipconfig-check.patch
apply_patch clr clr-respect-no-versioned-soname.patch
Expand Down
6 changes: 6 additions & 0 deletions build_tools/ci_install_build_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

curl https://storage.googleapis.com/git-repo-downloads/repo > /usr/local/bin/repo
chmod a+x /usr/local/bin/repo
yum install -y numactl-devel elfutils-libelf-devel vim-common git-lfs
pip install CppHeaderParser
81 changes: 81 additions & 0 deletions build_tools/fetch_sources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env python
# Fetches sources from a specified branch/set of projects.
# This script is available for users, but it is primarily the mechanism
# the CI uses to get to a clean state.

import argparse
from pathlib import Path
import subprocess
import sys

DEFAULT_SOURCES_DIR = Path(__file__).resolve().parent.parent / "sources"


def exec(args: list[str], cwd: Path):
print(f"++ Exec: {args} (in {cwd})")
subprocess.check_call(args, cwd=str(cwd))


def run(args):
repo_dir: Path = args.dir
print(f"Setting up repo in {repo_dir}")
repo_dir.mkdir(exist_ok=True, parents=True)
exec(
[
"repo",
"init",
"-u",
"https://github.com/RadeonOpenCompute/ROCm.git",
"--depth=1",
],
cwd=repo_dir,
)
exec(["repo", "sync", "-j16"] + args.projects, cwd=repo_dir)

# Fixup LLVM.
if "llvm-project" in args.projects:
print("Fixing up llvm-project")
llvm_dir = repo_dir / "llvm-project"
exec(["git", "fetch", "rocm-org", "amd-staging", "--depth=1"], cwd=llvm_dir)
exec(["git", "checkout", "rocm-org/amd-staging"], cwd=llvm_dir)

# Patches.
if not args.no_patch:
apply_patches(args)


def apply_patches(args):
# TODO: Can just merge this script in here if it survives.
script = Path(__file__).resolve().parent / "apply_patches.sh"
exec([script], cwd=args.dir)


def main(argv):
parser = argparse.ArgumentParser(prog="fetch_sources")
parser.add_argument(
"--dir", type=Path, help="Repo dir", default=DEFAULT_SOURCES_DIR
)
parser.add_argument(
"--branch", type=str, help="Branch to sync", default="amd-staging"
)
parser.add_argument("--no-patch", action="store_true", help="Disable patching")
parser.add_argument(
"--projects",
nargs="+",
type=str,
default=[
"clr",
"HIP",
"llvm-project",
"rocm-cmake",
"rocm-core",
"ROCR-Runtime",
"ROCT-Thunk-Interface",
],
)
args = parser.parse_args(argv)
run(args)


if __name__ == "__main__":
main(sys.argv[1:])
17 changes: 0 additions & 17 deletions fetch_sources.sh

This file was deleted.

7 changes: 5 additions & 2 deletions python_projects/runtime/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ def finalize_options(self):
bdist_wheel = None


VERSION = os.getenv("THEROCK_PY_VERSION", "0.1.dev1")
VERSION = os.getenv("THEROCK_PY_VERSION", None)
SUFFIX = os.getenv("THEROCK_PY_SUFFIX", "")
if not VERSION:
VERSION = "0.1.dev1"
SETUPPY_DIR = Path(__file__).resolve().parent
SOURCE_DIR = SETUPPY_DIR.parent.parent
# Note that setuptools always builds into a "build" directory that
Expand Down Expand Up @@ -107,7 +110,7 @@ def run(self):
CMAKE_BUILD_DIR.mkdir(parents=True, exist_ok=True)

setup(
name=f"TheRock-runtime",
name=f"TheRock-runtime{SUFFIX}",
version=f"{VERSION}", # TODO: Get from env var.
author="TheRock Authors",
author_email="[email protected]",
Expand Down

0 comments on commit f51da82

Please sign in to comment.