Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hpvm-release
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
llvm
hpvm-release
Commits
e04f3b4d
Commit
e04f3b4d
authored
5 years ago
by
Elizabeth
Browse files
Options
Downloads
Patches
Plain Diff
Implemented functionality to run binaries and started table generation
parent
5febbf3a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
llvm/projects/hpvm-tensor-rt/build_pldi/table_generator.py
+96
-0
96 additions, 0 deletions
llvm/projects/hpvm-tensor-rt/build_pldi/table_generator.py
with
96 additions
and
0 deletions
llvm/projects/hpvm-tensor-rt/build_pldi/table_generator.py
0 → 100644
+
96
−
0
View file @
e04f3b4d
import
collections
import
glob
import
os
import
subprocess
import
shutil
class
TableGenerator
:
def
__init__
(
self
,
dir_name
,
iters
,
profiler_binary_name
):
self
.
__dir_name
=
dir_name
self
.
__network_name
=
dir_name
self
.
__iters
=
iters
self
.
__profiler_binary_name
=
profiler_binary_name
def
__is_binary
(
self
,
file_path
):
# Binary name must start with the network name as per our naming standards
return
os
.
path
.
isfile
(
file_path
)
and
os
.
access
(
file_path
,
os
.
X_OK
)
and
\
file_path
.
find
(
self
.
__network_name
)
!=
-
1
def
run_binaries_in_input_dir
(
self
):
if
not
os
.
path
.
isdir
(
self
.
__dir_name
):
print
(
"
ERROR: Directory %s not found
"
%
self
.
__dir_name
)
exit
(
1
)
self
.
__results_dir_name
=
"
%s_results
"
%
self
.
__dir_name
try
:
os
.
mkdir
(
self
.
__results_dir_name
)
except
OSError
:
if
os
.
path
.
isdir
(
self
.
__results_dir_name
):
print
(
"
Directory already exists. Clearing directory.
"
)
for
old_file
in
glob
.
glob
(
os
.
path
.
join
(
self
.
__results_dir_name
,
"
*
"
)):
os
.
remove
(
old_file
)
else
:
print
(
"
ERROR: Directory doesn
'
t exist but failed to create dir
"
)
for
binary_name
in
os
.
listdir
(
self
.
__dir_name
):
binary_path
=
os
.
path
.
join
(
self
.
__dir_name
,
binary_name
)
if
not
self
.
__is_binary
(
binary_path
):
continue
if
not
os
.
path
.
isfile
(
binary_path
):
print
(
"
ERROR: Binary %s not found
"
%
binary_path
)
exit
(
1
)
output_file
=
os
.
path
.
join
(
self
.
__results_dir_name
,
binary_name
+
"
.txt
"
)
# No stdout/stderr piping needed for now
subprocess
.
Popen
([
profiler_binary_name
,
binary_path
,
str
(
self
.
__iters
),
\
output_file
]).
communicate
()
def
__get_approximation_type
(
self
,
results_filename
):
approx_type_start_ind
=
results_file
.
find
(
self
.
__network_name
)
\
+
len
(
self
.
__network_name
)
+
1
# + 1 to account for _ delimiter
approx_type_end_ind
=
results_file
.
find
(
"
.txt
"
)
return
results_filename
[
approx_type_start_ind
:
approx_type_end_ind
]
def
generate_table
(
self
):
# Copy ops file to results directory to use as empty table
table_filename
=
os
.
path
.
join
(
self
.
__results_dir_name
,
\
"
%s_tensors.txt
"
%
self
.
__network_name
)
# TODO un hard code this
soc_operations_file_name
=
os
.
path
.
join
(
"
/home/nvidia/soc_simulator
"
,
\
"
%s_cifar10
"
%
self
.
__network_name
)
shutil
.
copyfile
(
soc_operations_file_name
,
table_filename
)
# Local table --> avoid setting any global variables in case this class is
# reused multiple times
table
=
defaultdict
(
defaultdict
(
str
))
for
results_file_name
in
os
.
listdir
(
self
.
__results_dir_name
):
# Ignore if not a results file
if
not
results_file_name
.
startswith
(
self
.
__network_name
):
continue
approx_type
=
self
.
__get_approximation_type
(
results_file_name
)
print
(
approx_type
)
results_file
=
open
(
os
.
path
.
join
(
self
.
__results_dir_name
,
results_file_name
),
"
r
"
)
for
line
in
results_file
:
print
(
line
)
results_file
.
close
()
# For each output file --> parse and get the storage files
# For each line --> store the time and energy
# <operation name> <type of approx> <time> <energy>
# Need to map to soc_operations file
# final file should be in the format of the soc_operations file
binary_dir_name
=
"
/home/nvidia/Gitlab/hpvm/llvm/projects/hpvm-tensor-rt/build_pldi/mobilenet
"
num_iters
=
1
profiler_binary_name
=
"
/home/nvidia/awesome_profiler/pp
"
table_gen
=
TableGenerator
(
binary_dir_name
,
num_iters
,
profiler_binary_name
)
table_gen
.
run_binaries_in_input_dir
()
table_gen
.
generate_tables
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment