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