Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pystencils
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
Package registry
Model registry
Operate
Environments
Terraform modules
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sebastian Bindgen
pystencils
Commits
0391c91d
Commit
0391c91d
authored
4 years ago
by
Markus Holzer
Browse files
Options
Downloads
Patches
Plain Diff
Replaced os.path with pathlib in kerncraft interface
parent
15dcdab3
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pystencils/kerncraft_coupling/generate_benchmark.py
+13
-10
13 additions, 10 deletions
pystencils/kerncraft_coupling/generate_benchmark.py
pystencils_tests/test_kerncraft_coupling.py
+11
-11
11 additions, 11 deletions
pystencils_tests/test_kerncraft_coupling.py
with
24 additions
and
21 deletions
pystencils/kerncraft_coupling/generate_benchmark.py
+
13
−
10
View file @
0391c91d
import
os
import
subprocess
import
subprocess
import
warnings
import
warnings
import
tempfile
import
tempfile
from
pathlib
import
Path
from
jinja2
import
Environment
,
PackageLoader
,
StrictUndefined
from
jinja2
import
Environment
,
PackageLoader
,
StrictUndefined
...
@@ -85,25 +85,28 @@ def run_c_benchmark(ast, inner_iterations, outer_iterations=3, path=None):
...
@@ -85,25 +85,28 @@ def run_c_benchmark(ast, inner_iterations, outer_iterations=3, path=None):
if
path
is
None
:
if
path
is
None
:
path
=
tempfile
.
mkdtemp
()
path
=
tempfile
.
mkdtemp
()
with
open
(
os
.
path
.
join
(
path
,
'
bench.c
'
),
'
w
'
)
as
f
:
if
isinstance
(
path
,
str
):
path
=
Path
(
path
)
with
open
(
path
/
'
bench.c
'
,
'
w
'
)
as
f
:
f
.
write
(
benchmark_code
)
f
.
write
(
benchmark_code
)
kerncraft_path
=
os
.
path
.
dirname
(
kerncraft
.
__file__
)
kerncraft_path
=
Path
(
kerncraft
.
__file__
)
.
parent
extra_flags
=
[
'
-I
'
+
get_pystencils_include_path
(),
extra_flags
=
[
'
-I
'
+
get_pystencils_include_path
(),
'
-I
'
+
os
.
path
.
join
(
kerncraft_path
,
'
headers
'
)]
'
-I
'
+
str
(
kerncraft_path
/
'
headers
'
)]
compiler_config
=
get_compiler_config
()
compiler_config
=
get_compiler_config
()
compile_cmd
=
[
compiler_config
[
'
command
'
]]
+
compiler_config
[
'
flags
'
].
split
()
compile_cmd
=
[
compiler_config
[
'
command
'
]]
+
compiler_config
[
'
flags
'
].
split
()
compile_cmd
+=
[
*
extra_flags
,
compile_cmd
+=
[
*
extra_flags
,
os
.
path
.
join
(
kerncraft_path
,
'
headers
'
,
'
timing.c
'
)
,
kerncraft_path
/
'
headers
'
/
'
timing.c
'
,
os
.
path
.
join
(
kerncraft_path
,
'
headers
'
,
'
dummy.c
'
)
,
kerncraft_path
/
'
headers
'
/
'
dummy.c
'
,
os
.
path
.
join
(
path
,
'
bench.c
'
)
,
path
/
'
bench.c
'
,
'
-o
'
,
os
.
path
.
join
(
path
,
'
bench
'
)
,
'
-o
'
,
path
/
'
bench
'
,
]
]
run_compile_step
(
compile_cmd
)
run_compile_step
(
compile_cmd
)
time_pre_estimation_per_iteration
=
float
(
subprocess
.
check_output
([
os
.
path
.
join
(
'
./
'
,
path
,
'
bench
'
)
,
str
(
10
)]))
time_pre_estimation_per_iteration
=
float
(
subprocess
.
check_output
([
'
./
'
/
path
/
'
bench
'
,
str
(
10
)]))
benchmark_time_limit
=
20
benchmark_time_limit
=
20
if
benchmark_time_limit
/
time_pre_estimation_per_iteration
<
inner_iterations
:
if
benchmark_time_limit
/
time_pre_estimation_per_iteration
<
inner_iterations
:
warn
=
(
f
"
A benchmark run with
{
inner_iterations
}
inner_iterations will probably take longer than
"
warn
=
(
f
"
A benchmark run with
{
inner_iterations
}
inner_iterations will probably take longer than
"
...
@@ -112,6 +115,6 @@ def run_c_benchmark(ast, inner_iterations, outer_iterations=3, path=None):
...
@@ -112,6 +115,6 @@ def run_c_benchmark(ast, inner_iterations, outer_iterations=3, path=None):
results
=
[]
results
=
[]
for
_
in
range
(
outer_iterations
):
for
_
in
range
(
outer_iterations
):
benchmark_time
=
float
(
subprocess
.
check_output
([
os
.
path
.
join
(
'
./
'
,
path
,
'
bench
'
)
,
str
(
inner_iterations
)]))
benchmark_time
=
float
(
subprocess
.
check_output
([
'
./
'
/
path
/
'
bench
'
,
str
(
inner_iterations
)]))
results
.
append
(
benchmark_time
)
results
.
append
(
benchmark_time
)
return
results
return
results
This diff is collapsed.
Click to expand it.
pystencils_tests/test_kerncraft_coupling.py
+
11
−
11
View file @
0391c91d
import
os
import
numpy
as
np
import
numpy
as
np
import
pytest
import
pytest
import
sympy
as
sp
import
sympy
as
sp
from
pathlib
import
Path
from
kerncraft.kernel
import
KernelCode
from
kerncraft.kernel
import
KernelCode
from
kerncraft.machinemodel
import
MachineModel
from
kerncraft.machinemodel
import
MachineModel
...
@@ -13,16 +13,16 @@ from pystencils.kerncraft_coupling import KerncraftParameters, PyStencilsKerncra
...
@@ -13,16 +13,16 @@ from pystencils.kerncraft_coupling import KerncraftParameters, PyStencilsKerncra
from
pystencils.kerncraft_coupling.generate_benchmark
import
generate_benchmark
,
run_c_benchmark
from
pystencils.kerncraft_coupling.generate_benchmark
import
generate_benchmark
,
run_c_benchmark
from
pystencils.timeloop
import
TimeLoop
from
pystencils.timeloop
import
TimeLoop
SCRIPT_FOLDER
=
os
.
path
.
dirname
(
os
.
path
.
realp
ath
(
__file__
)
)
SCRIPT_FOLDER
=
P
ath
(
__file__
)
.
parent
INPUT_FOLDER
=
os
.
path
.
join
(
SCRIPT_FOLDER
,
"
kerncraft_inputs
"
)
INPUT_FOLDER
=
SCRIPT_FOLDER
/
"
kerncraft_inputs
"
@pytest.mark.kerncraft
@pytest.mark.kerncraft
def
test_compilation
():
def
test_compilation
():
machine_file_path
=
os
.
path
.
join
(
INPUT_FOLDER
,
"
Example_SandyBridgeEP_E5-2680.yml
"
)
machine_file_path
=
INPUT_FOLDER
/
"
Example_SandyBridgeEP_E5-2680.yml
"
machine
=
MachineModel
(
path_to_yaml
=
machine_file_path
)
machine
=
MachineModel
(
path_to_yaml
=
machine_file_path
)
kernel_file_path
=
os
.
path
.
join
(
INPUT_FOLDER
,
"
2d-5pt.c
"
)
kernel_file_path
=
INPUT_FOLDER
/
"
2d-5pt.c
"
with
open
(
kernel_file_path
)
as
kernel_file
:
with
open
(
kernel_file_path
)
as
kernel_file
:
reference_kernel
=
KernelCode
(
kernel_file
.
read
(),
machine
=
machine
,
filename
=
kernel_file_path
)
reference_kernel
=
KernelCode
(
kernel_file
.
read
(),
machine
=
machine
,
filename
=
kernel_file_path
)
reference_kernel
.
get_kernel_header
(
name
=
'
test_kernel
'
)
reference_kernel
.
get_kernel_header
(
name
=
'
test_kernel
'
)
...
@@ -43,7 +43,7 @@ def test_compilation():
...
@@ -43,7 +43,7 @@ def test_compilation():
@pytest.mark.kerncraft
@pytest.mark.kerncraft
def
analysis
(
kernel
,
model
=
'
ecmdata
'
):
def
analysis
(
kernel
,
model
=
'
ecmdata
'
):
machine_file_path
=
os
.
path
.
join
(
INPUT_FOLDER
,
"
Example_SandyBridgeEP_E5-2680.yml
"
)
machine_file_path
=
INPUT_FOLDER
/
"
Example_SandyBridgeEP_E5-2680.yml
"
machine
=
MachineModel
(
path_to_yaml
=
machine_file_path
)
machine
=
MachineModel
(
path_to_yaml
=
machine_file_path
)
if
model
==
'
ecmdata
'
:
if
model
==
'
ecmdata
'
:
model
=
ECMData
(
kernel
,
machine
,
KerncraftParameters
())
model
=
ECMData
(
kernel
,
machine
,
KerncraftParameters
())
...
@@ -63,8 +63,8 @@ def analysis(kernel, model='ecmdata'):
...
@@ -63,8 +63,8 @@ def analysis(kernel, model='ecmdata'):
def
test_3d_7pt_osaca
():
def
test_3d_7pt_osaca
():
size
=
[
20
,
200
,
200
]
size
=
[
20
,
200
,
200
]
kernel_file_path
=
os
.
path
.
join
(
INPUT_FOLDER
,
"
3d-7pt.c
"
)
kernel_file_path
=
INPUT_FOLDER
/
"
3d-7pt.c
"
machine_file_path
=
os
.
path
.
join
(
INPUT_FOLDER
,
"
Example_SandyBridgeEP_E5-2680.yml
"
)
machine_file_path
=
INPUT_FOLDER
/
"
Example_SandyBridgeEP_E5-2680.yml
"
machine_model
=
MachineModel
(
path_to_yaml
=
machine_file_path
)
machine_model
=
MachineModel
(
path_to_yaml
=
machine_file_path
)
with
open
(
kernel_file_path
)
as
kernel_file
:
with
open
(
kernel_file_path
)
as
kernel_file
:
reference_kernel
=
KernelCode
(
kernel_file
.
read
(),
machine
=
machine_model
,
filename
=
kernel_file_path
)
reference_kernel
=
KernelCode
(
kernel_file
.
read
(),
machine
=
machine_model
,
filename
=
kernel_file_path
)
...
@@ -90,7 +90,7 @@ def test_3d_7pt_osaca():
...
@@ -90,7 +90,7 @@ def test_3d_7pt_osaca():
@pytest.mark.kerncraft
@pytest.mark.kerncraft
def
test_2d_5pt
():
def
test_2d_5pt
():
size
=
[
30
,
50
,
3
]
size
=
[
30
,
50
,
3
]
kernel_file_path
=
os
.
path
.
join
(
INPUT_FOLDER
,
"
2d-5pt.c
"
)
kernel_file_path
=
INPUT_FOLDER
/
"
2d-5pt.c
"
with
open
(
kernel_file_path
)
as
kernel_file
:
with
open
(
kernel_file_path
)
as
kernel_file
:
reference_kernel
=
KernelCode
(
kernel_file
.
read
(),
machine
=
None
,
filename
=
kernel_file_path
)
reference_kernel
=
KernelCode
(
kernel_file
.
read
(),
machine
=
None
,
filename
=
kernel_file_path
)
reference
=
analysis
(
reference_kernel
)
reference
=
analysis
(
reference_kernel
)
...
@@ -112,7 +112,7 @@ def test_2d_5pt():
...
@@ -112,7 +112,7 @@ def test_2d_5pt():
@pytest.mark.kerncraft
@pytest.mark.kerncraft
def
test_3d_7pt
():
def
test_3d_7pt
():
size
=
[
30
,
50
,
50
]
size
=
[
30
,
50
,
50
]
kernel_file_path
=
os
.
path
.
join
(
INPUT_FOLDER
,
"
3d-7pt.c
"
)
kernel_file_path
=
INPUT_FOLDER
/
"
3d-7pt.c
"
with
open
(
kernel_file_path
)
as
kernel_file
:
with
open
(
kernel_file_path
)
as
kernel_file
:
reference_kernel
=
KernelCode
(
kernel_file
.
read
(),
machine
=
None
,
filename
=
kernel_file_path
)
reference_kernel
=
KernelCode
(
kernel_file
.
read
(),
machine
=
None
,
filename
=
kernel_file_path
)
reference_kernel
.
set_constant
(
'
M
'
,
size
[
0
])
reference_kernel
.
set_constant
(
'
M
'
,
size
[
0
])
...
@@ -158,4 +158,4 @@ def test_benchmark():
...
@@ -158,4 +158,4 @@ def test_benchmark():
timeloop_time
=
timeloop
.
benchmark
(
number_of_time_steps_for_estimation
=
1
)
timeloop_time
=
timeloop
.
benchmark
(
number_of_time_steps_for_estimation
=
1
)
np
.
testing
.
assert_almost_equal
(
c_benchmark_run
,
timeloop_time
,
decimal
=
5
)
np
.
testing
.
assert_almost_equal
(
c_benchmark_run
,
timeloop_time
,
decimal
=
4
)
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