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