diff --git a/pystencils/backends/cbackend.py b/pystencils/backends/cbackend.py index 8c835fd1d699aad905b5b528d4b4f2e7542d4280..9603d6d232bd677b1e6ca0cb7ec147773b688fdb 100644 --- a/pystencils/backends/cbackend.py +++ b/pystencils/backends/cbackend.py @@ -282,7 +282,15 @@ class CBackend: np_dtype = node.symbol.dtype.base_type.numpy_dtype required_size = np_dtype.itemsize * node.size + align size = modulo_ceil(required_size, align) - code = "{dtype} {name}=({dtype})aligned_alloc({align}, {size}) + {offset};" + code = "#if __cplusplus >= 201703L || __STDC_VERSION__ >= 201112L\n" + code += "{dtype} {name}=({dtype})aligned_alloc({align}, {size}) + {offset};\n" + code += "#elif defined(_MSC_VER)\n" + code += "{dtype} {name}=({dtype})_aligned_malloc({size}, {align}) + {offset};\n" + code += "#else\n" + code += "{dtype} {name};\n" + code += "posix_memalign((void**) &{name}, {align}, {size});\n" + code += "{name} += {offset};\n" + code += "#endif" return code.format(dtype=node.symbol.dtype, name=self.sympy_printer.doprint(node.symbol.name), size=self.sympy_printer.doprint(size), @@ -291,7 +299,12 @@ class CBackend: def _print_TemporaryMemoryFree(self, node): align = 64 - return "free(%s - %d);" % (self.sympy_printer.doprint(node.symbol.name), node.offset(align)) + code = "#if defined(_MSC_VER)\n" + code += "_aligned_free(%s - %d);\n" % (self.sympy_printer.doprint(node.symbol.name), node.offset(align)) + code += "#else\n" + code += "free(%s - %d);\n" % (self.sympy_printer.doprint(node.symbol.name), node.offset(align)) + code += "#endif" + return code def _print_SkipIteration(self, _): return "continue;" diff --git a/pystencils/cpu/cpujit.py b/pystencils/cpu/cpujit.py index f5f8f63c1b2058614f4553b4146017b6fa362145..84908dcb29b38fc89a1b381d1491fbde59a09db7 100644 --- a/pystencils/cpu/cpujit.py +++ b/pystencils/cpu/cpujit.py @@ -160,7 +160,7 @@ def read_config(): ('msvc_version', 'latest'), ('llc_command', get_llc_command() or 'llc'), ('arch', 'x64'), - ('flags', '/Ox /fp:fast /OpenMP /arch:avx /std:c++17'), + ('flags', '/Ox /fp:fast /OpenMP /arch:avx'), ('restrict_qualifier', '__restrict') ]) elif platform.system().lower() == 'darwin': @@ -168,7 +168,7 @@ def read_config(): ('os', 'darwin'), ('command', 'clang++'), ('llc_command', get_llc_command() or 'llc'), - ('flags', '-Ofast -DNDEBUG -fPIC -march=native -Xclang -fopenmp -std=c++17'), + ('flags', '-Ofast -DNDEBUG -fPIC -march=native -Xclang -fopenmp -std=c++11'), ('restrict_qualifier', '__restrict__') ]) default_cache_config = OrderedDict([