Skip to content

Commit 3891f85

Browse files
deeppatAWSwinefred
authored andcommitted
Add mem check to build script (#329)
* Moved mem check to build script * Standardizing output
1 parent 86a8f9d commit 3891f85

File tree

3 files changed

+101
-65
lines changed

3 files changed

+101
-65
lines changed

hdk/common/shell_v04151701/build/scripts/aws_build_dcp_from_cl.sh

Lines changed: 62 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,32 @@ vivado_script="create_dcp_from_cl.tcl"
4242
foreground=0
4343
run_aws_emulation=0
4444
notify=0
45+
ignore_memory_requirement=0
46+
expected_memory_usage=30000000
47+
48+
function info_msg {
49+
echo -e "INFO: $1"
50+
}
51+
52+
function debug_msg {
53+
if [[ $debug == 0 ]]; then
54+
return
55+
fi
56+
echo -e "DEBUG: $1"
57+
}
58+
59+
function warn_msg {
60+
echo -e "WARNING: $1"
61+
}
62+
63+
function err_msg {
64+
echo -e >&2 "ERROR: $1"
65+
}
66+
67+
function get_instance_memory {
68+
local mem=$(awk -F"[: ]+" '/MemTotal/ {print $2;exit}' /proc/meminfo)
69+
echo "$mem"
70+
}
4571

4672
# Parse command-line arguments
4773
while [ "$1" != "" ]; do
@@ -67,6 +93,8 @@ while [ "$1" != "" ]; do
6793
;;
6894
-notify ) notify=1
6995
;;
96+
-ignore_memory_requirement) ignore_memory_requirement=1
97+
;;
7098
-h | -H | -help ) usage
7199
exit
72100
;;
@@ -78,66 +106,79 @@ done
78106

79107
# Check that script exists
80108
if ! [ -f "$vivado_script" ]; then
81-
echo "ERROR: $vivado_script doesn't exist."
109+
err_msg "$vivado_script doesn't exist."
82110
exit 1
83111
fi
84112

85113
# Check that strategy is valid
86114
shopt -s extglob
87115
if [[ $strategy != @(BASIC|DEFAULT|EXPLORE|TIMING|CONGESTION) ]]; then
88-
echo "ERROR: $strategy isn't a valid strategy. Valid strategies are BASIC, DEFAULT, EXPLORE, TIMING and CONGESTION."
116+
err_msg "$strategy isn't a valid strategy. Valid strategies are BASIC, DEFAULT, EXPLORE, TIMING and CONGESTION."
89117
exit 1
90118
fi
91119

92120
# Check that clock_recipe_a is valid
93121
shopt -s extglob
94122
if [[ $clock_recipe_a != @(A0|A1|A2) ]]; then
95-
echo "ERROR: $clock_recipe_a isn't a valid Clock Group A recipe. Valid Clock Group A recipes are A0, A1, and A2."
123+
err_msg "$clock_recipe_a isn't a valid Clock Group A recipe. Valid Clock Group A recipes are A0, A1, and A2."
96124
exit 1
97125
fi
98126

99127
# Check that clock_recipe_b is valid
100128
shopt -s extglob
101129
if [[ $clock_recipe_b != @(B0|B1) ]]; then
102-
echo "ERROR: $clock_recipe_b isn't a valid Clock Group B recipe. Valid Clock Group B recipes are B0 and B1."
130+
err_msg "$clock_recipe_b isn't a valid Clock Group B recipe. Valid Clock Group B recipes are B0 and B1."
103131
exit 1
104132
fi
105133

106134
# Check that clock_recipe_c is valid
107135
shopt -s extglob
108136
if [[ $clock_recipe_c != @(C0|C1) ]]; then
109-
echo "ERROR: $clock_recipe_c isn't a valid Clock Group C recipe. Valid Clock Group C recipes are C0 and C1."
137+
err_msg "$clock_recipe_c isn't a valid Clock Group C recipe. Valid Clock Group C recipes are C0 and C1."
110138
exit 1
111139
fi
112140

