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
fc2c9afb
Commit
fc2c9afb
authored
4 years ago
by
shingjan
Browse files
Options
Downloads
Patches
Plain Diff
template ready, working on hpvm codegen
parent
5744a820
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/onnx/frontend/hpvm_codegen.py
+32
-30
32 additions, 30 deletions
hpvm/projects/onnx/frontend/hpvm_codegen.py
with
32 additions
and
30 deletions
hpvm/projects/onnx/frontend/hpvm_codegen.py
+
32
−
30
View file @
fc2c9afb
class
GraphCodeGen
:
def
__init__
(
self
,
graph
):
self
.
_headers
=
""
self
.
_nodes
=
""
self
.
_root
=
""
self
.
_root_struct
=
""
self
.
_main_func
=
""
class
HpvmCodeGen
:
def
__init__
(
self
,
DFG
,
weights_dir
,
test_data
=
None
,
test_labels
=
None
):
self
.
program_str
=
""
self
.
graph
=
DFG
.
graph
self
.
tensors
=
DFG
.
tensors
self
.
nodes
=
DFG
.
nodes
self
.
var_cnt
=
0
self
.
weights_dir
=
weights_dir
self
.
test_data
=
test_data
self
.
test_labels
=
test_labels
self
.
filter_names
=
{}
# essentially tensors
def
emit
H
eader
s
(
self
):
def
emit
_h
eader
(
self
):
headers
=
"
\n
#include <stdio.h>
\n
"
headers
+=
"
#include <stdlib.h>
\n
"
headers
+=
"
#include <unistd.h>
\n
"
...
...
@@ -16,9 +20,9 @@ class GraphCodeGen:
headers
+=
"
#include <visc.h>
\n
"
headers
+=
"
#include <tensorTypes.h>
\n
"
headers
+=
"
#include <tensorUtils.h>
\n\n
"
self
.
_headers
=
headers
self
.
program_str
+
=
headers
def
emit
R
oot
(
self
):
def
emit
_r
oot
(
self
):
def
emitRootNodeHeader
():
root_signature
=
"
void root(
"
index
=
0
...
...
@@ -39,8 +43,8 @@ class GraphCodeGen:
for
f_name
in
self
.
filter_names
:
root_signature
+=
f_name
if
index
<
len
(
self
.
filter_names
)
-
1
:
root_signature
+=
"
,
"
index
+=
1
root_signature
+=
"
,
"
index
+=
1
root_signature
+=
"
, 0);
\n\n
"
return
root_signature
...
...
@@ -69,15 +73,15 @@ class GraphCodeGen:
root_struct
+=
"
}
\n
RootIn;
\n\n
"
return
root_struct
self
.
_
ro
ot
+=
emitRootNodeHeader
()
self
.
_
ro
ot
_str
uct
+=
emitRootStructure
()
self
.
codegen
(
self
.
dfg
)
self
.
_
ro
ot
+=
emitRootNodeFooter
()
self
.
p
ro
gram_str
+=
emitRootNodeHeader
()
self
.
p
ro
gram
_str
+=
emitRootStructure
()
#
self.codegen(self.dfg)
self
.
p
ro
gram_str
+=
emitRootNodeFooter
()
def
emit
M
ain
Func
(
self
,
test_data
):
def
emit
_m
ain
(
self
,
test_data
):
main_func_str
=
"
int main(){
\n\n
"
main_func_str
+=
self
.
weight_str
main_func_str
+=
self
.
input_str
#
main_func_str += self.weight_str
#
main_func_str += self.input_str
main_func_str
+=
"
\n
__visc__init();
\n
"
main_func_str
+=
"
RootIn* args = static_cast<RootIn*>(malloc(sizeof(RootIn)));
\n\n
"
for
f_name
in
self
.
filter_names
:
...
...
@@ -91,19 +95,17 @@ class GraphCodeGen:
main_func_str
+=
"
computeAccuracy3(labels, result);
\n
"
main_func_str
+=
"
return 0;
\n\n
"
main_func_str
+=
"
}
\n
"
self
.
_main_func
+=
main_func_str
self
.
program_str
+=
main_func_str
def
emitSource
(
self
,
dir_prefix
):
source
=
self
.
_headers
+
self
.
_nodes
+
self
.
_root
source
+=
self
.
_root_struct
+
self
.
_main_func
print
(
source
)
def
emit_source
(
self
,
dir_prefix
):
print
(
self
.
program_str
)
f
=
open
(
dir_prefix
+
"
/approxhpvm_src.cc
"
,
"
w+
"
)
f
.
write
(
s
ource
)
f
.
write
(
s
elf
.
program_str
)
f
.
close
()
def
compile
(
self
,
model
,
weights_dir
,
test_data
):
self
.
emit
H
eader
s
()
self
.
emitRoot
()
self
.
emit
M
ain
Func
(
test_data
)
def
compile
(
self
):
self
.
emit
_h
eader
()
#
self.emitRoot()
self
.
emit
_m
ain
(
self
.
test_data
)
# dump generated program string to source file
self
.
emit
S
ource
(
weights_dir
)
self
.
emit
_s
ource
(
self
.
weights_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