1# Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC. 2# Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707. 3# All Rights reserved. See files LICENSE and NOTICE for details. 4# 5# This file is part of CEED, a collection of benchmarks, miniapps, software 6# libraries and APIs for efficient high-order finite element and spectral 7# element discretizations for exascale applications. For more information and 8# source code availability see http://github.com/ceed. 9# 10# The CEED research is supported by the Exascale Computing Project 17-SC-20-SC, 11# a collaborative effort of two U.S. Department of Energy organizations (Office 12# of Science and the National Nuclear Security Administration) responsible for 13# the planning and preparation of a capable exascale ecosystem, including 14# software, applications, hardware, advanced system engineering and early 15# testbed platforms, in support of the nation's exascale computing imperative. 16 17CONFIG ?= config.mk 18-include $(CONFIG) 19COMMON ?= common.mk 20-include $(COMMON) 21 22ifeq (,$(filter-out undefined default,$(origin CC))) 23 CC = gcc 24endif 25ifeq (,$(filter-out undefined default,$(origin CXX))) 26 CXX = g++ 27endif 28ifeq (,$(filter-out undefined default,$(origin FC))) 29 FC = gfortran 30endif 31ifeq (,$(filter-out undefined default,$(origin LINK))) 32 LINK = $(CC) 33endif 34NVCC ?= $(CUDA_DIR)/bin/nvcc 35NVCC_CXX ?= $(CXX) 36HIPCC ?= $(HIP_DIR)/bin/hipcc 37 38# ASAN must be left empty if you don't want to use it 39ASAN ?= 40 41LDFLAGS ?= 42UNDERSCORE ?= 1 43 44# MFEM_DIR env variable should point to sibling directory 45ifneq ($(wildcard ../mfem/libmfem.*),) 46 MFEM_DIR ?= ../mfem 47endif 48 49# NEK5K_DIR env variable should point to sibling directory 50ifneq ($(wildcard ../Nek5000/*),) 51 NEK5K_DIR ?= $(abspath ../Nek5000) 52endif 53export NEK5K_DIR 54MPI ?= 1 55 56# CEED_DIR env for NEK5K testing 57export CEED_DIR = $(abspath .) 58 59# XSMM_DIR env variable should point to XSMM master (github.com/hfp/libxsmm) 60XSMM_DIR ?= ../libxsmm 61 62# OCCA_DIR env variable should point to OCCA master (github.com/libocca/occa) 63OCCA_DIR ?= ../occa 64 65# env variable MAGMA_DIR can be used too 66MAGMA_DIR ?= ../magma 67# If CUDA_DIR is not set, check for nvcc, or resort to /usr/local/cuda 68CUDA_DIR ?= $(or $(patsubst %/,%,$(dir $(patsubst %/,%,$(dir \ 69 $(shell which nvcc 2> /dev/null))))),/usr/local/cuda) 70HIP_DIR ?= /opt/rocm 71 72# Check for PETSc in ../petsc 73ifneq ($(wildcard ../petsc/lib/libpetsc.*),) 74 PETSC_DIR ?= ../petsc 75endif 76 77# Warning: SANTIZ options still don't run with /gpu/occa 78# export LSAN_OPTIONS=suppressions=.asanignore 79AFLAGS = -fsanitize=address #-fsanitize=undefined -fno-omit-frame-pointer 80 81CC_VENDOR := $(patsubst gcc%,gcc,$(firstword $(filter gcc% clang icc XL,$(shell $(CC) --version)))) 82FC_VENDOR := $(firstword $(filter GNU ifort XL,$(shell $(FC) --version 2>&1 || $(FC) -qversion))) 83 84# Default extra flags by vendor 85MARCHFLAG.gcc := -march=native 86MARCHFLAG.clang := $(MARCHFLAG.gcc) 87MARCHFLAG.icc := 88OMP_SIMD_FLAG.gcc := -fopenmp-simd 89OMP_SIMD_FLAG.clang := $(OMP_SIMD_FLAG.gcc) 90OMP_SIMD_FLAG.icc := -qopenmp-simd 91OPT.gcc := -ffp-contract=fast 92OPT.clang := $(OPT.gcc) 93CFLAGS.gcc := -fPIC -std=c99 -Wall -Wextra -Wno-unused-parameter -MMD -MP 94CFLAGS.clang := $(CFLAGS.gcc) 95CFLAGS.icc := $(CFLAGS.gcc) 96CFLAGS.XL := -qpic -MMD 97CXXFLAGS.gcc := -fPIC -std=c++11 -Wall -Wextra -Wno-unused-parameter -MMD -MP 98CXXFLAGS.clang := $(CXXFLAGS.gcc) 99CXXFLAGS.icc := $(CXXFLAGS.gcc) 100CXXFLAGS.XL := -qpic -MMD 101FFLAGS.GNU := -fPIC -cpp -Wall -Wextra -Wno-unused-parameter -Wno-unused-dummy-argument -MMD -MP 102FFLAGS.ifort := -fPIC -cpp 103FFLAGS.XL := -qpic -ffree-form -qpreprocess -qextname -MMD 104 105# This check works with compilers that use gcc and clang. It fails with some 106# compilers; e.g., xlc apparently ignores all options when -E is passed, thus 107# succeeds with any flags. Users can pass MARCHFLAG=... if desired. 108cc_check_flag = $(shell $(CC) -E -Werror $(1) -x c /dev/null > /dev/null 2>&1 && echo 1) 109MARCHFLAG := $(MARCHFLAG.$(CC_VENDOR)) 110MARCHFLAG := $(if $(call cc_check_flag,$(MARCHFLAG)),$(MARCHFLAG),-mcpu=native) 111MARCHFLAG := $(if $(call cc_check_flag,$(MARCHFLAG)),$(MARCHFLAG)) 112 113OMP_SIMD_FLAG := $(OMP_SIMD_FLAG.$(CC_VENDOR)) 114OMP_SIMD_FLAG := $(if $(call cc_check_flag,$(OMP_SIMD_FLAG)),$(OMP_SIMD_FLAG)) 115 116OPT ?= -O -g $(MARCHFLAG) $(OPT.$(CC_VENDOR)) $(OMP_SIMD_FLAG) 117CFLAGS ?= $(OPT) $(CFLAGS.$(CC_VENDOR)) 118CXXFLAGS ?= $(OPT) $(CXXFLAGS.$(CC_VENDOR)) 119NVCCFLAGS ?= -ccbin $(CXX) -Xcompiler "$(OPT)" -Xcompiler -fPIC 120HIPCCFLAGS ?= $(OPT) -fPIC 121FFLAGS ?= $(OPT) $(FFLAGS.$(FC_VENDOR)) 122 123ifeq ($(COVERAGE), 1) 124 CFLAGS += --coverage 125 LDFLAGS += --coverage 126endif 127 128CFLAGS += $(if $(ASAN),$(AFLAGS)) 129FFLAGS += $(if $(ASAN),$(AFLAGS)) 130LDFLAGS += $(if $(ASAN),$(AFLAGS)) 131CPPFLAGS += -I./include 132LDLIBS = -lm 133OBJDIR := build 134LIBDIR := lib 135 136# Installation variables 137prefix ?= /usr/local 138bindir = $(prefix)/bin 139libdir = $(prefix)/lib 140includedir = $(prefix)/include 141pkgconfigdir = $(libdir)/pkgconfig 142INSTALL = install 143INSTALL_PROGRAM = $(INSTALL) 144INSTALL_DATA = $(INSTALL) -m644 145 146# Get number of processors of the machine 147NPROCS := $(shell getconf _NPROCESSORS_ONLN) 148# prepare make options to run in parallel 149MFLAGS := -j $(NPROCS) --warn-undefined-variables \ 150 --no-print-directory --no-keep-going 151 152PYTHON ?= python3 153PROVE ?= prove 154PROVE_OPTS ?= -j $(NPROCS) 155DARWIN := $(filter Darwin,$(shell uname -s)) 156SO_EXT := $(if $(DARWIN),dylib,so) 157 158ceed.pc := $(LIBDIR)/pkgconfig/ceed.pc 159libceed := $(LIBDIR)/libceed.$(SO_EXT) 160CEED_LIBS = -lceed 161libceed.c := $(filter-out interface/ceed-cuda.c interface/ceed-hip.c, $(wildcard interface/ceed*.c)) 162gallery.c := $(wildcard gallery/*/ceed*.c) 163libceed.c += $(gallery.c) 164libceed_test := $(LIBDIR)/libceed_test.$(SO_EXT) 165libceeds = $(libceed) $(libceed_test) 166BACKENDS_BUILTIN := /cpu/self/ref/serial /cpu/self/ref/blocked /cpu/self/opt/serial /cpu/self/opt/blocked 167BACKENDS := $(BACKENDS_BUILTIN) 168 169# Tests 170tests.c := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.c)) 171tests.f := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.f90)) 172tests := $(tests.c:tests/%.c=$(OBJDIR)/%) 173ctests := $(tests) 174tests += $(tests.f:tests/%.f90=$(OBJDIR)/%) 175# Examples 176examples.c := $(sort $(wildcard examples/ceed/*.c)) 177examples.f := $(sort $(wildcard examples/ceed/*.f)) 178examples := $(examples.c:examples/ceed/%.c=$(OBJDIR)/%) 179examples += $(examples.f:examples/ceed/%.f=$(OBJDIR)/%) 180# MFEM Examples 181mfemexamples.cpp := $(sort $(wildcard examples/mfem/*.cpp)) 182mfemexamples := $(mfemexamples.cpp:examples/mfem/%.cpp=$(OBJDIR)/mfem-%) 183# Nek5K Examples 184nekexamples := $(OBJDIR)/nek-bps 185# PETSc Examples 186petscexamples.c := $(wildcard examples/petsc/*.c) 187petscexamples := $(petscexamples.c:examples/petsc/%.c=$(OBJDIR)/petsc-%) 188# Fluid Dynamics Examples 189fluidsexamples.c := $(sort $(wildcard examples/fluids/*.c)) 190fluidsexamples := $(fluidsexamples.c:examples/fluids/%.c=$(OBJDIR)/fluids-%) 191# Solid Mechanics Examples 192solidsexamples.c := $(sort $(wildcard examples/solids/*.c)) 193solidsexamples := $(solidsexamples.c:examples/solids/%.c=$(OBJDIR)/solids-%) 194 195# Backends/[ref, blocked, template, memcheck, opt, avx, occa, magma] 196ref.c := $(sort $(wildcard backends/ref/*.c)) 197blocked.c := $(sort $(wildcard backends/blocked/*.c)) 198template.c := $(sort $(wildcard backends/template/*.c)) 199ceedmemcheck.c := $(sort $(wildcard backends/memcheck/*.c)) 200opt.c := $(sort $(wildcard backends/opt/*.c)) 201avx.c := $(sort $(wildcard backends/avx/*.c)) 202xsmm.c := $(sort $(wildcard backends/xsmm/*.c)) 203cuda.c := $(sort $(wildcard backends/cuda/*.c)) 204cuda.cpp := $(sort $(wildcard backends/cuda/*.cpp)) 205cuda.cu := $(sort $(wildcard backends/cuda/kernels/*.cu)) 206cuda-shared.c := $(sort $(wildcard backends/cuda-shared/*.c)) 207cuda-shared.cu := $(sort $(wildcard backends/cuda-shared/kernels/*.cu)) 208cuda-gen.c := $(sort $(wildcard backends/cuda-gen/*.c)) 209cuda-gen.cpp := $(sort $(wildcard backends/cuda-gen/*.cpp)) 210cuda-gen.cu := $(sort $(wildcard backends/cuda-gen/kernels/*.cu)) 211occa.cpp := $(sort $(shell find backends/occa -type f -name *.cpp)) 212magma.c := $(sort $(wildcard backends/magma/*.c)) 213magma.cu := $(sort $(wildcard backends/magma/kernels/*.cu)) 214hip.c := $(sort $(wildcard backends/hip/*.c)) 215hip.cpp := $(sort $(wildcard backends/hip/*.cpp)) 216hip.hip := $(sort $(wildcard backends/hip/kernels/*.hip.cpp)) 217 218# Quiet, color output 219quiet ?= $($(1)) 220 221# Cancel built-in and old-fashioned implicit rules which we don't use 222.SUFFIXES: 223 224.SECONDEXPANSION: # to expand $$(@D)/.DIR 225 226%/.DIR : 227 @mkdir -p $(@D) 228 @touch $@ 229 230.PRECIOUS: %/.DIR 231 232lib: $(libceed) $(ceed.pc) 233# run 'lib' target in parallel 234par:;@$(MAKE) $(MFLAGS) V=$(V) lib 235backend_status = $(if $(filter $1,$(BACKENDS)), [backends: $1], [not found]) 236info: 237 $(info ------------------------------------) 238 $(info CC = $(CC)) 239 $(info CXX = $(CXX)) 240 $(info FC = $(FC)) 241 $(info CPPFLAGS = $(CPPFLAGS)) 242 $(info CFLAGS = $(value CFLAGS)) 243 $(info CXXFLAGS = $(value CXXFLAGS)) 244 $(info FFLAGS = $(value FFLAGS)) 245 $(info NVCCFLAGS = $(value NVCCFLAGS)) 246 $(info HIPCCFLAGS = $(value HIPCCFLAGS)) 247 $(info LDFLAGS = $(value LDFLAGS)) 248 $(info LDLIBS = $(LDLIBS)) 249 $(info OPT = $(OPT)) 250 $(info AFLAGS = $(AFLAGS)) 251 $(info ASAN = $(or $(ASAN),(empty))) 252 $(info V = $(or $(V),(empty)) [verbose=$(if $(V),on,off)]) 253 $(info ------------------------------------) 254 $(info MEMCHK_STATUS = $(MEMCHK_STATUS)$(call backend_status,/cpu/self/memcheck/serial /cpu/sef/memcheck/blocked)) 255 $(info AVX_STATUS = $(AVX_STATUS)$(call backend_status,/cpu/self/avx/serial /cpu/self/avx/blocked)) 256 $(info XSMM_DIR = $(XSMM_DIR)$(call backend_status,/cpu/self/xsmm/serial /cpu/self/xsmm/blocked)) 257 $(info OCCA_DIR = $(OCCA_DIR)$(call backend_status,$(OCCA_BACKENDS))) 258 $(info MAGMA_DIR = $(MAGMA_DIR)$(call backend_status,/gpu/magma /gpu/magma/det)) 259 $(info CUDA_DIR = $(CUDA_DIR)$(call backend_status,$(CUDA_BACKENDS))) 260 $(info HIP_DIR = $(HIP_DIR)$(call backend_status,$(HIP_BACKENDS))) 261 $(info ------------------------------------) 262 $(info MFEM_DIR = $(MFEM_DIR)) 263 $(info NEK5K_DIR = $(NEK5K_DIR)) 264 $(info PETSC_DIR = $(PETSC_DIR)) 265 $(info ------------------------------------) 266 $(info prefix = $(prefix)) 267 $(info includedir = $(value includedir)) 268 $(info libdir = $(value libdir)) 269 $(info pkgconfigdir = $(value pkgconfigdir)) 270 $(info ------------------------------------) 271 @true 272info-backends: 273 $(info make: 'lib' with optional backends: $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS))) 274.PHONY: lib all par info info-backends 275 276$(libceed) : LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed))) 277$(libceed_test) : LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed_test))) 278 279# Standard Backends 280libceed.c += $(ref.c) 281libceed.c += $(blocked.c) 282libceed.c += $(opt.c) 283 284# Testing Backends 285test_backends.c := $(template.c) 286TEST_BACKENDS := /cpu/self/tmpl /cpu/self/tmpl/sub 287 288# Memcheck Backend 289MEMCHK_STATUS = Disabled 290MEMCHK := $(shell echo "\#include <valgrind/memcheck.h>" | $(CC) $(CPPFLAGS) -E - >/dev/null 2>&1 && echo 1) 291ifeq ($(MEMCHK),1) 292 MEMCHK_STATUS = Enabled 293 libceed.c += $(ceedmemcheck.c) 294 BACKENDS += /cpu/self/memcheck/serial /cpu/self/memcheck/blocked 295endif 296 297# AVX Backed 298AVX_STATUS = Disabled 299AVX_FLAG := $(if $(filter clang,$(CC_VENDOR)),+avx,-mavx) 300AVX := $(filter $(AVX_FLAG),$(shell $(CC) $(OPT) -v -E -x c /dev/null 2>&1)) 301ifneq ($(AVX),) 302 AVX_STATUS = Enabled 303 libceed.c += $(avx.c) 304 BACKENDS += /cpu/self/avx/serial /cpu/self/avx/blocked 305endif 306 307# libXSMM Backends 308ifneq ($(wildcard $(XSMM_DIR)/lib/libxsmm.*),) 309 $(libceeds) : LDFLAGS += -L$(XSMM_DIR)/lib -Wl,-rpath,$(abspath $(XSMM_DIR)/lib) 310 $(libceeds) : LDLIBS += -lxsmm -ldl 311 MKL ?= 312 ifeq (,$(MKL)$(MKLROOT)) 313 BLAS_LIB = -lblas 314 else 315 ifneq ($(MKLROOT),) 316 # Some installs put everything inside an intel64 subdirectory, others not 317 MKL_LIBDIR = $(dir $(firstword $(wildcard $(MKLROOT)/lib/intel64/libmkl_sequential.* $(MKLROOT)/lib/libmkl_sequential.*))) 318 MKL_LINK = -L$(MKL_LIBDIR) -Wl,-rpath,$(MKL_LIBDIR) 319 endif 320 BLAS_LIB = $(MKL_LINK) -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl 321 endif 322 $(libceeds) : LDLIBS += $(BLAS_LIB) 323 libceed.c += $(xsmm.c) 324 $(xsmm.c:%.c=$(OBJDIR)/%.o) $(xsmm.c:%=%.tidy) : CPPFLAGS += -I$(XSMM_DIR)/include 325 BACKENDS += /cpu/self/xsmm/serial /cpu/self/xsmm/blocked 326endif 327 328# OCCA Backends 329OCCA_BACKENDS = /cpu/occa/serial 330ifneq ($(wildcard $(OCCA_DIR)/lib/libocca.*),) 331 OCCA_MODES := $(shell $(OCCA_DIR)/bin/occa modes) 332 OCCA_BACKENDS += $(if $(filter OpenMP,$(OCCA_MODES)),/cpu/occa/openmp) 333# OCCA_BACKENDS += $(if $(filter OpenCL,$(OCCA_MODES)),/opencl/occa) 334 OCCA_BACKENDS += $(if $(filter HIP,$(OCCA_MODES)),/gpu/occa/hip) 335 OCCA_BACKENDS += $(if $(filter CUDA,$(OCCA_MODES)),/gpu/occa/cuda) 336 337 $(libceeds) : CPPFLAGS += -I$(OCCA_DIR)/include 338 $(libceeds) : LDFLAGS += -L$(OCCA_DIR)/lib -Wl,-rpath,$(abspath $(OCCA_DIR)/lib) 339 $(libceeds) : LDLIBS += -locca 340 $(libceeds) : LINK = $(CXX) 341 libceed.cpp += $(occa.cpp) 342 BACKENDS += $(OCCA_BACKENDS) 343endif 344 345# CUDA Backends 346CUDA_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(CUDA_DIR)/$d/libcudart.${SO_EXT})) 347CUDA_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(CUDA_LIB_DIR)))) 348CUDA_LIB_DIR_STUBS := $(CUDA_LIB_DIR)/stubs 349CUDA_BACKENDS = /gpu/cuda/ref /gpu/cuda/shared /gpu/cuda/gen 350ifneq ($(CUDA_LIB_DIR),) 351 $(libceeds) : CPPFLAGS += -I$(CUDA_DIR)/include 352 $(libceeds) : LDFLAGS += -L$(CUDA_LIB_DIR) -Wl,-rpath,$(abspath $(CUDA_LIB_DIR)) 353 $(libceeds) : LDLIBS += -lcudart -lnvrtc -lcuda -lcublas 354 $(libceeds) : LINK = $(CXX) 355 libceed.c += interface/ceed-cuda.c 356 libceed.c += $(cuda.c) $(cuda-shared.c) $(cuda-gen.c) 357 libceed.cpp += $(cuda.cpp) $(cuda-gen.cpp) 358 libceed.cu += $(cuda.cu) $(cuda-shared.cu) $(cuda-gen.cu) 359 BACKENDS += $(CUDA_BACKENDS) 360endif 361 362# HIP Backends 363HIP_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(HIP_DIR)/$d/libamdhip64.${SO_EXT})) 364HIP_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(HIP_LIB_DIR)))) 365HIP_BACKENDS = /gpu/hip/ref 366ifneq ($(HIP_LIB_DIR),) 367 $(libceeds) : HIPCCFLAGS += -I./include 368 ifneq ($(CXX), $(HIPCC)) 369 CPPFLAGS += $(subst =,,$(shell $(HIP_DIR)/bin/hipconfig -C)) 370 endif 371 $(libceeds) : CPPFLAGS += -I$(HIP_DIR)/include -Wno-unused-function 372 $(libceeds) : LDFLAGS += -L$(HIP_LIB_DIR) -Wl,-rpath,$(abspath $(HIP_LIB_DIR)) 373 $(libceeds) : LDLIBS += -lamdhip64 -lhipblas 374 $(libceeds) : LINK = $(CXX) 375 libceed.c += interface/ceed-hip.c 376 libceed.c += $(hip.c) 377 libceed.cpp += $(hip.cpp) 378 libceed.hip += $(hip.hip) 379 BACKENDS += $(HIP_BACKENDS) 380endif 381 382# MAGMA Backend 383ifneq ($(wildcard $(MAGMA_DIR)/lib/libmagma.*),) 384 ifneq ($(CUDA_LIB_DIR),) 385 cuda_link = -Wl,-rpath,$(CUDA_LIB_DIR) -L$(CUDA_LIB_DIR) -lcublas -lcusparse -lcudart 386 omp_link = -fopenmp 387 magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(cuda_link) $(omp_link) 388 magma_link_shared = -L$(MAGMA_DIR)/lib -Wl,-rpath,$(abspath $(MAGMA_DIR)/lib) -lmagma 389 magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static)) 390 $(libceeds) : LDLIBS += $(magma_link) 391 $(tests) $(examples) : LDLIBS += $(magma_link) 392 libceed.c += $(magma.c) 393 libceed.cu += $(magma.cu) 394 $(magma.c:%.c=$(OBJDIR)/%.o) $(magma.c:%=%.tidy) : CPPFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include 395 $(magma.cu:%.cu=$(OBJDIR)/%.o) : CPPFLAGS += --compiler-options=-fPIC -DADD_ -I$(MAGMA_DIR)/include -I$(MAGMA_DIR)/magmablas -I$(MAGMA_DIR)/control -I$(CUDA_DIR)/include 396 BACKENDS += /gpu/magma /gpu/magma/det 397 endif 398endif 399 400export BACKENDS 401 402libceed.o = $(libceed.c:%.c=$(OBJDIR)/%.o) $(libceed.cpp:%.cpp=$(OBJDIR)/%.o) $(libceed.cu:%.cu=$(OBJDIR)/%.o) $(libceed.hip:%.hip.cpp=$(OBJDIR)/%.o) 403$(filter %fortran.o,$(libceed.o)) : CPPFLAGS += $(if $(filter 1,$(UNDERSCORE)),-DUNDERSCORE) 404$(libceed.o): | info-backends 405$(libceed) : $(libceed.o) | $$(@D)/.DIR 406 $(call quiet,LINK) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS) 407 408$(OBJDIR)/%.o : $(CURDIR)/%.c | $$(@D)/.DIR 409 $(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<) 410 411$(OBJDIR)/%.o : $(CURDIR)/%.cpp | $$(@D)/.DIR 412 $(call quiet,CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(abspath $<) 413 414$(OBJDIR)/%.o : $(CURDIR)/%.cu | $$(@D)/.DIR 415 $(call quiet,NVCC) $(filter-out -Wno-unused-function, $(CPPFLAGS)) $(NVCCFLAGS) -c -o $@ $(abspath $<) 416 417$(OBJDIR)/%.o : $(CURDIR)/%.hip.cpp | $$(@D)/.DIR 418 $(call quiet,HIPCC) $(HIPCCFLAGS) -c -o $@ $(abspath $<) 419 420$(OBJDIR)/% : tests/%.c | $$(@D)/.DIR 421 $(call quiet,LINK.c) $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 422 423$(OBJDIR)/% : tests/%.f90 | $$(@D)/.DIR 424 $(call quiet,LINK.F) -DSOURCE_DIR='"$(abspath $(<D))/"' $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 425 426$(OBJDIR)/% : examples/ceed/%.c | $$(@D)/.DIR 427 $(call quiet,LINK.c) $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 428 429$(OBJDIR)/% : examples/ceed/%.f | $$(@D)/.DIR 430 $(call quiet,LINK.F) -DSOURCE_DIR='"$(abspath $(<D))/"' $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 431 432$(OBJDIR)/mfem-% : examples/mfem/%.cpp $(libceed) | $$(@D)/.DIR 433 +$(MAKE) -C examples/mfem CEED_DIR=`pwd` \ 434 MFEM_DIR="$(abspath $(MFEM_DIR))" CXX=$(CXX) $* 435 mv examples/mfem/$* $@ 436 437# Note: Multiple Nek files cannot be built in parallel. The '+' here enables 438# this single Nek bps file to be built in parallel with other examples, 439# such as when calling `make prove-all -j2`. 440$(OBJDIR)/nek-bps : examples/nek/bps/bps.usr examples/nek/nek-examples.sh $(libceed) | $$(@D)/.DIR 441 +$(MAKE) -C examples MPI=$(MPI) CEED_DIR=`pwd` NEK5K_DIR="$(abspath $(NEK5K_DIR))" nek 442 mv examples/nek/build/bps $(OBJDIR)/bps 443 cp examples/nek/nek-examples.sh $(OBJDIR)/nek-bps 444 445$(OBJDIR)/petsc-% : examples/petsc/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR 446 +$(MAKE) -C examples/petsc CEED_DIR=`pwd` \ 447 PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $* 448 mv examples/petsc/$* $@ 449 450$(OBJDIR)/fluids-% : examples/fluids/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR 451 +$(MAKE) -C examples/fluids CEED_DIR=`pwd` \ 452 PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $* 453 mv examples/fluids/$* $@ 454 455$(OBJDIR)/solids-% : examples/solids/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR 456 +$(MAKE) -C examples/solids CEED_DIR=`pwd` \ 457 PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $* 458 mv examples/solids/$* $@ 459 460libceed_test.o = $(test_backends.c:%.c=$(OBJDIR)/%.o) 461$(libceed_test) : $(libceed.o) $(libceed_test.o) | $$(@D)/.DIR 462 $(call quiet,LINK) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS) 463 464$(examples) : $(libceed) 465$(tests) : $(libceed_test) 466$(tests) : CEED_LIBS = -lceed_test 467$(tests) $(examples) : LDFLAGS += -Wl,-rpath,$(abspath $(LIBDIR)) -L$(LIBDIR) 468 469run-t% : BACKENDS += $(TEST_BACKENDS) 470run-% : $(OBJDIR)/% 471 @tests/tap.sh $(<:$(OBJDIR)/%=%) 472 473external_examples := \ 474 $(if $(MFEM_DIR),$(mfemexamples)) \ 475 $(if $(PETSC_DIR),$(petscexamples)) \ 476 $(if $(NEK5K_DIR),$(nekexamples)) \ 477 $(if $(PETSC_DIR),$(fluidsexamples)) \ 478 $(if $(PETSC_DIR),$(solidsexamples)) 479 480allexamples = $(examples) $(external_examples) 481 482# The test and prove targets can be controlled via pattern searches. The 483# default is to run tests and those examples that have no external dependencies. 484# Examples of finer grained control: 485# 486# make test search='petsc mfem' # PETSc and MFEM examples 487# make prove search='t3' # t3xx series tests 488# make junit search='ex petsc' # core ex* and PETSc tests 489search ?= t ex 490realsearch = $(search:%=%%) 491matched = $(foreach pattern,$(realsearch),$(filter $(OBJDIR)/$(pattern),$(tests) $(allexamples))) 492 493# Test core libCEED 494test : $(matched:$(OBJDIR)/%=run-%) 495 496# Run test target in parallel 497tst : ;@$(MAKE) $(MFLAGS) V=$(V) test 498# CPU C tests only for backend % 499ctc-% : $(ctests);@$(foreach tst,$(ctests),$(tst) /cpu/$*;) 500 501prove : BACKENDS += $(TEST_BACKENDS) 502prove : $(matched) 503 $(info Testing backends: $(BACKENDS)) 504 $(PROVE) $(PROVE_OPTS) --exec 'tests/tap.sh' $(matched:$(OBJDIR)/%=%) 505# Run prove target in parallel 506prv : ;@$(MAKE) $(MFLAGS) V=$(V) prove 507 508prove-all : 509 +$(MAKE) prove realsearch=% 510 511junit-t% : BACKENDS += $(TEST_BACKENDS) 512junit-% : $(OBJDIR)/% 513 @printf " %10s %s\n" TEST $(<:$(OBJDIR)/%=%); $(PYTHON) tests/junit.py $(<:$(OBJDIR)/%=%) 514 515junit : $(matched:$(OBJDIR)/%=junit-%) 516 517all: $(alltests) 518 519examples : $(allexamples) 520ceedexamples : $(examples) 521nekexamples : $(nekexamples) 522mfemexamples : $(mfemexamples) 523petscexamples : $(petscexamples) 524 525# Benchmarks 526allbenchmarks = petsc-bps 527bench_targets = $(addprefix bench-,$(allbenchmarks)) 528.PHONY: $(bench_targets) benchmarks 529$(bench_targets): bench-%: $(OBJDIR)/% 530 cd benchmarks && ./benchmark.sh --ceed "$(BACKENDS)" -r $(*).sh 531benchmarks: $(bench_targets) 532 533$(ceed.pc) : pkgconfig-prefix = $(abspath .) 534$(OBJDIR)/ceed.pc : pkgconfig-prefix = $(prefix) 535.INTERMEDIATE : $(OBJDIR)/ceed.pc 536%/ceed.pc : ceed.pc.template | $$(@D)/.DIR 537 @sed "s:%prefix%:$(pkgconfig-prefix):" $< > $@ 538 539install : $(libceed) $(OBJDIR)/ceed.pc 540 $(INSTALL) -d $(addprefix $(if $(DESTDIR),"$(DESTDIR)"),"$(includedir)"\ 541 "$(libdir)" "$(pkgconfigdir)") 542 $(INSTALL_DATA) include/ceed.h "$(DESTDIR)$(includedir)/" 543 $(INSTALL_DATA) include/ceedf.h "$(DESTDIR)$(includedir)/" 544 $(INSTALL_DATA) $(libceed) "$(DESTDIR)$(libdir)/" 545 $(INSTALL_DATA) $(OBJDIR)/ceed.pc "$(DESTDIR)$(pkgconfigdir)/" 546 547.PHONY : cln clean doxygen doc lib install all print test tst prove prv prove-all junit examples style style-c style-py tidy info info-backends 548 549cln clean : 550 $(RM) -r $(OBJDIR) $(LIBDIR) dist *egg* .pytest_cache *cffi* 551 $(MAKE) -C examples clean NEK5K_DIR="$(abspath $(NEK5K_DIR))" 552 $(MAKE) -C tests/python clean 553 $(RM) benchmarks/*output.txt 554 555distclean : clean 556 $(RM) -r doc/html doc/sphinx/build $(CONFIG) 557 558DOXYGEN ?= doxygen 559doxygen : 560 $(DOXYGEN) Doxyfile 561 562doc-html doc-latexpdf doc-epub : doc-% : doxygen 563 make -C doc/sphinx $* 564 565doc : doc-html 566 567style-c : 568 @astyle --options=.astylerc \ 569 $(filter-out include/ceedf.h $(wildcard tests/t*-f.h), \ 570 $(wildcard include/*.h interface/*.[ch] tests/*.[ch] backends/*/*.[ch] \ 571 examples/*/*/*.[ch] examples/*/*.[ch] examples/*/*.[ch]pp gallery/*/*.[ch])) 572 573AUTOPEP8 = autopep8 574style-py : AUTOPEP8_ARGS = --in-place --aggressive 575style-py : 576 @$(AUTOPEP8) $(AUTOPEP8_ARGS) $(wildcard *.py python**/*.py tests/python**/*.py examples**/*.py doc/sphinx/source**/*.py benchmarks/*.py) 577 578style : style-c style-py 579 580CLANG_TIDY ?= clang-tidy 581 582%.c.tidy : %.c 583 $(CLANG_TIDY) $(TIDY_OPTS) $^ -- $(CPPFLAGS) --std=c99 -I$(CUDA_DIR)/include 584 585%.cpp.tidy : %.cpp 586 $(CLANG_TIDY) $(TIDY_OPTS) $^ -- $(CPPFLAGS) --std=c++11 -I$(CUDA_DIR)/include -I$(OCCA_DIR)/include 587 588tidy_c : $(libceed.c:%=%.tidy) 589tidy_cpp : $(libceed.cpp:%=%.tidy) 590 591tidy : tidy_c tidy_cpp 592 593print : 594 @echo $(VAR)=$($(VAR)) 595 596print-% : 597 $(info [ variable name]: $*) 598 $(info [ origin]: $(origin $*)) 599 $(info [ flavor]: $(flavor $*)) 600 $(info [ value]: $(value $*)) 601 $(info [expanded value]: $($*)) 602 $(info ) 603 @true 604 605# "make configure" detects any variables passed on the command line or 606# previously set in config.mk, caching them in config.mk as simple 607# (:=) variables. Variables set in config.mk or on the command line 608# take precedence over the defaults provided in the file. Typical 609# usage: 610# 611# make configure CC=/path/to/my/cc CUDA_DIR=/opt/cuda 612# make 613# make prove 614# 615# The values in the file can be updated by passing them on the command 616# line, e.g., 617# 618# make configure CC=/path/to/other/clang 619 620# All variables to consider for caching 621CONFIG_VARS = CC CXX FC NVCC NVCC_CXX HIPCC \ 622 OPT CFLAGS CPPFLAGS CXXFLAGS FFLAGS NVCCFLAGS HIPCCFLAGS \ 623 LDFLAGS LDLIBS \ 624 MAGMA_DIR XSMM_DIR CUDA_DIR MFEM_DIR PETSC_DIR NEK5K_DIR HIP_DIR 625 626# $(call needs_save,CFLAGS) returns true (a nonempty string) if CFLAGS 627# was set on the command line or in config.mk (where it will appear as 628# a simple variable). 629needs_save = $(or $(filter command line,$(origin $(1))),$(filter simple,$(flavor $(1)))) 630 631configure : 632 $(file > $(CONFIG)) 633 $(foreach v,$(CONFIG_VARS),$(if $(call needs_save,$(v)),$(file >> $(CONFIG),$(v) := $($(v))))) 634 @echo "Configuration cached in $(CONFIG):" 635 @cat $(CONFIG) 636 637wheel : export MARCHFLAG = -march=generic 638wheel : export WHEEL_PLAT = manylinux2010_x86_64 639wheel : 640 docker run -it --user $(shell id -u):$(shell id -g) --rm -v $(PWD):/io -w /io \ 641 -e MARCHFLAG -e WHEEL_PLAT \ 642 quay.io/pypa/$(WHEEL_PLAT) python/make-wheels.sh 643 644.PHONY : configure wheel 645 646# Include *.d deps when not -B = --always-make: useful if the paths are wonky in a container 647-include $(if $(filter B,$(MAKEFLAGS)),,$(libceed.c:%.c=$(OBJDIR)/%.d) $(tests.c:tests/%.c=$(OBJDIR)/%.d)) 648