Add 'projects/rocprofiler-systems/' from commit '92e1d84c72c9321d79a1866e0090fae0215e6557'
git-subtree-dir: projects/rocprofiler-systems git-subtree-mainline:ee9e74df21git-subtree-split:92e1d84c72
Этот коммит содержится в:
Коммит
6755fa3a36
699 files changed
+179131
No files matched your search
@@ -0,0 +1,23 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2022 Advanced Micro Devices, Inc. All Rights Reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
@@ -0,0 +1,400 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
: ${VERBOSE:=0}
|
||||
: ${EXTRA_ARGS:=""}
|
||||
: ${BUILD_DIR:=build-release}
|
||||
: ${VERSION:=0.0.4}
|
||||
: ${ROCM_VERSION:=4.5.0}
|
||||
: ${BOOST_VERSION:=1.79.0}
|
||||
: ${NJOBS:=12}
|
||||
: ${DISTRO:=""}
|
||||
: ${LTO:="OFF"}
|
||||
: ${STRIP:="OFF"}
|
||||
: ${LIBGCC:="ON"}
|
||||
: ${LIBSTDCXX:="ON"}
|
||||
: ${MAX_THREADS:=2048}
|
||||
: ${PERFETTO_TOOLS:="ON"}
|
||||
: ${HIDDEN_VIZ:="ON"}
|
||||
: ${PYTHON_VERSIONS:="6 7 8 9 10 11 12 13"}
|
||||
: ${GENERATORS:="STGZ DEB RPM"}
|
||||
: ${MPI_IMPL:="openmpi"}
|
||||
: ${CLEAN:=0}
|
||||
: ${FRESH:=0}
|
||||
: ${WITH_CORE:=0}
|
||||
: ${WITH_MPI:=0}
|
||||
: ${WITH_ROCM:=0}
|
||||
: ${WITH_ROCM_MPI:=0}
|
||||
: ${IS_DOCKER:=0}
|
||||
: ${CONDA_ROOT:=/opt/conda}
|
||||
|
||||
if [ -z "${DISTRO}" ]; then
|
||||
if [ -f /etc/os-release ]; then
|
||||
DISTRO=$(cat /etc/os-release | egrep "^ID=" | sed 's/"/ /g' | sed 's/=/ /g' | sed 's/-/ /g' | awk '{print $2}')-$(cat /etc/os-release | egrep "^VERSION=" | sed 's/"/ /g' | sed 's/=/ /g' | awk '{print $2}')
|
||||
else
|
||||
DISTRO=$(lsb_release -i | awk '{print $NF}')-$(lsb_release -r | awk '{print $NF}')
|
||||
fi
|
||||
fi
|
||||
|
||||
tolower()
|
||||
{
|
||||
echo "$@" | awk -F '\\|~\\|' '{print tolower($1)}';
|
||||
}
|
||||
|
||||
toupper()
|
||||
{
|
||||
echo "$@" | awk -F '\\|~\\|' '{print toupper($1)}';
|
||||
}
|
||||
|
||||
usage()
|
||||
{
|
||||
print_option() { printf " --%-10s %-36s %s\n" "${1}" "${2}" "${3}"; }
|
||||
echo "Options:"
|
||||
python_info="(Use '+nopython' to build w/o python, use '+python' to python build with python)"
|
||||
print_option core "[+nopython] [+python]" "Core ${python_info}"
|
||||
print_option mpi "[+nopython] [+python]" "MPI ${python_info}"
|
||||
print_option rocm "[+nopython] [+python]" "ROCm ${python_info}"
|
||||
print_option rocm-mpi "[+nopython] [+python]" "ROCm + MPI ${python_info}"
|
||||
print_option mpi-impl "[openmpi|mpich]" "MPI implementation"
|
||||
|
||||
echo ""
|
||||
print_default_option() { printf " --%-20s %-26s %s (default: %s)\n" "${1}" "${2}" "${3}" "$(tolower ${4})"; }
|
||||
print_default_option lto "[on|off]" "Enable LTO" "${LTO}"
|
||||
print_default_option strip "[on|off]" "Strip libraries" "${STRIP}"
|
||||
print_default_option perfetto-tools "[on|off]" "Install perfetto tools" "${PERFETTO_TOOLS}"
|
||||
print_default_option static-libgcc "[on|off]" "Build with static libgcc" "${LIBGCC}"
|
||||
print_default_option static-libstdcxx "[on|off]" "Build with static libstdc++" "${LIBSTDCXX}"
|
||||
print_default_option hidden-visibility "[on|off]" "Build with hidden visibility" "${HIDDEN_VIZ}"
|
||||
print_default_option max-threads "N" "Max number of threads supported" "${MAX_THREADS}"
|
||||
print_default_option parallel "N" "Number of parallel build jobs" "${NJOBS}"
|
||||
print_default_option generators "[STGZ][DEB][RPM][+others]" "CPack generators" "${GENERATORS}"
|
||||
}
|
||||
|
||||
send-error()
|
||||
{
|
||||
usage
|
||||
echo -e "\nError: ${@}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
reset-last()
|
||||
{
|
||||
last() { send-error "Unsupported argument :: ${1}"; }
|
||||
}
|
||||
|
||||
reset-last
|
||||
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
ARG=${1}
|
||||
shift
|
||||
VAL=0
|
||||
|
||||
case "${ARG}" in
|
||||
--clean)
|
||||
CLEAN=1
|
||||
reset-last
|
||||
continue
|
||||
;;
|
||||
--fresh)
|
||||
FRESH=1
|
||||
reset-last
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
if [ "$1" = "+nopython" ]; then
|
||||
VAL=$(( ${VAL} + 1 ))
|
||||
shift
|
||||
elif [ "$1" = "+python" ]; then
|
||||
VAL=$(( ${VAL} + 2 ))
|
||||
shift
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
case "${ARG}" in
|
||||
? | -h | --help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
--core)
|
||||
WITH_CORE=${VAL}
|
||||
reset-last
|
||||
;;
|
||||
--mpi)
|
||||
WITH_MPI=${VAL}
|
||||
reset-last
|
||||
;;
|
||||
--rocm)
|
||||
WITH_ROCM=${VAL}
|
||||
reset-last
|
||||
;;
|
||||
--rocm-mpi)
|
||||
WITH_ROCM_MPI=${VAL}
|
||||
reset-last
|
||||
;;
|
||||
--mpi-impl)
|
||||
MPI_IMPL=${1}
|
||||
shift
|
||||
reset-last
|
||||
;;
|
||||
--lto)
|
||||
LTO=$(toupper ${1})
|
||||
shift
|
||||
reset-last
|
||||
;;
|
||||
--static-libgcc)
|
||||
LIBGCC=$(toupper ${1})
|
||||
shift
|
||||
reset-last
|
||||
;;
|
||||
--static-libstdcxx)
|
||||
LIBSTDCXX=$(toupper ${1})
|
||||
shift
|
||||
reset-last
|
||||
;;
|
||||
--strip)
|
||||
STRIP=$(toupper ${1})
|
||||
shift
|
||||
reset-last
|
||||
;;
|
||||
--hidden-visibility)
|
||||
HIDDEN_VIZ=$(toupper ${1})
|
||||
shift
|
||||
reset-last
|
||||
;;
|
||||
--perfetto-tools)
|
||||
PERFETTO_TOOLS=$(toupper ${1})
|
||||
shift
|
||||
reset-last
|
||||
;;
|
||||
--max-threads)
|
||||
MAX_THREADS=${1}
|
||||
shift
|
||||
reset-last
|
||||
;;
|
||||
--parallel)
|
||||
NJOBS=${1}
|
||||
shift
|
||||
reset-last
|
||||
;;
|
||||
--generators)
|
||||
GENERATORS=$(toupper ${1})
|
||||
shift
|
||||
last() { GENERATORS="${GENERATORS} $(toupper ${1})"; }
|
||||
;;
|
||||
*)
|
||||
last ${ARG} ${1}
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
NPROC=$(nproc)
|
||||
if [ ${NJOBS} -gt ${NPROC} ]; then NJOBS=${NPROC}; fi
|
||||
|
||||
CMAKE_ARGS="-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=OFF -DCPACK_GENERATOR=STGZ"
|
||||
ROCPROFSYS_GENERAL_ARGS="-DROCPROFSYS_CPACK_SYSTEM_NAME=${DISTRO} -DROCPROFSYS_ROCM_VERSION=${ROCM_VERSION} -DROCPROFSYS_MAX_THREADS=${MAX_THREADS} -DROCPROFSYS_STRIP_LIBRARIES=${STRIP} -DROCPROFSYS_INSTALL_PERFETTO_TOOLS=${PERFETTO_TOOLS}"
|
||||
ROCPROFSYS_BUILD_ARGS="-DROCPROFSYS_BUILD_TESTING=OFF -DROCPROFSYS_BUILD_EXAMPLES=OFF -DROCPROFSYS_BUILD_PAPI=ON -DROCPROFSYS_BUILD_LTO=${LTO} -DROCPROFSYS_BUILD_HIDDEN_VISIBILITY=${HIDDEN_VIZ} -DROCPROFSYS_BUILD_STATIC_LIBGCC=${LIBGCC} -DROCPROFSYS_BUILD_STATIC_LIBSTDCXX=${LIBSTDCXX} -DROCPROFSYS_BUILD_RELEASE=ON"
|
||||
ROCPROFSYS_USE_ARGS="-DROCPROFSYS_USE_MPI_HEADERS=ON -DROCPROFSYS_USE_OMPT=ON -DROCPROFSYS_USE_PAPI=ON"
|
||||
TIMEMORY_ARGS="-DTIMEMORY_USE_LIBUNWIND=ON -DTIMEMORY_BUILD_LIBUNWIND=ON -DTIMEMORY_BUILD_PORTABLE=ON"
|
||||
DYNINST_ARGS="-DROCPROFSYS_BUILD_DYNINST=ON $(echo -DROCPROFSYS_BUILD_{TBB,BOOST,ELFUTILS,LIBIBERTY}=ON) -DROCPROFSYS_BOOST_DOWNLOAD_VERSION=${BOOST_VERSION}"
|
||||
STANDARD_ARGS="${CMAKE_ARGS} ${ROCPROFSYS_GENERAL_ARGS} ${ROCPROFSYS_USE_ARGS} ${ROCPROFSYS_BUILD_ARGS} ${TIMEMORY_ARGS} ${DYNINST_ARGS} ${EXTRA_ARGS}"
|
||||
|
||||
SCRIPT_DIR=$(realpath $(dirname ${BASH_SOURCE[0]}))
|
||||
cd $(dirname ${SCRIPT_DIR})
|
||||
echo -e "Working directory: $(pwd)"
|
||||
|
||||
umask 0000
|
||||
|
||||
verbose-run()
|
||||
{
|
||||
echo -e "\n##### Executing \"${@}\"... #####\n"
|
||||
eval $@
|
||||
}
|
||||
|
||||
copy-installer()
|
||||
{
|
||||
TYPE=${1}
|
||||
shift
|
||||
DEST=${1}
|
||||
shift
|
||||
if [ -z "${1}" ]; then
|
||||
echo "Warning! No cpack installer for ${TYPE} generator"
|
||||
return
|
||||
else
|
||||
for i in ${@}
|
||||
do
|
||||
verbose-run cp ${i} ${DEST}/
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
build-and-package-base()
|
||||
{
|
||||
local DIR=${1}
|
||||
shift
|
||||
if [ "${FRESH}" -gt 0 ]; then
|
||||
verbose-run rm -rf ${BUILD_DIR}/${DIR}/*
|
||||
fi
|
||||
verbose-run cmake -B ${BUILD_DIR}/${DIR} -DCMAKE_INSTALL_PREFIX=${BUILD_DIR}/${DIR}/install-release ${STANDARD_ARGS} $@ .
|
||||
if [ "${CLEAN}" -gt 0 ]; then
|
||||
verbose-run cmake --build ${BUILD_DIR}/${DIR} --target clean
|
||||
fi
|
||||
pushd ${BUILD_DIR}/${DIR}
|
||||
verbose-run cat CPackConfig.cmake
|
||||
if [ "${VERBOSE}" -gt 0 ]; then
|
||||
verbose-run cat cmake_install.cmake
|
||||
fi
|
||||
popd
|
||||
verbose-run cmake --build ${BUILD_DIR}/${DIR} --target all --parallel ${NJOBS}
|
||||
verbose-run cmake --build ${BUILD_DIR}/${DIR} --target install --parallel ${NJOBS}
|
||||
pushd ${BUILD_DIR}/${DIR}
|
||||
verbose-run rm -f *.sh *.deb *.rpm
|
||||
popd
|
||||
for i in ${GENERATORS}
|
||||
do
|
||||
pushd ${BUILD_DIR}/${DIR}
|
||||
case "${i}" in
|
||||
STGZ)
|
||||
verbose-run cpack -G STGZ
|
||||
EXT="sh"
|
||||
SEP="-"
|
||||
DEST="stgz"
|
||||
;;
|
||||
DEB)
|
||||
verbose-run cpack -G DEB -D CPACK_PACKAGING_INSTALL_PREFIX=/opt/rocprofiler-systems
|
||||
EXT="deb"
|
||||
SEP="_"
|
||||
DEST="deb"
|
||||
;;
|
||||
RPM)
|
||||
verbose-run cpack -G RPM -D CPACK_PACKAGING_INSTALL_PREFIX=/opt/rocprofiler-systems
|
||||
EXT="rpm"
|
||||
SEP="-"
|
||||
DEST="rpm"
|
||||
;;
|
||||
7Z | 7ZIP)
|
||||
verbose-run cpack -G 7Z
|
||||
EXT="7z"
|
||||
SEP="-"
|
||||
DEST="zip"
|
||||
;;
|
||||
TBZ2)
|
||||
verbose-run cpack -G TBZ2
|
||||
EXT="tar.bz2"
|
||||
SEP="-"
|
||||
DEST="zip"
|
||||
;;
|
||||
TGZ)
|
||||
verbose-run cpack -G TGZ
|
||||
EXT="tar.gz"
|
||||
SEP="-"
|
||||
DEST="zip"
|
||||
;;
|
||||
TXZ)
|
||||
verbose-run cpack -G TXZ
|
||||
EXT="tar.xz"
|
||||
SEP="-"
|
||||
DEST="zip"
|
||||
;;
|
||||
TZ)
|
||||
verbose-run cpack -G TZ
|
||||
EXT="tar.Z"
|
||||
SEP="-"
|
||||
DEST="zip"
|
||||
;;
|
||||
TZST)
|
||||
verbose-run cpack -G TZST
|
||||
EXT="tar.zst"
|
||||
SEP="-"
|
||||
DEST="zip"
|
||||
;;
|
||||
ZIP)
|
||||
verbose-run cpack -G ZIP
|
||||
EXT="zip"
|
||||
SEP="-"
|
||||
DEST="zip"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported cpack generator: ${i}"
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
popd
|
||||
verbose-run mkdir -p ${BUILD_DIR}/${DEST}
|
||||
verbose-run copy-installer ${i} ${BUILD_DIR}/${DEST} ${BUILD_DIR}/${DIR}/rocprofiler-systems${SEP}${VERSION}-*.${EXT}
|
||||
done
|
||||
}
|
||||
|
||||
build-and-package-python()
|
||||
{
|
||||
local DIR=${1}
|
||||
shift
|
||||
local _PYTHON_ENVS=""
|
||||
for i in ${PYTHON_VERSIONS}
|
||||
do
|
||||
conda activate py3.${i}
|
||||
if [ -z "${_PYTHON_ENVS}" ]; then
|
||||
_PYTHON_ENVS="$(dirname $(dirname $(which python)))"
|
||||
else
|
||||
_PYTHON_ENVS="${_PYTHON_ENVS};$(dirname $(dirname $(which python)))"
|
||||
fi
|
||||
conda deactivate
|
||||
done
|
||||
build-and-package-base ${DIR}-python $@ -DROCPROFSYS_USE_PYTHON=ON -DROCPROFSYS_BUILD_PYTHON=ON -DROCPROFSYS_PYTHON_ROOT_DIRS=\"${_PYTHON_ENVS}\"
|
||||
}
|
||||
|
||||
build-and-package()
|
||||
{
|
||||
local VAL=${1}
|
||||
shift
|
||||
if [ "${VAL}" -eq 1 ]; then
|
||||
build-and-package-base ${@}
|
||||
elif [ "${VAL}" -eq 2 ]; then
|
||||
build-and-package-python ${@}
|
||||
elif [ "${VAL}" -eq 3 ]; then
|
||||
build-and-package-base ${@}
|
||||
build-and-package-python ${@}
|
||||
else
|
||||
echo -e "Skipping build/package for ${1}"
|
||||
fi
|
||||
}
|
||||
|
||||
if [ -d ${CONDA_ROOT}/bin ]; then
|
||||
export PATH=${PATH}:${CONDA_ROOT}/bin
|
||||
source activate
|
||||
fi
|
||||
|
||||
if [ "${IS_DOCKER}" -ne 0 ]; then git config --global --add safe.directory ${PWD}; fi
|
||||
|
||||
verbose-run echo "Build rocprofiler-systems installers with generators: ${GENERATORS}"
|
||||
|
||||
build-and-package ${WITH_CORE} ${DISTRO}-core -DROCPROFSYS_USE_ROCM=OFF -DROCPROFSYS_USE_MPI=OFF
|
||||
build-and-package ${WITH_MPI} ${DISTRO}-${MPI_IMPL} -DROCPROFSYS_USE_ROCM=OFF -DROCPROFSYS_USE_MPI=ON
|
||||
build-and-package ${WITH_ROCM} ${DISTRO}-rocm-${ROCM_VERSION} -DROCPROFSYS_USE_ROCM=ON -DROCPROFSYS_USE_MPI=OFF
|
||||
build-and-package ${WITH_ROCM_MPI} ${DISTRO}-rocm-${ROCM_VERSION}-${MPI_IMPL} -DROCPROFSYS_USE_ROCM=ON -DROCPROFSYS_USE_MPI=ON
|
||||
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
if ! command -v gersemi &> /dev/null; then
|
||||
echo "gersemi could not be found. Please install it with 'pip install gersemi' or 'apt install gersemi'."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for file in "$@"; do
|
||||
# Run gersemi in-place
|
||||
gersemi -i "$file"
|
||||
# Check if the file has changes using git diff
|
||||
if ! git diff --quiet -- "$file"; then
|
||||
echo "Formatted: $file"
|
||||
fi
|
||||
done
|
||||
|
||||
exit 0
|
||||
@@ -0,0 +1,245 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
# Start of configuration
|
||||
preamble="Copyright +(\([cC]\) +)?"
|
||||
postamble=",? +Advanced +Micro +Devices, +Inc\."
|
||||
find_pattern="$preamble([0-9]{4}-)?[0-9]{4}$postamble"
|
||||
# printf format string, receives the current year as a parameter
|
||||
uptodate_pattern="$preamble([0-9]{4}-)?%d$postamble"
|
||||
# <pattern>/<replacement> interpreted with sed syntax, also passed to printf
|
||||
# printf interprets '\' escape sequences so they must be escaped
|
||||
# The capture groups are as follows:
|
||||
# - \1 is the whole preamble text
|
||||
# - \3 is the start year, \2 is skipped because it is used for an optional part of the preamble
|
||||
# - \5 is the end of the copyright statement after the end year, \4 would be the original end year
|
||||
# as written in the file, it is replaced by the current year instead.
|
||||
replace_pattern="($preamble)([0-9]{4})(-[0-9]{4})?($postamble)/\\\1\\\3-%d\\\5"
|
||||
# End of configuration
|
||||
|
||||
print_help() { printf -- \
|
||||
"\033[36musuage\033[0m: \033[33mcheck_year.sh [-h] [-u] [-a] [-d <SHA>] [-k] [-v]\033[0m
|
||||
\033[36mdescription\033[0m: Checks for if the copyright year in the staged files is up to date and displays the files with out-of-date copyright statements. Exits with '0' if successful and with '1' if something is out of date.
|
||||
\033[36moptions\033[0m:
|
||||
\033[34m-h\033[0m Displays this message.
|
||||
\033[34m-u\033[0m Automatically updates the copyright year
|
||||
\033[34m-a\033[0m Automatically applies applies the changes to current staging environment. Implies '-u' and '-c'.
|
||||
\033[34m-c\033[0m Compare files to the index instead of the working tree.
|
||||
\033[34m-d <SHA>\033[0m Compare using the diff of a hash.
|
||||
\033[34m-k\033[0m Compare using the fork point: where this branch and 'remotes/origin/HEAD' diverge.
|
||||
\033[34m-q\033[0m Suppress updates about progress.
|
||||
\033[34m-v\033[0m Verbose output.
|
||||
Use '\033[33mgit config --local hooks.updateCopyright <true|false>\033[0m' to automatically apply copyright changes on commit.
|
||||
"
|
||||
}
|
||||
|
||||
# argument parsing
|
||||
apply=false
|
||||
update=false
|
||||
verbose=false
|
||||
forkdiff=false
|
||||
quiet=false
|
||||
cached=false
|
||||
|
||||
while getopts "auhvkqcd:" arg; do
|
||||
case $arg in
|
||||
a) update=true;apply=true;cached=true;;
|
||||
u) update=true;;
|
||||
v) verbose=true;;
|
||||
k) forkdiff=true;;
|
||||
q) quiet=true;;
|
||||
c) cached=true;;
|
||||
d) diff_hash=${OPTARG};;
|
||||
h) print_help; exit;;
|
||||
*) print help; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
# If set, check all files changed since the fork point
|
||||
if $forkdiff; then
|
||||
branch="$(git rev-parse --abbrev-ref HEAD)"
|
||||
remote="$(git config --local --get "branch.$branch.remote" || echo 'origin')"
|
||||
source_commit="remotes/$remote/HEAD"
|
||||
|
||||
# don't use fork-point for finding fork point (lol)
|
||||
# see: https://stackoverflow.com/a/53981615
|
||||
diff_hash="$(git merge-base "$source_commit" "$branch")"
|
||||
fi
|
||||
|
||||
if [ -n "${diff_hash}" ]; then
|
||||
$verbose && printf -- "Using base commit: %s\n" "${diff_hash}"
|
||||
else
|
||||
diff_hash="HEAD"
|
||||
fi
|
||||
|
||||
# Current year
|
||||
year="$(date +%Y)"
|
||||
|
||||
# Enable rename detection with full matches only, this skips copyright checks for file name only
|
||||
# changes.
|
||||
diff_opts=(-z --name-only '--diff-filter=MA' '--find-renames=100%')
|
||||
git_grep_opts=(-z --extended-regexp --ignore-case --no-recursive -I)
|
||||
if $cached; then
|
||||
diff_opts+=(--cached)
|
||||
git_grep_opts+=(--cached)
|
||||
fi
|
||||
|
||||
! $quiet && printf -- "Checking if copyright statements are up-to-date... "
|
||||
mapfile -d $'\0' changed_files < <(git diff-index "${diff_opts[@]}" "$diff_hash" | LANG=C.UTF-8 sort -z)
|
||||
|
||||
if ! (( ${#changed_files[@]} )); then
|
||||
! $quiet && printf -- "\033[32mDone!\033[0m\n"
|
||||
$verbose && printf -- "\033[36mNo changed files found.\033[0m\n"
|
||||
exit 0
|
||||
fi;
|
||||
|
||||
mapfile -d $'\0' found_copyright < <( \
|
||||
git grep "${git_grep_opts[@]}" --files-with-matches -e "$find_pattern" \
|
||||
-- "${changed_files[@]}" | \
|
||||
LANG=C.UTF-8 sort -z)
|
||||
|
||||
outdated_copyright=()
|
||||
if (( ${#found_copyright[@]} )); then
|
||||
# uptodate_pattern variable holds the format string using it as such is intentional
|
||||
# shellcheck disable=SC2059
|
||||
printf -v uptodate_pattern -- "$uptodate_pattern" "$year"
|
||||
mapfile -d $'\0' outdated_copyright < <( \
|
||||
git grep "${git_grep_opts[@]}" --files-without-match -e "$uptodate_pattern" \
|
||||
-- "${found_copyright[@]}" | \
|
||||
LANG=C.UTF-8 sort -z)
|
||||
fi
|
||||
|
||||
! $quiet && printf -- "\033[32mDone!\033[0m\n"
|
||||
if $verbose; then
|
||||
# Compute the files that don't have a copyright as the set difference of
|
||||
# `changed_files and `found_copyright`
|
||||
mapfile -d $'\0' notfound_copyright < <( \
|
||||
printf -- '%s\0' "${changed_files[@]}" | \
|
||||
LANG=C.UTF-8 comm -z -23 - <(printf -- '%s\0' "${found_copyright[@]}"))
|
||||
|
||||
if (( ${#notfound_copyright[@]} )); then
|
||||
printf -- "\033[36mCouldn't find a copyright statement in %d file(s):\033[0m\n" \
|
||||
"${#notfound_copyright[@]}"
|
||||
printf -- ' - %q\n' "${notfound_copyright[@]}"
|
||||
fi
|
||||
|
||||
# Similarly the up-to-date files are the difference of `found_copyright` and `outdated_copyright`
|
||||
mapfile -d $'\0' uptodate_copyright < <( \
|
||||
printf -- '%s\0' "${found_copyright[@]}" | \
|
||||
LANG=C.UTF-8 comm -z -23 - <(printf -- '%s\0' "${outdated_copyright[@]}"))
|
||||
|
||||
if (( ${#uptodate_copyright[@]} )); then
|
||||
printf -- "\033[36mThe copyright statement was already up to date in %d file(s):\033[0m\n" \
|
||||
"${#uptodate_copyright[@]}"
|
||||
printf -- ' - %q\n' "${uptodate_copyright[@]}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! (( ${#outdated_copyright[@]} )); then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
printf -- \
|
||||
"\033[31m==== COPYRIGHT OUT OF DATE ====\033[0m
|
||||
\033[36m%d file(s) need(s) to be updated:\033[0m\n" "${#outdated_copyright[@]}"
|
||||
printf -- ' - %q\n' "${outdated_copyright[@]}"
|
||||
|
||||
# If we don't need to update, we early exit.
|
||||
if ! $update; then
|
||||
printf -- \
|
||||
"\nRun '\033[33m%s -u\033[0m' to update the copyright statement(s). See '-h' for more info,
|
||||
or set '\033[33mgit config --local hooks.updateCopyright true\033[0m' to automatically update copyrights when committing.\n" \
|
||||
"${BASH_SOURCE[0]}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if $apply; then
|
||||
! $quiet && printf -- "Updating copyrights and staging changes... "
|
||||
else
|
||||
! $quiet && printf -- "Updating copyrights... "
|
||||
fi
|
||||
|
||||
# replace_pattern variable holds a format string, using it as such is intentional
|
||||
# shellcheck disable=SC2059
|
||||
printf -v replace_pattern -- "$replace_pattern" "$year"
|
||||
# Just update the files in place if only touching the working-tree
|
||||
if ! $apply; then
|
||||
sed --regexp-extended --separate "s/$replace_pattern/g" -i "${outdated_copyright[@]}"
|
||||
printf -- "\033[32mDone!\033[0m\n"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
generate_patch() {
|
||||
# Sed command to create a hunk for a copyright statement fix
|
||||
# expects input to be line number then copyright statement on the next line
|
||||
to_hunk_cmd="{# Print hunk header, move to the next line
|
||||
s/.+/@@ -&,1 +&,1 @@/;n
|
||||
# Print removed line by prepending '-' to it
|
||||
;s/^/-/;p
|
||||
# Print added line, replace the '-' with '+' and replace the copyright statement
|
||||
s/^-/+/;s/$replace_pattern/g}"
|
||||
|
||||
# Run file-names through git ls-files, just to get a (possibly) quoted name for each
|
||||
mapfile -t -d $'\n' quoted_files < <(git ls-files --cached -- "${outdated_copyright[@]}")
|
||||
for ((i = 0;i < ${#outdated_copyright[@]}; i++)); do
|
||||
file="${outdated_copyright["$i"]}"
|
||||
quoted="${quoted_files["$i"]}"
|
||||
# Drop the quote from the start and end (to avoid quoting twice)
|
||||
escaped="${quoted#\"}"; escaped="${escaped%\"}"
|
||||
a="\"a/$escaped\""
|
||||
b="\"b/$escaped\""
|
||||
|
||||
printf -- "diff --git %s %s\n--- %s\n+++ %s\n" "$a" "$b" "$a" "$b"
|
||||
|
||||
# Print line number and line for each line with a copyright statement
|
||||
git cat-file blob ":$file" | \
|
||||
sed --quiet --regexp-extended "/$find_pattern/{=;p}" | \
|
||||
sed --regexp-extended "$to_hunk_cmd"
|
||||
done
|
||||
}
|
||||
|
||||
patch_file="$(git rev-parse --git-dir)/copyright-fix.patch"
|
||||
generate_patch > "$patch_file"
|
||||
|
||||
# Cleanup patch file when the script exits
|
||||
finish () {
|
||||
rm -f "$patch_file"
|
||||
}
|
||||
# The trap will be invoked whenever the script exits, even due to a signal, this is a bash only
|
||||
# feature
|
||||
trap finish EXIT
|
||||
|
||||
if ! git apply --unidiff-zero < "$patch_file"; then
|
||||
printf -- "\033[31mFailed to apply changes to working tree.
|
||||
Perhaps the fix is already applied, but not yet staged?\n\033[0m"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! git apply --cached --unidiff-zero < "$patch_file"; then
|
||||
printf -- "\033[31mFailed to apply change to the index.\n\033[0m"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
! $quiet && printf -- "\033[32mDone!\033[0m\n"
|
||||
exit 0
|
||||
@@ -0,0 +1,91 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
expected_copyright=("Copyright (c)" ".COPYRIGHT")
|
||||
files_with_missing_copyright=()
|
||||
files=("$@")
|
||||
|
||||
if [[ "$ALLOW_MISSING_COPYRIGHT" == "1" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
for file in "${files[@]}"; do
|
||||
if [[ -f "$file" ]]; then
|
||||
found=0
|
||||
for pattern in "${expected_copyright[@]}"; do
|
||||
if grep -Fq "$pattern" "$file"; then
|
||||
found=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [[ $found -eq 0 ]]; then
|
||||
files_with_missing_copyright+=("$file")
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${#files_with_missing_copyright[@]} -ne 0 ]; then
|
||||
if [[ "$ADD_COPYRIGHT" == "1" ]]; then
|
||||
for file in "${files_with_missing_copyright[@]}"; do
|
||||
# Determine the comment style based on the file extension
|
||||
if [[ "$file" == *.c || "$file" == *.cpp || "$file" == *.h || "$file" == *.hpp ]]; then
|
||||
comS="//"
|
||||
else
|
||||
comS="#"
|
||||
fi
|
||||
|
||||
# Read LICENSE file and prepend comment prefix to each line
|
||||
copyright_notice=""
|
||||
while IFS= read -r line; do
|
||||
if [[ -n "$line" ]]; then
|
||||
copyright_notice+="$comS $line"$'\n'
|
||||
else
|
||||
copyright_notice+="$comS"$'\n'
|
||||
fi
|
||||
done < LICENSE
|
||||
|
||||
# Add the notice to the beginning of the file
|
||||
temp_file=$(mktemp)
|
||||
{
|
||||
echo -e "$copyright_notice"
|
||||
cat "$file"
|
||||
} > "$temp_file"
|
||||
mv "$temp_file" "$file"
|
||||
done
|
||||
echo "Copyright notices added."
|
||||
exit 1
|
||||
fi
|
||||
echo "The following files are missing a valid copyright notice:"
|
||||
echo ""
|
||||
for file in "${files_with_missing_copyright[@]}"; do
|
||||
echo "$file"
|
||||
done
|
||||
echo ""
|
||||
echo "It may be the case that the copyright is not required by some files."
|
||||
echo "To override this check, set the environment variable ALLOW_MISSING_COPYRIGHT=1"
|
||||
echo "To add the copyright to all files listed above, set the environment variable ADD_COPYRIGHT=1"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@@ -0,0 +1,59 @@
|
||||
#!/bin/bash
|
||||
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
SOURCE_DIR=..
|
||||
BUILD_DIR=.
|
||||
|
||||
if [ -n "$1" ]; then SOURCE_DIR=$1; shift; fi
|
||||
if [ -n "$1" ]; then BUILD_DIR=$1; shift; fi
|
||||
|
||||
echo "Testing 'cmake --build ${BUILD_DIR} --target all'..."
|
||||
cmake --build ${BUILD_DIR} --target all
|
||||
RET=$?
|
||||
|
||||
echo -n "Testing whether ${SOURCE_DIR}/include/timemory is a valid path... "
|
||||
if [ ! -d ${SOURCE_DIR}/include/timemory ]; then
|
||||
RET=1;
|
||||
fi
|
||||
echo " Done"
|
||||
|
||||
if [ "${RET}" -ne 0 ]; then
|
||||
echo "Run from build directory within the source tree"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for i in $(find ${SOURCE_DIR}/include/timemory -type f | egrep '\.(h|hpp|c|cpp)$')
|
||||
do
|
||||
echo -n "Attempting to remove ${i}... "
|
||||
rm $i
|
||||
cmake --build ${BUILD_DIR} --target all &> /dev/null
|
||||
RET=$?
|
||||
if [ "${RET}" -ne 0 ]; then
|
||||
git checkout ${i} &> /dev/null
|
||||
echo "Failed"
|
||||
else
|
||||
git add ${i} &> /dev/null
|
||||
echo "Success"
|
||||
fi
|
||||
done
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import glob
|
||||
|
||||
"""
|
||||
This script reads in function prototypes can generates the implementation pieces
|
||||
needed to dlsym the function in librocprof-sys.
|
||||
|
||||
Example input file:
|
||||
|
||||
bool OnLoad(HsaApiTable* table, uint64_t runtime_version, uint64_t failed_tool_count,
|
||||
const char* const* failed_tool_names);
|
||||
void OnUnload();
|
||||
|
||||
generates:
|
||||
|
||||
##### declaration:
|
||||
|
||||
bool OnLoad(HsaApiTable*, uint64_t, uint64_t, const char* const*) ROCPROFSYS_PUBLIC_API;
|
||||
void OnUnload() ROCPROFSYS_PUBLIC_API;
|
||||
|
||||
##### dlsym:
|
||||
|
||||
ROCPROFSYS_DLSYM(OnLoad_f, m_omnihandle, "OnLoad");
|
||||
ROCPROFSYS_DLSYM(OnUnload_f, m_omnihandle, "OnUnload");
|
||||
|
||||
##### member variables:
|
||||
|
||||
bool (*OnLoad_f)(HsaApiTable*, uint64_t, uint64_t, const char* const*) = nullptr;
|
||||
void (*OnUnload_f)() = nullptr;
|
||||
|
||||
##### callers:
|
||||
|
||||
bool OnLoad(HsaApiTable* table, uint64_t runtime_version, uint64_t failed_tool_count, const char* const* failed_tool_names)
|
||||
{
|
||||
return ROCPROFSYS_DL_INVOKE(get_indirect().OnLoad_f, table, runtime_version, failed_tool_count, failed_tool_names);
|
||||
}
|
||||
|
||||
void OnUnload()
|
||||
{
|
||||
return ROCPROFSYS_DL_INVOKE(get_indirect().OnUnload_f);
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
class function:
|
||||
def __init__(self, _f):
|
||||
self.return_type = _f.split(" ", 1)[0]
|
||||
_f = "".join(_f.split(" ", 1)[1:])
|
||||
self.func_name = _f.split("(", 1)[0]
|
||||
_f = "".join(_f.split("(", 1)[1:]).rstrip(")")
|
||||
self.params = [x.strip() for x in _f.split(",")]
|
||||
self.param_types = []
|
||||
self.param_names = []
|
||||
for itr in self.params:
|
||||
_fields = itr.split(" ")
|
||||
_len = len(_fields)
|
||||
self.param_types.append(" ".join(_fields[0 : (_len - 1)]))
|
||||
self.param_names.append(_fields[-1])
|
||||
|
||||
def valid(self):
|
||||
return len(self.func_name) > 0
|
||||
|
||||
def member_variables(self):
|
||||
return " {} (*{}_f)({}) = nullptr;".format(
|
||||
self.return_type, self.func_name, ", ".join(self.param_types)
|
||||
)
|
||||
|
||||
def function_decl(self):
|
||||
return " {} {}({}) ROCPROFSYS_PUBLIC_API;".format(
|
||||
self.return_type, self.func_name, ", ".join(self.param_types)
|
||||
)
|
||||
|
||||
def dlsym_function(self):
|
||||
return ' ROCPROFSYS_DLSYM({0}_f, m_omnihandle, "{0}");'.format(self.func_name)
|
||||
|
||||
def call_dlsym_function(self):
|
||||
_param_names = ", ".join(self.param_names)
|
||||
if _param_names and _param_names != ", ":
|
||||
_param_names = f", {_param_names}"
|
||||
return " {} {}({})\n {}\n return ROCPROFSYS_DL_INVOKE(get_indirect().{}_f{});\n {}".format(
|
||||
self.return_type,
|
||||
self.func_name,
|
||||
", ".join(self.params),
|
||||
"{",
|
||||
self.func_name,
|
||||
_param_names,
|
||||
"}",
|
||||
)
|
||||
|
||||
|
||||
def run(fname):
|
||||
with open(fname, "r") as f:
|
||||
_str = ""
|
||||
for itr in f.read():
|
||||
_str += itr.replace("\n", " ")
|
||||
|
||||
while " " in _str:
|
||||
_str = _str.replace(" ", " ")
|
||||
data = [x.strip(" ") for x in _str.split(";")]
|
||||
|
||||
funcs = []
|
||||
for itr in data:
|
||||
f = function(itr)
|
||||
if f.valid():
|
||||
funcs.append(f)
|
||||
|
||||
return funcs
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
funcs = []
|
||||
for inp in sys.argv[1:]:
|
||||
if os.path.exists(inp):
|
||||
funcs += run(inp)
|
||||
else:
|
||||
for itr in glob.glob(f"{inp}*"):
|
||||
if os.path.exists(itr):
|
||||
funcs += run(itr)
|
||||
else:
|
||||
printf(f"No file matched {itr}")
|
||||
|
||||
if funcs:
|
||||
print(f"\n##### declaration:\n")
|
||||
for itr in funcs:
|
||||
print("{}".format(itr.function_decl()))
|
||||
|
||||
print(f"\n##### dlsym:\n")
|
||||
for itr in funcs:
|
||||
print("{}".format(itr.dlsym_function()))
|
||||
|
||||
print(f"\n##### member variables:\n")
|
||||
for itr in funcs:
|
||||
print("{}".format(itr.member_variables()))
|
||||
|
||||
print(f"\n##### callers:")
|
||||
for itr in funcs:
|
||||
print("")
|
||||
print("{}".format(itr.call_dlsym_function()))
|
||||
|
||||
print("")
|
||||
@@ -0,0 +1,119 @@
|
||||
#!/bin/bash
|
||||
|
||||
EXE=$(basename ${1})
|
||||
DIR=gperftools-output
|
||||
mkdir -p ${DIR}
|
||||
|
||||
# gperftools settings
|
||||
: ${N:=0}
|
||||
: ${GPERFTOOLS_PROFILE:=""}
|
||||
: ${GPERFTOOLS_PROFILE_BASE:=${DIR}/prof.${EXE}}
|
||||
: ${MALLOCSTATS:=1}
|
||||
: ${CPUPROFILE_FREQUENCY:=250}
|
||||
: ${CPUPROFILE_REALTIME:=1}
|
||||
: ${PPROF:=$(which google-pprof)}
|
||||
: ${PPROF:=$(which pprof)}
|
||||
|
||||
# rendering settings
|
||||
: ${INTERACTIVE:=0}
|
||||
: ${IMG_FORMAT:="png"}
|
||||
#: ${DOT_ARGS:='-Gsize=24,24\! -Gdpi=200'}
|
||||
: ${DOT_ARGS:=""}
|
||||
: ${PPROF_ARGS:="--no_strip_temp --functions"}
|
||||
|
||||
if [ "$(uname)" = "Darwin" ]; then
|
||||
if [ "${IMG_FORMAT}" = "jpeg" ]; then
|
||||
IMG_FORMAT="jpg"
|
||||
fi
|
||||
fi
|
||||
|
||||
run-verbose()
|
||||
{
|
||||
echo "### ${@} ###" 1>&2
|
||||
eval ${@}
|
||||
}
|
||||
|
||||
while [ -z "${GPERFTOOLS_PROFILE}" ]
|
||||
do
|
||||
TEST_FILE=${GPERFTOOLS_PROFILE_BASE}.${N}
|
||||
if [ ! -f "${TEST_FILE}" ]; then
|
||||
GPERFTOOLS_PROFILE=${TEST_FILE}
|
||||
fi
|
||||
N=$((${N}+1))
|
||||
done
|
||||
|
||||
export MALLOCSTATS
|
||||
export CPUPROFILE_FREQUENCY
|
||||
export CPUPROFILE_REALTIME
|
||||
|
||||
echo -e "\n\t--> Outputting profile to '${GPERFTOOLS_PROFILE}'...\n"
|
||||
|
||||
# remove profile file if unsucessful execution
|
||||
cleanup-failure() { set +v ; echo "failure"; rm -f ${GPERFTOOLS_PROFILE}; exit 1; }
|
||||
trap cleanup-failure SIGHUP SIGINT SIGQUIT SIGILL SIGABRT SIGKILL
|
||||
|
||||
ADD_LIBS()
|
||||
{
|
||||
for i in $@
|
||||
do
|
||||
if [ -z "${ADD_LIB_LIST}" ]; then
|
||||
ADD_LIB_LIST="--add_lib=${i}"
|
||||
else
|
||||
ADD_LIB_LIST="${ADD_LIB_LIST} --add_lib=${i}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
ADD_PRELOAD()
|
||||
{
|
||||
for i in $@
|
||||
do
|
||||
if [ -z "${LIBS}" ]; then
|
||||
LIBS=${i}
|
||||
else
|
||||
LIBS="${LIBS}:${i}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
run-pprof()
|
||||
{
|
||||
if [ -n "${PPROF}" ]; then
|
||||
run-verbose ${PPROF} ${ADD_LIB_LIST} ${PPROF_ARGS} "${@}"
|
||||
else
|
||||
echo -e "neither google-pprof nor pprof were found!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# configure pre-loading of profiler library
|
||||
for i in $(find ${PWD} -type f | egrep 'librocprof-sys' | egrep -v '\.a$' | egrep '\.so$') $(ldd ${1} | awk '{print $(NF-1)}')
|
||||
do
|
||||
if [ -f "${i}" ]; then run-verbose ADD_LIBS "${i}"; fi
|
||||
done
|
||||
run-verbose ADD_PRELOAD $(ldd ${1} | egrep 'profiler' | awk '{print $(NF-1)}') /usr/lib/$(uname -m)-linux-gnu/libprofiler.so
|
||||
LIBS=$(echo ${LIBS} | sed 's/^://g')
|
||||
|
||||
set -e
|
||||
# run the application
|
||||
LD_PRELOAD=${LIBS} CPUPROFILE_FREQUENCY=${CPUPROFILE_FREQUENCY} CPUPROFILE=${GPERFTOOLS_PROFILE} ${@} | tee ${GPERFTOOLS_PROFILE}.log
|
||||
set +e
|
||||
|
||||
# generate the results
|
||||
EXT=so
|
||||
if [ -f "${GPERFTOOLS_PROFILE}" ]; then
|
||||
run-pprof --text ${1} ${GPERFTOOLS_PROFILE} | c++filt -n -t 1> ${GPERFTOOLS_PROFILE}.txt
|
||||
run-pprof ${PPROF} --text --cum ${1} ${GPERFTOOLS_PROFILE} | c++filt -n -t 1> ${GPERFTOOLS_PROFILE}.cum.txt
|
||||
# if dot is available
|
||||
if [ -n "$(which dot)" ]; then
|
||||
run-pprof ${PPROF} --dot ${1} ${GPERFTOOLS_PROFILE} 1> ${GPERFTOOLS_PROFILE}.dot
|
||||
run-verbose $(which dot) ${DOT_ARGS} -T${IMG_FORMAT} ${GPERFTOOLS_PROFILE}.dot -o ${GPERFTOOLS_PROFILE}.${IMG_FORMAT}
|
||||
fi
|
||||
if [ "${INTERACTIVE}" -gt 0 ]; then
|
||||
run-pprof ${PPROF} ${1} ${GPERFTOOLS_PROFILE}
|
||||
fi
|
||||
else
|
||||
echo -e "profile file \"${GPERFTOOLS_PROFILE}\" not found!"
|
||||
ls -la
|
||||
exit 1
|
||||
fi
|
||||
@@ -0,0 +1,67 @@
|
||||
#!/bin/bash
|
||||
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
# Check if the folder path is provided
|
||||
if [ -z "$1" ]; then
|
||||
echo "Usage: $0 <folder_path>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Assign the folder path to a variable
|
||||
FOLDER_PATH=$1
|
||||
|
||||
# Check if the folder exists
|
||||
if [ ! -d "$FOLDER_PATH" ]; then
|
||||
echo "Error: Folder '$FOLDER_PATH' does not exist."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if there are more than one .proto files
|
||||
PROTO_FILES=("$FOLDER_PATH"/*.proto)
|
||||
if [ ${#PROTO_FILES[@]} -le 1 ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Merging multiprocess files ..."
|
||||
# Check if all .proto files have been fully written or wait
|
||||
TIMEOUT=60 # Timeout in seconds
|
||||
for file in "${PROTO_FILES[@]}"; do
|
||||
SECONDS=0
|
||||
while lsof "$file" > /dev/null 2>&1; do
|
||||
if [ $SECONDS -ge $TIMEOUT ]; then
|
||||
echo "Timeout reached while waiting for $file to be released."
|
||||
break
|
||||
fi
|
||||
echo "Waiting for $file to be released..."
|
||||
sleep 1
|
||||
done
|
||||
done
|
||||
|
||||
# Output file name
|
||||
OUTPUT_FILE="merged.proto"
|
||||
|
||||
# Merge all .proto files into one file
|
||||
cat "$FOLDER_PATH"/*.proto > "$FOLDER_PATH"/"$OUTPUT_FILE"
|
||||
|
||||
echo "All multiprocess .proto files in '$FOLDER_PATH' have been merged into '$OUTPUT_FILE'."
|
||||
@@ -0,0 +1,106 @@
|
||||
#!/bin/bash -e
|
||||
#
|
||||
# This script allows CMAKE_CXX_COMPILER to be a standard
|
||||
# C++ compiler and rocprofiler-systems sets RULE_LAUNCH_COMPILE and
|
||||
# RULE_LAUNCH_LINK in CMake so that all compiler and link
|
||||
# commands are prefixed with this script followed by the
|
||||
# C++ compiler. Thus if $1 == $2 then we know the command
|
||||
# was intended for the C++ compiler and we discard both
|
||||
# $1 and $2 and redirect the command to linker.
|
||||
# If $1 != $2 then we know that the command was not intended
|
||||
# for the C++ compiler and we just discard $1 and launch
|
||||
# the original command. Examples of when $2 will not equal
|
||||
# $1 are 'ar', 'cmake', etc. during the linking phase
|
||||
#
|
||||
|
||||
# emit a message about the underlying command executed
|
||||
: ${DEBUG:=0}
|
||||
: ${ROCPROFSYS_DEBUG_LAUNCH_COMPILER:=${DEBUG}}
|
||||
|
||||
debug-message()
|
||||
{
|
||||
if [ "${ROCPROFSYS_DEBUG_LAUNCH_COMPILER}" -ne 0 ]; then
|
||||
echo -e "##### $(basename ${BASH_SOURCE[0]}) executing: \"$@\"... #####"
|
||||
fi
|
||||
}
|
||||
|
||||
# if rocprofiler-systems compiler is not passed, someone is probably trying to invoke it directly
|
||||
if [ -z "${1}" ]; then
|
||||
echo -e "\n${BASH_SOURCE[0]} was invoked without the rocprofiler-systems compiler as the first argument."
|
||||
echo "This script is not indended to be directly invoked by any mechanism other"
|
||||
echo -e "than through a RULE_LAUNCH_COMPILE or RULE_LAUNCH_LINK property set in CMake.\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# if rocprofiler-systems compiler is not passed, someone is probably trying to invoke it directly
|
||||
if [ -z "${2}" ]; then
|
||||
echo -e "\n${BASH_SOURCE[0]} was invoked without the C++ compiler as the second argument."
|
||||
echo "This script is not indended to be directly invoked by any mechanism other"
|
||||
echo -e "than through a RULE_LAUNCH_COMPILE or RULE_LAUNCH_LINK property set in CMake.\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# if there aren't two args, this isn't necessarily invalid, just a bit strange
|
||||
if [ -z "${3}" ]; then exit 0; fi
|
||||
|
||||
# store the rocprofiler-systems compiler
|
||||
ROCPROFSYS_COMPILER=${1}
|
||||
|
||||
# remove the rocprofiler-systems compiler from the arguments
|
||||
shift
|
||||
|
||||
# store the expected C++ compiler
|
||||
CXX_COMPILER=${1}
|
||||
|
||||
# remove the expected C++ compiler from the arguments
|
||||
shift
|
||||
|
||||
# discards the clang-tidy arguments
|
||||
if [ "$(basename ${1})" = "cmake" ] && [ "${2}" = "-E" ] && [ "${3}" = "__run_co_compile" ]; then
|
||||
c=1
|
||||
n=1
|
||||
for i in "${@}"
|
||||
do
|
||||
if [ "${i}" = "--" ]; then
|
||||
break;
|
||||
fi
|
||||
if [ "${c}" -gt 3 ]; then
|
||||
n=$((${n} + 1))
|
||||
fi
|
||||
c=$((${c} + 1))
|
||||
done
|
||||
|
||||
if [[ $# -gt ${c} ]]; then
|
||||
n=$((${n} + 3)) # add three because of the first 3 args
|
||||
for i in $(seq 1 1 ${n})
|
||||
do
|
||||
shift
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "${CXX_COMPILER}" != "${1}" ]]; then
|
||||
debug-message $@
|
||||
# the command does not depend on rocprofiler-systems so just execute the command w/o re-directing to ${ROCPROFSYS_COMPILER}
|
||||
eval $@
|
||||
else
|
||||
# the executable is the C++ compiler, so we need to re-direct to ${ROCPROFSYS_COMPILER}
|
||||
if [ ! -f "${ROCPROFSYS_COMPILER}" ]; then
|
||||
echo -e "\nError: the compiler redirect for rocprofiler-systems was not found at ${ROCPROFSYS_COMPILER}\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# discard the compiler from the command
|
||||
shift
|
||||
|
||||
if [ -n "$(basename ${ROCPROFSYS_COMPILER} | egrep 'amdclang|amdllvm')" ]; then
|
||||
# this ensures the libomptarget-amdgpu-gfx*.bc files are found
|
||||
LLVM_LIB_DIR=$(cd $(dirname $(realpath ${ROCPROFSYS_COMPILER}))/../lib && pwd)
|
||||
debug-message export LIBRARY_PATH=${LLVM_LIB_DIR}:${LIBRARY_PATH}
|
||||
export LIBRARY_PATH=${LLVM_LIB_DIR}:${LIBRARY_PATH}
|
||||
fi
|
||||
|
||||
debug-message ${ROCPROFSYS_COMPILER} $@
|
||||
# execute ${ROCPROFSYS_COMPILER} (again, usually nvcc_wrapper)
|
||||
${ROCPROFSYS_COMPILER} $@
|
||||
fi
|
||||
@@ -0,0 +1,17 @@
|
||||
leak:Dyninst::
|
||||
leak:dyninst
|
||||
leak:tbb::
|
||||
leak:boost::
|
||||
leak:libdw
|
||||
leak:libamd_comgr
|
||||
leak:libpfm4
|
||||
leak:libhsa
|
||||
leak:libamdhip64
|
||||
leak:libroctracer64
|
||||
leak:librocprofiler64
|
||||
leak:__cxx_global_var_init
|
||||
leak:tim::timemory_argparse
|
||||
leak:tim::argparse::argument_parser::parse_known_args
|
||||
leak:std::shared_ptr<std::promise<void> >
|
||||
leak:realloc
|
||||
leak:Kokkos::
|
||||
@@ -0,0 +1,31 @@
|
||||
# false positive
|
||||
race:rocprofsys::component::pthread_create_gotcha::operator()
|
||||
race:pthread_create
|
||||
race:tim::impl::storage<*>::_data()
|
||||
race:tim::graph<*>::append_child
|
||||
|
||||
# unlock of mutex by wrong thread (rsmi_init -> rsmi_shut_down)
|
||||
called_from_lib:librocm_smi64.so
|
||||
|
||||
# suppress any races originating in Dyninst
|
||||
called_from_lib:libcommon.so
|
||||
called_from_lib:libdynC_API.so
|
||||
called_from_lib:libdynDwarf.so
|
||||
called_from_lib:libdynElf.so
|
||||
called_from_lib:libdyninstAPI.so
|
||||
called_from_lib:libinstructionAPI.so
|
||||
called_from_lib:libparseAPI.so
|
||||
called_from_lib:libpatchAPI.so
|
||||
called_from_lib:libpcontrol.so
|
||||
called_from_lib:libstackwalk.so
|
||||
called_from_lib:libsymtabAPI.so
|
||||
called_from_lib:libtbb.so
|
||||
|
||||
# suppress any races originating in some Dyninst function
|
||||
race_top:Dyninst::
|
||||
race:Dyninst::
|
||||
race:libparseAPI.so
|
||||
race:boost::
|
||||
|
||||
# thread leaks
|
||||
thread:*
|
||||
+321
@@ -0,0 +1,321 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import glob
|
||||
import socket
|
||||
import shutil
|
||||
import argparse
|
||||
import multiprocessing
|
||||
|
||||
|
||||
def which(cmd, require):
|
||||
v = shutil.which(cmd)
|
||||
if require and v is None:
|
||||
raise RuntimeError(f"{cmd} not found")
|
||||
return v if v is not None else ""
|
||||
|
||||
|
||||
def generate_custom(args, cmake_args, ctest_args):
|
||||
if not os.path.exists(args.binary_dir):
|
||||
os.makedirs(args.binary_dir)
|
||||
|
||||
NAME = args.name
|
||||
SITE = args.site
|
||||
BUILD_JOBS = args.build_jobs
|
||||
SUBMIT_URL = args.submit_url
|
||||
SOURCE_DIR = os.path.realpath(args.source_dir)
|
||||
BINARY_DIR = os.path.realpath(args.binary_dir)
|
||||
CMAKE_ARGS = " ".join(cmake_args)
|
||||
CTEST_ARGS = " ".join(ctest_args)
|
||||
|
||||
GIT_CMD = which("git", require=True)
|
||||
GCOV_CMD = which("gcov", require=False)
|
||||
CMAKE_CMD = which("cmake", require=True)
|
||||
CTEST_CMD = which("ctest", require=True)
|
||||
|
||||
NAME = re.sub(r"(.*)-([0-9]+)/merge", "PR_\\2_\\1", NAME)
|
||||
|
||||
return f"""
|
||||
set(CTEST_PROJECT_NAME "rocprofiler-systems")
|
||||
set(CTEST_NIGHTLY_START_TIME "05:00:00 UTC")
|
||||
|
||||
set(CTEST_DROP_METHOD "http")
|
||||
set(CTEST_DROP_SITE_CDASH TRUE)
|
||||
set(CTEST_SUBMIT_URL "https://{SUBMIT_URL}")
|
||||
|
||||
set(CTEST_UPDATE_TYPE git)
|
||||
set(CTEST_UPDATE_VERSION_ONLY TRUE)
|
||||
set(CTEST_GIT_INIT_SUBMODULES TRUE)
|
||||
|
||||
set(CTEST_OUTPUT_ON_FAILURE TRUE)
|
||||
set(CTEST_USE_LAUNCHERS TRUE)
|
||||
set(CMAKE_CTEST_ARGUMENTS --output-on-failure {CTEST_ARGS})
|
||||
|
||||
set(CTEST_CUSTOM_MAXIMUM_NUMBER_OF_ERRORS "100")
|
||||
set(CTEST_CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS "100")
|
||||
set(CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE "51200")
|
||||
set(CTEST_CUSTOM_COVERAGE_EXCLUDE "/usr/.*;.*external/.*;.*examples/.*")
|
||||
|
||||
set(CTEST_SITE "{SITE}")
|
||||
set(CTEST_BUILD_NAME "{NAME}")
|
||||
|
||||
set(CTEST_SOURCE_DIRECTORY {SOURCE_DIR})
|
||||
set(CTEST_BINARY_DIRECTORY {BINARY_DIR})
|
||||
|
||||
set(CTEST_UPDATE_COMMAND {GIT_CMD})
|
||||
set(CTEST_CONFIGURE_COMMAND "{CMAKE_CMD} -B {BINARY_DIR} {SOURCE_DIR} -DROCPROFSYS_BUILD_CI=ON {CMAKE_ARGS}")
|
||||
set(CTEST_BUILD_COMMAND "{CMAKE_CMD} --build {BINARY_DIR} --target all --parallel {BUILD_JOBS}")
|
||||
set(CTEST_COVERAGE_COMMAND {GCOV_CMD})
|
||||
"""
|
||||
|
||||
|
||||
def generate_dashboard_script(args):
|
||||
CODECOV = 1 if args.coverage else 0
|
||||
DASHBOARD_MODE = args.mode
|
||||
SOURCE_DIR = os.path.realpath(args.source_dir)
|
||||
BINARY_DIR = os.path.realpath(args.binary_dir)
|
||||
|
||||
_script = """
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/CTestCustom.cmake")
|
||||
|
||||
macro(handle_error _message _ret)
|
||||
if(NOT ${${_ret}} EQUAL 0)
|
||||
ctest_submit(PARTS Done RETURN_VALUE _submit_ret)
|
||||
message(FATAL_ERROR "${_message} failed: ${${_ret}}")
|
||||
endif()
|
||||
endmacro()
|
||||
"""
|
||||
|
||||
_script += f"""
|
||||
ctest_start({DASHBOARD_MODE})
|
||||
ctest_update(SOURCE "{SOURCE_DIR}")
|
||||
ctest_configure(BUILD "{BINARY_DIR}" RETURN_VALUE _configure_ret)
|
||||
ctest_submit(PARTS Start Update Configure RETURN_VALUE _submit_ret)
|
||||
|
||||
handle_error("Configure" _configure_ret)
|
||||
|
||||
ctest_build(BUILD "{BINARY_DIR}" RETURN_VALUE _build_ret)
|
||||
ctest_submit(PARTS Build RETURN_VALUE _submit_ret)
|
||||
|
||||
handle_error("Build" _build_ret)
|
||||
|
||||
ctest_test(BUILD "{BINARY_DIR}" RETURN_VALUE _test_ret)
|
||||
ctest_submit(PARTS Test RETURN_VALUE _submit_ret)
|
||||
|
||||
if("{CODECOV}" GREATER 0)
|
||||
ctest_coverage(
|
||||
BUILD "{BINARY_DIR}"
|
||||
RETURN_VALUE _coverage_ret
|
||||
CAPTURE_CMAKE_ERROR _coverage_err)
|
||||
ctest_submit(PARTS Coverage RETURN_VALUE _submit_ret)
|
||||
endif()
|
||||
|
||||
handle_error("Testing" _test_ret)
|
||||
|
||||
ctest_submit(PARTS Done RETURN_VALUE _submit_ret)
|
||||
"""
|
||||
return _script
|
||||
|
||||
|
||||
def parse_cdash_args(args):
|
||||
BUILD_JOBS = multiprocessing.cpu_count()
|
||||
DASHBOARD_MODE = "Continuous"
|
||||
DASHBOARD_STAGES = [
|
||||
"Start",
|
||||
"Update",
|
||||
"Configure",
|
||||
"Build",
|
||||
"Test",
|
||||
"MemCheck",
|
||||
"Coverage",
|
||||
"Submit",
|
||||
]
|
||||
SOURCE_DIR = os.getcwd()
|
||||
BINARY_DIR = os.path.join(SOURCE_DIR, "build")
|
||||
SITE = socket.gethostname()
|
||||
NAME = None
|
||||
SUBMIT_URL = "my.cdash.org/submit.php?project=rocprofiler-systems"
|
||||
CODECOV = False
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
parser.add_argument(
|
||||
"-n", "--name", help="Job name", default=None, type=str, required=True
|
||||
)
|
||||
parser.add_argument("-s", "--site", help="Site name", default=SITE, type=str)
|
||||
parser.add_argument(
|
||||
"-c", "--coverage", help="Enable code coverage", action="store_true"
|
||||
)
|
||||
parser.add_argument(
|
||||
"-j", "--build-jobs", help="Number of build tasks", default=BUILD_JOBS, type=int
|
||||
)
|
||||
parser.add_argument(
|
||||
"-B", "--binary-dir", help="Build directory", default=BINARY_DIR, type=str
|
||||
)
|
||||
parser.add_argument(
|
||||
"-S", "--source-dir", help="Source directory", default=SOURCE_DIR, type=str
|
||||
)
|
||||
parser.add_argument(
|
||||
"-M",
|
||||
"--mode",
|
||||
help="Dashboard mode",
|
||||
default=DASHBOARD_MODE,
|
||||
choices=("Continuous", "Nightly", "Experimental"),
|
||||
type=str,
|
||||
)
|
||||
parser.add_argument(
|
||||
"-T",
|
||||
"--stages",
|
||||
help="Dashboard stages",
|
||||
nargs="+",
|
||||
default=DASHBOARD_STAGES,
|
||||
choices=DASHBOARD_STAGES,
|
||||
type=str,
|
||||
)
|
||||
parser.add_argument(
|
||||
"--submit-url", help="CDash submission site", default=SUBMIT_URL, type=str
|
||||
)
|
||||
parser.add_argument(
|
||||
"--repeat-until-pass", help="<N> for --repeat until-pass:<N>", default=3, type=int
|
||||
)
|
||||
parser.add_argument(
|
||||
"--repeat-until-fail",
|
||||
help="<N> for --repeat until-fail:<N>",
|
||||
default=None,
|
||||
type=int,
|
||||
)
|
||||
parser.add_argument(
|
||||
"--repeat-after-timeout",
|
||||
help="<N> for --repeat after-timeout:<N>",
|
||||
default=2,
|
||||
type=int,
|
||||
)
|
||||
|
||||
return parser.parse_args(args)
|
||||
|
||||
|
||||
def parse_args(args=None):
|
||||
if args is None:
|
||||
args = sys.argv[1:]
|
||||
|
||||
index = 0
|
||||
input_args = []
|
||||
ctest_args = []
|
||||
cmake_args = []
|
||||
data = [input_args, cmake_args, ctest_args]
|
||||
|
||||
for itr in args:
|
||||
if itr == "--":
|
||||
index += 1
|
||||
if index > 2:
|
||||
raise RuntimeError("Usage: <options> -- <ctest-args> -- <cdash-args>")
|
||||
else:
|
||||
data[index].append(itr)
|
||||
|
||||
cdash_args = parse_cdash_args(input_args)
|
||||
|
||||
if cdash_args.coverage:
|
||||
cmake_args += [
|
||||
"-DROCPROFSYS_BUILD_CODECOV=ON",
|
||||
"-DROCPROFSYS_STRIP_LIBRARIES=OFF",
|
||||
]
|
||||
|
||||
def get_repeat_val(_param):
|
||||
_value = getattr(cdash_args, f"repeat_{_param}".replace("-", "_"))
|
||||
return [f"{_param}:{_value}"] if _value is not None and _value > 1 else []
|
||||
|
||||
repeat_args = (
|
||||
get_repeat_val("until-pass")
|
||||
+ get_repeat_val("until-fail")
|
||||
+ get_repeat_val("after-timeout")
|
||||
)
|
||||
ctest_args += ["--repeat"] + repeat_args if len(repeat_args) > 0 else []
|
||||
|
||||
return [cdash_args, cmake_args, ctest_args]
|
||||
|
||||
|
||||
def run(*args, **kwargs):
|
||||
import subprocess
|
||||
|
||||
return subprocess.run(*args, **kwargs)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
args, cmake_args, ctest_args = parse_args()
|
||||
|
||||
if not os.path.exists(args.binary_dir):
|
||||
os.makedirs(args.binary_dir)
|
||||
|
||||
from textwrap import dedent
|
||||
|
||||
_config = dedent(generate_custom(args, cmake_args, ctest_args))
|
||||
_script = dedent(generate_dashboard_script(args))
|
||||
|
||||
with open(os.path.join(args.binary_dir, "CTestCustom.cmake"), "w") as f:
|
||||
f.write(f"{_config}\n")
|
||||
|
||||
with open(os.path.join(args.binary_dir, "dashboard.cmake"), "w") as f:
|
||||
f.write(f"{_script}\n")
|
||||
|
||||
CTEST_CMD = which("ctest", require=True)
|
||||
|
||||
dashboard_args = ["-D"]
|
||||
for itr in args.stages:
|
||||
dashboard_args.append(f"{args.mode}{itr}")
|
||||
|
||||
try:
|
||||
run(
|
||||
[CTEST_CMD]
|
||||
+ dashboard_args
|
||||
+ [
|
||||
"-S",
|
||||
os.path.join(args.binary_dir, "dashboard.cmake"),
|
||||
"--output-on-failure",
|
||||
"-V",
|
||||
]
|
||||
+ ctest_args,
|
||||
check=True,
|
||||
)
|
||||
finally:
|
||||
if "-VV" not in ctest_args:
|
||||
for file in glob.glob(
|
||||
os.path.join(args.binary_dir, "Testing/**"), recursive=True
|
||||
):
|
||||
if not os.path.isfile(file):
|
||||
continue
|
||||
print(f"\n\n\n###### Reading {file}... ######\n\n\n")
|
||||
with open(file, "r") as inpf:
|
||||
fdata = inpf.read()
|
||||
if "LastTest" not in file and "Coverage" not in file:
|
||||
print(fdata)
|
||||
oname = os.path.basename(file)
|
||||
if oname.endswith(".log"):
|
||||
oname += ".log"
|
||||
with open(os.path.join(args.binary_dir, oname), "w") as outf:
|
||||
print(f"\n\n###### Writing {oname}... ######\n\n")
|
||||
outf.write(fdata)
|
||||
+285
@@ -0,0 +1,285 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
SCRIPT_DIR=$(realpath $(dirname ${BASH_SOURCE[0]}))
|
||||
cd $(dirname ${SCRIPT_DIR})
|
||||
|
||||
tolower()
|
||||
{
|
||||
echo "$@" | awk -F '\\|~\\|' '{print tolower($1)}';
|
||||
}
|
||||
|
||||
toupper()
|
||||
{
|
||||
echo "$@" | awk -F '\\|~\\|' '{print toupper($1)}';
|
||||
}
|
||||
|
||||
: ${CMAKE_BUILD_PARALLEL_LEVEL:=$(nproc)}
|
||||
: ${DASHBOARD_MODE:="Continuous"}
|
||||
: ${DASHBOARD_STAGES:="Start Update Configure Build Test MemCheck Coverage Submit"}
|
||||
: ${SOURCE_DIR:=${PWD}}
|
||||
: ${BINARY_DIR:=${PWD}/build}
|
||||
: ${SITE:=$(hostname)}
|
||||
: ${NAME:=""}
|
||||
: ${SUBMIT_URL:="my.cdash.org/submit.php?project=rocprofiler-systems"}
|
||||
: ${CODECOV:=0}
|
||||
|
||||
usage()
|
||||
{
|
||||
print_option() { printf " --%-20s %-24s %s\n" "${1}" "${2}" "${3}"; }
|
||||
print_default_option() { printf " --%-20s %-24s %s (default: %s)\n" "${1}" "${2}" "${3}" "$(tolower ${4})"; }
|
||||
|
||||
echo "Options:"
|
||||
print_option "help -h" "" "This message"
|
||||
|
||||
echo ""
|
||||
print_option "coverage -c" "" "Enable code coverage"
|
||||
print_default_option "name -n" "<NAME>" "Job name" ""
|
||||
print_default_option "site -s" "<NAME>" "Site name" "${SITE}"
|
||||
print_default_option "source-dir -S" "<N>" "Source directory" "${SOURCE_DIR}"
|
||||
print_default_option "binary-dir -B" "<N>" "Build directory" "${BINARY_DIR}"
|
||||
print_default_option "build-jobs -j" "<N>" "Number of build jobs" "${CMAKE_BUILD_PARALLEL_LEVEL}"
|
||||
print_default_option cmake-args "<ARGS...>" "CMake configuration args" "none"
|
||||
print_default_option ctest-args "<ARGS...>" "CTest command args" "none"
|
||||
print_default_option cdash-mode "<ARGS...>" "CDash mode" "${DASHBOARD_MODE}"
|
||||
print_default_option cdash-stages "<ARGS...>" "CDash stages" "${DASHBOARD_STAGES}"
|
||||
print_default_option submit-url "<URL>" "CDash submission URL" "${SUBMIT_URL}"
|
||||
#print_default_option lto "[on|off]" "Enable LTO" "${LTO}"
|
||||
}
|
||||
|
||||
send-error()
|
||||
{
|
||||
usage
|
||||
echo -e "\nError: ${@}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
verbose-run()
|
||||
{
|
||||
echo -e "\n### Executing \"${@}\"... ###\n"
|
||||
eval "${@}"
|
||||
}
|
||||
|
||||
reset-last()
|
||||
{
|
||||
last() { send-error "Unsupported argument :: \"${1}\""; }
|
||||
}
|
||||
|
||||
reset-last
|
||||
|
||||
n=0
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
case "${1}" in
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
-c|--coverage)
|
||||
CODECOV=1
|
||||
reset-last
|
||||
;;
|
||||
-n|--name)
|
||||
shift
|
||||
NAME=$(echo ${1} | sed 's/g++/gcc/g' | sed 's/\/merge//1')
|
||||
reset-last
|
||||
;;
|
||||
-s|--site)
|
||||
shift
|
||||
SITE=${1}
|
||||
reset-last
|
||||
;;
|
||||
-S|--source-dir)
|
||||
shift
|
||||
SOURCE_DIR=${1}
|
||||
reset-last
|
||||
;;
|
||||
-B|--binary-dir)
|
||||
shift
|
||||
BINARY_DIR=${1}
|
||||
reset-last
|
||||
;;
|
||||
-j|--build-jobs)
|
||||
shift
|
||||
CMAKE_BUILD_PARALLEL_LEVEL=${1}
|
||||
reset-last
|
||||
;;
|
||||
--cmake-args)
|
||||
if [ -n "${2}" ]; then
|
||||
shift
|
||||
CMAKE_ARGS=${1}
|
||||
fi
|
||||
last() { CMAKE_ARGS="${CMAKE_ARGS} ${1}"; }
|
||||
;;
|
||||
--ctest-args)
|
||||
if [ -n "${2}" ]; then
|
||||
shift
|
||||
CTEST_ARGS=${1}
|
||||
fi
|
||||
last() { CTEST_ARGS="${CTEST_ARGS} \"${1}\""; }
|
||||
;;
|
||||
--cdash-mode)
|
||||
shift
|
||||
DASHBOARD_MODE=${1}
|
||||
reset-last
|
||||
;;
|
||||
--cdash-stages)
|
||||
shift
|
||||
DASHBOARD_STAGES=${1}
|
||||
last() { DASHBOARD_STAGES="${DASHBOARD_STAGES} ${1}"; }
|
||||
;;
|
||||
--submit-url)
|
||||
shift
|
||||
SUBMIT_URL=${1}
|
||||
reset-last
|
||||
;;
|
||||
--*)
|
||||
send-error "Unsupported argument at position $((${n} + 1)) :: \"${1}\""
|
||||
;;
|
||||
*)
|
||||
last ${1}
|
||||
;;
|
||||
esac
|
||||
n=$((${n} + 1))
|
||||
shift
|
||||
done
|
||||
|
||||
if [ -z "${NAME}" ]; then send-error "--name option required"; fi
|
||||
|
||||
CDASH_ARGS=""
|
||||
for i in ${DASHBOARD_STAGES}
|
||||
do
|
||||
if [ -z "${CDASH_ARGS}" ]; then
|
||||
CDASH_ARGS="-D ${DASHBOARD_MODE}${i}"
|
||||
else
|
||||
CDASH_ARGS="${CDASH_ARGS} -D ${DASHBOARD_MODE}${i}"
|
||||
fi
|
||||
done
|
||||
|
||||
export CMAKE_BUILD_PARALLEL_LEVEL
|
||||
|
||||
if [ "${CODECOV}" -gt 0 ]; then
|
||||
GCOV_CMD=$(which gcov)
|
||||
CMAKE_ARGS="${CMAKE_ARGS} -DROCPROFSYS_BUILD_CODECOV=ON -DROCPROFSYS_STRIP_LIBRARIES=OFF"
|
||||
fi
|
||||
|
||||
GIT_CMD=$(which git)
|
||||
CMAKE_CMD=$(which cmake)
|
||||
CTEST_CMD=$(which ctest)
|
||||
SOURCE_DIR=$(realpath ${SOURCE_DIR})
|
||||
BINARY_DIR=$(realpath ${BINARY_DIR})
|
||||
|
||||
verbose-run mkdir -p ${BINARY_DIR}
|
||||
|
||||
cat << EOF > ${BINARY_DIR}/CTestCustom.cmake
|
||||
|
||||
set(CTEST_PROJECT_NAME "rocprofiler-systems")
|
||||
set(CTEST_NIGHTLY_START_TIME "05:00:00 UTC")
|
||||
|
||||
set(CTEST_DROP_METHOD "http")
|
||||
set(CTEST_DROP_SITE_CDASH TRUE)
|
||||
set(CTEST_SUBMIT_URL "https://${SUBMIT_URL}")
|
||||
|
||||
set(CTEST_UPDATE_TYPE git)
|
||||
set(CTEST_UPDATE_VERSION_ONLY TRUE)
|
||||
set(CTEST_GIT_INIT_SUBMODULES TRUE)
|
||||
|
||||
set(CTEST_OUTPUT_ON_FAILURE TRUE)
|
||||
set(CTEST_USE_LAUNCHERS TRUE)
|
||||
set(CMAKE_CTEST_ARGUMENTS --output-on-failure ${CTEST_ARGS})
|
||||
|
||||
set(CTEST_CUSTOM_MAXIMUM_NUMBER_OF_ERRORS "100")
|
||||
set(CTEST_CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS "100")
|
||||
set(CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE "51200")
|
||||
set(CTEST_CUSTOM_COVERAGE_EXCLUDE "/usr/.*;.*external/.*;.*examples/.*")
|
||||
|
||||
set(CTEST_SITE "${SITE}")
|
||||
set(CTEST_BUILD_NAME "${NAME}")
|
||||
|
||||
set(CTEST_SOURCE_DIRECTORY ${SOURCE_DIR})
|
||||
set(CTEST_BINARY_DIRECTORY ${BINARY_DIR})
|
||||
|
||||
set(CTEST_UPDATE_COMMAND ${GIT_CMD})
|
||||
set(CTEST_CONFIGURE_COMMAND "${CMAKE_CMD} -B ${BINARY_DIR} ${SOURCE_DIR} -DROCPROFSYS_BUILD_CI=ON ${CMAKE_ARGS}")
|
||||
set(CTEST_BUILD_COMMAND "${CMAKE_CMD} --build ${BINARY_DIR} --target all --parallel ${CMAKE_BUILD_PARALLEL_LEVEL}")
|
||||
set(CTEST_COVERAGE_COMMAND ${GCOV_CMD})
|
||||
EOF
|
||||
|
||||
verbose-run cd ${BINARY_DIR}
|
||||
|
||||
cat << EOF > dashboard.cmake
|
||||
cmake_minimum_required(VERSION 3.18.4 FATAL_ERROR)
|
||||
|
||||
include("\${CMAKE_CURRENT_LIST_DIR}/CTestCustom.cmake")
|
||||
|
||||
set(_STAGES ${DASHBOARD_STAGES})
|
||||
|
||||
macro(handle_submit)
|
||||
if("Submit" IN_LIST _STAGES)
|
||||
ctest_submit(
|
||||
${ARGN}
|
||||
CAPTURE_CMAKE_ERROR _submit_err)
|
||||
if(NOT \${_submit_err} EQUAL 0)
|
||||
message(WARNING "Submission failed: ctest_submit(\${ARGN})")
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
macro(handle_error _message _ret)
|
||||
if(NOT \${\${_ret}} EQUAL 0)
|
||||
handle_submit(PARTS Done RETURN_VALUE _submit_ret)
|
||||
message(FATAL_ERROR "\${_message} failed: \${\${_ret}}")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
ctest_start(${DASHBOARD_MODE})
|
||||
ctest_update(SOURCE "${SOURCE_DIR}")
|
||||
ctest_configure(BUILD "${BINARY_DIR}" RETURN_VALUE _configure_ret)
|
||||
|
||||
handle_submit(PARTS Start Update Configure RETURN_VALUE _submit_ret)
|
||||
handle_error("Configure" _configure_ret)
|
||||
|
||||
ctest_build(BUILD "${BINARY_DIR}" RETURN_VALUE _build_ret)
|
||||
handle_submit(PARTS Build RETURN_VALUE _submit_ret)
|
||||
handle_error("Build" _build_ret)
|
||||
|
||||
ctest_test(BUILD "${BINARY_DIR}" RETURN_VALUE _test_ret)
|
||||
handle_submit(PARTS Test RETURN_VALUE _submit_ret)
|
||||
|
||||
if("${CODECOV}" GREATER 0)
|
||||
ctest_coverage(
|
||||
BUILD "${BINARY_DIR}"
|
||||
RETURN_VALUE _coverage_ret
|
||||
CAPTURE_CMAKE_ERROR _coverage_err)
|
||||
handle_submit(PARTS Coverage RETURN_VALUE _submit_ret)
|
||||
endif()
|
||||
|
||||
handle_error("Testing" _test_ret)
|
||||
|
||||
handle_submit(PARTS Done RETURN_VALUE _submit_ret)
|
||||
EOF
|
||||
|
||||
verbose-run cat CTestCustom.cmake
|
||||
verbose-run cat dashboard.cmake
|
||||
verbose-run ctest ${CDASH_ARGS} -S dashboard.cmake --output-on-failure -V ${CTEST_ARGS}
|
||||
@@ -0,0 +1,176 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
SCRIPT_DIR=$(realpath $(dirname ${BASH_SOURCE[0]}))
|
||||
cd $(dirname ${SCRIPT_DIR})
|
||||
echo -e "Working directory: $(pwd)"
|
||||
|
||||
error-message()
|
||||
{
|
||||
echo -e "\nError! ${@}\n"
|
||||
exit -1
|
||||
}
|
||||
|
||||
verbose-run()
|
||||
{
|
||||
echo -e "\n##### Executing \"${@}\"... #####\n"
|
||||
eval $@
|
||||
}
|
||||
|
||||
if [ -d "$(realpath /tmp)" ]; then
|
||||
: ${TMPDIR:=/tmp}
|
||||
export TMPDIR
|
||||
fi
|
||||
|
||||
: ${EXAMPLE_DIR:=examples}
|
||||
: ${EXAMPLE_NAME:=user-api}
|
||||
: ${SOURCE_DIR:=$(mktemp -t -d rocprof-sys-test-source-XXXX)}
|
||||
: ${BINARY_DIR:=$(mktemp -t -d rocprof-sys-test-build-XXXX)}
|
||||
: ${INSTALL_DIR:=$(mktemp -t -d rocprof-sys-install-XXXX)}
|
||||
: ${INSTALL_SCRIPT:=""}
|
||||
|
||||
usage()
|
||||
{
|
||||
print_option() { printf " --%-10s %-24s %s (default: %s)\n" "${1}" "${2}" "${3}" "${4}"; }
|
||||
echo "Options:"
|
||||
print_option example-name "<NAME>" "Name of the example project" "${EXAMPLE_NAME}"
|
||||
print_option example-dir "<PATH>" "Directory containing example" "${EXAMPLE_DIR}"
|
||||
print_option source-dir "<PATH>" "Location to copy example to" "${SOURCE_DIR}"
|
||||
print_option binary-dir "<PATH>" "Location to build" "${BINARY_DIR}"
|
||||
print_option install-dir "<PATH>" "Location of rocprofiler-systems installation" "${INSTALL_DIR}"
|
||||
print_option install-script "<FILEPATH>" "Absolute path to the installer script" ""
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
ARG=${1}
|
||||
shift
|
||||
|
||||
VAL=""
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
VAL=${1}
|
||||
shift
|
||||
break
|
||||
done
|
||||
|
||||
if [ -z "${VAL}" ]; then
|
||||
echo "Error! Missing value for argument \"${ARG}\""
|
||||
usage
|
||||
exit -1
|
||||
fi
|
||||
|
||||
case "${ARG}" in
|
||||
--example-name)
|
||||
EXAMPLE_NAME=${VAL}
|
||||
continue
|
||||
;;
|
||||
--example-dir)
|
||||
EXAMPLE_DIR=${VAL}
|
||||
continue
|
||||
;;
|
||||
--source-dir)
|
||||
SOURCE_DIR=${VAL}
|
||||
continue
|
||||
;;
|
||||
--binary-dir)
|
||||
BINARY_DIR=${VAL}
|
||||
continue
|
||||
;;
|
||||
--install-dir)
|
||||
INSTALL_DIR=${VAL}
|
||||
continue
|
||||
;;
|
||||
--install-script)
|
||||
INSTALL_SCRIPT=${VAL}
|
||||
continue
|
||||
;;
|
||||
*)
|
||||
echo -e "Error! Unknown option : ${ARG}"
|
||||
usage
|
||||
exit -1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ ! -f "${INSTALL_DIR}/include/rocprofiler-systems/user.h" ]; then
|
||||
if [ -z "${INSTALL_SCRIPT}" ]; then
|
||||
error-message "Unable to find \"rocprofiler-systems/user.h\" in \"${INSTALL_DIR}/include\" and installation script not provided"
|
||||
elif [ ! -f "${INSTALL_SCRIPT}" ]; then
|
||||
error-message "Unable to locate \"${INSTALL_SCRIPT}\" in directory \"${PWD}\""
|
||||
else
|
||||
verbose-run mkdir -p ${INSTALL_DIR}
|
||||
verbose-run $(realpath ${INSTALL_SCRIPT}) --prefix=${INSTALL_DIR} --skip-license --exclude-subdir
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -d ${SOURCE_DIR} ]; then
|
||||
verbose-run mkdir -p ${SOURCE_DIR}
|
||||
fi
|
||||
|
||||
verbose-run cp -v -r ${EXAMPLE_DIR}/${EXAMPLE_NAME}/* ${SOURCE_DIR}/
|
||||
|
||||
verbose-run pushd ${SOURCE_DIR}
|
||||
|
||||
cat << EOF > CMakeLists.txt
|
||||
cmake_minimum_required(VERSION 3.18.4.0 FATAL_ERROR)
|
||||
|
||||
project(test LANGUAGES C CXX)
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(rocprofiler-systems REQUIRED COMPONENTS user)
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
get_target_property(LIBS rocprofiler-systems::rocprofiler-systems INTERFACE_LINK_LIBRARIES)
|
||||
foreach(_LIB \${LIBS})
|
||||
foreach(_VAR LINK_LIBRARIES INCLUDE_DIRECTORIES)
|
||||
get_target_property(_VAL \${_LIB} INTERFACE_\${_VAR})
|
||||
if(_VAL)
|
||||
message(STATUS "\${_LIB} :: \${_VAR} :: \${_VAL}")
|
||||
endif()
|
||||
endforeach()
|
||||
endforeach()
|
||||
|
||||
file(GLOB sources \${CMAKE_CURRENT_LIST_DIR}/*.cpp \${CMAKE_CURRENT_LIST_DIR}/*.c)
|
||||
add_executable(app \${sources})
|
||||
target_link_libraries(app PRIVATE Threads::Threads rocprofiler-systems::rocprofiler-systems)
|
||||
EOF
|
||||
|
||||
export CMAKE_PREFIX_PATH=${INSTALL_DIR}:${CMAKE_PREFIX_PATH}
|
||||
|
||||
verbose-run find .
|
||||
verbose-run cmake -B ${BINARY_DIR} ${SOURCE_DIR}
|
||||
verbose-run cmake --build ${BINARY_DIR} --target all --parallel 2 -- VERBOSE=1
|
||||
|
||||
set +e
|
||||
|
||||
verbose-run pushd ${BINARY_DIR}
|
||||
verbose-run ./app
|
||||
verbose-run popd
|
||||
verbose-run popd
|
||||
+228
@@ -0,0 +1,228 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
SCRIPT_DIR=$(realpath $(dirname ${BASH_SOURCE[0]}))
|
||||
cd $(dirname ${SCRIPT_DIR})
|
||||
echo -e "Working directory: $(pwd)"
|
||||
|
||||
: ${SLEEP_TIME:=0}
|
||||
|
||||
error-message()
|
||||
{
|
||||
echo -e "\nError! ${@}\n"
|
||||
exit -1
|
||||
}
|
||||
|
||||
verbose-run()
|
||||
{
|
||||
echo -e "\n##### Executing \"${@}\"... #####\n"
|
||||
sleep ${SLEEP_TIME}
|
||||
eval $@
|
||||
}
|
||||
|
||||
toupper()
|
||||
{
|
||||
echo "$@" | awk -F '\\|~\\|' '{print toupper($1)}';
|
||||
}
|
||||
|
||||
get-bool()
|
||||
{
|
||||
echo "${1}" | egrep -i '^(y|on|yes|true|[1-9])$' &> /dev/null && echo 1 || echo 0
|
||||
}
|
||||
|
||||
if [ -d "$(realpath /tmp)" ]; then
|
||||
: ${TMPDIR:=/tmp}
|
||||
export TMPDIR
|
||||
fi
|
||||
|
||||
: ${CONFIG_DIR:=$(mktemp -t -d rocprof-sys-test-install-XXXX)}
|
||||
: ${SOURCE_DIR:=$(dirname ${SCRIPT_DIR})}
|
||||
: ${ENABLE_ROCPROFSYS_INSTRUMENT:=1}
|
||||
: ${ENABLE_ROCPROFSYS_AVAIL:=1}
|
||||
: ${ENABLE_ROCPROFSYS_SAMPLE:=1}
|
||||
: ${ENABLE_ROCPROFSYS_PYTHON:=0}
|
||||
: ${ENABLE_ROCPROFSYS_REWRITE:=1}
|
||||
: ${ENABLE_ROCPROFSYS_RUNTIME:=1}
|
||||
|
||||
usage()
|
||||
{
|
||||
print_option() { printf " --%-10s %-30s %s (default: %s)\n" "${1}" "${2}" "${3}" "${4}"; }
|
||||
echo "Options:"
|
||||
print_option source-dir "<PATH>" "Location of source directory" "${SOURCE_DIR}"
|
||||
print_option test-rocprof-sys-instrument "0|1" "Enable testing rocprof-sys-instrument" "${ENABLE_ROCPROFSYS_INSTRUMENT}"
|
||||
print_option test-rocprof-sys-avail "0|1" "Enable testing rocprof-sys-avail" "${ENABLE_ROCPROFSYS_AVAIL}"
|
||||
print_option test-rocprof-sys-sample "0|1" "Enable testing rocprof-sys-sample" "${ENABLE_ROCPROFSYS_SAMPLE}"
|
||||
print_option test-rocprof-sys-python "0|1" "Enable testing rocprof-sys-python" "${ENABLE_ROCPROFSYS_PYTHON}"
|
||||
print_option test-rocprof-sys-rewrite "0|1" "Enable testing rocprof-sys-instrument binary rewrite" "${ENABLE_ROCPROFSYS_REWRITE}"
|
||||
print_option test-rocprof-sys-runtime "0|1" "Enable testing rocprof-sys-instrument runtime instrumentation" "${ENABLE_ROCPROFSYS_RUNTIME}"
|
||||
}
|
||||
|
||||
cat << EOF > ${CONFIG_DIR}/rocprof-sys.cfg
|
||||
ROCPROFSYS_VERBOSE = 2
|
||||
ROCPROFSYS_PROFILE = ON
|
||||
ROCPROFSYS_TRACE = ON
|
||||
ROCPROFSYS_USE_SAMPLING = ON
|
||||
ROCPROFSYS_USE_PROCESS_SAMPLING = ON
|
||||
ROCPROFSYS_OUTPUT_PATH = %env{CONFIG_DIR}%/rocprof-sys-tests-output
|
||||
ROCPROFSYS_OUTPUT_PREFIX = %tag%/
|
||||
ROCPROFSYS_SAMPLING_FREQ = 100
|
||||
ROCPROFSYS_SAMPLING_DELAY = 0.05
|
||||
ROCPROFSYS_COUT_OUTPUT = ON
|
||||
ROCPROFSYS_TIME_OUTPUT = OFF
|
||||
ROCPROFSYS_USE_PID = OFF
|
||||
EOF
|
||||
|
||||
export CONFIG_DIR
|
||||
export ROCPROFSYS_CONFIG_FILE=${CONFIG_DIR}/rocprof-sys.cfg
|
||||
verbose-run cat ${ROCPROFSYS_CONFIG_FILE}
|
||||
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
ARG=${1}
|
||||
shift
|
||||
|
||||
VAL="$(echo ${ARG} | sed 's/=/ /1' | awk '{print $2}')"
|
||||
if [ -z "${VAL}" ]; then
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
VAL=$(get-bool ${1})
|
||||
shift
|
||||
break
|
||||
done
|
||||
else
|
||||
VAL=$(get-bool ${VAL})
|
||||
ARG="$(echo ${ARG} | sed 's/=/ /1' | awk '{print $1}')"
|
||||
fi
|
||||
|
||||
if [ -z "${VAL}" ]; then
|
||||
echo "Error! Missing value for argument \"${ARG}\""
|
||||
usage
|
||||
exit -1
|
||||
fi
|
||||
|
||||
case "${ARG}" in
|
||||
--test-rocprof-sys-instrument)
|
||||
ENABLE_ROCPROFSYS_INSTRUMENT=${VAL}
|
||||
continue
|
||||
;;
|
||||
--test-rocprof-sys-avail)
|
||||
ENABLE_ROCPROFSYS_AVAIL=${VAL}
|
||||
continue
|
||||
;;
|
||||
--test-rocprof-sys-sample)
|
||||
ENABLE_ROCPROFSYS_SAMPLE=${VAL}
|
||||
continue
|
||||
;;
|
||||
--test-rocprof-sys-python)
|
||||
ENABLE_ROCPROFSYS_PYTHON=${VAL}
|
||||
continue
|
||||
;;
|
||||
--test-rocprof-sys-rewrite)
|
||||
ENABLE_ROCPROFSYS_REWRITE=${VAL}
|
||||
continue
|
||||
;;
|
||||
--test-rocprof-sys-runtime)
|
||||
ENABLE_ROCPROFSYS_RUNTIME=${VAL}
|
||||
continue
|
||||
;;
|
||||
--source-dir)
|
||||
SOURCE_DIR=${VAL}
|
||||
continue
|
||||
;;
|
||||
*)
|
||||
echo -e "Error! Unknown option : ${ARG}"
|
||||
usage
|
||||
exit -1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
test-rocprof-sys-instrument()
|
||||
{
|
||||
verbose-run which rocprof-sys-instrument
|
||||
verbose-run ldd $(which rocprof-sys-instrument)
|
||||
verbose-run rocprof-sys-instrument --help
|
||||
}
|
||||
|
||||
test-rocprof-sys-avail()
|
||||
{
|
||||
verbose-run which rocprof-sys-avail
|
||||
verbose-run ldd $(which rocprof-sys-avail)
|
||||
verbose-run rocprof-sys-avail --help
|
||||
verbose-run rocprof-sys-avail -a
|
||||
}
|
||||
|
||||
test-rocprof-sys-sample()
|
||||
{
|
||||
verbose-run which rocprof-sys-sample
|
||||
verbose-run ldd $(which rocprof-sys-sample)
|
||||
verbose-run rocprof-sys-sample --help
|
||||
verbose-run rocprof-sys-sample --cputime 100 --realtime 50 --hsa-interrupt 0 -TPH -- python3 ${SOURCE_DIR}/examples/python/external.py -n 5 -v 20
|
||||
}
|
||||
|
||||
test-rocprof-sys-python()
|
||||
{
|
||||
verbose-run which rocprof-sys-python
|
||||
verbose-run rocprof-sys-python --help
|
||||
verbose-run rocprof-sys-python -b -- ${SOURCE_DIR}/examples/python/builtin.py -n 5 -v 5
|
||||
verbose-run rocprof-sys-python -b -- ${SOURCE_DIR}/examples/python/noprofile.py -n 5 -v 5
|
||||
verbose-run rocprof-sys-python -- ${SOURCE_DIR}/examples/python/external.py -n 5 -v 5
|
||||
verbose-run python3 ${SOURCE_DIR}/examples/python/source.py -n 5 -v 5
|
||||
}
|
||||
|
||||
test-rocprof-sys-rewrite()
|
||||
{
|
||||
if [ -f /usr/bin/coreutils ]; then
|
||||
local LS_NAME=coreutils
|
||||
local LS_ARGS="--coreutils-prog=ls"
|
||||
else
|
||||
local LS_NAME=ls
|
||||
local LS_ARGS=""
|
||||
fi
|
||||
verbose-run rocprof-sys-instrument -e -v 1 -o ${CONFIG_DIR}/ls.inst --simulate -- ${LS_NAME}
|
||||
for i in $(find ${CONFIG_DIR}/rocprof-sys-tests-output/ls.inst -type f); do verbose-run ls ${i}; done
|
||||
verbose-run rocprof-sys-instrument -e -v 1 -o ${CONFIG_DIR}/ls.inst -- ${LS_NAME}
|
||||
verbose-run rocprof-sys-run -- ${CONFIG_DIR}/ls.inst ${LS_ARGS}
|
||||
}
|
||||
|
||||
test-rocprof-sys-runtime()
|
||||
{
|
||||
if [ -f /usr/bin/coreutils ]; then
|
||||
local LS_NAME=coreutils
|
||||
local LS_ARGS="--coreutils-prog=ls"
|
||||
else
|
||||
local LS_NAME=ls
|
||||
local LS_ARGS=""
|
||||
fi
|
||||
verbose-run rocprof-sys-instrument -e -v 1 --simulate -- ${LS_NAME} ${LS_ARGS}
|
||||
for i in $(find ${CONFIG_DIR}/rocprof-sys-tests-output/$(basename ${LS_NAME}) -type f); do verbose-run ls ${i}; done
|
||||
verbose-run rocprof-sys-instrument -e -v 1 -- ${LS_NAME} ${LS_ARGS}
|
||||
}
|
||||
|
||||
if [ "${ENABLE_ROCPROFSYS_INSTRUMENT}" -ne 0 ]; then verbose-run test-rocprof-sys-instrument; fi
|
||||
if [ "${ENABLE_ROCPROFSYS_AVAIL}" -ne 0 ]; then verbose-run test-rocprof-sys-avail; fi
|
||||
if [ "${ENABLE_ROCPROFSYS_SAMPLE}" -ne 0 ]; then verbose-run test-rocprof-sys-sample; fi
|
||||
if [ "${ENABLE_ROCPROFSYS_PYTHON}" -ne 0 ]; then verbose-run test-rocprof-sys-python; fi
|
||||
if [ "${ENABLE_ROCPROFSYS_REWRITE}" -ne 0 ]; then verbose-run test-rocprof-sys-rewrite; fi
|
||||
if [ "${ENABLE_ROCPROFSYS_RUNTIME}" -ne 0 ]; then verbose-run test-rocprof-sys-runtime; fi
|
||||
+203
@@ -0,0 +1,203 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
SCRIPT_DIR=$(realpath $(dirname ${BASH_SOURCE[0]}))
|
||||
cd $(dirname ${SCRIPT_DIR})
|
||||
echo -e "Working directory: $(pwd)"
|
||||
|
||||
umask 0000
|
||||
|
||||
verbose-run()
|
||||
{
|
||||
echo -e "\n##### Executing \"${@}\"... #####\n"
|
||||
eval $@
|
||||
}
|
||||
|
||||
: ${RPM_FILE:=""}
|
||||
: ${DEB_FILE:=""}
|
||||
: ${STGZ_FILE:=""}
|
||||
: ${SUDO_CMD:=""}
|
||||
|
||||
usage()
|
||||
{
|
||||
print_option() { printf " --%-10s %-24s %s\n" "${1}" "${2}" "${3}"; }
|
||||
echo "Options:"
|
||||
print_option stgz "<FILE>" "Run installation test on STGZ package"
|
||||
print_option deb "<FILE>" "Run installation test on DEB package"
|
||||
print_option rpm "<FILE>" "Run installation test on RPM package"
|
||||
print_option sudo "" "Execute commands with sudo"
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
ARG=${1}
|
||||
shift
|
||||
|
||||
case "${ARG}" in
|
||||
--clean)
|
||||
CLEAN=1
|
||||
continue
|
||||
;;
|
||||
--fresh)
|
||||
FRESH=1
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
|
||||
VAL=""
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
VAL=${1}
|
||||
shift
|
||||
break
|
||||
done
|
||||
|
||||
if [ -z "${VAL}" ]; then
|
||||
echo "Error! Missing value for argument \"${ARG}\""
|
||||
usage
|
||||
exit -1
|
||||
fi
|
||||
|
||||
case "${ARG}" in
|
||||
? | -h | --help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
--stgz)
|
||||
STGZ_FILE=${VAL}
|
||||
;;
|
||||
--deb)
|
||||
DEB_FILE=${VAL}
|
||||
;;
|
||||
--rpm)
|
||||
RPM_FILE=${VAL}
|
||||
;;
|
||||
--sudo)
|
||||
SUDO_CMD=sudo
|
||||
;;
|
||||
*)
|
||||
echo -e "Error! Unknown option : ${ARG}"
|
||||
usage
|
||||
exit -1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
remove-pycache()
|
||||
{
|
||||
rm -rf ${1}/lib/python/site-packages/rocprofsys/__pycache__
|
||||
}
|
||||
|
||||
setup-env()
|
||||
{
|
||||
rm -rf ${1}/*
|
||||
export PATH=${1}/bin:${PATH}
|
||||
export LD_LIBRARY_PATH=${1}/lib:/opt/rocm/lib:${LD_LIBRARY_PATH}
|
||||
}
|
||||
|
||||
test-install()
|
||||
{
|
||||
ROCPROFSYS_MODULE_PATH="${1}/lib/python/site-packages/rocprofsys"
|
||||
verbose-run rocprof-sys-instrument --help
|
||||
verbose-run rocprof-sys-avail --help
|
||||
verbose-run rocprof-sys-avail --all
|
||||
|
||||
if [ -d $ROCPROFSYS_MODULE_PATH ]; then
|
||||
verbose-run which python3
|
||||
verbose-run python3 --version
|
||||
PYTHON_VERSION=$(python3 -c "import sys; print(f'python-{sys.version_info.major}{sys.version_info.minor}')")
|
||||
|
||||
if [ -z "$(find $ROCPROFSYS_MODULE_PATH -name "*${PYTHON_VERSION}*" -print -quit)" ]; then
|
||||
echo "Error: No library found for Python version ${PYTHON_VERSION} in $ROCPROFSYS_MODULE_PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
verbose-run rocprof-sys-python --help
|
||||
fi
|
||||
}
|
||||
|
||||
change-directory()
|
||||
{
|
||||
if [ ! -f "${1}" ]; then
|
||||
if [ -f "/home/rocprofiler-systems/${1}" ]; then
|
||||
cd /home/rocprofiler-systems
|
||||
elif [ -f "/home/rocprofiler-systems/docker/${1}" ]; then
|
||||
cd /home/rocprofiler-systems/docker
|
||||
fi
|
||||
fi
|
||||
realpath ${1}
|
||||
}
|
||||
|
||||
test-stgz()
|
||||
{
|
||||
if [ -z "${1}" ]; then return; fi
|
||||
|
||||
local INSTALLER=$(change-directory ${1})
|
||||
mkdir /opt/rocprofiler-systems-stgz
|
||||
setup-env /opt/rocprofiler-systems-stgz
|
||||
|
||||
verbose-run ${INSTALLER} --prefix=/opt/rocprofiler-systems-stgz --skip-license --exclude-dir
|
||||
|
||||
test-install /opt/rocprofiler-systems-stgz
|
||||
}
|
||||
|
||||
test-deb()
|
||||
{
|
||||
if [ -z "${1}" ]; then return; fi
|
||||
|
||||
local INSTALLER=$(change-directory ${1})
|
||||
setup-env /opt/rocprofiler-systems
|
||||
|
||||
verbose-run ${SUDO_CMD} dpkg --contents ${INSTALLER}
|
||||
verbose-run ${SUDO_CMD} dpkg -i ${INSTALLER}
|
||||
|
||||
test-install /opt/rocprofiler-systems
|
||||
remove-pycache /opt/rocprofiler-systems
|
||||
verbose-run apt-get remove -y rocprofiler-systems
|
||||
if [ -d /opt/rocprofiler-systems ]; then
|
||||
find /opt/rocprofiler-systems -type f
|
||||
fi
|
||||
}
|
||||
|
||||
test-rpm()
|
||||
{
|
||||
if [ -z "${1}" ]; then return; fi
|
||||
|
||||
local INSTALLER=$(change-directory ${1})
|
||||
setup-env /opt/rocprofiler-systems
|
||||
|
||||
verbose-run ${SUDO_CMD} rpm -ql -p ${INSTALLER}
|
||||
verbose-run ${SUDO_CMD} rpm -v -i -p ${INSTALLER} --nodeps
|
||||
|
||||
test-install /opt/rocprofiler-systems
|
||||
remove-pycache /opt/rocprofiler-systems
|
||||
verbose-run rpm -e rocprofiler-systems
|
||||
if [ -d /opt/rocprofiler-systems ]; then
|
||||
find /opt/rocprofiler-systems -type f
|
||||
fi
|
||||
}
|
||||
|
||||
test-stgz ${STGZ_FILE}
|
||||
test-deb ${DEB_FILE}
|
||||
test-rpm ${RPM_FILE}
|
||||
@@ -0,0 +1,56 @@
|
||||
#!/bin/bash
|
||||
|
||||
for i in $@
|
||||
do
|
||||
echo "##### Replacing LICENSE in ${i}... #####"
|
||||
rg -UF '// Copyright (c) 2018 Advanced Micro Devices, Inc. All Rights Reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// with the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimers.
|
||||
//
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimers in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// * Neither the names of Advanced Micro Devices, Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this Software without specific prior written permission.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
|
||||
// THE SOFTWARE.
|
||||
' -r '// MIT License
|
||||
//
|
||||
// Copyright (c) 2022 Advanced Micro Devices, Inc. All Rights Reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
' -N --color=never --passthru ${i} > tmp-replace
|
||||
mv tmp-replace ${i}
|
||||
done
|
||||
@@ -0,0 +1,76 @@
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
cmake_minimum_required(VERSION 3.18.4)
|
||||
|
||||
if(NOT DEFINED ROCPROFSYS_VERSION)
|
||||
file(READ "${CMAKE_CURRENT_LIST_DIR}/../VERSION" FULL_VERSION_STRING LIMIT_COUNT 1)
|
||||
string(REGEX REPLACE "(\n|\r)" "" FULL_VERSION_STRING "${FULL_VERSION_STRING}")
|
||||
string(
|
||||
REGEX REPLACE
|
||||
"([0-9]+)\.([0-9]+)\.([0-9]+)(.*)"
|
||||
"\\1.\\2.\\3"
|
||||
ROCPROFSYS_VERSION
|
||||
"${FULL_VERSION_STRING}"
|
||||
)
|
||||
endif()
|
||||
|
||||
find_package(Git)
|
||||
|
||||
if(Git_FOUND AND EXISTS ".git")
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} describe --tags
|
||||
OUTPUT_VARIABLE ROCPROFSYS_GIT_TAG
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
RESULT_VARIABLE _GIT_DESCRIBE_RESULT
|
||||
ERROR_QUIET
|
||||
)
|
||||
if(NOT _GIT_DESCRIBE_RESULT EQUAL 0)
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} describe
|
||||
OUTPUT_VARIABLE ROCPROFSYS_GIT_TAG
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
RESULT_VARIABLE _GIT_DESCRIBE_RESULT
|
||||
ERROR_QUIET
|
||||
)
|
||||
endif()
|
||||
else()
|
||||
message(
|
||||
STATUS
|
||||
"Git not found or .git directory not found; using version ${ROCPROFSYS_VERSION}"
|
||||
)
|
||||
set(GIT_DESCRIBE "v${ROCPROFSYS_VERSION}")
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED OUTPUT_DIR)
|
||||
set(OUTPUT_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
endif()
|
||||
|
||||
message(STATUS "Writing ${OUTPUT_DIR}/rocprofiler-systems-install.py.")
|
||||
message(STATUS "rocprofiler-systems version: ${ROCPROFSYS_VERSION}.")
|
||||
message(STATUS "rocprofiler-systems git describe: ${ROCPROFSYS_GIT_TAG}")
|
||||
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_LIST_DIR}/../cmake/Templates/rocprof-sys-install.py.in
|
||||
${OUTPUT_DIR}/rocprofiler-systems-install.py
|
||||
@ONLY
|
||||
)
|
||||
Reference in new issue
Block a user