Compare commits
17
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f43172dc4d | ||
|
|
676c2d0262 | ||
|
|
1a7db93b57 | ||
|
|
bd11a96d81 | ||
|
|
d06b50b52c | ||
|
|
259c0133b7 | ||
|
|
14aceac330 | ||
|
|
f41011fed6 | ||
|
|
f676068887 | ||
|
|
c6d64bc432 | ||
|
|
da58a23a51 | ||
|
|
8b2acc964f | ||
|
|
f34ea6d88b | ||
|
|
86ae459f13 | ||
|
|
ec7f405a71 | ||
|
|
9fe8a97d1e | ||
|
|
86e07bee68 |
+7
-1
@@ -215,6 +215,7 @@ if (MFEM_USE_HIP)
|
||||
endif()
|
||||
find_package(HIP REQUIRED)
|
||||
find_package(HIPSPARSE REQUIRED)
|
||||
find_package(HIPBLAS REQUIRED)
|
||||
endif()
|
||||
|
||||
# OpenMP
|
||||
@@ -482,6 +483,11 @@ if (MFEM_USE_ENZYME)
|
||||
find_package(ENZYME REQUIRED)
|
||||
endif()
|
||||
|
||||
# MAGMA
|
||||
if (MFEM_USE_MAGMA)
|
||||
find_package(MAGMA REQUIRED)
|
||||
endif()
|
||||
|
||||
# MFEM_TIMER_TYPE
|
||||
if (NOT DEFINED MFEM_TIMER_TYPE)
|
||||
if (APPLE)
|
||||
@@ -522,7 +528,7 @@ set(MFEM_TPLS OPENMP HYPRE LAPACK BLAS SuperLUDist STRUMPACK METIS SuiteSparse
|
||||
SUNDIALS PETSC SLEPC MUMPS AXOM FMS CONDUIT Ginkgo GNUTLS GSLIB
|
||||
NETCDF MPFR PUMI HIOP POSIXCLOCKS MFEMBacktrace ZLIB OCCA CEED RAJA UMPIRE
|
||||
ADIOS2 CUBLAS CUSPARSE MKL_CPARDISO AMGX CALIPER CODIPACK BENCHMARK PARELAG
|
||||
MPI_CXX HIP HIPSPARSE MOONOLITH BLITZ ALGOIM ENZYME)
|
||||
MPI_CXX HIP HIPSPARSE HIPBLAS MOONOLITH BLITZ ALGOIM ENZYME MAGMA)
|
||||
|
||||
# Add all *_FOUND libraries in the variable TPL_LIBRARIES.
|
||||
set(TPL_LIBRARIES "")
|
||||
|
||||
@@ -61,6 +61,7 @@ set(MFEM_USE_ALGOIM @MFEM_USE_ALGOIM@)
|
||||
set(MFEM_USE_BENCHMARK @MFEM_USE_BENCHMARK@)
|
||||
set(MFEM_USE_PARELAG @MFEM_USE_PARELAG@)
|
||||
set(MFEM_USE_ENZYME @MFEM_USE_ENZYME@)
|
||||
set(MFEM_USE_MAGMA @MFEM_USE_MAGMA@)
|
||||
|
||||
set(MFEM_CXX_COMPILER "@CMAKE_CXX_COMPILER@")
|
||||
set(MFEM_CXX_FLAGS "@CMAKE_CXX_FLAGS@")
|
||||
|
||||
@@ -193,4 +193,8 @@
|
||||
// Enable Enzyme for AD
|
||||
#cmakedefine MFEM_USE_ENZYME
|
||||
|
||||
// Enable MAGMA linear algebra package
|
||||
#cmakedefine MFEM_USE_MAGMA
|
||||
|
||||
|
||||
#endif // MFEM_CONFIG_HEADER
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
# Copyright (c) 2010-2022, Lawrence Livermore National Security, LLC. Produced
|
||||
# at the Lawrence Livermore National Laboratory. All Rights reserved. See files
|
||||
# LICENSE and NOTICE for details. LLNL-CODE-806117.
|
||||
#
|
||||
# This file is part of the MFEM library. For more information and source code
|
||||
# availability visit https://mfem.org.
|
||||
#
|
||||
# MFEM is free software; you can redistribute it and/or modify it under the
|
||||
# terms of the BSD-3 license. We welcome feedback and contributions, see file
|
||||
# CONTRIBUTING.md for details.
|
||||
|
||||
# Defines the following variables:
|
||||
# - MAGMA_FOUND
|
||||
# - MAGMA_LIBRARIES
|
||||
# - MAGMA_INCLUDE_DIRS
|
||||
|
||||
include(MfemCmakeUtilities)
|
||||
mfem_find_package(MAGMA MAGMA MAGMA_DIR "include" "magma_v2.h" "lib" "magma;magma_sparse"
|
||||
"Paths to headers required by MAGMA." "Libraries required by MAGMA.")
|
||||
@@ -873,7 +873,7 @@ function(mfem_export_mk_files)
|
||||
MFEM_USE_HIP MFEM_USE_RAJA MFEM_USE_OCCA MFEM_USE_CEED MFEM_USE_CALIPER
|
||||
MFEM_USE_UMPIRE MFEM_USE_SIMD MFEM_USE_ADIOS2 MFEM_USE_MKL_CPARDISO
|
||||
MFEM_USE_ADFORWARD MFEM_USE_CODIPACK MFEM_USE_BENCHMARK MFEM_USE_PARELAG
|
||||
MFEM_USE_MOONOLITH MFEM_USE_ALGOIM MFEM_USE_ENZYME)
|
||||
MFEM_USE_MOONOLITH MFEM_USE_ALGOIM MFEM_USE_ENZYME MFEM_USE_MAGMA)
|
||||
foreach(var ${CONFIG_MK_BOOL_VARS})
|
||||
if (${var})
|
||||
set(${var} YES)
|
||||
|
||||
@@ -198,4 +198,8 @@
|
||||
// Enable the Enzyme LLVM plugin
|
||||
// #define MFEM_USE_ENZYME
|
||||
|
||||
// Enable the MAGMA package
|
||||
// #define MFEM_USE_MAGMA
|
||||
|
||||
|
||||
#endif // MFEM_CONFIG_HEADER
|
||||
|
||||
@@ -63,6 +63,7 @@ MFEM_USE_CODIPACK = @MFEM_USE_CODIPACK@
|
||||
MFEM_USE_BENCHMARK = @MFEM_USE_BENCHMARK@
|
||||
MFEM_USE_PARELAG = @MFEM_USE_PARELAG@
|
||||
MFEM_USE_ENZYME = @MFEM_USE_ENZYME@
|
||||
MFEM_USE_MAGMA = @MFEM_USE_MAGMA@
|
||||
|
||||
# Compiler, compile options, and link options
|
||||
MFEM_CXX = @MFEM_CXX@
|
||||
|
||||
@@ -65,6 +65,7 @@ option(MFEM_USE_CODIPACK "Enable automatic differentiation (AD) using CoDiPack"
|
||||
option(MFEM_USE_BENCHMARK "Enable Google Benchmark" OFF)
|
||||
option(MFEM_USE_PARELAG "Enable ParELAG" OFF)
|
||||
option(MFEM_USE_ENZYME "Enable Enzyme" OFF)
|
||||
option(MFEM_USE_MAGMA "Enable MAGMA" OFF)
|
||||
|
||||
# Optional overrides for autodetected MPIEXEC and MPIEXEC_NUMPROC_FLAG
|
||||
# set(MFEM_MPIEXEC "mpirun" CACHE STRING "Command for running MPI tests")
|
||||
@@ -256,6 +257,8 @@ set(CODIPACK_INCLUDE_DIRS "${MFEM_DIR}/../CoDiPack/include" CACHE STRING
|
||||
"Path to CoDiPack headers.")
|
||||
set(CODIPACK_LIBRARIES "")
|
||||
|
||||
set(MAGMA_DIR "${MFEM_DIR}/../magma" CACHE PATH "Path to MAGMA")
|
||||
|
||||
# Some useful variables:
|
||||
set(CMAKE_SKIP_PREPROCESSED_SOURCE_RULES ON) # Skip *.i rules
|
||||
set(CMAKE_SKIP_ASSEMBLY_SOURCE_RULES ON) # Skip *.s rules
|
||||
|
||||
+7
-2
@@ -166,6 +166,7 @@ MFEM_USE_CODIPACK = NO
|
||||
MFEM_USE_BENCHMARK = NO
|
||||
MFEM_USE_PARELAG = NO
|
||||
MFEM_USE_ENZYME = NO
|
||||
MFEM_USE_MAGMA = NO
|
||||
|
||||
# MPI library compile and link flags
|
||||
# These settings are used only when building MFEM with MPI + HIP
|
||||
@@ -459,11 +460,11 @@ GSLIB_LIB = -L$(GSLIB_DIR)/lib -lgs
|
||||
|
||||
# CUDA library configuration
|
||||
CUDA_OPT =
|
||||
CUDA_LIB = -lcusparse
|
||||
CUDA_LIB = -lcusparse -lcublas
|
||||
|
||||
# HIP library configuration
|
||||
HIP_OPT =
|
||||
HIP_LIB = -L$(HIP_DIR)/lib $(XLINKER)-rpath,$(HIP_DIR)/lib -lhipsparse
|
||||
HIP_LIB = -L$(HIP_DIR)/lib $(XLINKER)-rpath,$(HIP_DIR)/lib -lhipsparse -lhipblas
|
||||
|
||||
# OCCA library configuration
|
||||
OCCA_DIR = @MFEM_DIR@/../occa
|
||||
@@ -560,6 +561,10 @@ ENZYME_VERSION ?= 14
|
||||
ENZYME_OPT = -fno-experimental-new-pass-manager -Xclang -load -Xclang $(ENZYME_DIR)/ClangEnzyme-$(ENZYME_VERSION).so
|
||||
ENZYME_LIB = ""
|
||||
|
||||
MAGMA_DIR ?= @MFEM_DIR@/../magma
|
||||
MAGMA_OPT = -I${MAGMA_DIR}/include/
|
||||
MAGMA_LIB = -L${MAGMA_DIR}/lib/ -lmagma -lmagma_sparse
|
||||
|
||||
# If YES, enable some informational messages
|
||||
VERBOSE = NO
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ list(APPEND SRCS
|
||||
sparsemat.cpp
|
||||
sparsesmoothers.cpp
|
||||
vector.cpp
|
||||
libBatchSolver.cpp
|
||||
)
|
||||
|
||||
list(APPEND HDRS
|
||||
@@ -57,6 +58,7 @@ list(APPEND HDRS
|
||||
tensor.hpp
|
||||
dual.hpp
|
||||
vector.hpp
|
||||
libBatchSolver.hpp
|
||||
)
|
||||
|
||||
if (MFEM_USE_MPI)
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
// Copyright (c) 2010-2022, Lawrence Livermore National Security, LLC. Produced
|
||||
// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
|
||||
// LICENSE and NOTICE for details. LLNL-CODE-806117.
|
||||
//
|
||||
// This file is part of the MFEM library. For more information and source code
|
||||
// availability visit https://mfem.org.
|
||||
//
|
||||
// MFEM is free software; you can redistribute it and/or modify it under the
|
||||
// terms of the BSD-3 license. We welcome feedback and contributions, see file
|
||||
// CONTRIBUTING.md for details.
|
||||
|
||||
#include "libBatchSolver.hpp"
|
||||
|
||||
namespace mfem
|
||||
{
|
||||
|
||||
void LibBatchMult::Mult(const Vector &b, Vector &x)
|
||||
{
|
||||
|
||||
#if defined(MFEM_USE_CUDA) || defined(MFEM_USE_HIP)
|
||||
if (Device::Allows(Backend::DEVICE_MASK))
|
||||
{
|
||||
#if defined(MFEM_USE_MAGMA)
|
||||
const double alpha = 1.0, beta = 0.0;
|
||||
#else
|
||||
const double alpha_t = 1.0, beta_t = 0.0;
|
||||
const double* alpha = &alpha_t;
|
||||
const double* beta = &beta_t;
|
||||
#endif
|
||||
|
||||
#if defined(MFEM_USE_HIP) || (defined(MFEM_USE_CUDA) && CUDA_VERSION >= 11070) || defined(MFEM_USE_MAGMA)
|
||||
#if defined(MFEM_USE_MAGMA)
|
||||
magmablas_dgemv_batched_strided(MagmaNoTrans,
|
||||
#else
|
||||
MFEM_SUB_cu_or_hip(blasStatus_t)
|
||||
status = MFEM_SUB_cu_or_hip(blasDgemvStridedBatched)(MFEM_SUB_Cuda_or_Hip(
|
||||
BLAS::Handle)(),
|
||||
MFEM_SUB_CU_or_HIP(BLAS_OP_N),
|
||||
#endif
|
||||
mat_size,
|
||||
mat_size,
|
||||
alpha,
|
||||
MatrixBatch.Read(),
|
||||
mat_size,
|
||||
mat_size * mat_size,
|
||||
b.Read(),
|
||||
1,
|
||||
mat_size,
|
||||
beta,
|
||||
x.Write(),
|
||||
1,
|
||||
mat_size,
|
||||
num_mats
|
||||
#if defined(MFEM_USE_MAGMA)
|
||||
, queue
|
||||
#endif
|
||||
);
|
||||
#else
|
||||
MFEM_SUB_cu_or_hip(blasStatus_t)
|
||||
status = MFEM_SUB_cu_or_hip(blasDgemmStridedBatched)(MFEM_SUB_Cuda_or_Hip(
|
||||
BLAS::Handle)(),
|
||||
MFEM_SUB_CU_or_HIP(BLAS_OP_N),
|
||||
MFEM_SUB_CU_or_HIP(BLAS_OP_N),
|
||||
mat_size,
|
||||
1,
|
||||
mat_size,
|
||||
alpha,
|
||||
MatrixBatch.Read(),
|
||||
mat_size,
|
||||
mat_size * mat_size,
|
||||
b.Read(),
|
||||
mat_size,
|
||||
mat_size,
|
||||
beta,
|
||||
x.Write(),
|
||||
mat_size,
|
||||
mat_size,
|
||||
num_mats);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined(MFEM_USE_MAGMA)
|
||||
MFEM_VERIFY(status == MFEM_SUB_CU_or_HIP(BLAS_STATUS_SUCCESS),
|
||||
"blasDgemvStridedBatched");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
const int rows = MatrixBatch.SizeI();
|
||||
const int cols = MatrixBatch.SizeJ();
|
||||
const int N = MatrixBatch.SizeK();
|
||||
|
||||
for (int e=0; e<N; ++e)
|
||||
{
|
||||
|
||||
//matvec
|
||||
for (int c=0; c<cols; ++c)
|
||||
{
|
||||
double dot=0.0;
|
||||
for (int r=0; r<rows; ++r)
|
||||
{
|
||||
int idx = r + rows * e;
|
||||
dot += MatrixBatch(c, r, e) * b(idx);
|
||||
}
|
||||
int idx = c + cols * e;
|
||||
x(idx) = dot;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} //mfem namespace
|
||||
@@ -0,0 +1,115 @@
|
||||
// Copyright (c) 2010-2022, Lawrence Livermore National Security, LLC. Produced
|
||||
// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
|
||||
// LICENSE and NOTICE for details. LLNL-CODE-806117.
|
||||
//
|
||||
// This file is part of the MFEM library. For more information and source code
|
||||
// availability visit https://mfem.org.
|
||||
//
|
||||
// MFEM is free software; you can redistribute it and/or modify it under the
|
||||
// terms of the BSD-3 license. We welcome feedback and contributions, see file
|
||||
// CONTRIBUTING.md for details.
|
||||
|
||||
#ifndef MFEM_LIB_BATCH_SOLVER
|
||||
#define MFEM_LIB_BATCH_SOLVER
|
||||
|
||||
#include "../config/config.hpp"
|
||||
#include "../general/globals.hpp"
|
||||
#include "matrix.hpp"
|
||||
#include "densemat.hpp"
|
||||
|
||||
#if defined(MFEM_USE_CUDA)
|
||||
// These macros prefixes the argument with `cuda` or `hip`, e.g. `cudaStream_t` or `hipStream_t`
|
||||
#define MFEM_SUB_cuda_or_hip(stub) cuda##stub
|
||||
#define MFEM_SUB_cu_or_hip(stub) cu##stub
|
||||
#define MFEM_SUB_Cuda_or_Hip(stub) Cuda##stub
|
||||
#define MFEM_SUB_CUDA_or_HIP(stub) CUDA##stub
|
||||
#define MFEM_SUB_CU_or_HIP(stub) CU##stub
|
||||
|
||||
#include <cuda.h>
|
||||
#include <cublas.h>
|
||||
#include <cusolverDn.h>
|
||||
#include <cuda_runtime.h>
|
||||
#endif // MFEM_USE_CUDA
|
||||
|
||||
#if defined(MFEM_USE_HIP)
|
||||
// These macros prefixes the argument with `cuda` or `hip`, e.g. `cudaStream_t` or `hipStream_t`
|
||||
#define MFEM_SUB_cu_or_hip(stub) hip##stub
|
||||
#define MFEM_SUB_cuda_or_hip(stub) hip##stub
|
||||
#define MFEM_SUB_Cuda_or_Hip(stub) Hip##stub
|
||||
#define MFEM_SUB_CUDA_or_HIP(stub) HIP##stub
|
||||
#define MFEM_SUB_CU_or_HIP(stub) HIP##stub
|
||||
#include <hipblas/hipblas.h>
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <hip/hip_runtime_api.h>
|
||||
#endif // MFEM_USE_HIP
|
||||
|
||||
#if defined(MFEM_USE_MAGMA)
|
||||
#include <magma_v2.h>
|
||||
#endif
|
||||
|
||||
namespace mfem
|
||||
{
|
||||
|
||||
#if defined(MFEM_USE_CUDA) || defined(MFEM_USE_HIP)
|
||||
class MFEM_SUB_Cuda_or_Hip(BLAS)
|
||||
{
|
||||
protected:
|
||||
MFEM_SUB_cu_or_hip(blasHandle_t) handle = nullptr;
|
||||
|
||||
MFEM_SUB_Cuda_or_Hip(BLAS)()
|
||||
{
|
||||
MFEM_SUB_cu_or_hip(blasStatus_t) status = MFEM_SUB_cu_or_hip(blasCreate)(
|
||||
&handle);
|
||||
MFEM_VERIFY(status == MFEM_SUB_CU_or_HIP(BLAS_STATUS_SUCCESS),
|
||||
"Cannot initialize BLAS.");
|
||||
}
|
||||
|
||||
~MFEM_SUB_Cuda_or_Hip(BLAS)() { MFEM_SUB_cu_or_hip(blasDestroy)(handle); }
|
||||
|
||||
static MFEM_SUB_Cuda_or_Hip(BLAS) & Instance()
|
||||
{
|
||||
static MFEM_SUB_Cuda_or_Hip(BLAS) instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
public:
|
||||
static MFEM_SUB_cu_or_hip(blasHandle_t) Handle() { return Instance().handle; }
|
||||
};
|
||||
#endif
|
||||
|
||||
/**
|
||||
Use GPU library calls to perform action of block diagonal matrices
|
||||
**/
|
||||
class LibBatchMult
|
||||
{
|
||||
|
||||
private:
|
||||
DenseTensor &MatrixBatch;
|
||||
|
||||
int mat_size, num_mats;
|
||||
#if defined(MFEM_USE_MAGMA)
|
||||
magma_int_t device = 0;
|
||||
magma_queue_t queue ;
|
||||
#endif
|
||||
public:
|
||||
LibBatchMult() = delete;
|
||||
|
||||
LibBatchMult(DenseTensor &MatrixBatch_) :
|
||||
MatrixBatch(MatrixBatch_),
|
||||
mat_size(MatrixBatch.SizeI()),
|
||||
num_mats(MatrixBatch.SizeK())
|
||||
{
|
||||
#if defined(MFEM_USE_MAGMA)
|
||||
magma_setdevice(device);
|
||||
magma_queue_create(device, &queue);
|
||||
#endif
|
||||
};
|
||||
|
||||
//Action of block diagonal matrix
|
||||
void Mult(const Vector &b, Vector &x);
|
||||
};
|
||||
|
||||
|
||||
} // namespace mfem
|
||||
|
||||
#endif
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "operator.hpp"
|
||||
#include "matrix.hpp"
|
||||
#include "sparsemat.hpp"
|
||||
#include "libBatchSolver.hpp"
|
||||
#include "complex_operator.hpp"
|
||||
#include "complex_densemat.hpp"
|
||||
#include "blockvector.hpp"
|
||||
|
||||
@@ -278,7 +278,7 @@ endif
|
||||
MFEM_REQ_LIB_DEPS = ENZYME SUPERLU MUMPS METIS FMS CONDUIT SIDRE LAPACK SUNDIALS\
|
||||
SUITESPARSE STRUMPACK GINKGO GNUTLS NETCDF PETSC SLEPC MPFR PUMI HIOP\
|
||||
GSLIB OCCA CEED RAJA UMPIRE MKL_CPARDISO AMGX CALIPER PARELAG BENCHMARK\
|
||||
MOONOLITH ALGOIM
|
||||
MOONOLITH ALGOIM MAGMA
|
||||
|
||||
|
||||
PETSC_ERROR_MSG = $(if $(PETSC_FOUND),,. PETSC config not found: $(PETSC_VARS))
|
||||
@@ -347,7 +347,7 @@ MFEM_DEFINES = MFEM_VERSION MFEM_VERSION_STRING MFEM_GIT_STRING MFEM_USE_MPI\
|
||||
MFEM_USE_SIMD MFEM_USE_ADIOS2 MFEM_USE_MKL_CPARDISO MFEM_USE_AMGX\
|
||||
MFEM_USE_MUMPS MFEM_USE_ADFORWARD MFEM_USE_CODIPACK MFEM_USE_CALIPER\
|
||||
MFEM_USE_BENCHMARK MFEM_USE_PARELAG MFEM_USE_ALGOIM MFEM_USE_ENZYME\
|
||||
MFEM_SOURCE_DIR MFEM_INSTALL_DIR MFEM_SHARED_BUILD
|
||||
MFEM_USE_MAGMA MFEM_SOURCE_DIR MFEM_INSTALL_DIR MFEM_SHARED_BUILD
|
||||
|
||||
# List of makefile variables that will be written to config.mk:
|
||||
MFEM_CONFIG_VARS = MFEM_CXX MFEM_HOST_CXX MFEM_CPPFLAGS MFEM_CXXFLAGS\
|
||||
@@ -710,6 +710,7 @@ status info:
|
||||
$(info MFEM_USE_BENCHMARK = $(MFEM_USE_BENCHMARK))
|
||||
$(info MFEM_USE_PARELAG = $(MFEM_USE_PARELAG))
|
||||
$(info MFEM_USE_ENZYME = $(MFEM_USE_ENZYME))
|
||||
$(info MFEM_USE_MAGMA = $(MFEM_USE_MAGMA))
|
||||
$(info MFEM_CXX = $(value MFEM_CXX))
|
||||
$(info MFEM_HOST_CXX = $(value MFEM_HOST_CXX))
|
||||
$(info MFEM_CPPFLAGS = $(value MFEM_CPPFLAGS))
|
||||
|
||||
Reference in New Issue
Block a user