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) 114265be9c8SjeremyltCEED_LIBS := -lceed 115d7b241e6Sjeremyltlibceed.c := $(wildcard interface/ceed*.c) 116265be9c8Sjeremyltlibceed_test := $(LIBDIR)/libceed_test.$(SO_EXT) 117265be9c8SjeremyltBACKENDS_BUILTIN := /cpu/self/ref/serial /cpu/self/ref/blocked /cpu/self/opt/serial /cpu/self/opt/blocked 118d20f937dSJed BrownBACKENDS := $(BACKENDS_BUILTIN) 119bf000209STzanio 120bf000209STzanio# Tests 12157c64913Sjeremylttests.c := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.c)) 1228980d4a7Sjeremylttests.f := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.f90)) 12391b7489eSJed Browntests := $(tests.c:tests/%.c=$(OBJDIR)/%) 1243f3e7340Scamierjsctests := $(tests) 1258980d4a7Sjeremylttests += $(tests.f:tests/%.f90=$(OBJDIR)/%) 12632d74c32SThilina Rathnayake#examples 127182fbe45STzanioexamples.c := $(sort $(wildcard examples/ceed/*.c)) 128182fbe45STzanioexamples.f := $(sort $(wildcard examples/ceed/*.f)) 129182fbe45STzanioexamples := $(examples.c:examples/ceed/%.c=$(OBJDIR)/%) 130182fbe45STzanioexamples += $(examples.f:examples/ceed/%.f=$(OBJDIR)/%) 1312158b1b0Sjeremylt#mfemexamples 1322158b1b0Sjeremyltmfemexamples.cpp := $(sort $(wildcard examples/mfem/*.cpp)) 13316c6c054SJed Brownmfemexamples := $(mfemexamples.cpp:examples/mfem/%.cpp=$(OBJDIR)/mfem-%) 1344d1cd9fcSJeremy L Thompson#nekexamples 1354d1cd9fcSJeremy L Thompsonnekexamples.usr := $(sort $(wildcard examples/nek5000/*.usr)) 136686de4acSJed Brownnekexamples := $(nekexamples.usr:examples/nek5000/%.usr=$(OBJDIR)/nek-%) 1374d1cd9fcSJeremy L Thompson#petscexamples 138e797ab98SJed Brownpetscexamples.c := $(sort $(wildcard examples/petsc/*.c)) 139e797ab98SJed Brownpetscexamples := $(petscexamples.c:examples/petsc/%.c=$(OBJDIR)/petsc-%) 1402774d5cbSJeremy L Thompson#navierstokesexample 1412774d5cbSJeremy L Thompsonnavierstokesexample.c := $(sort $(wildcard examples/navier-stokes/*.c)) 1422774d5cbSJeremy L Thompsonnavierstokesexample := $(navierstokesexample.c:examples/navier-stokes/%.c=$(OBJDIR)/navier-stokes-%) 143e797ab98SJed Brown 14489c6efa4Sjeremylt# backends/[ref, blocked, template, memcheck, opt, avx, occa, magma] 145ae3cba82Scamierjsref.c := $(sort $(wildcard backends/ref/*.c)) 14689c6efa4Sjeremyltblocked.c := $(sort $(wildcard backends/blocked/*.c)) 147a718229cSjeremylttemplate.c := $(sort $(wildcard backends/template/*.c)) 14889c6efa4Sjeremyltceedmemcheck.c := $(sort $(wildcard backends/memcheck/*.c)) 14989c6efa4Sjeremyltopt.c := $(sort $(wildcard backends/opt/*.c)) 15089c6efa4Sjeremyltavx.c := $(sort $(wildcard backends/avx/*.c)) 15189c6efa4Sjeremyltxsmm.c := $(sort $(wildcard backends/xsmm/*.c)) 1529f0427d9SYohanncuda.c := $(sort $(wildcard backends/cuda/*.c)) 1539f0427d9SYohanncuda.cu := $(sort $(wildcard backends/cuda/*.cu)) 15455ae60f9SYohanncuda-reg.c := $(sort $(wildcard backends/cuda-reg/*.c)) 15555ae60f9SYohanncuda-reg.cu := $(sort $(wildcard backends/cuda-reg/*.cu)) 156c532df63SYohanncuda-shared.c := $(sort $(wildcard backends/cuda-shared/*.c)) 157c532df63SYohanncuda-shared.cu := $(sort $(wildcard backends/cuda-shared/*.cu)) 158ae3cba82Scamierjsocca.c := $(sort $(wildcard backends/occa/*.c)) 159755585ceSStan Tomovmagma_preprocessor := python backends/magma/gccm.py 160c4acb06bSStan Tomovmagma_pre_src := $(filter-out %_tmp.c, $(wildcard backends/magma/ceed-*.c)) 161c4acb06bSStan Tomovmagma_dsrc := $(wildcard backends/magma/magma_d*.c) 162c4acb06bSStan Tomovmagma_tmp.c := $(magma_pre_src:%.c=%_tmp.c) 163c4acb06bSStan Tomovmagma_tmp.cu := $(magma_pre_src:%.c=%_cuda.cu) 164c4acb06bSStan Tomovmagma_allsrc.c := $(magma_dsrc) $(magma_tmp.c) 165c4acb06bSStan Tomovmagma_allsrc.cu:= $(magma_tmp.cu) 16682985883Scamierjs 1679bdc3d68Scamierjs# Output using the 216-color rules mode 16818a724fcScamierjsrule_file = $(notdir $(1)) 16918a724fcScamierjsrule_path = $(patsubst %/,%,$(dir $(1))) 17018a724fcScamierjslast_path = $(notdir $(patsubst %/,%,$(dir $(1)))) 1713c5d0cdfSJed Brownansicolor = $(shell echo $(call last_path,$(1)) | cksum | cut -b1-2 | xargs -IS expr 2 \* S + 17) 172abb87f81Scamierjsemacs_out = @printf " %10s %s/%s\n" $(1) $(call rule_path,$(2)) $(call rule_file,$(2)) 173abb87f81Scamierjscolor_out = @if [ -t 1 ]; then \ 17418a724fcScamierjs printf " %10s \033[38;5;%d;1m%s\033[m/%s\n" \ 1753c5d0cdfSJed Brown $(1) $(call ansicolor,$(2)) \ 17618a724fcScamierjs $(call rule_path,$(2)) $(call rule_file,$(2)); else \ 17718a724fcScamierjs printf " %10s %s\n" $(1) $(2); fi 178f797d7b2Scamierjs# if TERM=dumb, use it, otherwise switch to the term one 179abb87f81Scamierjsoutput = $(if $(TERM:dumb=),$(call color_out,$1,$2),$(call emacs_out,$1,$2)) 18082985883Scamierjs 1819bdc3d68Scamierjs# if V is set to non-nil, turn the verbose mode 18218a724fcScamierjsquiet = $(if $(V),$($(1)),$(call output,$1,$@);$($(1))) 18321ae6867Scamierjs 184da72e7fcSJed Brown# Cancel built-in and old-fashioned implicit rules which we don't use 1859df38c42SVeselin Dobrev.SUFFIXES: 186da72e7fcSJed Brown 18791b7489eSJed Brown.SECONDEXPANSION: # to expand $$(@D)/.DIR 1889df38c42SVeselin Dobrev 189c4acb06bSStan Tomov.SECONDARY: $(magma_tmp.c) $(magma_tmp.cu) 19014c1ded1SStan Tomov 19191b7489eSJed Brown%/.DIR : 19291b7489eSJed Brown @mkdir -p $(@D) 19391b7489eSJed Brown @touch $@ 19491b7489eSJed Brown 19591b7489eSJed Brown.PRECIOUS: %/.DIR 19691b7489eSJed Brown 19723072ed2SVeselin Dobrevlib: $(libceed) $(ceed.pc) 19823072ed2SVeselin Dobrev# run 'lib' target in parallel 1992f4d9adbSJeremy L Thompsonpar:;@$(MAKE) $(MFLAGS) V=$(V) lib 200d20f937dSJed Brownbackend_status = $(if $(filter $1,$(BACKENDS)), [backends: $1], [not found]) 201bf3e26f6SVeselin Dobrevinfo: 202bf3e26f6SVeselin Dobrev $(info ------------------------------------) 203bf3e26f6SVeselin Dobrev $(info CC = $(CC)) 204bf3e26f6SVeselin Dobrev $(info FC = $(FC)) 205bf3e26f6SVeselin Dobrev $(info CPPFLAGS = $(CPPFLAGS)) 206bf3e26f6SVeselin Dobrev $(info CFLAGS = $(value CFLAGS)) 207bf3e26f6SVeselin Dobrev $(info FFLAGS = $(value FFLAGS)) 208bf3e26f6SVeselin Dobrev $(info NVCCFLAGS = $(value NVCCFLAGS)) 209bf3e26f6SVeselin Dobrev $(info LDFLAGS = $(value LDFLAGS)) 210bf3e26f6SVeselin Dobrev $(info LDLIBS = $(LDLIBS)) 211bf3e26f6SVeselin Dobrev $(info OPT = $(OPT)) 212bf3e26f6SVeselin Dobrev $(info AFLAGS = $(AFLAGS)) 213bf3e26f6SVeselin Dobrev $(info ASAN = $(or $(ASAN),(empty))) 214bf3e26f6SVeselin Dobrev $(info V = $(or $(V),(empty)) [verbose=$(if $(V),on,off)]) 215bf3e26f6SVeselin Dobrev $(info ------------------------------------) 216bdc3149dSjeremylt $(info MEMCHK_STATUS = $(MEMCHK_STATUS)$(call backend_status,/cpu/self/ref/memcheck)) 21784a01de5SJeremy L Thompson $(info AVX_STATUS = $(AVX_STATUS)$(call backend_status,/cpu/self/avx/serial /cpu/self/avx/blocked)) 21884a01de5SJeremy L Thompson $(info XSMM_DIR = $(XSMM_DIR)$(call backend_status,/cpu/self/xsmm/serial /cpu/self/xsmm/blocked)) 219d20f937dSJed Brown $(info OCCA_DIR = $(OCCA_DIR)$(call backend_status,/cpu/occa /gpu/occa /omp/occa)) 220d20f937dSJed Brown $(info MAGMA_DIR = $(MAGMA_DIR)$(call backend_status,/gpu/magma)) 221ab9cabdeSVeselin Dobrev $(info CUDA_DIR = $(CUDA_DIR)$(call backend_status,$(CUDA_BACKENDS))) 222bf3e26f6SVeselin Dobrev $(info ------------------------------------) 223bf3e26f6SVeselin Dobrev $(info MFEM_DIR = $(MFEM_DIR)) 2244d1cd9fcSJeremy L Thompson $(info NEK5K_DIR = $(NEK5K_DIR)) 225bf3e26f6SVeselin Dobrev $(info PETSC_DIR = $(PETSC_DIR)) 226bf3e26f6SVeselin Dobrev $(info ------------------------------------) 227bf3e26f6SVeselin Dobrev $(info prefix = $(prefix)) 228bf3e26f6SVeselin Dobrev $(info includedir = $(value includedir)) 229bf3e26f6SVeselin Dobrev $(info libdir = $(value libdir)) 230bf3e26f6SVeselin Dobrev $(info okldir = $(value okldir)) 231bf3e26f6SVeselin Dobrev $(info pkgconfigdir = $(value pkgconfigdir)) 232bf3e26f6SVeselin Dobrev $(info ------------------------------------) 233bf3e26f6SVeselin Dobrev @true 23423072ed2SVeselin Dobrevinfo-backends: 235d20f937dSJed Brown $(info make: 'lib' with optional backends: $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS))) 2362f4d9adbSJeremy L Thompson.PHONY: lib all par info info-backends 2370e439e50SJed Brown 23824d002f4SJed Brown$(libceed) : LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed))) 23969762e1fScamierjs 24048fffa06Sjeremylt# Standard Backends 24187174f08SJed Brownlibceed.c += $(ref.c) 2424a2e7687Sjeremyltlibceed.c += $(blocked.c) 24389c6efa4Sjeremyltlibceed.c += $(opt.c) 24423072ed2SVeselin Dobrev 245265be9c8Sjeremylt# Testing Backends 246265be9c8Sjeremylttest_backends.c := $(template.c) 247265be9c8SjeremyltTEST_BACKENDS := /cpu/self/tmpl /cpu/self/tmpl/sub 248265be9c8Sjeremylt 249fc7cf9a0Sjeremylt# Memcheck Backend 250bdc3149dSjeremyltMEMCHK_STATUS = Disabled 251b8fb44e7SJed BrownMEMCHK := $(shell echo "\#include <valgrind/memcheck.h>" | $(CC) $(CPPFLAGS) -E - >/dev/null 2>&1 && echo 1) 252bdc3149dSjeremyltifeq ($(MEMCHK),1) 253bdc3149dSjeremylt MEMCHK_STATUS = Enabled 254fc7cf9a0Sjeremylt libceed.c += $(ceedmemcheck.c) 255fc7cf9a0Sjeremylt BACKENDS += /cpu/self/ref/memcheck 256fc7cf9a0Sjeremyltendif 257fc7cf9a0Sjeremylt 25848fffa06Sjeremylt# AVX Backed 25948fffa06SjeremyltAVX_STATUS = Disabled 2605efe2378SjeremyltAVX := $(shell $(CC) $(OPT) -v -E - < /dev/null 2>&1 | grep -c avx) 26148fffa06Sjeremyltifeq ($(AVX),1) 26248fffa06Sjeremylt AVX_STATUS = Enabled 26348fffa06Sjeremylt libceed.c += $(avx.c) 26484a01de5SJeremy L Thompson BACKENDS += /cpu/self/avx/serial /cpu/self/avx/blocked 26548fffa06Sjeremyltendif 26648fffa06Sjeremylt 2678d713cf6Sjeremylt# libXSMM Backends 2688d713cf6Sjeremyltifneq ($(wildcard $(XSMM_DIR)/lib/libxsmm.*),) 2698d713cf6Sjeremylt $(libceed) : LDFLAGS += -L$(XSMM_DIR)/lib -Wl,-rpath,$(abspath $(XSMM_DIR)/lib) 270724a7164Sjeremylt $(libceed) : LDLIBS += -lxsmm -ldl 271724a7164Sjeremylt MKL ?= 0 272724a7164Sjeremylt ifneq (0,$(MKL)) 273724a7164Sjeremylt $(libceed) : LDLIBS += -mkl 274724a7164Sjeremylt else 275724a7164Sjeremylt $(libceed) : LDLIBS += -lblas 276724a7164Sjeremylt endif 2778d713cf6Sjeremylt libceed.c += $(xsmm.c) 278683faae0SJed Brown $(xsmm.c:%.c=$(OBJDIR)/%.o) $(xsmm.c:%=%.tidy) : CPPFLAGS += -I$(XSMM_DIR)/include 2798d713cf6Sjeremylt BACKENDS += /cpu/self/xsmm/serial /cpu/self/xsmm/blocked 2808d713cf6Sjeremyltendif 2818d713cf6Sjeremylt 28248fffa06Sjeremylt# OCCA Backends 2837f5ff99bSVeselin Dobrevifneq ($(wildcard $(OCCA_DIR)/lib/libocca.*),) 284fc377ca6SJed Brown $(libceed) : LDFLAGS += -L$(OCCA_DIR)/lib -Wl,-rpath,$(abspath $(OCCA_DIR)/lib) 28512123fd5Scamierjs $(libceed) : LDLIBS += -locca 28687174f08SJed Brown libceed.c += $(occa.c) 287683faae0SJed Brown $(occa.c:%.c=$(OBJDIR)/%.o) $(occa.c:%=%.tidy) : CPPFLAGS += -I$(OCCA_DIR)/include 288a953af89SJed Brown BACKENDS += /cpu/occa /gpu/occa /omp/occa 28921ae6867Scamierjsendif 29023072ed2SVeselin Dobrev 2919f0427d9SYohann# Cuda Backend 2925a9ca9adSVeselin DobrevCUDA_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(CUDA_DIR)/$d/libcudart.${SO_EXT})) 2935a9ca9adSVeselin DobrevCUDA_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(CUDA_LIB_DIR)))) 294c532df63SYohannCUDA_BACKENDS = /gpu/cuda/ref /gpu/cuda/reg /gpu/cuda/shared 2955a9ca9adSVeselin Dobrevifneq ($(CUDA_LIB_DIR),) 2969f0427d9SYohann $(libceed) : CFLAGS += -I$(CUDA_DIR)/include 2979f0427d9SYohann $(libceed) : LDFLAGS += -L$(CUDA_LIB_DIR) -Wl,-rpath,$(abspath $(CUDA_LIB_DIR)) 2989f0427d9SYohann $(libceed) : LDLIBS += -lcudart -lnvrtc -lcuda 299c532df63SYohann libceed.c += $(cuda.c) $(cuda-reg.c) $(cuda-shared.c) 300c532df63SYohann libceed.cu += $(cuda.cu) $(cuda-reg.cu) $(cuda-shared.cu) 301ab9cabdeSVeselin Dobrev BACKENDS += $(CUDA_BACKENDS) 3029f0427d9SYohannendif 3039f0427d9SYohann 3049f0427d9SYohann# MAGMA Backend 3059f0427d9SYohannifneq ($(wildcard $(MAGMA_DIR)/lib/libmagma.*),) 3069f0427d9SYohann ifneq ($(CUDA_LIB_DIR),) 3071dc2661bSVeselin Dobrev cuda_link = -Wl,-rpath,$(CUDA_LIB_DIR) -L$(CUDA_LIB_DIR) -lcublas -lcusparse -lcudart 3081dc2661bSVeselin Dobrev omp_link = -fopenmp 3091dc2661bSVeselin Dobrev magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(cuda_link) $(omp_link) 3107692a9b0SVeselin Dobrev magma_link_shared = -L$(MAGMA_DIR)/lib -Wl,-rpath,$(abspath $(MAGMA_DIR)/lib) -lmagma 3117692a9b0SVeselin Dobrev magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static)) 3127692a9b0SVeselin Dobrev $(libceed) : LDLIBS += $(magma_link) 3137692a9b0SVeselin Dobrev $(tests) $(examples) : LDLIBS += $(magma_link) 314c4acb06bSStan Tomov libceed.c += $(magma_allsrc.c) 315c4acb06bSStan Tomov libceed.cu += $(magma_allsrc.cu) 316683faae0SJed Brown $(magma_allsrc.c:%.c=$(OBJDIR)/%.o) $(magma_allsrc.c:%=%.tidy) : CPPFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include 317c4acb06bSStan 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 318ce41f623SJed Brown BACKENDS += /gpu/magma 31982b77998SStan Tomov endif 3205a9ca9adSVeselin Dobrevendif 321755585ceSStan Tomov 322ce41f623SJed Brownexport BACKENDS 323ce41f623SJed Brown 324755585ceSStan Tomov# generate magma_tmp.c and magma_cuda.cu from magma.c 32529715310SJed Brown%_tmp.c %_cuda.cu : %.c 326755585ceSStan Tomov $(magma_preprocessor) $< 327755585ceSStan Tomov 32823072ed2SVeselin Dobrevlibceed.o = $(libceed.c:%.c=$(OBJDIR)/%.o) $(libceed.cu:%.cu=$(OBJDIR)/%.o) 32923072ed2SVeselin Dobrev$(libceed.o): | info-backends 33023072ed2SVeselin Dobrev$(libceed) : $(libceed.o) | $$(@D)/.DIR 33121ae6867Scamierjs $(call quiet,CC) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS) 33291b7489eSJed Brown 33358e8d3b7SJed Brown$(OBJDIR)/%.o : $(CURDIR)/%.c | $$(@D)/.DIR 334b5b03409SJed Brown $(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<) 335ae3cba82Scamierjs 33658e8d3b7SJed Brown$(OBJDIR)/%.o : $(CURDIR)/%.cu | $$(@D)/.DIR 337755585ceSStan Tomov $(call quiet,NVCC) $(CPPFLAGS) $(NVCCFLAGS) -c -o $@ $(abspath $<) 338755585ceSStan Tomov 339b5b03409SJed Brown$(OBJDIR)/% : tests/%.c | $$(@D)/.DIR 340265be9c8Sjeremylt $(call quiet,LINK.c) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 34178b5556aScamierjs 3428980d4a7Sjeremylt$(OBJDIR)/% : tests/%.f90 | $$(@D)/.DIR 343265be9c8Sjeremylt $(call quiet,LINK.F) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 34432d74c32SThilina Rathnayake 345182fbe45STzanio$(OBJDIR)/% : examples/ceed/%.c | $$(@D)/.DIR 346265be9c8Sjeremylt $(call quiet,LINK.c) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 34791b7489eSJed Brown 348182fbe45STzanio$(OBJDIR)/% : examples/ceed/%.f | $$(@D)/.DIR 349265be9c8Sjeremylt $(call quiet,LINK.F) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 350673d494eSThilina Rathnayake 35116c6c054SJed Brown$(OBJDIR)/mfem-% : examples/mfem/%.cpp $(libceed) | $$(@D)/.DIR 352*c4216f28SJed Brown +$(MAKE) -C examples/mfem CEED_DIR=`pwd` \ 3532f4d9adbSJeremy L Thompson MFEM_DIR="$(abspath $(MFEM_DIR))" $* 35416c6c054SJed Brown mv examples/mfem/$* $@ 35516c6c054SJed Brown 3567f6cf205SJed Brown$(OBJDIR)/petsc-% : examples/petsc/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR 357*c4216f28SJed Brown +$(MAKE) -C examples/petsc CEED_DIR=`pwd` \ 3582f4d9adbSJeremy L Thompson PETSC_DIR="$(abspath $(PETSC_DIR))" $* 359e797ab98SJed Brown mv examples/petsc/$* $@ 360e797ab98SJed Brown 3612774d5cbSJeremy L Thompson$(OBJDIR)/navier-stokes-% : examples/navier-stokes/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR 362*c4216f28SJed Brown +$(MAKE) -C examples/navier-stokes CEED_DIR=`pwd` \ 3632774d5cbSJeremy L Thompson PETSC_DIR="$(abspath $(PETSC_DIR))" $* 3642774d5cbSJeremy L Thompson mv examples/navier-stokes/$* $@ 3652774d5cbSJeremy L Thompson 366265be9c8Sjeremyltlibceed_test.o = $(test_backends.c:%.c=$(OBJDIR)/%.o) $(libceed.o) 367265be9c8Sjeremylt$(libceed_test) : $(libceed) 368265be9c8Sjeremylt$(libceed_test) : $(libceed_test.o) | $$(@D)/.DIR 369265be9c8Sjeremylt $(call quiet,CC) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS) 370265be9c8Sjeremylt 371265be9c8Sjeremylt$(examples) : $(libceed) 372686de4acSJed Brown$(tests) : $(libceed_test) 373686de4acSJed Brown$(tests) : CEED_LIBS += -lceed_test 374fc377ca6SJed Brown$(tests) $(examples) : LDFLAGS += -Wl,-rpath,$(abspath $(LIBDIR)) -L$(LIBDIR) 3754859b599SJed Brown 376686de4acSJed Brownrun-t% : BACKENDS += $(TEST_BACKENDS) 377dad465e7SJed Brownrun-% : $(OBJDIR)/% 378d1f7f8d3SJed Brown @tests/tap.sh $(<:$(OBJDIR)/%=%) 379686de4acSJed Brown 380686de4acSJed Brownexternal_examples := \ 381686de4acSJed Brown $(if $(MFEM_DIR),$(mfemexamples)) \ 382686de4acSJed Brown $(if $(PETSC_DIR),$(petscexamples)) \ 383686de4acSJed Brown $(if $(NEK5K_DIR),$(nekexamples)) 384686de4acSJed Brown 385686de4acSJed Brownallexamples = $(examples) $(external_examples) 386686de4acSJed Brown 387686de4acSJed Brown# The test and prove targets can be controlled via pattern searches. The 388686de4acSJed Brown# default is to run tests and those examples that have no external dependencies. 389686de4acSJed Brown# Examples of finer grained control: 390686de4acSJed Brown# 391686de4acSJed Brown# make test search='petsc mfem' # PETSc and MFEM examples 392686de4acSJed Brown# make prove search='t3' # t3xx series tests 393686de4acSJed Brown# make junit search='ex petsc' # core ex* and PETSc tests 394686de4acSJed Brownsearch ?= t ex 395686de4acSJed Brownrealsearch = $(search:%=%%) 396686de4acSJed Brownmatched = $(foreach pattern,$(realsearch),$(filter $(OBJDIR)/$(pattern),$(tests) $(allexamples))) 397686de4acSJed Brown# Work around Nek examples not having normal targets 398686de4acSJed Brownmatched_prereq = $(filter-out $(OBJDIR)/nek%,$(matched)) $(if $(findstring nek,$(matched)),prepnektests) 399686de4acSJed Brown 4002158b1b0Sjeremylt# Test core libCEED 401686de4acSJed Browntest : $(matched:$(OBJDIR)/%=run-%) 4022158b1b0Sjeremylt 4033b56482dScamierjs# run test target in parallel 4046850bcb5Scamierjstst : ;@$(MAKE) $(MFLAGS) V=$(V) test 4053b56482dScamierjs# CPU C tests only for backend % 4063f3e7340Scamierjsctc-% : $(ctests);@$(foreach tst,$(ctests),$(tst) /cpu/$*;) 4074859b599SJed Brown 408686de4acSJed Brownprove : BACKENDS += $(TEST_BACKENDS) 409686de4acSJed Brownprove : $(matched_prereq) 410a5dc8077SJed Brown $(info Testing backends: $(BACKENDS)) 411686de4acSJed Brown $(PROVE) $(PROVE_OPTS) --exec 'tests/tap.sh' $(matched:$(OBJDIR)/%=%) 4123b56482dScamierjs# run prove target in parallel 4136850bcb5Scamierjsprv : ;@$(MAKE) $(MFLAGS) V=$(V) prove 414bfa078e6SJed Brown 4154d1cd9fcSJeremy L Thompsonprepnektests: 4164d1cd9fcSJeremy L Thompson (export CC FC && cd examples && make prepnektests) 4172158b1b0Sjeremylt 418686de4acSJed Brownprove-all : 419686de4acSJed Brown +$(MAKE) prove realsearch=% 420686de4acSJed Brown 421686de4acSJed Brownjunit-t% : BACKENDS += $(TEST_BACKENDS) 4228ec9d54bSJed Brownjunit-% : $(OBJDIR)/% 423bdb0bdbbSJed Brown @printf " %10s %s\n" TEST $(<:$(OBJDIR)/%=%); $(PYTHON) tests/junit.py $(<:$(OBJDIR)/%=%) 4248ec9d54bSJed Brown 4258ec9d54bSJed Brownjunit : $(alltests:$(OBJDIR)/%=junit-%) 4268ec9d54bSJed Brown 4272f4d9adbSJeremy L Thompsonall: $(alltests) 4282f4d9adbSJeremy L Thompson 4292f4d9adbSJeremy L Thompsonexamples : $(allexamples) 4302f4d9adbSJeremy L Thompson 4312f4d9adbSJeremy L Thompson# Benchmarks 4322f4d9adbSJeremy L Thompsonallbenchmarks = petsc-bp1 petsc-bp3 4334e79ff5bSVeselin Dobrevbench_targets = $(addprefix bench-,$(allbenchmarks)) 4344e79ff5bSVeselin Dobrev.PHONY: $(bench_targets) benchmarks 4354e79ff5bSVeselin Dobrev$(bench_targets): bench-%: $(OBJDIR)/% 4362f4d9adbSJeremy L Thompson cd benchmarks && ./benchmark.sh --ceed "$(BACKENDS)" -r $(*).sh 4374e79ff5bSVeselin Dobrevbenchmarks: $(bench_targets) 4382c6ea02fSJed Brown 4396ea7c6c1SJed Brown$(ceed.pc) : pkgconfig-prefix = $(abspath .) 440d5217624SJed Brown$(OBJDIR)/ceed.pc : pkgconfig-prefix = $(prefix) 441d5217624SJed Brown.INTERMEDIATE : $(OBJDIR)/ceed.pc 4426ea7c6c1SJed Brown%/ceed.pc : ceed.pc.template | $$(@D)/.DIR 4436ea7c6c1SJed Brown @sed "s:%prefix%:$(pkgconfig-prefix):" $< > $@ 4440e439e50SJed Brown 445bf3e26f6SVeselin DobrevOCCA := $(OCCA_DIR)/bin/occa 446cc6ff0d7SJed BrownOKL_KERNELS := $(wildcard backends/occa/*.okl) 447cc6ff0d7SJed Brown 448cc6ff0d7SJed Brownokl-cache : 449cc6ff0d7SJed Brown $(OCCA) cache ceed $(OKL_KERNELS) 450cc6ff0d7SJed Brown 451cc6ff0d7SJed Brownokl-clear: 452cc6ff0d7SJed Brown $(OCCA) clear -y -l ceed 453a5ba6ca9Scamierjs 454d5217624SJed Browninstall : $(libceed) $(OBJDIR)/ceed.pc 455bf3e26f6SVeselin Dobrev $(INSTALL) -d $(addprefix $(if $(DESTDIR),"$(DESTDIR)"),"$(includedir)"\ 456bf3e26f6SVeselin Dobrev "$(libdir)" "$(pkgconfigdir)" $(if $(OCCA_ON),"$(okldir)")) 4571e25a746SJed Brown $(INSTALL_DATA) include/ceed.h "$(DESTDIR)$(includedir)/" 458f91e0974SThilina Rathnayake $(INSTALL_DATA) include/ceedf.h "$(DESTDIR)$(includedir)/" 4591e25a746SJed Brown $(INSTALL_DATA) $(libceed) "$(DESTDIR)$(libdir)/" 4601e25a746SJed Brown $(INSTALL_DATA) $(OBJDIR)/ceed.pc "$(DESTDIR)$(pkgconfigdir)/" 461bf3e26f6SVeselin Dobrev $(if $(OCCA_ON),$(INSTALL_DATA) $(OKL_KERNELS) "$(DESTDIR)$(okldir)/") 462d5217624SJed Brown 463683faae0SJed 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 464d635b4c6Scamierjs 4656e5d1fd9Scamierjscln clean : 466df0ef7e4SVeselin Dobrev $(RM) -r $(OBJDIR) $(LIBDIR) 4672774d5cbSJeremy L Thompson $(MAKE) -C examples clean 468c4acb06bSStan Tomov $(RM) $(magma_tmp.c) $(magma_tmp.cu) backends/magma/*~ backends/magma/*.o 4692f4d9adbSJeremy L Thompson $(RM) -rf benchmarks/*output.txt 4704859b599SJed Brown 47107838a1cSTzaniodistclean : clean 4728c23e06aSJed Brown $(RM) -r doc/html 47307838a1cSTzanio 4740ab95609SJed Browndoc : 4757bd3a522STzanio doxygen Doxyfile 4767bd3a522STzanio 477f2fa494dScamierjsstyle : 47820b73d85SJed Brown @astyle --options=.astylerc \ 47920b73d85SJed Brown $(filter-out include/ceedf.h tests/t310-basis-f.h, \ 48020b73d85SJed Brown $(wildcard include/*.h interface/*.[ch] tests/*.[ch] backends/*/*.[ch] \ 48120b73d85SJed Brown examples/*/*.[ch] examples/*/*.[ch]pp)) 4820dbfdfc5SJed Brown 483683faae0SJed BrownCLANG_TIDY ?= clang-tidy 484683faae0SJed Brown%.c.tidy : %.c 485683faae0SJed Brown $(CLANG_TIDY) $^ -- $(CPPFLAGS) 486683faae0SJed Brown 487683faae0SJed Browntidy : $(libceed.c:%=%.tidy) 488683faae0SJed Brown 4894859b599SJed Brownprint : 4904859b599SJed Brown @echo $(VAR)=$($(VAR)) 491582447c9SJed Brown 4929df38c42SVeselin Dobrevprint-% : 4939df38c42SVeselin Dobrev $(info [ variable name]: $*) 4949df38c42SVeselin Dobrev $(info [ origin]: $(origin $*)) 4959df38c42SVeselin Dobrev $(info [ value]: $(value $*)) 4969df38c42SVeselin Dobrev $(info [expanded value]: $($*)) 4979df38c42SVeselin Dobrev $(info ) 4989df38c42SVeselin Dobrev @true 4999df38c42SVeselin Dobrev 500d1f7f8d3SJed Brown-include $(libceed.c:%.c=$(OBJDIR)/%.d) $(tests.c:tests/%.c=$(OBJDIR)/%.d) 501