Skip to content

Commit a9a7c14

Browse files
committed
[AOMP] Taskification/control-flow inversion for scripts, part 1
This is an experimental patch to incrementally refactor the build scripts. The approach taken is particularly relevant to scripts which build multiple configurations of a component. There are several ideas here. Firstly, build scripts can be introspected so you can see what they are doing: $ ./build_offload.sh list_configs asan perf perf+asan debug debug+asan $ AOMP_BUILD_SANITIZER=0 ./build_offload.sh list_configs perf debug Build steps are split into different tasks, each of which is wrapped in a "task_foo" function (which is passed the configuration name): $ ./build_offload.sh list_tasks perf clean cmake build install You can list all tasks list this: $ ./build_offload.sh list task_precheck task_patch task_clean asan task_cmake asan task_build asan task_install asan task_clean perf task_cmake perf task_build perf task_install perf task_clean perf+asan task_cmake perf+asan task_build perf+asan task_install perf+asan task_clean debug task_cmake debug task_build debug task_install debug task_postinstall debug task_clean debug+asan task_cmake debug+asan task_build debug+asan task_install debug+asan task_unpatch Or e.g. see what will happen for different env var settings: $ AOMP_BUILD_DEBUG=0 ./build_offload.sh list task_precheck task_patch task_clean asan task_cmake asan task_build asan task_install asan task_clean perf task_cmake perf task_build perf task_install perf task_clean perf+asan task_cmake perf+asan task_build perf+asan task_install perf+asan task_unpatch You can still invoke the build scripts the same way as at present: $ ./build_offload.sh [...builds everything...] $ ./build_offload.sh cmake [...just runs cmake steps...] $ ./build_offload.sh nocmake [...just runs build steps...] $ ./build_offload.sh install [...just runs install steps...] Only the build_offload.sh script has been done so far, but this backward compatibility allows other scripts to be refactored in a similar way incrementally. The aim (not yet realised) is to then provide a new or alternate front-end (to build_aomp.sh) using exactly the same build scripts, allowing fine-grained control over which components to build/rebuild, and so on. Internally, the refactoring already done on build_offload.sh demonstrates very much deduplication, particularly around the setting of cmake options. Further work will allow much of the "boilerplate" in each of the build scripts to be replaced by a central implementation. Environment variables used to control the build are now read via two functions (get_config_var_string and get_config_var_bool). There are several reasons for this indirection: - It allows us to have a single location to check which environment variables are being used to control the build. - (For the alternate frontend) the options can be changed via e.g. command-line options instead of environment variables. - The _bool function emits the string 'true' or 'false'. This allows the use of: if $Result; then ... fi instead of if [ "$Result" -eq 1 ]; then ... fi which is shorter/somewhat easier to read. "Actions" (the emulated "nocmake", etc. options, and the new "list", etc. options) are implemented as functions named "do_{foo}", invoked by the new "command_dispatcher" function. There are a few other actions, e.g.: $ ./build_offload.sh show_build_dir perf /home/julbrown/git/aomp21.0/build/home/julbrown/git/aomp21.0/offload_perf These will be more useful once more scripts are "taskified".
1 parent d2eaacc commit a9a7c14

File tree

2 files changed

+603
-435
lines changed

2 files changed

+603
-435
lines changed

bin/aomp_utils

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,167 @@ function is_apu(){
233233
fi
234234
}
235235

