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
26eb0e32
Commit
26eb0e32
authored
5 years ago
by
Elizabeth
Browse files
Options
Downloads
Patches
Plain Diff
Implemented fp16 source code generation method
parent
9e7264a5
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
llvm/projects/hpvm-tensor-rt/code_autogenerators/source_code_autogenerator.py
+45
-13
45 additions, 13 deletions
...ensor-rt/code_autogenerators/source_code_autogenerator.py
with
45 additions
and
13 deletions
llvm/projects/hpvm-tensor-rt/code_autogenerators/source_code_autogenerator.py
+
45
−
13
View file @
26eb0e32
...
...
@@ -110,16 +110,49 @@ def get_new_function_calls(complete_line, knob_config):
new_line
.
append
(
"
%s%s, %s)
"
%
(
knob_config
.
modified_func_name
,
old_func_call
[:
-
1
],
'
,
'
.
join
(
knob_config
.
params
)))
orig_func_ind
=
complete_line
.
find
(
knob_config
.
orig_func_name
,
line_start_ind
)
new_line
.
append
(
complete_line
[
line_start_ind
:
])
#print(new_line)
return
''
.
join
(
new_line
)
def
generate_fp32_source
(
knob_config
,
new_file
,
source_file
):
pass
def
generate_fp16_source
(
knob_config
,
new_file
,
source_file
):
pass
def
generate_approx_source
(
knob_config
,
new_file
,
source_file
,
filename_dir
):
def
generate_fp32_source
(
new_file
,
source_file
):
# Copy the source code over
new_file
.
write
(
source_file
.
read
())
def
generate_fp16_source
(
knob_config
,
new_file
,
source_file
,
orig_source_dir
):
file_contents
=
source_file
.
read
()
# Fix all local paths
last_include_ind
=
file_contents
.
rfind
(
"
#include
"
)
last_include_newline_ind
=
file_contents
.
find
(
"
\n
"
,
last_include_ind
)
include_lines
=
file_contents
[
:
last_include_newline_ind
].
split
(
"
\n
"
)
new_file_contents
=
[]
for
line
in
include_lines
:
if
line
.
startswith
(
"
#
"
):
include_file
=
line
.
split
()[
1
]
if
include_file
.
startswith
(
"
\"
"
):
new_include_path
=
get_new_path
(
include_file
.
replace
(
"
\"
"
,
""
),
orig_source_dir
.
replace
(
"
\"
"
,
""
))
new_file_contents
.
append
(
"
#include
\"
%s
\"\n
"
%
new_include_path
)
else
:
new_file_contents
.
append
(
line
)
new_file_contents
.
append
(
file_contents
[
last_include_newline_ind
:
])
new_file_contents
=
'
\n
'
.
join
(
new_file_contents
)
# Replace all tensorOperation calls with tensorHalfOperation calls
# Derived from ../bin/replace_half_calls.py
# NOTE: Not very portable but I don't see another way of ONLY replacing tensorOperation FUNCTION calls
new_file_contents
=
new_file_contents
.
replace
(
"
tensorConvolution
"
,
"
tensorHalfConvolution
"
)
new_file_contents
=
new_file_contents
.
replace
(
"
tensorAdd
"
,
"
tensorHalfAdd
"
)
new_file_contents
=
new_file_contents
.
replace
(
"
tensorRelu
"
,
"
tensorHalfRelu
"
)
new_file_contents
=
new_file_contents
.
replace
(
"
tensorRelu2
"
,
"
tensorHalfRelu2
"
)
new_file_contents
=
new_file_contents
.
replace
(
"
tensorTanh
"
,
"
tensorHalfTanh
"
)
new_file_contents
=
new_file_contents
.
replace
(
"
tensorPooling
"
,
"
tensorHalfPooling
"
)
new_file_contents
=
new_file_contents
.
replace
(
"
tensorGemmGPU
"
,
"
tensorHalfGemmGPU
"
)
new_file
.
write
(
new_file_contents
)
def
generate_approx_source
(
knob_config
,
new_file
,
source_file
,
orig_source_dir
):
new_file_contents
=
[]
# Store complete line to handle cases where one line of code is split into two lines
...
...
@@ -130,7 +163,7 @@ def generate_approx_source(knob_config, new_file, source_file, filename_dir):
if
line
.
startswith
(
"
#
"
):
include_file
=
line
.
split
()[
1
]
if
include_file
.
startswith
(
"
\"
"
):
new_include_path
=
get_new_path
(
include_file
.
replace
(
"
\"
"
,
""
),
filenam
e_dir
.
replace
(
"
\"
"
,
""
))
new_include_path
=
get_new_path
(
include_file
.
replace
(
"
\"
"
,
""
),
orig_sourc
e_dir
.
replace
(
"
\"
"
,
""
))
new_file_contents
.
append
(
"
#include
\"
%s
\"\n
"
%
new_include_path
)
else
:
new_file_contents
.
append
(
line
)
...
...
@@ -165,19 +198,18 @@ def generate_source_code(table, dir_name, filename, source_name):
source_name: Filename without the file extension (ex: foo/blah.cc --> blah)
'''
source_file
=
open
(
filename
,
"
r
"
)
filenam
e_dir
=
os
.
path
.
dirname
(
filename
)
orig_sourc
e_dir
=
os
.
path
.
dirname
(
filename
)
for
knob_config
in
table
:
source_file
.
seek
(
0
,
0
)
new_filename
=
os
.
path
.
join
(
dir_name
,
"
%s_%s.cc
"
%
(
source_name
,
knob_config
.
id
))
new_file
=
open
(
new_filename
,
"
w
"
)
if
knob_config
.
approx
==
Approx
.
FP16
:
pass
generate_fp16_source
(
knob_config
,
new_file
,
source_file
,
orig_source_dir
)
elif
knob_config
.
approx
==
Approx
.
FP32
:
pass
generate_fp32_source
(
new_file
,
source_file
)
else
:
generate_approx_source
(
knob_config
,
new_file
,
source_file
,
filenam
e_dir
)
generate_approx_source
(
knob_config
,
new_file
,
source_file
,
orig_sourc
e_dir
)
new_file
.
close
()
print
(
"
Generated source code as %s
"
%
new_filename
)
...
...
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