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 17dc753d40SJed Brownifeq (,$(filter-out undefined default,$(origin CC))) 186ed738d9SJed Brown CC = gcc 19dc753d40SJed Brownendif 20dc753d40SJed Brownifeq (,$(filter-out undefined default,$(origin FC))) 2181c9eb91SStan Tomov FC = gfortran 22dc753d40SJed Brownendif 237692a9b0SVeselin DobrevNVCC = $(CUDA_DIR)/bin/nvcc 24e86995feScamierjs 253b56482dScamierjs# ASAN must be left empty if you don't want to use it 260a7eccc5ScamierjsASAN ?= 276850bcb5Scamierjs 28e86995feScamierjsLDFLAGS ?= 2932d74c32SThilina RathnayakeUNDERSCORE ?= 1 301b58aefaScamierjs 31f9fa8c39Sjeremylt# MFEM_DIR env variable should point to sibling directory 32bf3e26f6SVeselin Dobrevifneq ($(wildcard ../mfem/libmfem.*),) 339ba53df8Sjeremylt MFEM_DIR ?= ../mfem 34f9fa8c39Sjeremyltendif 35f9fa8c39Sjeremylt 364d1cd9fcSJeremy L Thompson# NEK5K_DIR env variable should point to sibling directory 374d1cd9fcSJeremy L Thompsonifneq ($(wildcard ../Nek5000/*),) 384d1cd9fcSJeremy L Thompson NEK5K_DIR ?= ../Nek5000 394d1cd9fcSJeremy L Thompsonendif 404d1cd9fcSJeremy L Thompson 418d713cf6Sjeremylt# XSMM_DIR env variable should point to XSMM master (github.com/hfp/libxsmm) 428d713cf6SjeremyltXSMM_DIR ?= ../libxsmm 438d713cf6Sjeremylt 4412123fd5Scamierjs# OCCA_DIR env variable should point to OCCA master (github.com/libocca/occa) 457f5ff99bSVeselin DobrevOCCA_DIR ?= ../occa 46f797d7b2Scamierjs 475a9ca9adSVeselin Dobrev# env variable MAGMA_DIR can be used too 485a9ca9adSVeselin DobrevMAGMA_DIR ?= ../magma 495a9ca9adSVeselin Dobrev# If CUDA_DIR is not set, check for nvcc, or resort to /usr/local/cuda 505a9ca9adSVeselin DobrevCUDA_DIR ?= $(or $(patsubst %/,%,$(dir $(patsubst %/,%,$(dir \ 515a9ca9adSVeselin Dobrev $(shell which nvcc 2> /dev/null))))),/usr/local/cuda) 5282b77998SStan Tomov 532f4d9adbSJeremy L Thompson# Check for PETSc in ../petsc 542f4d9adbSJeremy L Thompsonifneq ($(wildcard ../petsc/lib/libpetsc.*),) 552f4d9adbSJeremy L Thompson PETSC_DIR ?= ../petsc 562f4d9adbSJeremy L Thompsonendif 572f4d9adbSJeremy L Thompson 58bf000209STzanio# Warning: SANTIZ options still don't run with /gpu/occa 5912123fd5Scamierjs# export LSAN_OPTIONS=suppressions=.asanignore 60c12ddcb5ScamierjsAFLAGS = -fsanitize=address #-fsanitize=undefined -fno-omit-frame-pointer 6132d74c32SThilina Rathnayake 622774d5cbSJeremy L ThompsonOPT = -O -g -march=native -ffp-contract=fast -fopenmp-simd 63323c739cSJed BrownCFLAGS = -std=c99 $(OPT) -Wall -Wextra -Wno-unused-parameter -fPIC -MMD -MP 649f0427d9SYohannNVCCFLAGS = -Xcompiler "$(OPT)" -Xcompiler -fPIC 651dc2661bSVeselin Dobrev# If using the IBM XL Fortran (xlf) replace FFLAGS appropriately: 661dc2661bSVeselin Dobrevifneq ($(filter %xlf %xlf_r,$(FC)),) 6710da579bSJeremy L Thompson FFLAGS = $(OPT) -ffree-form -qpreprocess -qextname -qpic -MMD 68323c739cSJed Brownelse # gfortran/Intel-style options 698980d4a7Sjeremylt FFLAGS = -cpp $(OPT) -Wall -Wextra -Wno-unused-parameter -Wno-unused-dummy-argument -fPIC -MMD -MP 701dc2661bSVeselin Dobrevendif 711b58aefaScamierjs 7232d74c32SThilina Rathnayakeifeq ($(UNDERSCORE), 1) 7332d74c32SThilina Rathnayake CFLAGS += -DUNDERSCORE 7432d74c32SThilina Rathnayakeendif 7532d74c32SThilina Rathnayake 76a6f4783aSJed Brownifeq ($(COVERAGE), 1) 77a6f4783aSJed Brown CFLAGS += --coverage 78a6f4783aSJed Brown LDFLAGS += --coverage 79a6f4783aSJed Brownendif 80a6f4783aSJed Brown 814dd6f121ScamierjsCFLAGS += $(if $(ASAN),$(AFLAGS)) 824dd6f121ScamierjsFFLAGS += $(if $(ASAN),$(AFLAGS)) 834dd6f121ScamierjsLDFLAGS += $(if $(ASAN),$(AFLAGS)) 846ea7c6c1SJed BrownCPPFLAGS = -I./include 85582447c9SJed BrownLDLIBS = -lm 8691b7489eSJed BrownOBJDIR := build 876ea7c6c1SJed BrownLIBDIR := lib 886ea7c6c1SJed Brown 89d5217624SJed Brown# Installation variables 90d5217624SJed Brownprefix ?= /usr/local 91d5217624SJed Brownbindir = $(prefix)/bin 92d5217624SJed Brownlibdir = $(prefix)/lib 93bf3e26f6SVeselin Dobrevokldir = $(libdir)/okl 94d5217624SJed Brownincludedir = $(prefix)/include 95d5217624SJed Brownpkgconfigdir = $(libdir)/pkgconfig 96d5217624SJed BrownINSTALL = install 97d5217624SJed BrownINSTALL_PROGRAM = $(INSTALL) 98d5217624SJed BrownINSTALL_DATA = $(INSTALL) -m644 99d5217624SJed Brown 1003b56482dScamierjs# Get number of processors of the machine 10169762e1fScamierjsNPROCS := $(shell getconf _NPROCESSORS_ONLN) 1023b56482dScamierjs# prepare make options to run in parallel 10382985883ScamierjsMFLAGS := -j $(NPROCS) --warn-undefined-variables \ 10421ae6867Scamierjs --no-print-directory --no-keep-going 10587e762eaSJed Brown 1068ec9d54bSJed BrownPYTHON ?= python3 107bfa078e6SJed BrownPROVE ?= prove 1083a1ec3cdSJed BrownPROVE_OPTS ?= -j $(NPROCS) 1095c719ab0SJed BrownDARWIN := $(filter Darwin,$(shell uname -s)) 1105c719ab0SJed BrownSO_EXT := $(if $(DARWIN),dylib,so) 1119df38c42SVeselin Dobrev 1126ea7c6c1SJed Brownceed.pc := $(LIBDIR)/pkgconfig/ceed.pc 11391b7489eSJed Brownlibceed := $(LIBDIR)/libceed.$(SO_EXT) 1147e68d260SJed BrownCEED_LIBS = -lceed 115d7b241e6Sjeremyltlibceed.c := $(wildcard interface/ceed*.c) 116265be9c8Sjeremyltlibceed_test := $(LIBDIR)/libceed_test.$(SO_EXT) 11776af460cSJed Brownlibceeds = $(libceed) $(libceed_test) 118265be9c8SjeremyltBACKENDS_BUILTIN := /cpu/self/ref/serial /cpu/self/ref/blocked /cpu/self/opt/serial /cpu/self/opt/blocked 119d20f937dSJed BrownBACKENDS := $(BACKENDS_BUILTIN) 120bf000209STzanio 121bf000209STzanio# Tests 12257c64913Sjeremylttests.c := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.c)) 1238980d4a7Sjeremylttests.f := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.f90)) 12491b7489eSJed Browntests := $(tests.c:tests/%.c=$(OBJDIR)/%) 1253f3e7340Scamierjsctests := $(tests) 1268980d4a7Sjeremylttests += $(tests.f:tests/%.f90=$(OBJDIR)/%) 12732d74c32SThilina Rathnayake#examples 128182fbe45STzanioexamples.c := $(sort $(wildcard examples/ceed/*.c)) 129182fbe45STzanioexamples.f := $(sort $(wildcard examples/ceed/*.f)) 130182fbe45STzanioexamples := $(examples.c:examples/ceed/%.c=$(OBJDIR)/%) 131182fbe45STzanioexamples += $(examples.f:examples/ceed/%.f=$(OBJDIR)/%) 1322158b1b0Sjeremylt#mfemexamples 1332158b1b0Sjeremyltmfemexamples.cpp := $(sort $(wildcard examples/mfem/*.cpp)) 13416c6c054SJed Brownmfemexamples := $(mfemexamples.cpp:examples/mfem/%.cpp=$(OBJDIR)/mfem-%) 1354d1cd9fcSJeremy L Thompson#nekexamples 1364d1cd9fcSJeremy L Thompsonnekexamples.usr := $(sort $(wildcard examples/nek5000/*.usr)) 137686de4acSJed Brownnekexamples := $(nekexamples.usr:examples/nek5000/%.usr=$(OBJDIR)/nek-%) 1384d1cd9fcSJeremy L Thompson#petscexamples 139e797ab98SJed Brownpetscexamples.c := $(sort $(wildcard examples/petsc/*.c)) 140e797ab98SJed Brownpetscexamples := $(petscexamples.c:examples/petsc/%.c=$(OBJDIR)/petsc-%) 1412774d5cbSJeremy L Thompson#navierstokesexample 1422774d5cbSJeremy L Thompsonnavierstokesexample.c := $(sort $(wildcard examples/navier-stokes/*.c)) 1432774d5cbSJeremy L Thompsonnavierstokesexample := $(navierstokesexample.c:examples/navier-stokes/%.c=$(OBJDIR)/navier-stokes-%) 144e797ab98SJed Brown 14589c6efa4Sjeremylt# backends/[ref, blocked, template, memcheck, opt, avx, occa, magma] 146ae3cba82Scamierjsref.c := $(sort $(wildcard backends/ref/*.c)) 14789c6efa4Sjeremyltblocked.c := $(sort $(wildcard backends/blocked/*.c)) 148a718229cSjeremylttemplate.c := $(sort $(wildcard backends/template/*.c)) 14989c6efa4Sjeremyltceedmemcheck.c := $(sort $(wildcard backends/memcheck/*.c)) 15089c6efa4Sjeremyltopt.c := $(sort $(wildcard backends/opt/*.c)) 15189c6efa4Sjeremyltavx.c := $(sort $(wildcard backends/avx/*.c)) 15289c6efa4Sjeremyltxsmm.c := $(sort $(wildcard backends/xsmm/*.c)) 1539f0427d9SYohanncuda.c := $(sort $(wildcard backends/cuda/*.c)) 1549f0427d9SYohanncuda.cu := $(sort $(wildcard backends/cuda/*.cu)) 15555ae60f9SYohanncuda-reg.c := $(sort $(wildcard backends/cuda-reg/*.c)) 15655ae60f9SYohanncuda-reg.cu := $(sort $(wildcard backends/cuda-reg/*.cu)) 157c532df63SYohanncuda-shared.c := $(sort $(wildcard backends/cuda-shared/*.c)) 158c532df63SYohanncuda-shared.cu := $(sort $(wildcard backends/cuda-shared/*.cu)) 159ae3cba82Scamierjsocca.c := $(sort $(wildcard backends/occa/*.c)) 160755585ceSStan Tomovmagma_preprocessor := python backends/magma/gccm.py 161c4acb06bSStan Tomovmagma_pre_src := $(filter-out %_tmp.c, $(wildcard backends/magma/ceed-*.c)) 162c4acb06bSStan Tomovmagma_dsrc := $(wildcard backends/magma/magma_d*.c) 163c4acb06bSStan Tomovmagma_tmp.c := $(magma_pre_src:%.c=%_tmp.c) 164c4acb06bSStan Tomovmagma_tmp.cu := $(magma_pre_src:%.c=%_cuda.cu) 165c4acb06bSStan Tomovmagma_allsrc.c := $(magma_dsrc) $(magma_tmp.c) 166c4acb06bSStan Tomovmagma_allsrc.cu:= $(magma_tmp.cu) 16782985883Scamierjs 1689bdc3d68Scamierjs# Output using the 216-color rules mode 16918a724fcScamierjsrule_file = $(notdir $(1)) 17018a724fcScamierjsrule_path = $(patsubst %/,%,$(dir $(1))) 17118a724fcScamierjslast_path = $(notdir $(patsubst %/,%,$(dir $(1)))) 1723c5d0cdfSJed Brownansicolor = $(shell echo $(call last_path,$(1)) | cksum | cut -b1-2 | xargs -IS expr 2 \* S + 17) 173abb87f81Scamierjsemacs_out = @printf " %10s %s/%s\n" $(1) $(call rule_path,$(2)) $(call rule_file,$(2)) 174abb87f81Scamierjscolor_out = @if [ -t 1 ]; then \ 17518a724fcScamierjs printf " %10s \033[38;5;%d;1m%s\033[m/%s\n" \ 1763c5d0cdfSJed Brown $(1) $(call ansicolor,$(2)) \ 17718a724fcScamierjs $(call rule_path,$(2)) $(call rule_file,$(2)); else \ 17818a724fcScamierjs printf " %10s %s\n" $(1) $(2); fi 179f797d7b2Scamierjs# if TERM=dumb, use it, otherwise switch to the term one 180abb87f81Scamierjsoutput = $(if $(TERM:dumb=),$(call color_out,$1,$2),$(call emacs_out,$1,$2)) 18182985883Scamierjs 1829bdc3d68Scamierjs# if V is set to non-nil, turn the verbose mode 18318a724fcScamierjsquiet = $(if $(V),$($(1)),$(call output,$1,$@);$($(1))) 18421ae6867Scamierjs 185da72e7fcSJed Brown# Cancel built-in and old-fashioned implicit rules which we don't use 1869df38c42SVeselin Dobrev.SUFFIXES: 187da72e7fcSJed Brown 18891b7489eSJed Brown.SECONDEXPANSION: # to expand $$(@D)/.DIR 1899df38c42SVeselin Dobrev 190c4acb06bSStan Tomov.SECONDARY: $(magma_tmp.c) $(magma_tmp.cu) 19114c1ded1SStan Tomov 19291b7489eSJed Brown%/.DIR : 19391b7489eSJed Brown @mkdir -p $(@D) 19491b7489eSJed Brown @touch $@ 19591b7489eSJed Brown 19691b7489eSJed Brown.PRECIOUS: %/.DIR 19791b7489eSJed Brown 19823072ed2SVeselin Dobrevlib: $(libceed) $(ceed.pc) 19923072ed2SVeselin Dobrev# run 'lib' target in parallel 2002f4d9adbSJeremy L Thompsonpar:;@$(MAKE) $(MFLAGS) V=$(V) lib 201d20f937dSJed Brownbackend_status = $(if $(filter $1,$(BACKENDS)), [backends: $1], [not found]) 202bf3e26f6SVeselin Dobrevinfo: 203bf3e26f6SVeselin Dobrev $(info ------------------------------------) 204bf3e26f6SVeselin Dobrev $(info CC = $(CC)) 205bf3e26f6SVeselin Dobrev $(info FC = $(FC)) 206bf3e26f6SVeselin Dobrev $(info CPPFLAGS = $(CPPFLAGS)) 207bf3e26f6SVeselin Dobrev $(info CFLAGS = $(value CFLAGS)) 208bf3e26f6SVeselin Dobrev $(info FFLAGS = $(value FFLAGS)) 209bf3e26f6SVeselin Dobrev $(info NVCCFLAGS = $(value NVCCFLAGS)) 210bf3e26f6SVeselin Dobrev $(info LDFLAGS = $(value LDFLAGS)) 211bf3e26f6SVeselin Dobrev $(info LDLIBS = $(LDLIBS)) 212bf3e26f6SVeselin Dobrev $(info OPT = $(OPT)) 213bf3e26f6SVeselin Dobrev $(info AFLAGS = $(AFLAGS)) 214bf3e26f6SVeselin Dobrev $(info ASAN = $(or $(ASAN),(empty))) 215bf3e26f6SVeselin Dobrev $(info V = $(or $(V),(empty)) [verbose=$(if $(V),on,off)]) 216bf3e26f6SVeselin Dobrev $(info ------------------------------------) 217bdc3149dSjeremylt $(info MEMCHK_STATUS = $(MEMCHK_STATUS)$(call backend_status,/cpu/self/ref/memcheck)) 21884a01de5SJeremy L Thompson $(info AVX_STATUS = $(AVX_STATUS)$(call backend_status,/cpu/self/avx/serial /cpu/self/avx/blocked)) 21984a01de5SJeremy L Thompson $(info XSMM_DIR = $(XSMM_DIR)$(call backend_status,/cpu/self/xsmm/serial /cpu/self/xsmm/blocked)) 220d20f937dSJed Brown $(info OCCA_DIR = $(OCCA_DIR)$(call backend_status,/cpu/occa /gpu/occa /omp/occa)) 221d20f937dSJed Brown $(info MAGMA_DIR = $(MAGMA_DIR)$(call backend_status,/gpu/magma)) 222ab9cabdeSVeselin Dobrev $(info CUDA_DIR = $(CUDA_DIR)$(call backend_status,$(CUDA_BACKENDS))) 223bf3e26f6SVeselin Dobrev $(info ------------------------------------) 224bf3e26f6SVeselin Dobrev $(info MFEM_DIR = $(MFEM_DIR)) 2254d1cd9fcSJeremy L Thompson $(info NEK5K_DIR = $(NEK5K_DIR)) 226bf3e26f6SVeselin Dobrev $(info PETSC_DIR = $(PETSC_DIR)) 227bf3e26f6SVeselin Dobrev $(info ------------------------------------) 228bf3e26f6SVeselin Dobrev $(info prefix = $(prefix)) 229bf3e26f6SVeselin Dobrev $(info includedir = $(value includedir)) 230bf3e26f6SVeselin Dobrev $(info libdir = $(value libdir)) 231bf3e26f6SVeselin Dobrev $(info okldir = $(value okldir)) 232bf3e26f6SVeselin Dobrev $(info pkgconfigdir = $(value pkgconfigdir)) 233bf3e26f6SVeselin Dobrev $(info ------------------------------------) 234bf3e26f6SVeselin Dobrev @true 23523072ed2SVeselin Dobrevinfo-backends: 236d20f937dSJed Brown $(info make: 'lib' with optional backends: $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS))) 2372f4d9adbSJeremy L Thompson.PHONY: lib all par info info-backends 2380e439e50SJed Brown 23924d002f4SJed Brown$(libceed) : LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed))) 24076af460cSJed Brown$(libceed_test) : LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed_test))) 24169762e1fScamierjs 24248fffa06Sjeremylt# Standard Backends 24387174f08SJed Brownlibceed.c += $(ref.c) 2444a2e7687Sjeremyltlibceed.c += $(blocked.c) 24589c6efa4Sjeremyltlibceed.c += $(opt.c) 24623072ed2SVeselin Dobrev 247265be9c8Sjeremylt# Testing Backends 248265be9c8Sjeremylttest_backends.c := $(template.c) 249265be9c8SjeremyltTEST_BACKENDS := /cpu/self/tmpl /cpu/self/tmpl/sub 250265be9c8Sjeremylt 251fc7cf9a0Sjeremylt# Memcheck Backend 252bdc3149dSjeremyltMEMCHK_STATUS = Disabled 253b8fb44e7SJed BrownMEMCHK := $(shell echo "\#include <valgrind/memcheck.h>" | $(CC) $(CPPFLAGS) -E - >/dev/null 2>&1 && echo 1) 254bdc3149dSjeremyltifeq ($(MEMCHK),1) 255bdc3149dSjeremylt MEMCHK_STATUS = Enabled 256fc7cf9a0Sjeremylt libceed.c += $(ceedmemcheck.c) 257fc7cf9a0Sjeremylt BACKENDS += /cpu/self/ref/memcheck 258fc7cf9a0Sjeremyltendif 259fc7cf9a0Sjeremylt 26048fffa06Sjeremylt# AVX Backed 26148fffa06SjeremyltAVX_STATUS = Disabled 2625efe2378SjeremyltAVX := $(shell $(CC) $(OPT) -v -E - < /dev/null 2>&1 | grep -c avx) 26348fffa06Sjeremyltifeq ($(AVX),1) 26448fffa06Sjeremylt AVX_STATUS = Enabled 26548fffa06Sjeremylt libceed.c += $(avx.c) 26684a01de5SJeremy L Thompson BACKENDS += /cpu/self/avx/serial /cpu/self/avx/blocked 26748fffa06Sjeremyltendif 26848fffa06Sjeremylt 2698d713cf6Sjeremylt# libXSMM Backends 2708d713cf6Sjeremyltifneq ($(wildcard $(XSMM_DIR)/lib/libxsmm.*),) 27176af460cSJed Brown $(libceeds) : LDFLAGS += -L$(XSMM_DIR)/lib -Wl,-rpath,$(abspath $(XSMM_DIR)/lib) 27276af460cSJed Brown $(libceeds) : LDLIBS += -lxsmm -ldl 273724a7164Sjeremylt MKL ?= 0 274724a7164Sjeremylt ifneq (0,$(MKL)) 27576af460cSJed Brown $(libceeds) : LDLIBS += -mkl 276724a7164Sjeremylt else 27776af460cSJed Brown $(libceeds) : LDLIBS += -lblas 278724a7164Sjeremylt endif 2798d713cf6Sjeremylt libceed.c += $(xsmm.c) 280683faae0SJed Brown $(xsmm.c:%.c=$(OBJDIR)/%.o) $(xsmm.c:%=%.tidy) : CPPFLAGS += -I$(XSMM_DIR)/include 2818d713cf6Sjeremylt BACKENDS += /cpu/self/xsmm/serial /cpu/self/xsmm/blocked 2828d713cf6Sjeremyltendif 2838d713cf6Sjeremylt 28448fffa06Sjeremylt# OCCA Backends 2857f5ff99bSVeselin Dobrevifneq ($(wildcard $(OCCA_DIR)/lib/libocca.*),) 28676af460cSJed Brown $(libceeds) : LDFLAGS += -L$(OCCA_DIR)/lib -Wl,-rpath,$(abspath $(OCCA_DIR)/lib) 28776af460cSJed Brown $(libceeds) : LDLIBS += -locca 28887174f08SJed Brown libceed.c += $(occa.c) 289683faae0SJed Brown $(occa.c:%.c=$(OBJDIR)/%.o) $(occa.c:%=%.tidy) : CPPFLAGS += -I$(OCCA_DIR)/include 290a953af89SJed Brown BACKENDS += /cpu/occa /gpu/occa /omp/occa 29121ae6867Scamierjsendif 29223072ed2SVeselin Dobrev 2939f0427d9SYohann# Cuda Backend 2945a9ca9adSVeselin DobrevCUDA_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(CUDA_DIR)/$d/libcudart.${SO_EXT})) 2955a9ca9adSVeselin DobrevCUDA_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(CUDA_LIB_DIR)))) 296c532df63SYohannCUDA_BACKENDS = /gpu/cuda/ref /gpu/cuda/reg /gpu/cuda/shared 2975a9ca9adSVeselin Dobrevifneq ($(CUDA_LIB_DIR),) 29876af460cSJed Brown $(libceeds) : CFLAGS += -I$(CUDA_DIR)/include 29976af460cSJed Brown $(libceeds) : LDFLAGS += -L$(CUDA_LIB_DIR) -Wl,-rpath,$(abspath $(CUDA_LIB_DIR)) 30076af460cSJed Brown $(libceeds) : LDLIBS += -lcudart -lnvrtc -lcuda 301c532df63SYohann libceed.c += $(cuda.c) $(cuda-reg.c) $(cuda-shared.c) 302c532df63SYohann libceed.cu += $(cuda.cu) $(cuda-reg.cu) $(cuda-shared.cu) 303ab9cabdeSVeselin Dobrev BACKENDS += $(CUDA_BACKENDS) 3049f0427d9SYohannendif 3059f0427d9SYohann 3069f0427d9SYohann# MAGMA Backend 3079f0427d9SYohannifneq ($(wildcard $(MAGMA_DIR)/lib/libmagma.*),) 3089f0427d9SYohann ifneq ($(CUDA_LIB_DIR),) 3091dc2661bSVeselin Dobrev cuda_link = -Wl,-rpath,$(CUDA_LIB_DIR) -L$(CUDA_LIB_DIR) -lcublas -lcusparse -lcudart 3101dc2661bSVeselin Dobrev omp_link = -fopenmp 3111dc2661bSVeselin Dobrev magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(cuda_link) $(omp_link) 3127692a9b0SVeselin Dobrev magma_link_shared = -L$(MAGMA_DIR)/lib -Wl,-rpath,$(abspath $(MAGMA_DIR)/lib) -lmagma 3137692a9b0SVeselin Dobrev magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static)) 31476af460cSJed Brown $(libceeds) : LDLIBS += $(magma_link) 3157692a9b0SVeselin Dobrev $(tests) $(examples) : LDLIBS += $(magma_link) 316c4acb06bSStan Tomov libceed.c += $(magma_allsrc.c) 317c4acb06bSStan Tomov libceed.cu += $(magma_allsrc.cu) 318683faae0SJed Brown $(magma_allsrc.c:%.c=$(OBJDIR)/%.o) $(magma_allsrc.c:%=%.tidy) : CPPFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include 319c4acb06bSStan 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 320ce41f623SJed Brown BACKENDS += /gpu/magma 32182b77998SStan Tomov endif 3225a9ca9adSVeselin Dobrevendif 323755585ceSStan Tomov 324ce41f623SJed Brownexport BACKENDS 325ce41f623SJed Brown 326755585ceSStan Tomov# generate magma_tmp.c and magma_cuda.cu from magma.c 32729715310SJed Brown%_tmp.c %_cuda.cu : %.c 328755585ceSStan Tomov $(magma_preprocessor) $< 329755585ceSStan Tomov 33023072ed2SVeselin Dobrevlibceed.o = $(libceed.c:%.c=$(OBJDIR)/%.o) $(libceed.cu:%.cu=$(OBJDIR)/%.o) 33123072ed2SVeselin Dobrev$(libceed.o): | info-backends 33223072ed2SVeselin Dobrev$(libceed) : $(libceed.o) | $$(@D)/.DIR 33321ae6867Scamierjs $(call quiet,CC) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS) 33491b7489eSJed Brown 33558e8d3b7SJed Brown$(OBJDIR)/%.o : $(CURDIR)/%.c | $$(@D)/.DIR 336b5b03409SJed Brown $(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<) 337ae3cba82Scamierjs 33858e8d3b7SJed Brown$(OBJDIR)/%.o : $(CURDIR)/%.cu | $$(@D)/.DIR 339755585ceSStan Tomov $(call quiet,NVCC) $(CPPFLAGS) $(NVCCFLAGS) -c -o $@ $(abspath $<) 340755585ceSStan Tomov 341b5b03409SJed Brown$(OBJDIR)/% : tests/%.c | $$(@D)/.DIR 342265be9c8Sjeremylt $(call quiet,LINK.c) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 34378b5556aScamierjs 3448980d4a7Sjeremylt$(OBJDIR)/% : tests/%.f90 | $$(@D)/.DIR 345265be9c8Sjeremylt $(call quiet,LINK.F) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 34632d74c32SThilina Rathnayake 347182fbe45STzanio$(OBJDIR)/% : examples/ceed/%.c | $$(@D)/.DIR 348265be9c8Sjeremylt $(call quiet,LINK.c) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 34991b7489eSJed Brown 350182fbe45STzanio$(OBJDIR)/% : examples/ceed/%.f | $$(@D)/.DIR 351265be9c8Sjeremylt $(call quiet,LINK.F) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 352673d494eSThilina Rathnayake 35316c6c054SJed Brown$(OBJDIR)/mfem-% : examples/mfem/%.cpp $(libceed) | $$(@D)/.DIR 354c4216f28SJed Brown +$(MAKE) -C examples/mfem CEED_DIR=`pwd` \ 3552f4d9adbSJeremy L Thompson MFEM_DIR="$(abspath $(MFEM_DIR))" $* 35616c6c054SJed Brown mv examples/mfem/$* $@ 35716c6c054SJed Brown 3587f6cf205SJed Brown$(OBJDIR)/petsc-% : examples/petsc/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR 359c4216f28SJed Brown +$(MAKE) -C examples/petsc CEED_DIR=`pwd` \ 3602f4d9adbSJeremy L Thompson PETSC_DIR="$(abspath $(PETSC_DIR))" $* 361e797ab98SJed Brown mv examples/petsc/$* $@ 362e797ab98SJed Brown 3632774d5cbSJeremy L Thompson$(OBJDIR)/navier-stokes-% : examples/navier-stokes/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR 364c4216f28SJed Brown +$(MAKE) -C examples/navier-stokes CEED_DIR=`pwd` \ 3652774d5cbSJeremy L Thompson PETSC_DIR="$(abspath $(PETSC_DIR))" $* 3662774d5cbSJeremy L Thompson mv examples/navier-stokes/$* $@ 3672774d5cbSJeremy L Thompson 368567e4d0aSJed Brownlibceed_test.o = $(test_backends.c:%.c=$(OBJDIR)/%.o) 36976af460cSJed Brown$(libceed_test) : $(libceed.o) $(libceed_test.o) | $$(@D)/.DIR 370265be9c8Sjeremylt $(call quiet,CC) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS) 371265be9c8Sjeremylt 372265be9c8Sjeremylt$(examples) : $(libceed) 37376af460cSJed Brown$(tests) : $(libceed_test) 37476af460cSJed Brown$(tests) : CEED_LIBS = -lceed_test 375fc377ca6SJed Brown$(tests) $(examples) : LDFLAGS += -Wl,-rpath,$(abspath $(LIBDIR)) -L$(LIBDIR) 3764859b599SJed Brown 377686de4acSJed Brownrun-t% : BACKENDS += $(TEST_BACKENDS) 378dad465e7SJed Brownrun-% : $(OBJDIR)/% 379d1f7f8d3SJed Brown @tests/tap.sh $(<:$(OBJDIR)/%=%) 380686de4acSJed Brown 381686de4acSJed Brownexternal_examples := \ 382686de4acSJed Brown $(if $(MFEM_DIR),$(mfemexamples)) \ 383686de4acSJed Brown $(if $(PETSC_DIR),$(petscexamples)) \ 384686de4acSJed Brown $(if $(NEK5K_DIR),$(nekexamples)) 385686de4acSJed Brown 386686de4acSJed Brownallexamples = $(examples) $(external_examples) 387686de4acSJed Brown 388686de4acSJed Brown# The test and prove targets can be controlled via pattern searches. The 389686de4acSJed Brown# default is to run tests and those examples that have no external dependencies. 390686de4acSJed Brown# Examples of finer grained control: 391686de4acSJed Brown# 392686de4acSJed Brown# make test search='petsc mfem' # PETSc and MFEM examples 393686de4acSJed Brown# make prove search='t3' # t3xx series tests 394686de4acSJed Brown# make junit search='ex petsc' # core ex* and PETSc tests 395686de4acSJed Brownsearch ?= t ex 396686de4acSJed Brownrealsearch = $(search:%=%%) 397686de4acSJed Brownmatched = $(foreach pattern,$(realsearch),$(filter $(OBJDIR)/$(pattern),$(tests) $(allexamples))) 398686de4acSJed Brown# Work around Nek examples not having normal targets 399686de4acSJed Brownmatched_prereq = $(filter-out $(OBJDIR)/nek%,$(matched)) $(if $(findstring nek,$(matched)),prepnektests) 400686de4acSJed Brown 4012158b1b0Sjeremylt# Test core libCEED 402686de4acSJed Browntest : $(matched:$(OBJDIR)/%=run-%) 4032158b1b0Sjeremylt 4043b56482dScamierjs# run test target in parallel 4056850bcb5Scamierjstst : ;@$(MAKE) $(MFLAGS) V=$(V) test 4063b56482dScamierjs# CPU C tests only for backend % 4073f3e7340Scamierjsctc-% : $(ctests);@$(foreach tst,$(ctests),$(tst) /cpu/$*;) 4084859b599SJed Brown 409686de4acSJed Brownprove : BACKENDS += $(TEST_BACKENDS) 410686de4acSJed Brownprove : $(matched_prereq) 411a5dc8077SJed Brown $(info Testing backends: $(BACKENDS)) 412686de4acSJed Brown $(PROVE) $(PROVE_OPTS) --exec 'tests/tap.sh' $(matched:$(OBJDIR)/%=%) 4133b56482dScamierjs# run prove target in parallel 4146850bcb5Scamierjsprv : ;@$(MAKE) $(MFLAGS) V=$(V) prove 415bfa078e6SJed Brown 4164d1cd9fcSJeremy L Thompsonprepnektests: 4174d1cd9fcSJeremy L Thompson (export CC FC && cd examples && make prepnektests) 4182158b1b0Sjeremylt 419686de4acSJed Brownprove-all : 420686de4acSJed Brown +$(MAKE) prove realsearch=% 421686de4acSJed Brown 422686de4acSJed Brownjunit-t% : BACKENDS += $(TEST_BACKENDS) 4238ec9d54bSJed Brownjunit-% : $(OBJDIR)/% 424bdb0bdbbSJed Brown @printf " %10s %s\n" TEST $(<:$(OBJDIR)/%=%); $(PYTHON) tests/junit.py $(<:$(OBJDIR)/%=%) 4258ec9d54bSJed Brown 4268ec9d54bSJed Brownjunit : $(alltests:$(OBJDIR)/%=junit-%) 4278ec9d54bSJed Brown 4282f4d9adbSJeremy L Thompsonall: $(alltests) 4292f4d9adbSJeremy L Thompson 4302f4d9adbSJeremy L Thompsonexamples : $(allexamples) 4312f4d9adbSJeremy L Thompson 4322f4d9adbSJeremy L Thompson# Benchmarks 433*0c59ef15SJeremy L Thompsonallbenchmarks = petsc-bps 4344e79ff5bSVeselin Dobrevbench_targets = $(addprefix bench-,$(allbenchmarks)) 4354e79ff5bSVeselin Dobrev.PHONY: $(bench_targets) benchmarks 4364e79ff5bSVeselin Dobrev$(bench_targets): bench-%: $(OBJDIR)/% 4372f4d9adbSJeremy L Thompson cd benchmarks && ./benchmark.sh --ceed "$(BACKENDS)" -r $(*).sh 4384e79ff5bSVeselin Dobrevbenchmarks: $(bench_targets) 4392c6ea02fSJed Brown 4406ea7c6c1SJed Brown$(ceed.pc) : pkgconfig-prefix = $(abspath .) 441d5217624SJed Brown$(OBJDIR)/ceed.pc : pkgconfig-prefix = $(prefix) 442d5217624SJed Brown.INTERMEDIATE : $(OBJDIR)/ceed.pc 4436ea7c6c1SJed Brown%/ceed.pc : ceed.pc.template | $$(@D)/.DIR 4446ea7c6c1SJed Brown @sed "s:%prefix%:$(pkgconfig-prefix):" $< > $@ 4450e439e50SJed Brown 446bf3e26f6SVeselin DobrevOCCA := $(OCCA_DIR)/bin/occa 447cc6ff0d7SJed BrownOKL_KERNELS := $(wildcard backends/occa/*.okl) 448cc6ff0d7SJed Brown 449cc6ff0d7SJed Brownokl-cache : 450cc6ff0d7SJed Brown $(OCCA) cache ceed $(OKL_KERNELS) 451cc6ff0d7SJed Brown 452cc6ff0d7SJed Brownokl-clear: 453cc6ff0d7SJed Brown $(OCCA) clear -y -l ceed 454a5ba6ca9Scamierjs 455d5217624SJed Browninstall : $(libceed) $(OBJDIR)/ceed.pc 456bf3e26f6SVeselin Dobrev $(INSTALL) -d $(addprefix $(if $(DESTDIR),"$(DESTDIR)"),"$(includedir)"\ 457bf3e26f6SVeselin Dobrev "$(libdir)" "$(pkgconfigdir)" $(if $(OCCA_ON),"$(okldir)")) 4581e25a746SJed Brown $(INSTALL_DATA) include/ceed.h "$(DESTDIR)$(includedir)/" 459f91e0974SThilina Rathnayake $(INSTALL_DATA) include/ceedf.h "$(DESTDIR)$(includedir)/" 4601e25a746SJed Brown $(INSTALL_DATA) $(libceed) "$(DESTDIR)$(libdir)/" 4611e25a746SJed Brown $(INSTALL_DATA) $(OBJDIR)/ceed.pc "$(DESTDIR)$(pkgconfigdir)/" 462bf3e26f6SVeselin Dobrev $(if $(OCCA_ON),$(INSTALL_DATA) $(OKL_KERNELS) "$(DESTDIR)$(okldir)/") 463d5217624SJed Brown 464683faae0SJed 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 465d635b4c6Scamierjs 4666e5d1fd9Scamierjscln clean : 467df0ef7e4SVeselin Dobrev $(RM) -r $(OBJDIR) $(LIBDIR) 4682774d5cbSJeremy L Thompson $(MAKE) -C examples clean 469c4acb06bSStan Tomov $(RM) $(magma_tmp.c) $(magma_tmp.cu) backends/magma/*~ backends/magma/*.o 4702f4d9adbSJeremy L Thompson $(RM) -rf benchmarks/*output.txt 4714859b599SJed Brown 47207838a1cSTzaniodistclean : clean 4738c23e06aSJed Brown $(RM) -r doc/html 47407838a1cSTzanio 4750ab95609SJed Browndoc : 4767bd3a522STzanio doxygen Doxyfile 4777bd3a522STzanio 478f2fa494dScamierjsstyle : 47920b73d85SJed Brown @astyle --options=.astylerc \ 48020b73d85SJed Brown $(filter-out include/ceedf.h tests/t310-basis-f.h, \ 48120b73d85SJed Brown $(wildcard include/*.h interface/*.[ch] tests/*.[ch] backends/*/*.[ch] \ 48220b73d85SJed Brown examples/*/*.[ch] examples/*/*.[ch]pp)) 4830dbfdfc5SJed Brown 484683faae0SJed BrownCLANG_TIDY ?= clang-tidy 485683faae0SJed Brown%.c.tidy : %.c 486683faae0SJed Brown $(CLANG_TIDY) $^ -- $(CPPFLAGS) 487683faae0SJed Brown 488683faae0SJed Browntidy : $(libceed.c:%=%.tidy) 489683faae0SJed Brown 4904859b599SJed Brownprint : 4914859b599SJed Brown @echo $(VAR)=$($(VAR)) 492582447c9SJed Brown 4939df38c42SVeselin Dobrevprint-% : 4949df38c42SVeselin Dobrev $(info [ variable name]: $*) 4959df38c42SVeselin Dobrev $(info [ origin]: $(origin $*)) 4969df38c42SVeselin Dobrev $(info [ value]: $(value $*)) 4979df38c42SVeselin Dobrev $(info [expanded value]: $($*)) 4989df38c42SVeselin Dobrev $(info ) 4999df38c42SVeselin Dobrev @true 5009df38c42SVeselin Dobrev 501d1f7f8d3SJed Brown-include $(libceed.c:%.c=$(OBJDIR)/%.d) $(tests.c:tests/%.c=$(OBJDIR)/%.d) 502