xref: /libCEED/Makefile (revision 1571c99d1f6878671bebdd65f042c55ec98b920f)
10c784865Scamierjs# Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
20c784865Scamierjs# Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
30c784865Scamierjs# All Rights reserved. See files LICENSE and NOTICE for details.
40d9661cdSTzanio#
50d9661cdSTzanio# This file is part of CEED, a collection of benchmarks, miniapps, software
60d9661cdSTzanio# libraries and APIs for efficient high-order finite element and spectral
70d9661cdSTzanio# element discretizations for exascale applications. For more information and
80d9661cdSTzanio# source code availability see http://github.com/ceed.
90d9661cdSTzanio#
100d9661cdSTzanio# The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
110d9661cdSTzanio# a collaborative effort of two U.S. Department of Energy organizations (Office
120d9661cdSTzanio# of Science and the National Nuclear Security Administration) responsible for
130d9661cdSTzanio# the planning and preparation of a capable exascale ecosystem, including
140d9661cdSTzanio# software, applications, hardware, advanced system engineering and early
150d9661cdSTzanio# testbed platforms, in support of the nation's exascale computing imperative.
160d9661cdSTzanio
17*1571c99dSValeria Barra-include config.mk
18*1571c99dSValeria Barra
19dc753d40SJed Brownifeq (,$(filter-out undefined default,$(origin CC)))
206ed738d9SJed Brown  CC = gcc
21dc753d40SJed Brownendif
22dc753d40SJed Brownifeq (,$(filter-out undefined default,$(origin FC)))
2381c9eb91SStan Tomov  FC = gfortran
24dc753d40SJed Brownendif
257692a9b0SVeselin DobrevNVCC = $(CUDA_DIR)/bin/nvcc
26e86995feScamierjs
273b56482dScamierjs# ASAN must be left empty if you don't want to use it
280a7eccc5ScamierjsASAN ?=
296850bcb5Scamierjs
30e86995feScamierjsLDFLAGS ?=
3132d74c32SThilina RathnayakeUNDERSCORE ?= 1
321b58aefaScamierjs
33f9fa8c39Sjeremylt# MFEM_DIR env variable should point to sibling directory
34bf3e26f6SVeselin Dobrevifneq ($(wildcard ../mfem/libmfem.*),)
359ba53df8Sjeremylt  MFEM_DIR ?= ../mfem
36f9fa8c39Sjeremyltendif
37f9fa8c39Sjeremylt
384d1cd9fcSJeremy L Thompson# NEK5K_DIR env variable should point to sibling directory
394d1cd9fcSJeremy L Thompsonifneq ($(wildcard ../Nek5000/*),)
404d1cd9fcSJeremy L Thompson  NEK5K_DIR ?= ../Nek5000
414d1cd9fcSJeremy L Thompsonendif
424d1cd9fcSJeremy L Thompson
438d713cf6Sjeremylt# XSMM_DIR env variable should point to XSMM master (github.com/hfp/libxsmm)
448d713cf6SjeremyltXSMM_DIR ?= ../libxsmm
458d713cf6Sjeremylt
4612123fd5Scamierjs# OCCA_DIR env variable should point to OCCA master (github.com/libocca/occa)
477f5ff99bSVeselin DobrevOCCA_DIR ?= ../occa
48f797d7b2Scamierjs
495a9ca9adSVeselin Dobrev# env variable MAGMA_DIR can be used too
505a9ca9adSVeselin DobrevMAGMA_DIR ?= ../magma
515a9ca9adSVeselin Dobrev# If CUDA_DIR is not set, check for nvcc, or resort to /usr/local/cuda
525a9ca9adSVeselin DobrevCUDA_DIR  ?= $(or $(patsubst %/,%,$(dir $(patsubst %/,%,$(dir \
535a9ca9adSVeselin Dobrev               $(shell which nvcc 2> /dev/null))))),/usr/local/cuda)
5482b77998SStan Tomov
552f4d9adbSJeremy L Thompson# Check for PETSc in ../petsc
562f4d9adbSJeremy L Thompsonifneq ($(wildcard ../petsc/lib/libpetsc.*),)
572f4d9adbSJeremy L Thompson  PETSC_DIR ?= ../petsc
582f4d9adbSJeremy L Thompsonendif
592f4d9adbSJeremy L Thompson
60bf000209STzanio# Warning: SANTIZ options still don't run with /gpu/occa
6112123fd5Scamierjs# export LSAN_OPTIONS=suppressions=.asanignore
62c12ddcb5ScamierjsAFLAGS = -fsanitize=address #-fsanitize=undefined -fno-omit-frame-pointer
6332d74c32SThilina Rathnayake
642774d5cbSJeremy L ThompsonOPT    = -O -g -march=native -ffp-contract=fast -fopenmp-simd
65323c739cSJed BrownCFLAGS = -std=c99 $(OPT) -Wall -Wextra -Wno-unused-parameter -fPIC -MMD -MP
669f0427d9SYohannNVCCFLAGS = -Xcompiler "$(OPT)" -Xcompiler -fPIC
671dc2661bSVeselin Dobrev# If using the IBM XL Fortran (xlf) replace FFLAGS appropriately:
681dc2661bSVeselin Dobrevifneq ($(filter %xlf %xlf_r,$(FC)),)
6910da579bSJeremy L Thompson  FFLAGS = $(OPT) -ffree-form -qpreprocess -qextname -qpic -MMD
70323c739cSJed Brownelse # gfortran/Intel-style options
718980d4a7Sjeremylt  FFLAGS = -cpp     $(OPT) -Wall -Wextra -Wno-unused-parameter -Wno-unused-dummy-argument -fPIC -MMD -MP
721dc2661bSVeselin Dobrevendif
731b58aefaScamierjs
7432d74c32SThilina Rathnayakeifeq ($(UNDERSCORE), 1)
7532d74c32SThilina Rathnayake  CFLAGS += -DUNDERSCORE
7632d74c32SThilina Rathnayakeendif
7732d74c32SThilina Rathnayake
78a6f4783aSJed Brownifeq ($(COVERAGE), 1)
79a6f4783aSJed Brown  CFLAGS += --coverage
80a6f4783aSJed Brown  LDFLAGS += --coverage
81a6f4783aSJed Brownendif
82a6f4783aSJed Brown
834dd6f121ScamierjsCFLAGS += $(if $(ASAN),$(AFLAGS))
844dd6f121ScamierjsFFLAGS += $(if $(ASAN),$(AFLAGS))
854dd6f121ScamierjsLDFLAGS += $(if $(ASAN),$(AFLAGS))
866ea7c6c1SJed BrownCPPFLAGS = -I./include
87582447c9SJed BrownLDLIBS = -lm
8891b7489eSJed BrownOBJDIR := build
896ea7c6c1SJed BrownLIBDIR := lib
906ea7c6c1SJed Brown
91d5217624SJed Brown# Installation variables
92d5217624SJed Brownprefix ?= /usr/local
93d5217624SJed Brownbindir = $(prefix)/bin
94d5217624SJed Brownlibdir = $(prefix)/lib
95bf3e26f6SVeselin Dobrevokldir = $(libdir)/okl
96d5217624SJed Brownincludedir = $(prefix)/include
97d5217624SJed Brownpkgconfigdir = $(libdir)/pkgconfig
98d5217624SJed BrownINSTALL = install
99d5217624SJed BrownINSTALL_PROGRAM = $(INSTALL)
100d5217624SJed BrownINSTALL_DATA = $(INSTALL) -m644
101d5217624SJed Brown
1023b56482dScamierjs# Get number of processors of the machine
10369762e1fScamierjsNPROCS := $(shell getconf _NPROCESSORS_ONLN)
1043b56482dScamierjs# prepare make options to run in parallel
10582985883ScamierjsMFLAGS := -j $(NPROCS) --warn-undefined-variables \
10621ae6867Scamierjs                       --no-print-directory --no-keep-going
10787e762eaSJed Brown
1088ec9d54bSJed BrownPYTHON ?= python3
109bfa078e6SJed BrownPROVE ?= prove
1103a1ec3cdSJed BrownPROVE_OPTS ?= -j $(NPROCS)
1115c719ab0SJed BrownDARWIN := $(filter Darwin,$(shell uname -s))
1125c719ab0SJed BrownSO_EXT := $(if $(DARWIN),dylib,so)
1139df38c42SVeselin Dobrev
1146ea7c6c1SJed Brownceed.pc := $(LIBDIR)/pkgconfig/ceed.pc
11591b7489eSJed Brownlibceed := $(LIBDIR)/libceed.$(SO_EXT)
1167e68d260SJed BrownCEED_LIBS = -lceed
117d7b241e6Sjeremyltlibceed.c := $(wildcard interface/ceed*.c)
118265be9c8Sjeremyltlibceed_test := $(LIBDIR)/libceed_test.$(SO_EXT)
11976af460cSJed Brownlibceeds = $(libceed) $(libceed_test)
120265be9c8SjeremyltBACKENDS_BUILTIN := /cpu/self/ref/serial /cpu/self/ref/blocked /cpu/self/opt/serial /cpu/self/opt/blocked
121d20f937dSJed BrownBACKENDS := $(BACKENDS_BUILTIN)
122bf000209STzanio
123bf000209STzanio# Tests
12457c64913Sjeremylttests.c   := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.c))
1258980d4a7Sjeremylttests.f   := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.f90))
12691b7489eSJed Browntests     := $(tests.c:tests/%.c=$(OBJDIR)/%)
1273f3e7340Scamierjsctests    := $(tests)
1288980d4a7Sjeremylttests     += $(tests.f:tests/%.f90=$(OBJDIR)/%)
12932d74c32SThilina Rathnayake#examples
130182fbe45STzanioexamples.c := $(sort $(wildcard examples/ceed/*.c))
131182fbe45STzanioexamples.f := $(sort $(wildcard examples/ceed/*.f))
132182fbe45STzanioexamples  := $(examples.c:examples/ceed/%.c=$(OBJDIR)/%)
133182fbe45STzanioexamples  += $(examples.f:examples/ceed/%.f=$(OBJDIR)/%)
1342158b1b0Sjeremylt#mfemexamples
1352158b1b0Sjeremyltmfemexamples.cpp := $(sort $(wildcard examples/mfem/*.cpp))
13616c6c054SJed Brownmfemexamples  := $(mfemexamples.cpp:examples/mfem/%.cpp=$(OBJDIR)/mfem-%)
1374d1cd9fcSJeremy L Thompson#nekexamples
1384d1cd9fcSJeremy L Thompsonnekexamples.usr := $(sort $(wildcard examples/nek5000/*.usr))
139686de4acSJed Brownnekexamples  := $(nekexamples.usr:examples/nek5000/%.usr=$(OBJDIR)/nek-%)
1404d1cd9fcSJeremy L Thompson#petscexamples
141e797ab98SJed Brownpetscexamples.c := $(sort $(wildcard examples/petsc/*.c))
142e797ab98SJed Brownpetscexamples  := $(petscexamples.c:examples/petsc/%.c=$(OBJDIR)/petsc-%)
1432774d5cbSJeremy L Thompson#navierstokesexample
1442774d5cbSJeremy L Thompsonnavierstokesexample.c := $(sort $(wildcard examples/navier-stokes/*.c))
1452774d5cbSJeremy L Thompsonnavierstokesexample  := $(navierstokesexample.c:examples/navier-stokes/%.c=$(OBJDIR)/navier-stokes-%)
146e797ab98SJed Brown
14789c6efa4Sjeremylt# backends/[ref, blocked, template, memcheck, opt, avx, occa, magma]
148ae3cba82Scamierjsref.c          := $(sort $(wildcard backends/ref/*.c))
14989c6efa4Sjeremyltblocked.c      := $(sort $(wildcard backends/blocked/*.c))
150a718229cSjeremylttemplate.c     := $(sort $(wildcard backends/template/*.c))
15189c6efa4Sjeremyltceedmemcheck.c := $(sort $(wildcard backends/memcheck/*.c))
15289c6efa4Sjeremyltopt.c          := $(sort $(wildcard backends/opt/*.c))
15389c6efa4Sjeremyltavx.c          := $(sort $(wildcard backends/avx/*.c))
15489c6efa4Sjeremyltxsmm.c         := $(sort $(wildcard backends/xsmm/*.c))
1559f0427d9SYohanncuda.c         := $(sort $(wildcard backends/cuda/*.c))
1569f0427d9SYohanncuda.cu        := $(sort $(wildcard backends/cuda/*.cu))
15755ae60f9SYohanncuda-reg.c     := $(sort $(wildcard backends/cuda-reg/*.c))
15855ae60f9SYohanncuda-reg.cu    := $(sort $(wildcard backends/cuda-reg/*.cu))
159c532df63SYohanncuda-shared.c  := $(sort $(wildcard backends/cuda-shared/*.c))
160c532df63SYohanncuda-shared.cu := $(sort $(wildcard backends/cuda-shared/*.cu))
161ae3cba82Scamierjsocca.c         := $(sort $(wildcard backends/occa/*.c))
162755585ceSStan Tomovmagma_preprocessor := python backends/magma/gccm.py
163c4acb06bSStan Tomovmagma_pre_src  := $(filter-out %_tmp.c, $(wildcard backends/magma/ceed-*.c))
164c4acb06bSStan Tomovmagma_dsrc     := $(wildcard backends/magma/magma_d*.c)
165c4acb06bSStan Tomovmagma_tmp.c    := $(magma_pre_src:%.c=%_tmp.c)
166c4acb06bSStan Tomovmagma_tmp.cu   := $(magma_pre_src:%.c=%_cuda.cu)
167c4acb06bSStan Tomovmagma_allsrc.c := $(magma_dsrc) $(magma_tmp.c)
168c4acb06bSStan Tomovmagma_allsrc.cu:= $(magma_tmp.cu)
16982985883Scamierjs
1709bdc3d68Scamierjs# Output using the 216-color rules mode
17118a724fcScamierjsrule_file = $(notdir $(1))
17218a724fcScamierjsrule_path = $(patsubst %/,%,$(dir $(1)))
17318a724fcScamierjslast_path = $(notdir $(patsubst %/,%,$(dir $(1))))
1743c5d0cdfSJed Brownansicolor = $(shell echo $(call last_path,$(1)) | cksum | cut -b1-2 | xargs -IS expr 2 \* S + 17)
175abb87f81Scamierjsemacs_out = @printf "  %10s %s/%s\n" $(1) $(call rule_path,$(2)) $(call rule_file,$(2))
176abb87f81Scamierjscolor_out = @if [ -t 1 ]; then \
17718a724fcScamierjs				printf "  %10s \033[38;5;%d;1m%s\033[m/%s\n" \
1783c5d0cdfSJed Brown					$(1) $(call ansicolor,$(2)) \
17918a724fcScamierjs					$(call rule_path,$(2)) $(call rule_file,$(2)); else \
18018a724fcScamierjs				printf "  %10s %s\n" $(1) $(2); fi
181f797d7b2Scamierjs# if TERM=dumb, use it, otherwise switch to the term one
182abb87f81Scamierjsoutput = $(if $(TERM:dumb=),$(call color_out,$1,$2),$(call emacs_out,$1,$2))
18382985883Scamierjs
1849bdc3d68Scamierjs# if V is set to non-nil, turn the verbose mode
18518a724fcScamierjsquiet = $(if $(V),$($(1)),$(call output,$1,$@);$($(1)))
18621ae6867Scamierjs
187da72e7fcSJed Brown# Cancel built-in and old-fashioned implicit rules which we don't use
1889df38c42SVeselin Dobrev.SUFFIXES:
189da72e7fcSJed Brown
19091b7489eSJed Brown.SECONDEXPANSION: # to expand $$(@D)/.DIR
1919df38c42SVeselin Dobrev
192c4acb06bSStan Tomov.SECONDARY: $(magma_tmp.c) $(magma_tmp.cu)
19314c1ded1SStan Tomov
19491b7489eSJed Brown%/.DIR :
19591b7489eSJed Brown	@mkdir -p $(@D)
19691b7489eSJed Brown	@touch $@
19791b7489eSJed Brown
19891b7489eSJed Brown.PRECIOUS: %/.DIR
19991b7489eSJed Brown
20023072ed2SVeselin Dobrevlib: $(libceed) $(ceed.pc)
20123072ed2SVeselin Dobrev# run 'lib' target in parallel
2022f4d9adbSJeremy L Thompsonpar:;@$(MAKE) $(MFLAGS) V=$(V) lib
203d20f937dSJed Brownbackend_status = $(if $(filter $1,$(BACKENDS)), [backends: $1], [not found])
204bf3e26f6SVeselin Dobrevinfo:
205bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
206bf3e26f6SVeselin Dobrev	$(info CC            = $(CC))
207bf3e26f6SVeselin Dobrev	$(info FC            = $(FC))
208bf3e26f6SVeselin Dobrev	$(info CPPFLAGS      = $(CPPFLAGS))
209bf3e26f6SVeselin Dobrev	$(info CFLAGS        = $(value CFLAGS))
210bf3e26f6SVeselin Dobrev	$(info FFLAGS        = $(value FFLAGS))
211bf3e26f6SVeselin Dobrev	$(info NVCCFLAGS     = $(value NVCCFLAGS))
212bf3e26f6SVeselin Dobrev	$(info LDFLAGS       = $(value LDFLAGS))
213bf3e26f6SVeselin Dobrev	$(info LDLIBS        = $(LDLIBS))
214bf3e26f6SVeselin Dobrev	$(info OPT           = $(OPT))
215bf3e26f6SVeselin Dobrev	$(info AFLAGS        = $(AFLAGS))
216bf3e26f6SVeselin Dobrev	$(info ASAN          = $(or $(ASAN),(empty)))
217bf3e26f6SVeselin Dobrev	$(info V             = $(or $(V),(empty)) [verbose=$(if $(V),on,off)])
218bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
219bdc3149dSjeremylt	$(info MEMCHK_STATUS = $(MEMCHK_STATUS)$(call backend_status,/cpu/self/ref/memcheck))
22084a01de5SJeremy L Thompson	$(info AVX_STATUS    = $(AVX_STATUS)$(call backend_status,/cpu/self/avx/serial /cpu/self/avx/blocked))
22184a01de5SJeremy L Thompson	$(info XSMM_DIR      = $(XSMM_DIR)$(call backend_status,/cpu/self/xsmm/serial /cpu/self/xsmm/blocked))
222d20f937dSJed Brown	$(info OCCA_DIR      = $(OCCA_DIR)$(call backend_status,/cpu/occa /gpu/occa /omp/occa))
223d20f937dSJed Brown	$(info MAGMA_DIR     = $(MAGMA_DIR)$(call backend_status,/gpu/magma))
224ab9cabdeSVeselin Dobrev	$(info CUDA_DIR      = $(CUDA_DIR)$(call backend_status,$(CUDA_BACKENDS)))
225bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
226bf3e26f6SVeselin Dobrev	$(info MFEM_DIR      = $(MFEM_DIR))
2274d1cd9fcSJeremy L Thompson	$(info NEK5K_DIR     = $(NEK5K_DIR))
228bf3e26f6SVeselin Dobrev	$(info PETSC_DIR     = $(PETSC_DIR))
229bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
230bf3e26f6SVeselin Dobrev	$(info prefix        = $(prefix))
231bf3e26f6SVeselin Dobrev	$(info includedir    = $(value includedir))
232bf3e26f6SVeselin Dobrev	$(info libdir        = $(value libdir))
233bf3e26f6SVeselin Dobrev	$(info okldir        = $(value okldir))
234bf3e26f6SVeselin Dobrev	$(info pkgconfigdir  = $(value pkgconfigdir))
235bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
236bf3e26f6SVeselin Dobrev	@true
23723072ed2SVeselin Dobrevinfo-backends:
238d20f937dSJed Brown	$(info make: 'lib' with optional backends: $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS)))
2392f4d9adbSJeremy L Thompson.PHONY: lib all par info info-backends
2400e439e50SJed Brown
24124d002f4SJed Brown$(libceed) : LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed)))
24276af460cSJed Brown$(libceed_test) : LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed_test)))
24369762e1fScamierjs
24448fffa06Sjeremylt# Standard Backends
24587174f08SJed Brownlibceed.c += $(ref.c)
2464a2e7687Sjeremyltlibceed.c += $(blocked.c)
24789c6efa4Sjeremyltlibceed.c += $(opt.c)
24823072ed2SVeselin Dobrev
249265be9c8Sjeremylt# Testing Backends
250265be9c8Sjeremylttest_backends.c := $(template.c)
251265be9c8SjeremyltTEST_BACKENDS := /cpu/self/tmpl /cpu/self/tmpl/sub
252265be9c8Sjeremylt
253fc7cf9a0Sjeremylt# Memcheck Backend
254bdc3149dSjeremyltMEMCHK_STATUS = Disabled
255b8fb44e7SJed BrownMEMCHK := $(shell echo "\#include <valgrind/memcheck.h>" | $(CC) $(CPPFLAGS) -E - >/dev/null 2>&1 && echo 1)
256bdc3149dSjeremyltifeq ($(MEMCHK),1)
257bdc3149dSjeremylt  MEMCHK_STATUS = Enabled
258fc7cf9a0Sjeremylt  libceed.c += $(ceedmemcheck.c)
259fc7cf9a0Sjeremylt  BACKENDS += /cpu/self/ref/memcheck
260fc7cf9a0Sjeremyltendif
261fc7cf9a0Sjeremylt
26248fffa06Sjeremylt# AVX Backed
26348fffa06SjeremyltAVX_STATUS = Disabled
2645efe2378SjeremyltAVX := $(shell $(CC) $(OPT) -v -E - < /dev/null 2>&1 | grep -c avx)
26548fffa06Sjeremyltifeq ($(AVX),1)
26648fffa06Sjeremylt  AVX_STATUS = Enabled
26748fffa06Sjeremylt  libceed.c += $(avx.c)
26884a01de5SJeremy L Thompson  BACKENDS += /cpu/self/avx/serial /cpu/self/avx/blocked
26948fffa06Sjeremyltendif
27048fffa06Sjeremylt
2718d713cf6Sjeremylt# libXSMM Backends
2728d713cf6Sjeremyltifneq ($(wildcard $(XSMM_DIR)/lib/libxsmm.*),)
27376af460cSJed Brown  $(libceeds) : LDFLAGS += -L$(XSMM_DIR)/lib -Wl,-rpath,$(abspath $(XSMM_DIR)/lib)
27476af460cSJed Brown  $(libceeds) : LDLIBS += -lxsmm -ldl
275724a7164Sjeremylt  MKL ?= 0
276724a7164Sjeremylt  ifneq (0,$(MKL))
27776af460cSJed Brown    $(libceeds) : LDLIBS += -mkl
278724a7164Sjeremylt  else
27976af460cSJed Brown    $(libceeds) : LDLIBS += -lblas
280724a7164Sjeremylt  endif
2818d713cf6Sjeremylt  libceed.c += $(xsmm.c)
282683faae0SJed Brown  $(xsmm.c:%.c=$(OBJDIR)/%.o) $(xsmm.c:%=%.tidy) : CPPFLAGS += -I$(XSMM_DIR)/include
2838d713cf6Sjeremylt  BACKENDS += /cpu/self/xsmm/serial /cpu/self/xsmm/blocked
2848d713cf6Sjeremyltendif
2858d713cf6Sjeremylt
28648fffa06Sjeremylt# OCCA Backends
2877f5ff99bSVeselin Dobrevifneq ($(wildcard $(OCCA_DIR)/lib/libocca.*),)
28876af460cSJed Brown  $(libceeds) : LDFLAGS += -L$(OCCA_DIR)/lib -Wl,-rpath,$(abspath $(OCCA_DIR)/lib)
28976af460cSJed Brown  $(libceeds) : LDLIBS += -locca
29087174f08SJed Brown  libceed.c += $(occa.c)
291683faae0SJed Brown  $(occa.c:%.c=$(OBJDIR)/%.o) $(occa.c:%=%.tidy) : CPPFLAGS += -I$(OCCA_DIR)/include
292a953af89SJed Brown  BACKENDS += /cpu/occa /gpu/occa /omp/occa
29321ae6867Scamierjsendif
29423072ed2SVeselin Dobrev
2959f0427d9SYohann# Cuda Backend
2965a9ca9adSVeselin DobrevCUDA_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(CUDA_DIR)/$d/libcudart.${SO_EXT}))
2975a9ca9adSVeselin DobrevCUDA_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(CUDA_LIB_DIR))))
298c532df63SYohannCUDA_BACKENDS = /gpu/cuda/ref /gpu/cuda/reg /gpu/cuda/shared
2995a9ca9adSVeselin Dobrevifneq ($(CUDA_LIB_DIR),)
30076af460cSJed Brown  $(libceeds) : CFLAGS += -I$(CUDA_DIR)/include
30176af460cSJed Brown  $(libceeds) : LDFLAGS += -L$(CUDA_LIB_DIR) -Wl,-rpath,$(abspath $(CUDA_LIB_DIR))
30276af460cSJed Brown  $(libceeds) : LDLIBS += -lcudart -lnvrtc -lcuda
303c532df63SYohann  libceed.c  += $(cuda.c) $(cuda-reg.c) $(cuda-shared.c)
304c532df63SYohann  libceed.cu += $(cuda.cu) $(cuda-reg.cu) $(cuda-shared.cu)
305ab9cabdeSVeselin Dobrev  BACKENDS += $(CUDA_BACKENDS)
3069f0427d9SYohannendif
3079f0427d9SYohann
3089f0427d9SYohann# MAGMA Backend
3099f0427d9SYohannifneq ($(wildcard $(MAGMA_DIR)/lib/libmagma.*),)
3109f0427d9SYohann  ifneq ($(CUDA_LIB_DIR),)
3111dc2661bSVeselin Dobrev  cuda_link = -Wl,-rpath,$(CUDA_LIB_DIR) -L$(CUDA_LIB_DIR) -lcublas -lcusparse -lcudart
3121dc2661bSVeselin Dobrev  omp_link = -fopenmp
3131dc2661bSVeselin Dobrev  magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(cuda_link) $(omp_link)
3147692a9b0SVeselin Dobrev  magma_link_shared = -L$(MAGMA_DIR)/lib -Wl,-rpath,$(abspath $(MAGMA_DIR)/lib) -lmagma
3157692a9b0SVeselin Dobrev  magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static))
31676af460cSJed Brown  $(libceeds)           : LDLIBS += $(magma_link)
3177692a9b0SVeselin Dobrev  $(tests) $(examples) : LDLIBS += $(magma_link)
318c4acb06bSStan Tomov  libceed.c  += $(magma_allsrc.c)
319c4acb06bSStan Tomov  libceed.cu += $(magma_allsrc.cu)
320683faae0SJed Brown  $(magma_allsrc.c:%.c=$(OBJDIR)/%.o) $(magma_allsrc.c:%=%.tidy) : CPPFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include
321c4acb06bSStan Tomov  $(magma_allsrc.cu:%.cu=$(OBJDIR)/%.o) : NVCCFLAGS += --compiler-options=-fPIC -DADD_ -I$(MAGMA_DIR)/include -I$(MAGMA_DIR)/magmablas -I$(MAGMA_DIR)/control -I$(CUDA_DIR)/include
322ce41f623SJed Brown  BACKENDS += /gpu/magma
32382b77998SStan Tomov  endif
3245a9ca9adSVeselin Dobrevendif
325755585ceSStan Tomov
326ce41f623SJed Brownexport BACKENDS
327ce41f623SJed Brown
328755585ceSStan Tomov# generate magma_tmp.c and magma_cuda.cu from magma.c
32929715310SJed Brown%_tmp.c %_cuda.cu : %.c
330755585ceSStan Tomov	$(magma_preprocessor) $<
331755585ceSStan Tomov
33223072ed2SVeselin Dobrevlibceed.o = $(libceed.c:%.c=$(OBJDIR)/%.o) $(libceed.cu:%.cu=$(OBJDIR)/%.o)
33323072ed2SVeselin Dobrev$(libceed.o): | info-backends
33423072ed2SVeselin Dobrev$(libceed) : $(libceed.o) | $$(@D)/.DIR
33521ae6867Scamierjs	$(call quiet,CC) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
33691b7489eSJed Brown
33758e8d3b7SJed Brown$(OBJDIR)/%.o : $(CURDIR)/%.c | $$(@D)/.DIR
338b5b03409SJed Brown	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<)
339ae3cba82Scamierjs
34058e8d3b7SJed Brown$(OBJDIR)/%.o : $(CURDIR)/%.cu | $$(@D)/.DIR
341755585ceSStan Tomov	$(call quiet,NVCC) $(CPPFLAGS) $(NVCCFLAGS) -c -o $@ $(abspath $<)
342755585ceSStan Tomov
343b5b03409SJed Brown$(OBJDIR)/% : tests/%.c | $$(@D)/.DIR
344265be9c8Sjeremylt	$(call quiet,LINK.c) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
34578b5556aScamierjs
3468980d4a7Sjeremylt$(OBJDIR)/% : tests/%.f90 | $$(@D)/.DIR
347265be9c8Sjeremylt	$(call quiet,LINK.F) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
34832d74c32SThilina Rathnayake
349182fbe45STzanio$(OBJDIR)/% : examples/ceed/%.c | $$(@D)/.DIR
350265be9c8Sjeremylt	$(call quiet,LINK.c) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
35191b7489eSJed Brown
352182fbe45STzanio$(OBJDIR)/% : examples/ceed/%.f | $$(@D)/.DIR
353265be9c8Sjeremylt	$(call quiet,LINK.F) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
354673d494eSThilina Rathnayake
35516c6c054SJed Brown$(OBJDIR)/mfem-% : examples/mfem/%.cpp $(libceed) | $$(@D)/.DIR
356c4216f28SJed Brown	+$(MAKE) -C examples/mfem CEED_DIR=`pwd` \
3572f4d9adbSJeremy L Thompson	  MFEM_DIR="$(abspath $(MFEM_DIR))" $*
35816c6c054SJed Brown	mv examples/mfem/$* $@
35916c6c054SJed Brown
3607f6cf205SJed Brown$(OBJDIR)/petsc-% : examples/petsc/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR
361c4216f28SJed Brown	+$(MAKE) -C examples/petsc CEED_DIR=`pwd` \
3622f4d9adbSJeremy L Thompson	  PETSC_DIR="$(abspath $(PETSC_DIR))" $*
363e797ab98SJed Brown	mv examples/petsc/$* $@
364e797ab98SJed Brown
3652774d5cbSJeremy L Thompson$(OBJDIR)/navier-stokes-% : examples/navier-stokes/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR
366c4216f28SJed Brown	+$(MAKE) -C examples/navier-stokes CEED_DIR=`pwd` \
3672774d5cbSJeremy L Thompson	  PETSC_DIR="$(abspath $(PETSC_DIR))" $*
3682774d5cbSJeremy L Thompson	mv examples/navier-stokes/$* $@
3692774d5cbSJeremy L Thompson
370567e4d0aSJed Brownlibceed_test.o = $(test_backends.c:%.c=$(OBJDIR)/%.o)
37176af460cSJed Brown$(libceed_test) : $(libceed.o) $(libceed_test.o) | $$(@D)/.DIR
372265be9c8Sjeremylt	$(call quiet,CC) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
373265be9c8Sjeremylt
374265be9c8Sjeremylt$(examples) : $(libceed)
37576af460cSJed Brown$(tests) : $(libceed_test)
37676af460cSJed Brown$(tests) : CEED_LIBS = -lceed_test
377fc377ca6SJed Brown$(tests) $(examples) : LDFLAGS += -Wl,-rpath,$(abspath $(LIBDIR)) -L$(LIBDIR)
3784859b599SJed Brown
379686de4acSJed Brownrun-t% : BACKENDS += $(TEST_BACKENDS)
380dad465e7SJed Brownrun-% : $(OBJDIR)/%
381d1f7f8d3SJed Brown	@tests/tap.sh $(<:$(OBJDIR)/%=%)
382686de4acSJed Brown
383686de4acSJed Brownexternal_examples := \
384686de4acSJed Brown	$(if $(MFEM_DIR),$(mfemexamples)) \
385686de4acSJed Brown	$(if $(PETSC_DIR),$(petscexamples)) \
386686de4acSJed Brown	$(if $(NEK5K_DIR),$(nekexamples))
387686de4acSJed Brown
388686de4acSJed Brownallexamples = $(examples) $(external_examples)
389686de4acSJed Brown
390686de4acSJed Brown# The test and prove targets can be controlled via pattern searches.  The
391686de4acSJed Brown# default is to run tests and those examples that have no external dependencies.
392686de4acSJed Brown# Examples of finer grained control:
393686de4acSJed Brown#
394686de4acSJed Brown#   make test search='petsc mfem'      # PETSc and MFEM examples
395686de4acSJed Brown#   make prove search='t3'             # t3xx series tests
396686de4acSJed Brown#   make junit search='ex petsc'       # core ex* and PETSc tests
397686de4acSJed Brownsearch ?= t ex
398686de4acSJed Brownrealsearch = $(search:%=%%)
399686de4acSJed Brownmatched = $(foreach pattern,$(realsearch),$(filter $(OBJDIR)/$(pattern),$(tests) $(allexamples)))
400686de4acSJed Brown# Work around Nek examples not having normal targets
401686de4acSJed Brownmatched_prereq = $(filter-out $(OBJDIR)/nek%,$(matched)) $(if $(findstring nek,$(matched)),prepnektests)
402686de4acSJed Brown
4032158b1b0Sjeremylt# Test core libCEED
404686de4acSJed Browntest : $(matched:$(OBJDIR)/%=run-%)
4052158b1b0Sjeremylt
4063b56482dScamierjs# run test target in parallel
4076850bcb5Scamierjstst : ;@$(MAKE) $(MFLAGS) V=$(V) test
4083b56482dScamierjs# CPU C tests only for backend %
4093f3e7340Scamierjsctc-% : $(ctests);@$(foreach tst,$(ctests),$(tst) /cpu/$*;)
4104859b599SJed Brown
411686de4acSJed Brownprove : BACKENDS += $(TEST_BACKENDS)
412686de4acSJed Brownprove : $(matched_prereq)
413a5dc8077SJed Brown	$(info Testing backends: $(BACKENDS))
414686de4acSJed Brown	$(PROVE) $(PROVE_OPTS) --exec 'tests/tap.sh' $(matched:$(OBJDIR)/%=%)
4153b56482dScamierjs# run prove target in parallel
4166850bcb5Scamierjsprv : ;@$(MAKE) $(MFLAGS) V=$(V) prove
417bfa078e6SJed Brown
4184d1cd9fcSJeremy L Thompsonprepnektests:
4194d1cd9fcSJeremy L Thompson	(export CC FC && cd examples && make prepnektests)
4202158b1b0Sjeremylt
421686de4acSJed Brownprove-all :
422686de4acSJed Brown	+$(MAKE) prove realsearch=%
423686de4acSJed Brown
424686de4acSJed Brownjunit-t% : BACKENDS += $(TEST_BACKENDS)
4258ec9d54bSJed Brownjunit-% : $(OBJDIR)/%
426bdb0bdbbSJed Brown	@printf "  %10s %s\n" TEST $(<:$(OBJDIR)/%=%); $(PYTHON) tests/junit.py $(<:$(OBJDIR)/%=%)
4278ec9d54bSJed Brown
4288ec9d54bSJed Brownjunit : $(alltests:$(OBJDIR)/%=junit-%)
4298ec9d54bSJed Brown
4302f4d9adbSJeremy L Thompsonall: $(alltests)
4312f4d9adbSJeremy L Thompson
4322f4d9adbSJeremy L Thompsonexamples : $(allexamples)
4332f4d9adbSJeremy L Thompson
4342f4d9adbSJeremy L Thompson# Benchmarks
4350c59ef15SJeremy L Thompsonallbenchmarks = petsc-bps
4364e79ff5bSVeselin Dobrevbench_targets = $(addprefix bench-,$(allbenchmarks))
4374e79ff5bSVeselin Dobrev.PHONY: $(bench_targets) benchmarks
4384e79ff5bSVeselin Dobrev$(bench_targets): bench-%: $(OBJDIR)/%
4392f4d9adbSJeremy L Thompson	cd benchmarks && ./benchmark.sh --ceed "$(BACKENDS)" -r $(*).sh
4404e79ff5bSVeselin Dobrevbenchmarks: $(bench_targets)
4412c6ea02fSJed Brown
4426ea7c6c1SJed Brown$(ceed.pc) : pkgconfig-prefix = $(abspath .)
443d5217624SJed Brown$(OBJDIR)/ceed.pc : pkgconfig-prefix = $(prefix)
444d5217624SJed Brown.INTERMEDIATE : $(OBJDIR)/ceed.pc
4456ea7c6c1SJed Brown%/ceed.pc : ceed.pc.template | $$(@D)/.DIR
4466ea7c6c1SJed Brown	@sed "s:%prefix%:$(pkgconfig-prefix):" $< > $@
4470e439e50SJed Brown
448bf3e26f6SVeselin DobrevOCCA        := $(OCCA_DIR)/bin/occa
449cc6ff0d7SJed BrownOKL_KERNELS := $(wildcard backends/occa/*.okl)
450cc6ff0d7SJed Brown
451cc6ff0d7SJed Brownokl-cache :
452cc6ff0d7SJed Brown	$(OCCA) cache ceed $(OKL_KERNELS)
453cc6ff0d7SJed Brown
454cc6ff0d7SJed Brownokl-clear:
455cc6ff0d7SJed Brown	$(OCCA) clear -y -l ceed
456a5ba6ca9Scamierjs
457d5217624SJed Browninstall : $(libceed) $(OBJDIR)/ceed.pc
458bf3e26f6SVeselin Dobrev	$(INSTALL) -d $(addprefix $(if $(DESTDIR),"$(DESTDIR)"),"$(includedir)"\
459bf3e26f6SVeselin Dobrev	  "$(libdir)" "$(pkgconfigdir)" $(if $(OCCA_ON),"$(okldir)"))
4601e25a746SJed Brown	$(INSTALL_DATA) include/ceed.h "$(DESTDIR)$(includedir)/"
461f91e0974SThilina Rathnayake	$(INSTALL_DATA) include/ceedf.h "$(DESTDIR)$(includedir)/"
4621e25a746SJed Brown	$(INSTALL_DATA) $(libceed) "$(DESTDIR)$(libdir)/"
4631e25a746SJed Brown	$(INSTALL_DATA) $(OBJDIR)/ceed.pc "$(DESTDIR)$(pkgconfigdir)/"
464bf3e26f6SVeselin Dobrev	$(if $(OCCA_ON),$(INSTALL_DATA) $(OKL_KERNELS) "$(DESTDIR)$(okldir)/")
465d5217624SJed Brown
466683faae0SJed Brown.PHONY : cln clean doc lib install all print test tst prove prv prove-all junit examples style tidy okl-cache okl-clear info info-backends
467d635b4c6Scamierjs
4686e5d1fd9Scamierjscln clean :
469df0ef7e4SVeselin Dobrev	$(RM) -r $(OBJDIR) $(LIBDIR)
4702774d5cbSJeremy L Thompson	$(MAKE) -C examples clean
471c4acb06bSStan Tomov	$(RM) $(magma_tmp.c) $(magma_tmp.cu) backends/magma/*~ backends/magma/*.o
4722f4d9adbSJeremy L Thompson	$(RM) -rf benchmarks/*output.txt
4734859b599SJed Brown
47407838a1cSTzaniodistclean : clean
4758c23e06aSJed Brown	$(RM) -r doc/html
47607838a1cSTzanio
4770ab95609SJed Browndoc :
4787bd3a522STzanio	doxygen Doxyfile
4797bd3a522STzanio
480f2fa494dScamierjsstyle :
48120b73d85SJed Brown	@astyle --options=.astylerc \
48220b73d85SJed Brown          $(filter-out include/ceedf.h tests/t310-basis-f.h, \
48320b73d85SJed Brown            $(wildcard include/*.h interface/*.[ch] tests/*.[ch] backends/*/*.[ch] \
48420b73d85SJed Brown              examples/*/*.[ch] examples/*/*.[ch]pp))
4850dbfdfc5SJed Brown
486683faae0SJed BrownCLANG_TIDY ?= clang-tidy
487683faae0SJed Brown%.c.tidy : %.c
488683faae0SJed Brown	$(CLANG_TIDY) $^ -- $(CPPFLAGS)
489683faae0SJed Brown
490683faae0SJed Browntidy : $(libceed.c:%=%.tidy)
491683faae0SJed Brown
4924859b599SJed Brownprint :
4934859b599SJed Brown	@echo $(VAR)=$($(VAR))
494582447c9SJed Brown
4959df38c42SVeselin Dobrevprint-% :
4969df38c42SVeselin Dobrev	$(info [ variable name]: $*)
4979df38c42SVeselin Dobrev	$(info [        origin]: $(origin $*))
4989df38c42SVeselin Dobrev	$(info [         value]: $(value $*))
4999df38c42SVeselin Dobrev	$(info [expanded value]: $($*))
5009df38c42SVeselin Dobrev	$(info )
5019df38c42SVeselin Dobrev	@true
5029df38c42SVeselin Dobrev
503d1f7f8d3SJed Brown-include $(libceed.c:%.c=$(OBJDIR)/%.d) $(tests.c:tests/%.c=$(OBJDIR)/%.d)
504