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 171571c99dSValeria Barra-include config.mk 181571c99dSValeria 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 25196a75e4SJed BrownNVCC ?= $(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/*),) 40*86a4271fSThilina Rathnayake NEK5K_DIR ?= $(abspath ../Nek5000) 414d1cd9fcSJeremy L Thompsonendif 42*86a4271fSThilina Rathnayakeexport NEK5K_DIR 43*86a4271fSThilina RathnayakeMPI ?= 1 44*86a4271fSThilina Rathnayake 45*86a4271fSThilina Rathnayake# CEED_DIR env for NEK5K testing 46*86a4271fSThilina Rathnayakeexport CEED_DIR = $(abspath .) 474d1cd9fcSJeremy L Thompson 488d713cf6Sjeremylt# XSMM_DIR env variable should point to XSMM master (github.com/hfp/libxsmm) 498d713cf6SjeremyltXSMM_DIR ?= ../libxsmm 508d713cf6Sjeremylt 5112123fd5Scamierjs# OCCA_DIR env variable should point to OCCA master (github.com/libocca/occa) 527f5ff99bSVeselin DobrevOCCA_DIR ?= ../occa 53f797d7b2Scamierjs 545a9ca9adSVeselin Dobrev# env variable MAGMA_DIR can be used too 555a9ca9adSVeselin DobrevMAGMA_DIR ?= ../magma 565a9ca9adSVeselin Dobrev# If CUDA_DIR is not set, check for nvcc, or resort to /usr/local/cuda 575a9ca9adSVeselin DobrevCUDA_DIR ?= $(or $(patsubst %/,%,$(dir $(patsubst %/,%,$(dir \ 585a9ca9adSVeselin Dobrev $(shell which nvcc 2> /dev/null))))),/usr/local/cuda) 5982b77998SStan Tomov 602f4d9adbSJeremy L Thompson# Check for PETSc in ../petsc 612f4d9adbSJeremy L Thompsonifneq ($(wildcard ../petsc/lib/libpetsc.*),) 622f4d9adbSJeremy L Thompson PETSC_DIR ?= ../petsc 632f4d9adbSJeremy L Thompsonendif 642f4d9adbSJeremy L Thompson 65bf000209STzanio# Warning: SANTIZ options still don't run with /gpu/occa 6612123fd5Scamierjs# export LSAN_OPTIONS=suppressions=.asanignore 67c12ddcb5ScamierjsAFLAGS = -fsanitize=address #-fsanitize=undefined -fno-omit-frame-pointer 6832d74c32SThilina Rathnayake 692774d5cbSJeremy L ThompsonOPT = -O -g -march=native -ffp-contract=fast -fopenmp-simd 70323c739cSJed BrownCFLAGS = -std=c99 $(OPT) -Wall -Wextra -Wno-unused-parameter -fPIC -MMD -MP 719f0427d9SYohannNVCCFLAGS = -Xcompiler "$(OPT)" -Xcompiler -fPIC 721dc2661bSVeselin Dobrev# If using the IBM XL Fortran (xlf) replace FFLAGS appropriately: 731dc2661bSVeselin Dobrevifneq ($(filter %xlf %xlf_r,$(FC)),) 7410da579bSJeremy L Thompson FFLAGS = $(OPT) -ffree-form -qpreprocess -qextname -qpic -MMD 75323c739cSJed Brownelse # gfortran/Intel-style options 768980d4a7Sjeremylt FFLAGS = -cpp $(OPT) -Wall -Wextra -Wno-unused-parameter -Wno-unused-dummy-argument -fPIC -MMD -MP 771dc2661bSVeselin Dobrevendif 781b58aefaScamierjs 7932d74c32SThilina Rathnayakeifeq ($(UNDERSCORE), 1) 8032d74c32SThilina Rathnayake CFLAGS += -DUNDERSCORE 8132d74c32SThilina Rathnayakeendif 8232d74c32SThilina Rathnayake 83a6f4783aSJed Brownifeq ($(COVERAGE), 1) 84a6f4783aSJed Brown CFLAGS += --coverage 85a6f4783aSJed Brown LDFLAGS += --coverage 86a6f4783aSJed Brownendif 87a6f4783aSJed Brown 884dd6f121ScamierjsCFLAGS += $(if $(ASAN),$(AFLAGS)) 894dd6f121ScamierjsFFLAGS += $(if $(ASAN),$(AFLAGS)) 904dd6f121ScamierjsLDFLAGS += $(if $(ASAN),$(AFLAGS)) 916ea7c6c1SJed BrownCPPFLAGS = -I./include 92582447c9SJed BrownLDLIBS = -lm 9391b7489eSJed BrownOBJDIR := build 946ea7c6c1SJed BrownLIBDIR := lib 956ea7c6c1SJed Brown 96d5217624SJed Brown# Installation variables 97d5217624SJed Brownprefix ?= /usr/local 98d5217624SJed Brownbindir = $(prefix)/bin 99d5217624SJed Brownlibdir = $(prefix)/lib 100bf3e26f6SVeselin Dobrevokldir = $(libdir)/okl 101d5217624SJed Brownincludedir = $(prefix)/include 102d5217624SJed Brownpkgconfigdir = $(libdir)/pkgconfig 103d5217624SJed BrownINSTALL = install 104d5217624SJed BrownINSTALL_PROGRAM = $(INSTALL) 105d5217624SJed BrownINSTALL_DATA = $(INSTALL) -m644 106d5217624SJed Brown 1073b56482dScamierjs# Get number of processors of the machine 10869762e1fScamierjsNPROCS := $(shell getconf _NPROCESSORS_ONLN) 1093b56482dScamierjs# prepare make options to run in parallel 11082985883ScamierjsMFLAGS := -j $(NPROCS) --warn-undefined-variables \ 11121ae6867Scamierjs --no-print-directory --no-keep-going 11287e762eaSJed Brown 1138ec9d54bSJed BrownPYTHON ?= python3 114bfa078e6SJed BrownPROVE ?= prove 1153a1ec3cdSJed BrownPROVE_OPTS ?= -j $(NPROCS) 1165c719ab0SJed BrownDARWIN := $(filter Darwin,$(shell uname -s)) 1175c719ab0SJed BrownSO_EXT := $(if $(DARWIN),dylib,so) 1189df38c42SVeselin Dobrev 1196ea7c6c1SJed Brownceed.pc := $(LIBDIR)/pkgconfig/ceed.pc 12091b7489eSJed Brownlibceed := $(LIBDIR)/libceed.$(SO_EXT) 1217e68d260SJed BrownCEED_LIBS = -lceed 122d7b241e6Sjeremyltlibceed.c := $(wildcard interface/ceed*.c) 123265be9c8Sjeremyltlibceed_test := $(LIBDIR)/libceed_test.$(SO_EXT) 12476af460cSJed Brownlibceeds = $(libceed) $(libceed_test) 125265be9c8SjeremyltBACKENDS_BUILTIN := /cpu/self/ref/serial /cpu/self/ref/blocked /cpu/self/opt/serial /cpu/self/opt/blocked 126d20f937dSJed BrownBACKENDS := $(BACKENDS_BUILTIN) 127bf000209STzanio 128bf000209STzanio# Tests 12957c64913Sjeremylttests.c := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.c)) 1308980d4a7Sjeremylttests.f := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.f90)) 13191b7489eSJed Browntests := $(tests.c:tests/%.c=$(OBJDIR)/%) 1323f3e7340Scamierjsctests := $(tests) 1338980d4a7Sjeremylttests += $(tests.f:tests/%.f90=$(OBJDIR)/%) 134*86a4271fSThilina Rathnayake# Examples 135182fbe45STzanioexamples.c := $(sort $(wildcard examples/ceed/*.c)) 136182fbe45STzanioexamples.f := $(sort $(wildcard examples/ceed/*.f)) 137182fbe45STzanioexamples := $(examples.c:examples/ceed/%.c=$(OBJDIR)/%) 138182fbe45STzanioexamples += $(examples.f:examples/ceed/%.f=$(OBJDIR)/%) 139*86a4271fSThilina Rathnayake# MFEM Examples 1402158b1b0Sjeremyltmfemexamples.cpp := $(sort $(wildcard examples/mfem/*.cpp)) 14116c6c054SJed Brownmfemexamples := $(mfemexamples.cpp:examples/mfem/%.cpp=$(OBJDIR)/mfem-%) 142*86a4271fSThilina Rathnayake# Nek5K Examples 143*86a4271fSThilina Rathnayakenekexamples := $(OBJDIR)/nek-bps 144*86a4271fSThilina Rathnayake# PETSc Examples 145e797ab98SJed Brownpetscexamples.c := $(sort $(wildcard examples/petsc/*.c)) 146e797ab98SJed Brownpetscexamples := $(petscexamples.c:examples/petsc/%.c=$(OBJDIR)/petsc-%) 147*86a4271fSThilina Rathnayake# Navier-Stokes Example 1482774d5cbSJeremy L Thompsonnavierstokesexample.c := $(sort $(wildcard examples/navier-stokes/*.c)) 1492774d5cbSJeremy L Thompsonnavierstokesexample := $(navierstokesexample.c:examples/navier-stokes/%.c=$(OBJDIR)/navier-stokes-%) 150e797ab98SJed Brown 151*86a4271fSThilina Rathnayake# Backends/[ref, blocked, template, memcheck, opt, avx, occa, magma] 152ae3cba82Scamierjsref.c := $(sort $(wildcard backends/ref/*.c)) 15389c6efa4Sjeremyltblocked.c := $(sort $(wildcard backends/blocked/*.c)) 154a718229cSjeremylttemplate.c := $(sort $(wildcard backends/template/*.c)) 15589c6efa4Sjeremyltceedmemcheck.c := $(sort $(wildcard backends/memcheck/*.c)) 15689c6efa4Sjeremyltopt.c := $(sort $(wildcard backends/opt/*.c)) 15789c6efa4Sjeremyltavx.c := $(sort $(wildcard backends/avx/*.c)) 15889c6efa4Sjeremyltxsmm.c := $(sort $(wildcard backends/xsmm/*.c)) 1599f0427d9SYohanncuda.c := $(sort $(wildcard backends/cuda/*.c)) 1609f0427d9SYohanncuda.cu := $(sort $(wildcard backends/cuda/*.cu)) 16155ae60f9SYohanncuda-reg.c := $(sort $(wildcard backends/cuda-reg/*.c)) 16255ae60f9SYohanncuda-reg.cu := $(sort $(wildcard backends/cuda-reg/*.cu)) 163c532df63SYohanncuda-shared.c := $(sort $(wildcard backends/cuda-shared/*.c)) 164c532df63SYohanncuda-shared.cu := $(sort $(wildcard backends/cuda-shared/*.cu)) 165ae3cba82Scamierjsocca.c := $(sort $(wildcard backends/occa/*.c)) 166755585ceSStan Tomovmagma_preprocessor := python backends/magma/gccm.py 167c4acb06bSStan Tomovmagma_pre_src := $(filter-out %_tmp.c, $(wildcard backends/magma/ceed-*.c)) 168c4acb06bSStan Tomovmagma_dsrc := $(wildcard backends/magma/magma_d*.c) 169c4acb06bSStan Tomovmagma_tmp.c := $(magma_pre_src:%.c=%_tmp.c) 170c4acb06bSStan Tomovmagma_tmp.cu := $(magma_pre_src:%.c=%_cuda.cu) 171c4acb06bSStan Tomovmagma_allsrc.c := $(magma_dsrc) $(magma_tmp.c) 172c4acb06bSStan Tomovmagma_allsrc.cu:= $(magma_tmp.cu) 17382985883Scamierjs 1749bdc3d68Scamierjs# Output using the 216-color rules mode 17518a724fcScamierjsrule_file = $(notdir $(1)) 17618a724fcScamierjsrule_path = $(patsubst %/,%,$(dir $(1))) 17718a724fcScamierjslast_path = $(notdir $(patsubst %/,%,$(dir $(1)))) 1783c5d0cdfSJed Brownansicolor = $(shell echo $(call last_path,$(1)) | cksum | cut -b1-2 | xargs -IS expr 2 \* S + 17) 179abb87f81Scamierjsemacs_out = @printf " %10s %s/%s\n" $(1) $(call rule_path,$(2)) $(call rule_file,$(2)) 180abb87f81Scamierjscolor_out = @if [ -t 1 ]; then \ 18118a724fcScamierjs printf " %10s \033[38;5;%d;1m%s\033[m/%s\n" \ 1823c5d0cdfSJed Brown $(1) $(call ansicolor,$(2)) \ 18318a724fcScamierjs $(call rule_path,$(2)) $(call rule_file,$(2)); else \ 18418a724fcScamierjs printf " %10s %s\n" $(1) $(2); fi 185f797d7b2Scamierjs# if TERM=dumb, use it, otherwise switch to the term one 186abb87f81Scamierjsoutput = $(if $(TERM:dumb=),$(call color_out,$1,$2),$(call emacs_out,$1,$2)) 18782985883Scamierjs 1889bdc3d68Scamierjs# if V is set to non-nil, turn the verbose mode 18918a724fcScamierjsquiet = $(if $(V),$($(1)),$(call output,$1,$@);$($(1))) 19021ae6867Scamierjs 191da72e7fcSJed Brown# Cancel built-in and old-fashioned implicit rules which we don't use 1929df38c42SVeselin Dobrev.SUFFIXES: 193da72e7fcSJed Brown 19491b7489eSJed Brown.SECONDEXPANSION: # to expand $$(@D)/.DIR 1959df38c42SVeselin Dobrev 196c4acb06bSStan Tomov.SECONDARY: $(magma_tmp.c) $(magma_tmp.cu) 19714c1ded1SStan Tomov 19891b7489eSJed Brown%/.DIR : 19991b7489eSJed Brown @mkdir -p $(@D) 20091b7489eSJed Brown @touch $@ 20191b7489eSJed Brown 20291b7489eSJed Brown.PRECIOUS: %/.DIR 20391b7489eSJed Brown 20423072ed2SVeselin Dobrevlib: $(libceed) $(ceed.pc) 20523072ed2SVeselin Dobrev# run 'lib' target in parallel 2062f4d9adbSJeremy L Thompsonpar:;@$(MAKE) $(MFLAGS) V=$(V) lib 207d20f937dSJed Brownbackend_status = $(if $(filter $1,$(BACKENDS)), [backends: $1], [not found]) 208bf3e26f6SVeselin Dobrevinfo: 209bf3e26f6SVeselin Dobrev $(info ------------------------------------) 210bf3e26f6SVeselin Dobrev $(info CC = $(CC)) 211bf3e26f6SVeselin Dobrev $(info FC = $(FC)) 212bf3e26f6SVeselin Dobrev $(info CPPFLAGS = $(CPPFLAGS)) 213bf3e26f6SVeselin Dobrev $(info CFLAGS = $(value CFLAGS)) 214bf3e26f6SVeselin Dobrev $(info FFLAGS = $(value FFLAGS)) 215bf3e26f6SVeselin Dobrev $(info NVCCFLAGS = $(value NVCCFLAGS)) 216bf3e26f6SVeselin Dobrev $(info LDFLAGS = $(value LDFLAGS)) 217bf3e26f6SVeselin Dobrev $(info LDLIBS = $(LDLIBS)) 218bf3e26f6SVeselin Dobrev $(info OPT = $(OPT)) 219bf3e26f6SVeselin Dobrev $(info AFLAGS = $(AFLAGS)) 220bf3e26f6SVeselin Dobrev $(info ASAN = $(or $(ASAN),(empty))) 221bf3e26f6SVeselin Dobrev $(info V = $(or $(V),(empty)) [verbose=$(if $(V),on,off)]) 222bf3e26f6SVeselin Dobrev $(info ------------------------------------) 223bdc3149dSjeremylt $(info MEMCHK_STATUS = $(MEMCHK_STATUS)$(call backend_status,/cpu/self/ref/memcheck)) 22484a01de5SJeremy L Thompson $(info AVX_STATUS = $(AVX_STATUS)$(call backend_status,/cpu/self/avx/serial /cpu/self/avx/blocked)) 22584a01de5SJeremy L Thompson $(info XSMM_DIR = $(XSMM_DIR)$(call backend_status,/cpu/self/xsmm/serial /cpu/self/xsmm/blocked)) 226d20f937dSJed Brown $(info OCCA_DIR = $(OCCA_DIR)$(call backend_status,/cpu/occa /gpu/occa /omp/occa)) 227d20f937dSJed Brown $(info MAGMA_DIR = $(MAGMA_DIR)$(call backend_status,/gpu/magma)) 228ab9cabdeSVeselin Dobrev $(info CUDA_DIR = $(CUDA_DIR)$(call backend_status,$(CUDA_BACKENDS))) 229bf3e26f6SVeselin Dobrev $(info ------------------------------------) 230bf3e26f6SVeselin Dobrev $(info MFEM_DIR = $(MFEM_DIR)) 2314d1cd9fcSJeremy L Thompson $(info NEK5K_DIR = $(NEK5K_DIR)) 232bf3e26f6SVeselin Dobrev $(info PETSC_DIR = $(PETSC_DIR)) 233bf3e26f6SVeselin Dobrev $(info ------------------------------------) 234bf3e26f6SVeselin Dobrev $(info prefix = $(prefix)) 235bf3e26f6SVeselin Dobrev $(info includedir = $(value includedir)) 236bf3e26f6SVeselin Dobrev $(info libdir = $(value libdir)) 237bf3e26f6SVeselin Dobrev $(info okldir = $(value okldir)) 238bf3e26f6SVeselin Dobrev $(info pkgconfigdir = $(value pkgconfigdir)) 239bf3e26f6SVeselin Dobrev $(info ------------------------------------) 240bf3e26f6SVeselin Dobrev @true 24123072ed2SVeselin Dobrevinfo-backends: 242d20f937dSJed Brown $(info make: 'lib' with optional backends: $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS))) 2432f4d9adbSJeremy L Thompson.PHONY: lib all par info info-backends 2440e439e50SJed Brown 24524d002f4SJed Brown$(libceed) : LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed))) 24676af460cSJed Brown$(libceed_test) : LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed_test))) 24769762e1fScamierjs 24848fffa06Sjeremylt# Standard Backends 24987174f08SJed Brownlibceed.c += $(ref.c) 2504a2e7687Sjeremyltlibceed.c += $(blocked.c) 25189c6efa4Sjeremyltlibceed.c += $(opt.c) 25223072ed2SVeselin Dobrev 253265be9c8Sjeremylt# Testing Backends 254265be9c8Sjeremylttest_backends.c := $(template.c) 255265be9c8SjeremyltTEST_BACKENDS := /cpu/self/tmpl /cpu/self/tmpl/sub 256265be9c8Sjeremylt 257fc7cf9a0Sjeremylt# Memcheck Backend 258bdc3149dSjeremyltMEMCHK_STATUS = Disabled 259b8fb44e7SJed BrownMEMCHK := $(shell echo "\#include <valgrind/memcheck.h>" | $(CC) $(CPPFLAGS) -E - >/dev/null 2>&1 && echo 1) 260bdc3149dSjeremyltifeq ($(MEMCHK),1) 261bdc3149dSjeremylt MEMCHK_STATUS = Enabled 262fc7cf9a0Sjeremylt libceed.c += $(ceedmemcheck.c) 263fc7cf9a0Sjeremylt BACKENDS += /cpu/self/ref/memcheck 264fc7cf9a0Sjeremyltendif 265fc7cf9a0Sjeremylt 26648fffa06Sjeremylt# AVX Backed 26748fffa06SjeremyltAVX_STATUS = Disabled 26877538c7aSJed BrownAVX := $(shell $(CC) $(OPT) -v -E - < /dev/null 2>&1 | grep -c ' -mavx') 26948fffa06Sjeremyltifeq ($(AVX),1) 27048fffa06Sjeremylt AVX_STATUS = Enabled 27148fffa06Sjeremylt libceed.c += $(avx.c) 27284a01de5SJeremy L Thompson BACKENDS += /cpu/self/avx/serial /cpu/self/avx/blocked 27348fffa06Sjeremyltendif 27448fffa06Sjeremylt 2758d713cf6Sjeremylt# libXSMM Backends 2768d713cf6Sjeremyltifneq ($(wildcard $(XSMM_DIR)/lib/libxsmm.*),) 27776af460cSJed Brown $(libceeds) : LDFLAGS += -L$(XSMM_DIR)/lib -Wl,-rpath,$(abspath $(XSMM_DIR)/lib) 27876af460cSJed Brown $(libceeds) : LDLIBS += -lxsmm -ldl 279724a7164Sjeremylt MKL ?= 0 280724a7164Sjeremylt ifneq (0,$(MKL)) 281c0ea1048SJed Brown BLAS_LIB = -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl 282724a7164Sjeremylt else 283c0ea1048SJed Brown BLAS_LIB = -lblas 284724a7164Sjeremylt endif 285c0ea1048SJed Brown $(libceeds) : LDLIBS += $(BLAS_LIB) 2868d713cf6Sjeremylt libceed.c += $(xsmm.c) 287683faae0SJed Brown $(xsmm.c:%.c=$(OBJDIR)/%.o) $(xsmm.c:%=%.tidy) : CPPFLAGS += -I$(XSMM_DIR)/include 2888d713cf6Sjeremylt BACKENDS += /cpu/self/xsmm/serial /cpu/self/xsmm/blocked 2898d713cf6Sjeremyltendif 2908d713cf6Sjeremylt 29148fffa06Sjeremylt# OCCA Backends 2927f5ff99bSVeselin Dobrevifneq ($(wildcard $(OCCA_DIR)/lib/libocca.*),) 29376af460cSJed Brown $(libceeds) : LDFLAGS += -L$(OCCA_DIR)/lib -Wl,-rpath,$(abspath $(OCCA_DIR)/lib) 29476af460cSJed Brown $(libceeds) : LDLIBS += -locca 29587174f08SJed Brown libceed.c += $(occa.c) 296683faae0SJed Brown $(occa.c:%.c=$(OBJDIR)/%.o) $(occa.c:%=%.tidy) : CPPFLAGS += -I$(OCCA_DIR)/include 297a953af89SJed Brown BACKENDS += /cpu/occa /gpu/occa /omp/occa 29821ae6867Scamierjsendif 29923072ed2SVeselin Dobrev 300*86a4271fSThilina Rathnayake# CUDA Backends 3015a9ca9adSVeselin DobrevCUDA_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(CUDA_DIR)/$d/libcudart.${SO_EXT})) 3025a9ca9adSVeselin DobrevCUDA_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(CUDA_LIB_DIR)))) 3033dd0010eSvaleriabarraCUDA_LIB_DIR_STUBS := $(CUDA_LIB_DIR)/stubs 304c532df63SYohannCUDA_BACKENDS = /gpu/cuda/ref /gpu/cuda/reg /gpu/cuda/shared 3055a9ca9adSVeselin Dobrevifneq ($(CUDA_LIB_DIR),) 3069d77422eSJed Brown $(libceeds) : CPPFLAGS += -I$(CUDA_DIR)/include 30776af460cSJed Brown $(libceeds) : LDFLAGS += -L$(CUDA_LIB_DIR) -Wl,-rpath,$(abspath $(CUDA_LIB_DIR)) 3089d77422eSJed Brown $(libceeds) : LDFLAGS += -L$(CUDA_LIB_DIR_STUBS) 30976af460cSJed Brown $(libceeds) : LDLIBS += -lcudart -lnvrtc -lcuda 310c532df63SYohann libceed.c += $(cuda.c) $(cuda-reg.c) $(cuda-shared.c) 311c532df63SYohann libceed.cu += $(cuda.cu) $(cuda-reg.cu) $(cuda-shared.cu) 312ab9cabdeSVeselin Dobrev BACKENDS += $(CUDA_BACKENDS) 3139f0427d9SYohannendif 3149f0427d9SYohann 3159f0427d9SYohann# MAGMA Backend 3169f0427d9SYohannifneq ($(wildcard $(MAGMA_DIR)/lib/libmagma.*),) 3179f0427d9SYohann ifneq ($(CUDA_LIB_DIR),) 3181dc2661bSVeselin Dobrev cuda_link = -Wl,-rpath,$(CUDA_LIB_DIR) -L$(CUDA_LIB_DIR) -lcublas -lcusparse -lcudart 3191dc2661bSVeselin Dobrev omp_link = -fopenmp 3201dc2661bSVeselin Dobrev magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(cuda_link) $(omp_link) 3217692a9b0SVeselin Dobrev magma_link_shared = -L$(MAGMA_DIR)/lib -Wl,-rpath,$(abspath $(MAGMA_DIR)/lib) -lmagma 3227692a9b0SVeselin Dobrev magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static)) 32376af460cSJed Brown $(libceeds) : LDLIBS += $(magma_link) 3247692a9b0SVeselin Dobrev $(tests) $(examples) : LDLIBS += $(magma_link) 325c4acb06bSStan Tomov libceed.c += $(magma_allsrc.c) 326c4acb06bSStan Tomov libceed.cu += $(magma_allsrc.cu) 327683faae0SJed Brown $(magma_allsrc.c:%.c=$(OBJDIR)/%.o) $(magma_allsrc.c:%=%.tidy) : CPPFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include 328c4acb06bSStan 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 329ce41f623SJed Brown BACKENDS += /gpu/magma 33082b77998SStan Tomov endif 3315a9ca9adSVeselin Dobrevendif 332755585ceSStan Tomov 333ce41f623SJed Brownexport BACKENDS 334ce41f623SJed Brown 335*86a4271fSThilina Rathnayake# Generate magma_tmp.c and magma_cuda.cu from magma.c 33629715310SJed Brown%_tmp.c %_cuda.cu : %.c 337755585ceSStan Tomov $(magma_preprocessor) $< 338755585ceSStan Tomov 33923072ed2SVeselin Dobrevlibceed.o = $(libceed.c:%.c=$(OBJDIR)/%.o) $(libceed.cu:%.cu=$(OBJDIR)/%.o) 34023072ed2SVeselin Dobrev$(libceed.o): | info-backends 34123072ed2SVeselin Dobrev$(libceed) : $(libceed.o) | $$(@D)/.DIR 34221ae6867Scamierjs $(call quiet,CC) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS) 34391b7489eSJed Brown 34458e8d3b7SJed Brown$(OBJDIR)/%.o : $(CURDIR)/%.c | $$(@D)/.DIR 345b5b03409SJed Brown $(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<) 346ae3cba82Scamierjs 34758e8d3b7SJed Brown$(OBJDIR)/%.o : $(CURDIR)/%.cu | $$(@D)/.DIR 348755585ceSStan Tomov $(call quiet,NVCC) $(CPPFLAGS) $(NVCCFLAGS) -c -o $@ $(abspath $<) 349755585ceSStan Tomov 350b5b03409SJed Brown$(OBJDIR)/% : tests/%.c | $$(@D)/.DIR 351265be9c8Sjeremylt $(call quiet,LINK.c) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 35278b5556aScamierjs 3538980d4a7Sjeremylt$(OBJDIR)/% : tests/%.f90 | $$(@D)/.DIR 354265be9c8Sjeremylt $(call quiet,LINK.F) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 35532d74c32SThilina Rathnayake 356182fbe45STzanio$(OBJDIR)/% : examples/ceed/%.c | $$(@D)/.DIR 357265be9c8Sjeremylt $(call quiet,LINK.c) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 35891b7489eSJed Brown 359182fbe45STzanio$(OBJDIR)/% : examples/ceed/%.f | $$(@D)/.DIR 360265be9c8Sjeremylt $(call quiet,LINK.F) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 361673d494eSThilina Rathnayake 36216c6c054SJed Brown$(OBJDIR)/mfem-% : examples/mfem/%.cpp $(libceed) | $$(@D)/.DIR 363c4216f28SJed Brown +$(MAKE) -C examples/mfem CEED_DIR=`pwd` \ 3642f4d9adbSJeremy L Thompson MFEM_DIR="$(abspath $(MFEM_DIR))" $* 36516c6c054SJed Brown mv examples/mfem/$* $@ 36616c6c054SJed Brown 367*86a4271fSThilina Rathnayake# Note: Multiple Nek files cannot be built in parallel. The '+' here enables 368*86a4271fSThilina Rathnayake# this single Nek bps file to be built in parallel with other examples, 369*86a4271fSThilina Rathnayake# such as when calling `make prove-all -j2`. 370*86a4271fSThilina Rathnayake$(OBJDIR)/nek-bps : examples/nek/bps/bps.usr examples/nek/nek-examples.sh $(libceed) | $$(@D)/.DIR 371*86a4271fSThilina Rathnayake +$(MAKE) -C examples MPI=$(MPI) CEED_DIR=`pwd` NEK5K_DIR="$(abspath $(NEK5K_DIR))" nek 372*86a4271fSThilina Rathnayake mv examples/nek/build/bps $(OBJDIR)/bps 373*86a4271fSThilina Rathnayake cp examples/nek/nek-examples.sh $(OBJDIR)/nek-bps 374*86a4271fSThilina Rathnayake 3757f6cf205SJed Brown$(OBJDIR)/petsc-% : examples/petsc/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR 376c4216f28SJed Brown +$(MAKE) -C examples/petsc CEED_DIR=`pwd` \ 3772f4d9adbSJeremy L Thompson PETSC_DIR="$(abspath $(PETSC_DIR))" $* 378e797ab98SJed Brown mv examples/petsc/$* $@ 379e797ab98SJed Brown 3802774d5cbSJeremy L Thompson$(OBJDIR)/navier-stokes-% : examples/navier-stokes/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR 381c4216f28SJed Brown +$(MAKE) -C examples/navier-stokes CEED_DIR=`pwd` \ 3822774d5cbSJeremy L Thompson PETSC_DIR="$(abspath $(PETSC_DIR))" $* 3832774d5cbSJeremy L Thompson mv examples/navier-stokes/$* $@ 3842774d5cbSJeremy L Thompson 385567e4d0aSJed Brownlibceed_test.o = $(test_backends.c:%.c=$(OBJDIR)/%.o) 38676af460cSJed Brown$(libceed_test) : $(libceed.o) $(libceed_test.o) | $$(@D)/.DIR 387265be9c8Sjeremylt $(call quiet,CC) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS) 388265be9c8Sjeremylt 389265be9c8Sjeremylt$(examples) : $(libceed) 39076af460cSJed Brown$(tests) : $(libceed_test) 39176af460cSJed Brown$(tests) : CEED_LIBS = -lceed_test 392fc377ca6SJed Brown$(tests) $(examples) : LDFLAGS += -Wl,-rpath,$(abspath $(LIBDIR)) -L$(LIBDIR) 3934859b599SJed Brown 394686de4acSJed Brownrun-t% : BACKENDS += $(TEST_BACKENDS) 395dad465e7SJed Brownrun-% : $(OBJDIR)/% 396d1f7f8d3SJed Brown @tests/tap.sh $(<:$(OBJDIR)/%=%) 397686de4acSJed Brown 398686de4acSJed Brownexternal_examples := \ 399686de4acSJed Brown $(if $(MFEM_DIR),$(mfemexamples)) \ 400686de4acSJed Brown $(if $(PETSC_DIR),$(petscexamples)) \ 401686de4acSJed Brown $(if $(NEK5K_DIR),$(nekexamples)) 402686de4acSJed Brown 403686de4acSJed Brownallexamples = $(examples) $(external_examples) 404686de4acSJed Brown 405686de4acSJed Brown# The test and prove targets can be controlled via pattern searches. The 406686de4acSJed Brown# default is to run tests and those examples that have no external dependencies. 407686de4acSJed Brown# Examples of finer grained control: 408686de4acSJed Brown# 409686de4acSJed Brown# make test search='petsc mfem' # PETSc and MFEM examples 410686de4acSJed Brown# make prove search='t3' # t3xx series tests 411686de4acSJed Brown# make junit search='ex petsc' # core ex* and PETSc tests 412686de4acSJed Brownsearch ?= t ex 413686de4acSJed Brownrealsearch = $(search:%=%%) 414686de4acSJed Brownmatched = $(foreach pattern,$(realsearch),$(filter $(OBJDIR)/$(pattern),$(tests) $(allexamples))) 415686de4acSJed Brown 4162158b1b0Sjeremylt# Test core libCEED 417686de4acSJed Browntest : $(matched:$(OBJDIR)/%=run-%) 4182158b1b0Sjeremylt 419*86a4271fSThilina Rathnayake# Run test target in parallel 4206850bcb5Scamierjstst : ;@$(MAKE) $(MFLAGS) V=$(V) test 4213b56482dScamierjs# CPU C tests only for backend % 4223f3e7340Scamierjsctc-% : $(ctests);@$(foreach tst,$(ctests),$(tst) /cpu/$*;) 4234859b599SJed Brown 424686de4acSJed Brownprove : BACKENDS += $(TEST_BACKENDS) 425*86a4271fSThilina Rathnayakeprove : $(matched) 426a5dc8077SJed Brown $(info Testing backends: $(BACKENDS)) 427686de4acSJed Brown $(PROVE) $(PROVE_OPTS) --exec 'tests/tap.sh' $(matched:$(OBJDIR)/%=%) 428*86a4271fSThilina Rathnayake# Run prove target in parallel 4296850bcb5Scamierjsprv : ;@$(MAKE) $(MFLAGS) V=$(V) prove 430bfa078e6SJed Brown 431686de4acSJed Brownprove-all : 432686de4acSJed Brown +$(MAKE) prove realsearch=% 433686de4acSJed Brown 434686de4acSJed Brownjunit-t% : BACKENDS += $(TEST_BACKENDS) 4358ec9d54bSJed Brownjunit-% : $(OBJDIR)/% 436bdb0bdbbSJed Brown @printf " %10s %s\n" TEST $(<:$(OBJDIR)/%=%); $(PYTHON) tests/junit.py $(<:$(OBJDIR)/%=%) 4378ec9d54bSJed Brown 43876174befSjeremyltjunit : $(matched:$(OBJDIR)/%=junit-%) 4398ec9d54bSJed Brown 4402f4d9adbSJeremy L Thompsonall: $(alltests) 4412f4d9adbSJeremy L Thompson 4422f4d9adbSJeremy L Thompsonexamples : $(allexamples) 443*86a4271fSThilina Rathnayakeceedexamples : $(examples) 444*86a4271fSThilina Rathnayakenekexamples : $(nekexamples) 445*86a4271fSThilina Rathnayakemfemexamples : $(mfemexamples) 446*86a4271fSThilina Rathnayakepetscexamples : $(petscexamples) 4472f4d9adbSJeremy L Thompson 4482f4d9adbSJeremy L Thompson# Benchmarks 4490c59ef15SJeremy L Thompsonallbenchmarks = petsc-bps 4504e79ff5bSVeselin Dobrevbench_targets = $(addprefix bench-,$(allbenchmarks)) 4514e79ff5bSVeselin Dobrev.PHONY: $(bench_targets) benchmarks 4524e79ff5bSVeselin Dobrev$(bench_targets): bench-%: $(OBJDIR)/% 4532f4d9adbSJeremy L Thompson cd benchmarks && ./benchmark.sh --ceed "$(BACKENDS)" -r $(*).sh 4544e79ff5bSVeselin Dobrevbenchmarks: $(bench_targets) 4552c6ea02fSJed Brown 4566ea7c6c1SJed Brown$(ceed.pc) : pkgconfig-prefix = $(abspath .) 457d5217624SJed Brown$(OBJDIR)/ceed.pc : pkgconfig-prefix = $(prefix) 458d5217624SJed Brown.INTERMEDIATE : $(OBJDIR)/ceed.pc 4596ea7c6c1SJed Brown%/ceed.pc : ceed.pc.template | $$(@D)/.DIR 4606ea7c6c1SJed Brown @sed "s:%prefix%:$(pkgconfig-prefix):" $< > $@ 4610e439e50SJed Brown 462bf3e26f6SVeselin DobrevOCCA := $(OCCA_DIR)/bin/occa 463cc6ff0d7SJed BrownOKL_KERNELS := $(wildcard backends/occa/*.okl) 464cc6ff0d7SJed Brown 465cc6ff0d7SJed Brownokl-cache : 466cc6ff0d7SJed Brown $(OCCA) cache ceed $(OKL_KERNELS) 467cc6ff0d7SJed Brown 468cc6ff0d7SJed Brownokl-clear: 469cc6ff0d7SJed Brown $(OCCA) clear -y -l ceed 470a5ba6ca9Scamierjs 471d5217624SJed Browninstall : $(libceed) $(OBJDIR)/ceed.pc 472bf3e26f6SVeselin Dobrev $(INSTALL) -d $(addprefix $(if $(DESTDIR),"$(DESTDIR)"),"$(includedir)"\ 473bf3e26f6SVeselin Dobrev "$(libdir)" "$(pkgconfigdir)" $(if $(OCCA_ON),"$(okldir)")) 4741e25a746SJed Brown $(INSTALL_DATA) include/ceed.h "$(DESTDIR)$(includedir)/" 475f91e0974SThilina Rathnayake $(INSTALL_DATA) include/ceedf.h "$(DESTDIR)$(includedir)/" 4761e25a746SJed Brown $(INSTALL_DATA) $(libceed) "$(DESTDIR)$(libdir)/" 4771e25a746SJed Brown $(INSTALL_DATA) $(OBJDIR)/ceed.pc "$(DESTDIR)$(pkgconfigdir)/" 478bf3e26f6SVeselin Dobrev $(if $(OCCA_ON),$(INSTALL_DATA) $(OKL_KERNELS) "$(DESTDIR)$(okldir)/") 479d5217624SJed Brown 480683faae0SJed 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 481d635b4c6Scamierjs 4826e5d1fd9Scamierjscln clean : 483df0ef7e4SVeselin Dobrev $(RM) -r $(OBJDIR) $(LIBDIR) 484*86a4271fSThilina Rathnayake $(MAKE) -C examples clean NEK5K_DIR="$(abspath $(NEK5K_DIR))" 485c4acb06bSStan Tomov $(RM) $(magma_tmp.c) $(magma_tmp.cu) backends/magma/*~ backends/magma/*.o 486196a75e4SJed Brown $(RM) benchmarks/*output.txt 4874859b599SJed Brown 48807838a1cSTzaniodistclean : clean 489196a75e4SJed Brown $(RM) -r doc/html config.mk 49007838a1cSTzanio 4910ab95609SJed Browndoc : 4927bd3a522STzanio doxygen Doxyfile 4937bd3a522STzanio 494f2fa494dScamierjsstyle : 49520b73d85SJed Brown @astyle --options=.astylerc \ 49620b73d85SJed Brown $(filter-out include/ceedf.h tests/t310-basis-f.h, \ 49720b73d85SJed Brown $(wildcard include/*.h interface/*.[ch] tests/*.[ch] backends/*/*.[ch] \ 49820b73d85SJed Brown examples/*/*.[ch] examples/*/*.[ch]pp)) 4990dbfdfc5SJed Brown 500683faae0SJed BrownCLANG_TIDY ?= clang-tidy 501683faae0SJed Brown%.c.tidy : %.c 502683faae0SJed Brown $(CLANG_TIDY) $^ -- $(CPPFLAGS) 503683faae0SJed Brown 504683faae0SJed Browntidy : $(libceed.c:%=%.tidy) 505683faae0SJed Brown 5064859b599SJed Brownprint : 5074859b599SJed Brown @echo $(VAR)=$($(VAR)) 508582447c9SJed Brown 5099df38c42SVeselin Dobrevprint-% : 5109df38c42SVeselin Dobrev $(info [ variable name]: $*) 5119df38c42SVeselin Dobrev $(info [ origin]: $(origin $*)) 5129df38c42SVeselin Dobrev $(info [ value]: $(value $*)) 5139df38c42SVeselin Dobrev $(info [expanded value]: $($*)) 5149df38c42SVeselin Dobrev $(info ) 5159df38c42SVeselin Dobrev @true 5169df38c42SVeselin Dobrev 517d3c6b40fSJed Brown# "make configure" will autodetect any variables not passed on the 518d3c6b40fSJed Brown# command line, caching the result in config.mk to be used on any 519d3c6b40fSJed Brown# subsequent invocations of make. For example, 520d3c6b40fSJed Brown# 521d3c6b40fSJed Brown# make configure CC=/path/to/my/cc CUDA_DIR=/opt/cuda 522d3c6b40fSJed Brown# make 523d3c6b40fSJed Brown# make prove 524d3c6b40fSJed Brownconfigure : 52557213447SValeria Barra @: > config.mk 52657213447SValeria Barra @echo "CC = $(CC)" | tee -a config.mk 52757213447SValeria Barra @echo "FC = $(FC)" | tee -a config.mk 52857213447SValeria Barra @echo "NVCC = $(NVCC)" | tee -a config.mk 529d3c6b40fSJed Brown @echo "CFLAGS = $(CFLAGS)" | tee -a config.mk 530d3c6b40fSJed Brown @echo "CPPFLAGS = $(CPPFLAGS)" | tee -a config.mk 531d3c6b40fSJed Brown @echo "FFLAGS = $(FFLAGS)" | tee -a config.mk 532d3c6b40fSJed Brown @echo "LDFLAGS = $(LDFLAGS)" | tee -a config.mk 533d3c6b40fSJed Brown @echo "LDLIBS = $(LDLIBS)" | tee -a config.mk 534d3c6b40fSJed Brown @echo "MAGMA_DIR = $(MAGMA_DIR)" | tee -a config.mk 535d3c6b40fSJed Brown @echo "XSMM_DIR = $(XSMM_DIR)" | tee -a config.mk 536d3c6b40fSJed Brown @echo "CUDA_DIR = $(CUDA_DIR)" | tee -a config.mk 537d3c6b40fSJed Brown @echo "MFEM_DIR = $(MFEM_DIR)" | tee -a config.mk 538d3c6b40fSJed Brown @echo "PETSC_DIR = $(PETSC_DIR)" | tee -a config.mk 539d3c6b40fSJed Brown @echo "NEK5K_DIR = $(NEK5K_DIR)" | tee -a config.mk 540d3c6b40fSJed Brown @echo "Configuration cached in config.mk" 541d3c6b40fSJed Brown 542d3c6b40fSJed Brown.PHONY : configure 543d3c6b40fSJed Brown 544d1f7f8d3SJed Brown-include $(libceed.c:%.c=$(OBJDIR)/%.d) $(tests.c:tests/%.c=$(OBJDIR)/%.d) 545