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
468e8569
Commit
468e8569
authored
6 years ago
by
Dominic Kempf
Browse files
Options
Downloads
Patches
Plain Diff
Costfunction sampling now works!
parent
00673ecf
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
+16
-25
16 additions, 25 deletions
python/dune/perftool/sumfact/vectorization.py
with
16 additions
and
25 deletions
python/dune/perftool/sumfact/vectorization.py
+
16
−
25
View file @
468e8569
"""
Sum factorization vectorization
"""
from
__future__
import
division
import
logging
from
dune.perftool.loopy.target
import
dtype_floatingpoint
...
...
@@ -19,7 +21,7 @@ from dune.perftool.sumfact.tabulation import (BasisTabulationMatrixArray,
set_quadrature_points
,
)
from
dune.perftool.error
import
PerftoolVectorizationError
from
dune.perftool.options
import
get_form_option
,
set_form_option
from
dune.perftool.options
import
get_form_option
,
get_option
,
set_form_option
from
dune.perftool.tools
import
add_to_frozendict
,
round_to_multiple
,
list_diff
from
pytools
import
product
...
...
@@ -83,16 +85,14 @@ def explicit_costfunction(sf):
return
1000000000000
_global_cost_for_target
=
0.0
_subset_cost_for_target
=
0.0
_global_kernel_amount
=
0
def
target_costfunction
(
sf
):
target
=
float
(
get_form_option
(
"
vectorization_target
"
))
realcost
=
costmodel
(
sf
)
val
=
abs
(
realcost
-
(
_subset_cost_for_target
/
_global_cost_for_target
)
*
target
)
print
(
val
)
return
val
ratio
=
sf
.
horizontal_width
/
_global_kernel_amount
return
abs
(
realcost
-
ratio
*
target
)
def
strategy_cost
(
strat_tuple
):
...
...
@@ -213,14 +213,12 @@ def decide_vectorization_strategy():
def
level1_optimal_vectorization_strategy
(
sumfacts
,
width
):
# If this uses the 'target' cost model, we need to
do an expensive setup step:
#
We switch to the 'model' implementation and find a minimum. This way we learn
#
abou
t the
total cost needed to weigh costs of subsets of sum factorization kernels
.
# If this uses the 'target' cost model, we need to
store information on how many
#
sum factorization kernels need to be implemented. This will be used to correctly
#
weigh
t the
cost target in the cost function
.
if
get_form_option
(
"
vectorization_strategy
"
)
==
"
target
"
:
set_form_option
(
"
vectorization_strategy
"
,
"
model
"
)
global
_global_cost_for_target
_global_cost_for_target
=
strategy_cost
(
level1_optimal_vectorization_strategy
(
sumfacts
,
width
))
set_form_option
(
"
vectorization_strategy
"
,
"
target
"
)
global
_global_kernel_amount
_global_kernel_amount
=
len
(
sumfacts
)
# Gather a list of possible quadrature point tuples
quad_points
=
[
quadrature_points_per_direction
()]
...
...
@@ -245,7 +243,12 @@ def level1_optimal_vectorization_strategy(sumfacts, width):
cost
=
strategy_cost
((
qp
,
optimal_strategies
[
qp
]))
print
(
"
The target cost was: {}
"
.
format
(
get_form_option
(
"
vectorization_target
"
)))
print
(
"
The achieved cost was: {}
"
.
format
(
cost
))
from
os.path
import
join
filename
=
join
(
get_option
(
"
project_basedir
"
),
"
targetstrat_{}
"
.
format
(
int
(
float
(
get_form_option
(
"
vectorization_target
"
)))))
with
open
(
filename
,
'
w
'
)
as
f
:
f
.
write
(
"
\n
"
.
join
(
stringify_vectorization_strategy
((
qp
,
optimal_strategies
[
qp
]))))
set_form_option
(
"
vectorization_strategy
"
,
"
target
"
)
print
(
"
The score in
'
target
'
logic was: {}
"
.
format
(
strategy_cost
((
qp
,
optimal_strategies
[
qp
]))))
return
qp
,
optimal_strategies
[
qp
]
...
...
@@ -260,18 +263,6 @@ def level2_optimal_vectorization_strategy(sumfacts, width, qp):
for
key
in
keys
:
key_sumfacts
=
frozenset
(
sf
for
sf
in
sumfacts
if
sf
.
parallel_key
==
key
)
# If this uses the 'target' cost model, we need to find out how the score of
# the normal cost model for the given subset of sum factorization kernels would
# be. This way we get a percentage of the total target, which should be spent in
# this subset.
if
get_form_option
(
"
vectorization_strategy
"
)
==
"
target
"
:
set_form_option
(
"
vectorization_strategy
"
,
"
model
"
)
global
_subset_cost_for_target
minimum
=
min
(
level2_optimal_vectorization_strategy_generator
(
key_sumfacts
,
width
,
qp
),
key
=
fixedqp_strategy_costfunction
(
qp
))
_subset_cost_for_target
=
strategy_cost
((
qp
,
minimum
))
set_form_option
(
"
vectorization_strategy
"
,
"
target
"
)
# 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
=
fixedqp_strategy_costfunction
(
qp
))
...
...
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