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
4cfeaece
Commit
4cfeaece
authored
6 years ago
by
Marcel Koch
Browse files
Options
Downloads
Patches
Plain Diff
refactoring timings.py
parent
ea5f2928
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/codegen/pdelab/driver/timings.py
+77
-70
77 additions, 70 deletions
python/dune/codegen/pdelab/driver/timings.py
with
77 additions
and
70 deletions
python/dune/codegen/pdelab/driver/timings.py
+
77
−
70
View file @
4cfeaece
"""
Timing related generator functions
"""
"""
Timing related generator functions
"""
from
dune.codegen.options
import
get_option
from
dune.codegen.generation
import
(
cached
,
from
dune.codegen.generation
import
(
cached
,
include_file
,
include_file
,
pre_include
,
pre_include
,
post_include
,
preamble
,
preamble
,
)
)
from
dune.codegen.options
import
get_option
from
dune.codegen.pdelab.driver
import
(
get_form_ident
,
from
dune.codegen.pdelab.driver
import
(
get_form_ident
,
is_linear
,
is_linear
,
name_initree
,
name_initree
,
...
@@ -21,7 +20,7 @@ from dune.codegen.pdelab.driver.gridoperator import (name_gridoperator,
...
@@ -21,7 +20,7 @@ from dune.codegen.pdelab.driver.gridoperator import (name_gridoperator,
type_gridoperator
,
type_gridoperator
,
)
)
from
dune.codegen.pdelab.driver.solve
import
(
name_vector
,
from
dune.codegen.pdelab.driver.solve
import
(
name_vector
,
typ
e_vector
,
defin
e_vector
,
)
)
...
@@ -90,6 +89,26 @@ def name_timing_stream():
...
@@ -90,6 +89,26 @@ def name_timing_stream():
return
name
return
name
def
name_temporary_vector
(
name
,
form
):
name
=
"
{}_{}
"
.
format
(
name
,
form
)
define_vector
(
name
,
form
)
return
name
@preamble
(
section
=
"
timings
"
)
def
define_jacobian
(
name
,
form_ident
):
t_go
=
type_gridoperator
(
form_ident
)
n_go
=
name_gridoperator
(
form_ident
)
return
[
"
using M_{} = typename {}::Traits::Jacobian;
"
.
format
(
form_ident
,
t_go
),
"
M_{} {}({});
"
.
format
(
form_ident
,
name
,
n_go
)]
def
name_jacobian
(
form_ident
):
name
=
"
J_{}
"
.
format
(
form_ident
)
define_jacobian
(
name
,
form_ident
)
return
name
@cached
@cached
def
setup_timer
():
def
setup_timer
():
# TODO check that we are using YASP?
# TODO check that we are using YASP?
...
@@ -99,100 +118,88 @@ def setup_timer():
...
@@ -99,100 +118,88 @@ def setup_timer():
include_file
(
"
dune/codegen/common/timer.hh
"
,
filetag
=
"
driver
"
)
include_file
(
"
dune/codegen/common/timer.hh
"
,
filetag
=
"
driver
"
)
@preamble
(
section
=
"
timings
"
)
def
init_region_timer
(
region
):
def
evaluate_residual_timer
():
n_go
=
name_gridoperator
(
get_form_ident
())
v
=
name_vector
(
get_form_ident
())
t_v
=
type_vector
(
get_form_ident
())
setup_timer
()
setup_timer
()
from
dune.codegen.generation
import
post_include
post_include
(
"
HP_DECLARE_TIMER({});
"
.
format
(
region
),
filetag
=
"
driver
"
)
if
get_option
(
'
instrumentation_level
'
)
>=
2
:
# Write back times
from
dune.codegen.generation
import
post_include
post_include
(
"
HP_DECLARE_TIMER(residual_evaluation);
"
,
filetag
=
"
driver
"
)
timestream
=
name_timing_stream
()
print_times
=
[]
lop_name
=
name_localoperator
(
get_form_ident
())
def
start_region_timer
(
region
):
return
[
"
HP_TIMER_START({});
"
.
format
(
region
)]
def
stop_region_timer
(
region
):
timestream
=
name_timing_stream
()
return
[
"
HP_TIMER_STOP({});
"
.
format
(
region
),
"
DUMP_TIMER({}, {}, {}, true);
"
.
format
(
get_option
(
"
instrumentation_level
"
),
region
,
timestream
)]
def
timed_region
(
region
,
actions
):
if
isinstance
(
actions
,
str
):
actions
=
[
actions
]
assert
(
isinstance
(
actions
,
list
))
assembly
=
[]
print_times
=
[]
init_region_timer
(
region
)
if
get_option
(
'
instrumentation_level
'
)
>=
3
:
if
get_option
(
'
instrumentation_level
'
)
>=
3
:
timestream
=
name_timing_stream
()
lop_name
=
name_localoperator
(
get_form_ident
())
print_times
.
append
(
"
{}.dump_timers({}, {}, true);
"
.
format
(
lop_name
,
timestream
,
name_timing_identifier
()))
print_times
.
append
(
"
{}.dump_timers({}, {}, true);
"
.
format
(
lop_name
,
timestream
,
name_timing_identifier
()))
if
get_option
(
'
instrumentation_level
'
)
>=
2
:
assembly
+=
start_region_timer
(
region
)
evaluation
=
[
"
HP_TIMER_START(residual_evaluation);
"
,
assembly
+=
actions
"
{}.residual({}, r);
"
.
format
(
n_go
,
v
),
assembly
+=
stop_region_timer
(
region
)
"
HP_TIMER_STOP(residual_evaluation);
"
,
"
DUMP_TIMER({}, residual_evaluation, {}, true);
"
.
format
(
get_option
(
"
instrumentation_level
"
),
timestream
)]
evaluation
.
extend
(
print_times
)
else
:
evaluation
=
[
"
{}.residual({}, r);
"
.
format
(
n_go
,
v
)]
evaluation
=
[
"
{} r({});
"
.
format
(
t_v
,
v
),
"
r=0.0;
"
]
+
evaluation
return
evaluation
return
assembly
+
print_times
@preamble
(
section
=
"
timings
"
)
@preamble
(
section
=
"
timings
"
)
def
apply_jacobian
_timer
():
def
evaluate_residual
_timer
():
n_go
=
name_gridoperator
(
get_form_ident
())
n_go
=
name_gridoperator
(
get_form_ident
())
v
=
name_vector
(
get_form_ident
())
v
=
name_vector
(
get_form_ident
())
t_v
=
type_vector
(
get_form_ident
())
r
=
name_temporary_vector
(
"
r
"
,
get_form_ident
())
setup_timer
()
action
=
"
{}.residual({}, {});
"
.
format
(
n_go
,
v
,
r
)
if
get_option
(
'
instrumentation_level
'
)
>=
2
:
if
get_option
(
'
instrumentation_level
'
)
>=
2
:
# Write back times
return
timed_region
(
"
residual_evaluation
"
,
action
)
from
dune.codegen.generation
import
post_include
else
:
post_include
(
"
HP_DECLARE_TIMER(apply_jacobian);
"
,
filetag
=
"
driver
"
)
return
action
timestream
=
name_timing_stream
()
print_times
=
[]
lop_name
=
name_localoperator
(
get_form_ident
())
if
get_option
(
'
instrumentation_level
'
)
>=
3
:
@preamble
(
section
=
"
timings
"
)
print_times
.
append
(
"
{}.dump_timers({}, {}, true);
"
.
format
(
lop_name
,
timestream
,
name_timing_identifier
()))
def
apply_jacobian_timer
():
form
=
get_form_ident
()
n_go
=
name_gridoperator
(
form
)
v
=
name_vector
(
form
)
if
is_linear
():
if
is_linear
():
declaration
=
[
"
{} j({});
"
.
format
(
t_v
,
v
),
"
j=0.0;
"
]
j
=
name_temporary_vector
(
"
j
"
,
form
)
evalu
ation
=
[
"
{}.jacobian_apply({},
j
);
"
.
format
(
n_go
,
v
)
]
a
c
tion
=
"
{}.jacobian_apply({},
{}
);
"
.
format
(
n_go
,
v
,
j
)
else
:
else
:
declaration
=
[
"
{} j0({});
"
.
format
(
t_v
,
v
),
"
j0=0.0;
"
,
j0
=
name_temporary_vector
(
"
j0
"
,
form
)
"
{} j1({});
"
.
format
(
t_v
,
v
),
"
j1=0.0;
"
]
j1
=
name_temporary_vector
(
"
j1
"
,
form
)
evalu
ation
=
[
"
{}.nonlinear_jacobian_apply({},
j0, j1
);
"
.
format
(
n_go
,
v
)
]
a
c
tion
=
"
{}.nonlinear_jacobian_apply({},
{}, {}
);
"
.
format
(
n_go
,
v
,
j0
,
j1
)
if
get_option
(
'
instrumentation_level
'
)
>=
2
:
if
get_option
(
'
instrumentation_level
'
)
>=
2
:
evaluation
=
[
"
HP_TIMER_START(apply_jacobian);
"
]
+
evaluation
+
[
"
HP_TIMER_STOP(apply_jacobian);
"
,
"
DUMP_TIMER({}, apply_jacobian, {}, true);
"
.
format
(
get_option
(
"
instrumentation_level
"
),
timestream
)]
return
timed_region
(
"
apply_jacobian
"
,
action
)
evaluation
.
extend
(
print_times
)
else
:
return
action
return
declaration
+
evaluation
@preamble
(
section
=
"
timings
"
)
@preamble
(
section
=
"
timings
"
)
def
assemble_matrix_timer
():
def
assemble_matrix_timer
():
t_go
=
type_gridoperator
(
get_form_ident
())
n_go
=
name_gridoperator
(
get_form_ident
())
n_go
=
name_gridoperator
(
get_form_ident
())
v
=
name_vector
(
get_form_ident
())
v
=
name_vector
(
get_form_ident
())
t_v
=
type_vector
(
get_form_ident
())
m
=
name_jacobian
(
get_form_ident
())
setup_timer
()
if
get_option
(
'
instrumentation_level
'
)
>=
2
:
# Write back times
from
dune.codegen.generation
import
post_include
post_include
(
"
HP_DECLARE_TIMER(matrix_assembly);
"
,
filetag
=
"
driver
"
)
timestream
=
name_timing_stream
()
print_times
=
[]
lop_name
=
name_localoperator
(
get_form_ident
())
action
=
"
{}.jacobian({},{});
"
.
format
(
n_go
,
v
,
m
)
if
get_option
(
'
instrumentation_level
'
)
>=
3
:
print_times
.
append
(
"
{}.dump_timers({}, {}, true);
"
.
format
(
lop_name
,
timestream
,
name_timing_identifier
()))
if
get_option
(
'
instrumentation_level
'
)
>=
2
:
if
get_option
(
'
instrumentation_level
'
)
>=
2
:
assembly
=
[
"
HP_TIMER_START(matrix_assembly);
"
,
return
timed_region
(
"
matrix_assembly
"
,
action
)
"
{}.jacobian({},m);
"
.
format
(
n_go
,
v
),
"
HP_TIMER_STOP(matrix_assembly);
"
,
"
DUMP_TIMER({}, matrix_assembly, {}, true);
"
.
format
(
get_option
(
"
instrumentation_level
"
),
timestream
)]
assembly
.
extend
(
print_times
)
else
:
else
:
assembly
=
[
"
{}.jacobian({},m);
"
.
format
(
n_go
,
v
)]
return
[
action
]
assembly
=
[
"
using M = typename {}::Traits::Jacobian;
"
.
format
(
t_go
),
"
M m({});
"
.
format
(
n_go
)]
+
assembly
return
assembly
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