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
e2309d39
Commit
e2309d39
authored
5 years ago
by
Elizabeth
Browse files
Options
Downloads
Patches
Plain Diff
Changed replacement to keep the original parameters but add new params
parent
e3c0e806
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
+23
-20
23 additions, 20 deletions
...ensor-rt/code_autogenerators/source_code_autogenerator.py
with
23 additions
and
20 deletions
llvm/projects/hpvm-tensor-rt/code_autogenerators/source_code_autogenerator.py
+
23
−
20
View file @
e2309d39
...
...
@@ -30,9 +30,6 @@ class KnobConfiguration:
self
.
modified_func_name
=
line_as_lst
[
-
1
]
self
.
params
=
line_as_lst
[
1
:
-
2
]
# Build the new function call
self
.
new_func_call
=
"
%s(%s)
"
%
(
self
.
modified_func_name
,
"
,
"
.
join
(
self
.
params
))
def
get_new_path
(
old_path
,
orig_source_code_dir
):
'''
...
...
@@ -48,6 +45,26 @@ def get_new_path(old_path, orig_source_code_dir):
return
os
.
path
.
join
(
"
..
"
,
orig_source_code_dir
,
old_path
)
# "complete_line" = a valid line of code
def
replace_function_calls
(
complete_line
,
knob_config
):
orig_func_ind
=
complete_line
.
find
(
knob_config
.
orig_func_name
)
new_line
=
[]
line_start_ind
=
0
last_ind
=
0
while
orig_func_ind
!=
-
1
:
new_line
.
append
(
complete_line
[
line_start_ind
:
orig_func_ind
])
line_start_ind
=
complete_line
.
find
(
"
)
"
,
orig_func_ind
)
+
1
old_func_call
=
complete_line
[
complete_line
.
find
(
"
(
"
,
orig_func_ind
):
line_start_ind
]
new_line
.
append
(
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_source_code
(
table
,
dir_name
,
filename
,
source_name
):
'''
Generates source code for all configurations in the table for one original source
...
...
@@ -65,7 +82,7 @@ def generate_source_code(table, dir_name, filename, source_name):
for
knob_config
in
table
:
source_file
.
seek
(
0
,
0
)
new_file_contents
=
[
file_comment
%
(
knob_config
.
orig_func_name
,
knob_config
.
new
_func_
call
)]
new_file_contents
=
[
file_comment
%
(
knob_config
.
orig_func_name
,
knob_config
.
modified
_func_
name
)]
# Store complete line to handle cases where one line of code is split into two lines
complete_line
=
""
...
...
@@ -93,20 +110,7 @@ def generate_source_code(table, dir_name, filename, source_name):
complete_line
+=
line
orig_func_ind
=
complete_line
.
find
(
knob_config
.
orig_func_name
)
if
orig_func_ind
!=
-
1
:
# Replace from an instance of origOp to first instance of ) after origOp
# with the new function call
new_line
=
[]
line_start_ind
=
0
last_ind
=
0
while
orig_func_ind
!=
-
1
:
new_line
.
append
(
complete_line
[
line_start_ind
:
orig_func_ind
])
new_line
.
append
(
knob_config
.
new_func_call
)
line_start_ind
=
complete_line
.
find
(
"
)
"
,
orig_func_ind
)
+
1
orig_func_ind
=
complete_line
.
find
(
knob_config
.
orig_func_name
,
line_start_ind
)
new_line
.
append
(
complete_line
[
line_start_ind
:
])
new_file_contents
.
append
(
''
.
join
(
new_line
))
new_file_contents
.
append
(
replace_function_calls
(
complete_line
,
knob_config
))
else
:
new_file_contents
.
append
(
complete_line
)
complete_line
=
""
...
...
@@ -115,8 +119,7 @@ def generate_source_code(table, dir_name, filename, source_name):
new_file
=
open
(
new_filename
,
"
w
"
)
new_file
.
write
(
''
.
join
(
new_file_contents
))
new_file
.
close
()
print
(
"
Generated source code for configuration %s as %s
"
\
%
(
knob_config
.
new_func_call
,
new_filename
))
print
(
"
Generated source code as %s
"
%
new_filename
)
source_file
.
close
()
...
...
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