113-
echo "AWS FPGA: Starting the design checkpoint build process"
114-
echo "AWS FPGA: Checking for proper environment variables and build directories"
141+
if [ $expected_memory_usage -gt `get_instance_memory` ]; then
142+
143+
output_message="YOUR INSTANCE has less memory than is necessary for certain builds. This means that your builds will take longer than expected. \nTo change to an instance type with more memory, please check our instance resize guide: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-resize.html"
144+
145+
if [[ $ignore_memory_requirement == 0 ]]; then
146+
err_msg "$output_message"
147+
err_msg "To ignore this memory requirement, source hdk_setup.sh again with -ignore_memory_requirement as an argument."
148+
exit 1
149+
else
150+
warn_msg "$output_message"
151+
fi
152+
fi
153+
154+
info_msg "Starting the design checkpoint build process"
155+
info_msg "Checking for proper environment variables and build directories"
115156

116157
if ! [ $HDK_SHELL_DIR ]
117158
then
118-
echo "ERROR: HDK_SHELL_DIR environment variable is not set, try running hdk_setup.sh script from the root directory of AWS FPGA repository."
159+
err_msg "HDK_SHELL_DIR environment variable is not set, try running hdk_setup.sh script from the root directory of AWS FPGA repository."
119160
exit 1
120161
fi
121162

122163
if ! [ $CL_DIR ]
123164
then
124-
echo "ERROR: CL_DIR environment variable is not set. Set CL_DIR to a valid directory."
165+
err_msg "CL_DIR environment variable is not set. Set CL_DIR to a valid directory."
125166
exit 1
126167
fi
127168

128169
if ! [ $HDK_DIR ]
129170
then
130-
echo "ERROR: HDK_DIR environment variable is not set, try running hdk_setup.sh script from the root directory of AWS FPGA repository."
171+
err_msg "HDK_DIR environment variable is not set, try running hdk_setup.sh script from the root directory of AWS FPGA repository."
131172
exit 1
132173
fi
133174

134175
if ! [ -x $HDK_SHELL_DIR/build/scripts/prepare_build_environment.sh ]
135176
then
136-
echo "prepare_build_env.sh script is not eXecutable, trying to apply chmod +x"
177+
info_msg "prepare_build_env.sh script is not eXecutable, trying to apply chmod +x"
137178
chmod +x $HDK_SHELL_DIR/build/scripts/prepare_build_environment.sh
138179
if ! [ -x $HDK_SHELL_DIR/build/scripts/prepare_build_environment.sh ]
139180
then
140-
echo "ERROR: Failed to change prepare_build_environment.sh to eXecutable, aborting!"
181+
err_msg "Failed to change prepare_build_environment.sh to eXecutable, aborting!"
141182
exit 1
142183
fi
143184
fi
@@ -146,18 +187,18 @@ $HDK_SHELL_DIR/build/scripts/prepare_build_environment.sh
146187

147188
if ! [[ $? -eq 0 ]]
148189
then
149-
echo "ERROR: Missing environment variable or unable to create the needed build directories, aborting!"
190+
err_msg "Missing environment variable or unable to create the needed build directories, aborting!"
150191
exit 1
151192
fi
152193

153194
# Use timestamp for logs and output files
154195
timestamp=$(date +"%y_%m_%d-%H%M%S")
155196
logname=$timestamp.vivado.log
156197

157-
echo "AWS FPGA: Environment variables and directories are present. Checking for Vivado installation."
198+
info_msg "Environment variables and directories are present. Checking for Vivado installation."
158199

159200
# Before going too far make sure Vivado is available
160-
vivado -version >/dev/null 2>&1 || { echo >&2 "ERROR - Please install/enable Vivado." ; return 1; }
201+
vivado -version >/dev/null 2>&1 || { err_msg "Please install/enable Vivado." ; return 1; }
161202

162203
# Get the HDK Version
163204
hdk_version=$(grep 'HDK_VERSION' $HDK_DIR/hdk_version.txt | sed 's/=/ /g' | awk '{print $2}')
@@ -180,12 +221,12 @@ cmd="vivado -mode batch -nojournal -log $logname -source $vivado_script -tclargs
180221
if [[ "$foreground" == "0" ]]; then
181222
nohup $cmd > $timestamp.nohup.out 2>&1 &
182223

