Skip to content
366 changes: 281 additions & 85 deletions CMakeLists.txt

Large diffs are not rendered by default.

83 changes: 12 additions & 71 deletions cmake/AMSConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,78 +1,19 @@
@PACKAGE_INIT@

# Expose configuration options with AMS_ prefix
set(AMS_WITH_MPI @WITH_MPI@)
set(AMS_WITH_CUDA @WITH_CUDA@)
set(AMS_WITH_CALIPER @WITH_CALIPER@)
set(AMS_WITH_HDF5 @WITH_HDF5@)
set(AMS_WITH_RMQ @WITH_RMQ@)
include(CMakeFindDependencyMacro)

find_dependency(fmt)
find_dependency(tl-expected)

if (NOT TARGET Torch)
set(AMS_TORCH_DIR @Torch_DIR@)
if (NOT Torch_DIR)
set(Torch_DIR ${AMS_TORCH_DIR})
endif()
find_dependency(Torch REQUIRED HINTS ${Torch_DIR})
endif()

#Add usage hints for downstream projects
if(AMS_WITH_MPI)
if (NOT TARGET MPI)
find_dependency(MPI REQUIRED)
endif()
endif()

if(AMS_WITH_CUDA)
if (NOT TARGET CUDA::cudart)
find_dependency(CUDAToolkit REQUIRED)
endif()
endif()

set(AMS_HDF5_DIR @AMS_HDF5_DIR@)
set(AMS_HDF5_LIB_TYPE @AMS_HDF5_LIB_TYPE@)
if (NOT TARGET hdf5-shared OR NOT TARGET hdf5-static)
if (NOT HDF5_DIR)
set(HDF5_DIR ${AMS_HDF5_DIR})
endif()

if (${AMS_HDF5_LIB_TYPE} STREQUAL "static")
find_dependency(HDF5 COMPONENTS C static HINTS @AMS_HDF5_DIR@ @AMS_HDF5_DIR@/share/cmake)
else()
find_dependency(HDF5 COMPONENTS C shared HINTS @AMS_HDF5_DIR@ @AMS_HDF5_DIR@/share/cmake)
endif()
endif()

if (AMS_WITH_CALIPER)
if (NOT TARGET caliper)
set(CALIPER_AMS_DIR @caliper_DIR@)
# check if we specify another caliper directory
if (NOT caliper_DIR)
set(caliper_DIR ${CALIPER_AMS_DIR})
endif()
find_dependency(caliper HINTS ${caliper_DIR})
endif()
endif()

if (AMS_WITH_RMQ)
set(AMS_RMQ_DIR @amqpcpp_DIR@)
if (NOT amqpcpp_DIR)
set(amqpcpp_DIR ${AMS_RMQ_DIR})
endif()
set(AMS_OPENSSL_FOUND_ROOT @AMS_OPENSSL_FOUND_ROOT@)
if (NOT OPENSSL_ROOT_DIR)
set(OPENSSL_ROOT_DIR ${AMS_OPENSSL_FOUND_ROOT})
endif()
find_dependency(amqpcpp REQUIRED HINTS ${amqpcpp_DIR})
# find dependency does not correctly discover OpenSSL, not sure why.
find_dependency(OpenSSL)
if (NOT OPENSSL_FOUND)
find_dependency(OpenSSL HINTS ${AMS_OPENSSL_FOUND_ROOT})
endif()
endif()
set(AMS_ENABLE_MPI @ENABLE_MPI@)
set(AMS_ENABLE_CUDA @ENABLE_CUDA@)
set(AMS_ENABLE_HIP @ENABLE_HIP@)
set(AMS_ENABLE_CALIPER @ENABLE_CALIPER@)
set(AMS_ENABLE_WORKFLOW @ENABLE_WORKFLOW@)
set(AMS_ENABLE_RMQ @ENABLE_RMQ@)
set(AMS_ENABLE_PERFFLOWASPECT @ENABLE_PERFFLOWASPECT@)
set(AMS_BUILD_SHARED_LIBS @BUILD_SHARED_LIBS@)
set(AMS_DEFER_STATIC_TPL_RESOLUTION @AMS_DEFER_STATIC_TPL_RESOLUTION@)
set(AMS_HDF5_MODE "@AMS_HDF5_MODE@")

@AMS_PACKAGE_DEPENDENCY_BLOCK@

