From ccc9b40676dda341d0678e04e8c58deadc2f34e3 Mon Sep 17 00:00:00 2001 From: Ofek Shilon Date: Thu, 7 Dec 2023 22:29:54 +0200 Subject: [PATCH 1/9] Fix: `remove_if` called without `erase` --- src/gen_policy.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gen_policy.cpp b/src/gen_policy.cpp index 432be8f..53074cf 100644 --- a/src/gen_policy.cpp +++ b/src/gen_policy.cpp @@ -540,4 +540,5 @@ void GenPolicy::removeProbability(std::vector> &orig, U id) { std::remove_if( orig.begin(), orig.end(), [&id](Probability &elem) -> bool { return elem.getId() == id; }); + orig.erase(new_end, orig.end()); } From 29cb61758ccbb59dcb318349444a2aa526ec2eef Mon Sep 17 00:00:00 2001 From: Ofek Shilon Date: Thu, 7 Dec 2023 23:01:37 +0200 Subject: [PATCH 2/9] Fix build --- src/gen_policy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gen_policy.cpp b/src/gen_policy.cpp index 53074cf..2f2e855 100644 --- a/src/gen_policy.cpp +++ b/src/gen_policy.cpp @@ -537,7 +537,7 @@ void GenPolicy::uniformProbFromMax(std::vector> &distr, template void GenPolicy::removeProbability(std::vector> &orig, U id) { - std::remove_if( + auto new_end = std::remove_if( orig.begin(), orig.end(), [&id](Probability &elem) -> bool { return elem.getId() == id; }); orig.erase(new_end, orig.end()); From 011aed331f38bcae5a6a8f967d04564c223e9fde Mon Sep 17 00:00:00 2001 From: Ofek Date: Thu, 21 Dec 2023 19:26:22 +0200 Subject: [PATCH 3/9] Handle exe names for windows --- scripts/gen_test_makefile.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scripts/gen_test_makefile.py b/scripts/gen_test_makefile.py index a97e552..2233b40 100755 --- a/scripts/gen_test_makefile.py +++ b/scripts/gen_test_makefile.py @@ -23,6 +23,7 @@ import argparse import logging import os +import platform import sys import re @@ -268,6 +269,8 @@ def parse_config(file_name): def detect_native_arch(): check_isa_file = os.path.abspath(common.yarpgen_scripts + os.sep + check_isa_file_name) check_isa_binary = os.path.abspath(common.yarpgen_scripts + os.sep + check_isa_file_name.replace(".cpp", "")) + if (platform.system() == 'Windows'): + check_isa_binary += ".exe" sys_compiler = "" for key in CompilerSpecs.all_comp_specs: @@ -281,12 +284,16 @@ def detect_native_arch(): if not common.if_exec_exist(check_isa_binary): if not os.path.exists(check_isa_file): common.print_and_exit("Can't find " + check_isa_file) - ret_code, output, err_output, time_expired, elapsed_time = \ - common.run_cmd([sys_compiler, check_isa_file, "-o", check_isa_binary], None) + if (platform.system() == 'Windows'): + ret_code, output, err_output, time_expired, elapsed_time = \ + common.run_cmd([sys_compiler, check_isa_file, "/Fe:\""+check_isa_binary+"\""], None) + else: + ret_code, output, err_output, time_expired, elapsed_time = \ + common.run_cmd([sys_compiler, check_isa_file, "-o", check_isa_binary], None) if ret_code != 0: common.print_and_exit("Can't compile " + check_isa_file + ": " + str(err_output, "utf-8")) - ret_code, output, err_output, time_expired, elapsed_time = common.run_cmd([check_isa_binary], None) + ret_code, output, err_output, time_expired, elapsed_time = common.run_cmd(cmd=[check_isa_binary], time_out=None, compilation_cmd=False) if ret_code != 0: common.print_and_exit("Error while executing " + check_isa_binary) native_arch_str = str(output, "utf-8").split()[0] From 1cfb063549f564b513e94c088376ad35d97451c1 Mon Sep 17 00:00:00 2001 From: Ofek Date: Thu, 21 Dec 2023 19:26:34 +0200 Subject: [PATCH 4/9] Warning fix --- src/stmt.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stmt.cpp b/src/stmt.cpp index 4048648..449facd 100644 --- a/src/stmt.cpp +++ b/src/stmt.cpp @@ -592,7 +592,7 @@ void LoopNestStmt::populate(std::shared_ptr ctx) { auto gen_pol = ctx->getGenPolicy(); auto new_ctx = std::make_shared(ctx); bool old_ctx_state = new_ctx->isTaken(); - std::vector>::iterator taken_switch_id; + auto taken_switch_id = loops.end(); auto simd_switch_id = loops.end(); auto mul_val_loop_idx = loops.end(); for (auto i = loops.begin(); i != loops.end(); ++i) { From bccfb289a04181ae7a8970aa25f2a7b8e420c1d2 Mon Sep 17 00:00:00 2001 From: Ofek Date: Thu, 21 Dec 2023 19:29:08 +0200 Subject: [PATCH 5/9] Introduce test_sets_win.txt --- scripts/gen_test_makefile.py | 5 +-- scripts/test_sets_win.txt | 66 ++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 scripts/test_sets_win.txt diff --git a/scripts/gen_test_makefile.py b/scripts/gen_test_makefile.py index 2233b40..0d6b54b 100755 --- a/scripts/gen_test_makefile.py +++ b/scripts/gen_test_makefile.py @@ -32,9 +32,10 @@ Test_Makefile_name = "Test_Makefile" license_file_name = "LICENSE.txt" check_isa_file_name = "check_isa.cpp" -default_test_sets_file_name = "test_sets.txt" -default_config_file = "test_sets.txt" +default_test_sets_file_name = "test_sets_win.txt" if (platform.system() == "Windows") else "test_sets.txt" + +default_config_file = default_test_sets_file_name comp_specs_line = "Compiler specs:" spec_list_len = 5 test_sets_line = "Testing sets:" diff --git a/scripts/test_sets_win.txt b/scripts/test_sets_win.txt new file mode 100644 index 0000000..1472214 --- /dev/null +++ b/scripts/test_sets_win.txt @@ -0,0 +1,66 @@ +############################################################################### +# +# Copyright (c) 2016-2023, Intel Corporation +# Copyright (c) 2019-2020, University of Utah +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +############################################################################### +# README: +# Testing configuration file +# You can start single-line comment with #. Don't use indentation at the beginning of line! +# Config can contain only one "Compiler specs" and "Testing sets" blocks! +# You should always specify "Compiler specs" before "Testing sets"! +############################################################################### + +Compiler specs: +# Spec name - codename for compiler and its options +# Executable name - name of compiler binary file. It should be in your PATH +# Common arguments - arguments which will be passed to every compiler run +# Arch prefix - prefix for specifying different architectures (it will be concatenated with Compiler arch value) + + +# Spec name | C++ executable name | C executable name | Common arguments | Arch prefix +msvc | C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.38.33130/bin/Hostx64/x64/cl.exe | C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.38.33130/bin/Hostx64/x64/cl.exe | | +clangcl | C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/Llvm/x64/bin/clang-cl.exe | C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/Llvm/x64/bin/clang-cl.exe | | +#gcc | g++ | gcc | -fPIC -mcmodel=large -w -fpermissive | -march= +#clang | clang++ | clang | -fPIC -mcmodel=large -w -fopenmp-simd | -march= +#polly | clang++ | clang | -fPIC -mcmodel=large -w -fopenmp-simd -mllvm -polly -mllvm -polly-vectorizer=stripmine | -march= +# Ubsan is clang or gcc with sanitizer options. It is used for generator check. +# If you want to use sanitizer with -m32, please make sure that you pass "-rtlib=compiler-rt -lgcc_s" options if you are using clang. +# Otherwise it may fail with "undefined reference to `__mulodi4'" error message. +# See https://bugs.llvm.org//show_bug.cgi?id=16404 for more information +# Note that -fpermissive option for gcc is required to allow reduction of ubsan_gcc fails. +# Otherwise result of reduction is empty program. + +Testing sets: +# Set name - codename for testing set +# Spec name - codename of spec, it should be described in Compiler specs +# Arguments - compiler options for this testing set +# Compiler arch - architecture which will be passed to compiler +# Sde arch - architecture which will be passed to SDE + +# Set name | Spec name | Arguments | Compiler arch | Sde arch + +msvc_no_opt | msvc | | | +msvc_opt | msvc | /O2 | | +clangcl_no_opt | clangcl | | | +clangcl_opt | clangcl | /O2 | | +#gcc_no_opt | gcc | -O0 | | +#gcc_opt | gcc | -O3 | | + +#clang_no_opt | clang | -O0 | | +#clang_opt | clang | -O3 | | + +Options for statistics' capture: +#Spec name | Arguments From 0a0ec505db4d5cd9b59340b0fdc892058260d5c1 Mon Sep 17 00:00:00 2001 From: Ofek Date: Thu, 21 Dec 2023 23:18:54 +0200 Subject: [PATCH 6/9] More fixes towards windows conformance --- scripts/common.py | 9 ++++++++- scripts/run_gen.py | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/common.py b/scripts/common.py index 564adfc..c25b2e8 100644 --- a/scripts/common.py +++ b/scripts/common.py @@ -27,6 +27,7 @@ import errno import logging import os +import platform import shutil import signal import subprocess @@ -231,7 +232,7 @@ def check_dir_and_create(directory): print_and_exit("Can't use '" + norm_dir + "' directory") -def run_cmd(cmd, time_out=None, num=-1, memory_limit=None): +def run_cmd(cmd, time_out=None, num=-1, memory_limit=None, compilation_cmd=True): is_time_expired = False shell = False if memory_limit is not None: @@ -239,6 +240,12 @@ def run_cmd(cmd, time_out=None, num=-1, memory_limit=None): new_cmd = "ulimit -v " + str(memory_limit) + " ; " new_cmd += " ".join(i for i in cmd) cmd = new_cmd + if platform.system() == "Windows" and compilation_cmd: + shell = True + new_cmd = "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvars64.bat ; " + new_cmd += " ".join(i for i in cmd) + cmd = new_cmd + start_time = os.times() with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, start_new_session=True, shell=shell) as process: try: diff --git a/scripts/run_gen.py b/scripts/run_gen.py index 03ad5d1..0dddd98 100755 --- a/scripts/run_gen.py +++ b/scripts/run_gen.py @@ -29,6 +29,7 @@ import multiprocessing import multiprocessing.managers import os +import platform import re import shutil import stat @@ -1510,6 +1511,8 @@ def prepare_env_and_start_testing(out_dir, timeout, targets, num_jobs, config_fi # Check for binary of generator yarpgen_bin = os.path.abspath(common.yarpgen_scripts + os.sep + "yarpgen") + if(platform.system() == "Windows"): + yarpgen_bin += ".exe" common.check_and_copy(yarpgen_bin, out_dir) ret_code, output, err_output, time_expired, elapsed_time = common.run_cmd([yarpgen_bin, "-v"], yarpgen_timeout, 0) common.yarpgen_version_str = str(output, "utf-8") From a67e294ad7a7347cd580600022ba929a0c790743 Mon Sep 17 00:00:00 2001 From: Ofek Shilon Date: Sat, 16 Dec 2023 22:55:11 +0200 Subject: [PATCH 7/9] Make run_gen.py work on windows --- scripts/run_gen.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/run_gen.py b/scripts/run_gen.py index 0dddd98..eebb686 100755 --- a/scripts/run_gen.py +++ b/scripts/run_gen.py @@ -30,6 +30,7 @@ import multiprocessing.managers import os import platform +import platform import re import shutil import stat @@ -1511,8 +1512,9 @@ def prepare_env_and_start_testing(out_dir, timeout, targets, num_jobs, config_fi # Check for binary of generator yarpgen_bin = os.path.abspath(common.yarpgen_scripts + os.sep + "yarpgen") - if(platform.system() == "Windows"): + if (platform.system() == 'Windows') : yarpgen_bin += ".exe" + common.check_and_copy(yarpgen_bin, out_dir) ret_code, output, err_output, time_expired, elapsed_time = common.run_cmd([yarpgen_bin, "-v"], yarpgen_timeout, 0) common.yarpgen_version_str = str(output, "utf-8") From b0d539b179952d2b94c29f405e3b475ea0a416b3 Mon Sep 17 00:00:00 2001 From: Ofek Shilon Date: Fri, 22 Dec 2023 18:32:46 +0200 Subject: [PATCH 8/9] Aim to run from wsl, start fixing makefil generation --- scripts/common.py | 2 +- scripts/gen_test_makefile.py | 8 ++++---- scripts/test_sets_win.txt | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/common.py b/scripts/common.py index c25b2e8..27eb653 100644 --- a/scripts/common.py +++ b/scripts/common.py @@ -242,7 +242,7 @@ def run_cmd(cmd, time_out=None, num=-1, memory_limit=None, compilation_cmd=True) cmd = new_cmd if platform.system() == "Windows" and compilation_cmd: shell = True - new_cmd = "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvars64.bat ; " + new_cmd = "\"/mnt/c/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvars64.bat\" ; " new_cmd += " ".join(i for i in cmd) cmd = new_cmd diff --git a/scripts/gen_test_makefile.py b/scripts/gen_test_makefile.py index 0d6b54b..fee3d7e 100755 --- a/scripts/gen_test_makefile.py +++ b/scripts/gen_test_makefile.py @@ -341,7 +341,7 @@ def gen_makefile(out_file_name, force, config_file, only_target=None, inject_bla compiler_name = target.specs.comp_c_name if common.selected_standard.is_cxx(): compiler_name = target.specs.comp_cxx_name - output += target.name + ": " + "COMPILER=" + compiler_name + "\n" + output += target.name + ": " + "COMPILER=\"" + compiler_name + "\"\n" optflags_str = target.name + ": " + "OPTFLAGS=" + target.args if target.arch.comp_name != "": @@ -349,7 +349,7 @@ def gen_makefile(out_file_name, force, config_file, only_target=None, inject_bla optflags_str += "\n" output += optflags_str # For performance reasons driver should always be compiled with -O0 - output += re.sub("-O\d", "-O0", (optflags_str.replace("OPTFLAGS", "DRIVER_OPTFLAGS"))) + output += re.sub("/O\d", "/O0", (optflags_str.replace("OPTFLAGS", "DRIVER_OPTFLAGS"))) if inject_blame_opt is not None: output += target.name + ": " + "BLAMEOPTS=" + inject_blame_opt + "\n" @@ -366,7 +366,7 @@ def gen_makefile(out_file_name, force, config_file, only_target=None, inject_bla output += "$(SOURCES:" + common.get_file_ext() + "=.o))\n" else: output += "$(patsubst %.ispc,%.o," + "$(SOURCES:" + common.get_file_ext() + "=.o))" + ")\n" - output += "\t" + "$(COMPILER) $(LDFLAGS) $(STDFLAGS) $(OPTFLAGS) -o $(EXECUTABLE) $^\n\n" + output += "\t" + "$(COMPILER) $(LDFLAGS) $(STDFLAGS) $(OPTFLAGS) /Fe:$(EXECUTABLE).exe $^\n\n" if stat_targets is not None and len(stat_targets) != 0: common.log_msg(logging.WARNING, "Can't find relevant stat_targets: " + str(stat_targets), forced_duplication=True) @@ -385,7 +385,7 @@ def gen_makefile(out_file_name, force, config_file, only_target=None, inject_bla output += "%" + source_name + ".o: " + source_prefix + source + force_str # For performance reasons driver should always be compiled with -O0 optflags_name = "$(OPTFLAGS)" if source_name != "driver" else "$(DRIVER_OPTFLAGS)" - output += "\t" + "$(COMPILER) $(CXXFLAGS) $(STDFLAGS) " + optflags_name + " -o $@ -c $<" + output += "\t" + "$(COMPILER) $(CXXFLAGS) $(STDFLAGS) " + optflags_name + " /Fe:$@.exe -c $<" if source_name == "func": output += " $(STATFLAGS) " if inject_blame_opt is not None: diff --git a/scripts/test_sets_win.txt b/scripts/test_sets_win.txt index 1472214..b665de9 100644 --- a/scripts/test_sets_win.txt +++ b/scripts/test_sets_win.txt @@ -31,8 +31,8 @@ Compiler specs: # Spec name | C++ executable name | C executable name | Common arguments | Arch prefix -msvc | C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.38.33130/bin/Hostx64/x64/cl.exe | C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.38.33130/bin/Hostx64/x64/cl.exe | | -clangcl | C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/Llvm/x64/bin/clang-cl.exe | C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/Llvm/x64/bin/clang-cl.exe | | +msvc | /mnt/c/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.38.33130/bin/Hostx64/x64/cl.exe | /mnt/c/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.38.33130/bin/Hostx64/x64/cl.exe | | +clangcl | /mnt/c/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/Llvm/x64/bin/clang-cl.exe | /mnt/c/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/Llvm/x64/bin/clang-cl.exe | | #gcc | g++ | gcc | -fPIC -mcmodel=large -w -fpermissive | -march= #clang | clang++ | clang | -fPIC -mcmodel=large -w -fopenmp-simd | -march= #polly | clang++ | clang | -fPIC -mcmodel=large -w -fopenmp-simd -mllvm -polly -mllvm -polly-vectorizer=stripmine | -march= From 78fb0c1e9c042df6ad187135b5caeb8116f5e3a6 Mon Sep 17 00:00:00 2001 From: Ofek Shilon Date: Fri, 22 Dec 2023 18:34:33 +0200 Subject: [PATCH 9/9] Add vscode debug config for windows in launch.json --- .vscode/launch.json | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..614b903 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,22 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "run_gen", + "type": "python", + "request": "launch", + "program": "${workspaceFolder}/scripts/run_gen.py", + "args": [ + "--config-file", + "${workspaceFolder}/scripts/test_sets_win.txt", + "--target", + "msvc clangcl" + ], + "console": "integratedTerminal", + "justMyCode": true + } + ] +} \ No newline at end of file