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
66b46d35
Commit
66b46d35
authored
6 years ago
by
Dominic Kempf
Browse files
Options
Downloads
Patches
Plain Diff
Dabble with the cost model
parent
ce8f3cc4
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
+18
-12
18 additions, 12 deletions
python/dune/perftool/sumfact/vectorization.py
with
18 additions
and
12 deletions
python/dune/perftool/sumfact/vectorization.py
+
18
−
12
View file @
66b46d35
...
...
@@ -54,20 +54,18 @@ def attach_vectorization_info(sf):
def
costmodel
(
sf
):
# Penalize vertical vectorization
vertical_penalty
=
1
+
math
.
log
(
sf
.
vertical_width
)
# Penalize vertical vectorization and scalar execution
verticality
=
sf
.
vertical_width
if
isinstance
(
sf
,
SumfactKernel
):
verticality
=
get_vcl_type_size
(
dtype_floatingpoint
())
vertical_penalty
=
1
+
0.5
*
math
.
log
(
verticality
,
2
)
memory_penalty
=
1.0
if
isinstance
(
sf
,
VectorizedSumfactKernel
):
memory_penalty
=
1.0
+
math
.
log
(
len
(
set
(
k
.
interface
for
k
in
sf
.
kernels
)),
2
)
# Penalize scalar sum factorization kernels
scalar_penalty
=
1
if
isinstance
(
sf
,
SumfactKernel
):
scalar_penalty
=
get_vcl_type_size
(
dtype_floatingpoint
())
memory_penalty
=
1.0
+
0.25
*
math
.
log
(
len
(
set
(
k
.
interface
for
k
in
sf
.
kernels
)),
2
)
# Return total operations
return
sf
.
operations
*
vertical_penalty
*
memory_penalty
*
scalar_penalty
return
sf
.
operations
*
vertical_penalty
*
memory_penalty
def
explicit_costfunction
(
sf
):
...
...
@@ -265,21 +263,27 @@ def level1_optimal_vectorization_strategy(sumfacts, width):
# Find the minimum cost strategy between all the quadrature point tuples
optimal_strategies
=
{
qp
:
level2_optimal_vectorization_strategy
(
sumfacts
,
width
,
qp
)
for
qp
in
quad_points
}
qp
=
min
(
optimal_strategies
,
key
=
lambda
qp
:
strategy_cost
((
qp
,
optimal_strategies
[
qp
])))
# If we are using the 'target' strategy, we might want to log some information.
if
get_form_option
(
"
vectorization_strategy
"
)
==
"
target
"
:
# Print the achieved cost and the target cost on the screen
set_form_option
(
"
vectorization_strategy
"
,
"
model
"
)
qp
=
min
(
optimal_strategies
,
key
=
lambda
qp
:
strategy_cost
((
qp
,
optimal_strategies
[
qp
])))
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
))
print
(
"
The optimal cost would be: {}
"
.
format
(
strategy_cost
(
level1_optimal_vectorization_strategy
(
sumfacts
,
width
))))
optimum
=
level1_optimal_vectorization_strategy
(
sumfacts
,
width
)
print
(
"
The optimal cost would be: {}
"
.
format
(
strategy_cost
(
optimum
)))
set_form_option
(
"
vectorization_strategy
"
,
"
target
"
)
print
(
"
The score in
'
target
'
logic was: {}
"
.
format
(
strategy_cost
((
qp
,
optimal_strategies
[
qp
]))))
# Print the employed vectorization strategy into a file
filename
=
"
targetstrat_{}.log
"
.
format
(
int
(
float
(
get_form_option
(
"
vectorization_target
"
))))
suffix
=
""
if
get_global_context_value
(
"
integral_type
"
)
==
"
interior_facet
"
:
suffix
=
"
_dir{}_mod{}
"
.
format
(
get_global_context_value
(
"
facedir_s
"
),
get_global_context_value
(
"
facemod_s
"
))
filename
=
"
targetstrat_{}{}.log
"
.
format
(
int
(
float
(
get_form_option
(
"
vectorization_target
"
))),
suffix
)
with
open
(
filename
,
'
w
'
)
as
f
:
f
.
write
(
"
\n
"
.
join
(
stringify_vectorization_strategy
((
qp
,
optimal_strategies
[
qp
]))))
...
...
@@ -291,6 +295,8 @@ def level1_optimal_vectorization_strategy(sumfacts, width):
# TODO: Depending on the number of samples, we might need a file lock here.
with
open
(
"
mapping.csv
"
,
'
a
'
)
as
f
:
f
.
write
(
"
"
.
join
((
identifier
,
str
(
cost
),
short_stringify_vectorization_strategy
((
qp
,
optimal_strategies
[
qp
]))))
+
"
\n
"
)
else
:
qp
=
min
(
optimal_strategies
,
key
=
lambda
qp
:
strategy_cost
((
qp
,
optimal_strategies
[
qp
])))
return
qp
,
optimal_strategies
[
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