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
74aec30b
"hpvm/test/dnn_benchmarks/keras/README.md" did not exist on "20af780dd765de9e3efa9c5ae9a3e9e41e5985c5"
Commit
74aec30b
authored
4 years ago
by
Hashim Sharif
Browse files
Options
Downloads
Patches
Plain Diff
Starting with Tuner HPVM-C generation
parent
461c1c6a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
hpvm/projects/keras/frontend/hpvm_dfg_translator.py
+62
-4
62 additions, 4 deletions
hpvm/projects/keras/frontend/hpvm_dfg_translator.py
with
62 additions
and
4 deletions
hpvm/projects/keras/frontend/hpvm_dfg_translator.py
+
62
−
4
View file @
74aec30b
...
@@ -17,6 +17,7 @@ class HPVMTranslator:
...
@@ -17,6 +17,7 @@ class HPVMTranslator:
self
.
root_str
=
""
self
.
root_str
=
""
self
.
root_struct_str
=
""
self
.
root_struct_str
=
""
self
.
main_func_str
=
""
self
.
main_func_str
=
""
self
.
tuner_main_func_str
=
""
self
.
file_header_str
=
""
self
.
file_header_str
=
""
self
.
hpvm_node_names
=
{}
self
.
hpvm_node_names
=
{}
...
@@ -709,7 +710,6 @@ class HPVMTranslator:
...
@@ -709,7 +710,6 @@ class HPVMTranslator:
main_func_str
+=
"
llvm_hpvm_invokeRtControl(result, labels_path.c_str(), start, end);
\n
"
main_func_str
+=
"
llvm_hpvm_invokeRtControl(result, labels_path.c_str(), start, end);
\n
"
main_func_str
+=
self
.
endBatchLoop
()
main_func_str
+=
self
.
endBatchLoop
()
main_func_str
+=
HPVM_cleanup
+
"
();
\n
"
main_func_str
+=
HPVM_cleanup
+
"
();
\n
"
####main_func_str += "computeAccuracy3(labels, result); \n"
####main_func_str += "computeAccuracy3(labels, result); \n"
...
@@ -719,10 +719,51 @@ class HPVMTranslator:
...
@@ -719,10 +719,51 @@ class HPVMTranslator:
self
.
main_func_str
+=
main_func_str
self
.
main_func_str
+=
main_func_str
def
genTunerMainFunction
(
self
,
test_data
,
batch_size
):
tuner_main_func_str
=
"
int main(int argc, char* argv[]){
\n\n
"
tuner_main_func_str
+=
self
.
weight_str
tuner_main_func_str
+=
self
.
input_str
tuner_main_func_str
+=
"
RootIn* args = static_cast<RootIn*>(malloc(sizeof(RootIn)));
\n\n
"
tuner_main_func_str
+=
self
.
handleTuneTestData
()
for
f_name
in
self
.
filter_names
:
tuner_main_func_str
+=
"
args->
"
+
f_name
+
"
=
"
+
f_name
+
"
;
\n
"
tuner_main_func_str
+=
"
args->
"
+
f_name
+
"
_bytes = 0;
\n
"
tuner_main_func_str
+=
self
.
genBatchLoop
(
test_data
,
batch_size
)
tuner_main_func_str
+=
"
\n
"
+
HPVM_init
+
"
();
\n
"
tuner_main_func_str
+=
"
void* dfg =
"
+
HPVM_launch
+
"
(0, root, (void*) args);
\n\n
"
tuner_main_func_str
+=
HPVM_wait
+
"
(dfg);
\n\n
"
if
LLVM_4_BRANCH
:
tuner_main_func_str
+=
"
void *result = static_cast<RootIn*>(args)->input;
\n
"
elif
LLVM_9_BRANCH
:
tuner_main_func_str
+=
"
void *result = static_cast<RootIn *>(args)->r.tensor;
\n
"
tuner_main_func_str
+=
"
hpvm_request_tensor(result, 0);
\n\n
"
tuner_main_func_str
+=
"
uint32_t* labels = readLabelsBatch3(labels_path.c_str(), start, end);
\n
"
tuner_main_func_str
+=
"
computeAccuracy3(labels, result);
\n
"
tuner_main_func_str
+=
HPVM_cleanup
+
"
();
\n
"
tuner_main_func_str
+=
self
.
endBatchLoop
()
tuner_main_func_str
+=
"
return 0;
\n\n
"
tuner_main_func_str
+=
"
}
\n
"
self
.
tuner_main_func_str
+=
tuner_main_func_str
def
generate
Source
Program
(
self
,
dir_prefix
):
def
generate
Test
Program
(
self
,
dir_prefix
):
program_str
=
self
.
file_header_str
+
self
.
node_str
+
self
.
root_str
program_str
=
self
.
file_header_str
+
self
.
node_str
+
self
.
root_str
program_str
+=
self
.
root_struct_str
+
self
.
main_func_str
program_str
+=
self
.
root_struct_str
+
self
.
main_func_str
...
@@ -733,19 +774,36 @@ class HPVMTranslator:
...
@@ -733,19 +774,36 @@ class HPVMTranslator:
f
.
write
(
program_str
)
f
.
write
(
program_str
)
f
.
close
()
f
.
close
()
def
generateTunerProgram
(
self
,
dir_prefix
):
program_str
=
self
.
file_header_str
+
self
.
node_str
+
self
.
root_str
program_str
+=
self
.
root_struct_str
+
self
.
tuner_main_func_str
DEBUG
(
program_str
)
f
=
open
(
dir_prefix
+
"
/approxhpvm_tuner_src.cc
"
,
"
w+
"
)
f
.
write
(
program_str
)
f
.
close
()
def
translate
(
self
,
model
,
src_dir
,
test_data
,
tuner_data
,
batch_size
):
def
translate
(
self
,
model
,
src_dir
,
test_data
,
tuner_data
,
batch_size
):
self
.
genFileHeader
()
self
.
genFileHeader
()
self
.
genRootNodeHeader
()
self
.
genRootNodeHeader
()
self
.
genRootStructure
()
self
.
genRootStructure
()
self
.
codegen
(
self
.
dfg
)
self
.
codegen
(
self
.
dfg
)
self
.
genRootNodeFooter
()
self
.
genRootNodeFooter
()
self
.
genMainFunction
(
test_data
,
batch_size
)
self
.
genMainFunction
(
test_data
,
batch_size
)
self
.
genTunerMainFunction
(
test_data
,
batch_size
)
# dump generated program string to source file
# dump generated program string to source file
self
.
generate
Source
Program
(
src_dir
)
self
.
generate
Test
Program
(
src_dir
)
self
.
generateTunerProgram
(
src_dir
)
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