diff --git a/test/optimizer/loop_collapse/negative/inner_loop_doall_only/__init__.py b/test/optimizer/loop_collapse/negative/inner_loop_doall_only/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/test/optimizer/loop_collapse/negative/inner_loop_doall_only/src/Makefile b/test/optimizer/loop_collapse/negative/inner_loop_doall_only/src/Makefile new file mode 100644 index 000000000..8b1635880 --- /dev/null +++ b/test/optimizer/loop_collapse/negative/inner_loop_doall_only/src/Makefile @@ -0,0 +1,15 @@ +all: clean prog + +prog: code.o + $(CXX) -o prog code.o $(CXXFLAGS) + +code.o: + $(CXX) -c -o code.o code.cpp $(CXXFLAGS) + +clean: + rm -rf .discopop + rm -rf src/.discopop + find . -not -name code.cpp -not -name Makefile -not -path **/FileMapping.txt -delete + +veryclean: clean + rm -f FileMapping.txt diff --git a/test/optimizer/loop_collapse/negative/inner_loop_doall_only/src/code.cpp b/test/optimizer/loop_collapse/negative/inner_loop_doall_only/src/code.cpp new file mode 100644 index 000000000..5d4d23cf3 --- /dev/null +++ b/test/optimizer/loop_collapse/negative/inner_loop_doall_only/src/code.cpp @@ -0,0 +1,24 @@ +#include +#include + +int main(int argc, const char* argv[]) { + static int n = 50000; + double *x = (double *) malloc(n * sizeof(double)); + double *y = (double *) malloc(n * sizeof(double)); + // Initialize x, y + // Do-All + for(int i = 0; i < n; ++i){ + x[i] = 1.0; + y[i] = 2.0; + } + + // Not Do-All + for(int i = 0; i < n/10; i++){ + // Do-All + for(int j = 0; j < 10; j++){ + y[i*10 + j] = x[i*10 + j] + y[i*9 +j]; + } + } + free(x); + free(y); +} diff --git a/test/optimizer/loop_collapse/negative/inner_loop_doall_only/test.py b/test/optimizer/loop_collapse/negative/inner_loop_doall_only/test.py new file mode 100644 index 000000000..64e4d6b57 --- /dev/null +++ b/test/optimizer/loop_collapse/negative/inner_loop_doall_only/test.py @@ -0,0 +1,67 @@ +import os +import pathlib +import unittest + +import jsonpickle + +from discopop_library.result_classes.DetectionResult import DetectionResult +from test.utils.subprocess_wrapper.command_execution_wrapper import run_cmd +from test.utils.validator_classes.DoAllInfoForValidation import DoAllInfoForValidation +from discopop_library.ConfigProvider.config_provider import run as run_config_provider +from discopop_library.ConfigProvider.ConfigProviderArguments import ConfigProviderArguments + + +class TestMethods(unittest.TestCase): + def test(self): + current_dir = pathlib.Path(__file__).parent.resolve() + dp_build_dir = run_config_provider( + ConfigProviderArguments( + return_dp_build_dir=True, + return_dp_source_dir=False, + return_llvm_bin_dir=False, + return_version_string=False, + ) + ) + + env_vars = dict(os.environ) + + src_dir = os.path.join(current_dir, "src") + + # create FileMapping + cmd = os.path.join(dp_build_dir, "scripts", "dp-fmap") + run_cmd(cmd, src_dir, env_vars) + + # build + env_vars["CC"] = os.path.join(dp_build_dir, "scripts", "CC_wrapper.sh") + env_vars["CXX"] = os.path.join(dp_build_dir, "scripts", "CXX_wrapper.sh") + cmd = "make" + run_cmd(cmd, src_dir, env_vars) + # execute instrumented program + cmd = "./prog" + run_cmd(cmd, src_dir, env_vars) + # execute DiscoPoP analysis + cwd = os.path.join(src_dir, ".discopop") + run_cmd("discopop_explorer", cwd, env_vars) + run_cmd("discopop_optimizer -o3", cwd, env_vars) + # validate results + try: + self.validate_results(current_dir, src_dir) + # clean environment + run_cmd("make veryclean", src_dir, env_vars) + except Exception as ex: + # clean environment + run_cmd("make veryclean", src_dir, env_vars) + raise ex + + def validate_results(self, test_dir, src_dir): + """Check that not collapse has been identified""" + + # load test output + test_output_file = os.path.join(src_dir, ".discopop", "optimizer", "detection_result_dump.json") + with open(test_output_file, "r") as f: + tmp_str = f.read() + test_output: DetectionResult = jsonpickle.decode(tmp_str) + + # check identified DoAllInfo objects for collapse clauses > 1 + for do_all_info in test_output.patterns.do_all: + self.assertTrue(do_all_info.collapse_level <= 1) diff --git a/test/optimizer/loop_collapse/negative/outer_loop_doall_only/__init__.py b/test/optimizer/loop_collapse/negative/outer_loop_doall_only/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/test/optimizer/loop_collapse/negative/outer_loop_doall_only/src/Makefile b/test/optimizer/loop_collapse/negative/outer_loop_doall_only/src/Makefile new file mode 100644 index 000000000..8b1635880 --- /dev/null +++ b/test/optimizer/loop_collapse/negative/outer_loop_doall_only/src/Makefile @@ -0,0 +1,15 @@ +all: clean prog + +prog: code.o + $(CXX) -o prog code.o $(CXXFLAGS) + +code.o: + $(CXX) -c -o code.o code.cpp $(CXXFLAGS) + +clean: + rm -rf .discopop + rm -rf src/.discopop + find . -not -name code.cpp -not -name Makefile -not -path **/FileMapping.txt -delete + +veryclean: clean + rm -f FileMapping.txt diff --git a/test/optimizer/loop_collapse/negative/outer_loop_doall_only/src/code.cpp b/test/optimizer/loop_collapse/negative/outer_loop_doall_only/src/code.cpp new file mode 100644 index 000000000..2de863084 --- /dev/null +++ b/test/optimizer/loop_collapse/negative/outer_loop_doall_only/src/code.cpp @@ -0,0 +1,22 @@ +#include +#include + +int main(int argc, const char* argv[]) { + static int n = 5000; + double *x = (double *) malloc(n * sizeof(double)); + double *y = (double *) malloc(n * sizeof(double)); + // Initialize x, y + // Do-All + for(int i = 0; i < n; ++i){ + x[i] = 1.0; + y[i] = 2.0; + } + + // Do-All + for(int i = 0; i < n/10; i++){ + // Not Do-All + for(int j = 0; j < 100; j++){ + y[i*10 + j] = x[i*10 + j] + y[i*10 +((j+2)%10)]; + } + } +} diff --git a/test/optimizer/loop_collapse/negative/outer_loop_doall_only/test.py b/test/optimizer/loop_collapse/negative/outer_loop_doall_only/test.py new file mode 100644 index 000000000..64e4d6b57 --- /dev/null +++ b/test/optimizer/loop_collapse/negative/outer_loop_doall_only/test.py @@ -0,0 +1,67 @@ +import os +import pathlib +import unittest + +import jsonpickle + +from discopop_library.result_classes.DetectionResult import DetectionResult +from test.utils.subprocess_wrapper.command_execution_wrapper import run_cmd +from test.utils.validator_classes.DoAllInfoForValidation import DoAllInfoForValidation +from discopop_library.ConfigProvider.config_provider import run as run_config_provider +from discopop_library.ConfigProvider.ConfigProviderArguments import ConfigProviderArguments + + +class TestMethods(unittest.TestCase): + def test(self): + current_dir = pathlib.Path(__file__).parent.resolve() + dp_build_dir = run_config_provider( + ConfigProviderArguments( + return_dp_build_dir=True, + return_dp_source_dir=False, + return_llvm_bin_dir=False, + return_version_string=False, + ) + ) + + env_vars = dict(os.environ) + + src_dir = os.path.join(current_dir, "src") + + # create FileMapping + cmd = os.path.join(dp_build_dir, "scripts", "dp-fmap") + run_cmd(cmd, src_dir, env_vars) + + # build + env_vars["CC"] = os.path.join(dp_build_dir, "scripts", "CC_wrapper.sh") + env_vars["CXX"] = os.path.join(dp_build_dir, "scripts", "CXX_wrapper.sh") + cmd = "make" + run_cmd(cmd, src_dir, env_vars) + # execute instrumented program + cmd = "./prog" + run_cmd(cmd, src_dir, env_vars) + # execute DiscoPoP analysis + cwd = os.path.join(src_dir, ".discopop") + run_cmd("discopop_explorer", cwd, env_vars) + run_cmd("discopop_optimizer -o3", cwd, env_vars) + # validate results + try: + self.validate_results(current_dir, src_dir) + # clean environment + run_cmd("make veryclean", src_dir, env_vars) + except Exception as ex: + # clean environment + run_cmd("make veryclean", src_dir, env_vars) + raise ex + + def validate_results(self, test_dir, src_dir): + """Check that not collapse has been identified""" + + # load test output + test_output_file = os.path.join(src_dir, ".discopop", "optimizer", "detection_result_dump.json") + with open(test_output_file, "r") as f: + tmp_str = f.read() + test_output: DetectionResult = jsonpickle.decode(tmp_str) + + # check identified DoAllInfo objects for collapse clauses > 1 + for do_all_info in test_output.patterns.do_all: + self.assertTrue(do_all_info.collapse_level <= 1)