Skip to content

Commit d2eaacc

Browse files
committed
[AOMP] Split aomp_utils out of aomp_common_vars
This patch splits aomp_utils (shell utility functions) out of aomp_common_vars, in preparation for adding lots more non-configuration-related stuff to the new file. This is mostly straightfoward, but build scripts, etc. need to source the new file also as well as aomp_common_vars.
1 parent 5948ec2 commit d2eaacc

File tree

86 files changed

+390
-302
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+390
-302
lines changed

bin/CBL_run_sollve.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export EFFLAGS="-ffree-form -ffree-line-length-none"
2121
# --- Start standard header to set AOMP environment variables ----
2222
realpath=`realpath $0`
2323
thisdir=`dirname $realpath`
24+
. "$thisdir/aomp_utils"
2425
. $thisdir/aomp_common_vars
2526
# --- end standard header ----
2627

bin/aomp_common_vars

Lines changed: 0 additions & 301 deletions
Original file line numberDiff line numberDiff line change
@@ -233,33 +233,6 @@ else
233233
fi
234234
fi
235235

236-
# Quote argument list suitable for passing as a single (string) argument to
237-
# cmake. Result can be used within a double-quoted string, i.e. using
238-
# "$(cmquot ...)".
239-
function cmquot() {
240-
local escaped_flags
241-
local escaped_flag
242-
local flag
243-
escaped_flags=()
244-
for flag in "$@"; do
245-
escaped_flag=$(printf "%s" "$flag" | sed 's/\\/\\\\/g; s/\$/\\$/g; s/ /\\ /g; s/"/\\"/g')
246-
escaped_flags+=("$escaped_flag")
247-
done
248-
echo "${escaped_flags[*]}"
249-
}
250-
251-
# Quote argument list suitable for passing back to the shell as a string.
252-
# Useful for e.g. dumping argument lists in such a way that they can be safely
253-
# copy & pasted into the user's terminal. Output should not be further quoted.
254-
function shquot() {
255-
local -a output
256-
output=()
257-
for arg in "$@"; do
258-
output+=(\'${arg//\'/\'\\\'\'}\')
259-
done
260-
printf '%s' "${output[*]}"
261-
}
262-
263236
# AOMP uses RPATH (not) RUNPATH because LD_LIBRARY_PATH is a user feature for
264237
# user lib development. We do not want the compiler runtime to search user paths
265238
# first because we want assurance to recreate reported compiler runtime fails.
@@ -559,277 +532,3 @@ if [ "$AOMP_BUILD_SANITIZER" == 1 ]; then
559532
fi
560533
fi
561534

562-
function check_writable_installdir() {
563-
local action=$1
564-
local installdir=$2
565-
566-
# Make sure we can update the install directory
567-
if [ "$action" == "install" ] ; then
568-
$SUDO mkdir -p "$installdir"
569-
570-
if ! $SUDO touch "$installdir/testfile"; then
571-
echo "ERROR: No update access to $installdir"
572-
exit 1
573-
fi
574-
$SUDO rm "$installdir/testfile"
575-
fi
576-
}
577-
578-
# TO use this function set variables patchdir and patchfile
579-
function patchrepo(){
580-
patchdir=$1
581-
if [ "$AOMP_APPLY_ROCM_PATCHES" == 1 ] && [ -d "$patchdir" ] ; then
582-
patches=""
583-
cd "$patchdir" || exit
584-
if [[ "$2" =~ "postinstall" ]]; then
585-
getpatchlist "$2"
586-
else
587-
getpatchlist
588-
fi
589-
590-
#loop through list of patches to apply
591-
if [ "$patches" != "" ] ; then
592-
patchloc=${AOMP_PATCH_CONTROL_FILE%/*}
593-
echo "patchloc=$patchloc"
594-
for patch in $patches; do
595-
patchfile=$patchloc/$patch
596-
if [ ! -f "$patchfile" ] ; then
597-
echo
598-
echo "ERROR: Patch $patchfile does not exist"
599-
echo " It is referenced in ${AOMP_PATCH_CONTROL_FILE}"
600-
exit 1
601-
fi
602-
603-
echo "Testing patch $patchfile to $patchdir"
604-
605-
applypatch="yes"
606-
if ! patch -p1 -t -N --dry-run <"$patchfile" >/dev/null; then
607-
applypatch="no"
608-
# Check to see if reverse patch applies cleanly
609-
if patch -p1 -R --dry-run -t <"$patchfile" >/dev/null; then
610-
echo "patch $patchfile was already applied to $patchdir"
611-
else
612-
echo
613-
echo "ERROR: Patch $patchfile will not apply"
614-
echo " cleanly to directory $patchdir"
615-
echo " Check if it was already applied."
616-
echo
617-
exit 1
618-
fi
619-
fi
620-
if [ "$applypatch" == "yes" ] ; then
621-
echo "Applying patch $patchfile to $patchdir"
622-
patch -p1 --no-backup-if-mismatch <"$patchfile"
623-
fi
624-
done
625-
fi
626-
fi
627-
628-
}
629-
630-
function removepatch(){
631-
patchdir=$1
632-
if [ "$AOMP_APPLY_ROCM_PATCHES" == 1 ] && [ -d "$patchdir" ] ; then
633-
patches=""
634-
cd "$patchdir" || exit
635-
getpatchlist
636-
if [ "$patches" != "" ] ; then
637-
echo "Patchdir $patchdir"
638-
echo "PATCHES TO REMOVE: $patches"
639-
fi
640-
patchloc=${AOMP_PATCH_CONTROL_FILE%/*}
641-
if [ "$patches" != "" ] ; then
642-
for patch in $patches; do
643-
patchfile=$patchloc/$patch
644-
echo "Testing reverse patch $patchfile to $patchdir"
645-
reversepatch="yes"
646-
# Check to see if reverse patch applies cleanly
647-
648-
if ! patch -p1 -R --dry-run -f <"$patchfile" >/dev/null; then
649-
echo "patch $patchfile was NOT applied $patchdir, no patch to reverse"
650-
reversepatch="no"
651-
fi
652-
if [ "$reversepatch" == "yes" ] ; then
653-
echo "Reversing patch $patchfile to $patchdir"
654-
patch -p1 -R -f --no-backup-if-mismatch <"$patchfile"
655-
fi
656-
done
657-
fi
658-
fi
659-
}
660-
661-
function getpatchlist(){
662-
currdir=$(pwd)
663-
basedir=$(basename "$currdir")
664-
if [[ "$1" =~ "postinstall" ]]; then
665-
reporegex="(^$1:\s)"
666-
else
667-
reporegex="(^$basedir:\s)"
668-
fi
669-
echo "FILE: $AOMP_PATCH_CONTROL_FILE"
670-
echo "regex $reporegex"
671-
#read patch control file and look for correct patches
672-
while read -r line; do
673-
if [[ "$line" =~ $reporegex ]]; then
674-
#remove basename from list of patches
675-
patches=${line/"${BASH_REMATCH[1]}"}
676-
echo "patches: $patches"
677-
break
678-
fi
679-
done < "$AOMP_PATCH_CONTROL_FILE"
680-
}
681-
682-
function setaompgpu (){
683-
if [[ -e "$AOMP/../../bin/rocm_agent_enumerator" ]]; then
684-
echo Set AOMP_GPU with ../.. rocm_agent_enumerator.
685-
detected_gpu=$("$AOMP"/../../bin/rocm_agent_enumerator | grep -m 1 -E 'gfx[^0]{1}.{2}')
686-
elif [[ -e "$AOMP/../bin/rocm_agent_enumerator" ]]; then
687-
echo Set AOMP_GPU with .. rocm_agent_enumerator.
688-
detected_gpu=$("$AOMP"/../bin/rocm_agent_enumerator | grep -m 1 -E 'gfx[^0]{1}.{2}')
689-
elif [[ "$AOMP" =~ "opt" ]]; then
690-
echo Set AOMP_GPU with rocm_agent_enumerator.
691-
detected_gpu=$("$AOMP"/../bin/rocm_agent_enumerator | grep -m 1 -E 'gfx[^0]{1}.{2}')
692-
else
693-
echo Set AOMP_GPU with rocm_agent_enumerator.
694-
if [ -a "$AOMP"/bin/rocm_agent_enumerator ]; then
695-
detected_gpu=$("$AOMP"/bin/rocm_agent_enumerator | grep -m 1 -E 'gfx[^0]{1}.{2}')
696-
elif [ -a "$AOMP"/bin/amdgpu-arch ]; then
697-
detected_gpu=$("$AOMP"/bin/amdgpu-arch)
698-
detected_gpu=$(echo "$detected_gpu" | awk '{print $1,$5}')
699-
detected_gpu=$(echo "$detected_gpu" | cut -d" " -f1) # pick first found
700-
elif [ -e "$AOMP"/../bin/mygpu ]; then
701-
detected_gpu=$("$AOMP"/../bin/mygpu)
702-
else
703-
echo "Error: in setaompgpu, could not find rocm_agent_enumerator"
704-
echo " Set AOMP_GPU, AOMP, or install ROCm"
705-
exit 1
706-
fi
707-
fi
708-
709-
AOMP_GPU=${AOMP_GPU:-$detected_gpu}
710-
export AOMP_GPU
711-
echo "AOMP_GPU = $AOMP_GPU"
712-
echo "AOMP = $AOMP"
713-
714-
if [ "$AOMP_GPU" == "" ] || [ "$AOMP_GPU" == "unknown" ]; then
715-
echo Error: AOMP_GPU not properly set...exiting.
716-
exit 1
717-
fi
718-
}
719-
720-
# GPUs which need HSA_XNACK=1 to be set for USM to work. The canonical place
721-
# this info is stored in these scripts is in test/Makefile.defs (SUPPORTS_USM).
722-
# We use a tiny custom makefile to extract the info.
723-
# Usage:
724-
# if gpu_needs_xnack_for_usm "$GPU"; then ...; fi
725-
726-
function gpu_needs_xnack_for_usm(){
727-
local needs_usm
728-
needs_usm=$(make -s -C "$thisdir"/../test -f USM_check.make GPU="$1")
729-
case "$needs_usm" in
730-
true)
731-
return 0
732-
;;
733-
false)
734-
return 1
735-
;;
736-
*)
737-
return 2
738-
;;
739-
esac
740-
}
741-
742-
# Return success (0) if ROCR_VISIBLE_DEVICES (or the first GPU if it is unset)
743-
# refers to an APU, as indicated by rocminfo returning
744-
# "Coherent Host Access: TRUE" for the device, else return failure (1).
745-
746-
function is_apu(){
747-
local device_num=${ROCR_VISIBLE_DEVICES:-0}
748-
local cha
749-
cha=$(ROCR_VISIBLE_DEVICES="$device_num" rocminfo | grep -m 1 -F "Coherent Host Access:")
750-
if [[ "$cha" =~ Coherent\ Host\ Access:[[:blank:]]+(TRUE|FALSE) ]]; then
751-
case "${BASH_REMATCH[1]}" in
752-
TRUE)
753-
return 0
754-
;;
755-
FALSE)
756-
return 1
757-
;;
758-
esac
759-
else
760-
# If we don't see the above pattern in rocminfo output, it's probably not
761-
# an APU.
762-
return 1
763-
fi
764-
}
765-
766-
function help_build_aomp(){
767-
/bin/cat 2>&1 <<"EOF"
768-
769-
The build scripts in this directory are used to build AOMP.
770-
771-
Repositories:
772-
Many repositories are used to build AOMP. The script clone_aomp.sh will
773-
clone all the necessary repositories as subdirectories of the directory
774-
$HOME/git/aomp11. The web repository locations and the required branches
775-
are set with the file aomp_common_vars
776-
777-
Build all components:
778-
To build all components, run these commands:
779-
780-
./clone_aomp.sh
781-
unset LD_LIBRARY_PATH
782-
./build_aomp.sh
783-
784-
Component builds:
785-
Developers can rebuild individual components by running the build script for
786-
that component. Make sure dependent components are built first. You can run
787-
build_aomp.sh to build call components in the correct order orsee the README.md
788-
file in this directory for the required order.
789-
790-
Each build script can run with no arguments or with a single argument
791-
"install" or "nocmake". Running with no options starts fresh with an empty
792-
component build directory. It then runs cmake with the correct cmake options
793-
then it runs make with a proper -j option.
794-
795-
Optional Arguments 'nocmake' and 'install' :
796-
The 'nocmake' or 'install' options can only be used after your initial build
797-
with no options. The 'nocmake' option is intended to restart make after
798-
you fix code following a failed build. The 'install' option will run 'make'
799-
and 'make install' causing installation into the directory $AOMP_INSTALL_DIR.
800-
The 'install' option will also create a symbolic link to directory $AOMP.
801-
802-
Environment Variables:
803-
You can set environment variables to override behavior of the build scripts
804-
NAME DEFAULT DESCRIPTION
805-
---- ------- -----------
806-
AOMP $HOME/rocm/aomp Where the compiler will be installed
807-
AOMP_REPOS $HOME/git/aomp11 Location of all aomp repos
808-
BUILD_TYPE Release The CMAKE build type
809-
BUILD_AOMP same as AOMP_REPOS Set a different build location than AOMP_REPOS
810-
AOMP_USE_NINJA 0 Use ninja if possible
811-
812-
To build a debug version of the compiler, run this command before the build:
813-
export BUILD_TYPE=debug
814-
815-
The BUILD_AOMP Envronment Variable:
816-
The build scripts will always build with cmake and make outside your source git trees.
817-
By default (without BUILD_AOMP) the build will occur in the "build" subdirectory of
818-
AOMP_REPOS. For example build_llvm will build in $AOMP_REPOS/build/llvm
819-
820-
The BUILD_AOMP environment variable enables source development outside your git
821-
repositories. By default, this feature is OFF. The BUILD_AOMP environment variable
822-
can be used if access to your git repositories is very slow or you want to test
823-
changes outside of your local git repositories (specified by AOMP_REPOS env var).
824-
If BUILD_AOMP is set, your git repositories (specifed by AOMP_REPOS) will be
825-
replicated to subdirectories of BUILD_AOMP using rsync. The subsequent build
826-
(cmake and make) will occur in subdirectory BUILD_AOMP/build/llvm.
827-
This replication only happens on your initial build, that is, if you specify no arguments.
828-
The option 'nocmake' skips replication and then restarts make in the build directory.
829-
The install option skips replication, skips cmake, runs 'make' and 'make install'.
830-
Be careful to always use options nocmake or install if you made local changes in
831-
BUILD_AOMP or your changes will be lost by a new replica of your git repositories.
832-
833-
EOF
834-
exit 0
835-
}

0 commit comments

Comments
 (0)