From 871a7e685fac7ea0177581912a2ee0bacfa00de6 Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Wed, 4 Aug 2021 17:07:08 +0800 Subject: [PATCH] Update starch to upstream commit 0c8249fa4bc523345c156885542e9192e8bf9420 --- starch/starch.py | 2 +- starch/templates/benchmark.c.template | 14 ++++++++++++-- starch/templates/makefile.template | 10 +++++++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/starch/starch.py b/starch/starch.py index 8cc43b8..1d0e0da 100644 --- a/starch/starch.py +++ b/starch/starch.py @@ -571,7 +571,7 @@ class Generator(object): def render(self, template_path, output_path, **kwargs): t = self.templates.get_template(template_path) - result = t.render(gen=self, current_dir=os.path.dirname(output_path), **kwargs) + result = t.render(gen=self, current_dir=os.path.dirname(output_path), **kwargs).replace('\r\n', '\n') if os.path.exists(output_path): with open(output_path, 'r') as f: diff --git a/starch/templates/benchmark.c.template b/starch/templates/benchmark.c.template index a9cbc9e..82a2144 100644 --- a/starch/templates/benchmark.c.template +++ b/starch/templates/benchmark.c.template @@ -15,6 +15,16 @@ #include #include +//On Windows platform, separate functions for allocating and freeing aligned memory must be used +#ifdef _WIN32 +# include +# define util_aligned_alloc(alignment,size) (_aligned_malloc(size, alignment)) +# define util_aligned_free(ptr) (_aligned_free(ptr)) +#else +# define util_aligned_alloc(alignment,size) (aligned_alloc(alignment,size)) +# define util_aligned_free(ptr) (free(ptr)) +#endif + #include "${os.path.relpath(gen.generated_include_path, current_dir)}" typedef struct timespec starch_benchmark_time; @@ -79,7 +89,7 @@ void *starch_benchmark_aligned_alloc(size_t alignment, size_t type_alignment, si * of a more restrictive larger alignment) */ size_t header_size = (use_alignment < sizeof(void*) ? sizeof(void*) : use_alignment); - char *block_ptr = aligned_alloc(use_alignment, header_size + size + use_alignment); + char *block_ptr = util_aligned_alloc(use_alignment, header_size + size + use_alignment); if (!block_ptr) { fprintf(stderr, "STARCH_BENCHMARK_ALLOC of %zu bytes failed: %s\n", size, strerror(errno)); return NULL; @@ -102,7 +112,7 @@ void starch_benchmark_aligned_free(void *user_ptr) if (!user_ptr) return; void **stash = (void**)user_ptr - 1; - free(*stash); + util_aligned_free(*stash); } static bool starch_benchmark_flavor_in_list(const char *flavor, const starch_benchmark_flavor_list *list) diff --git a/starch/templates/makefile.template b/starch/templates/makefile.template index 3fae92c..5b3fc2b 100644 --- a/starch/templates/makefile.template +++ b/starch/templates/makefile.template @@ -21,6 +21,7 @@ # $(STARCH_BENCHMARK_OBJ): object files providing a standalone benchmarking app (link all of $(STARCH_OBJS) too) # explicit build rules for each object file listed in $(STARCH_OBJS) +MKDIR_P = mkdir -p STARCH_CFLAGS := -D${mix.macro} <% import os @@ -35,7 +36,8 @@ STARCH_CFLAGS := -D${mix.macro} o_files.append(o_file) %> ${o_file}: ${c_file} ${impl_c_files} - $(STARCH_COMPILE) $(STARCH_CFLAGS) ${flavor.cflags} ${c_file} -o ${o_file} + @$(MKDIR_P) $(dir $(STARCH_OBJ_PATH)${o_file}) + $(STARCH_COMPILE) $(STARCH_CFLAGS) ${flavor.cflags} ${c_file} -o $(STARCH_OBJ_PATH)${o_file} % endfor <% c_file = os.path.relpath(gen.generated_dispatcher_path, gen.runtime_dir) @@ -43,7 +45,8 @@ ${o_file}: ${c_file} ${impl_c_files} o_files.append(o_file) %> ${o_file}: ${c_file} ${impl_c_files} - $(STARCH_COMPILE) $(STARCH_CFLAGS) ${c_file} -o ${o_file} + @$(MKDIR_P) $(dir $(STARCH_OBJ_PATH)${o_file}) + $(STARCH_COMPILE) $(STARCH_CFLAGS) ${c_file} -o $(STARCH_OBJ_PATH)${o_file} STARCH_OBJS := ${' '.join(o_files)} @@ -52,6 +55,7 @@ STARCH_OBJS := ${' '.join(o_files)} o_file = os.path.splitext(c_file)[0] + '.o' %> ${o_file}: ${c_file} ${benchmark_c_files} - $(STARCH_COMPILE) $(STARCH_CFLAGS) ${c_file} -o ${o_file} + @$(MKDIR_P) $(dir $(STARCH_OBJ_PATH)${o_file}) + $(STARCH_COMPILE) $(STARCH_CFLAGS) ${c_file} -o $(STARCH_OBJ_PATH)${o_file} STARCH_BENCHMARK_OBJ := ${o_file}