Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 8 additions & 51 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)

project( Waves2AMR
LANGUAGES C CXX
)
project(Waves2AMR LANGUAGES C CXX)

message(STATUS "CMake version: ${CMAKE_VERSION}")
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

#
# Check if CMAKE_BUILD_TYPE is given. If not, use default
#
if ( NOT CMAKE_BUILD_TYPE )
set(CMAKE_CONFIGURATION_TYPES "Release;Debug;MinSizeRel;RelWithDebInfo")
set(CMAKE_BUILD_TYPE Release
CACHE STRING
"Choose the build type, e.g. Release, Debug, or RelWithDebInfo." FORCE)
else ()
message(STATUS "Build type set by user to '${CMAKE_BUILD_TYPE}'.")
endif()

#
# Options
#
option(WAVES2AMR_ENABLE_MPI "Enable MPI" OFF)

set(WAVES2AMR_GPU_BACKEND_VALUES NONE SYCL CUDA HIP)
Expand All @@ -31,9 +14,6 @@ if (NOT WAVES2AMR_GPU_BACKEND IN_LIST WAVES2AMR_GPU_BACKEND_VALUES)
" Must be one of ${WAVES2AMR_GPU_BACKEND_VALUES}")
endif ()

#
# Find AMReX, check for required components
#
if (NOT TARGET AMReX::amrex)
set(AMREX_REQUIRED_COMPONENTS 3D DOUBLE)
if (WAVES2AMR_ENABLE_MPI)
Expand All @@ -45,58 +25,36 @@ if (NOT TARGET AMReX::amrex)
find_package(AMReX CONFIG REQUIRED ${AMREX_REQUIRED_COMPONENTS} )
endif ()

#
# Enable CUDA if requested
#
if (WAVES2AMR_GPU_BACKEND STREQUAL "CUDA")
include(AMReXTargetHelpers)
endif ()

# FFTW library is required
include_directories(${FFTW_DIR}/include/)
set(fftw_lib ${FFTW_DIR}/lib/libfftw3.a)

