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-ref.c := $(sort $(wildcard backends/cuda-ref/*.c)) 229cuda-ref.cpp := $(sort $(wildcard backends/cuda-ref/*.cpp)) 230cuda-ref.cu := $(sort $(wildcard backends/cuda-ref/kernels/*.cu)) 231cuda-shared.c := $(sort $(wildcard backends/cuda-shared/*.c)) 232cuda-shared.cu := $(sort $(wildcard backends/cuda-shared/kernels/*.cu)) 233cuda-gen.c := $(sort $(wildcard backends/cuda-gen/*.c)) 234cuda-gen.cpp := $(sort $(wildcard backends/cuda-gen/*.cpp)) 235cuda-gen.cu := $(sort $(wildcard backends/cuda-gen/kernels/*.cu)) 236occa.cpp := $(sort $(shell find backends/occa -type f -name *.cpp)) 237magma.c := $(sort $(wildcard backends/magma/*.c)) 238magma.cu := $(sort $(wildcard backends/magma/kernels/cuda/*.cu)) 239magma.hip := $(sort $(wildcard backends/magma/kernels/hip/*.hip.cpp)) 240hip.c := $(sort $(wildcard backends/hip/*.c)) 241hip.cpp := $(sort $(wildcard backends/hip/*.cpp)) 242hip-ref.c := $(sort $(wildcard backends/hip-ref/*.c)) 243hip-ref.cpp := $(sort $(wildcard backends/hip-ref/*.cpp)) 244hip-ref.hip := $(sort $(wildcard backends/hip-ref/kernels/*.hip.cpp)) 245hip-shared.c := $(sort $(wildcard backends/hip-shared/*.c)) 246hip-gen.c := $(sort $(wildcard backends/hip-gen/*.c)) 247hip-gen.cpp := $(sort $(wildcard backends/hip-gen/*.cpp)) 248 249# Quiet, color output 250quiet ?= $($(1)) 251 252# Cancel built-in and old-fashioned implicit rules which we don't use 253.SUFFIXES: 254 255.SECONDEXPANSION: # to expand $$(@D)/.DIR 256 257%/.DIR : 258 @mkdir -p $(@D) 259 @touch $@ 260 261.PRECIOUS: %/.DIR 262 263lib: $(libceed) $(ceed.pc) 264# run 'lib' target in parallel 265par:;@$(MAKE) $(MFLAGS) V=$(V) lib 266backend_status = $(if $(filter $1,$(BACKENDS_MAKE)), [backends: $1], [not found]) 267info: 268 $(info ------------------------------------) 269 $(info CC = $(CC)) 270 $(info CXX = $(CXX)) 271 $(info FC = $(FC)) 272 $(info CPPFLAGS = $(CPPFLAGS)) 273 $(info CFLAGS = $(value CFLAGS)) 274 $(info CXXFLAGS = $(value CXXFLAGS)) 275 $(info FFLAGS = $(value FFLAGS)) 276 $(info NVCCFLAGS = $(value NVCCFLAGS)) 277 $(info HIPCCFLAGS = $(value HIPCCFLAGS)) 278 $(info LDFLAGS = $(value LDFLAGS)) 279 $(info LDLIBS = $(LDLIBS)) 280 $(info AR = $(AR)) 281 $(info ARFLAGS = $(ARFLAGS)) 282 $(info OPT = $(OPT)) 283 $(info AFLAGS = $(AFLAGS)) 284 $(info ASAN = $(or $(ASAN),(empty))) 285 $(info VERBOSE = $(or $(V),(empty)) [verbose=$(if $(V),on,off)]) 286 $(info ------------------------------------) 287 $(info MEMCHK_STATUS = $(MEMCHK_STATUS)$(call backend_status,$(MEMCHK_BACKENDS))) 288 $(info AVX_STATUS = $(AVX_STATUS)$(call backend_status,$(AVX_BACKENDS))) 289 $(info XSMM_DIR = $(XSMM_DIR)$(call backend_status,$(XSMM_BACKENDS))) 290 $(info OCCA_DIR = $(OCCA_DIR)$(call backend_status,$(OCCA_BACKENDS))) 291 $(info MAGMA_DIR = $(MAGMA_DIR)$(call backend_status,$(MAGMA_BACKENDS))) 292 $(info CUDA_DIR = $(CUDA_DIR)$(call backend_status,$(CUDA_BACKENDS))) 293 $(info HIP_DIR = $(HIP_DIR)$(call backend_status,$(HIP_BACKENDS))) 294 $(info ------------------------------------) 295 $(info MFEM_DIR = $(MFEM_DIR)) 296 $(info NEK5K_DIR = $(NEK5K_DIR)) 297 $(info PETSC_DIR = $(PETSC_DIR)) 298 $(info ------------------------------------) 299 $(info prefix = $(prefix)) 300 $(info includedir = $(value includedir)) 301 $(info libdir = $(value libdir)) 302 $(info pkgconfigdir = $(value pkgconfigdir)) 303 $(info ------------------------------------) 304 @true 305info-backends: 306 $(info make: 'lib' with optional backends: $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS))) 307 @true 308info-backends-all: 309 $(info make: 'lib' with backends: $(filter-out $(TEST_BACKENDS),$(BACKENDS))) 310 @true 311 312$(libceed.so) : LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed.so))) 313 314# Standard Backends 315libceed.c += $(ref.c) 316libceed.c += $(blocked.c) 317libceed.c += $(opt.c) 318 319# Memcheck Backend 320MEMCHK_STATUS = Disabled 321MEMCHK := $(shell echo "$(HASH)include <valgrind/memcheck.h>" | $(CC) $(CPPFLAGS) -E - >/dev/null 2>&1 && echo 1) 322MEMCHK_BACKENDS = /cpu/self/memcheck/serial /cpu/self/memcheck/blocked 323ifeq ($(MEMCHK),1) 324 MEMCHK_STATUS = Enabled 325 libceed.c += $(ceedmemcheck.c) 326 BACKENDS_MAKE += $(MEMCHK_BACKENDS) 327endif 328 329# AVX Backed 330AVX_STATUS = Disabled 331AVX_FLAG := $(if $(filter clang,$(CC_VENDOR)),+avx,-mavx) 332AVX := $(filter $(AVX_FLAG),$(shell $(CC) $(OPT) -v -E -x c /dev/null 2>&1)) 333AVX_BACKENDS = /cpu/self/avx/serial /cpu/self/avx/blocked 334ifneq ($(AVX),) 335 AVX_STATUS = Enabled 336 libceed.c += $(avx.c) 337 BACKENDS_MAKE += $(AVX_BACKENDS) 338endif 339 340# Collect list of libraries and paths for use in linking and pkg-config 341PKG_LIBS = 342 343# libXSMM Backends 344XSMM_BACKENDS = /cpu/self/xsmm/serial /cpu/self/xsmm/blocked 345ifneq ($(wildcard $(XSMM_DIR)/lib/libxsmm.*),) 346 PKG_LIBS += -L$(abspath $(XSMM_DIR))/lib -lxsmm -ldl 347 MKL ?= 348 ifeq (,$(MKL)$(MKLROOT)) 349 BLAS_LIB = -lblas 350 else 351 ifneq ($(MKLROOT),) 352 # Some installs put everything inside an intel64 subdirectory, others not 353 MKL_LIBDIR = $(dir $(firstword $(wildcard $(MKLROOT)/lib/intel64/libmkl_sequential.* $(MKLROOT)/lib/libmkl_sequential.*))) 354 MKL_LINK = -L$(MKL_LIBDIR) 355 PKG_LIB_DIRS += $(MKL_LIBDIR) 356 endif 357 BLAS_LIB = $(MKL_LINK) -Wl,--push-state,--no-as-needed -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl -Wl,--pop-state 358 endif 359 PKG_LIBS += $(BLAS_LIB) 360 libceed.c += $(xsmm.c) 361 $(xsmm.c:%.c=$(OBJDIR)/%.o) $(xsmm.c:%=%.tidy) : CPPFLAGS += -I$(XSMM_DIR)/include 362 BACKENDS_MAKE += $(XSMM_BACKENDS) 363endif 364 365# OCCA Backends 366OCCA_BACKENDS = /cpu/self/occa 367ifneq ($(wildcard $(OCCA_DIR)/lib/libocca.*),) 368 OCCA_MODES := $(shell $(OCCA_DIR)/bin/occa modes) 369 OCCA_BACKENDS += $(if $(filter OpenMP,$(OCCA_MODES)),/cpu/openmp/occa) 370# OCCA_BACKENDS += $(if $(filter OpenCL,$(OCCA_MODES)),/gpu/opencl/occa) 371 OCCA_BACKENDS += $(if $(filter HIP,$(OCCA_MODES)),/gpu/hip/occa) 372 OCCA_BACKENDS += $(if $(filter CUDA,$(OCCA_MODES)),/gpu/cuda/occa) 373 374 $(libceeds) : CPPFLAGS += -I$(OCCA_DIR)/include 375 PKG_LIBS += -L$(abspath $(OCCA_DIR))/lib -locca 376 LIBCEED_CONTAINS_CXX = 1 377 libceed.cpp += $(occa.cpp) 378 BACKENDS_MAKE += $(OCCA_BACKENDS) 379endif 380 381# CUDA Backends 382CUDA_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(CUDA_DIR)/$d/libcudart.${SO_EXT})) 383CUDA_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(CUDA_LIB_DIR)))) 384CUDA_LIB_DIR_STUBS := $(CUDA_LIB_DIR)/stubs 385CUDA_BACKENDS = /gpu/cuda/ref /gpu/cuda/shared /gpu/cuda/gen 386ifneq ($(CUDA_LIB_DIR),) 387 $(libceeds) : CPPFLAGS += -I$(CUDA_DIR)/include 388 PKG_LIBS += -L$(abspath $(CUDA_LIB_DIR)) -lcudart -lnvrtc -lcuda -lcublas 389 LIBCEED_CONTAINS_CXX = 1 390 libceed.c += interface/ceed-cuda.c 391 libceed.c += $(cuda.c) $(cuda-ref.c) $(cuda-shared.c) $(cuda-gen.c) 392 libceed.cpp += $(cuda-ref.cpp) $(cuda-gen.cpp) 393 libceed.cu += $(cuda-ref.cu) $(cuda-shared.cu) $(cuda-gen.cu) 394 BACKENDS_MAKE += $(CUDA_BACKENDS) 395endif 396 397# HIP Backends 398HIP_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(HIP_DIR)/$d/libamdhip64.${SO_EXT})) 399HIP_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(HIP_LIB_DIR)))) 400HIP_BACKENDS = /gpu/hip/ref /gpu/hip/shared /gpu/hip/gen 401ifneq ($(HIP_LIB_DIR),) 402 $(libceeds) : HIPCCFLAGS += -I./include 403 ifneq ($(CXX), $(HIPCC)) 404 CPPFLAGS += $(subst =,,$(shell $(HIP_DIR)/bin/hipconfig -C)) 405 endif 406 $(libceeds) : CPPFLAGS += -I$(HIP_DIR)/include 407 PKG_LIBS += -L$(abspath $(HIP_LIB_DIR)) -lamdhip64 -lhipblas 408 LIBCEED_CONTAINS_CXX = 1 409 libceed.c += interface/ceed-hip.c 410 libceed.c += $(hip.c) $(hip-ref.c) $(hip-shared.c) $(hip-gen.c) 411 libceed.cpp += $(hip.cpp) $(hip-ref.cpp) $(hip-gen.cpp) 412 libceed.hip += $(hip-ref.hip) 413 BACKENDS_MAKE += $(HIP_BACKENDS) 414endif 415 416# MAGMA Backend 417ifneq ($(wildcard $(MAGMA_DIR)/lib/libmagma.*),) 418 MAGMA_ARCH=$(shell nm -g $(MAGMA_DIR)/lib/libmagma.* | grep -c "hipblas") 419 ifeq ($(MAGMA_ARCH), 0) #CUDA MAGMA 420 ifneq ($(CUDA_LIB_DIR),) 421 cuda_link = -Wl,-rpath,$(CUDA_LIB_DIR) -L$(CUDA_LIB_DIR) -lcublas -lcusparse -lcudart 422 omp_link = -fopenmp 423 magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(cuda_link) $(omp_link) 424 magma_link_shared = -L$(MAGMA_DIR)/lib -Wl,-rpath,$(abspath $(MAGMA_DIR)/lib) -lmagma 425 magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static)) 426 PKG_LIBS += $(magma_link) 427 libceed.c += $(magma.c) 428 libceed.cu += $(magma.cu) 429 $(magma.c:%.c=$(OBJDIR)/%.o) $(magma.c:%=%.tidy) : CPPFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include 430 $(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 431 MAGMA_BACKENDS = /gpu/cuda/magma /gpu/cuda/magma/det 432 endif 433 else # HIP MAGMA 434 ifneq ($(HIP_LIB_DIR),) 435 hip_link = -Wl,-rpath,$(HIP_LIB_DIR) -L$(HIP_LIB_DIR) -lhipblas -lhipsparse -lamdhip64 436 omp_link = -fopenmp 437 magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(hip_link) $(omp_link) 438 magma_link_shared = -L$(MAGMA_DIR)/lib -Wl,-rpath,$(abspath $(MAGMA_DIR)/lib) -lmagma 439 magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static)) 440 PKG_LIBS += $(magma_link) 441 libceed.c += $(magma.c) 442 libceed.hip += $(magma.hip) 443 ifneq ($(CXX), $(HIPCC)) 444 $(magma.c:%.c=$(OBJDIR)/%.o) $(magma.c:%=%.tidy) : CPPFLAGS += -I$(MAGMA_DIR)/include -I$(HIP_DIR)/include -DHAVE_HIP -DADD_ 445 else 446 $(magma.c:%.c=$(OBJDIR)/%.o) $(magma.c:%=%.tidy) : HIPCCFLAGS += -I$(MAGMA_DIR)/include -I$(HIP_DIR)/include -DHAVE_HIP -DADD_ 447 endif 448 $(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_ 449 MAGMA_BACKENDS = /gpu/hip/magma /gpu/hip/magma/det 450 endif 451 endif 452 LIBCEED_CONTAINS_CXX = 1 453 BACKENDS_MAKE += $(MAGMA_BACKENDS) 454endif 455 456BACKENDS_ENV ?= BACKENDS 457ifneq ($(BACKENDS_ENV),) 458 BACKENDS = $(BACKENDS_MAKE) 459 export BACKENDS 460endif 461 462_pkg_ldflags = $(filter -L%,$(PKG_LIBS)) 463_pkg_ldlibs = $(filter-out -L%,$(PKG_LIBS)) 464$(libceeds) : LDFLAGS += $(_pkg_ldflags) $(_pkg_ldflags:-L%=-Wl,-rpath,%) 465$(libceeds) : LDLIBS += $(_pkg_ldlibs) 466ifeq ($(STATIC),1) 467$(examples) $(tests) : LDFLAGS += $(_pkg_ldflags) $(_pkg_ldflags:-L%=-Wl,-rpath,%) 468$(examples) $(tests) : LDLIBS += $(_pkg_ldlibs) 469endif 470 471pkgconfig-libs-private = $(PKG_LIBS) 472ifeq ($(LIBCEED_CONTAINS_CXX),1) 473 $(libceeds) : LINK = $(CXX) 474 ifeq ($(STATIC),1) 475 $(examples) $(tests) : LDLIBS += $(LIBCXX) 476 pkgconfig-libs-private += $(LIBCXX) 477 endif 478endif 479 480# File names *-weak.c contain weak symbol definitions, which must be listed last 481# when creating shared or static libraries. 482weak_last = $(filter-out %-weak.o,$(1)) $(filter %-weak.o,$(1)) 483 484libceed.o = $(libceed.c:%.c=$(OBJDIR)/%.o) $(libceed.cpp:%.cpp=$(OBJDIR)/%.o) $(libceed.cu:%.cu=$(OBJDIR)/%.o) $(libceed.hip:%.hip.cpp=$(OBJDIR)/%.o) 485$(filter %fortran.o,$(libceed.o)) : CPPFLAGS += $(if $(filter 1,$(UNDERSCORE)),-DUNDERSCORE) 486$(libceed.o): | info-backends 487$(libceed.so) : $(call weak_last,$(libceed.o)) | $$(@D)/.DIR 488 $(call quiet,LINK) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS) 489 490$(libceed.a) : $(call weak_last,$(libceed.o)) | $$(@D)/.DIR 491 $(call quiet,AR) $(ARFLAGS) $@ $^ 492 493$(OBJDIR)/%.o : $(CURDIR)/%.c | $$(@D)/.DIR 494 $(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<) 495 496$(OBJDIR)/%.o : $(CURDIR)/%.cpp | $$(@D)/.DIR 497 $(call quiet,CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(abspath $<) 498 499$(OBJDIR)/%.o : $(CURDIR)/%.cu | $$(@D)/.DIR 500 $(call quiet,NVCC) $(filter-out -Wno-unused-function, $(CPPFLAGS)) $(NVCCFLAGS) -c -o $@ $(abspath $<) 501 502$(OBJDIR)/%.o : $(CURDIR)/%.hip.cpp | $$(@D)/.DIR 503 $(call quiet,HIPCC) $(HIPCCFLAGS) -c -o $@ $(abspath $<) 504 505$(OBJDIR)/% : tests/%.c | $$(@D)/.DIR 506 $(call quiet,LINK.c) $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 507 508$(OBJDIR)/% : tests/%.f90 | $$(@D)/.DIR 509 $(call quiet,LINK.F) -DSOURCE_DIR='"$(abspath $(<D))/"' $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 510 511$(OBJDIR)/% : examples/ceed/%.c | $$(@D)/.DIR 512 $(call quiet,LINK.c) $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 513 514$(OBJDIR)/% : examples/ceed/%.f | $$(@D)/.DIR 515 $(call quiet,LINK.F) -DSOURCE_DIR='"$(abspath $(<D))/"' $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS) 516 517$(OBJDIR)/mfem-% : examples/mfem/%.cpp $(libceed) | $$(@D)/.DIR 518 +$(MAKE) -C examples/mfem CEED_DIR=`pwd` \ 519 MFEM_DIR="$(abspath $(MFEM_DIR))" CXX=$(CXX) $* 520 cp examples/mfem/$* $@ 521 522# Note: Multiple Nek files cannot be built in parallel. The '+' here enables 523# this single Nek bps file to be built in parallel with other examples, 524# such as when calling `make prove-all -j2`. 525$(OBJDIR)/nek-bps : examples/nek/bps/bps.usr examples/nek/nek-examples.sh $(libceed) | $$(@D)/.DIR 526 +$(MAKE) -C examples MPI=$(MPI) CEED_DIR=`pwd` NEK5K_DIR="$(abspath $(NEK5K_DIR))" nek 527 mv examples/nek/build/bps $(OBJDIR)/bps 528 cp examples/nek/nek-examples.sh $(OBJDIR)/nek-bps 529 530# Several executables have common utilities, but we can't build the utilities 531# from separate submake invocations because they'll compete with each 532# other/corrupt output. So we put it in this utility library, but we don't want 533# to manually list source dependencies up at this level, so we'll just always 534# call recursive make to check that this utility is up to date. 535examples/petsc/libutils.a.PHONY: $(libceed) $(ceed.pc) 536 +$(call quiet,MAKE) -C examples/petsc CEED_DIR=`pwd` AR=$(AR) ARFLAGS=$(ARFLAGS) \ 537 PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $(basename $(@F)) 538 539$(OBJDIR)/petsc-% : examples/petsc/%.c examples/petsc/libutils.a.PHONY $(libceed) $(ceed.pc) | $$(@D)/.DIR 540 +$(call quiet,MAKE) -C examples/petsc CEED_DIR=`pwd` \ 541 PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $* 542 cp examples/petsc/$* $@ 543 544$(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 545 +$(call quiet,MAKE) -C examples/fluids CEED_DIR=`pwd` \ 546 PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $* 547 cp examples/fluids/$* $@ 548 549$(OBJDIR)/solids-% : examples/solids/%.c examples/solids/%.h \ 550 examples/solids/problems/*.c examples/solids/src/*.c \ 551 examples/solids/include/*.h examples/solids/problems/*.h examples/solids/qfunctions/*.h \ 552 $(libceed) $(ceed.pc) | $$(@D)/.DIR 553 +$(call quiet,MAKE) -C examples/solids CEED_DIR=`pwd` \ 554 PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $* 555 cp examples/solids/$* $@ 556 557$(examples) : $(libceed) 558$(tests) : $(libceed) 559$(tests) $(examples) : LDFLAGS += -Wl,-rpath,$(abspath $(LIBDIR)) -L$(LIBDIR) 560 561run-% : $(OBJDIR)/% 562 @tests/tap.sh $(<:$(OBJDIR)/%=%) 563 564external_examples := \ 565 $(if $(MFEM_DIR),$(mfemexamples)) \ 566 $(if $(PETSC_DIR),$(petscexamples)) \ 567 $(if $(NEK5K_DIR),$(nekexamples)) \ 568 $(if $(PETSC_DIR),$(fluidsexamples)) \ 569 $(if $(PETSC_DIR),$(solidsexamples)) 570 571allexamples = $(examples) $(external_examples) 572 573# The test and prove targets can be controlled via pattern searches. The 574# default is to run tests and those examples that have no external dependencies. 575# Examples of finer grained control: 576# 577# make test search='petsc mfem' # PETSc and MFEM examples 578# make prove search='t3' # t3xx series tests 579# make junit search='ex petsc' # core ex* and PETSc tests 580search ?= t ex 581realsearch = $(search:%=%%) 582matched = $(foreach pattern,$(realsearch),$(filter $(OBJDIR)/$(pattern),$(tests) $(allexamples))) 583 584# Test core libCEED 585test : $(matched:$(OBJDIR)/%=run-%) 586 587# Run test target in parallel 588tst : ;@$(MAKE) $(MFLAGS) V=$(V) test 589# CPU C tests only for backend % 590ctc-% : $(ctests);@$(foreach tst,$(ctests),$(tst) /cpu/$*;) 591 592prove : $(matched) 593 $(info Testing backends: $(BACKENDS)) 594 $(PROVE) $(PROVE_OPTS) --exec 'tests/tap.sh' $(matched:$(OBJDIR)/%=%) 595# Run prove target in parallel 596prv : ;@$(MAKE) $(MFLAGS) V=$(V) prove 597 598prove-all : 599 +$(MAKE) prove realsearch=% 600 601junit-% : $(OBJDIR)/% 602 @printf " %10s %s\n" TEST $(<:$(OBJDIR)/%=%); $(PYTHON) tests/junit.py $(<:$(OBJDIR)/%=%) 603 604junit : $(matched:$(OBJDIR)/%=junit-%) 605 606all: $(alltests) 607 608examples : $(allexamples) 609ceedexamples : $(examples) 610nekexamples : $(nekexamples) 611mfemexamples : $(mfemexamples) 612petscexamples : $(petscexamples) 613 614# Benchmarks 615allbenchmarks = petsc-bps 616bench_targets = $(addprefix bench-,$(allbenchmarks)) 617.PHONY: $(bench_targets) benchmarks 618$(bench_targets): bench-%: $(OBJDIR)/% 619 cd benchmarks && ./benchmark.sh --ceed "$(BACKENDS_MAKE)" -r $(*).sh 620benchmarks: $(bench_targets) 621 622$(ceed.pc) : pkgconfig-prefix = $(abspath .) 623$(OBJDIR)/ceed.pc : pkgconfig-prefix = $(prefix) 624.INTERMEDIATE : $(OBJDIR)/ceed.pc 625%/ceed.pc : ceed.pc.template | $$(@D)/.DIR 626 @$(SED) \ 627 -e "s:%prefix%:$(pkgconfig-prefix):" \ 628 -e "s:%libs_private%:$(pkgconfig-libs-private):" $< > $@ 629 630install : $(libceed) $(OBJDIR)/ceed.pc 631 $(INSTALL) -d $(addprefix $(if $(DESTDIR),"$(DESTDIR)"),"$(includedir)"\ 632 "$(includedir)/ceed/" "$(libdir)" "$(pkgconfigdir)") 633 $(INSTALL_DATA) include/ceed/ceed.h "$(DESTDIR)$(includedir)/ceed/" 634 $(INSTALL_DATA) include/ceed/ceed-f32.h "$(DESTDIR)$(includedir)/ceed/" 635 $(INSTALL_DATA) include/ceed/ceed-f64.h "$(DESTDIR)$(includedir)/ceed/" 636 $(INSTALL_DATA) include/ceed/fortran.h "$(DESTDIR)$(includedir)/ceed/" 637 $(INSTALL_DATA) include/ceed/backend.h "$(DESTDIR)$(includedir)/ceed/" 638 $(INSTALL_DATA) include/ceed/cuda.h "$(DESTDIR)$(includedir)/ceed/" 639 $(INSTALL_DATA) include/ceed/hip.h "$(DESTDIR)$(includedir)/ceed/" 640 $(INSTALL_DATA) include/ceed/hash.h "$(DESTDIR)$(includedir)/ceed/" 641 $(INSTALL_DATA) include/ceed/khash.h "$(DESTDIR)$(includedir)/ceed/" 642 $(INSTALL_DATA) $(libceed) "$(DESTDIR)$(libdir)/" 643 $(INSTALL_DATA) $(OBJDIR)/ceed.pc "$(DESTDIR)$(pkgconfigdir)/" 644 $(INSTALL_DATA) include/ceed.h "$(DESTDIR)$(includedir)/" 645 $(INSTALL_DATA) include/ceedf.h "$(DESTDIR)$(includedir)/" 646 647.PHONY : all cln clean doxygen doc lib install par print test tst prove prv prove-all junit examples style style-c style-py tidy iwyu info info-backends info-backends-all 648 649cln clean : 650 $(RM) -r $(OBJDIR) $(LIBDIR) dist *egg* .pytest_cache *cffi* 651 $(call quiet,MAKE) -C examples clean NEK5K_DIR="$(abspath $(NEK5K_DIR))" 652 $(call quiet,MAKE) -C python/tests clean 653 $(RM) benchmarks/*output.txt 654 655distclean : clean 656 $(RM) -r doc/html doc/sphinx/build $(CONFIG) 657 658DOXYGEN ?= doxygen 659doxygen : 660 $(DOXYGEN) -q Doxyfile 661 662doc-html doc-latexpdf doc-epub doc-livehtml : doc-% : doxygen 663 make -C doc/sphinx $* 664 665doc : doc-html 666 667style-c : 668 @astyle --options=.astylerc \ 669 $(filter-out include/ceedf.h $(wildcard tests/t*-f.h), \ 670 $(wildcard include/*.h interface/*.[ch] tests/*.[ch] backends/*/*.[ch] \ 671 examples/*/*/*.[ch] examples/*/*.[ch] examples/*/*.[ch]pp gallery/*/*.[ch])) 672 673AUTOPEP8 = autopep8 674style-py : AUTOPEP8_ARGS = --in-place --aggressive 675style-py : 676 @$(AUTOPEP8) $(AUTOPEP8_ARGS) $(wildcard *.py python**/*.py python/tests/*.py examples**/*.py doc/sphinx/source**/*.py benchmarks/*.py) 677 678style : style-c style-py 679 680CLANG_TIDY ?= clang-tidy 681 682%.c.tidy : %.c 683 $(CLANG_TIDY) $(TIDY_OPTS) $^ -- $(CPPFLAGS) --std=c99 -I$(CUDA_DIR)/include -I$(HIP_DIR)/include 684 685%.cpp.tidy : %.cpp 686 $(CLANG_TIDY) $(TIDY_OPTS) $^ -- $(CPPFLAGS) --std=c++11 -I$(CUDA_DIR)/include -I$(OCCA_DIR)/include -I$(HIP_DIR)/include 687 688tidy_c : $(libceed.c:%=%.tidy) 689tidy_cpp : $(libceed.cpp:%=%.tidy) 690 691tidy : tidy_c tidy_cpp 692 693ifneq ($(wildcard ../iwyu/*),) 694 IWYU_DIR ?= ../iwyu 695 IWYU_CC ?= $(IWYU_DIR)/build/bin/include-what-you-use 696endif 697 698iwyu : CC=$(IWYU_CC) 699iwyu : lib 700 701print : 702 @echo $(VAR)=$($(VAR)) 703 704print-% : 705 $(info [ variable name]: $*) 706 $(info [ origin]: $(origin $*)) 707 $(info [ flavor]: $(flavor $*)) 708 $(info [ value]: $(value $*)) 709 $(info [expanded value]: $($*)) 710 $(info ) 711 @true 712 713# "make configure" detects any variables passed on the command line or 714# previously set in config.mk, caching them in config.mk as simple 715# (:=) variables. Variables set in config.mk or on the command line 716# take precedence over the defaults provided in the file. Typical 717# usage: 718# 719# make configure CC=/path/to/my/cc CUDA_DIR=/opt/cuda 720# make 721# make prove 722# 723# The values in the file can be updated by passing them on the command 724# line, e.g., 725# 726# make configure CC=/path/to/other/clang 727 728# All variables to consider for caching 729CONFIG_VARS = CC CXX FC NVCC NVCC_CXX HIPCC \ 730 OPT CFLAGS CPPFLAGS CXXFLAGS FFLAGS NVCCFLAGS HIPCCFLAGS \ 731 AR ARFLAGS LDFLAGS LDLIBS LIBCXX SED \ 732 MAGMA_DIR OCCA_DIR XSMM_DIR CUDA_DIR CUDA_ARCH MFEM_DIR PETSC_DIR NEK5K_DIR HIP_DIR HIP_ARCH 733 734# $(call needs_save,CFLAGS) returns true (a nonempty string) if CFLAGS 735# was set on the command line or in config.mk (where it will appear as 736# a simple variable). 737needs_save = $(or $(filter command line,$(origin $(1))),$(filter simple,$(flavor $(1)))) 738 739configure : 740 $(file > $(CONFIG)) 741 $(foreach v,$(CONFIG_VARS),$(if $(call needs_save,$(v)),$(file >> $(CONFIG),$(v) := $($(v))))) 742 @echo "Configuration cached in $(CONFIG):" 743 @cat $(CONFIG) 744 745wheel : export MARCHFLAG = -march=generic 746wheel : export WHEEL_PLAT = manylinux2010_x86_64 747wheel : 748 docker run -it --user $(shell id -u):$(shell id -g) --rm -v $(PWD):/io -w /io \ 749 -e MARCHFLAG -e WHEEL_PLAT \ 750 quay.io/pypa/$(WHEEL_PLAT) python/make-wheels.sh 751 752.PHONY : configure wheel 753 754# Include *.d deps when not -B = --always-make: useful if the paths are wonky in a container 755-include $(if $(filter B,$(MAKEFLAGS)),,$(libceed.c:%.c=$(OBJDIR)/%.d) $(tests.c:tests/%.c=$(OBJDIR)/%.d)) 756