File: Makefile

package info (click to toggle)
libxsmm 1.17-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 14,976 kB
  • sloc: ansic: 119,587; cpp: 27,680; fortran: 9,179; sh: 5,765; makefile: 5,040; pascal: 2,312; python: 1,812; f90: 1,773
file content (297 lines) | stat: -rw-r--r-- 7,617 bytes parent folder | download | duplicates (2)
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
###############################################################################
# Copyright (c) Intel Corporation - All rights reserved.                      #
# This file is part of the LIBXSMM library.                                   #
#                                                                             #
# For information on the license, see the LICENSE file.                       #
# Further information: https://github.com/hfp/libxsmm/                        #
# SPDX-License-Identifier: BSD-3-Clause                                       #
###############################################################################
# Sasikanth Avancha, Dhiraj Kalamkar, Alexander Heinecke (Intel Corp.)
###############################################################################

PROJECT := gxm

CONFIG_FILE := Makefile.config
include $(CONFIG_FILE)

BUILD_DIR_LINK := $(BUILD_DIR)
ifeq ($(RELEASE_BUILD_DIR),)
	RELEASE_BUILD_DIR := .$(BUILD_DIR)_release
endif
ifeq ($(DEBUG_BUILD_DIR),)
	DEBUG_BUILD_DIR := .$(BUILD_DIR)_debug
endif

DEBUG ?= 0
ifeq ($(DEBUG), 1)
	BUILD_DIR := $(DEBUG_BUILD_DIR)
	OTHER_BUILD_DIR := $(RELEASE_BUILD_DIR)
else
	BUILD_DIR := $(RELEASE_BUILD_DIR)
	OTHER_BUILD_DIR := $(DEBUG_BUILD_DIR)
endif

# All of the directories containing code.
SRC_DIRS := $(shell find * -type d -exec bash -c "find {} -maxdepth 1 \
	\( -name '*.cpp' -o -name '*.proto' \) | grep -q ." \; -print)

BINARY_NAME := $(PROJECT)
BIN_BUILD_DIR := $(BUILD_DIR)/bin
FULL_BIN_NAME := $(BIN_BUILD_DIR)/$(BINARY_NAME)

