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