-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile.guix
171 lines (135 loc) · 5.21 KB
/
Makefile.guix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# GNU Guix makefile
#
# To build faster_lmm_d on GNU Guix:
#
# make -f Makefile.guix [CUDA=1] [VALIDATE=1] [FORCE_DUPLICATE=1] [BLAS=1] [debug|release|check]
#
# run with
#
# ./build/faster_lmm_d
#
# where
#
# BLAS=1 builds with standard BLAS instead of OpenBLAS
# CUDA=1 builds with CUDA support
# FORCE_DUPLICATE=1 prevents overwrites (purity)
# PARALLEL=0 switch off parallel compute
# VALIDATE=1 validates matrix multiplication
# LIB_PATH= set lib path
#
# current combinations are
#
# Default: -
# Parallel version: PARALLEL=1 BLAS=1
# CUDA version: CUDA=1
#
# Example:
#
# make -f Makefile.guix -j 4 LIB_PATH=~/opt/ldc/lib
# make -f Makefile.guix -j 4 LIB_PATH=~/opt/ldc/lib CUDA=1 CUDA_LIB_PATH=/home/pjotr/opt/lib
# The following two are modified by the Guix package:
D_COMPILER=$(shell which ldc2)
LDC_LIB_PATH=$(shell dirname $(shell dirname $(D_COMPILER)))/lib
LIB_PATH=$(HOME)/.guix-profile/lib
ifdef CUDA
CUDA_LIB_PATH=/usr/local/cuda-7.0/lib64
endif
DUB_INCLUDE = \
-I~/.dub/packages/dstats-1.0.3/dstats/source/ \
-I~/.dub/packages/gsl-0.1.8/gsl/source/ \
-I~/.dub/packages/cblas-1.0.0/cblas/source/ \
-I~/.dub/packages/dyaml-0.6.3/dyaml/source/ \
-I~/.dub/packages/tinyendian-0.1.2/tinyendian/source/ \
-I~/.dub/packages/resusage-0.2.7/resusage/source/
DUB_LIBS = \
$(HOME)/.dub/packages/dstats-1.0.3/dstats/libdstats.a \
$(HOME)/.dub/packages/dyaml-0.6.3/dyaml/libdyaml.a \
$(HOME)/.dub/packages/gsl-0.1.8/gsl/libgsl.a \
$(HOME)/.dub/packages/tinyendian-0.1.2/tinyendian/libtinyendian.a \
$(HOME)/.dub/packages/resusage-0.2.7/resusage/lib/libresusage.a
ifdef CUDA
DUB_INCLUDE += -I~/.dub/packages/cuda_d-0.1.0/cuda_d/source/
DUB_LIBS += $(HOME)/.dub/packages/cuda_d-0.1.0/cuda_d/libcuda_d.a
endif
DFLAGS = -wi -I./source $(DUB_INCLUDE)
DLIBS = $(LDC_LIB_PATH)/libphobos2-ldc.a $(LDC_LIB_PATH)/libdruntime-ldc.a $(DUB_LIBS)
DLIBS_DEBUG = $(LDC_LIB_PATH)/libphobos2-ldc-debug.a $(LDC_LIB_PATH)/libdruntime-ldc-debug.a $(DUB_LIBS)
RPATH = -L--rpath=$(dir $(realpath $(LIB_PATH)/libstdc++.so.6)):$(dir $(realpath $(LIB_PATH)/libopenblas.so)):$(dir $(realpath $(LIB_PATH)/liblapacke.so.3)):$(dir $(realpath $(LIB_PATH)/libgsl.so.23)):$(dir $(realpath $(LIB_PATH)/librt.so)):$(realpath $(CUDA_LIB_PATH)):/usr/local/cuda-7.0/lib64
LIBS = -L-L$(LDC_LIB_PATH) -L-L$(LIB_PATH) -L-lgsl
ifdef BLAS
LIBS += -L-lgslcblas -L-lblas
else
LIBS += -L-lopenblas
endif
LIBS += -L-llapacke -L-llapack
SRC = $(wildcard source/faster_lmm_d/*.d) $(wildcard source/faster_lmm_d/*/*.d) $(wildcard source/test/*.d)
OBJ = $(SRC:.d=.o)
OUT = build/faster_lmm_d
ifdef CUDA
LIBS += -L-L$(CUDA_LIB_PATH) -L-L/usr/local/cuda-7.0/lib64 -L=-lcublas -L=-lcudart -L=-lcuda
# LIBS += $(CUDA_LIB_PATH)/libcublas_static.a $(CUDA_LIB_PATH)/libcudart_static.a /usr/lib/x86_64-linux-gnu/crti.o /usr/lib/x86_64-linux-gnu/crt1.o
# LIBS += $(CUDA_LIB_PATH)/libcublas_static.a $(CUDA_LIB_PATH)/libcudart_static.a /usr/lib/x86_64-linux-gnu/crti.o /usr/lib/x86_64-linux-gnu/crt1.o
endif
# The Guix targets resolve the RPATH automatically
guix: DFLAGS += -O -g -inline
guix-debug: DFLAGS += -O0 -g -d-debug -unittest
# The development options are run from ~/.guix-profile and need to inject the RPATH
debug: DFLAGS += -O0 -g -d-debug $(RPATH) -link-debuglib -disable-fp-elim -unittest
release: DFLAGS += -O -release $(RPATH)
profile: DFLAGS += -fprofile-instr-generate=fast_lmm_d-profiler.out $(RPATH)
getIR: DFLAGS += -output-ll
getBC: DFLAGS += -output-bc
gperf: LIBS += -L=-lprofiler
gperf: DUB_INCLUDE += -I~/.dub/packages/gperftools_d-0.1.0/gperftools_d/source/
gperf: DUB_LIBS += $(HOME)/.dub/packages/gperftools_d-0.1.0/gperftools_d/libgperftools_d.a
guix release: LIBS += $(DLIBS)
guix-debug debug profile: LIBS += $(DLIBS_DEBUG)
.PHONY: all guix guix-debug debug release profile clean cleanIR cleanBC test gperf
all: debug
build-setup:
mkdir -p build/
guix guix-debug default debug release profile getIR getBC gperf: $(OUT)
ifdef CUDA
DFLAGS += -d-version=CUDA
endif
ifdef FORCE_DUPLICATE
DFLAGS += -d-version=FORCE_DUPLICATE
endif
ifndef PARALLEL
DFLAGS += -d-version=PARALLEL
endif
ifdef VALIDATE
DFLAGS += -d-version=VALIDATE
endif
# ---- Compile step
%.o: %.d
$(D_COMPILER) $(DFLAGS) -c $< -od=$(dir $@)
# ---- Link step
$(OUT): build-setup $(OBJ)
$(D_COMPILER) $(DFLAGS) -of=build/faster_lmm_d $(OBJ) $(LIBS)
test:
./run_tests.sh
check: test # alias
debug-strip: debug
objcopy --only-keep-debug build/faster_lmm_d faster_lmm_d.debug
objcopy --strip-debug build/faster_lmm_d
objcopy --add-gnu-debuglink=faster_lmm_d.debug build/faster_lmm_d
mv faster_lmm_d.debug build/
# ---- Get profiler info, see https://wiki.dlang.org/LDC_LLVM_profiling_instrumentation
run-profiler: profile test
ldc-profdata merge fast_lmm_d-profiler.out -output faster_lmm_d.profdata
install:
install -m 0755 build/faster_lmm_d $(prefix)/bin
run-gperf: gperf
$ CPUPROFILE=./prof.out ./run_tests.sh
pprof --gv build/faster_lmm_d ./prof.out
clean:
rm -rf build/*
rm -vf source/faster_lmm_d/*.{a,o}
rm -vf source/faster_lmm_d/*/*.{a,o}
rm -vf source/test/*.{a,o}
rm -f $(OBJ) $(OUT) trace.{def,log}
cleanIR:
rm -f $(IR) trace.{def,log}
cleanBC:
rm -f $(BC) trace.{def,log}