183-
echo "AWS FPGA: Build through Vivado is running as background process, this may take few hours."
184-
echo "AWS FPGA: Output is being redirected to $timestamp.nohup.out"
185-
echo "AWS FPGA: If you have set your EMAIL environment variable and -notify is specified, you will receive a notification when complete."
186-
echo "AWS FPGA: (See \$HDK_DIR/cl/examples/README.md for details)"
224+
info_msg "Build through Vivado is running as background process, this may take few hours."
225+
info_msg "Output is being redirected to $timestamp.nohup.out"
226+
info_msg "If you have set your EMAIL environment variable and -notify is specified, you will receive a notification when complete."
227+
info_msg " (See \$HDK_DIR/cl/examples/README.md for details)"
187228
else
188-
echo "AWS FPGA: Build through Vivado is running in the foreground, this may take a few hours."
189-
echo "AWS FPGA: The build may be terminated if the network connection to this terminal window is lost."
229+
info_msg "Build through Vivado is running in the foreground, this may take a few hours."
230+
info_msg "The build may be terminated if the network connection to this terminal window is lost."
190231
$cmd
191232
fi

hdk/common/shell_v04151701/build/scripts/prepare_build_environment.sh

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,67 +15,86 @@
1515
# implied. See the License for the specific language governing permissions and
1616
# limitations under the License.
1717

18+
function info_msg {
19+
echo -e "INFO: $1"
20+
}
21+
22+
function debug_msg {
23+
if [[ $debug == 0 ]]; then
24+
return
25+
fi
26+
echo -e "DEBUG: $1"
27+
}
28+
29+
function warn_msg {
30+
echo -e "WARNING: $1"
31+
}
32+
33+
function err_msg {
34+
echo -e >&2 "ERROR: $1"
35+
}
36+
1837
if ! [[ $CL_DIR ]]
1938
then
20-
echo "ERROR: Environment variable CL_DIR is not defined"
39+
err_msg "Environment variable CL_DIR is not defined"
2140
exit 1
2241
fi
2342

2443
if ! [[ $HDK_SHELL_DIR ]]
2544
then
26-
echo "ERROR: Environment variable HDK_SHELL_DIR is not defined"
45+
err_msg "Environment variable HDK_SHELL_DIR is not defined"
2746
exit 1
2847
fi
2948

3049
if ! [ -d $CL_DIR/build/constraints ]
3150
then
32-
echo "ERROR: Constraints directory is not found in $CL_DIR/build/ directory"
51+
err_msg "Constraints directory is not found in $CL_DIR/build/ directory"
3352
exit 1
3453
fi
3554

3655
if ! [ -d $CL_DIR/build/reports ]
3756
then
38-
echo "Creating the reports directory"
57+
info_msg "Creating the reports directory"
3958
mkdir $CL_DIR/build/reports
4059
if ! [ -d $CL_DIR/build/reports ]
4160
then
42-
echo "ERROR: Failed to create reports directory, please check directory permissions"
61+
err_msg "Failed to create reports directory, please check directory permissions"
4362
exit 1
4463
fi
4564
fi
4665

4766

4867
if ! [ -d $CL_DIR/build/checkpoints ]
4968
then
50-
echo "Creating the checkpointss directory"
69+
info_msg "Creating the checkpoints directory"
5170
mkdir $CL_DIR/build/checkpoints
5271
if ! [ -d $CL_DIR/build/checkpoints ]
5372
then
54-
echo "ERROR: Failed to create checkpoints directory, please check directory permissions"
73+
err_msg "Failed to create checkpoints directory, please check directory permissions"
5574
exit 1
5675
fi
5776
fi
5877

5978

6079
if ! [ -d $CL_DIR/build/checkpoints/to_aws ]
6180
then
62-
echo "Creating the checkpoints\/to_aws directory"
81+
info_msg "Creating the checkpoints/to_aws directory"
6382
mkdir $CL_DIR/build/checkpoints/to_aws
6483
if ! [ -d $CL_DIR/build/checkpoints/to_aws ]
6584
then
66-
echo "ERROR: Failed to create directory, please check directory permissions"
85+
err_msg "Failed to create directory, please check directory permissions"
6786
exit 1
6887
fi
6988
fi
7089

