Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try using precompiled headers to speed up tests #672

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*.o-*
*.exe
*.a
*.gch

# /doc/
/doc/api
Expand Down
94 changes: 87 additions & 7 deletions make/tests
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@ GTEST_CXXFLAGS += -isystem $(GTEST)/include -isystem $(GTEST) -O$O
##
# Build the google test library.
##
$(GTEST)/src/gtest-all.o: CXXFLAGS += $(GTEST_CXXFLAGS)

test/%$(EXE) : CXXFLAGS += $(GTEST_CXXFLAGS)
test/%$(EXE) : test/%.o $(GTEST_MAIN) $(GTEST)/src/gtest-all.o
$(LINK.cpp) -o $@ $^


$(GTEST)/src/gtest-all.o: $(GTEST)/src/gtest-all.cc
$(COMPILE.cpp) -o $@ $<

$(GTEST)/%.cc: ;

##
# Rule for generating dependencies.
Expand All @@ -43,6 +39,7 @@ test/unit/libmultiple.so : test/unit/multiple_translation_units1.o test/unit/mul

test/unit/multiple_translation_units_test.cpp : test/unit/libmultiple.so


############################################################
#
# CVODES tests
Expand Down Expand Up @@ -76,6 +73,89 @@ test/dummy.cpp:
.PHONY: test-headers
test-headers: $(HEADER_TESTS)

test/unit/math_include_test.o: test/unit/math_include_test.cpp
$(COMPILE.cpp) $< -o $@

############################################################
#
# General make targets for tests
# (necessary now that implicit SUFFIX rules are actually turned off)
#

test/%$(EXE) : CXXFLAGS += $(GTEST_CXXFLAGS)
test/%$(EXE) : test/%.o $(GTEST_MAIN) $(GTEST)/src/gtest-all.o
$(LINK.cpp) -o $@ $^

# We need these explicit targets here because we turned off suffixes. We can't
# make a more general pattern rule like test/%.o because we want to force make
# to generate the pre-compiled headers (below) when applicable.
test/unit/math_c11_test.o: test/unit/math_c11_test.cpp
$(COMPILE.cpp) $< -o $@

test/unit/math/memory/%.o: test/unit/math/memory/%.cpp
$(COMPILE.cpp) $< -o $@

############################################################
#
# Targets to include proper pre-compiled header files (.hpp.gch) for unit tests
# and distribution tests
##

.PRECIOUS: %.hpp.gch test/%.o

%.hpp.gch: %.hpp
$(COMPILE.cpp) -o $@ $(@:.gch=)

test/prob/%.o : stan/math/mix/mat.hpp.gch test/prob/%.cpp
$(COMPILE.cpp) $(if $(filter $(CC_TYPE),clang++),-include-pch $<) -o $@ $(@:.o=.cpp)

test/unit/math/prim/scal/%.o : stan/math/prim/scal.hpp.gch test/unit/math/prim/scal/%.cpp
$(COMPILE.cpp) $(if $(filter $(CC_TYPE),clang++),-include-pch $<) -o $@ $(@:.o=.cpp)

test/unit/math/prim/arr/%.o : stan/math/prim/arr.hpp.gch test/unit/math/prim/arr/%.cpp
$(COMPILE.cpp) $(if $(filter $(CC_TYPE),clang++),-include-pch $<) -o $@ $(@:.o=.cpp)

test/unit/math/prim/mat/%.o : stan/math/prim/mat.hpp.gch test/unit/math/prim/mat/%.cpp
$(COMPILE.cpp) $(if $(filter $(CC_TYPE),clang++),-include-pch $<) -o $@ $(@:.o=.cpp)

test/unit/math/rev/core/%.o : stan/math/rev/core.hpp.gch test/unit/math/rev/core/%.cpp
$(COMPILE.cpp) $(if $(filter $(CC_TYPE),clang++),-include-pch $<) -o $@ $(@:.o=.cpp)

test/unit/math/rev/scal/%.o : stan/math/rev/scal.hpp.gch test/unit/math/rev/scal/%.cpp
$(COMPILE.cpp) $(if $(filter $(CC_TYPE),clang++),-include-pch $<) -o $@ $(@:.o=.cpp)

test/unit/math/rev/arr/%.o : stan/math/rev/arr.hpp.gch test/unit/math/rev/arr/%.cpp
$(COMPILE.cpp) $(if $(filter $(CC_TYPE),clang++),-include-pch $<) -o $@ $(@:.o=.cpp)

test/unit/math/rev/mat/%.o : stan/math/rev/mat.hpp.gch test/unit/math/rev/mat/%.cpp
$(COMPILE.cpp) $(if $(filter $(CC_TYPE),clang++),-include-pch $<) -o $@ $(@:.o=.cpp)

test/unit/math/fwd/core/%.o : stan/math/fwd/core.hpp.gch test/unit/math/fwd/core/%.cpp
$(COMPILE.cpp) $(if $(filter $(CC_TYPE),clang++),-include-pch $<) -o $@ $(@:.o=.cpp)

test/unit/math/fwd/scal/%.o : stan/math/fwd/scal.hpp.gch test/unit/math/fwd/scal/%.cpp
$(COMPILE.cpp) $(if $(filter $(CC_TYPE),clang++),-include-pch $<) -o $@ $(@:.o=.cpp)

test/unit/math/fwd/arr/%.o : stan/math/fwd/arr.hpp.gch test/unit/math/fwd/arr/%.cpp
$(COMPILE.cpp) $(if $(filter $(CC_TYPE),clang++),-include-pch $<) -o $@ $(@:.o=.cpp)

test/unit/math/fwd/mat/%.o : stan/math/fwd/mat.hpp.gch test/unit/math/fwd/mat/%.cpp
$(COMPILE.cpp) $(if $(filter $(CC_TYPE),clang++),-include-pch $<) -o $@ $(@:.o=.cpp)

test/unit/math/mix/scal/%.o : stan/math/mix/scal.hpp.gch test/unit/math/mix/scal/%.cpp
$(COMPILE.cpp) $(if $(filter $(CC_TYPE),clang++),-include-pch $<) -o $@ $(@:.o=.cpp)

test/unit/math/mix/arr/%.o : stan/math/mix/arr.hpp.gch test/unit/math/mix/arr/%.cpp
$(COMPILE.cpp) $(if $(filter $(CC_TYPE),clang++),-include-pch $<) -o $@ $(@:.o=.cpp)

test/unit/math/mix/mat/%.o : stan/math/mix/mat.hpp.gch test/unit/math/mix/mat/%.cpp
$(COMPILE.cpp) $(if $(filter $(CC_TYPE),clang++),-include-pch $<) -o $@ $(@:.o=.cpp)

# No stan/math/mix/core.hpp exists
test/unit/math/mix/core/%.o : test/unit/math/mix/core/%.cpp
$(COMPILE.cpp) -o $@ $(@:.o=.cpp)


############################################################
##
# Test generator for distribution tests
Expand Down
5 changes: 2 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Makefile for Stan.
##

.SUFFIXES:

# The default target of this Makefile is...
help:

## Disable implicit rules.
SUFIXES:

include make/default_compiler_options

##
Expand Down
2 changes: 1 addition & 1 deletion runTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

winsfx = ".exe"
testsfx = "_test.cpp"
batchSize = 25
batchSize = 32


def processCLIArgs():
Expand Down