include("${CMAKE_CURRENT_LIST_DIR}/AMSTargets.cmake")
check_required_components("@PROJECT_NAME@")
55 changes: 30 additions & 25 deletions src/AMSlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ set(AMS_LIB_SRC wf/debug.cpp wf/logger.cpp wf/utils.cpp wf/SmallVector.cpp ml/su

list(APPEND AMS_LIB_SRC wf/hdf5db.cpp)

if (WITH_RMQ)
if (ENABLE_RMQ)
list(APPEND AMS_LIB_SRC wf/rmqdb.cpp)
endif()

add_library(AMS ${AMS_LIB_SRC})

get_target_property(AMS_TYPE AMS TYPE)
blt_add_library(NAME AMS SOURCES ${AMS_LIB_SRC})
add_library(AMS::AMS ALIAS AMS)

# ------------------------------------------------------------------------------
# setup the lib first
Expand All @@ -28,34 +27,35 @@ target_include_directories(AMS PUBLIC
$<INSTALL_INTERFACE:include>
)

target_link_libraries(AMS PUBLIC fmt::fmt tl::expected)
target_link_libraries(AMS PRIVATE fmt::fmt nlohmann_json::nlohmann_json ${AMS_APP_LIBRARIES}
$<BUILD_INTERFACE:tl::expected>)

if (BUILD_SHARED_LIBS AND AMS_DEFER_STATIC_TPL_RESOLUTION AND UNIX AND NOT APPLE)
target_link_options(AMS PRIVATE "-Wl,--unresolved-symbols=ignore-all")
endif()

if (WITH_CUDA)
if (ENABLE_CUDA)
target_link_libraries(AMS PRIVATE CUDA::cudart)
elseif (WITH_HIP)
elseif (ENABLE_HIP)
target_link_libraries(AMS PRIVATE hip::host)
endif()

target_link_libraries(AMS PUBLIC $<BUILD_INTERFACE:${AMS_HDF5_TARGET}> PRIVATE $<INSTALL_INTERFACE:${AMS_HDF5_TARGET}>)
remove_static_from_libs(TO LINK_AMS_HDF5_TARGETS FROM ${AMS_HDF5_LINK_TARGETS})
target_link_libraries(AMS PRIVATE ${LINK_AMS_HDF5_TARGETS})

if (WITH_CALIPER)
target_link_libraries(AMS PUBLIC $<BUILD_INTERFACE:caliper> PRIVATE $<INSTALL_INTERFACE:caliper>)
if (ENABLE_CALIPER)
target_link_libraries(AMS PRIVATE caliper)
endif()

if (WITH_MPI)
target_link_libraries(AMS PUBLIC $<BUILD_INTERFACE:MPI::MPI_CXX> PRIVATE $<INSTALL_INTERFACE:MPI::MPI_CXX>)
if (ENABLE_MPI)
target_link_libraries(AMS PRIVATE MPI::MPI_CXX)
endif()

if (WITH_RMQ)
target_link_libraries(AMS PUBLIC $<BUILD_INTERFACE:amqpcpp> PRIVATE $<INSTALL_INTERFACE:amqpcpp>)
if (ENABLE_RMQ)
target_link_libraries(AMS PRIVATE amqpcpp)

if (OPENSSL_FOUND)
target_link_libraries(AMS PUBLIC
$<BUILD_INTERFACE:OpenSSL::SSL>
$<BUILD_INTERFACE:OpenSSL::Crypto>
PRIVATE
$<INSTALL_INTERFACE:OpenSSL::SSL>
$<INSTALL_INTERFACE:OpenSSL::Crypto>)
target_link_libraries(AMS PRIVATE OpenSSL::SSL OpenSSL::Crypto)
endif()
# NOTE: We set here the event/event pthreads as public. As there is no easy way
# to do a find package(libevent) and RMQ is not exposing that properly.
Expand All @@ -64,9 +64,10 @@ if (WITH_RMQ)
target_link_libraries(AMS PUBLIC ${LIBEVENT_LIBRARY} ${LIBEVENT_THREAD})
endif()

target_link_libraries(AMS PUBLIC
$<BUILD_INTERFACE:stdc++fs torch> PRIVATE
$<INSTALL_INTERFACE:stdc++fs torch>)
target_link_libraries(AMS PRIVATE stdc++fs torch)
if (ENABLE_RMQ)
target_link_libraries(AMS PRIVATE Threads::Threads)
endif()


configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/include/AMS-config.h.in" "${PROJECT_BINARY_DIR}/include/AMS-config.h")
Expand Down Expand Up @@ -94,6 +95,11 @@ install(TARGETS AMS
)

# Export the AMS targets for use by external projects
export(EXPORT AMSTargets
NAMESPACE AMS::
FILE "${CMAKE_CURRENT_BINARY_DIR}/AMSTargets.cmake"
)

install(EXPORT AMSTargets
NAMESPACE AMS:: # Prefix target names with AMS::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/AMS" # Install location for CMake config
Expand All @@ -106,7 +112,7 @@ install(FILES
${PROJECT_BINARY_DIR}/include/AMSTypes.hpp
${PROJECT_BINARY_DIR}/include/ArrayRef.hpp
${PROJECT_BINARY_DIR}/include/SmallVector.hpp
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/" # Headers installed into AMS subdir
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/"
)


Expand All @@ -130,4 +136,3 @@ install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/AMSConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/AMS"
)

6 changes: 2 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
#
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

if (WITH_AMS_LIB)
add_subdirectory(AMSlib)
endif()
add_subdirectory(AMSlib)

if (WITH_WORKFLOW)
if (ENABLE_WORKFLOW)
add_subdirectory(AMSWorkflow)
endif()
1 change: 1 addition & 0 deletions tests/AMSlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ add_subdirectory(torch)
add_subdirectory(db)
add_subdirectory(wf)
add_subdirectory(ams_interface)
add_subdirectory(downstream)
#add_subdirectory(perf_regression)

9 changes: 4 additions & 5 deletions tests/AMSlib/ams_interface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ endfunction()


function(BUILD_UNIT_TEST exe source)
add_executable(${exe} ${source})
blt_add_executable(NAME ${exe} SOURCES ${source})
target_compile_features(${exe} PRIVATE cxx_std_17)
if (WITH_CUDA)
if (ENABLE_CUDA)
target_link_libraries(${exe} PRIVATE CUDA::cudart)
elseif(WITH_HIP)
elseif (ENABLE_HIP)
target_link_libraries(${exe} PRIVATE hip::host)
endif()

target_include_directories(${exe} PRIVATE ${CMAKE_SOURCE_DIR}/src/AMSlib/)
target_include_directories(${exe} PRIVATE ${CMAKE_BINARY_DIR}/include/)
target_include_directories(${exe} PRIVATE ${AMS_TEST_ROOT})
target_link_libraries(${exe} PRIVATE stdc++fs AMS torch Catch2::Catch2WithMain)
target_link_libraries(${exe} PRIVATE ${AMS_HDF5_TARGET})
target_link_libraries(${exe} PRIVATE ${AMS_HDF5_LINK_TARGETS})
target_compile_definitions(${exe} PRIVATE ${AMS_APP_DEFINES} CATCH_CONFIG_PREFIX_ALL)
endfunction()

Expand All @@ -26,4 +26,3 @@ ADD_AMS_UNIT_TEST(AMS_EXPLICIT ams_explicit_end_to_end)

BUILD_UNIT_TEST(int_interface int_interface.cpp)
ADD_AMS_UNIT_TEST(AMS_INT_INTERFACE int_interface)

11 changes: 6 additions & 5 deletions tests/AMSlib/db/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function(BUILD_UNIT_TEST exe source)
add_executable(${exe} ${source})
blt_add_executable(NAME ${exe} SOURCES ${source})

target_include_directories(${exe} PRIVATE ${caliper_INCLUDE_DIR} ${MPI_INCLUDE_PATH})
target_include_directories(${exe} PRIVATE ${CMAKE_SOURCE_DIR}/src/AMSlib/)
Expand All @@ -8,14 +8,14 @@ function(BUILD_UNIT_TEST exe source)
target_include_directories(${exe} PRIVATE ${AMS_TEST_ROOT})
target_compile_features(${exe} PRIVATE cxx_std_17)

target_link_libraries(${exe} PRIVATE ${AMS_HDF5_TARGET})
target_link_libraries(${exe} PRIVATE ${AMS_HDF5_LINK_TARGETS})

if (WITH_CALIPER)
if (ENABLE_CALIPER)
message(STATUS "Building witth caliper ${exe}")
target_link_libraries(${exe} PRIVATE caliper)
endif()

if (WITH_RMQ)
if (ENABLE_RMQ)
target_link_libraries(${exe} PRIVATE amqpcpp)
if (OPENSSL_FOUND)
target_link_libraries(${exe} PRIVATE OpenSSL::SSL OpenSSL::Crypto)
Expand All @@ -25,7 +25,7 @@ function(BUILD_UNIT_TEST exe source)
target_link_libraries(${exe} PRIVATE ${LIBEVENT_LIBRARY} ${LIBEVENT_THREAD})
endif()

if (WITH_MPI)
if (ENABLE_MPI)
target_link_libraries(${exe} PRIVATE MPI::MPI_CXX)
endif()

Expand All @@ -38,4 +38,5 @@ function(ADD_DB_UNIT_TEST name exec)
endfunction()

BUILD_UNIT_TEST(db_hdf5 db_hdf5.cpp)
target_link_libraries(db_hdf5 PRIVATE fmt::fmt)
ADD_DB_UNIT_TEST(DB::HDF5 db_hdf5)
46 changes: 46 additions & 0 deletions tests/AMSlib/downstream/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright 2021-2023 Lawrence Livermore National Security, LLC and other
# AMSLib Project Developers
#
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

set(AMS_DOWNSTREAM_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/consumer_mock")
set(AMS_DOWNSTREAM_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/consumer_mock-build")
set(AMS_DOWNSTREAM_PACKAGE_DIR "${PROJECT_BINARY_DIR}/src/AMSlib")

set(AMS_DOWNSTREAM_CONFIGURE_ARGS
-DAMS_DIR:PATH=${AMS_DOWNSTREAM_PACKAGE_DIR}
-DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}
)

if (CMAKE_BUILD_TYPE)
list(APPEND AMS_DOWNSTREAM_CONFIGURE_ARGS
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE})
endif()

foreach (_hint fmt_DIR Torch_DIR HDF5_DIR hdf5_DIR ZLIB_DIR caliper_DIR
amqpcpp_DIR OpenSSL_ROOT_DIR CUDAToolkit_DIR HIP_DIR)
if (DEFINED ${_hint} AND NOT "${${_hint}}" STREQUAL "")
list(APPEND AMS_DOWNSTREAM_CONFIGURE_ARGS
-D${_hint}:PATH=${${_hint}})
endif()
endforeach()

add_test(NAME AMS_DOWNSTREAM_CONSUMER_CONFIGURE
COMMAND ${CMAKE_COMMAND}
-S ${AMS_DOWNSTREAM_SOURCE_DIR}
-B ${AMS_DOWNSTREAM_BINARY_DIR}
${AMS_DOWNSTREAM_CONFIGURE_ARGS})
set_tests_properties(AMS_DOWNSTREAM_CONSUMER_CONFIGURE
PROPERTIES
FIXTURES_SETUP AMSDownstream
LABELS DOWNSTREAM)

add_test(NAME AMS_DOWNSTREAM_CONSUMER_BUILD
COMMAND ${CMAKE_COMMAND}
--build ${AMS_DOWNSTREAM_BINARY_DIR}
--config $<CONFIG>)
set_tests_properties(AMS_DOWNSTREAM_CONSUMER_BUILD
PROPERTIES
FIXTURES_REQUIRED AMSDownstream
LABELS DOWNSTREAM)
14 changes: 14 additions & 0 deletions tests/AMSlib/downstream/consumer_mock/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2021-2023 Lawrence Livermore National Security, LLC and other
# AMSLib Project Developers
#
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

cmake_minimum_required(VERSION 3.21)

project(AMSConsumer LANGUAGES CXX)

find_package(AMS REQUIRED)

add_executable(ams_consumer main.cpp)
target_compile_features(ams_consumer PRIVATE cxx_std_17)
target_link_libraries(ams_consumer PRIVATE AMS::AMS)
15 changes: 15 additions & 0 deletions tests/AMSlib/downstream/consumer_mock/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright 2021-2023 Lawrence Livermore National Security, LLC and other
* AMSLib Project Developers
*
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

#include "AMS.h"

int main()
{
ams::AMSExecutor exec = 0;
(void)exec;
return 0;
}
2 changes: 1 addition & 1 deletion tests/AMSlib/models/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ set(GENERATED_CPU_MODELS
${CMAKE_CURRENT_BINARY_DIR}/linear_scripted_single_cpu_random.pt
)

if (WITH_CUDA OR WITH_HIP)
if (ENABLE_CUDA OR ENABLE_HIP)
set(GENERATED_GPU_MODELS
${CMAKE_CURRENT_BINARY_DIR}/double_gpu_duq_max.pt
${CMAKE_CURRENT_BINARY_DIR}/double_gpu_duq_mean.pt
Expand Down
Loading
Loading