interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / tools / extract / extract.sh

111 lines · 6035 bytes Raw Blame History
1#!/usr/bin/env bash
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# extract.sh: cut the CUDA++ history out of Omega and physics with git's own
4# tools (fast-export path-limited, fast-import into fresh repos). No git-filter-repo
5# (it is Python; the project has none).
6#
7# tools/extract/extract.sh WORK_DIR GRAPH_DIR [OMEGA_REV] [PHYSICS_REV]
8#
9# WORK_DIR gets: omega.git, physics.git (fresh bare clones from GitHub),
10# omega-cut.git, physics-cut.git (the kept history), paths-*.txt (kept paths with
11# every earlier name each file had), commit-map-*.tsv (old sha -> new sha) and
12# tree-check-*.txt (every kept blob at the tip equals the original's).
13# GRAPH_DIR is the output of graph.sh (keep-paths.txt).
14set -euo pipefail
15export LC_ALL=C
16
17work=${1:?work dir}
18graph=${2:?graph dir}
19omega_rev=${3:-main}
20physics_rev=${4:-main}
21here=$(cd "$(dirname "$0")" && pwd)
22mkdir -p "$work"
23work=$(cd "$work" && pwd)
24
25clone() { # url dir
26 if [[ -d $2 ]]; then git -C "$2" fetch -q origin '+refs/heads/*:refs/heads/*'; else git clone -q --bare "$1" "$2"; fi
27}
28clone git@github.com:aien-spark/omega.git "$work/omega.git"
29clone git@github.com:aien-spark/physics.git "$work/physics.git"
30
31# expand REPO REV PATHFILE OUT: add every earlier name of every kept file
32expand() {
33 local repo=$1 rev=$2 in=$3 outf=$4 p
34 : > "$outf.new"
35 while IFS= read -r p; do
36 [[ -z $p || $p == \#* ]] && continue
37 echo "$p" >> "$outf.new"
38 if git -C "$repo" cat-file -e "$rev:$p" 2>/dev/null && [[ $(git -C "$repo" cat-file -t "$rev:$p") == blob ]]; then
39 git -C "$repo" log --follow --name-only --format= "$rev" -- "$p" >> "$outf.new"
40 fi
41 done < "$in"
42 # a --follow hit that still exists at the tip is a separate file (a copy), not a predecessor
43 grep . "$outf.new" | sort -u | while IFS= read -r p; do
44 if grep -qxF "$p" "$in" || ! git -C "$repo" cat-file -e "$rev:$p" 2>/dev/null; then echo "$p"; fi
45 done > "$outf"; rm -f "$outf.new"
46}
47
48# cut REPO REV PATHFILE DEST NAME
49# fast-export eats the first "--" itself (parse-options), so the paths need a second one.
50cut_history() {
51 local repo=$1 rev=$2 paths=$3 dest=$4 name=$5
52 rm -rf "$dest"; git init -q --bare "$dest"
53 # export a named ref: fast-export writes the ref name into the stream
54 git -C "$repo" update-ref refs/heads/cudapp-cut "$rev"
55 mapfile -t list < "$paths"
56 local x
57 while IFS= read -r x; do [[ -n $x && $x != \#* ]] && list+=(":(exclude)$x"); done < "$here/$name-exclude.txt"
58 git -C "$repo" fast-export --signed-tags=strip --tag-of-filtered-object=drop \
59 --export-marks="$work/marks-$name-export" --reencode=yes refs/heads/cudapp-cut -- -- "${list[@]}" |
60 git -C "$dest" fast-import --quiet --export-marks="$work/marks-$name-import"
61 # fast-export names the ref after REV; normalise to refs/heads/main
62 local ref
63 ref=$(git -C "$dest" for-each-ref --format='%(refname)' refs/heads | head -1)
64 [[ $ref == refs/heads/main ]] || git -C "$dest" update-ref refs/heads/main "$ref"
65 join <(sort "$work/marks-$name-export") <(sort "$work/marks-$name-import") |
66 awk '{print $2"\t"$3}' > "$work/commit-map-$name.tsv"
67}
68
69# tree_check REPO REV DEST PATHFILE NAME: kept tip blobs must equal the originals
70tree_check() {
71 local repo=$1 rev=$2 dest=$3 paths=$4 name=$5 p a b bad=0
72 : > "$work/tree-check-$name.txt"
73 while IFS= read -r p; do
74 [[ -z $p || $p == \#* ]] && continue
75 a=$(git -C "$repo" ls-tree -r "$rev" -- "$p" | awk -v ex="$here/$name-exclude.txt" 'BEGIN {while ((getline l < ex) > 0) if (l !~ /^#/ && l != "") skip[l]=1} !($4 in skip) {print $3"\t"$4}' | sort)
76 b=$(git -C "$dest" ls-tree -r main -- "$p" | awk '{print $3"\t"$4}' | sort)
77 if [[ $a == "$b" && -n $a ]]; then echo "same $p" >> "$work/tree-check-$name.txt"
78 else echo "DIFF $p" >> "$work/tree-check-$name.txt"; bad=1; fi
79 done < "$paths"
80 # nothing outside the kept paths may be in the cut tip
81 git -C "$dest" ls-tree -r --name-only main > "$work/tip-files-$name.txt"
82 while IFS= read -r f; do
83 grep -qxF "$f" <(git -C "$repo" ls-tree -r --name-only "$rev" -- $(grep -v '^#' "$paths")) ||
84 { echo "EXTRA $f" >> "$work/tree-check-$name.txt"; bad=1; }
85 done < "$work/tip-files-$name.txt"
86 echo "$name tree check: $(grep -c '^same' "$work/tree-check-$name.txt") same, $(grep -c -v '^same' "$work/tree-check-$name.txt" || true) not"
87 return $bad
88}
89
90omega_tip=$(git -C "$work/omega.git" rev-parse "$omega_rev")
91physics_tip=$(git -C "$work/physics.git" rev-parse "$physics_rev")
92echo "omega $omega_rev = $omega_tip; physics $physics_rev = $physics_tip"
93
94expand "$work/omega.git" "$omega_tip" "$graph/keep-paths.txt" "$work/paths-omega.txt"
95grep -v '^#' "$here/physics-paths.txt" | grep . > "$work/keep-physics.txt"
96expand "$work/physics.git" "$physics_tip" "$work/keep-physics.txt" "$work/paths-physics.txt"
97# earlier names that are not kept names: listed for the audit (they carry history in)
98comm -13 <(sort -u "$graph/keep-paths.txt") "$work/paths-omega.txt" > "$work/lineage-omega.txt" || true
99comm -13 <(sort -u "$work/keep-physics.txt") "$work/paths-physics.txt" > "$work/lineage-physics.txt" || true
100# the excluded binary must not come back through lineage
101grep -vxF -f "$here/physics-exclude.txt" "$work/paths-physics.txt" > "$work/paths-physics.txt.k" || true
102mv "$work/paths-physics.txt.k" "$work/paths-physics.txt"
103
104cut_history "$work/omega.git" "$omega_tip" "$work/paths-omega.txt" "$work/omega-cut.git" omega
105cut_history "$work/physics.git" "$physics_tip" "$work/paths-physics.txt" "$work/physics-cut.git" physics
106
107rc=0
108tree_check "$work/omega.git" "$omega_tip" "$work/omega-cut.git" "$graph/keep-paths.txt" omega || rc=1
109tree_check "$work/physics.git" "$physics_tip" "$work/physics-cut.git" "$work/keep-physics.txt" physics || rc=1
110echo "omega-cut $(git -C "$work/omega-cut.git" rev-list --count main) commits, physics-cut $(git -C "$work/physics-cut.git" rev-list --count main) commits"
111exit $rc