Skip to content

Commit c846dc4

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 a05cf63 commit c846dc4

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.
@@ -548,277 +521,3 @@ if [ "$AOMP_BUILD_SANITIZER" == 1 ]; then
548521
fi
549522
fi
550523

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

0 commit comments

Comments
 (0)