Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-codegen
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Christian Heinigk
dune-codegen
Commits
4f25d438
Commit
4f25d438
authored
6 years ago
by
Dominic Kempf
Browse files
Options
Downloads
Patches
Plain Diff
Introduce an asynchronous minimization function
parent
aa6d4fbd
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
python/dune/perftool/sumfact/vectorization.py
+32
-4
32 additions, 4 deletions
python/dune/perftool/sumfact/vectorization.py
with
32 additions
and
4 deletions
python/dune/perftool/sumfact/vectorization.py
+
32
−
4
View file @
4f25d438
...
@@ -30,6 +30,7 @@ import itertools as it
...
@@ -30,6 +30,7 @@ import itertools as it
import
loopy
as
lp
import
loopy
as
lp
import
numpy
as
np
import
numpy
as
np
import
math
import
math
import
sys
@generator_factory
(
item_tags
=
(
"
vecinfo
"
,
"
dryrundata
"
),
cache_key_generator
=
lambda
o
,
n
:
o
)
@generator_factory
(
item_tags
=
(
"
vecinfo
"
,
"
dryrundata
"
),
cache_key_generator
=
lambda
o
,
n
:
o
)
...
@@ -160,6 +161,33 @@ def stringify_vectorization_strategy(strategy):
...
@@ -160,6 +161,33 @@ def stringify_vectorization_strategy(strategy):
return
result
return
result
def
minimize
(
iterable
,
key
=
lambda
x
:
x
):
"""
A minimization function that is capable of asynchronous
evaluation of the iterable if the python version supports it.
"""
version
=
sys
.
version_info
if
version
.
major
==
3
and
version
.
minor
>
5
:
import
asyncio
from
concurrent.futures
import
ThreadPoolExecutor
loop
=
asyncio
.
get_event_loop
()
executor
=
ThreadPoolExecutor
(
max_workers
=
1
)
@asyncio.coroutine
def
key_coro
(
i
):
return
loop
.
run_in_executor
(
executor
,
key
,
i
)
tasks
=
{}
for
i
in
iterable
:
tasks
[
i
]
=
asyncio
.
async
(
key_coro
(
i
),
loop
=
loop
)
loop
.
run_until_complete
(
asyncio
.
gather
(
*
tasks
.
values
()))
return
min
(
tasks
.
items
(),
key
=
lambda
t
:
t
[
1
].
result
())[
0
]
else
:
return
min
(
iterable
,
key
=
key
)
def
short_stringify_vectorization_strategy
(
strategy
):
def
short_stringify_vectorization_strategy
(
strategy
):
"""
A short string decribing the vectorization strategy. This is used
"""
A short string decribing the vectorization strategy. This is used
in costmodel validation plots to describe what a data point does
in costmodel validation plots to describe what a data point does
...
@@ -272,7 +300,7 @@ def level1_optimal_vectorization_strategy(sumfacts, width):
...
@@ -272,7 +300,7 @@ def level1_optimal_vectorization_strategy(sumfacts, width):
# Print the achieved cost and the target cost on the screen
# Print the achieved cost and the target cost on the screen
set_form_option
(
"
vectorization_strategy
"
,
"
model
"
)
set_form_option
(
"
vectorization_strategy
"
,
"
model
"
)
target
=
float
(
get_form_option
(
"
vectorization_target
"
))
target
=
float
(
get_form_option
(
"
vectorization_target
"
))
qp
=
min
(
optimal_strategies
,
key
=
lambda
qp
:
abs
(
strategy_cost
((
qp
,
optimal_strategies
[
qp
]))
-
target
))
qp
=
min
imize
(
optimal_strategies
,
key
=
lambda
qp
:
abs
(
strategy_cost
((
qp
,
optimal_strategies
[
qp
]))
-
target
))
cost
=
strategy_cost
((
qp
,
optimal_strategies
[
qp
]))
cost
=
strategy_cost
((
qp
,
optimal_strategies
[
qp
]))
print
(
"
The target cost was: {}
"
.
format
(
target
))
print
(
"
The target cost was: {}
"
.
format
(
target
))
...
@@ -300,7 +328,7 @@ def level1_optimal_vectorization_strategy(sumfacts, width):
...
@@ -300,7 +328,7 @@ def level1_optimal_vectorization_strategy(sumfacts, width):
with
open
(
"
mapping.csv
"
,
'
a
'
)
as
f
:
with
open
(
"
mapping.csv
"
,
'
a
'
)
as
f
:
f
.
write
(
"
"
.
join
((
identifier
,
str
(
cost
),
short_stringify_vectorization_strategy
((
qp
,
optimal_strategies
[
qp
]))))
+
"
\n
"
)
f
.
write
(
"
"
.
join
((
identifier
,
str
(
cost
),
short_stringify_vectorization_strategy
((
qp
,
optimal_strategies
[
qp
]))))
+
"
\n
"
)
else
:
else
:
qp
=
min
(
optimal_strategies
,
key
=
lambda
qp
:
strategy_cost
((
qp
,
optimal_strategies
[
qp
])))
qp
=
min
imize
(
optimal_strategies
,
key
=
lambda
qp
:
strategy_cost
((
qp
,
optimal_strategies
[
qp
])))
return
qp
,
optimal_strategies
[
qp
]
return
qp
,
optimal_strategies
[
qp
]
...
@@ -316,8 +344,8 @@ def level2_optimal_vectorization_strategy(sumfacts, width, qp):
...
@@ -316,8 +344,8 @@ def level2_optimal_vectorization_strategy(sumfacts, width, qp):
key_sumfacts
=
frozenset
(
sf
for
sf
in
sumfacts
if
sf
.
parallel_key
==
key
)
key_sumfacts
=
frozenset
(
sf
for
sf
in
sumfacts
if
sf
.
parallel_key
==
key
)
# Minimize over all the opportunities for the subset given by the current key
# Minimize over all the opportunities for the subset given by the current key
key_strategy
=
min
(
level2_optimal_vectorization_strategy_generator
(
key_sumfacts
,
width
,
qp
),
key_strategy
=
min
imize
(
level2_optimal_vectorization_strategy_generator
(
key_sumfacts
,
width
,
qp
),
key
=
fixedqp_strategy_costfunction
(
qp
))
key
=
fixedqp_strategy_costfunction
(
qp
))
sfdict
=
add_to_frozendict
(
sfdict
,
key_strategy
)
sfdict
=
add_to_frozendict
(
sfdict
,
key_strategy
)
return
sfdict
return
sfdict
...
...
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