7190

7291
if ! [ -d $CL_DIR/build/src_post_encryption ]
7392
then
74-
echo "Creating the src_port_encryption directory"
93+
info_msg "Creating the src_port_encryption directory"
7594
mkdir $CL_DIR/build/src_post_encryption
7695
if ! [ -d $CL_DIR/build/src_post_encryption ]
7796
then
78-
echo "ERROR: Failed to create directory, please check directory permissions"
97+
err_msg "Failed to create directory, please check directory permissions"
7998
exit 1
8099
fi
81100
fi

hdk_setup.sh

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# Amazon FGPA Hardware Development Kit
2-
#
1+
# Amazon FPGA Hardware Development Kit
2+
#
33
# Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4-
#
4+
#
55
# Licensed under the Amazon Software License (the "License"). You may not use
66
# this file except in compliance with the License. A copy of the License is
77
# located at
8-
#
8+
#
99
# http://aws.amazon.com/asl/
10-
#
10+
#
1111
# or in the "license" file accompanying this file. This file is distributed on
1212
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or
1313
# implied. See the License for the specific language governing permissions and
@@ -28,26 +28,24 @@ script_name=$(basename $full_script)
2828
script_dir=$(dirname $full_script)
2929

3030
debug=0
31-
ignore_memory_requirement=0
32-
expected_memory_usage=30000000
3331

3432
function info_msg {
35-
echo -e "AWS FPGA-INFO: $1"
33+
echo -e "INFO: $1"
3634
}
3735

3836
function debug_msg {
3937
if [[ $debug == 0 ]]; then
4038
return
4139
fi
42-
echo -e "AWS FPGA-DEBUG: $1"
40+
echo -e "DEBUG: $1"
4341
}
4442

4543
function warn_msg {
46-
echo -e "AWS FPGA-WARNING: $1"
44+
echo -e "WARNING: $1"
4745
}
4846

4947
function err_msg {
50-
echo -e >&2 "AWS FPGA-ERROR: $1"
48+
echo -e >&2 "ERROR: $1"
5149
}
5250

5351
function usage {
@@ -68,11 +66,6 @@ function help {
6866
usage
6967
}
7068

71-
function get_instance_memory {
72-
local mem=$(awk -F"[: ]+" '/MemTotal/ {print $2;exit}' /proc/meminfo)
73-
echo "$mem"
74-
}
75-
7669
# Process command line args
7770
args=( "$@" )
7871
for (( i = 0; i < ${#args[@]}; i++ )); do
@@ -85,10 +78,6 @@ for (( i = 0; i < ${#args[@]}; i++ )); do
8578
help
8679
return 0
8780
;;
88-
-ignore_memory_requirement)
89-
info_msg "Ignoring the instance memory requirement."
90-
ignore_memory_requirement=1
91-
;;
9281
*)
9382
err_msg "Invalid option: $arg\n"
9483
usage
@@ -107,19 +96,6 @@ else
10796
debug_msg "AWS_FPGA_REPO_DIR=$AWS_FPGA_REPO_DIR"
10897
fi
10998

110-
if [ $expected_memory_usage -gt `get_instance_memory` ]; then
111-
112-
output_message="YOUR INSTANCE has less memory than is necessary for certain builds. This means that your builds will take longer than expected. \nTo change to an instance type with more memory, please check our instance resize guide: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-resize.html"
113-
114-
if [[ $ignore_memory_requirement == 0 ]]; then
115-
err_msg "$output_message"
116-
err_msg "To ignore this memory requirement, source hdk_setup.sh again with -ignore_memory_requirement as an argument."
117-
return 2
118-
else
119-
warn_msg "$output_message"
120-
fi
121-
fi
122-
12399
debug_msg "Checking for Vivado install:"
124100

125101
# On the FPGA Developer AMI use module load to use the correct version of Vivado

0 commit comments

Comments
 (0)