Skip to content

Commit

Permalink
Merge pull request #5 from xsdk-project/add-cuda
Browse files Browse the repository at this point in the history
Add CUDA with a couple CUDA enabled examples
  • Loading branch information
balos1 authored Mar 2, 2021
2 parents d0dd34e + e6bf026 commit f66e707
Show file tree
Hide file tree
Showing 13 changed files with 1,574 additions and 16 deletions.
18 changes: 17 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include(FindPackageHandleStandardArgs)

# build options
option(ENABLE_CUDA "Enable CUDA" OFF)
option(CMAKE_CUDA_ARCHITECTURES "CUDA architecture(s) to target" "70")

option(ENABLE_HYPRE "Enable hypre" ON)
set(HYPRE_DIR "${HYPRE_DIR}" CACHE PATH "Path to hypre installation directory")

option(ENABLE_MFEM "Enable MFEM" ON)
set(MFEM_DIR "${MFEM_DIR}" CACHE PATH "Path to MFEM installation directory")

option(ENABLE_MAGMA "Enable MAGMA" OFF)
set(MAGMA_DIR "${MAGMA_DIR}" CACHE PATH "Path to MAGMA installation directory")

option(ENABLE_PETSC "Enable PETSc" ON)
set(PETSC_DIR "${PETSC_DIR}" CACHE PATH "Path to PETSc installation directory")

