1 #!/bin/bash
2 #
3 # BLIS
4 # An object-based framework for developing high-performance BLAS-like
5 # libraries.
6 #
7 # Copyright (C) 2014, The University of Texas at Austin
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions are
11 # met:
12 # - Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # - Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in the
16 # documentation and/or other materials provided with the distribution.
17 # - Neither the name of The University of Texas at Austin nor the names
18 # of its contributors may be used to endorse or promote products
19 # derived from this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #
33 #
35 #
36 # Makefile
37 #
38 # Field G. Van Zee
39 #
40 # Makefile for standalone BLIS test drivers.
41 #
43 #
44 # --- Makefile PHONY target definitions ----------------------------------------
45 #
47 .PHONY: all bin clean \
48 check-env check-env-mk check-env-fragments check-env-make-defs \
49 run run-amd64 run-x86 run-arm
53 #
54 # --- Makefile initialization --------------------------------------------------
55 #
57 # Define the name of the configuration file.
58 CONFIG_MK_FILE := config.mk
60 # Define the name of the file containing build and architecture-specific
61 # makefile definitions.
62 MAKE_DEFS_FILE := make_defs.mk
64 # All makefile fragments in the tree will have this name.
65 FRAGMENT_MK := .fragment.mk
67 # Locations of important files.
68 CONFIG_DIR := config
69 FRAME_DIR := frame
70 LIB_DIR := lib
74 #
75 # --- Include makefile configuration file --------------------------------------
76 #
78 # Construct the path to the makefile configuration file that was generated by
79 # the configure script.
80 CONFIG_MK_PATH := ../$(CONFIG_MK_FILE)
82 # Include the configuration file.
83 -include $(CONFIG_MK_PATH)
85 # Detect whether we actually got the configuration file. If we didn't, then
86 # it is likely that the user has not yet generated it (via configure).
87 ifeq ($(strip $(CONFIG_MK_INCLUDED)),yes)
88 CONFIG_MK_PRESENT := yes
89 else
90 CONFIG_MK_PRESENT := no
91 endif
93 # Override the DIST_PATH value obtained from config.mk, since it is relative
94 # to the build directory.
95 DIST_PATH := ..
97 # Now we have access to CONFIG_NAME, which tells us which sub-directory of the
98 # config directory to use as our configuration.
99 CONFIG_PATH := $(DIST_PATH)/$(CONFIG_DIR)/$(CONFIG_NAME)
100 FRAME_PATH := $(DIST_PATH)/$(FRAME_DIR)
104 #
105 # --- Include makefile definitions file ----------------------------------------
106 #
108 # Construct the path to the makefile definitions file residing inside of
109 # the configuration sub-directory.
110 MAKE_DEFS_MK_PATH := $(CONFIG_PATH)/$(MAKE_DEFS_FILE)
112 # Include the makefile definitions file.
113 -include $(MAKE_DEFS_MK_PATH)
115 # Detect whether we actually got the make definitios file. If we didn't, then
116 # it is likely that the configuration is invalid (or incomplete).
117 ifeq ($(strip $(MAKE_DEFS_MK_INCLUDED)),yes)
118 MAKE_DEFS_MK_PRESENT := yes
119 else
120 MAKE_DEFS_MK_PRESENT := no
121 endif
125 #
126 # --- Include makefile fragments -----------------------------------------------
127 #
129 # Initialize our list of directory paths to makefile fragments with the empty
130 # list. This variable will accumulate all of the directory paths in which
131 # makefile fragments reside.
132 FRAGMENT_DIR_PATHS :=
134 # This variable is used by the include statements as they recursively include
135 # one another. For the framework source tree ('frame' directory), we initialize
136 # it to the top-level directory since that is its parent.
137 PARENT_PATH := $(DIST_PATH)
139 # Recursively include all the makefile fragments in the framework itself.
140 -include $(addsuffix /$(FRAGMENT_MK), $(FRAME_PATH))
142 # Now set PARENT_PATH to $(DIST_PATH)/config in preparation to include the
143 # fragments in the configuration sub-directory.
144 PARENT_PATH := $(DIST_PATH)/$(CONFIG_DIR)
146 # Recursively include all the makefile fragments in the configuration
147 # sub-directory.
148 -include $(addsuffix /$(FRAGMENT_MK), $(CONFIG_PATH))
150 # Create a list of the makefile fragments.
151 MAKEFILE_FRAGMENTS := $(addsuffix /$(FRAGMENT_MK), $(FRAGMENT_DIR_PATHS))
153 # Detect whether we actually got any makefile fragments. If we didn't, then it
154 # is likely that the user has not yet generated them (via configure).
155 ifeq ($(strip $(MAKEFILE_FRAGMENTS)),)
156 MAKEFILE_FRAGMENTS_PRESENT := no
157 else
158 MAKEFILE_FRAGMENTS_PRESENT := yes
159 endif
163 #
164 # --- Compiler include path definitions ----------------------------------------
165 #
167 # Expand the fragment paths that contain .h files to attain the set of header
168 # files present in all fragment paths.
169 MK_HEADER_FILES := $(foreach frag_path, $(FRAGMENT_DIR_PATHS), \
170 $(wildcard $(frag_path)/*.h))
172 # Strip the leading, internal, and trailing whitespace from our list of header
173 # files. This makes the "make install-headers" much more readable.
174 MK_HEADER_FILES := $(strip $(MK_HEADER_FILES))
176 # Expand the fragment paths that contain .h files, and take the first
177 # expansion. Then, strip the header filename to leave the path to each header
178 # location. Notice this process even weeds out duplicates! Add the config
179 # directory manually since it contains FLA_config.h.
180 MK_HEADER_DIR_PATHS := $(dir $(foreach frag_path, $(FRAGMENT_DIR_PATHS), \
181 $(firstword $(wildcard $(frag_path)/*.h))))
183 # Add -I to each header path so we can specify our include search paths to the
184 # C compiler.
185 INCLUDE_PATHS := $(strip $(patsubst %, -I%, $(MK_HEADER_DIR_PATHS)))
186 CFLAGS := $(CFLAGS) $(INCLUDE_PATHS)
191 #
192 # --- BLAS and LAPACK implementations ------------------------------------------
193 #
195 # BLIS library and header path. This is simply wherever it was installed.
196 BLIS_LIB_PATH := $(INSTALL_PREFIX)/lib
197 BLIS_INC_PATH := $(INSTALL_PREFIX)/include/blis
198 BLIS_LIB := ../$(BLIS_LIB_PATH)/libblis.a
200 # BLIS library.
201 #BLIS_LIB_PATH := $(DIST_PATH)/$(LIB_DIR)/$(CONFIG_NAME)
204 # BLAS library path(s). This is where the BLAS libraries reside.
205 #BLAS_LIB_PATH := $(HOME)/flame/lib
207 # OpenBLAS, ATLAS, and MKL libraries.
208 #BLAS_LIB := $(LIB_PATH)/libblas.a
209 #BLAS_LIB := $(LIB_PATH)/libgoto.a
210 #BLAS_LIB := $(LIB_PATH)/libgoto2.a
211 #OPENBLAS_LIB := $(BLAS_LIB_PATH)/libopenblas.a
212 #ATLAS_LIB := $(BLAS_LIB_PATH)/libf77blas.a \
213 # $(BLAS_LIB_PATH)/libatlas.a
214 #MKL_LIB := -L/opt/intel/mkl/10.2.2.025/lib/em64t/ \
215 # -lmkl_sequential -lmkl_core -lmkl_intel_lp64
217 #Adding CBLAS Testing
218 ifeq ($(lib),CBLAS)
219 CBLAS_INC_PATH:= ../../cblas/include
220 #CBLAS w/o openCL wrappers
221 CBLAS_LIB_PATH := ../../cblas/lib/ARM
222 ifeq ($(CONFIG_NAME),cortex-a15)
223 CBLAS_LIB:= $(CBLAS_LIB_PATH)/libcblas_ARM.a
224 else
225 CBLAS_LIB:= $(CBLAS_LIB_PATH)/libcblas_LINUX.a
226 endif
227 else ifeq ($(lib),OpenCLCBLAS)
228 #CBLAS w/ openCL Wrappers
229 CBLAS_INC_PATH:= ../../cblas/include
230 BLAS_LIB_DIR = ../../lib
231 CFLAGS+=-fopenmp
232 endif
235 #
236 # --- Optional overrides -------------------------------------------------------
237 #
239 # Uncomment and modify these definitions if you wish to override the values
240 # present in the current BLIS configuration's makefile definitions file
241 # (ie: config/<configname>/make_defs.mk).
242 # CC := gcc
243 # LINKER := $(CC)
244 # CFLAGS := -g -O2 -Wall -Wno-comment
245 # LDFLAGS :=
246 # INSTALL_PREFIX := $(HOME)/blis
250 #
251 # --- General build definitions ------------------------------------------------
252 #
254 TEST_SRC_PATH := src
255 TEST_OBJ_PATH := obj
257 # Gather all local object files.
258 TEST_OBJS := $(patsubst $(TEST_SRC_PATH)/%.c, \
259 $(TEST_OBJ_PATH)/%.o, \
260 $(wildcard $(TEST_SRC_PATH)/*.c))
262 ifeq ($(CONFIG_NAME),pnacl)
263 # Linked executable
264 TEST_BIN := test_libblis.unstable.pexe
265 # Finalized executable
266 TEST_BIN_PNACL := test_libblis.pexe
267 # Translated executable for x86-64
268 TEST_BIN_AMD64 := test_libblis.x86-64.nexe
269 # Translated executable for x86
270 TEST_BIN_X86 := test_libblis.x86.nexe
271 # Translated executable for ARM
272 TEST_BIN_ARM := test_libblis.arm.nexe
273 else
274 # Binary executable name.
275 TEST_BIN := test_libblis_$(CONFIG_NAME).x
276 endif
278 # Add installed and local header paths to CFLAGS
279 CFLAGS += -I$(BLIS_INC_PATH) -I$(TEST_SRC_PATH)
281 ifeq ($(lib),CBLAS)
282 #CBLAS w/o OpenCL wrappers
283 LDFLAGS += -L$(TARGET_ROOTDIR)/lib -L$(TARGET_ROOTDIR)/usr/lib -Wl,-rpath-link,$(TARGET_ROOTDIR)/lib -Wl,-rpath-link,$(TARGET_ROOTDIR)/usr/lib
285 CFLAGS += -I$(CBLAS_INC_PATH)
286 CFLAGS += -DCBLAS
287 temp := $(CBLAS_LIB) $(BLIS_LIB) -lOpenCL -locl_util -lstdc++ -lrt
288 BLIS_LIB := $(temp)
290 else ifeq ($(lib),OpenCLCBLAS)
291 #CBLAS w/ OpenCL wrappers
292 CFLAGS += -I$(CBLAS_INC_PATH)
293 CFLAGS += -DCBLAS
294 CFLAGS += -I$(TARGET_ROOTDIR)/usr/include -idirafter /usr/include
295 BLIS_LIB := $(BLAS_LIB_DIR)/libcblas_armplusdsp.a -lOpenCL -locl_util -lstdc++ -lrt -lpthread
296 LDFLAGS += -L$(TARGET_ROOTDIR)/lib -L$(TARGET_ROOTDIR)/usr/lib -Wl,-rpath-link,$(TARGET_ROOTDIR)/lib -Wl,-rpath-link,$(TARGET_ROOTDIR)/usr/lib
297 endif
301 #
302 # --- Targets/rules ------------------------------------------------------------
303 #
305 # --- Primary targets ---
307 all: check-env bin
309 ifeq ($(CONFIG_NAME),pnacl)
310 bin: check-env $(TEST_BIN) $(TEST_BIN_PNACL) $(TEST_BIN_AMD64) $(TEST_BIN_X86) $(TEST_BIN_ARM)
311 else
312 bin: check-env $(TEST_BIN)
313 endif
316 # --- Environment check rules ---
318 check-env: check-env-make-defs check-env-fragments check-env-mk
320 check-env-mk:
321 ifeq ($(CONFIG_MK_PRESENT),no)
322 $(error Cannot proceed: config.mk not detected! Run configure first)
323 endif
325 check-env-fragments: check-env-mk
326 ifeq ($(MAKEFILE_FRAGMENTS_PRESENT),no)
327 $(error Cannot proceed: makefile fragments not detected! Run configure first)
328 endif
330 check-env-make-defs: check-env-fragments
331 ifeq ($(MAKE_DEFS_MK_PRESENT),no)
332 $(error Cannot proceed: make_defs.mk not detected! Invalid configuration)
333 endif
336 # --Object file rules --
338 #$(TEST_OBJ_PATH)/%.o: $(TEST_SRC_PATH)/%.c $(BLIS_LIB)
339 $(TEST_OBJ_PATH)/%.o: $(TEST_SRC_PATH)/%.c
340 ifeq ($(BLIS_ENABLE_VERBOSE_MAKE_OUTPUT),yes)
341 $(CC) $(CFLAGS) -c $< -o $@
342 else
343 @echo "Compiling $<"
344 @$(CC) $(CFLAGS) -c $< -o $@
345 endif
348 # -- Executable file rules --
350 $(TEST_BIN): $(TEST_OBJS) #$(BLIS_LIB)
351 ifeq ($(BLIS_ENABLE_VERBOSE_MAKE_OUTPUT),yes)
352 $(LINKER) $(TEST_OBJS) $(BLIS_LIB) $(LDFLAGS) -o $@
353 else
354 @echo "Linking $@ against '$(BLIS_LIB) $(LDFLAGS)'"
355 $(LINKER) $(TEST_OBJS) $(BLIS_LIB) $(LDFLAGS) -o $@
356 endif
358 ifeq ($(CONFIG_NAME),pnacl)
360 # Finalize PNaCl executable (i.e. convert from LLVM bitcode to PNaCl bitcode)
361 $(TEST_BIN_PNACL): $(TEST_BIN)
362 ifeq ($(BLIS_ENABLE_VERBOSE_MAKE_OUTPUT),yes)
363 $(FINALIZER) $(FINFLAGS) -o $@ $(TEST_BIN)
364 else
365 @echo "Finalizing $@"
366 @$(FINALIZER) $(FINFLAGS) -o $@ $(TEST_BIN)
367 endif
369 # Translate PNaCl executable to x86-64 NaCl executable
370 $(TEST_BIN_AMD64): $(TEST_BIN_PNACL)
371 ifeq ($(BLIS_ENABLE_VERBOSE_MAKE_OUTPUT),yes)
372 $(TRANSLATOR) $(TRNSFLAGS) $(TRNSAMD64FLAGS) $< -o $@
373 else
374 @echo "Translating $< -> $@"
375 @$(TRANSLATOR) $(TRNSFLAGS) $(TRNSAMD64FLAGS) $< -o $@
376 endif
379 # Translate PNaCl executable to x86 NaCl executable
380 $(TEST_BIN_X86): $(TEST_BIN_PNACL)
381 ifeq ($(BLIS_ENABLE_VERBOSE_MAKE_OUTPUT),yes)
382 $(TRANSLATOR) $(TRNSFLAGS) $(TRNSX86FLAGS) $< -o $@
383 else
384 @echo "Translating $< -> $@"
385 @$(TRANSLATOR) $(TRNSFLAGS) $(TRNSX86FLAGS) $< -o $@
386 endif
388 # Translate PNaCl executable to ARMv7 NaCl executable
389 $(TEST_BIN_ARM): $(TEST_BIN_PNACL)
390 ifeq ($(BLIS_ENABLE_VERBOSE_MAKE_OUTPUT),yes)
391 $(TRANSLATOR) $(TRNSFLAGS) $(TRNSARMFLAGS) $< -o $@
392 else
393 @echo "Translating $< -> $@"
394 @$(TRANSLATOR) $(TRNSFLAGS) $(TRNSARMFLAGS) $< -o $@
395 endif
397 endif
399 # -- Test run rules --
401 ifeq ($(CONFIG_NAME),pnacl)
402 run-amd64: $(TEST_BIN_AMD64)
403 $(NACL_SDK_ROOT)/tools/sel_ldr_x86_64 -a -c -q -B $(NACL_SDK_ROOT)/tools/irt_core_x86_64.nexe -- $(TEST_BIN_AMD64)
404 run-x86: $(TEST_BIN_X86)
405 $(NACL_SDK_ROOT)/tools/sel_ldr_x86_32 -a -c -q -B $(NACL_SDK_ROOT)/tools/irt_core_x86_32.nexe -- $(TEST_BIN_X86)
406 run-arm: $(TEST_BIN_ARM)
407 $(NACL_SDK_ROOT)/tools/sel_ldr_arm -a -c -q -B $(NACL_SDK_ROOT)/tools/irt_core_arm.nexe -- $(TEST_BIN_ARM)
408 else
409 run: $(TEST_BIN)
410 ./$(TEST_BIN)
411 endif
413 # -- Clean rules --
415 ifeq ($(CONFIG_NAME),pnacl)
416 clean:
417 - $(RM_F) $(TEST_OBJS) $(TEST_BIN) $(TEST_BIN_PNACL) $(TEST_BIN_AMD64) $(TEST_BIN_X86) $(TEST_BIN_ARM)
418 else
419 clean:
420 - $(RM_F) $(TEST_OBJS) $(TEST_BIN)
421 endif