236+
valid_config() {
237+
local thiscfg=$1
238+
local -a configs
239+
local oldlastpipe
240+
local cfg
241+
oldlastpipe="$(shopt -p lastpipe)"
242+
shopt -s lastpipe
243+
do_list_configs | mapfile -t configs
244+
for cfg in "${configs[@]}"; do
245+
if [ "$cfg" = "$thiscfg" ]; then
246+
eval "$oldlastpipe"
247+
return 0
248+
fi
249+
done
250+
eval "$oldlastpipe"
251+
return 1
252+
}
253+
254+
runcmd() {
255+
"$@"
256+
}
257+
258+
aomp_tasks_filtered() {
259+
local filter
260+
local cfg
261+
local task
262+
local cmd
263+
if [ "$1" = "--dryrun" ]; then
264+
cmd="echo"
265+
shift
266+
else
267+
cmd="runcmd"
268+
fi
269+
filter=$1
270+
do_list_init | while read -r initfn; do
271+
$cmd "task_${initfn}"
272+
done
273+
do_list_configs | while read -r cfg; do
274+
do_list_tasks "$cfg" | while read -r task; do
275+
if [[ "$task" =~ $filter ]]; then
276+
$cmd "task_${task}" "$cfg"
277+
fi
278+
done
279+
done
280+
do_list_fini | while read -r finifn; do
281+
$cmd "task_${finifn}"
282+
done
283+
}
284+
285+
get_config_var_string() {
286+
#local component=$1
287+
local -n _varname=$2
288+
case "$2" in
289+
BUILD_DIR)
290+
printf "%s/build" "$_varname"
291+
return
292+
;;
293+
LLVM_INSTALL_LOC|AOMP_PROC|CUDABIN|CUDAT|CUDAINCLUDE|REPO_DIR|\
294+
AOMP_NINJA_BIN|AOMP_JOB_THREADS|LLVM_PROJECT_ROOT)
295+
;;
296+
*)
297+
>&2 echo "Unknown string configuration variable '$2'"
298+
exit 1
299+
;;
300+
esac
301+
printf "%s" "$_varname"
302+
}
303+
304+
get_config_var_bool() {
305+
#local component=$1
306+
local -n _varname=$2
307+
case "$2" in
308+
AOMP_BUILD_CUDA|AOMP_APPLY_ATD_AMD_STAGING_PATCH|AOMP_USE_NINJA|\
309+
AOMP_STANDALONE_BUILD|SANITIZER|AOMP_LEGACY_OPENMP|AOMP_BUILD_SANITIZER|\
310+
AOMP_BUILD_PERF|AOMP_BUILD_DEBUG)
311+
;;
312+
*)
313+
>&2 echo "Unknown bool configuration variable '$2'"
314+
exit 1
315+
;;
316+
esac
317+
if [[ $_varname = 1 ]]; then
318+
echo "true"
319+
else
320+
echo "false"
321+
fi
322+
}
323+
324+
do_aomp_all() {
325+
aomp_tasks_filtered '.*'
326+
}
327+
328+
do_cmake() {
329+
aomp_tasks_filtered '^(clean|cmake)'
330+
}
331+
332+
do_nocmake() {
333+
aomp_tasks_filtered 'build'
334+
}
335+
336+
do_install() {
337+
aomp_tasks_filtered '^(install|postinstall)'
338+
}
339+
340+
do_show_src_dir() {
341+
if [ $# -eq 0 ]; then
342+
printf "%s\n" "$(get_src_dir)"
343+
else
344+
local WhichComp=$1
345+
"$thisdir/build_${WhichComp}.sh" show_src_dir
346+
fi
347+
}
348+
349+
do_show_build_dir() {
350+
local WhichComp
351+
local Cfg
352+
if [ $# -eq 1 ]; then
353+
Cfg=$1
354+
printf "%s\n" "$(get_build_dir "$Cfg")"
355+
elif [ $# -eq 2 ]; then
356+
WhichComp=$1
357+
Cfg=$2
358+
"$thisdir/build_${WhichComp}.sh" show_build_dir "$Cfg"
359+
else
360+
>&2 echo "Usage: show_build_dir [<component>] <cfg>"
361+
exit 1
362+
fi
363+
}
364+
365+
do_show_install_dir() {
366+
local WhichComp
367+
local Cfg
368+
if [ $# -eq 1 ]; then
369+
Cfg=$1
370+
printf "%s\n" "$(get_install_dir "$Cfg")"
371+
elif [ $# -eq 2 ]; then
372+
WhichComp=$1
373+
Cfg=$2
374+
"$thisdir/build_${WhichComp}.sh" show_install_dir "$Cfg"
375+
else
376+
>&2 echo "Usage: show_install_dir [<component>] <cfg>"
377+
exit 1
378+
fi
379+
}
380+
381+
do_list() {
382+
aomp_tasks_filtered --dryrun '.*'
383+
}
384+
385+
command_dispatcher() {
386+
local _proc
387+
_proc=$1
388+
if [ "$_proc" ]; then
389+
shift
390+
"do_${_proc}" "$@"
391+
else
392+
shift
393+
do_aomp_all "$@"
394+
fi
395+
}
396+
236397
function help_build_aomp(){
237398
/bin/cat 2>&1 <<"EOF"
238399

0 commit comments

Comments
 (0)