Expand All @@ -27,18 +33,28 @@ set(TRILINOS_DIR "${Trilinos_DIR}" CACHE PATH "Path to Trilinos installation dir

set(METIS_DIR "${METIS_DIR}" CACHE PATH "Path to Metis installation directory")

if(ENABLE_CUDA)
enable_language(CUDA)
set(CMAKE_CUDA_HOST_COMPILER ${CMAKE_CXX_COMPILER})
endif()

# check for hypre
if(ENABLE_HYPRE)
find_package(HYPRE REQUIRED)
endif()

# check for PETSc
# check for MFEM
if(ENABLE_MFEM)
find_package(ZLIB REQUIRED)
find_package(MFEM REQUIRED)
find_package(Ginkgo REQUIRED)
endif()

# check for MAGMA
if(ENABLE_MAGMA)
find_package(MAGMA REQUIRED)
endif()

# check for PETSC
if(ENABLE_PETSC)
find_package(PETSC REQUIRED)
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@ in the README.md files in the library subfolders. For more information on the x
| hypre/ij_laplacian.c | HYPRE+SuperLU_Dist | 2D Laplacian problem |
| libensemble/test_persistent_aposmm_tao.py | libEnsemble+PETSc | 2D constrained optimization problem |
| mfem/hypre-superlu/convdiff.cpp | MFEM+HYPRE+SuperLU_Dist | 2D steady state convective diffusion |
| mfem/ginkgo/mfem_ex1_gko.cpp | MFEM+Ginkgo | 2D Poisson problem with Ginko solver |
| mfem/petsc/obstacle.cpp | MFEM+PETSc | Membrane obstacle problem (min energy functional) |
| mfem/sundials/transient-heat.cpp | MFEM+SUNDIALS | 2D Transient nonlinear heat conduction |
| mfem/sundials/advection.cpp | MFEM+SUNDIALS (CUDA) | 2D Time-dependent advection |
| petsc/ex19.c | PETSc+HYPRE+SuperLU_Dist | 2D nonlinear driven cavity problem |
| sundials/ark_brusselator1D_FEM_sludist.cpp| SUNDIALS+SuperLU_Dist | Chemical kinetics brusselator problem |
| sundials/cv_petsc_ex7.c | SUNDIALS+PETSc | 2D nonlinear PDE solution |
| trilinos/SimpleSolve_WithParameters.cpp | Trilinos+SuperLU_Dist | Small linear system direct solution |
| mfem/ginkgo/mfem_ex1_gko.cpp | MFEM+Ginkgo | 2D Poisson problem with Ginko solver |

These examples are currently in the repo but will not be enabled until we release a new version of the xSDK.
These examples are currently in the repo but will not be enabled in the xsdk-examples spack package until we release a new version of the xSDK.
They can still be built using CMake directly.

| Example | Libraries | Description |
|:-------------------------------------------|:----------------------------|:--------------------------------------------------|
| sundials/cvRoberts_blockdiag_magma.cpp | SUNDIALS+MAGMA (CUDA) | Solves a group of chemical kinetics ODEs |

## Install the code samples

Expand Down
108 changes: 108 additions & 0 deletions cmake/FindMAGMA.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# SUNDIALS Copyright Start
# Copyright (c) 2002-2021, Lawrence Livermore National Security
# and Southern Methodist University.
# All rights reserved.
#
# See the top-level LICENSE and NOTICE files for details.
#
# SPDX-License-Identifier: BSD-3-Clause
# SUNDIALS Copyright End
# -----------------------------------------------------------------------------
# Find module that locates the MAGMA linear algebra library.
# -----------------------------------------------------------------------------

# find the MAGMA include path
find_path(MAGMA_INCLUDE_DIR magma_v2.h
NAMES magma_v2.h
HINTS ${MAGMA_DIR} $ENV{MAGMA_DIR}
PATH_SUFFIXES include
NO_DEFAULT_PATH
DOC "Directory with MAGMA header"
)

# find the main MAGMA library
find_library(MAGMA_LIBRARY
NAMES magma
HINTS ${MAGMA_DIR} $ENV{MAGMA_DIR}
PATH_SUFFIXES lib lib64
NO_DEFAULT_PATH
DOC "The MAGMA library.")

# Find the optional sparse component
if("SPARSE" IN_LIST MAGMA_FIND_COMPONENTS)
set(_sparse_required MAGMA_SPARSE_LIBRARY)
find_library(MAGMA_SPARSE_LIBRARY
NAMES magma_sparse
HINTS ${MAGMA_DIR} $ENV{MAGMA_DIR}
PATH_SUFFIXES lib lib64
NO_DEFAULT_PATH
DOC "The MAGMA sparse library.")
else()
set(_sparse_required )
endif()

# Determine MAGMA version and libraries it depends on
if(MAGMA_LIBRARY AND MAGMA_INCLUDE_DIR)
get_filename_component(libdir ${MAGMA_LIBRARY} DIRECTORY)
find_file(MAGMA_PKG_CONFIG_PATH magma.pc PATHS "${libdir}/pkgconfig")

if(MAGMA_PKG_CONFIG_PATH)
file(STRINGS ${MAGMA_PKG_CONFIG_PATH} _version_string REGEX "Version: [0-9].[0-9].[0-9]")
string(REGEX MATCHALL "[0-9]" _version_full "${_version_string}")

list(GET _version_full 0 _version_major)
list(GET _version_full 1 _version_minor)
list(GET _version_full 2 _version_patch)

set(MAGMA_VERSION "${_version_major}.${_version_minor}.${_version_patch}")

file(STRINGS ${MAGMA_PKG_CONFIG_PATH} _libraries_string REGEX "Libs:.*")
string(REPLACE " " ";" _libraries_list ${_libraries_string})
list(SUBLIST _libraries_list 1 -1 _libraries_list) # remove 'Libs:' part

set(_interface_libraires )
foreach(lib ${_libraries_list})
if(NOT (lib STREQUAL "-lmagma" OR lib STREQUAL "-lmagma_sparse" OR lib STREQUAL "-L\${libdir}" OR lib STREQUAL "") )
string(REPLACE "-l" "" lib ${lib})
list(APPEND _interface_libraires ${lib})
endif()
endforeach()
endif()
endif()

set(MAGMA_LIBRARIES "${MAGMA_LIBRARY};${_interface_libraires}")

find_package_handle_standard_args(MAGMA
REQUIRED_VARS
MAGMA_LIBRARY
MAGMA_LIBRARIES
MAGMA_INCLUDE_DIR
${_sparse_required}
VERSION_VAR
MAGMA_VERSION
)

# Create target for MAGMA
if(MAGMA_FOUND)

if(NOT TARGET XSDK::MAGMA)
add_library(XSDK::MAGMA UNKNOWN IMPORTED)
endif()

set_target_properties(XSDK::MAGMA PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${MAGMA_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "${_interface_libraires}"
IMPORTED_LOCATION "${MAGMA_LIBRARY}")

if(MAGMA_SPARSE_LIBRARY)
if(NOT TARGET XSDK::MAGMA_SPARSE)
add_library(XSDK::MAGMA_SPARSE UNKNOWN IMPORTED)
endif()

set_target_properties(XSDK::MAGMA_SPARSE PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${MAGMA_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "${MAGMA_LIBRARY};${_interface_libraires}"
IMPORTED_LOCATION "${MAGMA_SPARSE_LIBRARY}")
endif()

endif()
17 changes: 12 additions & 5 deletions cmake/FindSUNDIALS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,23 @@ if(NOT SUNDIALS_FIND_COMPONENTS)
"nvecmpiplusx")
endif()

if(ENABLE_SUPERLU)
list(APPEND SUNDIALS_FIND_COMPONENTS "sunmatrixslunrloc")
list(APPEND SUNDIALS_FIND_COMPONENTS "sunlinsolsuperludist")
if(ENABLE_CUDA)
list(APPEND SUNDIALS_FIND_COMPONENTS "nveccuda")
endif()
if(ENABLE_MFEM)
list(APPEND SUNDIALS_FIND_COMPONENTS "kinsol")
endif()
if(ENABLE_MAGMA)
list(APPEND SUNDIALS_FIND_COMPONENTS "sunmatrixmagmadense")
list(APPEND SUNDIALS_FIND_COMPONENTS "sunlinsolmagmadense")
endif()
if(ENABLE_PETSC)
list(APPEND SUNDIALS_FIND_COMPONENTS "nvecpetsc")
list(APPEND SUNDIALS_FIND_COMPONENTS "sunnonlinsolpetscsnes")
endif()
if(ENABLE_MFEM)
list(APPEND SUNDIALS_FIND_COMPONENTS "kinsol")
if(ENABLE_SUPERLU)
list(APPEND SUNDIALS_FIND_COMPONENTS "sunmatrixslunrloc")
list(APPEND SUNDIALS_FIND_COMPONENTS "sunlinsolsuperludist")
endif()

# find the library for each component
Expand Down
4 changes: 2 additions & 2 deletions mfem/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.12)
project(mfem-examples
DESCRIPTION "MFEM Examples"
LANGUAGES CXX)

add_subdirectory(ginkgo)
add_subdirectory(hypre-superlu)
add_subdirectory(ginkgo)
add_subdirectory(petsc)
add_subdirectory(sundials)

Expand Down
106 changes: 106 additions & 0 deletions mfem/data/periodic-hexagon.mesh
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
MFEM mesh v1.0

#
# MFEM Geometry Types (see mesh/geom.hpp):
#
# POINT = 0
# SEGMENT = 1
# TRIANGLE = 2
# SQUARE = 3
# TETRAHEDRON = 4
# CUBE = 5
#

dimension
2

# format: <attribute> <geometry type> <vertex 0> <vertex 1> ...
elements
12

1 3 0 2 8 5
1 3 2 1 3 8
1 3 5 8 6 11
1 3 8 3 0 6

2 3 0 4 9 6
2 3 4 1 2 9
2 3 6 9 7 11
2 3 9 2 0 7

3 3 0 3 10 7
3 3 3 1 4 10
3 3 7 10 5 11
3 3 10 4 0 5

boundary
0

vertices
12

nodes
FiniteElementSpace
FiniteElementCollection: L2_T1_2D_P1
VDim: 2
Ordering: 1

-0.50 -0.8660254037844386
0.00 -0.8660254037844386
-0.25 -0.4330127018922193
0.25 -0.4330127018922193

0.00 -0.8660254037844386
0.50 -0.8660254037844386
0.25 -0.4330127018922193
0.75 -0.4330127018922193

-0.25 -0.4330127018922193
0.25 -0.4330127018922193
0.00 0.0
0.50 0.0

0.25 -0.4330127018922193
0.75 -0.4330127018922193
0.50 0.0
1.00 0.0

1.00 0.0
0.75 0.4330127018922193
0.50 0.0
0.25 0.4330127018922193

0.75 0.4330127018922193
0.50 0.8660254037844386
0.25 0.4330127018922193
0.00 0.8660254037844386

0.50 0.0
0.25 0.4330127018922193
0.00 0.0
-0.25 0.4330127018922193

0.25 0.4330127018922193
0.00 0.8660254037844386
-0.25 0.4330127018922193
-0.50 0.8660254037844386

-0.50 0.8660254037844386
-0.75 0.4330127018922193
-0.25 0.4330127018922193
-0.50 0.0

-0.75 0.4330127018922193
-1.00 0.0
-0.50 0.0
-0.75 -0.4330127018922193

-0.25 0.4330127018922193
-0.50 0.0
0.00 0.0
-0.25 -0.4330127018922193

-0.50 0.0
-0.75 -0.4330127018922193
-0.25 -0.4330127018922193
-0.50 -0.8660254037844386
5 changes: 4 additions & 1 deletion mfem/sundials/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
cmake_minimum_required(VERSION 3.12)
project(transient-heat
DESCRIPTION "Transient Heat Conduction using MFEM + SUNDIALS + HYPRE"
LANGUAGES C)
LANGUAGES C CXX)

set(CMAKE_C_COMPILER ${MPI_C_COMPILER})
set(CMAKE_CXX_COMPILER ${MPI_CXX_COMPILER})

add_executable(transient-heat transient-heat.cpp)
target_link_libraries(transient-heat PRIVATE XSDK::MFEM XSDK::SUNDIALS XSDK::HYPRE PETSC::ALL ZLIB::ZLIB)

add_executable(advection advection.cpp)
target_link_libraries(advection PRIVATE XSDK::MFEM XSDK::SUNDIALS XSDK::HYPRE PETSC::ALL ZLIB::ZLIB)

install(TARGETS transient-heat RUNTIME DESTINATION bin)
Loading

0 comments on commit f66e707

Please sign in to comment.