Skip to content

Commit

Permalink
get groundtruth compiled and used in "make run" comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebentley15 committed Jun 30, 2017
1 parent 4c1b2f7 commit 41b9736
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 14 deletions.
58 changes: 46 additions & 12 deletions data/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
FFLAGS ?=
DEV_TARGET ?= devrun
DEV_CUTARGET ?= cu_devrun
GT_TARGET ?= gtrun
GT_OUT := ground-truth.csv

UNAME_S := $(shell uname -s)

Expand All @@ -25,6 +27,10 @@ DEV_CC ?= {dev_compiler}
DEV_OPTL ?= {dev_optl}
DEV_SWITCHES ?= {dev_switches}

GT_CC := {ground_truth_compiler}
GT_OPTL := {ground_truth_optl}
GT_SWITCHES := {ground_truth_switches}

LD_REQUIRED += -lm
LD_REQUIRED += -lstdc++
ifeq ($(UNAME_S),Darwin) # If we are on a Mac OSX system
Expand All @@ -42,8 +48,10 @@ TESTS := $(wildcard tests/*.cpp)
SOURCE := $(wildcard *.cpp)
SOURCE += $(TESTS)

DEV_OBJ := $(SOURCE:%.cpp=%_dev.o)
DEV_DEPS := $(SOURCE:%.cpp=%_dev.d)
DEV_OBJ = $(SOURCE:%.cpp=%_dev.o)
DEV_DEPS = $(SOURCE:%.cpp=%_dev.d)
GT_OBJ = $(SOURCE:%.cpp=%_gt.o)
GT_DEPS = $(SOURCE:%.cpp=%_gt.d)

CLANG := clang++
INTEL := icpc
Expand Down Expand Up @@ -298,15 +306,20 @@ help:
@echo ' help Show this help and exit (default target)'
@echo ' dev Only run the devel compilation to test things out'
@echo ' devcuda Only run the devel CUDA compilation to test CUDA out'
@echo ' groundtruth Compile the ground-truth version and get its output'
@echo ' gt Same as groundtruth'
@echo ' run Run all combinations of compilation, results in results/'
@echo ' clean Clean intermediate files'
@echo ' veryclean Runs clean + removes targets and results'
@echo ' distclean Same as veryclean'
@echo

.PHONY: dev devcuda run
.PHONY: dev devcuda gt groundtruth run
dev: $(DEV_TARGET)
devcuda: $(DEV_CUTARGET)
gt: $(GT_TARGET) $(GT_OUT)
groundtruth: $(GT_TARGET) $(GT_OUT)

run: $(TARGETS) $(CUTARGETS)

.PHONY: clean
Expand All @@ -316,22 +329,27 @@ clean:
rm -f $(DEV_CUOBJ)
rm -f $(OBJ)
rm -f $(CUOBJ)
rm -f $(GT_OBJ)
rm -f $(GT_DEPS)

.PHONY: veryclean distclean
veryclean: distclean
distclean: clean
rm -f $(DEV_TARGET)
rm -f $(DEV_CUTARGET)
rm -f $(TARGETS)
rm -f $(TARGETS:%.csv=%.csv*.dat)
rm -f $(addsuffix *.dat,$(TARGETS))
rm -f $(BIN)
rm -f $(CUTARGETS)
rm -f $(CUTARGETS:%.csv=%.csv*.dat)
rm -f $(addsuffix *.dat,$(CUTARGETS))
rm -f $(CUBIN)
rm -f $(GT_TARGET)
rm -f $(GT_OUT)
rm -f $(addsuffix *.dat,$(GT_OUT))
-rmdir $(RESULTS_DIR)

.PRECIOUS: %.d
-include $(SOURCE:%.cpp=%.d) $(DEV_DEPS)
-include $(SOURCE:%.cpp=%.d) $(DEV_DEPS) $(GT_DEPS)

Makefile: flit-config.toml $(dir $(FLIT_SCRIPT))/flit_update.py
$(FLIT_SCRIPT) update
Expand All @@ -348,6 +366,7 @@ cleanlibflit:
rm -rf lib

$(DEV_TARGET): lib/libflit.so
$(GT_TARGET): lib/libflit.so
$(BIN): lib/libflit.so
$(CUBIN): lib/libflit.so
endif # ifeq ($(UNAME_S),Darwin): meaning, we are on a mac
Expand All @@ -368,7 +387,7 @@ $(DEV_TARGET): $(DEV_OBJ) Makefile
-DFLIT_COMPILER='"$(DEV_CC)"' \
-DFLIT_OPTL='"$(DEV_OPTL)"' \
-DFLIT_SWITCHES='"$(DEV_SWITCHES)"' \
-DFLIT_FILENAME='"$(DEV_TARGET)"'
-DFLIT_FILENAME='"$(notdir $(DEV_TARGET))"'

ifdef HAS_CUDA
$(DEV_CUTARGET): $(DEV_CUOBJ) Makefile
Expand All @@ -378,11 +397,26 @@ $(DEV_CUTARGET): $(DEV_CUOBJ) Makefile
$(NVCC) -c $(NVCC_CFLAGS) $(DEV_NVCC_CC) $< -o $@
endif # ifdef HAS_CUDA

# Ground truth compilation rules
$(GT_OUT): $(GT_TARGET)
./$(GT_TARGET) --output $(GT_OUT)

$(GT_TARGET): $(GT_OBJ) Makefile
$(GT_CC) $(CC_REQUIRED) -o $@ $(GT_OBJ) $(LD_REQUIRED)

%_gt.o: %.cpp Makefile
$(GT_CC) $(GT_OPTL) $(GT_SWITCHES) $(CC_REQUIRED) $(DEPFLAGS) -c $< -o $@ \
-DFLIT_HOST='"$(HOSTNAME)"' \
-DFLIT_COMPILER='"$(GT_CC)"' \
-DFLIT_OPTL='"$(GT_OPTL)"' \
-DFLIT_SWITCHES='"$(GT_SWITCHES)"' \
-DFLIT_FILENAME='"$(notdir $(GT_TARGET))"'

# Now the true magic begins for the full run compilation rules
# very cool: recyclable target definitions! adapted from
# http://make.mad-scientist.net/the-eval-function/


# TODO: try without PERCENT variable
PERCENT := %

# Generates rules for
Expand All @@ -397,8 +431,8 @@ PERCENT := %
# @param $3: variable name containing the optimization level (e.g. O2)
define TARGETS_RULE
# run test and collect results
$$(RESULTS_DIR)/$(strip $2)_$$(HOSTNAME)_$(strip $1)_$(strip $3)_out.csv: $$(RESULTS_DIR)/$(strip $2)_$$(HOSTNAME)_$(strip $1)_$(strip $3)
-./$$< --output $$@
$$(RESULTS_DIR)/$(strip $2)_$$(HOSTNAME)_$(strip $1)_$(strip $3)_out.csv: $$(RESULTS_DIR)/$(strip $2)_$$(HOSTNAME)_$(strip $1)_$(strip $3) $$(GT_OUT)
-./$$< --output $$@ --ground-truth $$(GT_OUT)

# link
$$(RESULTS_DIR)/$(strip $2)_$$(HOSTNAME)_$(strip $1)_$(strip $3) : $$(SOURCE:$(PERCENT).cpp=$(PERCENT)_$(strip $2)_$$(HOSTNAME)_$(strip $1)_$(strip $3).o)
Expand Down Expand Up @@ -437,8 +471,8 @@ $(foreach c, $(COMPILERS), \
# (e.g. UNSOPTS for --funsafe-math-optimizations)
define CUTARGETS_RULE
#run test
NVCC_$$(HOSTNAME)_$(strip $1)_out.csv : NVCC_$$(HOSTNAME)_$(strip $1)
./$$< --output $$@
NVCC_$$(HOSTNAME)_$(strip $1)_out.csv : NVCC_$$(HOSTNAME)_$(strip $1) $$(GT_OUT)
./$$< --output $$@ --ground-truth $$(GT_OUT)

#link test
NVCC_$$(HOSTNAME)_$(strip $1) : $$(CUSOURCE:$(PERCENT).cpp=$(PERCENT)_NVCC_$$(HOSTNAME)_$(strip $1).o)
Expand Down
22 changes: 20 additions & 2 deletions scripts/flitcli/flit_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def main(arguments, prog=sys.argv[0]):
dev_compiler_name = dev_build['compiler_name']
dev_optl = dev_build['optimization_level']
dev_switches = dev_build['switches']
matching_dev_compilers = [x for x in projconf['hosts'][0]['compilers']
if x['name'] == dev_compiler_name]
matching_dev_compilers = [x for x in host['compilers']
if x['name'] == dev_compiler_name]
assert len(matching_dev_compilers) > 0, \
'Compiler name {0} not found'.format(dev_compiler_name)
assert len(matching_dev_compilers) < 2, \
Expand All @@ -54,13 +54,31 @@ def main(arguments, prog=sys.argv[0]):
if '/' in dev_compiler_bin:
dev_compiler_bin = os.path.realpath(dev_compiler_bin)

ground_truth = host['ground_truth']
gt_compiler_name = ground_truth['compiler_name']
gt_optl = ground_truth['optimization_level']
gt_switches = ground_truth['switches']
matching_gt_compilers = [x for x in host['compilers']
if x['name'] == gt_compiler_name]
assert len(matching_dev_compilers) > 0, \
'Compiler name {0} not found'.format(gt_compiler_name)
assert len(matching_dev_compilers) < 2, \
'Multiple compilers with name {0} found'.format(gt_compiler_names)
# TODO: use the compiler mnemonic rather than the path
gt_compiler_bin = matching_gt_compilers[0]['binary']
if '/' in dev_compiler_bin:
gt_compiler_bin = os.path.realpath(gt_compiler_name)

flitutil.process_in_file(
os.path.join(conf.data_dir, 'Makefile.in'),
makefile,
{
'dev_compiler': dev_compiler_bin,
'dev_optl': dev_optl,
'dev_switches': dev_switches,
'ground_truth_compiler': gt_compiler_bin,
'ground_truth_optl': gt_optl,
'ground_truth_switches': gt_switches,
'flit_include_dir': conf.include_dir,
'flit_lib_dir': conf.lib_dir,
'flit_script': os.path.join(conf.script_dir, 'flit.py'),
Expand Down

0 comments on commit 41b9736

Please sign in to comment.