-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95df276
commit 8a0a3c8
Showing
8 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
15 changes: 15 additions & 0 deletions
15
test/optimizer/loop_collapse/negative/inner_loop_doall_only/src/Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
24 changes: 24 additions & 0 deletions
24
test/optimizer/loop_collapse/negative/inner_loop_doall_only/src/code.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
|
||
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); | ||
} |
67 changes: 67 additions & 0 deletions
67
test/optimizer/loop_collapse/negative/inner_loop_doall_only/test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
Empty file.
15 changes: 15 additions & 0 deletions
15
test/optimizer/loop_collapse/negative/outer_loop_doall_only/src/Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
22 changes: 22 additions & 0 deletions
22
test/optimizer/loop_collapse/negative/outer_loop_doall_only/src/code.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
|
||
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)]; | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
test/optimizer/loop_collapse/negative/outer_loop_doall_only/test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |