From 41b9736922dd0f77761b032cbe6888cac70c3543 Mon Sep 17 00:00:00 2001 From: Michael Bentley Date: Fri, 30 Jun 2017 00:15:00 -0700 Subject: [PATCH] get groundtruth compiled and used in "make run" comparisons --- data/Makefile.in | 58 +++++++++++++++++++++++++++------- scripts/flitcli/flit_update.py | 22 +++++++++++-- 2 files changed, 66 insertions(+), 14 deletions(-) diff --git a/data/Makefile.in b/data/Makefile.in index 5a376019..d4afe49a 100644 --- a/data/Makefile.in +++ b/data/Makefile.in @@ -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) @@ -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 @@ -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 @@ -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 @@ -316,6 +329,8 @@ clean: rm -f $(DEV_CUOBJ) rm -f $(OBJ) rm -f $(CUOBJ) + rm -f $(GT_OBJ) + rm -f $(GT_DEPS) .PHONY: veryclean distclean veryclean: distclean @@ -323,15 +338,18 @@ 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 @@ -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 @@ -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 @@ -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 @@ -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) @@ -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) diff --git a/scripts/flitcli/flit_update.py b/scripts/flitcli/flit_update.py index fd5f5187..53e324b0 100644 --- a/scripts/flitcli/flit_update.py +++ b/scripts/flitcli/flit_update.py @@ -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, \ @@ -54,6 +54,21 @@ 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, @@ -61,6 +76,9 @@ def main(arguments, prog=sys.argv[0]): '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'),