From 04c41db0d327a80099efe3977f75ee504013ac5b Mon Sep 17 00:00:00 2001 From: Jan Patrick Lehr Date: Mon, 23 Feb 2026 15:58:30 +0100 Subject: [PATCH 01/10] [NFC] Fix shellcheck warnings for run_miniQMC (#1990) This fixes the shellcheck warnings in run script for miniQMC benchmark. --- bin/run_miniQMC.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/bin/run_miniQMC.sh b/bin/run_miniQMC.sh index fef7f6244e..64ddd31d09 100755 --- a/bin/run_miniQMC.sh +++ b/bin/run_miniQMC.sh @@ -9,11 +9,11 @@ # ROCM_INSTALL_PATH top-level ROCm install directory (default: /opt/rocm-5.3.0) # --- Start standard header to set AOMP environment variables ---- -realpath=`realpath $0` -thisdir=`dirname $realpath` +realpath=`realpath "$0"` +thisdir=`dirname "$realpath"` export AOMP_USE_CCACHE=0 -. $thisdir/aomp_common_vars +. "$thisdir"/aomp_common_vars # --- end standard header ---- # Default ROCm installation @@ -46,31 +46,31 @@ export rocsolver_DIR=${ROCM}/lib/cmake/rocsolver/ : ${MQMC_GIT_TAG:=9d9d7d3} -if [ ! -d $MQMC_SOURCE_DIR ]; then - git clone https://github.com/ye-luo/miniqmc $MQMC_SOURCE_DIR - git checkout ${MQMC_GIT_TAG} +if [ ! -d "$MQMC_SOURCE_DIR" ]; then + git clone https://github.com/ye-luo/miniqmc "$MQMC_SOURCE_DIR" + git checkout "${MQMC_GIT_TAG}" fi -rm -rf ${MQMC_BUILD_DIR} +rm -rf "${MQMC_BUILD_DIR}" # Note: We currently need the -fopenmp-assume-no-nested-parallelism to work around a call to malloc which probably should not be there. # In the case that we disable hostservices, the application crashes when trying to call malloc. -CMAKE_PREFIX_PATH=${ROCM}/lib/cmake/ cmake -B ${MQMC_BUILD_DIR} -S ${MQMC_SOURCE_DIR} -DCMAKE_CXX_COMPILER=clang++ -DENABLE_OFFLOAD=ON -DQMC_ENABLE_ROCM=ON -DCMAKE_CXX_FLAGS='-fopenmp-assume-no-nested-parallelism -DCUDART_VERSION=10000 -DcudaMemoryTypeManaged=hipMemoryTypeManaged ' -DAMDGPU_DISABLE_HOST_DEVMEM=ON -DCMAKE_VERBOSE_MAKEFILE=ON +CMAKE_PREFIX_PATH=${ROCM}/lib/cmake/ cmake -B "${MQMC_BUILD_DIR}" -S "${MQMC_SOURCE_DIR}" -DCMAKE_CXX_COMPILER=clang++ -DENABLE_OFFLOAD=ON -DQMC_ENABLE_ROCM=ON -DCMAKE_CXX_FLAGS='-fopenmp-assume-no-nested-parallelism -DCUDART_VERSION=10000 -DcudaMemoryTypeManaged=hipMemoryTypeManaged ' -DAMDGPU_DISABLE_HOST_DEVMEM=ON -DCMAKE_VERBOSE_MAKEFILE=ON # Build miniqmc binaries #cmake --build ${MQMC_BUILD_DIR} --clean-first -j ${MQMC_NUM_BUILD_PROCS} -pushd ${MQMC_BUILD_DIR} +pushd "${MQMC_BUILD_DIR}" || exit make clean -make --output-sync -j ${MQMC_NUM_BUILD_PROCS} -popd +make --output-sync -j "${MQMC_NUM_BUILD_PROCS}" +popd || exit echo "Running Tests" echo "OMP_NUM_THREADS=${MQMC_OMP_NUM_THREADS} ${MQMC_BUILD_DIR}/bin/check_spo_batched_reduction -n 10" -OMP_NUM_THREADS=${MQMC_OMP_NUM_THREADS} ${MQMC_BUILD_DIR}/bin/check_spo_batched_reduction -n 10 +OMP_NUM_THREADS=${MQMC_OMP_NUM_THREADS} "${MQMC_BUILD_DIR}"/bin/check_spo_batched_reduction -n 10 echo "" echo "OMP_NUM_THREADS=${MQMC_OMP_NUM_THREADS} ${MQMC_BUILD_DIR}/bin/miniqmc" -OMP_NUM_THREADS=${MQMC_OMP_NUM_THREADS} ${MQMC_BUILD_DIR}/bin/miniqmc -v +OMP_NUM_THREADS=${MQMC_OMP_NUM_THREADS} "${MQMC_BUILD_DIR}"/bin/miniqmc -v echo "" echo "OMP_NUM_THREADS=${MQMC_OMP_NUM_THREADS} ${MQMC_BUILD_DIR}/bin/check_spo -n 10" -OMP_NUM_THREADS=${MQMC_OMP_NUM_THREADS} ${MQMC_BUILD_DIR}/bin/check_spo -n 10 -v +OMP_NUM_THREADS=${MQMC_OMP_NUM_THREADS} "${MQMC_BUILD_DIR}"/bin/check_spo -n 10 -v From b29f732a7da2a9f026bb62ca93c86613bf195c63 Mon Sep 17 00:00:00 2001 From: Jan Patrick Lehr Date: Tue, 24 Feb 2026 10:25:19 +0100 Subject: [PATCH 02/10] [LLVM Test Suite] Adds run script for simple HIP tests (#1973) This enables to clone, update, configure, run the simple HIP tests from the LLVM test suite. --- bin/run_llvm-test-suite.sh | 228 +++++++++++++++++++++++++++++++++++++ 1 file changed, 228 insertions(+) create mode 100755 bin/run_llvm-test-suite.sh diff --git a/bin/run_llvm-test-suite.sh b/bin/run_llvm-test-suite.sh new file mode 100755 index 0000000000..504cb39345 --- /dev/null +++ b/bin/run_llvm-test-suite.sh @@ -0,0 +1,228 @@ +#!/usr/bin/env bash + +# +#Copyright © Advanced Micro Devices, Inc., or its affiliates. +# +#SPDX-License-Identifier: MIT +# + +# Build script for llvm-test-suite with HIP support using AOMP compiler + +# --- Start standard header to set AOMP environment variables ---- +realpath=$(realpath "$0") +thisdir=$(dirname "$realpath") +export AOMP_USE_CCACHE=0 + +# shellcheck source=aomp_common_vars +. "$thisdir/aomp_common_vars" +# --- end standard header ---- + +# Environment variable defaults +: "${LLVMTS_TLDIR:=$AOMP_REPOS_TEST/llvm-test-suite}" +: "${LLVMTS_SRC_DIR:=$LLVMTS_TLDIR/src}" +: "${LLVMTS_BUILD_DIR:=$LLVMTS_TLDIR/build}" +: "${LLVMTS_EXTERNAL_DIR:=$LLVMTS_TLDIR/External}" +: "${LLVMTS_LOGS_DIR:=$LLVMTS_TLDIR/logs}" +: "${LLVMTS_GPU:=$AOMP_GPU}" +: "${LLVMTS_BUILD_TYPE:=Release}" +: "${LLVMTS_TEST_TIMEOUT:=840}" +# Fallback to system ROCm if AOMP doesn't have HIP libraries +: "${ROCM:=/opt/rocm}" + +# Determine clang major version for device libs path +CLANG_VERSION=$("${AOMP}/bin/clang" --version | head -1 | grep -o 'version [0-9]*' | awk '{print $2}') +if [ -z "${CLANG_VERSION}" ]; then + echo "WARNING: Could not determine clang version, defaulting to 23" + CLANG_VERSION=23 +fi + +# Set AMD device libs path for HIP compilation +# HIP tests need to find device bitcode libraries +HIP_DEVICE_LIB_PATH="${AOMP}/lib/clang/${CLANG_VERSION}/lib/amdgcn/bitcode" +export HIP_DEVICE_LIB_PATH + +pushd "${AOMP_REPOS_TEST}" || exit +mkdir -p "${LLVMTS_TLDIR}" && cd "${LLVMTS_TLDIR}" || exit + +# Control variables +DoConfigure='no' +DoCompile='no' +DoTest='no' +DoUpdate='no' +IsVerbose='no' + +while getopts "j:cbtvhu" opt; do + case ${opt} in + j) AOMP_BUILD_JOBS=${OPTARG} ;; + c) DoConfigure='yes' ;; + b) DoCompile='yes' ;; + t) DoTest='yes' ;; + v) IsVerbose='yes' ;; + u) DoUpdate='yes' ;; + h) + echo "Usage: $(basename "$0") [-j build_jobs] [-c configure] [-b build] [-t test] [-v verbose] [-u update_sources]" + echo "" + echo "Options:" + echo " -c Run CMake configuration" + echo " -b Build the test suite" + echo " -t Run tests" + echo " -u Update sources (git pull)" + echo " -j Number of parallel build jobs (default: $AOMP_BUILD_JOBS)" + echo " -v Verbose mode (set -x)" + echo " -h Show this help message" + echo "" + echo "Environment Variables:" + echo " LLVMTS_TLDIR - Top-level directory (default: \$AOMP_REPOS_TEST/llvm-test-suite)" + echo " LLVMTS_GPU - Target GPU(s) (default: \$AOMP_GPU)" + echo " LLVMTS_BUILD_TYPE - CMake build type (default: Release)" + echo " LLVMTS_TEST_TIMEOUT - Test timeout in seconds (default: 800)" + echo " AOMP - AOMP compiler location (default: \$HOME/rocm/aomp)" + echo " ROCM - ROCm installation path (fallback, default: /opt/rocm)" + echo " Only needed if AOMP doesn't contain HIP libraries" + exit 0 + ;; + \?) + echo "Usage: $(basename "$0") [-j build_jobs] [-c configure] [-b build] [-t test] [-v verbose] [-u update_sources] [-h help]" + exit 1 + ;; + esac +done + +if [ "${IsVerbose}" == "yes" ]; then + set -x +fi + +# Detect ninja vs make +TestBuildTool='make' +CmakeGenerator="" +if command -v ninja >/dev/null; then + CmakeGenerator="-GNinja" + TestBuildTool='ninja' +fi + +# Create log directory +if [ ! -d "${LLVMTS_LOGS_DIR}" ]; then + mkdir -p "${LLVMTS_LOGS_DIR}" +fi + +# Clone or update repository +if [ ! -d "${LLVMTS_SRC_DIR}" ]; then + echo "Cloning llvm-test-suite repository..." + git clone https://github.com/llvm/llvm-test-suite.git "${LLVMTS_SRC_DIR}" +elif [ "${DoUpdate}" == "yes" ]; then + echo "Updating llvm-test-suite repository..." + cd "${LLVMTS_SRC_DIR}" || exit + git pull + cd "${LLVMTS_TLDIR}" || exit +fi + +# Check for HIP tests in the cloned suite +if [ -d "${LLVMTS_SRC_DIR}" ] && [ ! -d "${LLVMTS_SRC_DIR}/External/HIP" ]; then + echo "WARNING: External/HIP tests not found in llvm-test-suite" + echo " The test suite may not have HIP tests available" +fi + +# Determine ROCm path for HIP tests +# Prefer using AOMP's root directory (which contains HIP runtime and libraries) +# over system ROCm installation. AOMP root is typically $AOMP/../.. when AOMP points +# to lib/llvm subdirectory +AOMP_ROOT_DIR=$(cd "${AOMP}/../.." && pwd) +if [ -f "${AOMP_ROOT_DIR}/lib/libamdhip64.so" ]; then + ROCM_FOR_TESTS="${AOMP_ROOT_DIR}" + echo "Using AOMP installation for HIP tests: ${ROCM_FOR_TESTS}" +elif [ -f "${AOMP}/../lib/libamdhip64.so" ]; then + # Handle case where AOMP points directly to root (e.g., /opt/rocm/llvm) + AOMP_ROOT_DIR=$(cd "${AOMP}/.." && pwd) + ROCM_FOR_TESTS="${AOMP_ROOT_DIR}" + echo "Using AOMP installation for HIP tests: ${ROCM_FOR_TESTS}" +else + if [ ! -d "${ROCM}" ]; then + echo "ERROR: AOMP installation does not contain HIP libraries and system ROCm not found at ${ROCM}" + echo " Please set ROCM environment variable to a valid ROCm installation" + exit 1 + fi + ROCM_FOR_TESTS="${ROCM}" + echo "Using system ROCm for HIP tests: ${ROCM_FOR_TESTS}" +fi + +# Export ROCm CMake directories based on selected ROCm path +export hsaruntime64_DIR=${ROCM_FOR_TESTS}/lib/cmake/hsa-runtime64/ +export hipblas_DIR=${ROCM_FOR_TESTS}/lib/cmake/hipblas/ +export hip_DIR=${ROCM_FOR_TESTS}/lib/cmake/hip +export AMDDeviceLibs_DIR=${ROCM_FOR_TESTS}/lib/cmake/AMDDeviceLibs/ +export amd_comgr_DIR=${ROCM_FOR_TESTS}/lib/cmake/amd_comgr/ + +# Get ROCm version and create symlink +if [ -f "${ROCM_FOR_TESTS}/.info/version" ]; then + ROCM_VERSION_FILE=$(cat "${ROCM_FOR_TESTS}/.info/version") +elif command -v dpkg >/dev/null && dpkg -l rocm-core >/dev/null 2>&1; then + ROCM_VERSION_FILE=$(dpkg -l rocm-core | grep rocm-core | awk '{print $3}' | cut -d- -f1) +else + # Default fallback version + ROCM_VERSION_FILE="6.0.0" +fi + +# Create hip subdirectory and symlink to ROCm installation +# This is a prerequisite / assumption that the LLVM test suite makes +if [ ! -d "${LLVMTS_EXTERNAL_DIR}/hip" ]; then + mkdir -p "${LLVMTS_EXTERNAL_DIR}/hip" +fi + +ROCM_LINK="${LLVMTS_EXTERNAL_DIR}/hip/rocm-${ROCM_VERSION_FILE}" +if [ ! -L "${ROCM_LINK}" ] && [ ! -d "${ROCM_LINK}" ]; then + echo "Creating symlink: ${ROCM_LINK} -> ${ROCM_FOR_TESTS}" + ln -sf "${ROCM_FOR_TESTS}" "${ROCM_LINK}" +fi + +# Configure with CMake +if [ "${DoConfigure}" == "yes" ]; then + echo "Configuring build with CMake..." + rm -rf "${LLVMTS_BUILD_DIR}" + cmake ${CmakeGenerator} \ + -B "${LLVMTS_BUILD_DIR}" \ + -S "${LLVMTS_SRC_DIR}" \ + -DTEST_SUITE_SUBDIRS=External \ + -DTEST_SUITE_EXTERNALS_DIR="${LLVMTS_EXTERNAL_DIR}" \ + -DTEST_SUITE_COLLECT_CODE_SIZE=OFF \ + -DTEST_SUITE_COLLECT_COMPILE_TIME=OFF \ + -DTEST_SUITE_LIT="${AOMP}/bin/llvm-lit" \ + -DCMAKE_STRIP="" \ + -DAMDGPU_ARCHS="${LLVMTS_GPU}" \ + -DCMAKE_BUILD_TYPE="${LLVMTS_BUILD_TYPE}" \ + -DCMAKE_C_COMPILER="${AOMP}/bin/clang" \ + -DCMAKE_CXX_COMPILER="${AOMP}/bin/clang++" \ + -DCMAKE_BUILD_TYPE="Release" +fi + +# Build +if [ "${DoCompile}" == "yes" ]; then + echo "Building llvm-test-suite..." + cmake --build "${LLVMTS_BUILD_DIR}" --parallel -j "${AOMP_BUILD_JOBS}" +fi + +# Run tests +if [ "${DoTest}" == "yes" ]; then + echo "Running HIP tests (timeout: ${LLVMTS_TEST_TIMEOUT}s)..." + cd "${LLVMTS_BUILD_DIR}" || exit + + echo "Log in ${LLVMTS_LOGS_DIR}/test-output.log" + + # Use timeout to prevent tests from hanging + # -k 30: Send SIGKILL after 30 seconds if SIGTERM doesn't terminate the process + # This ensures even completely hung processes are killed + if command -v timeout >/dev/null; then + timeout -k 30 "${LLVMTS_TEST_TIMEOUT}" "${TestBuildTool}" check-hip-simple 2>&1 | tee "${LLVMTS_LOGS_DIR}/test-output.log" + test_exit_code="${PIPESTATUS[0]}" + if [ "${test_exit_code}" -eq 124 ]; then + echo "WARNING: Tests timed out after ${LLVMTS_TEST_TIMEOUT} seconds" + elif [ "${test_exit_code}" -eq 137 ]; then + echo "WARNING: Tests were forcefully killed (SIGKILL) after timeout grace period" + fi + else + echo "WARNING: timeout command not found. Not running tests" + popd + exit 1 + fi +fi + +popd || exit From 44235fcca97c8e630be80300602ae30d3c67b9e2 Mon Sep 17 00:00:00 2001 From: Jan Patrick Lehr Date: Tue, 24 Feb 2026 11:31:21 +0100 Subject: [PATCH 03/10] [NFC][LLaMA] Initial shellcheck fixes (#1994) This applies an initial set of automated shellcheck fixes. --- bin/run_llama.sh | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/bin/run_llama.sh b/bin/run_llama.sh index 2772764577..24cbc44757 100755 --- a/bin/run_llama.sh +++ b/bin/run_llama.sh @@ -23,8 +23,8 @@ : ${LLAMA_BENCH_HF_ID:="ggml-org/gemma-3-1b-it-GGUF"} : ${LLAMA_CACHE:="$HOME/.cache/llama.cpp"} -pushd ${AOMP_REPOS_TEST} -mkdir -p ${LLAMA_TLDIR} && cd ${LLAMA_TLDIR} +pushd "${AOMP_REPOS_TEST}" || exit +mkdir -p "${LLAMA_TLDIR}" && cd "${LLAMA_TLDIR}" || exit # Run CMake configuration DoConfigure='no' @@ -63,22 +63,20 @@ if [ "${IsVerbose}" == "yes" ]; then set -x fi -TestBuildTool='make' if command -v ninja >/dev/null; then CmakeGenerator="-GNinja" - TestBuildTool='ninja' fi -if [ ! -d ${LLAMA_TESTS_LOG_LOCATION} ]; then - mkdir -p ${LLAMA_TESTS_LOG_LOCATION} +if [ ! -d "${LLAMA_TESTS_LOG_LOCATION}" ]; then + mkdir -p "${LLAMA_TESTS_LOG_LOCATION}" fi -if [ ! -d ${LLAMA_SRC_DIR} ]; then +if [ ! -d "${LLAMA_SRC_DIR}" ]; then echo "Cloning llama.cpp repository..." git clone https://github.com/ggml-org/llama.cpp.git src elif [ "${DoUpdate}" == "yes" ]; then echo "Updating llama.cpp repository..." - cd ${LLAMA_SRC_DIR} + cd "${LLAMA_SRC_DIR}" || exit git pull cd .. fi @@ -87,7 +85,7 @@ if ! command -v git-lfs >/dev/null; then echo "WARNING: git-lfs is not installed. Expect some tests to fail." else # Ensure git-lfs is initialized and pulls any large files - cd ${LLAMA_SRC_DIR} + cd "${LLAMA_SRC_DIR}" || exit git lfs install git lfs pull cd .. @@ -95,27 +93,27 @@ fi echo "Configuring build with CMake..." if [ "${DoConfigure}" == "yes" ]; then - rm -rf ${LLAMA_BUILD_DIR} + rm -rf "${LLAMA_BUILD_DIR}" cmake -B build \ -S src \ - -DCMAKE_PREFIX_PATH=${AOMP}/lib/cmake \ + -DCMAKE_PREFIX_PATH="${AOMP}"/lib/cmake \ -DGGML_HIP=On \ -DCMAKE_BUILD_TYPE=${LLAMA_BUILD_MODE} \ -DGPU_TARGETS=${LLAMA_GPU} \ ${CmakeGenerator} \ - -DCMAKE_C_COMPILER=${AOMP}/bin/clang \ - -DCMAKE_CXX_COMPILER=${AOMP}/bin/clang++ \ - -DCMAKE_HIP_COMPILER=${AOMP}/bin/clang++ + -DCMAKE_C_COMPILER="${AOMP}"/bin/clang \ + -DCMAKE_CXX_COMPILER="${AOMP}"/bin/clang++ \ + -DCMAKE_HIP_COMPILER="${AOMP}"/bin/clang++ fi if [ "${DoCompile}" == "yes" ]; then echo "Building LLaMA..." - cmake --build ${LLAMA_BUILD_DIR} --parallel -j ${AOMP_BUILD_JOBS} + cmake --build "${LLAMA_BUILD_DIR}" --parallel -j "${AOMP_BUILD_JOBS}" fi if [ "${DoCTest}" == "yes" ]; then echo "Running tests..." - cd ${LLAMA_BUILD_DIR} + cd "${LLAMA_BUILD_DIR}" || exit echo "Log in ${LLAMA_TESTS_LOG_LOCATION}/ctest.log" # Some model files are git-lfs and come from huggingface. They will auto-download during test @@ -124,7 +122,7 @@ fi if [ "${DoBenchmark}" == "yes" ]; then echo "Running benchmark..." - cd ${LLAMA_BUILD_DIR} + cd "${LLAMA_BUILD_DIR}" || exit # Download model from HF (this will make it avail in local cache); bench call requires local model file # llama-cli will turn on interactive mode, so echo /exit to it immediately echo "/exit" | ./bin/llama-cli -hf ${LLAMA_BENCH_HF_ID} @@ -140,4 +138,4 @@ if [ "${DoBenchmark}" == "yes" ]; then ./bin/llama-bench -ngl 999 -fa 1 -ub 2048 -m "$LlamaModelPath" 2>&1 | tee -a "${LLAMA_TESTS_LOG_LOCATION}/llama-bench.log" fi -popd +popd || exit From 6747071d4989af9902fc486894501298fc4f4443 Mon Sep 17 00:00:00 2001 From: gregrodgers Date: Thu, 22 May 2025 10:03:08 -0500 Subject: [PATCH 04/10] [AOMP] aomp-shellcheck, initial version This patch adds a helper script to wrap the 'shellcheck' utility, aiming to split checks into (a) those that should be fixed by hand, (b) those which can be fixed automatically with reasonable precision, and (c) those which should always be ignored. --- bin/aomp-shellcheck | 90 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100755 bin/aomp-shellcheck diff --git a/bin/aomp-shellcheck b/bin/aomp-shellcheck new file mode 100755 index 0000000000..446ee8feb5 --- /dev/null +++ b/bin/aomp-shellcheck @@ -0,0 +1,90 @@ +#!/bin/bash +# +# aomp-shell-format: Run shellcheck and shfmt to cleanup aomp shell script. +# +# Process: +# 1. RUn shellcheck --include $_fixByHand, fail if any found +# 2. Run shellcheck --include $_patchable to generate patch +# 3 Apply patch +# 4. Run shellcheck --exclude $_alwaysExclude +# if any fails then +# return 1 +# proceed to update this aomp-shell-format utility by adding +# falled codes to either _fixByHand, _patchable, or _alwaysExclude +# else +# return 0 +# + +_fixByHand="SC2050" +_fixByHand="${_fixByHand},SC2046" +_fixByHand="${_fixByHand},SC2291" +_fixByHand="${_fixByHand},SC2181" +_fixByHand="${_fixByHand},SC2236" +_fixByHandOpts="--shell=bash --include=${_fixByHand}" +# +_patchable="SC2086" +_patchable="${_patchable},SC2164" +_patchable="${_patchable},SC2006" +_patchableOpts="--shell=bash -f diff --include=${_patchable}" + +_alwaysExclude="SC2034" # ignore unused vars +_alwaysExclude="${_alwaysExclude},SC2016" # use double quote instead of single +_alwaysExclude="${_alwaysExclude},SC1083" # TODO: consider this for fixByHand +_alwaysExcludeOpts="--shell=bash --exclude=${_alwaysExclude}" + +_shellfile=$1 +if [ -z $_shellfile ] || [ ! -f $_shellfile ] ; then + echo "ERROR: please specify an existing input file as 1st argument" + exit 1 +fi + +_shellcheck_bin=$(which shellcheck) +if [ "$_shellcheck_bin" == "" ] ; then + echo "ERROR: please install shellcheck" + exit 1 +fi + +_patchfile=/tmp/patchfile$$ +touch $_patchfile +if [ $? != 0 ] ; then + echo "ERROR: Could not create or update $_patchfile" + exit 1 +fi +echo +echo "---- STEP 1 ---- Check for fixByHand fails -----" +echo "$_shellcheck_bin $_fixByHandOpts $_shellfile" +$_shellcheck_bin $_fixByHandOpts $_shellfile +_rc=$? +if [ $_rc != 0 ] ; then + echo + echo "ERROR: shellcheck found erros that must be fixed by hand. rc=$-rc" + exit 1 +fi +echo +echo "---- STEP 2 ---- Check and repair patchable fails -----" +echo "$_shellcheck_bin $_patchableOpts $_shellfile \>$_patchfile" +$_shellcheck_bin $_patchableOpts $_shellfile >$_patchfile +patch -p1 --dry-run <$_patchfile +_rc=$? +if [ $_rc != 0 ] ; then + echo "ERROR: Could not dryrun patch in $_patchfile to file $_shellfile" + exit 1 +fi +echo +echo "---- STEP 3 ---- Applying patch $_patchfile to $_shellfile" +patch -p1 <$_patchfile +echo rm $_patchfile +rm $_patchfile # patch should work because of dryrun test above +echo +echo "---- STEP 4 ---- Test for codes not handled in $0" +echo "$_shellcheck_bin $_alwaysExcludeOpts $_shellfile" +$_shellcheck_bin $_alwaysExcludeOpts $_shellfile +_rc=$? +if [ $_rc != 0 ] ; then + echo + echo "ERROR: shellcheck found codes not yet handled, must fix $0" + exit $_rc +fi +echo +echo "DONE: script $_shellfile is clean" +exit 0 From 6a40b2191d81d0caad55d3418a665163ba5bda82 Mon Sep 17 00:00:00 2001 From: Julian Brown Date: Thu, 22 May 2025 10:04:35 -0500 Subject: [PATCH 05/10] [AOMP] Move some shellcheck options to fixByHand This patch moves some potentially semantics-altering automatic fixes to the fixByHand list. --- bin/aomp-shellcheck | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/aomp-shellcheck b/bin/aomp-shellcheck index 446ee8feb5..8c7a11f537 100755 --- a/bin/aomp-shellcheck +++ b/bin/aomp-shellcheck @@ -20,15 +20,15 @@ _fixByHand="${_fixByHand},SC2046" _fixByHand="${_fixByHand},SC2291" _fixByHand="${_fixByHand},SC2181" _fixByHand="${_fixByHand},SC2236" +_fixByHand="${_fixByHand},SC2086" +_fixByHand="${_fixByHand},SC2034" # ignore unused vars _fixByHandOpts="--shell=bash --include=${_fixByHand}" # -_patchable="SC2086" -_patchable="${_patchable},SC2164" +_patchable="SC2164" _patchable="${_patchable},SC2006" _patchableOpts="--shell=bash -f diff --include=${_patchable}" -_alwaysExclude="SC2034" # ignore unused vars -_alwaysExclude="${_alwaysExclude},SC2016" # use double quote instead of single +_alwaysExclude="SC2016" # use double quote instead of single _alwaysExclude="${_alwaysExclude},SC1083" # TODO: consider this for fixByHand _alwaysExcludeOpts="--shell=bash --exclude=${_alwaysExclude}" From bfa02b84dd5d77844c8c9035d05b61d2acb5ca83 Mon Sep 17 00:00:00 2001 From: Julian Brown Date: Thu, 22 May 2025 11:26:57 -0500 Subject: [PATCH 06/10] [AOMP] shellcheck fixes for aomp-shellcheck This patch allows multiple scripts to listed for aomp-shellcheck, and contains some cleanups based on running shellcheck on that script itself. --- bin/aomp-shellcheck | 98 ++++++++++++++++++++++++++++----------------- 1 file changed, 62 insertions(+), 36 deletions(-) diff --git a/bin/aomp-shellcheck b/bin/aomp-shellcheck index 8c7a11f537..a41256a54c 100755 --- a/bin/aomp-shellcheck +++ b/bin/aomp-shellcheck @@ -15,25 +15,47 @@ # return 0 # -_fixByHand="SC2050" -_fixByHand="${_fixByHand},SC2046" -_fixByHand="${_fixByHand},SC2291" -_fixByHand="${_fixByHand},SC2181" -_fixByHand="${_fixByHand},SC2236" -_fixByHand="${_fixByHand},SC2086" -_fixByHand="${_fixByHand},SC2034" # ignore unused vars -_fixByHandOpts="--shell=bash --include=${_fixByHand}" -# -_patchable="SC2164" -_patchable="${_patchable},SC2006" -_patchableOpts="--shell=bash -f diff --include=${_patchable}" +# Join list of arguments using separator passed as first argument. +# join ',' a b c +# -> a,b,c +join() { + local IFS=$1 + shift + printf "%s" "$*" +} + +_fixByHand=(SC2050 # Forgotten $ on variable + SC2046 # Quote to prevent word splitting + SC2291 # Quote repeated spaces + SC2181 # Check exit code directly not with $? + SC2236 # Use -n instead of ! -z + SC2086 # Double quote to prevent globbing and word splitting + SC2034 # Ignore unused vars + SC1083 # Accidentally literal braces + SC2076 # Regex syntax check + SC2038 # find -print0 + SC2068) # Avoid re-splitting array expansion +_fixByHandOpts=(--shell=bash --include="$(join ',' "${_fixByHand[@]}")") + +_patchable=(SC2164 # Use cd ... || exit + SC2006) # Use $(...) instead of legacy backticks +_patchableOpts=(--shell=bash -f diff --include="$(join ',' "${_patchable[@]}")") -_alwaysExclude="SC2016" # use double quote instead of single -_alwaysExclude="${_alwaysExclude},SC1083" # TODO: consider this for fixByHand -_alwaysExcludeOpts="--shell=bash --exclude=${_alwaysExclude}" +_alwaysExclude=(SC2016 # Use double quote instead of single + SC2002 # Useless cat + SC2004) # '$' on arithmetic vars +_alwaysExcludeOpts=(--shell=bash --exclude="$(join ',' "${_alwaysExclude[@]}")") -_shellfile=$1 -if [ -z $_shellfile ] || [ ! -f $_shellfile ] ; then +declare -a _shellfiles=( "$@" ) +_missing=0 +for _shellfile in "${_shellfiles[@]}"; do + if [ ! -f "$_shellfile" ]; then + (( _missing++ )) + fi +done +unset _shellfile + +if [ "${#_shellfiles[@]}" -eq 0 ] || [ "$_missing" -gt 0 ] ; then echo "ERROR: please specify an existing input file as 1st argument" exit 1 fi @@ -45,40 +67,40 @@ if [ "$_shellcheck_bin" == "" ] ; then fi _patchfile=/tmp/patchfile$$ -touch $_patchfile -if [ $? != 0 ] ; then + +if ! touch "$_patchfile"; then echo "ERROR: Could not create or update $_patchfile" exit 1 fi echo echo "---- STEP 1 ---- Check for fixByHand fails -----" -echo "$_shellcheck_bin $_fixByHandOpts $_shellfile" -$_shellcheck_bin $_fixByHandOpts $_shellfile +echo "$_shellcheck_bin -x ${_fixByHandOpts[*]} ${_shellfiles[*]}" + +$_shellcheck_bin -x "${_fixByHandOpts[@]}" "${_shellfiles[@]}" _rc=$? -if [ $_rc != 0 ] ; then +if [[ $_rc != 0 ]]; then echo - echo "ERROR: shellcheck found erros that must be fixed by hand. rc=$-rc" + echo "ERROR: shellcheck found errors that must be fixed by hand. rc=$_rc" exit 1 fi echo echo "---- STEP 2 ---- Check and repair patchable fails -----" -echo "$_shellcheck_bin $_patchableOpts $_shellfile \>$_patchfile" -$_shellcheck_bin $_patchableOpts $_shellfile >$_patchfile -patch -p1 --dry-run <$_patchfile -_rc=$? -if [ $_rc != 0 ] ; then - echo "ERROR: Could not dryrun patch in $_patchfile to file $_shellfile" +echo "$_shellcheck_bin -x ${_patchableOpts[*]} ${_shellfiles[*]} \>$_patchfile" +$_shellcheck_bin -x "${_patchableOpts[@]}" "${_shellfiles[@]}" >$_patchfile + +if ! patch -p1 --dry-run <"$_patchfile"; then + echo "ERROR: Could not dryrun patch in $_patchfile to file ${_shellfiles[*]}" exit 1 fi echo -echo "---- STEP 3 ---- Applying patch $_patchfile to $_shellfile" -patch -p1 <$_patchfile -echo rm $_patchfile -rm $_patchfile # patch should work because of dryrun test above +echo "---- STEP 3 ---- Applying patch $_patchfile to ${_shellfiles[*]}" +patch -p1 <"$_patchfile" +echo "rm $_patchfile" +rm "$_patchfile" # patch should work because of dryrun test above echo echo "---- STEP 4 ---- Test for codes not handled in $0" -echo "$_shellcheck_bin $_alwaysExcludeOpts $_shellfile" -$_shellcheck_bin $_alwaysExcludeOpts $_shellfile +echo "$_shellcheck_bin -x ${_alwaysExcludeOpts[*]} ${_shellfiles[*]}" +$_shellcheck_bin -x "${_alwaysExcludeOpts[@]}" "${_shellfiles[@]}" _rc=$? if [ $_rc != 0 ] ; then echo @@ -86,5 +108,9 @@ if [ $_rc != 0 ] ; then exit $_rc fi echo -echo "DONE: script $_shellfile is clean" +if [ "${#_shellfiles[@]}" -eq 1 ]; then + echo "DONE: script ${_shellfiles[*]} is clean" +else + echo "DONE: scripts $(join ',' ${_shellfiles[@]}) are clean" +fi exit 0 From aca9c400b2cfd393a34430c0f1457a2203eb5369 Mon Sep 17 00:00:00 2001 From: Julian Brown Date: Wed, 4 Jun 2025 06:07:28 -0500 Subject: [PATCH 07/10] [AOMP] Add --check-only option to aomp-shellcheck This patch adds a --check-only option to aomp-shellcheck to avoid automatically altering files, e.g. when called via an automation system. --- bin/aomp-shellcheck | 74 +++++++++++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 22 deletions(-) diff --git a/bin/aomp-shellcheck b/bin/aomp-shellcheck index a41256a54c..d96582d49b 100755 --- a/bin/aomp-shellcheck +++ b/bin/aomp-shellcheck @@ -39,13 +39,20 @@ _fixByHandOpts=(--shell=bash --include="$(join ',' "${_fixByHand[@]}")") _patchable=(SC2164 # Use cd ... || exit SC2006) # Use $(...) instead of legacy backticks -_patchableOpts=(--shell=bash -f diff --include="$(join ',' "${_patchable[@]}")") +_patchableOpts=(--shell=bash --include="$(join ',' "${_patchable[@]}")") _alwaysExclude=(SC2016 # Use double quote instead of single SC2002 # Useless cat SC2004) # '$' on arithmetic vars _alwaysExcludeOpts=(--shell=bash --exclude="$(join ',' "${_alwaysExclude[@]}")") +_check_only=false + +if [ $1 == "--check-only" ]; then + _check_only=true + shift +fi + declare -a _shellfiles=( "$@" ) _missing=0 for _shellfile in "${_shellfiles[@]}"; do @@ -66,12 +73,6 @@ if [ "$_shellcheck_bin" == "" ] ; then exit 1 fi -_patchfile=/tmp/patchfile$$ - -if ! touch "$_patchfile"; then - echo "ERROR: Could not create or update $_patchfile" - exit 1 -fi echo echo "---- STEP 1 ---- Check for fixByHand fails -----" echo "$_shellcheck_bin -x ${_fixByHandOpts[*]} ${_shellfiles[*]}" @@ -83,25 +84,54 @@ if [[ $_rc != 0 ]]; then echo "ERROR: shellcheck found errors that must be fixed by hand. rc=$_rc" exit 1 fi -echo -echo "---- STEP 2 ---- Check and repair patchable fails -----" -echo "$_shellcheck_bin -x ${_patchableOpts[*]} ${_shellfiles[*]} \>$_patchfile" -$_shellcheck_bin -x "${_patchableOpts[@]}" "${_shellfiles[@]}" >$_patchfile -if ! patch -p1 --dry-run <"$_patchfile"; then - echo "ERROR: Could not dryrun patch in $_patchfile to file ${_shellfiles[*]}" - exit 1 +if $_check_only; then + echo + echo "---- STEP 2 ---- Check patchable fails -----" + echo "$_shellcheck_bin -x ${_patchableOpts[@]} ${_shellfiles[@]}" + $_shellcheck_bin -x "${_patchableOpts[@]}" "${_shellfiles[@]}" + + echo + echo "---- STEP 3 ---- (Skipping for --check-only)" +else + echo + echo "---- STEP 2 ---- Check and repair patchable fails -----" + + _patchfile=/tmp/patchfile$$ + + if ! touch "$_patchfile"; then + echo "ERROR: Could not create or update $_patchfile" + exit 1 + fi + + echo "$_shellcheck_bin -x ${_patchableOpts[*]} -f diff ${_shellfiles[*]} \>$_patchfile" + $_shellcheck_bin -x "${_patchableOpts[@]}" -f diff "${_shellfiles[@]}" >$_patchfile + + if ! patch -p1 --dry-run <"$_patchfile"; then + echo "ERROR: Could not dryrun patch in $_patchfile to file ${_shellfiles[*]}" + exit 1 + fi + echo + echo "---- STEP 3 ---- Applying patch $_patchfile to ${_shellfiles[*]}" + patch -p1 <"$_patchfile" + echo "rm $_patchfile" + rm "$_patchfile" # patch should work because of dryrun test above fi -echo -echo "---- STEP 3 ---- Applying patch $_patchfile to ${_shellfiles[*]}" -patch -p1 <"$_patchfile" -echo "rm $_patchfile" -rm "$_patchfile" # patch should work because of dryrun test above + echo echo "---- STEP 4 ---- Test for codes not handled in $0" -echo "$_shellcheck_bin -x ${_alwaysExcludeOpts[*]} ${_shellfiles[*]}" -$_shellcheck_bin -x "${_alwaysExcludeOpts[@]}" "${_shellfiles[@]}" -_rc=$? +if $_check_only; then + # A non-check-only run would avoid triggering the patchable checks again + # in this invocation. Mask them out for a check-only run. + _excludeOpts=(--shell=bash --exclude="$(join ',' "${_alwaysExclude[@]}" "${_patchable[@]}")") + echo "$_shellcheck_bin -x ${_excludeOpts[*]} ${_shellfiles[*]}" + $_shellcheck_bin -x "${_excludeOpts[@]}" "${_shellfiles[@]}" + _rc=$? +else + echo "$_shellcheck_bin -x ${_alwaysExcludeOpts[*]} ${_shellfiles[*]}" + $_shellcheck_bin -x "${_alwaysExcludeOpts[@]}" "${_shellfiles[@]}" + _rc=$? +fi if [ $_rc != 0 ] ; then echo echo "ERROR: shellcheck found codes not yet handled, must fix $0" From 82dc1c6b7a07203f8671ae43af7c780e72106f87 Mon Sep 17 00:00:00 2001 From: Jan Patrick Lehr Date: Wed, 25 Feb 2026 12:46:10 +0100 Subject: [PATCH 08/10] [Lint] Adds shellcheck workflow (#1989) This adds a workflow that runs vanilla shellcheck across all .sh scripts inside the AOMP repository. Also adds a shellcheck.rc file. The checks excluded are taken from https://github.com/ROCm/aomp/pull/1463 --- .github/workflows/aomp-shell.yml | 16 ++++++++++++++++ .shellcheckrc | 1 + 2 files changed, 17 insertions(+) create mode 100644 .github/workflows/aomp-shell.yml create mode 100644 .shellcheckrc diff --git a/.github/workflows/aomp-shell.yml b/.github/workflows/aomp-shell.yml new file mode 100644 index 0000000000..f989b39404 --- /dev/null +++ b/.github/workflows/aomp-shell.yml @@ -0,0 +1,16 @@ +name: AOMP Lint + +on: + push: + pull_request: + +jobs: + aomp-lint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: Run shellcheck + run: | + find . -name "*.sh" -exec shellcheck -S info {} + diff --git a/.shellcheckrc b/.shellcheckrc new file mode 100644 index 0000000000..ec6f4bb8bb --- /dev/null +++ b/.shellcheckrc @@ -0,0 +1 @@ +disable=SC2016,SC2002,SC2004 From 4026ddb05b0e73bd0466c5f76833192f7329e6fa Mon Sep 17 00:00:00 2001 From: Jan Patrick Lehr Date: Wed, 25 Feb 2026 13:30:24 +0100 Subject: [PATCH 09/10] [LLVM Test Suite] Enable HIP catch2 tests (#1999) This enables the HIP catch2 tests that are already present in the LLVM test suite. --- bin/run_llvm-test-suite.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/bin/run_llvm-test-suite.sh b/bin/run_llvm-test-suite.sh index 504cb39345..1f4be38149 100755 --- a/bin/run_llvm-test-suite.sh +++ b/bin/run_llvm-test-suite.sh @@ -188,10 +188,11 @@ if [ "${DoConfigure}" == "yes" ]; then -DTEST_SUITE_LIT="${AOMP}/bin/llvm-lit" \ -DCMAKE_STRIP="" \ -DAMDGPU_ARCHS="${LLVMTS_GPU}" \ + -DHIP_EXPORT_XUNIT_XML=ON \ + -DENABLE_HIP_CATCH_TESTS=ON \ -DCMAKE_BUILD_TYPE="${LLVMTS_BUILD_TYPE}" \ -DCMAKE_C_COMPILER="${AOMP}/bin/clang" \ - -DCMAKE_CXX_COMPILER="${AOMP}/bin/clang++" \ - -DCMAKE_BUILD_TYPE="Release" + -DCMAKE_CXX_COMPILER="${AOMP}/bin/clang++" fi # Build @@ -207,11 +208,12 @@ if [ "${DoTest}" == "yes" ]; then echo "Log in ${LLVMTS_LOGS_DIR}/test-output.log" + for TestTarget in check-hip-simple check-hip-catch; do # Use timeout to prevent tests from hanging # -k 30: Send SIGKILL after 30 seconds if SIGTERM doesn't terminate the process # This ensures even completely hung processes are killed if command -v timeout >/dev/null; then - timeout -k 30 "${LLVMTS_TEST_TIMEOUT}" "${TestBuildTool}" check-hip-simple 2>&1 | tee "${LLVMTS_LOGS_DIR}/test-output.log" + timeout -k 30 "${LLVMTS_TEST_TIMEOUT}" "${TestBuildTool}" "${TestTarget}" 2>&1 | tee "${LLVMTS_LOGS_DIR}/test-output.log" test_exit_code="${PIPESTATUS[0]}" if [ "${test_exit_code}" -eq 124 ]; then echo "WARNING: Tests timed out after ${LLVMTS_TEST_TIMEOUT} seconds" @@ -220,9 +222,10 @@ if [ "${DoTest}" == "yes" ]; then fi else echo "WARNING: timeout command not found. Not running tests" - popd + popd || exit 1 exit 1 fi + done fi popd || exit From 184ad179c29d709d71cdf142d0f17e192c56f217 Mon Sep 17 00:00:00 2001 From: dpalermo Date: Wed, 25 Feb 2026 14:13:51 -0600 Subject: [PATCH 10/10] [srock] Define CMAKE_HIP_COMPILER (#2000) * [srock] Define CMAKE_HIP_COMPILER - Allows building on systems with /opt/rocm * Move libc add_subdirectory(benchmarks) under LLVM_INCLUDE_TESTS - Needed when -DTHEROCK_ENABLE_LLVM_TESTS=1 is used --- srock-bin/patches/amd-staging/_TheRock.patch | 18 +++++++++++++++--- .../amd-staging/compiler_amd-llvm.patch | 16 ++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 srock-bin/patches/amd-staging/compiler_amd-llvm.patch diff --git a/srock-bin/patches/amd-staging/_TheRock.patch b/srock-bin/patches/amd-staging/_TheRock.patch index 92013f8c9b..eab4d1475c 100644 --- a/srock-bin/patches/amd-staging/_TheRock.patch +++ b/srock-bin/patches/amd-staging/_TheRock.patch @@ -1,3 +1,15 @@ +diff --git a/cmake/therock_subproject.cmake b/cmake/therock_subproject.cmake +index e8356406..d3373e56 100644 +--- a/cmake/therock_subproject.cmake ++++ b/cmake/therock_subproject.cmake +@@ -1410,6 +1410,7 @@ function(_therock_cmake_subproject_setup_toolchain + string(APPEND _toolchain_contents "set(AMDGPU_TARGETS @_filtered_gpu_targets@ CACHE STRING \"From super-project\" FORCE)\n") + string(APPEND _toolchain_contents "set(GPU_TARGETS @_filtered_gpu_targets@ CACHE STRING \"From super-project\" FORCE)\n") + string(APPEND _toolchain_contents "set(CMAKE_HIP_ARCHITECTURES @_filtered_gpu_targets@ CACHE STRING \"From super-project\" FORCE)\n") ++ string(APPEND _toolchain_contents "set(CMAKE_HIP_COMPILER \"@AMD_LLVM_CXX_COMPILER@\")\n") + endif() + + # General settings applicable to all toolchains. diff --git a/compiler/CMakeLists.txt b/compiler/CMakeLists.txt index 9db31320..8552b77c 100644 --- a/compiler/CMakeLists.txt @@ -63,10 +75,10 @@ index 48aa6a8b..20ea73f1 100644 # Setup the install rpath (let CMake handle build RPATH per usual): # * Executables and libraries can always search their adjacent lib directory diff --git a/profiler/CMakeLists.txt b/profiler/CMakeLists.txt -index 4b1f02ef..fef7efed 100644 +index de446e14..af47ddad 100644 --- a/profiler/CMakeLists.txt +++ b/profiler/CMakeLists.txt -@@ -81,11 +81,16 @@ endif(THEROCK_BUILD_TESTING) +@@ -82,11 +82,16 @@ endif(THEROCK_BUILD_TESTING) EXTERNAL_SOURCE_DIR "${THEROCK_ROCM_SYSTEMS_SOURCE_DIR}/projects/rocprofiler-sdk" BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/rocprofiler-sdk" BACKGROUND_BUILD @@ -83,7 +95,7 @@ index 4b1f02ef..fef7efed 100644 COMPILER_TOOLCHAIN amd-hip RUNTIME_DEPS -@@ -160,11 +165,15 @@ endif(THEROCK_BUILD_TESTING) +@@ -163,11 +168,15 @@ endif(THEROCK_BUILD_TESTING) # Must build with the HIP compiler. amd-hip CMAKE_ARGS diff --git a/srock-bin/patches/amd-staging/compiler_amd-llvm.patch b/srock-bin/patches/amd-staging/compiler_amd-llvm.patch new file mode 100644 index 0000000000..3ae33ffbec --- /dev/null +++ b/srock-bin/patches/amd-staging/compiler_amd-llvm.patch @@ -0,0 +1,16 @@ +diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt +index 46d799cbec11..e1228651d856 100644 +--- a/libc/CMakeLists.txt ++++ b/libc/CMakeLists.txt +@@ -420,10 +420,9 @@ add_subdirectory(lib) + if(LLVM_INCLUDE_TESTS) + add_subdirectory(test) + add_subdirectory(fuzzing) ++# add_subdirectory(benchmarks) + endif() + +-add_subdirectory(benchmarks) +- + if (LIBC_INCLUDE_DOCS) + add_subdirectory(docs) + endif()