# Source files
# CXX_SRCS are the source files excluding the test ones.
CXX_SRCS := $(shell find src/ ! -name "test_*.cpp" -name "*.cpp" | sort)
#$(info CXX_SRCS = $(CXX_SRCS))
# BUILD_INCLUDE_DIR contains any generated header files we want to include.
BUILD_INCLUDE_DIR := $(BUILD_DIR)
# PROTO_SRCS are the protocol buffer definitions
PROTO_SRC_DIR := proto
PROTO_SRCS := $(wildcard $(PROTO_SRC_DIR)/*.proto)
# PROTO_BUILD_DIR will contain the .cc and obj files generated from
# PROTO_SRCS; PROTO_BUILD_INCLUDE_DIR will contain the .h header files
PROTO_BUILD_DIR := $(BUILD_DIR)/$(PROTO_SRC_DIR)
PROTO_BUILD_INCLUDE_DIR := $(BUILD_DIR)/proto
NONGEN_CXX_SRCS := $(shell find \
	src/ \
	include/ \
	-name "*.cpp" -or -name "*.hpp")

# Generated files
# The generated files for protocol buffers
PROTO_GEN_HEADER_SRCS := $(addprefix $(PROTO_BUILD_DIR)/, \
		$(call qndir,${PROTO_SRCS:.proto=.pb.h}))
PROTO_GEN_HEADER := $(addprefix $(PROTO_BUILD_INCLUDE_DIR)/, \
		$(call qndir,${PROTO_SRCS:.proto=.pb.h}))
PROTO_GEN_CC := $(addprefix $(BUILD_DIR)/, ${PROTO_SRCS:.proto=.pb.cc})
# Source file objects
CXX_OBJS := $(addprefix $(BUILD_DIR)/, ${CXX_SRCS:.cpp=.o})
PROTO_OBJS := ${PROTO_GEN_CC:.cc=.o}
OBJS := $(PROTO_OBJS) $(CXX_OBJS)
# Output files for automatic dependency generation
DEPS := ${CXX_OBJS:.o=.d}

# Compiler warning locations
WARNS_EXT := warnings.txt
CXX_WARNS := $(addprefix $(BUILD_DIR)/, ${CXX_SRCS:.cpp=.o.$(WARNS_EXT)})
ALL_WARNS := $(ALL_CXX_WARNS)
EMPTY_WARN_REPORT := $(BUILD_DIR)/.$(WARNS_EXT)
NONEMPTY_WARN_REPORT := $(BUILD_DIR)/$(WARNS_EXT)

# include and lib directories

INCLUDE_DIRS += $(BUILD_INCLUDE_DIR) ./src ./include
LIBRARIES += glog gflags protobuf m

USE_OPENCV ?= 1

ifeq ($(USE_OPENCV), 1)
	LIBRARIES += opencv_core opencv_highgui opencv_imgproc

	ifeq ($(OPENCV_VERSION), 3)
		LIBRARIES += opencv_imgcodecs
	endif
endif

WARNINGS := -Wall -Wno-sign-compare

# build directories
LIB_BUILD_DIR := ./lib
ALL_BUILD_DIRS := $(sort $(BUILD_DIR) $(addprefix $(BUILD_DIR)/, $(SRC_DIRS)) \
	$(LIB_BUILD_DIR) $(BIN_BUILD_DIR) $(PROTO_BUILD_INCLUDE_DIR))

# build
# Determine platform
UNAME := $(shell uname -s)
ifeq ($(UNAME), Linux)
	LINUX := 1
endif

# Linux
ifeq ($(LINUX), 1)
	LIBRARIES += stdc++
endif

# Custom compiler
ifdef CUSTOM_CXX
	CXX := $(CUSTOM_CXX)
endif

# Architecture
ifeq ($(ARCH), avx2)
	COMMON_FLAGS += -xCORE-AVX2
endif
ifeq ($(ARCH), avx512_common)
	COMMON_FLAGS += -xCOMMON-AVX512
	#CXXFLAGS += -DUSE_NTS_SPLIT -DUSE_NTS_BN -DUSE_BLOCKING_BN
endif
ifeq ($(ARCH), avx512_mic)
	COMMON_FLAGS += -xMIC-AVX512
	#CXXFLAGS += -DUSE_NTS_SPLIT -DUSE_NTS_BN
endif

# Debugging
ifeq ($(DEBUG), 1)
	COMMON_FLAGS += -g -O0
else
	COMMON_FLAGS += -DNDEBUG -O2 -ip -ipo #-qopt-report-phase=vec -qopt-report=2
endif

# configure IO libraries
ifeq ($(USE_OPENCV), 1)
	COMMON_FLAGS += -DUSE_OPENCV
endif

# CPU-only configuration
ifeq ($(CPU_ONLY), 1)
	OBJS := $(PROTO_OBJS) $(CXX_OBJS)
	ALL_WARNS := $(ALL_CXX_WARNS)
	COMMON_FLAGS += -DCPU_ONLY
endif

ifeq ($(OPENMP), 1)
	COMMON_FLAGS += -qopenmp
endif

# BLAS configuration (default = mkl)
ifeq ($(BLAS), openblas)
	# OpenBLAS
	LIBRARIES += openblas

	BLAS_INCLUDE = $(OPENBLAS)/include
	BLAS_LIB = $(OPENBLAS)/lib
	INCLUDE_DIRS += $(BLAS_INCLUDE)
	LIBRARY_DIRS += $(BLAS_LIB)
endif
ifeq ($(BLAS), mkl)
	COMMON_FLAGS += -mkl
endif

INCLUDE_DIRS += $(GXM_LIBRARY_PATH)/include
LIBRARY_DIRS += $(GXM_LIBRARY_PATH)/lib

LIBRARY_DIRS += $(LIB_BUILD_DIR)

# libxsmm paths
LIBRARIES += xsmm xsmmext
INCLUDE_DIRS += $(LIBXSMM_PATH)/include
LIBRARY_DIRS += $(LIBXSMM_PATH)/lib

#MLSL paths
ifeq ($(MLSL), 1)
  LIBRARIES += mlsl
  INCLUDE_DIRS += $(MLSL_ROOT)/intel64/include
  LIBRARY_DIRS += $(MLSL_ROOT)/intel64/lib
  CXXFLAGS += -DUSE_MLSL
  CXX = mpiicpc
endif

ifeq ($(MLSL_WITH_BF16), 1)
  CXXFLAGS += -DBF16_MLSL
endif

ifeq ($(LMDB), 1)
  LIBRARIES += lmdb
  LIBRARY_DIRS += $(GXM_LIBRARY_PATH)/lib
  INCLUDE_DIRS += $(GXM_LIBRARY_PATH)/include
  CXXFLAGS += -DUSE_LMDB
endif

# Optimized Buffer allocation for BP
ifeq ($(BPOPT_ALLOC), 1)
  CXXFLAGS += -DUSE_OPTBP_ALLOC
endif

ifeq ($(NUMA_ON), 1)
  CXXFLAGS += -DUSE_NUMA
endif

ifeq ($(XSMM_TIMING), 1)
  CXXFLAGS += -DUSE_XSMM_TIMING
endif

# Return all
ifeq ($(RETURN_NC), 1)
	CXXFLAGS += -DRETURNALL
endif

# Timing per layer
ifeq ($(TIME), 1)
	CXXFLAGS += -DTIMING
endif

# Stats for layer activations/weights
ifeq ($(STATS), 1)
  	CXXFLAGS += -DGETSTATS
endif

ifeq ($(DUMP_ACT), 1)
  	CXXFLAGS += -DDUMP_ACT_DATA
endif

ifeq ($(DUMP_WT), 1)
  	CXXFLAGS += -DDUMP_WT_DATA
endif

ifeq ($(CANCHECK), 1)
  	CXXFLAGS += -DCANARY_CHECK
endif

ifeq ($(FP32_BU), 1)
  	CXXFLAGS += -DCHECK_BLOWUP_FP32
endif

# Complete build flags.
COMMON_FLAGS += $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir))
CXXFLAGS += $(COMMON_FLAGS) $(WARNINGS) -std=c++11
LINKFLAGS += $(COMMON_FLAGS) $(WARNINGS)

LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) \
		$(foreach library,$(LIBRARIES),-l$(library))

# build targets
all: bin

bin: $(FULL_BIN_NAME)

$(BUILD_DIR_LINK): $(BUILD_DIR)/.linked

$(BUILD_DIR)/.linked:
	@ mkdir -p $(BUILD_DIR)
	@ $(RM) $(OTHER_BUILD_DIR)/.linked
	@ $(RM) -r $(BUILD_DIR_LINK)
	@ ln -s $(BUILD_DIR) $(BUILD_DIR_LINK)
	@ touch $@

$(ALL_BUILD_DIRS): | $(BUILD_DIR_LINK)
	@ mkdir -p $@

$(FULL_BIN_NAME): $(OBJS)
		$(CXX) -o $@ $(OBJS) $(LINKFLAGS) $(LDFLAGS)

$(BUILD_DIR)/%.o: %.cpp | $(ALL_BUILD_DIRS)
	@ echo CXX $<
	$(CXX) $< $(CXXFLAGS) -c -o $@ 2> $@.$(WARNS_EXT) \
		|| (cat $@.$(WARNS_EXT); exit 1)
	@ cat $@.$(WARNS_EXT)

$(PROTO_BUILD_DIR)/%.pb.o: $(PROTO_BUILD_DIR)/%.pb.cc $(PROTO_GEN_HEADER) \
		| $(PROTO_BUILD_DIR)
	@ echo CXX $<
	$(CXX) $< $(CXXFLAGS) -c -o $@ 2> $@.$(WARNS_EXT) \
		|| (cat $@.$(WARNS_EXT); exit 1)
	@ cat $@.$(WARNS_EXT)

proto: $(PROTO_GEN_CC) $(PROTO_GEN_HEADER)

$(PROTO_BUILD_DIR)/%.pb.cc $(PROTO_BUILD_DIR)/%.pb.h : \
		$(PROTO_SRC_DIR)/%.proto | $(PROTO_BUILD_DIR)
	@ echo PROTOC $<
	protoc --proto_path=$(PROTO_SRC_DIR) --cpp_out=$(PROTO_BUILD_DIR) $<

clean:
	@- $(RM) -rf $(ALL_BUILD_DIRS)
	@- $(RM) -rf $(OTHER_BUILD_DIR)
	@- $(RM) -rf $(BUILD_DIR_LINK)

-include $(DEPS)