Skip to content
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
117 changes: 97 additions & 20 deletions bin/calculate_divergence.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
# COMPONENT - Index into list of paths (default: "" for entire repo)
# LLVM_BRANCH - LLVM branch to compare (default: main)
# ROCm_BRANCH - ROCm branch to compare (default: amd-staging)
# RESULTS_DIR - Path to results dir (default: <current_dir>/results)
# PER_FILE - Creates per-file diffs (default: 0)
# FILE_GROUPS - Used for per-file diffs to group files together (default: 1)
################################################################################

timestamp="$(date +"%Y-%m-%d_%H-%M")"
Expand All @@ -34,11 +37,11 @@ declare -A components=(
declare -A directories=(
[llvm]=${LLVM_REPO_DIR:=${HOME}/git/llvm-project.diff}
[path]=${LLVM_PATH:=""}
[results]="$(pwd)/results"
[results]=${RESULTS_DIR:="$(pwd)/results"}
)

declare -A diff_args=(
[component]=${COMPONENT:="driver"}
[component]=${COMPONENT:=""}
[options]="stat patch"
)

Expand Down Expand Up @@ -235,19 +238,60 @@ update_sources() {
}

################################################################################
# Calculates the divergence between source and target branches using git's
# merge-base comparison. Generates diff output files in multiple formats
# (stat and patch by default) and saves them to the results directory with
# timestamped filenames. Optionally limits analysis to a specific paths.
# Takes the set of changed files and produces one or more Git patch files
# per logical unit. When FILE_GROUPS is disabled emits on patch per file
# otherwise groups files by their shared base name allowing for combined
# patches for example header and related source files. Each patch is generated
# via `git diff --merge-base` and written into a dedicated, timestamped
# subdirectory under the main results folder, using a sanitized base name for
# the filename.
################################################################################
create_file_patches() {
if [[ ${#changed_files[@]} -eq 0 ]]; then
return 0
fi

print_step "Generating file based git diff --$op"
local results_dir="${directories[results]}/$1"
mkdir -p $results_dir

local -A groups
for cf in "${changed_files[@]}"; do
if [[ "$FILE_GROUPS" -eq 0 ]]; then
git diff --merge-base --$op $a_ref $b_ref -- $cf > "$results_dir/${cf//[\/.]/_}.$op"
else
groups["$(basename "${cf%.*}")"]+=" $cf"
fi
done

if [[ "$FILE_GROUPS" -eq 0 ]]; then
return 0
fi

for key in "${!groups[@]}"; do
cf="${groups[$key]}"
IFS=' ' read -r -a grouped_files <<< "${groups[$key]}"
if [[ ${#grouped_files[@]} > 1 ]]; then
print_info "processing as one:${cf// /$'\n'}"
else
print_info "processing$cf"
fi
git diff --merge-base --$op $a_ref $b_ref --$cf> "$results_dir/${key//[\/.]/_}.$op"
done
}

################################################################################
# Determines the common ancestor (merge-base) of two Git references and
# produces diff outputs between them. Based on configured options, it will
# generate summary statistics and full diffs, saving each to timestamped
# files in the results directory. Optionally limits analysis to specified
# paths. When per-file patching is enabled, it splits the overall patch into
# individual files.
################################################################################
calculate_differences() {
local -n a="$source_config"
local -n b="$target_config"
local a_ref="${a[ref]}"
local b_ref="${b[ref]}"
local path_arg="${diff_args[path]}"

local filename="${a[file]}-${b[file]}${diff_args[file_suffix]}[$timestamp]"
local filename="${timestamp}_${a[file]}-${b[file]}${diff_args[file_suffix]}"
filename="${filename//\//_}"

print_step "Calculating difference"
Expand All @@ -261,11 +305,35 @@ calculate_differences() {
fi

print_info "$(git diff --merge-base --shortstat $a_ref $b_ref $path_arg)"
local per_file_ops=("patch")

IFS=' ' read -ra operations <<< "${diff_args[options]}"
for op in "${operations[@]}"; do
print_info "calculating git diff --$op"
git diff --merge-base --$op $a_ref $b_ref $path_arg > "${directories[results]}/$filename.$op"
if [[ "$PER_FILE" -eq 0 ]] || ! printf "%s\n" "${per_file_ops[@]}" | grep -qx "$op"; then
print_info "calculating git diff --$op"
git diff --merge-base --$op $a_ref $b_ref $path_arg > "${directories[results]}/$filename.$op"
else
mapfile -t changed_files < <(git diff --merge-base --name-only "$a_ref" "$b_ref" $path_arg)
create_file_patches $filename
fi
done
}

################################################################################
# Outputs the script relevant environment variables and the values they are
# set to after they were assigned their default values if not set.
################################################################################
print_environment() {
if [[ "$SILENT" -eq 1 ]]; then
return 0
fi

print_step "Processed environment"
local other_vars=("LLVM_REPO_DIR" "LLVM_PATH" "COMPONENT" "LLVM_BRANCH" "ROCm_BRANCH" "RESULTS_DIR")

for var_name in "${other_vars[@]}" "${default_false[@]}" "${default_true[@]}"; do
local -n var="$var_name"
print_info "$var_name=$var"
done
}

Expand All @@ -280,12 +348,16 @@ calculate_differences() {
# an unrecognized value, it defaults to 0 (false).
################################################################################
process_environment() {
print_step "Process environment"
local boolean_vars=("SKIP_FETCH" "SILENT" "SETUP_ONLY" "SKIP_SETUP")
default_false=("SKIP_FETCH" "SILENT" "SETUP_ONLY" "SKIP_SETUP" "PER_FILE")
default_true=("FILE_GROUPS")

for var_name in "${boolean_vars[@]}"; do
for var_name in "${default_false[@]}" "${default_true[@]}"; do
local -n var="$var_name"
var=${var:-0}
if printf '%s\n' "${default_true[@]}" | grep -qx "$var_name"; then
var=${var:-1}
else
var=${var:-0}
fi

case "${var,,}" in
true|1|yes|y)
Expand All @@ -295,11 +367,9 @@ process_environment() {
var=0
;;
*)
var=0
var=-
;;
esac

print_info "$var_name=$var"
done
}

Expand All @@ -313,6 +383,7 @@ main() {
exec > >(tee -a "$log_file") 2>&1

process_environment
print_environment

if [[ "$SKIP_SETUP" -eq 0 ]]; then
setup_directory
Expand All @@ -327,6 +398,12 @@ main() {

update_configs
update_sources

declare -g -n a="$source_config"
declare -g -n b="$target_config"
a_ref="${a[ref]}"
b_ref="${b[ref]}"

calculate_differences

print_step "Cleaning up"
Expand Down
23 changes: 11 additions & 12 deletions bin/run_composable-kernels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,14 @@ elif [ "${ShouldUpdateCKRepo}" == 'yes' ]; then
popd
fi

if ! command -v ninja >/dev/null ; then
echo "Ninja not found, falling back to make"
CmakeGenerator="Unix Makefiles"
else
CmakeGenerator="Ninja"
CKBuildTool='make'
if command -v ninja >/dev/null ; then
CmakeGenerator="-GNinja"
CKBuildTool='ninja'
fi

# TODO Fix / Finalize the cmake command
CKCmakeCmd="cmake -G${CmakeGenerator} -B ${CK_BUILD} -S ${CK_REPO} -DCMAKE_PREFIX_PATH=${ROCM_PATH} -DCMAKE_INSTALL_PREFIX=${CK_INSTALL} "
CKCmakeCmd="cmake ${CmakeGenerator} -B ${CK_BUILD} -S ${CK_REPO} -DCMAKE_PREFIX_PATH=${ROCM_PATH} -DCMAKE_INSTALL_PREFIX=${CK_INSTALL} "
CKCmakeCmd+="-DCMAKE_CXX_COMPILER=${AOMP}/bin/clang++ -DCMAKE_HIP_COMPILER=${AOMP}/bin/clang++ "
CKCmakeCmd+="-DCMAKE_BUILD_TYPE=Release -DGPU_TARGETS=${CK_GPU_TARGETS} "
# For some reason, CK on gfx12 wants this set.
Expand Down Expand Up @@ -299,7 +298,7 @@ fi
if [ "${ShouldRebuildCK}" == 'yes' ] || [ "${ShouldInstallCK}" == 'yes' ]; then
pushd ${CK_BUILD} || exit 1

time ninja -j ${CKBuildParallelism}
time ${CKBuildTool} -j ${CKBuildParallelism}
if [ $? -ne 0 ]; then
exit 1
fi
Expand All @@ -312,7 +311,7 @@ if [ "${ShouldInstallCK}" == 'yes' ]; then
pushd ${CK_BUILD} || exit 1

# TODO: Check parallelism. This may use all available threads.
time ninja install
time ${CKBuildTool} install
if [ $? -ne 0 ]; then
exit 1
fi
Expand Down Expand Up @@ -340,7 +339,7 @@ if [ "${SelectedSuite}" == 'smoke' ]; then
mkdir -p "${CK_TESTS_LOG_LOCATION}" || exit 1
fi
pushd ${CK_BUILD} || exit 1
ninja -j 16 smoke 2>&1 | tee "${CK_TESTS_LOG_LOCATION}/smoke_tests.log"
${CKBuildTool} -j 16 smoke 2>&1 | tee "${CK_TESTS_LOG_LOCATION}/smoke_tests.log"
echo "Log at ${CK_TESTS_LOG_LOCATION}/smoke_tests.log"
popd
fi
Expand All @@ -351,7 +350,7 @@ if [ "${SelectedSuite}" == 'regression' ]; then
mkdir -p "${CK_TESTS_LOG_LOCATION}" || exit 1
fi
pushd ${CK_BUILD} || exit 1
ninja -j 16 regression 2>&1 | tee "${CK_TESTS_LOG_LOCATION}/regression_tests.log"
${CKBuildTool} -j 16 regression 2>&1 | tee "${CK_TESTS_LOG_LOCATION}/regression_tests.log"
echo "Log at ${CK_TESTS_LOG_LOCATION}/regression_tests.log"
popd
fi
Expand Down Expand Up @@ -415,7 +414,7 @@ fi
# Handle CK client examples
if [ "${SelectedSuite}" == 'client-examples' ]; then
# Configure and build the client examples
CKCmakeCmd="cmake -G ${CmakeGenerator} "
CKCmakeCmd="cmake ${CmakeGenerator} "
CKCmakeCmd+="-B ${CK_CLIENT_EXAMPLES_BUILD} -S ${CK_CLIENT_EXAMPLES_SOURCE} "
CKCmakeCmd+="-DCMAKE_CXX_COMPILER=${AOMP}/bin/clang++ "
CKCmakeCmd+="-DCMAKE_HIP_COMPILER=${AOMP}/bin/clang++ "
Expand Down Expand Up @@ -443,7 +442,7 @@ if [ "${SelectedSuite}" == 'client-examples' ]; then

pushd ${CK_CLIENT_EXAMPLES_BUILD} || exit 1

ninja
${CKBuildTool}
if [ $? -ne 0 ]; then
exit 1
fi
Expand Down