1# Copyright (c) 2017-2026, Lawrence Livermore National Security, LLC and other CEED contributors. 2# All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3# 4# SPDX-License-Identifier: BSD-2-Clause 5# 6# This file is part of CEED: http://github.com/ceed 7 8# ------------------------------------------------------------ 9# Configuration 10# ------------------------------------------------------------ 11 12# config.mk stores cached configuration variables 13CONFIG ?= config.mk 14-include $(CONFIG) 15 16# common.mk holds definitions used in various makefiles throughout the project 17COMMON ?= common.mk 18-include $(COMMON) 19 20# Quiet, color output 21quiet ?= $($(1)) 22 23# Cancel built-in and old-fashioned implicit rules which we don't use 24.SUFFIXES: 25 26.SECONDEXPANSION: # to expand $$(@D)/.DIR 27 28%/.DIR : 29 @mkdir -p $(@D) 30 @touch $@ 31 32.PRECIOUS: %/.DIR 33 34 35DARWIN := $(filter Darwin,$(shell uname -s)) 36 37 38# ------------------------------------------------------------ 39# Root directories for backend dependencies 40# ------------------------------------------------------------ 41 42# XSMM_DIR env variable should point to XSMM main (github.com/hfp/libxsmm) 43XSMM_DIR ?= ../libxsmm 44 45# Often /opt/cuda or /usr/local/cuda, but sometimes present on machines that don't support CUDA 46CUDA_DIR ?= 47CUDA_ARCH ?= 48 49# Often /opt/rocm, but sometimes present on machines that don't support HIP 50ROCM_DIR ?= 51HIP_ARCH ?= 52 53# env variable MAGMA_DIR can be used too 54MAGMA_DIR ?= ../magma 55 56 57# ------------------------------------------------------------ 58# Compiler flags 59# ------------------------------------------------------------ 60 61# Detect user compiler options and set defaults 62ifeq (,$(filter-out undefined default,$(origin CC))) 63 CC = gcc 64endif 65ifeq (,$(filter-out undefined default,$(origin CXX))) 66 CXX = g++ 67endif 68ifeq (,$(filter-out undefined default,$(origin FC))) 69 FC = gfortran 70endif 71ifeq (,$(filter-out undefined default,$(origin LINK))) 72 LINK = $(CC) 73endif 74ifeq (,$(filter-out undefined default,$(origin AR))) 75 AR = ar 76endif 77ifeq (,$(filter-out undefined default,$(origin ARFLAGS))) 78 ARFLAGS = $(if $(DARWIN),cr,crD) 79endif 80NVCC ?= $(CUDA_DIR)/bin/nvcc 81NVCC_CXX ?= $(CXX) 82HIPCC ?= $(ROCM_DIR)/bin/hipcc 83SYCLCXX ?= $(CXX) 84SED ?= sed 85ifneq ($(EMSCRIPTEN),) 86 STATIC = 1 87 EXE_SUFFIX = .wasm 88 EM_LDFLAGS = -s TOTAL_MEMORY=256MB 89endif 90 91# ASAN must be left empty if you don't want to use it 92ASAN ?= 93 94# These are the values automatically detected here in the makefile. They are 95# augmented with LDFLAGS and LDLIBS from the environment/passed by command line, 96# if any. If the user sets CEED_LDFLAGS or CEED_LDLIBS, they are used *instead 97# of* what we populate here (thus that's advanced usage and not recommended). 98CEED_LDFLAGS ?= 99CEED_LDLIBS ?= 100 101UNDERSCORE ?= 1 102 103# Verbose mode, V or VERBOSE 104V ?= $(VERBOSE) 105 106# SANTIZ options 107AFLAGS ?= -fsanitize=address #-fsanitize=undefined -fno-omit-frame-pointer 108 109# Note: Intel oneAPI C/C++ compiler is now icx/icpx 110CC_VENDOR := $(firstword $(filter gcc (GCC) clang cc icc icc_orig oneAPI XL emcc,$(subst -, ,$(shell $(CC) --version)))) 111CC_VENDOR := $(subst (GCC),gcc,$(subst icc_orig,icc,$(CC_VENDOR))) 112CC_VENDOR := $(if $(filter cc,$(CC_VENDOR)),gcc,$(CC_VENDOR)) 113FC_VENDOR := $(if $(FC),$(firstword $(filter GNU ifort ifx XL,$(shell $(FC) --version 2>&1 || $(FC) -qversion)))) 114 115# Host architecture for setting appropriate flags 116UNAME_M := $(shell uname -m) 117 118# Default extra flags by vendor 119# GCC: use -march=native only on x86 (where -mcpu doesn't exist); use -mcpu=native elsewhere 120MARCHFLAG.gcc := $(if $(filter x86_64 i%86,$(UNAME_M)),-march=native,-mcpu=native) 121MARCHFLAG.clang := $(MARCHFLAG.gcc) 122MARCHFLAG.icc := 123MARCHFLAG.oneAPI := $(MARCHFLAG.clang) 124OMP_SIMD_FLAG.gcc := -fopenmp-simd 125OMP_SIMD_FLAG.clang := $(OMP_SIMD_FLAG.gcc) 126OMP_SIMD_FLAG.icc := -qopenmp-simd 127OMP_SIMD_FLAG.oneAPI := $(OMP_SIMD_FLAG.icc) 128OMP_FLAG.gcc := -fopenmp 129OMP_FLAG.clang := $(OMP_FLAG.gcc) 130OMP_FLAG.icc := -qopenmp 131OMP_FLAG.oneAPI := $(OMP_FLAG.icc) 132SYCL_FLAG.gcc := 133SYCL_FLAG.clang := -fsycl 134SYCL_FLAG.icc := 135SYCL_FLAG.oneAPI := -fsycl -fno-sycl-id-queries-fit-in-int 136OPT.gcc := -g -ffp-contract=fast 137OPT.clang := $(OPT.gcc) 138OPT.icc := $(OPT.gcc) 139OPT.oneAPI := $(OPT.clang) 140OPT.emcc := 141CFLAGS.gcc := $(if $(STATIC),,-fPIC) -std=c11 -Wall -Wextra -Wno-unused-parameter -MMD -MP 142CFLAGS.clang := $(CFLAGS.gcc) 143CFLAGS.icc := $(CFLAGS.gcc) 144CFLAGS.oneAPI := $(CFLAGS.clang) 145CFLAGS.XL := $(if $(STATIC),,-qpic) -MMD 146CFLAGS.emcc := $(CFLAGS.clang) 147CXXFLAGS.gcc := $(if $(STATIC),,-fPIC) -std=c++11 -Wall -Wextra -Wno-unused-parameter -MMD -MP 148CXXFLAGS.clang := $(CXXFLAGS.gcc) 149CXXFLAGS.icc := $(CXXFLAGS.gcc) 150CXXFLAGS.oneAPI := $(CXXFLAGS.clang) 151CXXFLAGS.XL := $(if $(STATIC),,-qpic) -std=c++11 -MMD 152CXXFLAGS.emcc := $(CXXFLAGS.clang) 153FFLAGS.GNU := $(if $(STATIC),,-fPIC) -cpp -Wall -Wextra -Wno-unused-parameter -Wno-unused-dummy-argument -MMD -MP 154FFLAGS.ifort := $(if $(STATIC),,-fPIC) -cpp 155FFLAGS.ifx := $(FFLAGS.ifort) 156FFLAGS.XL := $(if $(STATIC),,-qpic) -ffree-form -qpreprocess -qextname -MMD 157 158# This check works with compilers that use gcc and clang. It fails with some 159# compilers; e.g., xlc apparently ignores all options when -E is passed, thus 160# succeeds with any flags. Users can pass MARCHFLAG=... if desired. 161cc_check_flag = $(shell $(CC) -E -Werror $(1) -x c /dev/null > /dev/null 2>&1 && echo 1) 162MARCHFLAG := $(MARCHFLAG.$(CC_VENDOR)) 163MARCHFLAG := $(if $(call cc_check_flag,$(MARCHFLAG)),$(MARCHFLAG),-mcpu=native) 164MARCHFLAG := $(if $(call cc_check_flag,$(MARCHFLAG)),$(MARCHFLAG)) 165 166OMP_SIMD_FLAG := $(OMP_SIMD_FLAG.$(CC_VENDOR)) 167OMP_SIMD_FLAG := $(if $(call cc_check_flag,$(OMP_SIMD_FLAG)),$(OMP_SIMD_FLAG)) 168 169# Error checking flags 170PEDANTIC ?= 171PEDANTICFLAGS ?= -Werror -pedantic 172 173# Compiler flags 174OPT ?= -O $(MARCHFLAG) $(OPT.$(CC_VENDOR)) $(OMP_SIMD_FLAG) 175CFLAGS ?= $(OPT) $(CFLAGS.$(CC_VENDOR)) $(if $(PEDANTIC),$(PEDANTICFLAGS)) 176CXXFLAGS ?= $(OPT) $(CXXFLAGS.$(CC_VENDOR)) $(if $(PEDANTIC),$(PEDANTICFLAGS)) 177FFLAGS ?= $(OPT) $(FFLAGS.$(FC_VENDOR)) 178LIBCXX ?= -lstdc++ 179NVCCFLAGS ?= -ccbin $(CXX) -Xcompiler '$(OPT)' -Xcompiler -fPIC 180ifneq ($(CUDA_ARCH),) 181 NVCCFLAGS += -arch=$(CUDA_ARCH) 182endif 183HIPCCFLAGS ?= $(filter-out $(OMP_SIMD_FLAG),$(OPT)) -fPIC -munsafe-fp-atomics 184ifneq ($(HIP_ARCH),) 185 HIPCCFLAGS += --offload-arch=$(HIP_ARCH) 186endif 187SYCL_FLAG := $(SYCL_FLAG.$(CC_VENDOR)) 188SYCLFLAGS ?= $(SYCL_FLAG) -fPIC -std=c++17 $(filter-out -std=c++11,$(CXXFLAGS)) $(filter-out $(OMP_SIMD_FLAG),$(OPT)) 189 190OPENMP ?= 191ifneq ($(OPENMP),) 192 OMP_FLAG := $(OMP_FLAG.$(CC_VENDOR)) 193 OMP_FLAG := $(if $(call cc_check_flag,$(OMP_FLAG)),$(OMP_FLAG)) 194 CFLAGS += $(OMP_FLAG) 195 CEED_LDFLAGS += $(OMP_FLAG) 196endif 197 198ifeq ($(COVERAGE), 1) 199 CFLAGS += --coverage 200 CXXFLAGS += --coverage 201 CEED_LDFLAGS += --coverage 202endif 203 204CFLAGS += $(if $(ASAN),$(AFLAGS)) 205FFLAGS += $(if $(ASAN),$(AFLAGS)) 206CEED_LDFLAGS += $(if $(ASAN),$(AFLAGS)) 207CPPFLAGS += -I./include 208CEED_LDLIBS = -lm 209OBJDIR := build 210for_install := $(filter install,$(MAKECMDGOALS)) 211LIBDIR := $(if $(for_install),$(OBJDIR),lib) 212 213# Installation variables 214prefix ?= /usr/local 215bindir = $(prefix)/bin 216libdir = $(prefix)/lib 217includedir = $(prefix)/include 218pkgconfigdir = $(libdir)/pkgconfig 219INSTALL = install 220INSTALL_PROGRAM = $(INSTALL) 221INSTALL_DATA = $(INSTALL) -m644 222 223# Get number of processors of the machine 224NPROCS := $(shell getconf _NPROCESSORS_ONLN) 225# prepare make options to run in parallel 226MFLAGS := -j $(NPROCS) --warn-undefined-variables \ 227 --no-print-directory --no-keep-going 228 229PYTHON ?= python3 230PROVE ?= prove 231PROVE_OPTS ?= -j $(NPROCS) 232SO_EXT := $(if $(DARWIN),dylib,so) 233 234ceed.pc := $(LIBDIR)/pkgconfig/ceed.pc 235libceed.so := $(LIBDIR)/libceed.$(SO_EXT) 236libceed.a := $(LIBDIR)/libceed.a 237libceed := $(if $(STATIC),$(libceed.a),$(libceed.so)) 238CEED_LIBS = -lceed 239libceeds = $(libceed) 240BACKENDS_BUILTIN := /cpu/self/ref/serial /cpu/self/ref/blocked /cpu/self/opt/serial /cpu/self/opt/blocked 241BACKENDS_MAKE := $(BACKENDS_BUILTIN) 242 243 244# ------------------------------------------------------------ 245# Root directories for examples using external libraries 246# ------------------------------------------------------------ 247 248# DEAL_II_DIR env variable should point to sibling directory 249ifneq ($(wildcard ../dealii/install/lib/libdeal_II.*),) 250 DEAL_II_DIR ?= ../dealii/install 251endif 252# Export for deal.II testing 253export DEAL_II_DIR 254 255# MFEM_DIR env variable should point to sibling directory 256ifneq ($(wildcard ../mfem/libmfem.*),) 257 MFEM_DIR ?= ../mfem 258endif 259 260# NEK5K_DIR env variable should point to sibling directory 261ifneq ($(wildcard ../Nek5000/*),) 262 NEK5K_DIR ?= $(abspath ../Nek5000) 263endif 264# Exports for NEK5K testing 265export CEED_DIR = $(abspath .) 266export NEK5K_DIR 267MPI ?= 1 268 269# Check for PETSc in ../petsc 270ifneq ($(wildcard ../petsc/lib/libpetsc.*),) 271 PETSC_DIR ?= ../petsc 272endif 273 274# ------------------------------------------------------------ 275# Build the library (default target) 276# ------------------------------------------------------------ 277 278lib: $(libceed) $(ceed.pc) 279# run 'lib' target in parallel 280par:;@$(MAKE) $(MFLAGS) V=$(V) lib 281 282$(libceed.so) : CEED_LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed.so))) 283 284# ------------------------------------------------------------ 285# Source files 286# ------------------------------------------------------------ 287 288# Interface and gallery 289libceed.c := $(filter-out interface/ceed-cuda.c interface/ceed-hip.c interface/ceed-jit-source-root-$(if $(for_install),default,install).c, $(wildcard interface/ceed*.c backends/weak/*.c gallery/*.c)) 290gallery.c := $(wildcard gallery/*/ceed*.c) 291libceed.c += $(gallery.c) 292 293# Backends 294# - CPU 295ref.c := $(sort $(wildcard backends/ref/*.c)) 296blocked.c := $(sort $(wildcard backends/blocked/*.c)) 297ceedmemcheck.c := $(sort $(wildcard backends/memcheck/*.c)) 298opt.c := $(sort $(wildcard backends/opt/*.c)) 299avx.c := $(sort $(wildcard backends/avx/*.c)) 300xsmm.c := $(sort $(wildcard backends/xsmm/*.c)) 301# - GPU 302cuda.c := $(sort $(wildcard backends/cuda/*.c)) 303cuda.cpp := $(sort $(wildcard backends/cuda/*.cpp)) 304cuda-ref.c := $(sort $(wildcard backends/cuda-ref/*.c)) 305cuda-ref.cpp := $(sort $(wildcard backends/cuda-ref/*.cpp)) 306cuda-ref.cu := $(sort $(wildcard backends/cuda-ref/kernels/*.cu)) 307cuda-shared.c := $(sort $(wildcard backends/cuda-shared/*.c)) 308cuda-gen.c := $(sort $(wildcard backends/cuda-gen/*.c)) 309cuda-gen.cpp := $(sort $(wildcard backends/cuda-gen/*.cpp)) 310cuda-all.c := interface/ceed-cuda.c $(cuda.c) $(cuda-ref.c) $(cuda-shared.c) $(cuda-gen.c) 311cuda-all.cpp := $(cuda.cpp) $(cuda-ref.cpp) $(cuda-gen.cpp) 312cuda-all.cu := $(cuda-ref.cu) 313hip.c := $(sort $(wildcard backends/hip/*.c)) 314hip.cpp := $(sort $(wildcard backends/hip/*.cpp)) 315hip-ref.c := $(sort $(wildcard backends/hip-ref/*.c)) 316hip-ref.cpp := $(sort $(wildcard backends/hip-ref/*.cpp)) 317hip-ref.hip := $(sort $(wildcard backends/hip-ref/kernels/*.hip.cpp)) 318hip-shared.c := $(sort $(wildcard backends/hip-shared/*.c)) 319hip-gen.c := $(sort $(wildcard backends/hip-gen/*.c)) 320hip-gen.cpp := $(sort $(wildcard backends/hip-gen/*.cpp)) 321hip-all.c := interface/ceed-hip.c $(hip.c) $(hip-ref.c) $(hip-shared.c) $(hip-gen.c) 322hip-all.cpp := $(hip.cpp) $(hip-ref.cpp) $(hip-gen.cpp) 323hip-all.hip := $(hip-ref.hip) 324sycl-core.cpp := $(sort $(wildcard backends/sycl/*.sycl.cpp)) 325sycl-ref.cpp := $(sort $(wildcard backends/sycl-ref/*.sycl.cpp)) 326sycl-shared.cpp:= $(sort $(wildcard backends/sycl-shared/*.sycl.cpp)) 327sycl-gen.cpp := $(sort $(wildcard backends/sycl-gen/*.sycl.cpp)) 328magma.c := $(sort $(wildcard backends/magma/*.c)) 329magma.cpp := $(sort $(wildcard backends/magma/*.cpp)) 330 331# Tests 332tests.c := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.c)) 333tests.f := $(if $(FC),$(sort $(wildcard tests/t[0-9][0-9][0-9]-*.f90))) 334tests := $(tests.c:tests/%.c=$(OBJDIR)/%$(EXE_SUFFIX)) 335ctests := $(tests) 336tests += $(tests.f:tests/%.f90=$(OBJDIR)/%$(EXE_SUFFIX)) 337 338# Examples 339examples.c := $(sort $(wildcard examples/ceed/*.c)) 340examples.f := $(if $(FC),$(sort $(wildcard examples/ceed/*.f90))) 341examples := $(examples.c:examples/ceed/%.c=$(OBJDIR)/%$(EXE_SUFFIX)) 342examples += $(examples.f:examples/ceed/%.f90=$(OBJDIR)/%$(EXE_SUFFIX)) 343 344# deal.II Examples 345dealiiexamples := $(OBJDIR)/dealii-bps 346 347# MFEM Examples 348mfemexamples.cpp := $(sort $(wildcard examples/mfem/*.cpp)) 349mfemexamples := $(mfemexamples.cpp:examples/mfem/%.cpp=$(OBJDIR)/mfem-%) 350 351# Nek5K Examples 352nekexamples := $(OBJDIR)/nek-bps 353 354# Rust QFunction Examples 355rustqfunctions.c := $(sort $(wildcard examples/rust-qfunctions/*.c)) 356rustqfunctionsexamples := $(rustqfunctions.c:examples/rust-qfunctions/%.c=$(OBJDIR)/rustqfunctions-%) 357 358# PETSc Examples 359petscexamples.c := $(wildcard examples/petsc/*.c) 360petscexamples := $(petscexamples.c:examples/petsc/%.c=$(OBJDIR)/petsc-%) 361 362# Fluid Dynamics Example 363fluidsexamples.c := $(sort $(wildcard examples/fluids/*.c)) 364fluidsexamples := $(fluidsexamples.c:examples/fluids/%.c=$(OBJDIR)/fluids-%) 365 366# Solid Mechanics Example 367solidsexamples.c := $(sort $(wildcard examples/solids/*.c)) 368solidsexamples := $(solidsexamples.c:examples/solids/%.c=$(OBJDIR)/solids-%) 369 370 371# ------------------------------------------------------------ 372# View configuration options 373# ------------------------------------------------------------ 374 375backend_status = $(if $(filter $1,$(BACKENDS_MAKE)), [backends: $1], [not found]) 376 377info-basic: 378 $(info -----------------------------------------) 379 $(info | ___ __ ______________________ |) 380 $(info | / (_) /_ / ____/ ____/ ____/ __ \ |) 381 $(info | / / / __ \/ / / __/ / __/ / / / / |) 382 $(info | / / / /_/ / /___/ /___/ /___/ /_/ / |) 383 $(info | /_/_/_.___/\____/_____/_____/_____/ |) 384 $(info -----------------------------------------) 385 $(info ) 386 $(info -----------------------------------------) 387 $(info ) 388 $(info Built-in Backends:) 389 $(info $(BACKENDS_BUILTIN)) 390 $(info ) 391 $(info Additional Backends:) 392 $(info $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS))) 393 $(info ) 394 $(info -----------------------------------------) 395 $(info ) 396 @true 397 398info: 399 $(info -----------------------------------------) 400 $(info | ___ __ ______________________ |) 401 $(info | / (_) /_ / ____/ ____/ ____/ __ \ |) 402 $(info | / / / __ \/ / / __/ / __/ / / / / |) 403 $(info | / / / /_/ / /___/ /___/ /___/ /_/ / |) 404 $(info | /_/_/_.___/\____/_____/_____/_____/ |) 405 $(info -----------------------------------------) 406 $(info ) 407 $(info -----------------------------------------) 408 $(info ) 409 $(info Built-in Backends:) 410 $(info $(BACKENDS_BUILTIN)) 411 $(info ) 412 $(info Additional Backends:) 413 $(info $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS))) 414 $(info ) 415 $(info -----------------------------------------) 416 $(info ) 417 $(info Compiler Flags:) 418 $(info CC = $(CC)) 419 $(info CXX = $(CXX)) 420 $(info FC = $(FC)) 421 $(info CPPFLAGS = $(CPPFLAGS)) 422 $(info CFLAGS = $(CFLAGS)) 423 $(info CXXFLAGS = $(CXXFLAGS)) 424 $(info FFLAGS = $(FFLAGS)) 425 $(info NVCCFLAGS = $(NVCCFLAGS)) 426 $(info HIPCCFLAGS = $(HIPCCFLAGS)) 427 $(info SYCLFLAGS = $(SYCLFLAGS)) 428 $(info CEED_LDFLAGS = $(CEED_LDFLAGS)) 429 $(info CEED_LDLIBS = $(CEED_LDLIBS)) 430 $(info AR = $(AR)) 431 $(info ARFLAGS = $(ARFLAGS)) 432 $(info OPT = $(OPT)) 433 $(info AFLAGS = $(AFLAGS)) 434 $(info ASAN = $(or $(ASAN),(empty))) 435 $(info VERBOSE = $(or $(V),(empty)) [verbose=$(if $(V),on,off)]) 436 $(info ) 437 $(info -----------------------------------------) 438 $(info ) 439 $(info Backend Dependencies:) 440 $(info MEMCHK_STATUS = $(MEMCHK_STATUS)$(call backend_status,$(MEMCHK_BACKENDS))) 441 $(info AVX_STATUS = $(AVX_STATUS)$(call backend_status,$(AVX_BACKENDS))) 442 $(info XSMM_DIR = $(XSMM_DIR)$(call backend_status,$(XSMM_BACKENDS))) 443 $(info CUDA_DIR = $(CUDA_DIR)$(call backend_status,$(CUDA_BACKENDS))) 444 $(info ROCM_DIR = $(ROCM_DIR)$(call backend_status,$(HIP_BACKENDS))) 445 $(info SYCL_DIR = $(SYCL_DIR)$(call backend_status,$(SYCL_BACKENDS))) 446 $(info MAGMA_DIR = $(MAGMA_DIR)$(call backend_status,$(MAGMA_BACKENDS))) 447 $(info ) 448 $(info -----------------------------------------) 449 $(info ) 450 $(info Example Dependencies:) 451 $(info MFEM_DIR = $(MFEM_DIR)) 452 $(info NEK5K_DIR = $(NEK5K_DIR)) 453 $(info PETSC_DIR = $(PETSC_DIR)) 454 $(info DEAL_II_DIR = $(DEAL_II_DIR)) 455 $(info ) 456 $(info -----------------------------------------) 457 $(info ) 458 $(info Install Options:) 459 $(info prefix = $(prefix)) 460 $(info includedir = $(value includedir)) 461 $(info libdir = $(value libdir)) 462 $(info pkgconfigdir = $(value pkgconfigdir)) 463 $(info ) 464 $(info -----------------------------------------) 465 $(info ) 466 $(info Git:) 467 $(info describe = $(GIT_DESCRIBE)) 468 $(info ) 469 $(info -----------------------------------------) 470 @true 471 472info-backends: 473 $(info make: 'lib' with optional backends: $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS))) 474 @true 475 476info-backends-all: 477 $(info make: 'lib' with backends: $(BACKENDS)) 478 @true 479 480 481# ------------------------------------------------------------ 482# Backends 483# ------------------------------------------------------------ 484 485# Standard Backends 486libceed.c += $(ref.c) 487libceed.c += $(blocked.c) 488libceed.c += $(opt.c) 489 490# Memcheck Backends 491MEMCHK_STATUS = Disabled 492MEMCHK := $(shell echo "$(HASH)include <valgrind/memcheck.h>" | $(CC) $(CPPFLAGS) -E - >/dev/null 2>&1 && echo 1) 493MEMCHK_BACKENDS = /cpu/self/memcheck/serial /cpu/self/memcheck/blocked 494ifeq ($(MEMCHK),1) 495 MEMCHK_STATUS = Enabled 496 libceed.c += $(ceedmemcheck.c) 497 BACKENDS_MAKE += $(MEMCHK_BACKENDS) 498endif 499 500# AVX Backeds 501AVX_STATUS = Disabled 502AVX_FLAG := $(if $(filter clang,$(CC_VENDOR)),+avx,-mavx) 503AVX := $(filter $(AVX_FLAG),$(shell $(CC) $(CFLAGS:-M%=) -v -E -x c /dev/null 2>&1)) 504AVX_BACKENDS = /cpu/self/avx/serial /cpu/self/avx/blocked 505ifneq ($(AVX),) 506 AVX_STATUS = Enabled 507 libceed.c += $(avx.c) 508 BACKENDS_MAKE += $(AVX_BACKENDS) 509endif 510 511# Collect list of libraries and paths for use in linking and pkg-config 512PKG_LIBS = 513# Stubs that will not be RPATH'd 514PKG_STUBS_LIBS = 515 516# libXSMM Backends 517XSMM_BACKENDS = /cpu/self/xsmm/serial /cpu/self/xsmm/blocked 518ifneq ($(wildcard $(XSMM_DIR)/lib/libxsmm.*),) 519 PKG_LIBS += -L$(abspath $(XSMM_DIR))/lib -lxsmm 520 MKL ?= 521 ifeq (,$(MKL)$(MKLROOT)) 522 BLAS_LIB ?= -lblas -ldl 523 else 524 ifneq ($(MKLROOT),) 525 # Some installs put everything inside an intel64 subdirectory, others not 526 MKL_LIBDIR = $(dir $(firstword $(wildcard $(MKLROOT)/lib/intel64/libmkl_sequential.* $(MKLROOT)/lib/libmkl_sequential.*))) 527 MKL_LINK = -L$(MKL_LIBDIR) 528 endif 529 BLAS_LIB ?= $(MKL_LINK) -Wl,--push-state,--no-as-needed -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl -Wl,--pop-state 530 endif 531 PKG_LIBS += $(BLAS_LIB) 532 libceed.c += $(xsmm.c) 533 $(xsmm.c:%.c=$(OBJDIR)/%.o) $(xsmm.c:%=%.tidy) : CPPFLAGS += -I$(XSMM_DIR)/include 534 BACKENDS_MAKE += $(XSMM_BACKENDS) 535endif 536 537# CUDA Backends 538ifneq ($(CUDA_DIR),) 539 CUDA_LIB_DIR := $(wildcard $(foreach d,lib lib64 lib/x86_64-linux-gnu,$(CUDA_DIR)/$d/libcudart.${SO_EXT})) 540 CUDA_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(CUDA_LIB_DIR)))) 541endif 542CUDA_LIB_DIR_STUBS := $(CUDA_LIB_DIR)/stubs 543CUDA_BACKENDS = /gpu/cuda/ref /gpu/cuda/shared /gpu/cuda/gen 544ifneq ($(CUDA_LIB_DIR),) 545 $(libceeds) : CPPFLAGS += -I$(CUDA_DIR)/include 546 PKG_LIBS += -L$(abspath $(CUDA_LIB_DIR)) -lcudart -lnvrtc -lcuda -lcublas 547 PKG_STUBS_LIBS += -L$(CUDA_LIB_DIR_STUBS) 548 LIBCEED_CONTAINS_CXX = 1 549 libceed.c += interface/ceed-cuda.c 550 libceed.c += $(cuda-all.c) 551 libceed.cpp += $(cuda-all.cpp) 552 libceed.cu += $(cuda-all.cu) 553 BACKENDS_MAKE += $(CUDA_BACKENDS) 554endif 555 556# HIP Backends 557HIP_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(ROCM_DIR)/$d/libamdhip64.${SO_EXT})) 558HIP_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(HIP_LIB_DIR)))) 559HIP_BACKENDS = /gpu/hip/ref /gpu/hip/shared /gpu/hip/gen 560ifneq ($(HIP_LIB_DIR),) 561 HIPCONFIG_CPPFLAGS := $(subst =,,$(shell $(ROCM_DIR)/bin/hipconfig -C)) 562 $(hip-all.c:%.c=$(OBJDIR)/%.o) $(hip-all.c:%=%.tidy): CPPFLAGS += $(HIPCONFIG_CPPFLAGS) 563 ifneq ($(CXX), $(HIPCC)) 564 $(hip-all.cpp:%.cpp=$(OBJDIR)/%.o) $(hip-all.cpp:%=%.tidy): CPPFLAGS += $(HIPCONFIG_CPPFLAGS) 565 endif 566 PKG_LIBS += -L$(abspath $(HIP_LIB_DIR)) -lamdhip64 -lhipblas 567 LIBCEED_CONTAINS_CXX = 1 568 libceed.c += $(hip-all.c) 569 libceed.cpp += $(hip-all.cpp) 570 libceed.hip += $(hip-all.hip) 571 BACKENDS_MAKE += $(HIP_BACKENDS) 572endif 573 574# SYCL Backends 575SYCL_BACKENDS = /gpu/sycl/ref /gpu/sycl/shared /gpu/sycl/gen 576ifneq ($(SYCL_DIR),) 577 SYCL_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(SYCL_DIR)/$d/libsycl.${SO_EXT})) 578 SYCL_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(SYCL_LIB_DIR)))) 579endif 580ifneq ($(SYCL_LIB_DIR),) 581 PKG_LIBS += $(SYCL_FLAG) -lze_loader 582 LIBCEED_CONTAINS_CXX = 1 583 libceed.sycl += $(sycl-core.cpp) $(sycl-ref.cpp) $(sycl-shared.cpp) $(sycl-gen.cpp) 584 BACKENDS_MAKE += $(SYCL_BACKENDS) 585endif 586 587# MAGMA Backends 588ifneq ($(wildcard $(MAGMA_DIR)/lib/libmagma.*),) 589 MAGMA_ARCH=$(shell nm -g $(MAGMA_DIR)/lib/libmagma.* | grep -c "hipblas") 590 ifeq ($(MAGMA_ARCH), 0) # CUDA MAGMA 591 ifneq ($(CUDA_LIB_DIR),) 592 cuda_link = $(if $(STATIC),,-Wl,-rpath,$(CUDA_LIB_DIR)) -L$(CUDA_LIB_DIR) -lcublas -lcusparse -lcudart 593 omp_link = -fopenmp 594 magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(cuda_link) $(omp_link) 595 magma_link_shared = -L$(MAGMA_DIR)/lib $(if $(STATIC),,-Wl,-rpath,$(abspath $(MAGMA_DIR)/lib)) -lmagma 596 magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static)) 597 PKG_LIBS += $(magma_link) 598 libceed.c += $(magma.c) 599 libceed.cpp += $(magma.cpp) 600 $(magma.c:%.c=$(OBJDIR)/%.o) $(magma.c:%=%.tidy) : CPPFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include 601 $(magma.cpp:%.cpp=$(OBJDIR)/%.o) $(magma.cpp:%=%.tidy) : CPPFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include 602 MAGMA_BACKENDS = /gpu/cuda/magma /gpu/cuda/magma/det 603 endif 604 else # HIP MAGMA 605 ifneq ($(HIP_LIB_DIR),) 606 omp_link = -fopenmp 607 hip_link = $(if $(STATIC),,-Wl,-rpath,$(HIP_LIB_DIR)) -L$(HIP_LIB_DIR) -lhipblas -lhipsparse -lamdhip64 608 magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(hip_link) $(omp_link) 609 magma_link_shared = -L$(MAGMA_DIR)/lib $(hip_link) $(omp_link) $(if $(STATIC),,-Wl,-rpath,$(abspath $(MAGMA_DIR)/lib)) -lmagma 610 magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static)) 611 PKG_LIBS += $(magma_link) 612 libceed.c += $(magma.c) 613 libceed.cpp += $(magma.cpp) 614 $(magma.c:%.c=$(OBJDIR)/%.o) $(magma.c:%=%.tidy) : CPPFLAGS += $(HIPCONFIG_CPPFLAGS) -I$(MAGMA_DIR)/include -I$(ROCM_DIR)/include -DCEED_MAGMA_USE_HIP -DADD_ 615 $(magma.cpp:%.cpp=$(OBJDIR)/%.o) $(magma.cpp:%=%.tidy) : CPPFLAGS += $(HIPCONFIG_CPPFLAGS) -I$(MAGMA_DIR)/include -I$(ROCM_DIR)/include -DCEED_MAGMA_USE_HIP -DADD_ 616 MAGMA_BACKENDS = /gpu/hip/magma /gpu/hip/magma/det 617 endif 618 endif 619 LIBCEED_CONTAINS_CXX = 1 620 BACKENDS_MAKE += $(MAGMA_BACKENDS) 621endif 622 623BACKENDS ?= $(BACKENDS_MAKE) 624export BACKENDS 625 626 627# ------------------------------------------------------------ 628# Linker Flags 629# ------------------------------------------------------------ 630 631_pkg_ldflags = $(filter -L%,$(PKG_LIBS)) 632_pkg_ldlibs = $(filter-out -L%,$(PKG_LIBS)) 633$(libceeds) : CEED_LDFLAGS += $(_pkg_ldflags) $(if $(STATIC),,$(_pkg_ldflags:-L%=-Wl,-rpath,%)) $(PKG_STUBS_LIBS) 634$(libceeds) : CEED_LDLIBS += $(_pkg_ldlibs) 635ifeq ($(STATIC),1) 636 $(examples) $(tests) : CEED_LDFLAGS += $(EM_LDFLAGS) $(_pkg_ldflags) $(if $(STATIC),,$(_pkg_ldflags:-L%=-Wl,-rpath,%)) $(PKG_STUBS_LIBS) 637 $(examples) $(tests) : CEED_LDLIBS += $(_pkg_ldlibs) 638endif 639 640pkgconfig-libs-private = $(PKG_LIBS) 641ifeq ($(LIBCEED_CONTAINS_CXX),1) 642 $(libceeds) : LINK = $(CXX) 643 ifeq ($(STATIC),1) 644 $(examples) $(tests) : CEED_LDLIBS += $(LIBCXX) 645 pkgconfig-libs-private += $(LIBCXX) 646 endif 647endif 648 649 650# ------------------------------------------------------------ 651# Building core library components 652# ------------------------------------------------------------ 653 654# File names *-weak.c contain weak symbol definitions, which must be listed last 655# when creating shared or static libraries. 656weak_last = $(filter-out %-weak.o,$(1)) $(filter %-weak.o,$(1)) 657 658libceed.o = $(libceed.c:%.c=$(OBJDIR)/%.o) $(libceed.cpp:%.cpp=$(OBJDIR)/%.o) $(libceed.cu:%.cu=$(OBJDIR)/%.o) $(libceed.hip:%.hip.cpp=$(OBJDIR)/%.o) $(libceed.sycl:%.sycl.cpp=$(OBJDIR)/%.o) 659$(filter %fortran.o,$(libceed.o)) : CPPFLAGS += $(if $(filter 1,$(UNDERSCORE)),-DUNDERSCORE) 660$(libceed.o): | info-backends 661$(libceed.so) : $(call weak_last,$(libceed.o)) | $$(@D)/.DIR 662 $(call quiet,LINK) $(LDFLAGS) $(CEED_LDFLAGS) -shared -o $@ $^ $(CEED_LDLIBS) $(LDLIBS) 663 664$(libceed.a) : $(call weak_last,$(libceed.o)) | $$(@D)/.DIR 665 $(call quiet,AR) $(ARFLAGS) $@ $^ 666 667$(OBJDIR)/%.o : $(CURDIR)/%.c | $$(@D)/.DIR 668 $(call quiet,CC) $(CPPFLAGS) $(CFLAGS) $(CONFIGFLAGS) -c -o $@ $(abspath $<) 669 670$(OBJDIR)/%.o : $(CURDIR)/%.cpp | $$(@D)/.DIR 671 $(call quiet,CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(abspath $<) 672 673$(OBJDIR)/%.o : $(CURDIR)/%.cu | $$(@D)/.DIR 674 $(call quiet,NVCC) $(filter-out -Wno-unused-function, $(CPPFLAGS)) $(NVCCFLAGS) -c -o $@ $(abspath $<) 675 676$(OBJDIR)/%.o : $(CURDIR)/%.hip.cpp | $$(@D)/.DIR 677 $(call quiet,HIPCC) $(CPPFLAGS) $(HIPCCFLAGS) -c -o $@ $(abspath $<) 678 679$(OBJDIR)/%.o : $(CURDIR)/%.sycl.cpp | $$(@D)/.DIR 680 $(call quiet,SYCLCXX) $(SYCLFLAGS) $(CPPFLAGS) -c -o $@ $(abspath $<) 681 682$(OBJDIR)/%.o : $(CURDIR)/%.sycl.cpp | $$(@D)/.DIR 683 $(call quiet,SYCLCXX) $(SYCLFLAGS) $(CPPFLAGS) -c -o $@ $(abspath $<) 684 685$(OBJDIR)/%$(EXE_SUFFIX) : tests/%.c | $$(@D)/.DIR 686 $(call quiet,LINK.c) $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(CEED_LDLIBS) $(LDLIBS) -I./tests/test-include 687 688$(OBJDIR)/%$(EXE_SUFFIX) : tests/%.f90 | $$(@D)/.DIR 689 $(call quiet,LINK.F) -DSOURCE_DIR='"$(abspath $(<D))/"' $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(CEED_LDLIBS) $(LDLIBS) 690 691$(OBJDIR)/%$(EXE_SUFFIX) : examples/ceed/%.c | $$(@D)/.DIR 692 $(call quiet,LINK.c) $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(CEED_LDLIBS) $(LDLIBS) 693 694$(OBJDIR)/%$(EXE_SUFFIX) : examples/ceed/%.f90 | $$(@D)/.DIR 695 $(call quiet,LINK.F) -DSOURCE_DIR='"$(abspath $(<D))/"' $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(CEED_LDLIBS) $(LDLIBS) 696 697 698# ------------------------------------------------------------ 699# Building examples 700# ------------------------------------------------------------ 701 702# deal.II 703# Note: Invoking deal.II's CMAKE build system here 704$(OBJDIR)/dealii-bps : examples/deal.II/*.cc examples/deal.II/*.h $(libceed) | $$(@D)/.DIR 705 mkdir -p examples/deal.II/build 706 cmake -B examples/deal.II/build -S examples/deal.II -DDEAL_II_DIR=$(DEAL_II_DIR) -DCEED_DIR=$(PWD) 707 +$(call quiet,MAKE) -C examples/deal.II/build 708 cp examples/deal.II/build/bps $(OBJDIR)/dealii-bps 709 710# MFEM 711$(OBJDIR)/mfem-% : examples/mfem/%.cpp $(libceed) | $$(@D)/.DIR 712 +$(MAKE) -C examples/mfem CEED_DIR=`pwd` \ 713 MFEM_DIR="$(abspath $(MFEM_DIR))" CXX=$(CXX) $* 714 cp examples/mfem/$* $@ 715 716# Nek5000 717# Note: Multiple Nek files cannot be built in parallel. The '+' here enables 718# this single Nek bps file to be built in parallel with other examples, 719# such as when calling `make prove-all -j2`. 720$(OBJDIR)/nek-bps : examples/nek/bps/bps.usr examples/nek/nek-examples.sh $(libceed) | $$(@D)/.DIR 721 +$(MAKE) -C examples MPI=$(MPI) CEED_DIR=`pwd` NEK5K_DIR="$(abspath $(NEK5K_DIR))" nek 722 mv examples/nek/build/bps $(OBJDIR)/bps 723 cp examples/nek/nek-examples.sh $(OBJDIR)/nek-bps 724 725# Rust QFunctions 726$(OBJDIR)/rustqfunctions-% : examples/rust-qfunctions/%.c $(libceed) | $$(@D)/.DIR 727 +$(MAKE) -C examples/rust-qfunctions CEED_DIR=`pwd` 728 cp examples/rust-qfunctions/$* $@ 729 730# PETSc 731# Several executables have common utilities, but we can't build the utilities 732# from separate submake invocations because they'll compete with each 733# other/corrupt output. So we put it in this utility library, but we don't want 734# to manually list source dependencies up at this level, so we'll just always 735# call recursive make to check that this utility is up to date. 736examples/petsc/libutils.a.PHONY: $(libceed) $(ceed.pc) 737 +$(call quiet,MAKE) -C examples/petsc CEED_DIR=`pwd` AR=$(AR) ARFLAGS=$(ARFLAGS) \ 738 PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $(basename $(@F)) 739 740$(OBJDIR)/petsc-% : examples/petsc/%.c examples/petsc/libutils.a.PHONY $(libceed) $(ceed.pc) | $$(@D)/.DIR 741 +$(call quiet,MAKE) -C examples/petsc CEED_DIR=`pwd` \ 742 PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $* 743 cp examples/petsc/$* $@ 744 745# Fluid dynamics proxy application 746$(OBJDIR)/fluids-% : examples/fluids/%.c examples/fluids/src/*.c examples/fluids/*.h examples/fluids/include/*.h examples/fluids/problems/*.c examples/fluids/qfunctions/*.h $(libceed) $(ceed.pc) examples/fluids/Makefile | $$(@D)/.DIR 747 +$(call quiet,MAKE) -C examples/fluids CEED_DIR=`pwd` \ 748 PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $* 749 cp examples/fluids/$* $@ 750 751# Solid mechanics proxy application 752$(OBJDIR)/solids-% : examples/solids/%.c examples/solids/%.h \ 753 examples/solids/problems/*.c examples/solids/src/*.c \ 754 examples/solids/include/*.h examples/solids/problems/*.h examples/solids/qfunctions/*.h \ 755 $(libceed) $(ceed.pc) | $$(@D)/.DIR 756 +$(call quiet,MAKE) -C examples/solids CEED_DIR=`pwd` \ 757 PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $* 758 cp examples/solids/$* $@ 759 760examples : $(allexamples) 761ceedexamples : $(examples) 762nekexamples : $(nekexamples) 763mfemexamples : $(mfemexamples) 764petscexamples : $(petscexamples) 765 766rustqfunctionsexamples : $(rustqfunctionsexamples) 767 768external_examples := \ 769 $(if $(MFEM_DIR),$(mfemexamples)) \ 770 $(if $(PETSC_DIR),$(petscexamples)) \ 771 $(if $(NEK5K_DIR),$(nekexamples)) \ 772 $(if $(DEAL_II_DIR),$(dealiiexamples)) \ 773 $(if $(PETSC_DIR),$(fluidsexamples)) \ 774 $(if $(PETSC_DIR),$(solidsexamples)) \ 775 $(if $(or $(RUST_QF),$(GPU_CLANG)),$(rustqfunctionsexamples)) 776 777allexamples = $(examples) $(external_examples) 778 779$(examples) : $(libceed) 780$(tests) : $(libceed) 781$(tests) $(examples) : override LDFLAGS += $(if $(STATIC),,-Wl,-rpath,$(abspath $(LIBDIR))) -L$(LIBDIR) 782 783 784# ------------------------------------------------------------ 785# Testing 786# ------------------------------------------------------------ 787 788# Set number processes for testing 789NPROC_TEST ?= 1 790export NPROC_TEST 791 792# Set pool size for testing 793NPROC_POOL ?= 1 794export NPROC_POOL 795 796run-% : $(OBJDIR)/% 797 @$(PYTHON) tests/junit.py --mode tap --ceed-backends $(BACKENDS) --nproc $(NPROC_TEST) --pool-size $(NPROC_POOL) --search '$(subsearch)' $(<:$(OBJDIR)/%=%) 798 799# The test and prove targets can be controlled via pattern searches. The 800# default is to run tests and those examples that have no external dependencies. 801# Examples of finer grained control: 802# 803# make test search='petsc mfem' # PETSc and MFEM examples 804# make prove search='t3' # t3xx series tests 805# make junit search='ex petsc' # core ex* and PETSc tests 806search ?= t ex 807realsearch = $(search:%=%%) 808matched = $(foreach pattern,$(realsearch),$(filter $(OBJDIR)/$(pattern),$(tests) $(allexamples))) 809subsearch ?= .* 810JUNIT_BATCH ?= '' 811 812# Test core libCEED 813test : $(matched:$(OBJDIR)/%=run-%) 814 815# Run test target in parallel 816tst : ;@$(MAKE) $(MFLAGS) V=$(V) test 817# CPU C tests only for backend % 818ctc-% : $(ctests);@$(foreach tst,$(ctests),$(tst) /cpu/$*;) 819 820# Testing with TAP format 821# https://testanything.org/tap-specification.html 822prove : $(matched) 823 $(info Testing backends: $(BACKENDS)) 824 $(PROVE) $(PROVE_OPTS) --exec '$(PYTHON) tests/junit.py' $(matched:$(OBJDIR)/%=%) :: --mode tap --ceed-backends $(BACKENDS) --nproc $(NPROC_TEST) --pool-size $(NPROC_POOL) --search '$(subsearch)' 825# Run prove target in parallel 826prv : ;@$(MAKE) $(MFLAGS) V=$(V) prove 827 828prove-all : 829 +$(MAKE) prove realsearch=% 830 831junit-% : $(OBJDIR)/% 832 @printf " %10s %s\n" TEST $(<:$(OBJDIR)/%=%); $(PYTHON) tests/junit.py --ceed-backends $(BACKENDS) --nproc $(NPROC_TEST) --pool-size $(NPROC_POOL) --search '$(subsearch)' --junit-batch $(JUNIT_BATCH) $(<:$(OBJDIR)/%=%) 833 834junit : $(matched:$(OBJDIR)/%=junit-%) 835 836all: $(alltests) 837 838# Benchmarks 839allbenchmarks = petsc-bps 840bench_targets = $(addprefix bench-,$(allbenchmarks)) 841.PHONY: $(bench_targets) benchmarks 842$(bench_targets): bench-%: $(OBJDIR)/% 843 cd benchmarks && ./benchmark.sh --ceed "$(BACKENDS)" -r $(*).sh 844benchmarks: $(bench_targets) 845 846$(ceed.pc) : pkgconfig-prefix = $(abspath .) 847$(OBJDIR)/ceed.pc : pkgconfig-prefix = $(prefix) 848.INTERMEDIATE : $(OBJDIR)/ceed.pc 849%/ceed.pc : ceed.pc.template | $$(@D)/.DIR 850 @$(SED) \ 851 -e "s:%prefix%:$(pkgconfig-prefix):" \ 852 -e "s:%opt%:$(OPT):" \ 853 -e "s:%libs_private%:$(pkgconfig-libs-private):" $< > $@ 854 855GIT_DESCRIBE = $(shell git -c safe.directory=$PWD describe --always --dirty 2>/dev/null || printf "unknown\n") 856 857$(OBJDIR)/interface/ceed-config.o: Makefile 858$(OBJDIR)/interface/ceed-config.o: CONFIGFLAGS += -DCEED_GIT_VERSION="\"$(GIT_DESCRIBE)\"" 859$(OBJDIR)/interface/ceed-config.o: CONFIGFLAGS += -DCEED_BUILD_CONFIGURATION="\"// Build Configuration:$(foreach v,$(CONFIG_VARS),\n$(v) = $($(v)))\"" 860 861$(OBJDIR)/interface/ceed-jit-source-root-default.o : CPPFLAGS += -DCEED_JIT_SOURCE_ROOT_DEFAULT="\"$(abspath ./include)/\"" 862$(OBJDIR)/interface/ceed-jit-source-root-install.o : CPPFLAGS += -DCEED_JIT_SOURCE_ROOT_DEFAULT="\"$(abspath $(includedir))/\"" 863 864 865# ------------------------------------------------------------ 866# Installation 867# ------------------------------------------------------------ 868 869install : $(libceed) $(OBJDIR)/ceed.pc 870 $(INSTALL) -d $(addprefix $(if $(DESTDIR),"$(DESTDIR)"),"$(includedir)"\ 871 "$(includedir)/ceed/" "$(includedir)/ceed/jit-source/"\ 872 "$(includedir)/ceed/jit-source/cuda/" "$(includedir)/ceed/jit-source/hip/"\ 873 "$(includedir)/ceed/jit-source/gallery/" "$(includedir)/ceed/jit-source/magma/"\ 874 "$(includedir)/ceed/jit-source/sycl/" "$(libdir)" "$(pkgconfigdir)") 875 $(INSTALL_DATA) include/ceed/ceed.h "$(DESTDIR)$(includedir)/ceed/" 876 $(INSTALL_DATA) include/ceed/deprecated.h "$(DESTDIR)$(includedir)/ceed/" 877 $(INSTALL_DATA) include/ceed/types.h "$(DESTDIR)$(includedir)/ceed/" 878 $(INSTALL_DATA) include/ceed/ceed-f32.h "$(DESTDIR)$(includedir)/ceed/" 879 $(INSTALL_DATA) include/ceed/ceed-f64.h "$(DESTDIR)$(includedir)/ceed/" 880 $(INSTALL_DATA) include/ceed/fortran.h "$(DESTDIR)$(includedir)/ceed/" 881 $(INSTALL_DATA) include/ceed/backend.h "$(DESTDIR)$(includedir)/ceed/" 882 $(INSTALL_DATA) include/ceed/cuda.h "$(DESTDIR)$(includedir)/ceed/" 883 $(INSTALL_DATA) include/ceed/hip.h "$(DESTDIR)$(includedir)/ceed/" 884 $(INSTALL_DATA) $(libceed) "$(DESTDIR)$(libdir)/" 885 $(INSTALL_DATA) $(OBJDIR)/ceed.pc "$(DESTDIR)$(pkgconfigdir)/" 886 $(INSTALL_DATA) include/ceed.h "$(DESTDIR)$(includedir)/" 887 $(INSTALL_DATA) include/ceedf.h "$(DESTDIR)$(includedir)/" 888 $(INSTALL_DATA) $(wildcard include/ceed/jit-source/cuda/*.h) "$(DESTDIR)$(includedir)/ceed/jit-source/cuda/" 889 $(INSTALL_DATA) $(wildcard include/ceed/jit-source/hip/*.h) "$(DESTDIR)$(includedir)/ceed/jit-source/hip/" 890 $(INSTALL_DATA) $(wildcard include/ceed/jit-source/gallery/*.h) "$(DESTDIR)$(includedir)/ceed/jit-source/gallery/" 891 $(INSTALL_DATA) $(wildcard include/ceed/jit-source/magma/*.h) "$(DESTDIR)$(includedir)/ceed/jit-source/magma/" 892 $(INSTALL_DATA) $(wildcard include/ceed/jit-source/sycl/*.h) "$(DESTDIR)$(includedir)/ceed/jit-source/sycl/" 893 894 895# ------------------------------------------------------------ 896# Cleaning 897# ------------------------------------------------------------ 898 899cln clean : 900 $(RM) -r $(OBJDIR) $(LIBDIR) dist *egg* .pytest_cache *cffi* 901 $(call quiet,MAKE) -C examples clean NEK5K_DIR="$(abspath $(NEK5K_DIR))" 902 $(call quiet,MAKE) -C python/tests clean 903 $(RM) benchmarks/*output.txt 904 $(RM) -rf temp 905 906distclean : clean 907 $(RM) -r doc/html doc/sphinx/build $(CONFIG) 908 909 910# ------------------------------------------------------------ 911# Documentation 912# ------------------------------------------------------------ 913 914DOXYGEN ?= doxygen 915 916doxygen : 917 $(DOXYGEN) -q Doxyfile 918 919doc-html doc-latexpdf doc-epub doc-livehtml : doc-% : doxygen 920 make -C doc/sphinx $* 921 922doc : doc-html 923 924 925# ------------------------------------------------------------ 926# Linting utilities 927# ------------------------------------------------------------ 928 929# Style/Format 930CLANG_FORMAT ?= clang-format 931CLANG_FORMAT_OPTS += -style=file -i 932AUTOPEP8 ?= autopep8 933AUTOPEP8_OPTS += --in-place --aggressive --max-line-length 120 934 935format.ch := $(filter-out include/ceedf.h $(wildcard tests/t*-f.h) $(wildcard examples/ceed/ex*-f.h), $(shell git ls-files '*.[ch]pp' '*.[ch]' '*.cu')) 936format.py := $(filter-out tests/junit-xml/junit_xml/__init__.py, $(shell git ls-files '*.py')) 937format.ot := $(filter-out doc/sphinx/source/CODE_OF_CONDUCT.md doc/sphinx/source/CONTRIBUTING.md, $(shell git ls-files '*.md' '*.f90')) 938 939format-c : 940 $(CLANG_FORMAT) $(CLANG_FORMAT_OPTS) $(format.ch) 941 942format-py : 943 $(AUTOPEP8) $(AUTOPEP8_OPTS) $(format.py) 944 945format-ot: 946 @$(SED) -r 's/\s+$$//' -i $(format.ot) 947 948format : format-c format-py format-ot 949 950# Vermin - python version requirements 951VERMIN ?= vermin 952VERMIN_OPTS += -t=3.8- --violations 953 954vermin : 955 $(VERMIN) $(VERMIN_OPTS) $(format.py) 956 957# Tidy 958CLANG_TIDY ?= clang-tidy 959 960%.c.tidy : %.c 961 $(CLANG_TIDY) $(TIDY_OPTS) $^ -- $(CPPFLAGS) --std=c11 -I$(CUDA_DIR)/include -I$(ROCM_DIR)/include -DCEED_JIT_SOURCE_ROOT_DEFAULT="\"$(abspath ./include)/\"" -DCEED_GIT_VERSION="\"$(GIT_DESCRIBE)\"" -DCEED_BUILD_CONFIGURATION="\"// Build Configuration:$(foreach v,$(CONFIG_VARS),\n$(v) = $($(v)))\"" 962 963%.cpp.tidy : %.cpp 964 $(CLANG_TIDY) $(TIDY_OPTS) $^ -- $(CPPFLAGS) --std=c++11 -I$(CUDA_DIR)/include -I$(ROCM_DIR)/include 965 966tidy-c : $(libceed.c:%=%.tidy) 967tidy-cpp : $(libceed.cpp:%=%.tidy) 968 969tidy : tidy-c tidy-cpp 970 971# Include-What-You-Use 972ifneq ($(wildcard ../iwyu/*),) 973 IWYU_DIR ?= ../iwyu 974 IWYU_CC ?= $(IWYU_DIR)/build/bin/include-what-you-use 975endif 976iwyu : 977 $(MAKE) -B CC=$(IWYU_CC) 978 979 980# ------------------------------------------------------------ 981# Variable printing for debugging 982# ------------------------------------------------------------ 983 984print : 985 @echo $(VAR)=$($(VAR)) 986 987print-% : 988 $(info [ variable name]: $*) 989 $(info [ origin]: $(origin $*)) 990 $(info [ flavor]: $(flavor $*)) 991 $(info [ value]: $(value $*)) 992 $(info [expanded value]: $($*)) 993 $(info ) 994 @true 995 996 997# ------------------------------------------------------------ 998# Configuration caching 999# ------------------------------------------------------------ 1000 1001# "make configure" detects any variables passed on the command line or 1002# previously set in config.mk, caching them in config.mk as simple 1003# (:=) variables. Variables set in config.mk or on the command line 1004# take precedence over the defaults provided in the file. Typical 1005# usage: 1006# 1007# make configure CC=/path/to/my/cc CUDA_DIR=/opt/cuda 1008# make 1009# make prove 1010# 1011# The values in the file can be updated by passing them on the command 1012# line, e.g., 1013# 1014# make configure CC=/path/to/other/clang 1015 1016# All variables to consider for caching 1017CONFIG_VARS = CC CXX FC NVCC NVCC_CXX HIPCC \ 1018 OPT CFLAGS CPPFLAGS CXXFLAGS FFLAGS NVCCFLAGS HIPCCFLAGS SYCLFLAGS \ 1019 AR ARFLAGS LDFLAGS LDLIBS LIBCXX SED \ 1020 MAGMA_DIR XSMM_DIR CUDA_DIR CUDA_ARCH MFEM_DIR PETSC_DIR NEK5K_DIR ROCM_DIR HIP_ARCH SYCL_DIR 1021 1022# $(call needs_save,CFLAGS) returns true (a nonempty string) if CFLAGS 1023# was set on the command line or in config.mk (where it will appear as 1024# a simple variable). 1025needs_save = $(or $(filter command line,$(origin $(1))),$(filter simple,$(flavor $(1)))) 1026 1027configure : 1028 $(file > $(CONFIG)) 1029 $(foreach v,$(CONFIG_VARS),$(if $(call needs_save,$(v)),$(file >> $(CONFIG),$(v) := $($(v))))) 1030 @echo "Configuration cached in $(CONFIG):" 1031 @cat $(CONFIG) 1032 1033 1034# ------------------------------------------------------------ 1035# Building Python wheels for deployment 1036# ------------------------------------------------------------ 1037 1038wheel : export MARCHFLAG = -march=generic 1039wheel : export WHEEL_PLAT = manylinux2010_x86_64 1040wheel : 1041 docker run -it --user $(shell id -u):$(shell id -g) --rm -v $(PWD):/io -w /io \ 1042 -e MARCHFLAG -e WHEEL_PLAT \ 1043 quay.io/pypa/$(WHEEL_PLAT) python/make-wheels.sh 1044 1045# ------------------------------------------------------------ 1046# Phony targets 1047# ------------------------------------------------------------ 1048 1049# These targets are not files but rather commands to run 1050.PHONY : all cln clean doxygen doc format lib install par print test tst prove prv prove-all junit examples tidy iwyu info info-backends info-backends-all configure wheel 1051 1052 1053# Include *.d deps when not -B = --always-make: useful if the paths are wonky in a container 1054-include $(if $(filter B,$(MAKEFLAGS)),,$(libceed.c:%.c=$(OBJDIR)/%.d) $(tests.c:tests/%.c=$(OBJDIR)/%.d)) 1055