diff --git a/Makefile b/Makefile index 1925282..b354dac 100644 --- a/Makefile +++ b/Makefile @@ -215,9 +215,40 @@ 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 + $(MAKE) -C tests -f Makefile clean + $(MAKE) -C tests -f Makefile_ocl clean diff --git a/src/ocldev.h b/src/ocldev.h index 68ea286..4a5b552 100644 --- a/src/ocldev.h +++ b/src/ocldev.h @@ -257,14 +257,29 @@ namespace dev { oclSafeCall(clGetPlatformInfo(PlatformIDs[dev], CL_PLATFORM_NAME, sizeof(platform_string), &platform_string, NULL)); std::cerr << " " << dev << ": " << platform_string << "\n"; } - fprintf(stderr, "Using platform %d \n", platform_id); - PlatformID = PlatformIDs[platform_id]; + + // Prefer NVIDIA platform if available. + int selected_platform = platform_id; + if (platform_id == 0 && numPlatforms > 1) { + for (cl_uint p = 0; p < numPlatforms; p++) { + char platform_string[1024]; + oclSafeCall(clGetPlatformInfo(PlatformIDs[p], CL_PLATFORM_NAME, sizeof(platform_string), &platform_string, NULL)); + if (strstr(platform_string, "NVIDIA") != NULL) { + std::cerr << "Found NVIDIA platform at index " << p << ", preferring it over others.\n"; + selected_platform = p; + break; + } + } + } + + fprintf(stderr, "Using platform %d \n", selected_platform); + PlatformID = PlatformIDs[selected_platform]; oclSafeCall(clGetDeviceIDs(PlatformID, DeviceType, 0, NULL, &DeviceCount)); Devices.resize(DeviceCount); oclSafeCall(clGetDeviceIDs(PlatformID, DeviceType, DeviceCount, &Devices[0], &DeviceCount)); - + std::cerr << "Found " << DeviceCount << " suitable devices: \n"; for (cl_uint dev = 0; dev < DeviceCount; dev++) { char device_string[1024]; 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)