OpenFPGA/openfpga.sh

163 lines
5.4 KiB
Bash
Raw Normal View History

2019-11-16 14:19:00 -06:00
#!/bin/bash
#title : openfpga.sh
#description : This script provides shortcut commands <bash functions>
# for several simple operations in OpenFPGA project
#author : Ganesh Gore <ganesh.gore@utah.edu>
#==============================================================================
2021-02-08 15:07:01 -06:00
if [ -z $OPENFPGA_PATH ]; then
echo "OPENFPGA_PATH variable not found"
export OPENFPGA_PATH=$(pwd);
echo "Setting OPENFPGA_PATH=${OPENFPGA_PATH}"
else
echo "OPENFPGA_PATH=${OPENFPGA_PATH}"
fi
2021-02-07 23:35:13 -06:00
export OPENFPGA_SCRIPT_PATH="${OPENFPGA_PATH}/openfpga_flow/scripts"
export OPENFPGA_TASK_PATH="${OPENFPGA_PATH}/openfpga_flow/tasks"
2019-11-16 16:52:32 -06:00
if [ -z $PYTHON_EXEC ]; then export PYTHON_EXEC="python3"; fi
2019-11-16 14:19:00 -06:00
# This function checks the path and
# raises warning if the command is not executing
# inside current OpendFPGA folder
check_execution_path (){
if [[ $1 != *"${OPENFPGA_PATH}"* ]]; then
2021-10-11 08:52:31 -05:00
echo -e "\e[33mCommand is not executed from configured OPENFPGA directory\e[0m"
2019-11-16 14:19:00 -06:00
fi
}
run-task-with-modelsim () {
2020-09-23 15:06:33 -05:00
echo "Script as to be run as \"run-task-with-modelsim task_name --maxthreads nb_threads other_run-modelsim_options\""
$PYTHON_EXEC $OPENFPGA_SCRIPT_PATH/run_fpga_task.py $1 $2 $3
$PYTHON_EXEC $OPENFPGA_SCRIPT_PATH/run_modelsim.py "$@"
}
2022-05-02 11:42:33 -05:00
create-task () {
if [ -z $1 ]; then
echo "requires task name create-task <task_name>"
return
fi
if [ -d $1 ]; then
echo "Task $1 already exists"
return
fi
2022-05-03 15:03:52 -05:00
template="template_tasks/yosys_vpr_template"
2023-02-11 19:24:20 -06:00
if [ ${#2} -ge 1 ]; then
2023-02-12 12:50:11 -06:00
if [[ "$2" == "fabric_netlist_gen" ]]; then template="template_tasks/${2}_template/";
elif [[ "$2" == "fabric_verification" ]]; then template="template_tasks/${2}_template/";
elif [[ "$2" == "frac-lut-arch-explore" ]]; then template="template_tasks/${2}_template/";
2023-02-11 19:24:20 -06:00
elif [[ "$2" == "vtr_benchmarks" ]]; then template="template_tasks/${2}_template/";
else template="$2"
2022-05-03 15:03:52 -05:00
fi
fi
2023-02-11 19:24:20 -06:00
if [ ! -f $OPENFPGA_PATH/openfpga_flow/tasks/${template}/config/task.conf ]; then
echo "Template project [${template}] does not exist" ; return;
2022-05-03 15:03:52 -05:00
fi
echo "Creating task $1"
echo "Template project ${template}"
2022-05-02 13:46:07 -05:00
mkdir -p $1
2022-05-03 15:03:52 -05:00
cp -r $OPENFPGA_PATH/openfpga_flow/tasks/${template}/* $1/
2022-05-02 11:42:33 -05:00
}
2023-02-11 19:24:20 -06:00
rerun-task () {
$PYTHON_EXEC $OPENFPGA_SCRIPT_PATH/run_fpga_task.py "$@" --remove_run_dir all
$PYTHON_EXEC $OPENFPGA_SCRIPT_PATH/run_fpga_task.py "$@"
}
2019-11-16 16:52:32 -06:00
run-task () {
$PYTHON_EXEC $OPENFPGA_SCRIPT_PATH/run_fpga_task.py "$@"
}
2021-02-03 11:34:34 -06:00
clean-run () {
rm -rf ./openfpga_flow/**/run???
}
2022-05-22 00:28:45 -05:00
clear-task-run () {
2023-02-11 19:24:20 -06:00
$PYTHON_EXEC $OPENFPGA_SCRIPT_PATH/run_fpga_task.py "$@" --remove_run_dir all
}
2019-11-16 20:10:04 -06:00
run-modelsim () {
$PYTHON_EXEC $OPENFPGA_SCRIPT_PATH/run_modelsim.py "$@"
}
2019-11-16 16:52:32 -06:00
run-flow () {
$PYTHON_EXEC $OPENFPGA_SCRIPT_PATH/run_fpga_flow.py "$@"
}
2019-11-16 14:19:00 -06:00
# lists all the configure task in task directory
list-tasks () {
2022-05-05 11:14:53 -05:00
echo "Repository Task"
tree -P 'task.conf' --prune $OPENFPGA_TASK_PATH | sed "/.* task.conf/d" | sed "/.* config/d" | sed '$d'
echo "Local Task"
2021-02-07 23:35:13 -06:00
tree -P 'task.conf' --prune | sed "/.* task.conf/d" | sed "/.* config/d" | sed '$d'
2019-11-16 14:19:00 -06:00
}
# Switch directory to root of OpenFPGA
goto-root () {
cd $OPENFPGA_PATH
}
2021-02-03 11:34:34 -06:00
# Run regression test locally
run-regression-local () {
cd ${OPENFPGA_PATH}
bash .github/workflows/*reg_test.sh
}
2019-11-16 14:19:00 -06:00
# Changes directory to task directory [goto_task <task_name> <run_num[default 0]>]
goto-task () {
if [ -z $1 ]; then
echo "requires task name goto_task <task_name> <run_num[default 0]>"
return
fi
goto_path=$OPENFPGA_TASK_PATH/$1
2022-05-05 11:14:53 -05:00
if [ -d $1 ]; then goto_path=./$1; fi
echo $goto_path
2021-02-03 11:34:34 -06:00
# Selects the run directory
2019-11-16 16:52:32 -06:00
run_num=""
2019-11-16 14:19:00 -06:00
if [ ! -d $goto_path ]; then echo "Task directory not found"; return; fi
2019-11-16 16:52:32 -06:00
if [[ "$2" =~ '^[0-9]+$' ]] ; then
if ! [[ $2 == '0' ]] ; then run_num="$(printf run%03d $2)"; else run_num="latest"; fi
if [ ! -d "$goto_path/$run_num" ]; then run_num="latest"; fi
2019-11-16 14:19:00 -06:00
fi
if [ ! -d $goto_path/$run_num ]; then
2019-11-16 16:52:32 -06:00
echo "\e[33mTask run directory not found -" $goto_path/$run_num "\e[0m"
2019-11-16 14:19:00 -06:00
else
2019-11-16 16:52:32 -06:00
echo "Switching current dirctory to" $goto_path/$run_num
2019-11-16 14:19:00 -06:00
cd $goto_path/$run_num
fi
2021-02-03 11:34:34 -06:00
# Selects benchmark directory
select benchRun in $(ls -d **/arch | sed "s/\/arch//" | head -n 20)
do
[ -d ${benchRun} ] && cd ${benchRun}
break
done
2019-11-16 14:19:00 -06:00
}
# Clears enviroment variables and fucntions
2019-11-16 16:52:32 -06:00
unset-openfpga (){
2019-11-16 14:19:00 -06:00
unset -v OPENFPGA_PATH
2019-11-16 16:52:32 -06:00
unset -f list-tasks run-task run-flow goto-task goto-root >/dev/null 2>&1
}
# Allow autocompletion of task
if [[ $(ps -p $$ -oargs=) == *"zsh"* ]]; then
autoload -U +X bashcompinit; bashcompinit;
fi
2021-02-08 15:07:01 -06:00
command -v shopt && shopt -s globstar
2021-02-07 23:35:13 -06:00
# TaskList=$(ls -tdalh ${OPENFPGA_TASK_PATH}/* | awk '{system("basename " $9)}' | awk '{printf("%s ",$1)}')
2022-05-05 11:14:53 -05:00
RepoTaskList=$(ls -tdalh ${OPENFPGA_TASK_PATH}/**/task.conf |
2021-02-07 23:35:13 -06:00
awk '{print $9}' | sed -e "s/\/config\/task.conf//" |
sed -e "s/${OPENFPGA_PATH//\//\\/}\/openfpga_flow\/tasks\///" |
awk '{printf("%s ",$1)}')
2022-05-05 11:14:53 -05:00
_TaskList()
{
local cur
COMPREPLY+=($( ls -R ./*/*/task.conf | sed -e "s/\/config\/task.conf//" | sed -e "s/^\.\///" | awk '{printf("%s ",$1)}' ) )
}
complete -W "${RepoTaskList}" -F _TaskList goto-task
complete -W "${RepoTaskList}" -F _TaskList run-task
complete -W "${RepoTaskList}" -F _TaskList run-modelsim
complete -W "${RepoTaskList}" create-task