Skip to content
This repository was archived by the owner on Dec 1, 2021. It is now read-only.

Commit 73127a9

Browse files
committed
Time measurement support on build. (#319)
-Extra optional option added to blueoil.sh. -Added timing as a default for lm_* targets . -CXXFLAGS now specified via make argument, rather than environment. -Timing can now optionally be built-in for lib_* targets as well.
1 parent 4456f1c commit 73127a9

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

blueoil.sh

+9-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function usage_exit(){
55
echo "Usage"
66
echo "${NAME} init"
77
echo "${NAME} train <YML_CONFIG_FILE> <OUTPUT_DIRECTORY(optional)> <EXPERIMENT_ID(optional)>"
8-
echo "${NAME} convert <YML_CONFIG_FILE> <EXPERIMENT_DIRECTORY> <CHECKPOINT_NO(optional)>"
8+
echo "${NAME} convert <YML_CONFIG_FILE> <EXPERIMENT_DIRECTORY> <CHECKPOINT_NO(optional)> <TIMING_ENABLE(optional)>"
99
echo "${NAME} predict <YML_CONFIG_FILE> <INPUT_DIRECTORY> <OUTPUT_DIRECTORY> <EXPERIMENT_DIRECTORY> <CHECKPOINT_NO(optional)>"
1010
echo "${NAME} tensorboard <EXPERIMENT_DIRECTORY> <PORT(optional)>"
1111
echo ""
@@ -170,6 +170,7 @@ function set_variables_for_restore(){
170170
OUTPUT_DIR=$(dirname ${EXPERIMENT_DIR})
171171
EXPERIMENT_ID=$(basename ${EXPERIMENT_DIR})
172172
CHECKPOINT_NO=${3:-0}
173+
TIME_FLAG=${4:-0}
173174
set_lmnet_docker_options
174175

175176
if [ ${CHECKPOINT_NO} -gt 0 ]; then
@@ -178,15 +179,18 @@ function set_variables_for_restore(){
178179
error_exit 1 "Invalid number of checkpoint, there is no checkpoints ${OUTPUT_DIR}/${EXPERIMENT_ID}/checkpoints/save.ckpt-${CHECKPOINT_NO}"
179180
fi
180181
fi
182+
if [ ${TIME_FLAG} -gt 0 ]; then
183+
TIMING_ENABLE="--timing"
184+
fi
181185
}
182186

183187
function blueoil_convert(){
184-
set_variables_for_restore $1 $2 $3
188+
set_variables_for_restore $1 $2 $3 $4
185189

186190
echo "#### Generate output files ####"
187191

188192
docker run ${LMNET_DOCKER_OPTIONS} ${DOCKER_IMAGE} \
189-
python blueoil/blueoil_convert.py -i ${EXPERIMENT_ID} ${RESTORE_OPTION}
193+
python blueoil/blueoil_convert.py -i ${EXPERIMENT_ID} ${RESTORE_OPTION} ${TIMING_ENABLE}
190194
error_exit $? "Failed to generate output files"
191195

192196
# Set path for DLK
@@ -253,9 +257,9 @@ case "$1" in
253257
exit 0;;
254258
"convert" )
255259
check_num_args $# -lt 3
256-
check_num_args $# -gt 4
260+
check_num_args $# -gt 5
257261
check_files_and_directories $2 $3
258-
blueoil_convert $2 $3 $4
262+
blueoil_convert $2 $3 $4 $5
259263
exit 0;;
260264
"predict" )
261265
check_num_args $# -lt 5

blueoil/blueoil_convert.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,20 @@ def make_all(project_dir, output_dir):
9292

9393
# Make each target and move output files
9494
for target, output in make_list:
95-
if target in ["lm_x86", "lm_arm", "lm_fpga", "lm_aarch64"]:
96-
os.environ["CXXFLAGS"] = cxxflags_cache + " -DFUNC_TIME_MEASUREMENT"
97-
else:
98-
os.environ["CXXFLAGS"] = cxxflags_cache
95+
if target in ["lib_x86", "lib_arm", "lib_fpga", "lib_aarch64"] and timing:
96+
cxxflags_cache += " -DFUNC_TIME_MEASUREMENT"
9997

98+
cxxflags = "CXXFLAGS=\"{}\"".format(cxxflags_cache)
10099
subprocess.run(("make", "clean", "--quiet"))
101-
subprocess.run(("make", target, "-j4", "--quiet"))
100+
subprocess.run(("make", target, cxxflags, "-j4", "--quiet"))
102101
strip_binary(output)
103102
output_file_path = os.path.join(output_dir, output)
104103
os.rename(output, output_file_path)
105104
# Return running directory
106105
os.chdir(running_dir)
107106

108107

109-
def run(experiment_id, restore_path, output_template_dir=None):
108+
def run(experiment_id, restore_path, timing, output_template_dir=None):
110109
"""Convert from trained model.
111110
112111
Returns:
@@ -148,7 +147,7 @@ def run(experiment_id, restore_path, output_template_dir=None):
148147
# Make
149148
project_dir_name = "{}.prj".format(project_name)
150149
project_dir = os.path.join(dest_dir_path, project_dir_name)
151-
make_all(project_dir, output_directories.get("library_dir"))
150+
make_all(project_dir, output_directories.get("library_dir"), timing)
152151

153152
return output_root_dir
154153

@@ -165,8 +164,14 @@ def run(experiment_id, restore_path, output_template_dir=None):
165164
help="restore ckpt file base path. e.g. saved/experiment/checkpoints/save.ckpt-10001",
166165
default=None,
167166
)
168-
def main(experiment_id, restore_path):
169-
run(experiment_id, restore_path)
167+
@click.option(
168+
"-t",
169+
"--timing",
170+
help="enable operation time measurements",
171+
is_flag=True,
172+
)
173+
def main(experiment_id, restore_path, timing):
174+
run(experiment_id, restore_path, timing)
170175

171176

172177
if __name__ == '__main__':

dlk/python/dlk/templates/Makefile.tpl

+3-3
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,15 @@ clean:
129129
-$(RM) $(OBJ)
130130

131131
lm_x86: CXX = g++
132-
lm_x86: FLAGS += $(INCLUDES) -O3 -std=c++14 -DUSE_PNG -pthread -g
132+
lm_x86: FLAGS += $(INCLUDES) -O3 -std=c++14 -DUSE_PNG -pthread -g -DFUNC_TIME_MEASUREMENT
133133
lm_x86: CXXFLAGS +=
134134

135135
lm_aarch64: CXX = aarch64-linux-gnu-g++
136-
lm_aarch64: FLAGS += $(INCLUDES) -std=c++14 -O3 -DUSE_PNG -pthread -g -fopenmp
136+
lm_aarch64: FLAGS += $(INCLUDES) -std=c++14 -O3 -DUSE_PNG -pthread -g -fopenmp -DFUNC_TIME_MEASUREMENT
137137
lm_aarch64: CXXFLAGS +=
138138

139139
lm_arm: CXX = arm-linux-gnueabihf-g++
140-
lm_arm: FLAGS += $(INCLUDES) -std=c++14 -O3 -DUSE_NEON -DUSE_PNG -mcpu=cortex-a9 -mfpu=neon -mthumb -s -pthread -g -fopenmp
140+
lm_arm: FLAGS += $(INCLUDES) -std=c++14 -O3 -DUSE_NEON -DUSE_PNG -mcpu=cortex-a9 -mfpu=neon -mthumb -s -pthread -g -fopenmp -DFUNC_TIME_MEASUREMENT
141141
lm_arm: CXXFLAGS +=
142142

143143
lm_fpga: CXX = arm-linux-gnueabihf-g++

0 commit comments

Comments
 (0)