]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/blob - Makefile
Do not duplicate Makefile and ninja - all is now done by ninja
[hercules2020/kcf.git] / Makefile
1 # Makefile to build all the available variants
2
3 BUILDS = opencvfft-st opencvfft-async opencvfft-openmp fftw fftw-async fftw-openmp fftw-big fftw-big-openmp cufftw cufftw-big cufftw-big-openmp cufft cufft-openmp cufft-big cufft-big-openmp
4 TESTSEQ = bag ball1 car1 book
5 TESTFLAGS = default fit128
6
7 all: $(BUILDS)
8
9 ninja: build.ninja
10         ninja
11
12 $(BUILDS): build.ninja
13         ninja build-$@/build.ninja
14         ninja -C build-$@
15
16 clean: build.ninja
17         ninja $@
18
19 CMAKE_OPTS += -G Ninja
20
21 ## Useful setting - uncomment and modify as needed
22 # CMAKE_OPTS += -DOpenCV_DIR=~/opt/opencv-2.4/share/OpenCV
23 # CMAKE_OPTS += -DCUDA_VERBOSE_BUILD=ON -DCUDA_NVCC_FLAGS="--verbose;--save-temps"
24 # export CC=gcc-5
25 # export CXX=g++-5
26 # export CUDA_BIN_PATH=/usr/local/cuda-9.0
27 # export CUDA_ARCH_LIST=6.2
28
29 CMAKE_OTPS_opencvfft-st      = -DFFT=OpenCV
30 CMAKE_OTPS_opencvfft-async   = -DFFT=OpenCV -DASYNC=ON
31 CMAKE_OTPS_opencvfft-openmp  = -DFFT=OpenCV -DOPENMP=ON
32 CMAKE_OTPS_fftw              = -DFFT=fftw
33 CMAKE_OTPS_fftw-openmp       = -DFFT=fftw -DOPENMP=ON
34 CMAKE_OTPS_fftw-async        = -DFFT=fftw -DASYNC=ON
35 CMAKE_OTPS_fftw-big          = -DFFT=fftw -DBIG_BATCH=ON
36 CMAKE_OTPS_fftw-big-openmp   = -DFFT=fftw -DBIG_BATCH=ON -DOPENMP=ON
37 CMAKE_OTPS_cufftw            = -DFFT=cuFFTW $(if $(CUDA_ARCH_LIST),-DCUDA_ARCH_LIST='$(CUDA_ARCH_LIST)')
38 CMAKE_OTPS_cufftw-big        = -DFFT=cuFFTW $(if $(CUDA_ARCH_LIST),-DCUDA_ARCH_LIST='$(CUDA_ARCH_LIST)') -DBIG_BATCH=ON
39 CMAKE_OTPS_cufftw-big-openmp = -DFFT=cuFFTW $(if $(CUDA_ARCH_LIST),-DCUDA_ARCH_LIST='$(CUDA_ARCH_LIST)') -DBIG_BATCH=ON -DOPENMP=ON
40 CMAKE_OTPS_cufft             = -DFFT=cuFFT  $(if $(CUDA_ARCH_LIST),-DCUDA_ARCH_LIST='$(CUDA_ARCH_LIST)')
41 CMAKE_OTPS_cufft-openmp      = -DFFT=cuFFT  $(if $(CUDA_ARCH_LIST),-DCUDA_ARCH_LIST='$(CUDA_ARCH_LIST)') -DOPENMP=ON
42 CMAKE_OTPS_cufft-big         = -DFFT=cuFFT  $(if $(CUDA_ARCH_LIST),-DCUDA_ARCH_LIST='$(CUDA_ARCH_LIST)') -DBIG_BATCH=ON
43 CMAKE_OTPS_cufft-big-openmp  = -DFFT=cuFFT  $(if $(CUDA_ARCH_LIST),-DCUDA_ARCH_LIST='$(CUDA_ARCH_LIST)') -DBIG_BATCH=ON -DOPENMP=ON
44
45 ##########################
46 ### Tests
47 ##########################
48
49 print-test-results = grep ^Average $(1)|sed -E -e "s|build-(.*)/kcf_vot-(.*).log:|\2;\1;|"|sort|column -t -s";"
50
51 test $(BUILDS:%=test-%) $(SEQ:%=test-%): build.ninja
52         ninja $@
53
54 vot2016 $(TESTSEQ:%=vot2016/%): vot2016.zip
55         unzip -d vot2016 -q $^
56         for i in $$(ls -d vot2016/*/); do ( echo Creating $${i}images.txt; cd $$i; ls *.jpg > images.txt ); done
57
58 .INTERMEDIATE: vot2016.zip
59 .SECONDARY:    vot2016.zip
60 vot2016.zip:
61         wget http://data.votchallenge.net/vot2016/vot2016.zip
62
63 ###################
64 # Ninja generator #
65 ###################
66
67 # Building all $(BUILDS) with make is slow, even when run with in
68 # parallel (make -j). The target below generates build.ninja file that
69 # compiles all variants in the same ways as this makefile, but faster.
70 # The down side is that the build needs about 10 GB of memory.
71
72 define nl
73
74
75 endef
76
77 define echo
78 echo $(1) '$(subst $(nl),\n,$(subst \,\\,$(2)))';
79 endef
80
81 # Ninja generator - to have faster parallel builds and tests
82 .PHONY: build.ninja build.ninja.new
83
84 build.ninja: build.ninja.new
85         @cmp -s $@ $< || mv -v $< $@
86
87 build.ninja.new:
88         @$(call echo,>$@,$(ninja-rule))
89         @$(foreach build,$(BUILDS),\
90                 $(call echo,>>$@,$(call ninja-build,$(build),$(CMAKE_OTPS_$(build)))))
91         @$(foreach build,$(BUILDS),$(foreach seq,$(TESTSEQ),$(foreach f,$(TESTFLAGS),\
92                 $(call echo,>>$@,$(call ninja-testcase,$(build),$(seq),$(f)))$(nl))))
93         @$(call echo,>>$@,build test: PRINT_RESULTS $(foreach build,$(BUILDS),$(foreach seq,$(TESTSEQ),$(foreach f,$(TESTFLAGS),$(call ninja-test,$(build),$(seq),$(f))))))
94         @$(foreach build,$(BUILDS),$(call echo,>>$@,build test-$(build): PRINT_RESULTS $(foreach seq,$(TESTSEQ),$(foreach f,$(TESTFLAGS),$(call ninja-test,$(build),$(seq),$(f))))))
95         @$(foreach seq,$(TESTSEQ),$(call echo,>>$@,build test-$(seq): PRINT_RESULTS $(foreach build,$(BUILDS),$(foreach f,$(TESTFLAGS),$(call ninja-test,$(build),$(seq),$(f))))))
96         @$(foreach seq,$(TESTSEQ),$(call echo,>>$@,build vot2016/$(seq): MAKE))
97
98
99 define ninja-rule
100 rule CMAKE
101   command = cd $$$$(dirname $$out) && cmake $(CMAKE_OPTS) $$opts ..
102 rule NINJA
103   # Absolute path in -C allows Emacs to properly jump to error message locations
104   command = ninja -C `realpath $$$$(dirname $$out)` && touch $$out
105   description = Ninja $$out
106 rule TEST_SEQ
107   command = build-$$build/kcf_vot $$flags $$seq > $$out
108 rule PRINT_RESULTS
109   description = Print results
110   command = $(call print-test-results,$$in)
111 rule MAKE
112   command = make $$out
113 rule CLEAN
114 #  command = /usr/bin/ninja -t clean -r NINJA
115   description = Cleaning all built files...
116   command = rm -rf $(BUILDS:%=build-%)
117 build clean: CLEAN
118 endef
119
120 define ninja-build
121 build build-$(1)/build.ninja: CMAKE
122   opts = $(2)
123 build build-$(1)/kcf_vot: NINJA build-$(1)/build.ninja $(shell git ls-files)
124 default build-$(1)/kcf_vot
125 endef
126
127 ninja-test = build-$(1)/kcf_vot-$(2)-$(3).log
128
129 # Usage: ninja-testcase <build> <seq> <flags>
130 define ninja-testcase
131 build build-$(1)/kcf_vot-$(2)-$(3).log: TEST_SEQ build-$(1)/kcf_vot $(filter-out %/output.txt,$(wildcard vot2016/$(2)/*)) || vot2016/$(2)
132   build = $(1)
133   seq = vot2016/$(2)
134   flags = $(if $(3:fit128=),,--fit=128)
135 endef