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
16 changes: 16 additions & 0 deletions .github/workflows/aomp-shell.yml
Original file line number Diff line number Diff line change
@@ -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 {} +
1 change: 1 addition & 0 deletions .shellcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
disable=SC2016,SC2002,SC2004
146 changes: 146 additions & 0 deletions bin/aomp-shellcheck
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#!/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
#

# 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 --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
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

_shellcheck_bin=$(which shellcheck)
if [ "$_shellcheck_bin" == "" ] ; then
echo "ERROR: please install shellcheck"
exit 1
fi

echo
echo "---- STEP 1 ---- Check for fixByHand fails -----"
echo "$_shellcheck_bin -x ${_fixByHandOpts[*]} ${_shellfiles[*]}"

$_shellcheck_bin -x "${_fixByHandOpts[@]}" "${_shellfiles[@]}"
_rc=$?
if [[ $_rc != 0 ]]; then
echo
echo "ERROR: shellcheck found errors that must be fixed by hand. rc=$_rc"
exit 1
fi

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 4 ---- Test for codes not handled in $0"
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"
exit $_rc
fi
echo
if [ "${#_shellfiles[@]}" -eq 1 ]; then
echo "DONE: script ${_shellfiles[*]} is clean"
else
echo "DONE: scripts $(join ',' ${_shellfiles[@]}) are clean"
fi
exit 0
34 changes: 16 additions & 18 deletions bin/run_llama.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -87,35 +85,35 @@ 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 ..
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
Expand All @@ -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}
Expand All @@ -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
Loading
Loading