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
No related branches found
No related tags found
1 merge request!2Adding likwid markers
Pipeline #54698 skipped
......@@ -6,7 +6,7 @@ from jinja2 import Environment, PackageLoader, StrictUndefined
import numpy as np
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.typing import get_base_type
from pystencils.sympyextensions import prod
......@@ -98,7 +98,7 @@ def kernel_main(kernels_ast: List[KernelFunction], *,
Returns:
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 = []
includes = set()
for kernel in kernels_ast:
......@@ -107,6 +107,8 @@ def kernel_main(kernels_ast: List[KernelFunction], *,
constants = []
fields = []
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():
if not p.is_field_parameter:
constants.append((p.symbol.name, str(p.symbol.dtype)))
......@@ -139,8 +141,10 @@ def kernel_main(kernels_ast: List[KernelFunction], *,
align = 0
fields.append((p.field_name, dtype, elements, size, offset, align))
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,
call_argument_list=",".join(call_parameters)))
call_argument_list=",".join(call_parameters), openmp=openmp))
includes.add(name)
......
......@@ -39,6 +39,9 @@ int main(int argc, char **argv)
{% else %}
{{dataType}}* {{field_name}} = ({{dataType}} *) malloc({{size}});
{% endif %}
{% if kernel.openmp %}
#pragma omp parallel for schedule(static)
{% endif %}
for (unsigned long long i = 0; i < {{elements}}; ++i)
{{field_name}}[i] = 0.23;
{% endfor %}
......@@ -50,7 +53,14 @@ int main(int argc, char **argv)
{% endfor %}
{% if likwid %}
{% if kernel.openmp %}
#pragma omp parallel
{
{% endif %}
LIKWID_MARKER_REGISTER("{{kernel.name}}");
{% if kernel.openmp %}
}
{% endif %}
{% endif %}
for(int warmup = 1; warmup >= 0; --warmup) {
......@@ -58,7 +68,14 @@ int main(int argc, char **argv)
if(warmup == 0) {
repeat = n_repeat;
{% if likwid %}
{% if kernel.openmp %}
#pragma omp parallel
{
{% endif %}
LIKWID_MARKER_START("{{kernel.name}}");
{% if kernel.openmp %}
}
{% endif %}
{% endif %}
}
......@@ -80,13 +97,20 @@ int main(int argc, char **argv)
{% endif %}
}
{% for field_name, dataType, elements, size, offset, alignment in kernel.fields %}
free({{field_name}});
{% endfor %}
{% if likwid %}
{% if kernel.openmp %}
#pragma omp parallel
{
{% endif %}
LIKWID_MARKER_STOP("{{kernel.name}}");
{% if kernel.openmp %}
}
{% endif %}
{% endif %}
{% for field_name, dataType, elements, size, offset, alignment in kernel.fields %}
free({{field_name}});
{% endfor %}
}
{% endfor %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment