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