From ce3b372ad135bd6f1958e5ceec1aad1745d0843a Mon Sep 17 00:00:00 2001 From: Jan Patrick Lehr Date: Tue, 2 Dec 2025 09:03:31 +0100 Subject: [PATCH 1/5] [CK] Fix CMake generator string (#1732) In https://github.com/ROCm/aomp/pull/1727 I did not get the escaping of \" right. This PR will simply use CMake defaul (Unix Makefiles) when ninja is not present and explicitly specify ninja when it is available. --- bin/run_composable-kernels.sh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/bin/run_composable-kernels.sh b/bin/run_composable-kernels.sh index f5d3a6477..a6ac3f0d5 100755 --- a/bin/run_composable-kernels.sh +++ b/bin/run_composable-kernels.sh @@ -256,15 +256,12 @@ 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" +if command -v ninja >/dev/null ; then + CmakeGenerator="-GNinja" 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. @@ -410,7 +407,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++ " From 4c503f5aeae28aa06310cd20e05970000777f13f Mon Sep 17 00:00:00 2001 From: Nicole Aschenbrenner Date: Tue, 2 Dec 2025 02:49:49 -0600 Subject: [PATCH 2/5] [calculate_divergence.sh] removes default component "driver" Removes default component "driver" accidentally commited from testing. Allows the script to default run on entiry llvm-project directory. --- bin/calculate_divergence.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/calculate_divergence.sh b/bin/calculate_divergence.sh index a080ad624..4fb0c73d2 100755 --- a/bin/calculate_divergence.sh +++ b/bin/calculate_divergence.sh @@ -38,7 +38,7 @@ declare -A directories=( ) declare -A diff_args=( - [component]=${COMPONENT:="driver"} + [component]=${COMPONENT:=""} [options]="stat patch" ) From 564e56a211ca01c621797f8e8bbf6094d6753552 Mon Sep 17 00:00:00 2001 From: Jan Patrick Lehr Date: Tue, 2 Dec 2025 09:59:40 +0100 Subject: [PATCH 3/5] [CK] Replace hardcoded 'ninja' with $CKBuildTool (#1734) Another follow-up on https://github.com/ROCm/aomp/pull/1732 to not rely on the hardcoded 'ninja' invocation but adjust the tool that is used depending on whether ninja is available. --- bin/run_composable-kernels.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bin/run_composable-kernels.sh b/bin/run_composable-kernels.sh index a6ac3f0d5..4bf08de75 100755 --- a/bin/run_composable-kernels.sh +++ b/bin/run_composable-kernels.sh @@ -256,8 +256,10 @@ elif [ "${ShouldUpdateCKRepo}" == 'yes' ]; then popd fi +CKBuildTool='make' if command -v ninja >/dev/null ; then CmakeGenerator="-GNinja" + CKBuildTool='ninja' fi # TODO Fix / Finalize the cmake command @@ -291,7 +293,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 @@ -304,7 +306,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 @@ -332,7 +334,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 @@ -343,7 +345,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 @@ -435,7 +437,7 @@ if [ "${SelectedSuite}" == 'client-examples' ]; then pushd ${CK_CLIENT_EXAMPLES_BUILD} || exit 1 - ninja + ${CKBuildTool} if [ $? -ne 0 ]; then exit 1 fi From fc2b5a6a645d3b262514a92dae64b0edb940b786 Mon Sep 17 00:00:00 2001 From: Nicole Aschenbrenner Date: Tue, 2 Dec 2025 06:56:41 -0600 Subject: [PATCH 4/5] [calculate_divergence.sh] adds functionality to create file (group) based diffs Saves created diff files into timestamped subdirectory. --- bin/calculate_divergence.sh | 115 ++++++++++++++++++++++++++++++------ 1 file changed, 96 insertions(+), 19 deletions(-) diff --git a/bin/calculate_divergence.sh b/bin/calculate_divergence.sh index 4fb0c73d2..c569cbe67 100755 --- a/bin/calculate_divergence.sh +++ b/bin/calculate_divergence.sh @@ -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: /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")" @@ -34,7 +37,7 @@ 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=( @@ -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" @@ -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 } @@ -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) @@ -295,11 +367,9 @@ process_environment() { var=0 ;; *) - var=0 + var=- ;; esac - - print_info "$var_name=$var" done } @@ -313,6 +383,7 @@ main() { exec > >(tee -a "$log_file") 2>&1 process_environment + print_environment if [[ "$SKIP_SETUP" -eq 0 ]]; then setup_directory @@ -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" From 9179bf1f289b51580df96e6903b5518cefd13b73 Mon Sep 17 00:00:00 2001 From: dpalermo Date: Tue, 2 Dec 2025 14:17:03 -0600 Subject: [PATCH 5/5] [build_supp] Update to ninja 1.13.2 (#1740) Environment variable support: - NINJA_NPROCS - specify number of procs to use - NINJA_STATUS - show detailed build progress - NINJA_VERBOSE - show command lines while building --- bin/build_supp.sh | 2 +- bin/patches/ninja-nprocs-v1.13.0.patch | 72 ++++++++++++++++++++++ bin/patches/ninja-nprocs-v1.13.1.patch | 85 ++++++++++++++++++++++++++ bin/patches/ninja-nprocs-v1.13.2.patch | 85 ++++++++++++++++++++++++++ 4 files changed, 243 insertions(+), 1 deletion(-) create mode 100644 bin/patches/ninja-nprocs-v1.13.0.patch create mode 100644 bin/patches/ninja-nprocs-v1.13.1.patch create mode 100644 bin/patches/ninja-nprocs-v1.13.2.patch diff --git a/bin/build_supp.sh b/bin/build_supp.sh index 4389106de..da7714141 100755 --- a/bin/build_supp.sh +++ b/bin/build_supp.sh @@ -195,7 +195,7 @@ function buildopenmpi(){ function buildninja(){ _cname="ninja" - _version=1.11.1 + _version=1.13.2 _installdir=$AOMP_SUPP_INSTALL/$_cname-$_version _linkfrom=$AOMP_SUPP/$_cname _builddir=$AOMP_SUPP_BUILD/$_cname diff --git a/bin/patches/ninja-nprocs-v1.13.0.patch b/bin/patches/ninja-nprocs-v1.13.0.patch new file mode 100644 index 000000000..a0a32ac11 --- /dev/null +++ b/bin/patches/ninja-nprocs-v1.13.0.patch @@ -0,0 +1,72 @@ +diff --git a/src/ninja.cc b/src/ninja.cc +index 85ae6eb..6e07fe9 100644 +--- a/src/ninja.cc ++++ b/src/ninja.cc +@@ -252,15 +252,40 @@ void Usage(const BuildConfig& config) { + + /// Choose a default value for the -j (parallelism) flag. + int GuessParallelism() { +- switch (int processors = GetProcessorCount()) { ++ int nprocs = GetProcessorCount(); ++ switch (nprocs) { + case 0: + case 1: +- return 2; + case 2: +- return 3; ++ nprocs++; ++ break; + default: +- return processors + 2; ++ nprocs += 2; ++ break; + } ++ ++ const char * nprocs_str = getenv("NINJA_NPROCS"); ++ if (!nprocs_str) return nprocs; ++ ++ char * end; ++ auto nprocs_env = strtol(nprocs_str, &end, 10); ++ ++ if (*end != 0 || nprocs_env <= 0) return nprocs; ++ ++ return int(nprocs_env); ++} ++ ++/// Returns verbosity mode from the environment variable ++int HasVerbose() { ++ const char * verbose_str = getenv("NINJA_VERBOSE"); ++ if (!verbose_str) return 0; ++ ++ char * end; ++ auto verbose = strtol(verbose_str, &end, 10); ++ ++ if (*end != 0 || verbose <= 0) return 0; ++ ++ return verbose > 0; + } + + /// Rebuild the build manifest, if necessary. +@@ -1779,6 +1804,9 @@ int ReadFlags(int* argc, char*** argv, + *argv += optind; + *argc -= optind; + ++ if (HasVerbose()) ++ config->verbosity = BuildConfig::VERBOSE; ++ + return -1; + } + +diff --git a/src/version.cc b/src/version.cc +index 0ee3061..ae5701b 100644 +--- a/src/version.cc ++++ b/src/version.cc +@@ -20,7 +20,7 @@ + + using namespace std; + +-const char* kNinjaVersion = "1.13.0"; ++const char* kNinjaVersion = "1.13.0-mk"; + + void ParseVersion(const string& version, int* major, int* minor) { + size_t end = version.find('.'); diff --git a/bin/patches/ninja-nprocs-v1.13.1.patch b/bin/patches/ninja-nprocs-v1.13.1.patch new file mode 100644 index 000000000..129d1ede8 --- /dev/null +++ b/bin/patches/ninja-nprocs-v1.13.1.patch @@ -0,0 +1,85 @@ +diff --git a/src/ninja.cc b/src/ninja.cc +index 92d0761..8e3e1b8 100644 +--- a/src/ninja.cc ++++ b/src/ninja.cc +@@ -252,15 +252,40 @@ void Usage(const BuildConfig& config) { + + /// Choose a default value for the -j (parallelism) flag. + int GuessParallelism() { +- switch (int processors = GetProcessorCount()) { ++ int nprocs = GetProcessorCount(); ++ switch (nprocs) { + case 0: + case 1: +- return 2; + case 2: +- return 3; ++ nprocs++; ++ break; + default: +- return processors + 2; ++ nprocs += 2; ++ break; + } ++ ++ const char * nprocs_str = getenv("NINJA_NPROCS"); ++ if (!nprocs_str) return nprocs; ++ ++ char * end; ++ auto nprocs_env = strtol(nprocs_str, &end, 10); ++ ++ if (*end != 0 || nprocs_env <= 0) return nprocs; ++ ++ return int(nprocs_env); ++} ++ ++/// Returns verbosity mode from the environment variable ++int HasVerbose() { ++ const char * verbose_str = getenv("NINJA_VERBOSE"); ++ if (!verbose_str) return 0; ++ ++ char * end; ++ auto verbose = strtol(verbose_str, &end, 10); ++ ++ if (*end != 0 || verbose <= 0) return 0; ++ ++ return verbose > 0; + } + + /// Rebuild the build manifest, if necessary. +@@ -1781,6 +1806,9 @@ int ReadFlags(int* argc, char*** argv, + *argv += optind; + *argc -= optind; + ++ if (HasVerbose()) ++ config->verbosity = BuildConfig::VERBOSE; ++ + return -1; + } + +diff --git a/src/status_printer.cc b/src/status_printer.cc +index e69cd15..0b9d0f8 100644 +--- a/src/status_printer.cc ++++ b/src/status_printer.cc +@@ -51,7 +51,7 @@ StatusPrinter::StatusPrinter(const BuildConfig& config) + + progress_status_format_ = getenv("NINJA_STATUS"); + if (!progress_status_format_) +- progress_status_format_ = "[%f/%t] "; ++ progress_status_format_ = "[%es %p %rx %f/%t] "; + } + + void StatusPrinter::EdgeAddedToPlan(const Edge* edge) { +diff --git a/src/version.cc b/src/version.cc +index 17e59e6..7b8d94c 100644 +--- a/src/version.cc ++++ b/src/version.cc +@@ -20,7 +20,7 @@ + + using namespace std; + +-const char* kNinjaVersion = "1.14.0.git"; ++const char* kNinjaVersion = "1.13.1-mk"; + + void ParseVersion(const string& version, int* major, int* minor) { + size_t end = version.find('.'); diff --git a/bin/patches/ninja-nprocs-v1.13.2.patch b/bin/patches/ninja-nprocs-v1.13.2.patch new file mode 100644 index 000000000..342aaf57f --- /dev/null +++ b/bin/patches/ninja-nprocs-v1.13.2.patch @@ -0,0 +1,85 @@ +diff --git a/src/ninja.cc b/src/ninja.cc +index 92d0761..8e3e1b8 100644 +--- a/src/ninja.cc ++++ b/src/ninja.cc +@@ -252,15 +252,40 @@ void Usage(const BuildConfig& config) { + + /// Choose a default value for the -j (parallelism) flag. + int GuessParallelism() { +- switch (int processors = GetProcessorCount()) { ++ int nprocs = GetProcessorCount(); ++ switch (nprocs) { + case 0: + case 1: +- return 2; + case 2: +- return 3; ++ nprocs++; ++ break; + default: +- return processors + 2; ++ nprocs += 2; ++ break; + } ++ ++ const char * nprocs_str = getenv("NINJA_NPROCS"); ++ if (!nprocs_str) return nprocs; ++ ++ char * end; ++ auto nprocs_env = strtol(nprocs_str, &end, 10); ++ ++ if (*end != 0 || nprocs_env <= 0) return nprocs; ++ ++ return int(nprocs_env); ++} ++ ++/// Returns verbosity mode from the environment variable ++int HasVerbose() { ++ const char * verbose_str = getenv("NINJA_VERBOSE"); ++ if (!verbose_str) return 0; ++ ++ char * end; ++ auto verbose = strtol(verbose_str, &end, 10); ++ ++ if (*end != 0 || verbose <= 0) return 0; ++ ++ return verbose > 0; + } + + /// Rebuild the build manifest, if necessary. +@@ -1781,6 +1806,9 @@ int ReadFlags(int* argc, char*** argv, + *argv += optind; + *argc -= optind; + ++ if (HasVerbose()) ++ config->verbosity = BuildConfig::VERBOSE; ++ + return -1; + } + +diff --git a/src/status_printer.cc b/src/status_printer.cc +index e69cd15..0b9d0f8 100644 +--- a/src/status_printer.cc ++++ b/src/status_printer.cc +@@ -51,7 +51,7 @@ StatusPrinter::StatusPrinter(const BuildConfig& config) + + progress_status_format_ = getenv("NINJA_STATUS"); + if (!progress_status_format_) +- progress_status_format_ = "[%f/%t] "; ++ progress_status_format_ = "[%es %p %rx %f/%t] "; + } + + void StatusPrinter::EdgeAddedToPlan(const Edge* edge) { +diff --git a/src/version.cc b/src/version.cc +index b108660..8fbd82b 100644 +--- a/src/version.cc ++++ b/src/version.cc +@@ -20,7 +20,7 @@ + + using namespace std; + +-const char* kNinjaVersion = "1.13.2"; ++const char* kNinjaVersion = "1.13.2-mk"; + + void ParseVersion(const string& version, int* major, int* minor) { + size_t end = version.find('.');