From c929ec4ffee197461489c91df8ec1aa827c68854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B6nig?= <jan.hoenig@fau.de> Date: Tue, 9 Nov 2021 19:09:20 +0100 Subject: [PATCH] WIP. TODO get rid of C++. Compile with C99 --- pystencils_benchmark/benchmark.py | 33 ++++++++- pystencils_benchmark/headers/dummy.c | 2 - pystencils_benchmark/headers/dummy.s | 45 ------------- pystencils_benchmark/templates/Makefile | 67 +++++++++++++++++++ .../aligned_malloc.h} | 7 +- .../templates/include_Clang.mk | 24 +++++++ pystencils_benchmark/templates/include_GCC.mk | 24 +++++++ pystencils_benchmark/templates/include_ICC.mk | 14 ++++ pystencils_benchmark/templates/kernel.h | 5 ++ .../templates/kernel_pystencils.c | 18 ----- .../templates/kernel_pystencils.h | 3 - pystencils_benchmark/templates/main.c | 66 ------------------ .../{headers => templates}/timing.c | 0 .../{headers => templates}/timing.h | 7 +- test.ipynb | 36 +++------- 15 files changed, 183 insertions(+), 168 deletions(-) delete mode 100644 pystencils_benchmark/headers/dummy.c delete mode 100644 pystencils_benchmark/headers/dummy.s create mode 100644 pystencils_benchmark/templates/Makefile rename pystencils_benchmark/{headers/kerncraft.h => templates/aligned_malloc.h} (82%) create mode 100644 pystencils_benchmark/templates/include_Clang.mk create mode 100644 pystencils_benchmark/templates/include_GCC.mk create mode 100644 pystencils_benchmark/templates/include_ICC.mk delete mode 100644 pystencils_benchmark/templates/kernel_pystencils.c delete mode 100644 pystencils_benchmark/templates/kernel_pystencils.h rename pystencils_benchmark/{headers => templates}/timing.c (100%) rename pystencils_benchmark/{headers => templates}/timing.h (79%) diff --git a/pystencils_benchmark/benchmark.py b/pystencils_benchmark/benchmark.py index 887913f..f3658df 100644 --- a/pystencils_benchmark/benchmark.py +++ b/pystencils_benchmark/benchmark.py @@ -37,6 +37,29 @@ def generate_benchmark(kernel_ast: KernelFunction, with open(src_path / 'main.c', 'w+') as f: f.write(kernel_main(kernel_ast)) + copy_static_files(path) + + +def copy_static_files(path: Path) -> None: + src_path = path / 'src' + src_path.mkdir(parents=True, exist_ok=True) + include_path = path / 'include' + include_path.mkdir(parents=True, exist_ok=True) + + env = Environment(loader=PackageLoader('pystencils_benchmark'), undefined=StrictUndefined) + files = ['Makefile', 'aligned_malloc.h', 'timing.h', 'timing.c', 'include_Clang.mk', 'include_GCC.mk', + 'include_ICC.mk'] + for file_name in files: + template = env.get_template(file_name).render() + if file_name[-1] == 'h': + target_path = include_path / file_name + elif file_name[-1] == 'c': + target_path = src_path / file_name + else: + target_path = path / file_name + with open(target_path, 'w+') as f: + f.write(template) + def kernel_main(kernel: KernelFunction, timing: bool = False): """ @@ -86,7 +109,7 @@ def kernel_main(kernel: KernelFunction, timing: bool = False): fields.append((p.field_name, dtype, elements, size, 0, 0)) call_parameters.append(p.field_name) - includes = f'#include "{kernel_name}"\n' + includes = f'#include "{kernel_name}.h"\n' jinja_context = { 'kernel_code': generate_c(kernel, dialect=Backend.C), 'kernel_name': kernel_name, @@ -104,8 +127,10 @@ def kernel_main(kernel: KernelFunction, timing: bool = False): def kernel_header(kernel_ast: KernelFunction, dialect: Backend = Backend.C) -> str: function_signature = generate_c(kernel_ast, dialect=dialect, signature_only=True) + header_guard = f'_{kernel_ast.function_name.upper()}_H' jinja_context = { + 'header_guard': header_guard, 'function_signature': function_signature, } @@ -118,7 +143,11 @@ def kernel_source(kernel_ast: KernelFunction, dialect: Backend = Backend.C) -> s kernel_name = kernel_ast.function_name function_source = generate_c(kernel_ast, dialect=dialect) headers = get_headers(kernel_ast) - headers.add(f'"{kernel_name}.h"') + # TODO remove this after pystencils update + if isinstance(headers, list): + headers.append(f'"{kernel_name}.h"') + else: + headers.add(f'"{kernel_name}.h"') jinja_context = { 'function_source': function_source, diff --git a/pystencils_benchmark/headers/dummy.c b/pystencils_benchmark/headers/dummy.c deleted file mode 100644 index a9b0070..0000000 --- a/pystencils_benchmark/headers/dummy.c +++ /dev/null @@ -1,2 +0,0 @@ -void dummy(void* a) {} -int var_false = 0; diff --git a/pystencils_benchmark/headers/dummy.s b/pystencils_benchmark/headers/dummy.s deleted file mode 100644 index 084f2f6..0000000 --- a/pystencils_benchmark/headers/dummy.s +++ /dev/null @@ -1,45 +0,0 @@ -# mark_description "Intel(R) C Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 14.0.0.074 Build 2013071"; -# mark_description "6"; -# mark_description "-std=c99 -S -xHost -O3 -fno-alias -restrict"; - .file "dummy.c" - .section __TEXT, __text -L_TXTST0: -# -- Begin _dummy -# mark_begin; - .align 4 - .globl _dummy -_dummy: -# parameter 1: %rdi -L_B1.1: # Preds L_B1.0 -L____tag_value__dummy.1: #1.23 - ret #1.24 - .align 4 -L____tag_value__dummy.3: # - # LOE -# mark_end; - .section __DATA, __data -# -- End _dummy - .section __DATA, __data - .globl _dummy.eh -// -- Begin SEGMENT __eh_frame - .section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support -__eh_frame_seg: -L.__eh_frame_seg: -EH_frame0: -L_fde_cie_0: - .long 0x00000014 - .long 0x00000000 - .long 0x00527a01 - .long 0x01107801 - .long 0x08070c10 - .long 0x01900190 -_dummy.eh: - .long 0x0000001c - .long _dummy.eh-L_fde_cie_0+0x4 - .quad L____tag_value__dummy.1-_dummy.eh-0x8 - .set L_Qlab1,L____tag_value__dummy.3-L____tag_value__dummy.1 - .quad L_Qlab1 - .long 0x00000000 - .long 0x00000000 -# End - .subsections_via_symbols diff --git a/pystencils_benchmark/templates/Makefile b/pystencils_benchmark/templates/Makefile new file mode 100644 index 0000000..5490559 --- /dev/null +++ b/pystencils_benchmark/templates/Makefile @@ -0,0 +1,67 @@ +TAG = GCC + +#CONFIGURE BUILD SYSTEM +TARGET = benchmark-$(TAG) +BUILD_DIR = ./$(TAG) +SRC_DIR = ./src +MAKE_DIR = ./ +Q ?= @ + +#DO NOT EDIT BELOW +include $(MAKE_DIR)/include_$(TAG).mk +INCLUDES += -I./include + +VPATH = $(SRC_DIR) +ASM = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.s,$(wildcard $(SRC_DIR)/*.c)) +OBJ = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o,$(wildcard $(SRC_DIR)/*.c)) +CPPFLAGS := $(CPPFLAGS) $(DEFINES) $(INCLUDES) + + +${TARGET}: $(BUILD_DIR) $(OBJ) + @echo "===> LINKING $(TARGET)" + $(Q)${LINKER} ${LFLAGS} -o $(TARGET) $(OBJ) $(LIBS) + +asm: $(BUILD_DIR) $(ASM) + +$(BUILD_DIR)/%.o: %.c + @echo "===> COMPILE $@" + $(Q)$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ + $(Q)$(CC) $(CPPFLAGS) -MT $(@:.d=.o) -MM $< > $(BUILD_DIR)/$*.d + +$(BUILD_DIR)/%.s: %.c + @echo "===> GENERATE ASM $@" + $(Q)$(CC) -S $(CPPFLAGS) $(CFLAGS) $< -o $@ + +tags: + @echo "===> GENERATE TAGS" + $(Q)ctags -R + + +$(BUILD_DIR): + @mkdir $(BUILD_DIR) + +ifeq ($(findstring $(MAKECMDGOALS),clean),) +-include $(OBJ:.o=.d) +endif + +.PHONY: clean distclean debug debug-clean debug-distclean + +debug: + @make TAG=GCCdebug + +debug-clean: + @make clean TAG=GCCdebug + +debug-distclean: + @make distclean TAG=GCCdebug + +clean: + @echo "===> CLEAN" + @rm -rf $(BUILD_DIR) + @rm -f tags + +distclean: clean + @echo "===> DIST CLEAN" + @rm -f $(TARGET) + @rm -f tags + diff --git a/pystencils_benchmark/headers/kerncraft.h b/pystencils_benchmark/templates/aligned_malloc.h similarity index 82% rename from pystencils_benchmark/headers/kerncraft.h rename to pystencils_benchmark/templates/aligned_malloc.h index 5624537..5353157 100644 --- a/pystencils_benchmark/headers/kerncraft.h +++ b/pystencils_benchmark/templates/aligned_malloc.h @@ -1,11 +1,8 @@ -#ifndef _KERNCRAFT_H -#define _KERNCRAFT_H +#ifndef _ALIGNED_MALLOC_H +#define _ALIGNED_MALLOC_H #include <stddef.h> #include <stdlib.h> -#define swap(a, b) {void* t = a; a = b; b = t;} - - inline void* aligned_malloc(size_t size, size_t align) { // Based on http://stackoverflow.com/q/16376942 void *result; diff --git a/pystencils_benchmark/templates/include_Clang.mk b/pystencils_benchmark/templates/include_Clang.mk new file mode 100644 index 0000000..dab3ce3 --- /dev/null +++ b/pystencils_benchmark/templates/include_Clang.mk @@ -0,0 +1,24 @@ +CC = clang +CXX = clang++ +FC = gfortran +LINKER = $(CXX) + +ANSI_CFLAGS = -ansi +ANSI_CFLAGS += -std=c++0x +ANSI_CFLAGS += -pedantic +ANSI_CFLAGS += -Wextra + +CFLAGS = -O3 -Wno-format -Wall $(ANSI_CFLAGS) +# More warning pls +CFLAGS += -Wfloat-equal -Wundef -Wshadow -Wpointer-arith -Wcast-align -Wstrict-overflow=5 -Wwrite-strings -Waggregate-return +# Maybe too much warnings +CFLAGS += -Wcast-qual -Wswitch-default -Wconversion -Wunreachable-code +CXXFLAGS := $(CFLAGS) +# Specific C flags +CFLAGS := $(CFLAGS) -Wstrict-prototypes +FCFLAGS = +CPPFLAGS = -std=c++0x +LFLAGS = #-fopenmp +DEFINES = -D_GNU_SOURCE -DNDEBUG +INCLUDES = #-I/usr/lib/gcc/x86_64-linux-gnu/4.8/include/ +LIBS = #-L/usr/lib/x86_64-linux-gnu/libomp.so.5 diff --git a/pystencils_benchmark/templates/include_GCC.mk b/pystencils_benchmark/templates/include_GCC.mk new file mode 100644 index 0000000..7c0c446 --- /dev/null +++ b/pystencils_benchmark/templates/include_GCC.mk @@ -0,0 +1,24 @@ +CC = gcc +CXX = g++ +FC = gfortran +LINKER = $(CXX) + +ANSI_CFLAGS = -ansi +ANSI_CFLAGS += -std=c++0x +ANSI_CFLAGS += -pedantic +ANSI_CFLAGS += -Wextra + +CFLAGS = -O3 -Wno-format -Wall $(ANSI_CFLAGS) -fopenmp +# More warning pls +#CFLAGS += -Wfloat-equal -Wundef -Wshadow -Wpointer-arith -Wcast-align -Wstrict-overflow=5 -Wwrite-strings -Waggregate-return +# Maybe too much warnings +#CFLAGS += -Wcast-qual -Wswitch-default -Wconversion -Wunreachable-code +CXXFLAGS := $(CFLAGS) +# Specific C flags +CFLAGS := $(CFLAGS) -Wstrict-prototypes +FCFLAGS = +CPPFLAGS = -std=c++0x +LFLAGS = -fopenmp +DEFINES = -D_GNU_SOURCE -DNDEBUG +INCLUDES = +LIBS = diff --git a/pystencils_benchmark/templates/include_ICC.mk b/pystencils_benchmark/templates/include_ICC.mk new file mode 100644 index 0000000..0c090fb --- /dev/null +++ b/pystencils_benchmark/templates/include_ICC.mk @@ -0,0 +1,14 @@ +CC = icc +CXX = icpc +FC = ifort +LINKER = $(FC) + +CFLAGS = -O3 -std=c99 -xHost +CXXFLAGS = $(CFLAGS) +FCFLAGS = -O3 -xHost +LFLAGS = +DEFINES = -D_GNU_SOURCE +INCLUDES = +LIBS = + + diff --git a/pystencils_benchmark/templates/kernel.h b/pystencils_benchmark/templates/kernel.h index 634b319..c7826ac 100644 --- a/pystencils_benchmark/templates/kernel.h +++ b/pystencils_benchmark/templates/kernel.h @@ -1,4 +1,9 @@ +#ifndef {{header_guard}} +#define {{header_guard}} + #define RESTRICT __restrict__ #define FUNC_PREFIX {{function_signature}}; + +#endif diff --git a/pystencils_benchmark/templates/kernel_pystencils.c b/pystencils_benchmark/templates/kernel_pystencils.c deleted file mode 100644 index 47fbf7c..0000000 --- a/pystencils_benchmark/templates/kernel_pystencils.c +++ /dev/null @@ -1,18 +0,0 @@ - -#include "kerncraft.h" -#include <stdlib.h> -#include <stdint.h> -#include <stdbool.h> -#include <math.h> -#include <stdio.h> - -{{ includes }} - -#define RESTRICT __restrict__ -#define FUNC_PREFIX -void dummy(void *); -void timing(double* wcTime, double* cpuTime); -extern int var_false; - - -{{kernel_code}} \ No newline at end of file diff --git a/pystencils_benchmark/templates/kernel_pystencils.h b/pystencils_benchmark/templates/kernel_pystencils.h deleted file mode 100644 index 539d51f..0000000 --- a/pystencils_benchmark/templates/kernel_pystencils.h +++ /dev/null @@ -1,3 +0,0 @@ -#define FUNC_PREFIX - -{{function_signature}} \ No newline at end of file diff --git a/pystencils_benchmark/templates/main.c b/pystencils_benchmark/templates/main.c index 37e95fd..7f7ad47 100644 --- a/pystencils_benchmark/templates/main.c +++ b/pystencils_benchmark/templates/main.c @@ -1,4 +1,3 @@ -#include "kerncraft.h" #include <stdlib.h> #include <stdint.h> #include <stdbool.h> @@ -10,47 +9,7 @@ #define RESTRICT __restrict__ #define FUNC_PREFIX -void dummy(void *); void timing(double* wcTime, double* cpuTime); -extern int var_false; - -/* see waLBerla src/field/allocation/AlignedMalloc */ -void *aligned_malloc_with_offset( uint64_t size, uint64_t alignment, uint64_t offset ) -{ - // With 0 alignment this function makes no sense - // use normal malloc instead - assert( alignment > 0 ); - // Tests if alignment is power of two (assuming alignment>0) - assert( !(alignment & (alignment - 1)) ); - assert( offset < alignment ); - - void *pa; // pointer to allocated memory - void *ptr; // pointer to usable aligned memory - - pa=std::malloc( (size+2*alignment-1 )+sizeof(void *)); - if(!pa) - return nullptr; - - // Find next aligned position, starting at pa+sizeof(void*)-1 - ptr=(void*)( ((size_t)pa+sizeof(void *)+alignment-1) & ~(alignment-1)); - ptr=(void*) ( (char*)(ptr) + alignment - offset); - - // Store pointer to real allocated chunk just before usable chunk - *((void **)ptr-1)=pa; - - assert( ((size_t)ptr+offset) % alignment == 0 ); - - return ptr; -} - -void aligned_free( void *ptr ) -{ - // assume that pointer to real allocated chunk is stored just before - // chunk that was given to user - if(ptr) - std::free(*((void **)ptr-1)); -} - int main(int argc, char **argv) { @@ -63,24 +22,12 @@ int main(int argc, char **argv) {%- endif %} for (unsigned long long i = 0; i < {{elements}}; ++i) {{field_name}}[i] = 0.23; - - if(var_false) - { - dummy({{field_name}}); - } - {%- endfor %} - - {%- for constantName, dataType in constants %} - // Constant {{constantName}} {{dataType}} {{constantName}}; {{constantName}} = 0.23; - if(var_false) - dummy(& {{constantName}}); - {%- endfor %} for(int warmup = 1; warmup >= 0; --warmup) { @@ -97,14 +44,6 @@ int main(int argc, char **argv) for (; repeat > 0; --repeat) { {{kernel_name}}({{call_argument_list}}); - - // Dummy calls - {%- for field_name, dataType, elements, size, offset, alignment in fields %} - if(var_false) dummy((void*){{field_name}}); - {%- endfor %} - {%- for constantName, dataType in constants %} - if(var_false) dummy((void*)&{{constantName}}); - {%- endfor %} } {%- if timing %} timing(&wcEndTime, &cpuEndTime); @@ -115,11 +54,6 @@ int main(int argc, char **argv) } {%- for field_name, dataType, elements, size, offset, alignment in fields %} - {%- if alignment > 0 %} - aligned_free({{field_name}}); - {%- else %} delete[] {{field_name}}; - {%- endif %} - {%- endfor %} } diff --git a/pystencils_benchmark/headers/timing.c b/pystencils_benchmark/templates/timing.c similarity index 100% rename from pystencils_benchmark/headers/timing.c rename to pystencils_benchmark/templates/timing.c diff --git a/pystencils_benchmark/headers/timing.h b/pystencils_benchmark/templates/timing.h similarity index 79% rename from pystencils_benchmark/headers/timing.h rename to pystencils_benchmark/templates/timing.h index b063384..6c6ff44 100644 --- a/pystencils_benchmark/headers/timing.h +++ b/pystencils_benchmark/templates/timing.h @@ -1,9 +1,12 @@ +#ifndef _TIMING_H +#define _TIMING_H + #include <sys/time.h> #include <sys/types.h> #include <stdlib.h> #include <stdio.h> #include <sys/resource.h> - - void timing(double* wcTime, double* cpuTime); + +#endif \ No newline at end of file diff --git a/test.ipynb b/test.ipynb index d1459d8..e6ac951 100644 --- a/test.ipynb +++ b/test.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 9, + "execution_count": 1, "metadata": { "collapsed": true }, @@ -10,16 +10,16 @@ "source": [ "import numpy as np\n", "import pystencils as ps\n", - "from pystencils_benchmark import kernel_header, kernel_source, generate_benchmark\n", + "from pystencils_benchmark import generate_benchmark\n", "from pathlib import Path" ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 2, "outputs": [], "source": [ - "config = ps.CreateKernelConfig()" + "config = ps.CreateKernelConfig(function_name='vadd')" ], "metadata": { "collapsed": false, @@ -30,7 +30,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 3, "outputs": [], "source": [ "a, b, c = ps.fields(a=np.ones(4000000), b=np.ones(4000000), c=np.ones(4000000))" @@ -44,7 +44,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 4, "outputs": [], "source": [ "@ps.kernel\n", @@ -60,7 +60,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 5, "outputs": [ { "data": { @@ -72,8 +72,8 @@ }, { "data": { - "text/plain": "FUNC_PREFIX void kernel(double * RESTRICT _data_a, double * RESTRICT const _data_b, double * RESTRICT const _data_c)\n{\n for (int64_t ctr_0 = 0; ctr_0 < 4000000; ctr_0 += 1)\n {\n _data_a[ctr_0] = _data_b[ctr_0] + _data_c[ctr_0];\n }\n}", - "text/html": "<div class=\"highlight\"><pre><span></span><span class=\"n\">FUNC_PREFIX</span><span class=\"w\"> </span><span class=\"kt\">void</span><span class=\"w\"> </span><span class=\"n\">kernel</span><span class=\"p\">(</span><span class=\"kt\">double</span><span class=\"w\"> </span><span class=\"o\">*</span><span class=\"w\"> </span><span class=\"n\">RESTRICT</span><span class=\"w\"> </span><span class=\"n\">_data_a</span><span class=\"p\">,</span><span class=\"w\"> </span><span class=\"kt\">double</span><span class=\"w\"> </span><span class=\"o\">*</span><span class=\"w\"> </span><span class=\"n\">RESTRICT</span><span class=\"w\"> </span><span class=\"k\">const</span><span class=\"w\"> </span><span class=\"n\">_data_b</span><span class=\"p\">,</span><span class=\"w\"> </span><span class=\"kt\">double</span><span class=\"w\"> </span><span class=\"o\">*</span><span class=\"w\"> </span><span class=\"n\">RESTRICT</span><span class=\"w\"> </span><span class=\"k\">const</span><span class=\"w\"> </span><span class=\"n\">_data_c</span><span class=\"p\">)</span><span class=\"w\"></span>\n<span class=\"p\">{</span><span class=\"w\"></span>\n<span class=\"w\"> </span><span class=\"k\">for</span><span class=\"w\"> </span><span class=\"p\">(</span><span class=\"kt\">int64_t</span><span class=\"w\"> </span><span class=\"n\">ctr_0</span><span class=\"w\"> </span><span class=\"o\">=</span><span class=\"w\"> </span><span class=\"mi\">0</span><span class=\"p\">;</span><span class=\"w\"> </span><span class=\"n\">ctr_0</span><span class=\"w\"> </span><span class=\"o\"><</span><span class=\"w\"> </span><span class=\"mi\">4000000</span><span class=\"p\">;</span><span class=\"w\"> </span><span class=\"n\">ctr_0</span><span class=\"w\"> </span><span class=\"o\">+=</span><span class=\"w\"> </span><span class=\"mi\">1</span><span class=\"p\">)</span><span class=\"w\"></span>\n<span class=\"w\"> </span><span class=\"p\">{</span><span class=\"w\"></span>\n<span class=\"w\"> </span><span class=\"n\">_data_a</span><span class=\"p\">[</span><span class=\"n\">ctr_0</span><span class=\"p\">]</span><span class=\"w\"> </span><span class=\"o\">=</span><span class=\"w\"> </span><span class=\"n\">_data_b</span><span class=\"p\">[</span><span class=\"n\">ctr_0</span><span class=\"p\">]</span><span class=\"w\"> </span><span class=\"o\">+</span><span class=\"w\"> </span><span class=\"n\">_data_c</span><span class=\"p\">[</span><span class=\"n\">ctr_0</span><span class=\"p\">];</span><span class=\"w\"></span>\n<span class=\"w\"> </span><span class=\"p\">}</span><span class=\"w\"></span>\n<span class=\"p\">}</span><span class=\"w\"></span>\n</pre></div>\n" + "text/plain": "FUNC_PREFIX void vadd(double * RESTRICT _data_a, double * RESTRICT const _data_b, double * RESTRICT const _data_c)\n{\n for (int64_t ctr_0 = 0; ctr_0 < 4000000; ctr_0 += 1)\n {\n _data_a[ctr_0] = _data_b[ctr_0] + _data_c[ctr_0];\n }\n}", + "text/html": "<div class=\"highlight\"><pre><span></span><span class=\"n\">FUNC_PREFIX</span><span class=\"w\"> </span><span class=\"kt\">void</span><span class=\"w\"> </span><span class=\"n\">vadd</span><span class=\"p\">(</span><span class=\"kt\">double</span><span class=\"w\"> </span><span class=\"o\">*</span><span class=\"w\"> </span><span class=\"n\">RESTRICT</span><span class=\"w\"> </span><span class=\"n\">_data_a</span><span class=\"p\">,</span><span class=\"w\"> </span><span class=\"kt\">double</span><span class=\"w\"> </span><span class=\"o\">*</span><span class=\"w\"> </span><span class=\"n\">RESTRICT</span><span class=\"w\"> </span><span class=\"k\">const</span><span class=\"w\"> </span><span class=\"n\">_data_b</span><span class=\"p\">,</span><span class=\"w\"> </span><span class=\"kt\">double</span><span class=\"w\"> </span><span class=\"o\">*</span><span class=\"w\"> </span><span class=\"n\">RESTRICT</span><span class=\"w\"> </span><span class=\"k\">const</span><span class=\"w\"> </span><span class=\"n\">_data_c</span><span class=\"p\">)</span><span class=\"w\"></span>\n<span class=\"p\">{</span><span class=\"w\"></span>\n<span class=\"w\"> </span><span class=\"k\">for</span><span class=\"w\"> </span><span class=\"p\">(</span><span class=\"kt\">int64_t</span><span class=\"w\"> </span><span class=\"n\">ctr_0</span><span class=\"w\"> </span><span class=\"o\">=</span><span class=\"w\"> </span><span class=\"mi\">0</span><span class=\"p\">;</span><span class=\"w\"> </span><span class=\"n\">ctr_0</span><span class=\"w\"> </span><span class=\"o\"><</span><span class=\"w\"> </span><span class=\"mi\">4000000</span><span class=\"p\">;</span><span class=\"w\"> </span><span class=\"n\">ctr_0</span><span class=\"w\"> </span><span class=\"o\">+=</span><span class=\"w\"> </span><span class=\"mi\">1</span><span class=\"p\">)</span><span class=\"w\"></span>\n<span class=\"w\"> </span><span class=\"p\">{</span><span class=\"w\"></span>\n<span class=\"w\"> </span><span class=\"n\">_data_a</span><span class=\"p\">[</span><span class=\"n\">ctr_0</span><span class=\"p\">]</span><span class=\"w\"> </span><span class=\"o\">=</span><span class=\"w\"> </span><span class=\"n\">_data_b</span><span class=\"p\">[</span><span class=\"n\">ctr_0</span><span class=\"p\">]</span><span class=\"w\"> </span><span class=\"o\">+</span><span class=\"w\"> </span><span class=\"n\">_data_c</span><span class=\"p\">[</span><span class=\"n\">ctr_0</span><span class=\"p\">];</span><span class=\"w\"></span>\n<span class=\"w\"> </span><span class=\"p\">}</span><span class=\"w\"></span>\n<span class=\"p\">}</span><span class=\"w\"></span>\n</pre></div>\n" }, "metadata": {}, "output_type": "display_data" @@ -92,22 +92,8 @@ }, { "cell_type": "code", - "execution_count": 14, - "outputs": [ - { - "ename": "AttributeError", - "evalue": "'list' object has no attribute 'add'", - "output_type": "error", - "traceback": [ - "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", - "\u001B[0;31mAttributeError\u001B[0m Traceback (most recent call last)", - "\u001B[0;32m/tmp/ipykernel_28091/2748650420.py\u001B[0m in \u001B[0;36m<module>\u001B[0;34m\u001B[0m\n\u001B[1;32m 1\u001B[0m \u001B[0mexample_path\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mPath\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mcwd\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m \u001B[0;34m/\u001B[0m \u001B[0;34m'example'\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m----> 2\u001B[0;31m \u001B[0mgenerate_benchmark\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mkernel_vadd\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mexample_path\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m", - "\u001B[0;32m~/git/pystencils-benchmark/pystencils_benchmark/benchmark.py\u001B[0m in \u001B[0;36mgenerate_benchmark\u001B[0;34m(kernel_ast, path, dialect)\u001B[0m\n\u001B[1;32m 31\u001B[0m \u001B[0mf\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mwrite\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mheader\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 32\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m---> 33\u001B[0;31m \u001B[0msource\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mkernel_source\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mkernel_ast\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mdialect\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 34\u001B[0m \u001B[0;32mwith\u001B[0m \u001B[0mopen\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0msrc_path\u001B[0m \u001B[0;34m/\u001B[0m \u001B[0;34mf'{kernel_name}.c'\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;34m'w+'\u001B[0m\u001B[0;34m)\u001B[0m \u001B[0;32mas\u001B[0m \u001B[0mf\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 35\u001B[0m \u001B[0mf\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mwrite\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0msource\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", - "\u001B[0;32m~/git/pystencils-benchmark/pystencils_benchmark/benchmark.py\u001B[0m in \u001B[0;36mkernel_source\u001B[0;34m(kernel_ast, dialect)\u001B[0m\n\u001B[1;32m 119\u001B[0m \u001B[0mfunction_source\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mgenerate_c\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mkernel_ast\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mdialect\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0mdialect\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 120\u001B[0m \u001B[0mheaders\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mget_headers\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mkernel_ast\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 121\u001B[0;31m \u001B[0mheaders\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0madd\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34mf'\"{kernel_name}.h\"'\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 122\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 123\u001B[0m jinja_context = {\n", - "\u001B[0;31mAttributeError\u001B[0m: 'list' object has no attribute 'add'" - ] - } - ], + "execution_count": 6, + "outputs": [], "source": [ "example_path = Path.cwd() / 'example'\n", "generate_benchmark(kernel_vadd, example_path)" -- GitLab