Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
pycodegen
pystencils
Commits
0998f2e1
Commit
0998f2e1
authored
May 03, 2019
by
Martin Bauer
Browse files
Kerncraft interface: update to work with kerncraft 0.8.0
parent
920a47d5
Pipeline
#15183
passed with stages
in 8 minutes and 41 seconds
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
pystencils/kerncraft_coupling/kerncraft_interface.py
View file @
0998f2e1
...
...
@@ -3,7 +3,7 @@ from tempfile import TemporaryDirectory
import
sympy
as
sp
from
collections
import
defaultdict
import
kerncraft
import
kerncraft.kerne
l
from
kerncraft.kern
craft
import
KernelCod
e
from
typing
import
Optional
from
kerncraft.machinemodel
import
MachineModel
...
...
@@ -16,7 +16,7 @@ from pystencils.utils import DotDict
import
warnings
class
PyStencilsKerncraftKernel
(
kerncraft
.
kernel
.
KernelCode
):
class
PyStencilsKerncraftKernel
(
KernelCode
):
"""
Implementation of kerncraft's kernel interface for pystencils CPU kernels.
Analyses a list of equations assuming they will be executed on a CPU
...
...
@@ -42,6 +42,7 @@ class PyStencilsKerncraftKernel(kerncraft.kernel.KernelCode):
self
.
kernel_ast
=
ast
self
.
temporary_dir
=
TemporaryDirectory
()
self
.
_keep_intermediates
=
debug_print
# Loops
inner_loops
=
[
l
for
l
in
filtered_tree_iteration
(
ast
,
LoopOverCoordinate
,
stop_type
=
SympyAssignment
)
...
...
@@ -127,14 +128,24 @@ class PyStencilsKerncraftKernel(kerncraft.kernel.KernelCode):
print
(
"----------------------------- FLOPS -------------------------------"
)
pprint
(
self
.
_flops
)
def
as_code
(
self
,
type_
=
'iaca'
,
openmp
=
False
):
def
as_code
(
self
,
type_
=
'iaca'
,
openmp
=
False
,
as_filename
=
False
):
"""
Generate and return compilable source code.
:param type: can be iaca or likwid.
:param openmp: if true, openmp code will be generated
Args:
type_: can be iaca or likwid.
openmp: if true, openmp code will be generated
as_filename:
"""
return
generate_benchmark
(
self
.
kernel_ast
,
likwid
=
type_
==
'likwid'
,
openmp
=
openmp
)
code
=
generate_benchmark
(
self
.
kernel_ast
,
likwid
=
type_
==
'likwid'
,
openmp
=
openmp
)
if
as_filename
:
fp
,
already_available
=
self
.
_get_intermediate_file
(
'kernel_{}.c'
.
format
(
type_
),
machine_and_compiler_dependent
=
False
)
if
not
already_available
:
fp
.
write
(
code
)
return
fp
.
name
else
:
return
code
class
KerncraftParameters
(
DotDict
):
...
...
pystencils_tests/test_kerncraft_coupling.py
View file @
0998f2e1
...
...
@@ -18,9 +18,12 @@ INPUT_FOLDER = os.path.join(SCRIPT_FOLDER, "kerncraft_inputs")
@
pytest
.
mark
.
kernkraft
def
test_compilation
():
machine_file_path
=
os
.
path
.
join
(
INPUT_FOLDER
,
"default_machine_file.yaml"
)
machine
=
MachineModel
(
path_to_yaml
=
machine_file_path
)
kernel_file_path
=
os
.
path
.
join
(
INPUT_FOLDER
,
"2d-5pt.c"
)
with
open
(
kernel_file_path
)
as
kernel_file
:
reference_kernel
=
KernelCode
(
kernel_file
.
read
(),
machine
=
No
ne
,
filename
=
kernel_file_path
)
reference_kernel
=
KernelCode
(
kernel_file
.
read
(),
machine
=
machi
ne
,
filename
=
kernel_file_path
)
reference_kernel
.
as_code
(
'likwid'
)
size
=
[
30
,
50
,
3
]
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment