diff --git a/.gitignore b/.gitignore index 542e9ff..df6a70c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ *.cle *.clh *.swp +.backend.stamp diff --git a/Makefile b/Makefile index 1925282..17b1df5 100644 --- a/Makefile +++ b/Makefile @@ -151,6 +151,26 @@ OBJS := $(CXX_SRC:%.cpp=%.o) INCLUDES += -Isrc CXXFLAGS += $(INCLUDES) -fPIC -g -O3 -Wall -Wextra -Wstrict-aliasing=2 -fopenmp +# The objects are backend-specific: the CUDA backend compiles cudadev.h while +# the OpenCL backend compiles ocldev.h (selected by -D_OCL_). Make only tracks +# file timestamps, not the value of BACKEND, so after building one backend a +# subsequent build with the other backend would silently reuse the existing +# objects and library. That produced the reported failure: an OpenCL test +# linked against a CUDA-compiled libsapporo2 tried to cuModuleLoad() a .cl +# source file, aborting with CUDA_ERROR_INVALID_IMAGE in cudadev.h. +# +# Record the active backend in a stamp file and depend on it so that switching +# BACKEND forces the objects to be recompiled. The stamp is only rewritten when +# the backend actually changes, so unchanged rebuilds stay incremental. +BACKEND_STAMP := .backend.stamp + +.PHONY: FORCE +$(BACKEND_STAMP): FORCE + @[ "$$(cat $@ 2>/dev/null)" = "$(BACKEND)" ] || \ + { echo "Backend changed to $(BACKEND), rebuilding objects"; echo "$(BACKEND)" > $@; } + +$(OBJS): $(BACKEND_STAMP) + src/sapporohostclass.o: $(KERNELS) %.o: %.cpp @@ -215,9 +235,41 @@ uninstall: rm -rf $(INSTALLED_LIBS) $(INSTALLED_HEADERS) +# Tests +# Build the test programs against the freshly built libraries and run the +# GPU-vs-CPU correctness tests for each supported integration order. The +# backend selected above determines which test Makefile and binaries are used. +ifeq ($(BACKEND), CUDA) + TEST_MAKEFILE := Makefile + TEST_SUFFIX := cuda +else + TEST_MAKEFILE := Makefile_ocl + TEST_SUFFIX := ocl +endif + +CORRECTNESS_TESTS := test_gravity_block_$(TEST_SUFFIX) \ + test_gravity_block_g5_$(TEST_SUFFIX) \ + test_gravity_block_6th_$(TEST_SUFFIX) + +.PHONY: build-tests +build-tests: all + $(MAKE) -C tests -f $(TEST_MAKEFILE) CXX="$(CXX)" CC="$(CC)" \ + $(if $(CUDA_TK),CUDA_TK="$(CUDA_TK)") + +.PHONY: test +test: build-tests + @for t in $(CORRECTNESS_TESTS); do \ + echo "=== Running $$t ==="; \ + ( cd tests && LD_LIBRARY_PATH="$(CURDIR):$$LD_LIBRARY_PATH" ./$$t ) || exit 1; \ + done + + # Clean-up .PHONY: clean clean: rm -f *.a *.so src/*.o src/SSE_AVX/SSE/*.o src/SSE_AVX/AVX/*.o rm -f src/CUDA/*.ptx src/CUDA/*.ptxh src/OpenCL/*.cle src/OpenCL/*.clh + rm -f $(BACKEND_STAMP) + $(MAKE) -C tests -f Makefile clean + $(MAKE) -C tests -f Makefile_ocl clean diff --git a/tests/Makefile_ocl b/tests/Makefile_ocl index 11ea0c1..5d5c106 100644 --- a/tests/Makefile_ocl +++ b/tests/Makefile_ocl @@ -3,7 +3,7 @@ CXX ?= g++ .SUFFIXES: .o .cpp .ptx .cu SAPPOROPATH=.. -SAPLIB2 = sapporo +SAPLIB2 = sapporo2 SAPLIB = lib$(SAPLIB2).a SAPLIBG6 = sapporoG6 @@ -28,7 +28,7 @@ PROG = test_gravity_block_ocl test_gravity_block_6th_ocl test_performance_rangeN all: $(OBJ) $(PROG) kernels kernels: - rm -f OpenCL && ln -s $(SAPPOROPATH)/OpenCL OpenCL + rm -f OpenCL && ln -s $(SAPPOROPATH)/src/OpenCL OpenCL test_gravity_block_ocl : test_gravity_block_ocl.o $(CXX) $(LDFLAGS) $^ -o $@ -L $(SAPPOROPATH) -l$(SAPLIB2) $(LDFLAGS)