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