#
# Define the object library to compile
#
add_library(waves_2_amr OBJECT)
if (BUILD_SHARED_LIBS)
set_target_properties(waves_2_amr PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
# Link required libraries
target_link_libraries(waves_2_amr PUBLIC AMReX::amrex)
target_link_libraries(waves_2_amr PRIVATE ${fftw_lib})

find_package(FFTW REQUIRED)
target_link_libraries(waves_2_amr PUBLIC FFTW::FFTW)

add_subdirectory(src)
add_subdirectory(include)

if (WAVES2AMR_GPU_BACKEND STREQUAL "CUDA")
setup_target_for_cuda_compilation(waves_2_amr)
endif ()

if ( NOT CMAKE_CXX_FLAGS )
target_link_libraries(waves_2_amr PUBLIC AMReX::Flags_CXX)
endif ()


# Installation rules
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

# Create non-object library for use as external target
add_library(waves_2_amr_api)
if (BUILD_SHARED_LIBS)
set_target_properties(waves_2_amr_api PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
target_link_libraries(waves_2_amr_api PUBLIC waves_2_amr)
add_library(${PROJECT_NAME}::waves_2_amr_api ALIAS waves_2_amr)
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS waves_2_amr)

# Collect all headers and make them installable with the target
get_target_property(WAVES2AMR_INCLUDES waves_2_amr SOURCES)
list(FILTER WAVES2AMR_INCLUDES INCLUDE REGEX "\\.h")
set_target_properties(
waves_2_amr PROPERTIES PUBLIC_HEADER "${WAVES2AMR_INCLUDES}")

# Install Waves2AMR
install(
TARGETS waves_2_amr_api waves_2_amr
EXPORT ${PROJECT_NAME}Targets
Expand All @@ -107,7 +65,6 @@ install(
PUBLIC_HEADER DESTINATION include
)

# Make Waves2AMR discoverable using `find_package`
install(
EXPORT ${PROJECT_NAME}Targets
NAMESPACE ${PROJECT_NAME}::
Expand Down
48 changes: 48 additions & 0 deletions cmake/FindFFTW.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# - Find the FFTW3 library
# This will define the following imported target:
#
# FFTW::FFTW - The FFTW library target
#
# and the following variables (for legacy support):
#
# FFTW_FOUND - True if FFTW was found
# FFTW_INCLUDE_DIRS - Include directories for FFTW
# FFTW_LIBRARIES - Libraries to link against

# Look for header
find_path(
FFTW_INCLUDE_DIR
NAMES fftw3.h
PATHS
${FFTW_DIR}
)

# Look for library (shared or static)
find_library(
FFTW_LIBRARY
NAMES fftw3 libfftw3
PATHS
${FFTW_DIR}
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
FFTW
REQUIRED_VARS FFTW_LIBRARY FFTW_INCLUDE_DIR
VERSION_VAR FFTW_VERSION
)

if(FFTW_FOUND)
set(FFTW_LIBRARIES ${FFTW_LIBRARY})
set(FFTW_INCLUDE_DIRS ${FFTW_INCLUDE_DIR})

if(NOT TARGET FFTW::FFTW)
add_library(FFTW::FFTW UNKNOWN IMPORTED)
set_target_properties(FFTW::FFTW PROPERTIES
IMPORTED_LOCATION "${FFTW_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${FFTW_INCLUDE_DIR}"
)
endif()
endif()

mark_as_advanced(FFTW_INCLUDE_DIR FFTW_LIBRARY)
16 changes: 0 additions & 16 deletions src/interp_to_mfab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,6 @@ void interp_to_mfab::interp_velocity_to_field(

// Number of levels
const int nlevels = vfield.size();
// Number of heights relevant to this processor
const int nhts = indvec.size();
// Copy hvec and indvec to device
amrex::Gpu::DeviceVector<int> indvec_dvc(indvec.size());
amrex::Gpu::copy(
Expand All @@ -464,12 +462,6 @@ void interp_to_mfab::interp_velocity_to_field(
amrex::Gpu::DeviceVector<amrex::Real> hvec_dvc(hvec.size());
amrex::Gpu::copy(
amrex::Gpu::hostToDevice, hvec.begin(), hvec.end(), hvec_dvc.begin());
// Get pointers to device vectors
const auto* indvec_ptr = indvec_dvc.data();
const auto* hvec_ptr = hvec_dvc.data();
const auto* uvec_ptr = uvec.data();
const auto* vvec_ptr = vvec.data();
const auto* wvec_ptr = wvec.data();

// Loop through cells and perform interpolation
for (int nl = 0; nl < nlevels; ++nl) {
Expand Down Expand Up @@ -506,8 +498,6 @@ void interp_to_mfab::interp_velocity_to_field(

// Number of levels
const int nlevels = vfield.size();
// Number of heights relevant to this processor
const int nhts = indvec.size();
// Copy hvec and indvec to device
amrex::Gpu::DeviceVector<int> indvec_dvc(indvec.size());
amrex::Gpu::copy(
Expand All @@ -516,12 +506,6 @@ void interp_to_mfab::interp_velocity_to_field(
amrex::Gpu::DeviceVector<amrex::Real> hvec_dvc(hvec.size());
amrex::Gpu::copy(
amrex::Gpu::hostToDevice, hvec.begin(), hvec.end(), hvec_dvc.begin());
// Get pointers to device vectors
const auto* indvec_ptr = indvec_dvc.data();
const auto* hvec_ptr = hvec_dvc.data();
const auto* uvec_ptr = uvec.data();
const auto* vvec_ptr = vvec.data();
const auto* wvec_ptr = wvec.data();

// Loop through cells and perform interpolation
for (int nl = 0; nl < nlevels; ++nl) {
Expand Down