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
Model registry
Operate
Environments
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
pycodegen
pystencils
Commits
ba316525
Commit
ba316525
authored
6 years ago
by
Julian Hammer
Browse files
Options
Downloads
Patches
Plain Diff
simplified kerncraft interface
parent
ed4bb4c7
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
pystencils/kerncraft_coupling/kerncraft_interface.py
+15
-60
15 additions, 60 deletions
pystencils/kerncraft_coupling/kerncraft_interface.py
with
15 additions
and
60 deletions
pystencils/kerncraft_coupling/kerncraft_interface.py
+
15
−
60
View file @
ba316525
...
@@ -19,7 +19,7 @@ from pystencils.utils import DotDict
...
@@ -19,7 +19,7 @@ from pystencils.utils import DotDict
import
warnings
import
warnings
class
PyStencilsKerncraftKernel
(
kerncraft
.
kernel
.
Kernel
):
class
PyStencilsKerncraftKernel
(
kerncraft
.
kernel
.
Kernel
Code
):
"""
"""
Implementation of kerncraft
'
s kernel interface for pystencils CPU kernels.
Implementation of kerncraft
'
s kernel interface for pystencils CPU kernels.
Analyses a list of equations assuming they will be executed on a CPU
Analyses a list of equations assuming they will be executed on a CPU
...
@@ -37,9 +37,13 @@ class PyStencilsKerncraftKernel(kerncraft.kernel.Kernel):
...
@@ -37,9 +37,13 @@ class PyStencilsKerncraftKernel(kerncraft.kernel.Kernel):
coordinates is not known. In this case either a structures of array (SoA) or
coordinates is not known. In this case either a structures of array (SoA) or
array of structures (AoS) layout is assumed
array of structures (AoS) layout is assumed
"""
"""
super
(
PyStencilsK
erncraft
K
ernel
,
self
)
.
__init__
(
machine
)
k
erncraft
.
k
ernel
.
Kernel
.
__init__
(
self
,
machine
)
self
.
ast
=
ast
# Initialize state
self
.
asm_block
=
None
self
.
_filename
=
None
self
.
kernel_ast
=
ast
self
.
temporary_dir
=
TemporaryDirectory
()
self
.
temporary_dir
=
TemporaryDirectory
()
# Loops
# Loops
...
@@ -123,63 +127,14 @@ class PyStencilsKerncraftKernel(kerncraft.kernel.Kernel):
...
@@ -123,63 +127,14 @@ class PyStencilsKerncraftKernel(kerncraft.kernel.Kernel):
print
(
"
----------------------------- FLOPS -------------------------------
"
)
print
(
"
----------------------------- FLOPS -------------------------------
"
)
pprint
(
self
.
_flops
)
pprint
(
self
.
_flops
)
def
iaca_analysis
(
self
,
micro_architecture
,
asm_block
=
'
auto
'
,
def
as_code
(
self
,
type_
=
'
iaca
'
,
openmp
=
False
):
pointer_increment
=
'
auto_with_manual_fallback
'
,
verbose
=
False
):
"""
compiler
,
compiler_args
=
self
.
_machine
.
get_compiler
()
Generate and return compilable source code.
if
'
-std=c99
'
not
in
compiler_args
:
compiler_args
+=
[
'
-std=c99
'
]
:param type: can be iaca or likwid.
header_path
=
kerncraft
.
get_header_path
()
:param openmp: if true, openmp code will be generated
"""
compiler_cmd
=
[
compiler
]
+
compiler_args
+
[
'
-I
'
+
header_path
]
return
generate_benchmark
(
self
.
kernel_ast
,
likwid
=
type_
==
'
likwid
'
)
src_file
=
os
.
path
.
join
(
self
.
temporary_dir
.
name
,
"
source.c
"
)
asm_file
=
os
.
path
.
join
(
self
.
temporary_dir
.
name
,
"
source.s
"
)
iaca_asm_file
=
os
.
path
.
join
(
self
.
temporary_dir
.
name
,
"
source.iaca.s
"
)
dummy_src_file
=
os
.
path
.
join
(
header_path
,
"
dummy.c
"
)
dummy_asm_file
=
os
.
path
.
join
(
self
.
temporary_dir
.
name
,
"
dummy.s
"
)
binary_file
=
os
.
path
.
join
(
self
.
temporary_dir
.
name
,
"
binary
"
)
# write source code to file
with
open
(
src_file
,
'
w
'
)
as
f
:
f
.
write
(
generate_benchmark
(
self
.
ast
,
likwid
=
False
))
# compile to asm files
subprocess
.
check_output
(
compiler_cmd
+
[
src_file
,
'
-S
'
,
'
-o
'
,
asm_file
])
subprocess
.
check_output
(
compiler_cmd
+
[
dummy_src_file
,
'
-S
'
,
'
-o
'
,
dummy_asm_file
])
with
open
(
asm_file
)
as
read
,
open
(
iaca_asm_file
,
'
w
'
)
as
write
:
instrumented_asm_block
=
iaca_instrumentation
(
read
,
write
)
# assemble asm files to executable
subprocess
.
check_output
(
compiler_cmd
+
[
iaca_asm_file
,
dummy_asm_file
,
'
-o
'
,
binary_file
])
result
=
iaca_analyse_instrumented_binary
(
binary_file
,
micro_architecture
)
return
result
,
instrumented_asm_block
def
build
(
self
,
lflags
=
None
,
verbose
=
False
,
openmp
=
False
):
# TODO do we use openmp or not???
compiler
,
compiler_args
=
self
.
_machine
.
get_compiler
()
if
'
-std=c99
'
not
in
compiler_args
:
compiler_args
.
append
(
'
-std=c99
'
)
header_path
=
kerncraft
.
get_header_path
()
cmd
=
[
compiler
]
+
compiler_args
+
[
'
-I
'
+
os
.
path
.
join
(
self
.
LIKWID_BASE
,
'
include
'
),
'
-L
'
+
os
.
path
.
join
(
self
.
LIKWID_BASE
,
'
lib
'
),
'
-I
'
+
header_path
,
'
-Wl,-rpath=
'
+
os
.
path
.
join
(
self
.
LIKWID_BASE
,
'
lib
'
),
]
dummy_src_file
=
os
.
path
.
join
(
header_path
,
'
dummy.c
'
)
src_file
=
os
.
path
.
join
(
self
.
temporary_dir
.
name
,
"
source_likwid.c
"
)
bin_file
=
os
.
path
.
join
(
self
.
temporary_dir
.
name
,
"
benchmark
"
)
with
open
(
src_file
,
'
w
'
)
as
f
:
f
.
write
(
generate_benchmark
(
self
.
ast
,
likwid
=
True
))
subprocess
.
check_output
(
cmd
+
[
src_file
,
dummy_src_file
,
'
-pthread
'
,
'
-llikwid
'
,
'
-o
'
,
bin_file
])
return
bin_file
class
KerncraftParameters
(
DotDict
):
class
KerncraftParameters
(
DotDict
):
...
...
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