Skip to content
Snippets Groups Projects
Commit b7c6dd59 authored by Christoph Alt's avatar Christoph Alt
Browse files

If openmp is used wrap the likwid markers calls in omp blocks

parent 2bf0e93f
1 merge request!2Adding likwid markers
Pipeline #54698 skipped with stage
...@@ -6,7 +6,7 @@ from jinja2 import Environment, PackageLoader, StrictUndefined ...@@ -6,7 +6,7 @@ from jinja2 import Environment, PackageLoader, StrictUndefined
import numpy as np import numpy as np
from pystencils.backends.cbackend import generate_c, get_headers from pystencils.backends.cbackend import generate_c, get_headers
from pystencils.astnodes import KernelFunction from pystencils.astnodes import KernelFunction, PragmaBlock
from pystencils.enums import Backend from pystencils.enums import Backend
from pystencils.typing import get_base_type from pystencils.typing import get_base_type
from pystencils.sympyextensions import prod from pystencils.sympyextensions import prod
...@@ -98,7 +98,7 @@ def kernel_main(kernels_ast: List[KernelFunction], *, ...@@ -98,7 +98,7 @@ def kernel_main(kernels_ast: List[KernelFunction], *,
Returns: Returns:
C code as string C code as string
""" """
Kernel = namedtuple('Kernel', ['name', 'constants', 'fields', 'call_parameters', 'call_argument_list']) Kernel = namedtuple('Kernel', ['name', 'constants', 'fields', 'call_parameters', 'call_argument_list', 'openmp'])
kernels = [] kernels = []
includes = set() includes = set()
for kernel in kernels_ast: for kernel in kernels_ast:
...@@ -107,6 +107,8 @@ def kernel_main(kernels_ast: List[KernelFunction], *, ...@@ -107,6 +107,8 @@ def kernel_main(kernels_ast: List[KernelFunction], *,
constants = [] constants = []
fields = [] fields = []
call_parameters = [] call_parameters = []
# TODO: Think about it maybe there is a better way to detect openmp
openmp = isinstance(kernel.body.args[0], PragmaBlock)
for p in kernel.get_parameters(): for p in kernel.get_parameters():
if not p.is_field_parameter: if not p.is_field_parameter:
constants.append((p.symbol.name, str(p.symbol.dtype))) constants.append((p.symbol.name, str(p.symbol.dtype)))
...@@ -139,8 +141,10 @@ def kernel_main(kernels_ast: List[KernelFunction], *, ...@@ -139,8 +141,10 @@ def kernel_main(kernels_ast: List[KernelFunction], *,
align = 0 align = 0
fields.append((p.field_name, dtype, elements, size, offset, align)) fields.append((p.field_name, dtype, elements, size, offset, align))
call_parameters.append(p.field_name) call_parameters.append(p.field_name)
# TODO: Think about openmp detection again
kernels.append(Kernel(name=name, fields=fields, constants=constants, call_parameters=call_parameters, kernels.append(Kernel(name=name, fields=fields, constants=constants, call_parameters=call_parameters,
call_argument_list=",".join(call_parameters))) call_argument_list=",".join(call_parameters), openmp=openmp))
includes.add(name) includes.add(name)
......
...@@ -39,6 +39,9 @@ int main(int argc, char **argv) ...@@ -39,6 +39,9 @@ int main(int argc, char **argv)
{% else %} {% else %}
{{dataType}}* {{field_name}} = ({{dataType}} *) malloc({{size}}); {{dataType}}* {{field_name}} = ({{dataType}} *) malloc({{size}});
{% endif %} {% endif %}
{% if kernel.openmp %}
#pragma omp parallel for schedule(static)
{% endif %}
for (unsigned long long i = 0; i < {{elements}}; ++i) for (unsigned long long i = 0; i < {{elements}}; ++i)
{{field_name}}[i] = 0.23; {{field_name}}[i] = 0.23;
{% endfor %} {% endfor %}
...@@ -50,7 +53,14 @@ int main(int argc, char **argv) ...@@ -50,7 +53,14 @@ int main(int argc, char **argv)
{% endfor %} {% endfor %}
{% if likwid %} {% if likwid %}
{% if kernel.openmp %}
#pragma omp parallel
{
{% endif %}
LIKWID_MARKER_REGISTER("{{kernel.name}}"); LIKWID_MARKER_REGISTER("{{kernel.name}}");
{% if kernel.openmp %}
}
{% endif %}
{% endif %} {% endif %}
for(int warmup = 1; warmup >= 0; --warmup) { for(int warmup = 1; warmup >= 0; --warmup) {
...@@ -58,7 +68,14 @@ int main(int argc, char **argv) ...@@ -58,7 +68,14 @@ int main(int argc, char **argv)
if(warmup == 0) { if(warmup == 0) {
repeat = n_repeat; repeat = n_repeat;
{% if likwid %} {% if likwid %}
{% if kernel.openmp %}
#pragma omp parallel
{
{% endif %}
LIKWID_MARKER_START("{{kernel.name}}"); LIKWID_MARKER_START("{{kernel.name}}");
{% if kernel.openmp %}
}
{% endif %}
{% endif %} {% endif %}
} }
...@@ -80,13 +97,20 @@ int main(int argc, char **argv) ...@@ -80,13 +97,20 @@ int main(int argc, char **argv)
{% endif %} {% endif %}
} }
{% for field_name, dataType, elements, size, offset, alignment in kernel.fields %}
free({{field_name}});
{% endfor %}
{% if likwid %} {% if likwid %}
{% if kernel.openmp %}
#pragma omp parallel
{
{% endif %}
LIKWID_MARKER_STOP("{{kernel.name}}"); LIKWID_MARKER_STOP("{{kernel.name}}");
{% if kernel.openmp %}
}
{% endif %}
{% endif %} {% endif %}
{% for field_name, dataType, elements, size, offset, alignment in kernel.fields %}
free({{field_name}});
{% endfor %}
} }
{% endfor %} {% endfor %}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment