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

adding support for the likwid marker api

parent 7a44d4fa
No related branches found
No related tags found
1 merge request!2Adding likwid markers
...@@ -22,7 +22,8 @@ _env = Environment(loader=PackageLoader('pystencils_benchmark'), undefined=Stric ...@@ -22,7 +22,8 @@ _env = Environment(loader=PackageLoader('pystencils_benchmark'), undefined=Stric
def generate_benchmark(kernel_asts: Union[KernelFunction, List[KernelFunction]], def generate_benchmark(kernel_asts: Union[KernelFunction, List[KernelFunction]],
path: Path = None, path: Path = None,
*, *,
compiler: Compiler = Compiler.GCC) -> None: compiler: Compiler = Compiler.GCC,
likwid: bool = False) -> None:
if path is None: if path is None:
path = Path('.') path = Path('.')
else: else:
...@@ -47,16 +48,17 @@ def generate_benchmark(kernel_asts: Union[KernelFunction, List[KernelFunction]], ...@@ -47,16 +48,17 @@ def generate_benchmark(kernel_asts: Union[KernelFunction, List[KernelFunction]],
f.write(source) f.write(source)
with open(src_path / 'main.c', 'w+') as f: with open(src_path / 'main.c', 'w+') as f:
f.write(kernel_main(kernel_asts)) f.write(kernel_main(kernel_asts, likwid=likwid))
copy_static_files(path) copy_static_files(path)
compiler_toolchain(path, compiler) compiler_toolchain(path, compiler, likwid)
def compiler_toolchain(path: Path, compiler: Compiler) -> None: def compiler_toolchain(path: Path, compiler: Compiler, likwid: bool) -> None:
name = compiler.name name = compiler.name
jinja_context = { jinja_context = {
'compiler': name, 'compiler': name,
'likwid': likwid,
} }
files = ['Makefile', f'{name}.mk'] files = ['Makefile', f'{name}.mk']
...@@ -85,7 +87,8 @@ def copy_static_files(path: Path) -> None: ...@@ -85,7 +87,8 @@ def copy_static_files(path: Path) -> None:
f.write(template) f.write(template)
def kernel_main(kernels_ast: List[KernelFunction], timing: bool = True): def kernel_main(kernels_ast: List[KernelFunction], *,
timing: bool = True, likwid: bool = False) -> str:
""" """
Return C code of a benchmark program for the given kernel. Return C code of a benchmark program for the given kernel.
...@@ -145,6 +148,7 @@ def kernel_main(kernels_ast: List[KernelFunction], timing: bool = True): ...@@ -145,6 +148,7 @@ def kernel_main(kernels_ast: List[KernelFunction], timing: bool = True):
'kernels': kernels, 'kernels': kernels,
'includes': includes, 'includes': includes,
'timing': timing, 'timing': timing,
'likwid': likwid,
} }
main = _env.get_template('main.c').render(**jinja_context) main = _env.get_template('main.c').render(**jinja_context)
......
...@@ -7,10 +7,25 @@ SRC_DIR = ./src ...@@ -7,10 +7,25 @@ SRC_DIR = ./src
MAKE_DIR = ./ MAKE_DIR = ./
Q ?= @ Q ?= @
{% if likwid %}
# LIKWID DEFINES
LIKWID_DEFINES := -DLIKWID_PERFMON
LIKWID_PATH = $(shell dirname $(shell which likwid-perfctr))
LIKWID_LIB := -L$(LIKWID_PATH)/../lib/
LIKWID_INC := -I$(LIKWID_PATH)/../include/
{% endif %}
#DO NOT EDIT BELOW #DO NOT EDIT BELOW
include $(MAKE_DIR)/$(TAG).mk include $(MAKE_DIR)/$(TAG).mk
INCLUDES += -I./include INCLUDES += -I./include
{% if likwid %}
INCLUDES += $(LIKWID_INC)
DEFINES += $(LIKWID_DEFINES)
LFLAGS += $(LIKWID_LIB)
LIBS += -llikwid
{% endif %}
VPATH = $(SRC_DIR) VPATH = $(SRC_DIR)
ASM = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.s,$(wildcard $(SRC_DIR)/*.c)) ASM = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.s,$(wildcard $(SRC_DIR)/*.c))
OBJ = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o,$(wildcard $(SRC_DIR)/*.c)) OBJ = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o,$(wildcard $(SRC_DIR)/*.c))
......
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
#include <stdlib.h> #include <stdlib.h>
#include "timing.h" #include "timing.h"
{% if likwid %}
#include <likwid-marker.h>
{% endif %}
//kernels //kernels
{% for include in includes %} {% for include in includes %}
...@@ -22,6 +25,10 @@ int main(int argc, char **argv) ...@@ -22,6 +25,10 @@ int main(int argc, char **argv)
return -1; return -1;
} }
int n_repeat = atoi(argv[1]); int n_repeat = atoi(argv[1]);
{% if likwid %}
LIKWID_MARKER_INIT;
{%- endif %}
{% for kernel in kernels %} {% for kernel in kernels %}
{ // Kernel: {{kernel.name}} { // Kernel: {{kernel.name}}
...@@ -42,10 +49,17 @@ int main(int argc, char **argv) ...@@ -42,10 +49,17 @@ int main(int argc, char **argv)
{{constantName}} = 0.23; {{constantName}} = 0.23;
{% endfor %} {% endfor %}
{% if likwid %}
LIKWID_MARKER_REGISTER("{{kernel.name}}");
{% endif %}
for(int warmup = 1; warmup >= 0; --warmup) { for(int warmup = 1; warmup >= 0; --warmup) {
int repeat = 2; int repeat = 2;
if(warmup == 0) { if(warmup == 0) {
repeat = n_repeat; repeat = n_repeat;
{% if likwid %}
LIKWID_MARKER_START("{{kernel.name}}");
{% endif %}
} }
{% if timing %} {% if timing %}
...@@ -65,9 +79,18 @@ int main(int argc, char **argv) ...@@ -65,9 +79,18 @@ int main(int argc, char **argv)
printf("%s\t%e\n", "{{kernel.name}}",(wcEndTime - wcStartTime) / n_repeat ); printf("%s\t%e\n", "{{kernel.name}}",(wcEndTime - wcStartTime) / n_repeat );
{% endif %} {% endif %}
} }
{% for field_name, dataType, elements, size, offset, alignment in kernel.fields %} {% for field_name, dataType, elements, size, offset, alignment in kernel.fields %}
free({{field_name}}); free({{field_name}});
{% endfor %} {% endfor %}
{% if likwid %}
LIKWID_MARKER_STOP("{{kernel.name}}");
{% endif %}
} }
{% endfor %} {% endfor %}
{% if likwid %}
LIKWID_MARKER_CLOSE;
{% endif %}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment