From 6567900c4e40296f7ca37d271a6b19540e770a78 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Thu, 22 Jun 2023 15:04:28 -0600 Subject: [PATCH 1/9] add the word Concept a bunch of places --- spiner/databox.hpp | 68 +++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/spiner/databox.hpp b/spiner/databox.hpp index 20e565a96..e2686402c 100644 --- a/spiner/databox.hpp +++ b/spiner/databox.hpp @@ -46,7 +46,7 @@ enum class DataStatus { Empty, Unmanaged, AllocatedHost, AllocatedDevice }; enum class AllocationTarget { Host, Device }; template ::value, bool>::type> class DataBox { public: @@ -94,7 +94,7 @@ class DataBox { dataView_(A) { setAllIndexed_(); } - PORTABLE_INLINE_FUNCTION DataBox(const DataBox &src) noexcept + PORTABLE_INLINE_FUNCTION DataBox(const DataBox &src) noexcept : rank_(src.rank_), status_(src.status_), data_(src.data_) { setAllIndexed_(); dataView_.InitWithShallowSlice(src.dataView_, 6, 0, src.dim(6)); @@ -106,7 +106,7 @@ class DataBox { // Slice constructor PORTABLE_INLINE_FUNCTION - DataBox(const DataBox &b, const int dim, const int indx, + DataBox(const DataBox &b, const int dim, const int indx, const int nvar) noexcept : status_(DataStatus::Unmanaged), data_(b.data_) { dataView_.InitWithShallowSlice(b.dataView_, dim, indx, nvar); @@ -157,14 +157,15 @@ class DataBox { // Slice operation PORTABLE_INLINE_FUNCTION - DataBox slice(const int dim, const int indx, const int nvar) const { + DataBox slice(const int dim, const int indx, + const int nvar) const { return DataBox(*this, dim, indx, nvar); } - PORTABLE_INLINE_FUNCTION DataBox slice(const int indx) const { + PORTABLE_INLINE_FUNCTION DataBox slice(const int indx) const { return slice(rank_, indx, 1); } - PORTABLE_INLINE_FUNCTION DataBox slice(const int ix2, - const int ix1) const { + PORTABLE_INLINE_FUNCTION DataBox slice(const int ix2, + const int ix1) const { // DataBox a(*this, rank_, ix2, 1); // return DataBox(a, a.rank_, ix1, 1); return slice(ix2).slice(ix1); @@ -203,12 +204,13 @@ class DataBox { // DataBox, interpolated at that slowest index. // WARNING: requires memory to be pre-allocated. // TODO: add 3d and higher interpFromDB if necessary - PORTABLE_INLINE_FUNCTION void interpFromDB(const DataBox &db, const T x); - PORTABLE_INLINE_FUNCTION void interpFromDB(const DataBox &db, const T x2, - const T x1); + PORTABLE_INLINE_FUNCTION void interpFromDB(const DataBox &db, + const T x); + PORTABLE_INLINE_FUNCTION void interpFromDB(const DataBox &db, + const T x2, const T x1); template - PORTABLE_INLINE_FUNCTION DataBox interpToDB(Args... args) { - DataBox db; + PORTABLE_INLINE_FUNCTION DataBox interpToDB(Args... args) { + DataBox db; db.interpFromDB(*this, std::forward(args)...); return db; } @@ -233,10 +235,10 @@ class DataBox { // Does no checks that memory is available. // Optionally copies shape of source with ndims fewer slowest-moving // dimensions - PORTABLE_INLINE_FUNCTION void copyShape(const DataBox &db, + PORTABLE_INLINE_FUNCTION void copyShape(const DataBox &db, const int ndims = 0); // Returns new databox with same memory and metadata - inline void copyMetadata(const DataBox &src); + inline void copyMetadata(const DataBox &src); #ifdef SPINER_USE_HDF inline herr_t saveHDF() const { return saveHDF(SP5::DB::FILENAME); } @@ -252,8 +254,9 @@ class DataBox { inline RegularGrid1D &range(const int i) { return grids_[i]; } // Assignment and move, both perform shallow copy - PORTABLE_INLINE_FUNCTION DataBox &operator=(const DataBox &other); - inline void copy(const DataBox &src); + PORTABLE_INLINE_FUNCTION DataBox & + operator=(const DataBox &other); + inline void copy(const DataBox &src); // utility info inline DataStatus dataStatus() const { return status_; } @@ -261,8 +264,8 @@ class DataBox { inline bool ownsAllocatedMemory() { return (status_ != DataStatus::Unmanaged); } - inline bool operator==(const DataBox &other) const; - inline bool operator!=(const DataBox &other) const { + inline bool operator==(const DataBox &other) const; + inline bool operator!=(const DataBox &other) const { return !(*this == other); } @@ -294,13 +297,14 @@ class DataBox { return indices_[i]; } - DataBox getOnDevice() const { // getOnDevice is always a deep copy + DataBox getOnDevice() const { // getOnDevice is always a deep copy // create device memory (host memory if no device) T *device_data = (T *)PORTABLE_MALLOC(sizeBytes()); // copy to device portableCopyToDevice(device_data, data_, sizeBytes()); // create new databox of size size - DataBox a{device_data, dim(6), dim(5), dim(4), dim(3), dim(2), dim(1)}; + DataBox a{device_data, dim(6), dim(5), dim(4), + dim(3), dim(2), dim(1)}; a.copyShape(*this); // set correct allocation status of the new databox if (PortsOfCall::EXECUTION_IS_HOST) { @@ -559,7 +563,7 @@ DataBox::interpToReal(const T x4, const T x3, const T x2, template PORTABLE_INLINE_FUNCTION void -DataBox::interpFromDB(const DataBox &db, const T x) { +DataBox::interpFromDB(const DataBox &db, const T x) { assert(db.indices_[db.rank_ - 1] == IndexType::Interpolated); assert(db.grids_[db.rank_ - 1].isWellFormed()); assert(size() == (db.size() / db.dim(db.rank_))); @@ -569,7 +573,7 @@ DataBox::interpFromDB(const DataBox &db, const T x) { copyShape(db, 1); db.grids_[db.rank_ - 1].weights(x, ix, w); - DataBox lower(db.slice(ix)), upper(db.slice(ix + 1)); + DataBox lower(db.slice(ix)), upper(db.slice(ix + 1)); // lower = db.slice(ix); // upper = db.slice(ix+1); for (int i = 0; i < size(); i++) { @@ -579,7 +583,7 @@ DataBox::interpFromDB(const DataBox &db, const T x) { template PORTABLE_INLINE_FUNCTION void -DataBox::interpFromDB(const DataBox &db, const T x2, +DataBox::interpFromDB(const DataBox &db, const T x2, const T x1) { assert(db.rank_ >= 2); assert(db.indices_[db.rank_ - 1] == IndexType::Interpolated); @@ -594,7 +598,7 @@ DataBox::interpFromDB(const DataBox &db, const T x2, db.grids_[db.rank_ - 2].weights(x1, ix1, w1); db.grids_[db.rank_ - 1].weights(x2, ix2, w2); - DataBox corners[2][2]{ + DataBox corners[2][2]{ {db.slice(ix2, ix1), db.slice(ix2 + 1, ix1)}, {db.slice(ix2, ix1 + 1), db.slice(ix2 + 1, ix1 + 1)}}; // copyShape(db,2); @@ -625,7 +629,7 @@ DataBox::interpFromDB(const DataBox &db, const T x2, // Optionally copies shape of source with ndims fewer slowest-moving dimensions template PORTABLE_INLINE_FUNCTION void -DataBox::copyShape(const DataBox &db, const int ndims) { +DataBox::copyShape(const DataBox &db, const int ndims) { rank_ = db.rank_ - ndims; int dims[MAXRANK]; for (int i = 0; i < MAXRANK; i++) @@ -643,7 +647,7 @@ DataBox::copyShape(const DataBox &db, const int ndims) { // reallocates and then copies shape from other databox // everything but the actual copy in a deep copy template -inline void DataBox::copyMetadata(const DataBox &src) { +inline void DataBox::copyMetadata(const DataBox &src) { AllocationTarget t = (src.status_ == DataStatus::AllocatedDevice ? AllocationTarget::Device : AllocationTarget::Host); @@ -795,8 +799,8 @@ inline herr_t DataBox::loadHDF(hid_t loc, // Performs shallow copy by default template -PORTABLE_INLINE_FUNCTION DataBox & -DataBox::operator=(const DataBox &src) { +PORTABLE_INLINE_FUNCTION DataBox & +DataBox::operator=(const DataBox &src) { if (this != &src) { rank_ = src.rank_; status_ = src.status_; @@ -812,14 +816,15 @@ DataBox::operator=(const DataBox &src) { // Performs a deep copy template -inline void DataBox::copy(const DataBox &src) { +inline void DataBox::copy(const DataBox &src) { copyMetadata(src); for (int i = 0; i < src.size(); i++) dataView_(i) = src(i); } template -inline bool DataBox::operator==(const DataBox &other) const { +inline bool +DataBox::operator==(const DataBox &other) const { if (rank_ != other.rank_) return false; for (int i = 0; i < rank_; i++) { if (indices_[i] != other.indices_[i]) return false; @@ -888,7 +893,8 @@ DataBox::canInterpToReal_(const int interpOrder) const { } template -inline DataBox getOnDeviceDataBox(const DataBox &a_host) { +inline DataBox +getOnDeviceDataBox(const DataBox &a_host) { return a_host.getOnDevice(); } template From ce715a7b448f9f0ee52a111402be37c120488561 Mon Sep 17 00:00:00 2001 From: Christopher Mauney Date: Fri, 23 Jun 2023 10:46:45 -0600 Subject: [PATCH 2/9] don't find/fetch if target is present --- cmake/content.cmake | 298 ++++++++++++++++++++++---------------------- 1 file changed, 148 insertions(+), 150 deletions(-) diff --git a/cmake/content.cmake b/cmake/content.cmake index ceba74491..730d97e82 100644 --- a/cmake/content.cmake +++ b/cmake/content.cmake @@ -1,96 +1,95 @@ include(FetchContent) -############################################################### -# +# ############################################################################## +# # For dependency management, use the `FetchContent` pattern # # NOTE: We seek to replicate the implementation of `FetchContent` -############################################################### - -# Constructs `FetchContent_Declare` call, and records information -# for population and linking -# -# ::Overview -# With `cmake@3.24` and higher, the functionality of `FetchContent_` has -# been updated to provide the capability to try a `find_package` at the -# content population stage. This allows for the flexibility provided by -# `FetchContent_` to easily coexist with the dependency configuration -# provided by `find_package`. Some benefits include: -# - automated fetching of content if it is unavailable -# - content population at configure. This allows for a package import -# to utilize `find_package()` or `add_subdirectory()` operations -# - local clones can be given priority with `FETCHCONTENT_SOURCE_DIR_`, -# which lets developers use dependencies explicitly in-tree -# The case where i.) the content or dependency is unavailable or ii.) it cannot -# be fetched (due, for example, to a failure of a download step) is an -# unavoidable error. +# ############################################################################## + +# Constructs `FetchContent_Declare` call, and records information for population +# and linking # -# As this cmake version is relatively fresh, we also want to provide a bridge -# to downstream code that still is pinned to an earlier releases of `cmake`. -# To that end, these macros provide for replicating the main features introduced -# to `FetchContent_` in `cmake@3.24`. Future releases of `spiner` will require -# a minimum of `cmake@3.24`. +# ::Overview With `cmake@3.24` and higher, the functionality of `FetchContent_` +# has been updated to provide the capability to try a `find_package` at the +# content population stage. This allows for the flexibility provided by +# `FetchContent_` to easily coexist with the dependency configuration provided +# by `find_package`. Some benefits include: - automated fetching of content if +# it is unavailable - content population at configure. This allows for a package +# import to utilize `find_package()` or `add_subdirectory()` operations - local +# clones can be given priority with `FETCHCONTENT_SOURCE_DIR_`, +# which lets developers use dependencies explicitly in-tree The case where i.) +# the content or dependency is unavailable or ii.) it cannot be fetched (due, +# for example, to a failure of a download step) is an unavoidable error. # -# :: Arguments -# pkg_name - the name of the package or content. usually the argument to `find_package()` -# options: -# - NO_FETCH - disables all download steps. If `find_package()` fails, produce an error -# single_value: -# - GIT_REPO - the URL of the git repository to clone, if necessary -# - GIT_TAG - the tag or commit to use -# - NAMESPACE - prefix book-keeping variables with this -# multi_value: -# - COMPONENTS - specify required components of . same as used in to `find_package` -# - EXPECTED_TARGETS - a list of targets that expected at population. -# if these targets are not available after the population stage, an error is produced. -# if not specified, will default to `::` -# - ENABLE_OPTS - a list of cache vars used to configure content that is imported using `add_subdirectory()` +# As this cmake version is relatively fresh, we also want to provide a bridge to +# downstream code that still is pinned to an earlier releases of `cmake`. To +# that end, these macros provide for replicating the main features introduced to +# `FetchContent_` in `cmake@3.24`. Future releases of `spiner` will require a +# minimum of `cmake@3.24`. +# +# :: Arguments pkg_name - the name of the package or content. usually the +# argument to `find_package()` options: - NO_FETCH - disables all +# download steps. If `find_package()` fails, produce an error +# single_value: - GIT_REPO - the URL of the git repository to clone, if +# necessary - GIT_TAG - the tag or commit to use - NAMESPACE - prefix +# book-keeping variables with this multi_value: - COMPONENTS - specify required +# components of . same as used in to `find_package` - EXPECTED_TARGETS +# - a list of targets that expected at population. if these targets are not +# available after the population stage, an error is produced. if not specified, +# will default to `::` - ENABLE_OPTS - a list of cache vars +# used to configure content that is imported using `add_subdirectory()` # macro(spiner_content_declare pkg_name) - set(options - NO_FETCH - ) - set(one_value_args - GIT_REPO - GIT_TAG - NAMESPACE - ) - set(multi_value_args - COMPONENTS - EXPECTED_TARGETS - ENABLE_OPTS - ) - - cmake_parse_arguments(fp "${options}" "${one_value_args}" "${multi_value_args}" "${ARGN}") + set(options NO_FETCH) + set(one_value_args GIT_REPO GIT_TAG NAMESPACE) + set(multi_value_args COMPONENTS EXPECTED_TARGETS ENABLE_OPTS) + + cmake_parse_arguments(fp "${options}" "${one_value_args}" + "${multi_value_args}" "${ARGN}") string(TOUPPER ${pkg_name} pkg_CAP) string(REPLACE "-" "_" pkg_CAP "${pkg_CAP}") - message(STATUS - "[${pkg_name}] FetchContent_Declare wrapper" - ) - # because the signature is different between versions, - # we build the cmake call beforehand + # loop through targets, if already present then bail + foreach(expected_target ${fp_EXPECTED_TARGETS};${pkg_name}) + if(TARGET ${expected_target}) + message( + STATUS + "target \"${expected_target}\" already exists, tagging ${pkg_name} as already present" + ) + set(${fp_NAMESPACE}_DECLARED_EXTERNAL_${pkg_CAP}_ALREADY_PRESENT TRUE) + break() + endif() + endforeach() + + message(STATUS "[${pkg_name}] FetchContent_Declare wrapper") + # because the signature is different between versions, we build the cmake call + # beforehand set(_fetch_content_cmd "FetchContent_Declare(${pkg_name}") - + if(fp_NO_FETCH) - message(VERBOSE + message( + VERBOSE " :: \"${pkg_name}\" is specified not fetchable, will rely on `find_package` for population" ) - string(APPEND _fetch_content_cmd " DOWNLOAD_COMMAND \":\"") + string(APPEND _fetch_content_cmd " DOWNLOAD_COMMAND \":\"") set(${fp_NAMESPACE}_DECLARED_EXTERNAL_${pkg_CAP}_NOFETCH TRUE) else() - message(VERBOSE + message( + VERBOSE " :: \"${pkg_name}\" is fetchable, will fall-back to git clone [${fp_GIT_REPO}] if other population methods fail" ) - string(APPEND _fetch_content_cmd " GIT_REPOSITORY ${fp_GIT_REPO} GIT_TAG ${fp_GIT_TAG}") + string(APPEND _fetch_content_cmd + " GIT_REPOSITORY ${fp_GIT_REPO} GIT_TAG ${fp_GIT_TAG}") endif() # bifurcation on cmake version - if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0") + if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0") # versions >= 3.24 will do an implicit `find_package`, so pass on # requirements to declaration - string(APPEND _fetch_content_cmd " FIND_PACKAGE_ARGS COMPONENTS ${fp_COMPONENTS}") + string(APPEND _fetch_content_cmd + " FIND_PACKAGE_ARGS COMPONENTS ${fp_COMPONENTS}") endif() # close the command @@ -101,7 +100,7 @@ macro(spiner_content_declare pkg_name) cmake_language(EVAL CODE "${_fetch_content_cmd}") # be safe and destroy the string unset(_fetch_content_cmd) - + # return some info list(APPEND ${fp_NAMESPACE}_DECLARED_EXTERNAL_CONTENT ${pkg_name}) @@ -110,102 +109,103 @@ macro(spiner_content_declare pkg_name) set(${fp_NAMESPACE}_DECLARED_EXTERNAL_${pkg_CAP}_PRIORS ${fp_PRIORS}) if(fp_EXPECTED_TARGETS) - set(${fp_NAMESPACE}_DECLARED_EXTERNAL_${pkg_CAP}_TARGETS ${fp_EXPECTED_TARGETS}) + set(${fp_NAMESPACE}_DECLARED_EXTERNAL_${pkg_CAP}_TARGETS + ${fp_EXPECTED_TARGETS}) else() - set(${fp_NAMESPACE}_DECLARED_EXTERNAL_${pkg_CAP}_TARGETS "${pkg_name}::${pkg_name}") + set(${fp_NAMESPACE}_DECLARED_EXTERNAL_${pkg_CAP}_TARGETS + "${pkg_name}::${pkg_name}") endif() - endmacro() # -# :: Overview -# This macro wraps a call to `FetchContent_MakeAvailable`. -# If we are using a `cmake` prior to 3.24, explicitly do a -# `find_package()` with the declared options -# :: Arguments -# single_value: -# - NAMESPACE - the namespace used in the corrisponding `spiner_content_declare` call +# :: Overview This macro wraps a call to `FetchContent_MakeAvailable`. If we are +# using a `cmake` prior to 3.24, explicitly do a `find_package()` with the +# declared options :: Arguments single_value: - NAMESPACE - the namespace used +# in the corrisponding `spiner_content_declare` call # macro(spiner_content_populate) set(options) - set(one_value_args - NAMESPACE - ) - set(multi_value_args - ) - - cmake_parse_arguments(fp "${options}" "${one_value_args}" "${multi_value_args}" "${ARGN}") - - message(STATUS - "[${fp_NAMESPACE}] Populating declared content" - ) - # fill lists to populate - # if cmake@3.24+, these are just the lists prepared in spiner_content_declare - # otherwise, manually check `find_package` and remove content if found + set(one_value_args NAMESPACE) + set(multi_value_args) + + cmake_parse_arguments(fp "${options}" "${one_value_args}" + "${multi_value_args}" "${ARGN}") + + message(STATUS "[${fp_NAMESPACE}] Populating declared content") + # fill lists to populate if cmake@3.24+, these are just the lists prepared in + # spiner_content_declare otherwise, manually check `find_package` and remove + # content if found foreach(pkg_name ${${fp_NAMESPACE}_DECLARED_EXTERNAL_CONTENT}) string(TOUPPER ${pkg_name} pkg_CAP) string(REPLACE "-" "_" pkg_CAP "${pkg_CAP}") - # bifurcation on cmake version - if (NOT CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0") - find_package(${pkg_name} - COMPONENTS ${${fp_NAMESPACE}_DECLARED_EXTERNAL_${pkg_CAP}_COMPONETS} - QUIET - ) - if(${pkg_name}_FOUND) - message(VERBOSE - "${pkg_name} located with `find_package`" - "${pkg_name}_DIR: ${${pkg_name}_DIR}" - ) + + if(NOT ${fp_NAMESPACE}_DECLARED_EXTERNAL_${pkg_CAP}_ALREADY_PRESENT) + # bifurcation on cmake version + if(NOT CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0") + find_package( + ${pkg_name} + COMPONENTS ${${fp_NAMESPACE}_DECLARED_EXTERNAL_${pkg_CAP}_COMPONETS} + QUIET) + if(${pkg_name}_FOUND) + message(VERBOSE "${pkg_name} located with `find_package`" + "${pkg_name}_DIR: ${${pkg_name}_DIR}") + else() + # if no fetching and not found, produce an error conditionally include + # a custom error msg + if(${fp_NAMESPACE}_DECLARED_EXTERNAL_${pkg_CAP}_NOFETCH) + message( + FATAL_ERROR + "${pkg_name} is requested, but it was not located and is not declared as fetchable.\n" + "if ${pkg_name} is installed, set \"-D${pkg_name}_ROOT=\"" + ) + endif() # NOFETCH + message( + VERBOSE + "${pkg_name} NOT located with `find_package`, appending to populate list." + " Will attempt to clone repository when content is populated.") + list(APPEND _fetchList ${pkg_name}) + list(APPEND _fetchOpts + ${${fp_NAMESPACE}_DECLARED_EXTERNAL_${pkg_CAP}_ENABLEOPTS}) + list(APPEND _fetchTars + ${${fp_NAMESPACE}_DECLARED_EXTERNAL_${pkg_CAP}_TARGETS}) + + endif() # FOUND else() - # if no fetching and not found, produce an error - # conditionally include a custom error msg - if(${fp_NAMESPACE}_DECLARED_EXTERNAL_${pkg_CAP}_NOFETCH) - message(FATAL_ERROR - "${pkg_name} is requested, but it was not located and is not declared as fetchable.\n" - "if ${pkg_name} is installed, set \"-D${pkg_name}_ROOT=\"" - ) - endif() # NOFETCH - message(VERBOSE - "${pkg_name} NOT located with `find_package`, appending to populate list." - " Will attempt to clone repository when content is populated." - ) list(APPEND _fetchList ${pkg_name}) - list(APPEND _fetchOpts ${${fp_NAMESPACE}_DECLARED_EXTERNAL_${pkg_CAP}_ENABLEOPTS}) - list(APPEND _fetchTars ${${fp_NAMESPACE}_DECLARED_EXTERNAL_${pkg_CAP}_TARGETS}) - - endif() # FOUND - else() - list(APPEND _fetchList ${pkg_name}) - list(APPEND _fetchOpts ${${fp_NAMESPACE}_DECLARED_EXTERNAL_${pkg_CAP}_ENABLEOPTS}) - list(APPEND _fetchTars ${${fp_NAMESPACE}_DECLARED_EXTERNAL_${pkg_CAP}_TARGETS}) - endif() #CMAKE_VERSION - # collect all targets, reguardless of populated - list(APPEND _expectedTars ${${fp_NAMESPACE}_DECLARED_EXTERNAL_${pkg_CAP}_TARGETS}) + list(APPEND _fetchOpts + ${${fp_NAMESPACE}_DECLARED_EXTERNAL_${pkg_CAP}_ENABLEOPTS}) + list(APPEND _fetchTars + ${${fp_NAMESPACE}_DECLARED_EXTERNAL_${pkg_CAP}_TARGETS}) + endif() # CMAKE_VERSION + # collect all targets, reguardless of populated + endif() # _ALREADY_PRESENT + list(APPEND _expectedTars + ${${fp_NAMESPACE}_DECLARED_EXTERNAL_${pkg_CAP}_TARGETS}) endforeach() - # for content to be populated, set some cache options given in spiner_content_declare + # for content to be populated, set some cache options given in + # spiner_content_declare foreach(ext_opt ${_fetchOpts}) message(DEBUG "setting \"${ext_opt}\"=ON") - set(${ext_opt} ON CACHE INTERNAL "") + set(${ext_opt} + ON + CACHE INTERNAL "") endforeach() - message(VERBOSE "\n" - " :: Populating dependency targets ${_fetchTars}\n" - " :: Calling `FetchContent_MakeAvailable` with ${_fetchList}\n" - ) - message(STATUS - "FetchContent_MakeAvailable prepared, " - "this may take a few moments if a download is required...\n" - ) - # populate + message(VERBOSE "\n" " :: Populating dependency targets ${_fetchTars}\n" + " :: Calling `FetchContent_MakeAvailable` with ${_fetchList}\n") + message(STATUS "FetchContent_MakeAvailable prepared, " + "this may take a few moments if a download is required...\n") + # populate FetchContent_MakeAvailable(${_fetchList}) # check that declared targets exist foreach(expected_target ${_expectedTars}) if(NOT TARGET ${expected_target}) - message(FATAL_ERROR + message( + FATAL_ERROR "target \"${expected_target}\" was expected, but does not exist after population!" - ) # NOT TARGET + ) # NOT TARGET endif() endforeach() @@ -220,15 +220,13 @@ macro(spiner_content_populate) unset(${fp_NAMESPACE}_DECLARED_EXTERNAL_CONTENT) endmacro() - -# © 2021. Triad National Security, LLC. All rights reserved. This -# program was produced under U.S. Government contract 89233218CNA000001 -# for Los Alamos National Laboratory (LANL), which is operated by Triad -# National Security, LLC for the U.S. Department of Energy/National -# Nuclear Security Administration. All rights in the program are -# reserved by Triad National Security, LLC, and the U.S. Department of -# Energy/National Nuclear Security Administration. The Government is -# granted for itself and others acting on its behalf a nonexclusive, -# paid-up, irrevocable worldwide license in this material to reproduce, -# prepare derivative works, distribute copies to the public, perform +# © 2021. Triad National Security, LLC. All rights reserved. This program was +# produced under U.S. Government contract 89233218CNA000001 for Los Alamos +# National Laboratory (LANL), which is operated by Triad National Security, LLC +# for the U.S. Department of Energy/National Nuclear Security Administration. +# All rights in the program are reserved by Triad National Security, LLC, and +# the U.S. Department of Energy/National Nuclear Security Administration. The +# Government is granted for itself and others acting on its behalf a +# nonexclusive, paid-up, irrevocable worldwide license in this material to +# reproduce, prepare derivative works, distribute copies to the public, perform # publicly and display publicly, and to permit others to do so. From 53a305b712054366f23dabadc0f5cb3fb1f1a50f Mon Sep 17 00:00:00 2001 From: Christopher Mauney Date: Tue, 27 Jun 2023 10:29:56 -0600 Subject: [PATCH 3/9] added exported cmake vars and changed testing var --- CMakeLists.txt | 231 ++++++++++++++++++++---------------- cmake/spinerConfig.cmake.in | 21 ++-- 2 files changed, 137 insertions(+), 115 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fc8c1c3f6..8ba842d81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,16 +1,15 @@ -#------------------------------------------------------------------------------# -# © 2021. Triad National Security, LLC. All rights reserved. This -# program was produced under U.S. Government contract 89233218CNA000001 -# for Los Alamos National Laboratory (LANL), which is operated by Triad -# National Security, LLC for the U.S. Department of Energy/National -# Nuclear Security Administration. All rights in the program are -# reserved by Triad National Security, LLC, and the U.S. Department of -# Energy/National Nuclear Security Administration. The Government is -# granted for itself and others acting on its behalf a nonexclusive, -# paid-up, irrevocable worldwide license in this material to reproduce, -# prepare derivative works, distribute copies to the public, perform +# ------------------------------------------------------------------------------# +# © 2021. Triad National Security, LLC. All rights reserved. This program was +# produced under U.S. Government contract 89233218CNA000001 for Los Alamos +# National Laboratory (LANL), which is operated by Triad National Security, LLC +# for the U.S. Department of Energy/National Nuclear Security Administration. +# All rights in the program are reserved by Triad National Security, LLC, and +# the U.S. Department of Energy/National Nuclear Security Administration. The +# Government is granted for itself and others acting on its behalf a +# nonexclusive, paid-up, irrevocable worldwide license in this material to +# reproduce, prepare derivative works, distribute copies to the public, perform # publicly and display publicly, and to permit others to do so. -#------------------------------------------------------------------------------# +# ------------------------------------------------------------------------------# cmake_minimum_required(VERSION 3.23) @@ -19,35 +18,46 @@ project(spiner VERSION ${SPINER_VERSION}) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -# bring in some helpful CMake scripts -# make cache variables for install destinations +# bring in some helpful CMake scripts make cache variables for install +# destinations include(GNUInstallDirs) # package config file include(CMakePackageConfigHelpers) +# dependent options +include(CMakeDependentOption) # Don't allow in-source builds if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) - message(FATAL_ERROR - "You cannot build in a source directory (or any directory with a CMakeLists.txt file). " - "Please make a build subdirectory. Feel free to remove CMakeCache.txt and CMakeFiles.") + message( + FATAL_ERROR + "You cannot build in a source directory (or any directory with a CMakeLists.txt file). " + "Please make a build subdirectory. Feel free to remove CMakeCache.txt and CMakeFiles." + ) endif() # If the user doesn't specify a build type, prefer RelWithDebInfo set(default_build_type "RelWithDebInfo") if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - message(STATUS "Setting build type to '${default_build_type}' as none was specified.") - set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE - STRING "Choose the type of build." FORCE) + message( + STATUS + "Setting build type to '${default_build_type}' as none was specified.") + set(CMAKE_BUILD_TYPE + "${default_build_type}" + CACHE STRING "Choose the type of build." FORCE) # Set the possible values of build type for cmake-gui - set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS - "Debug" "Release" "MinSizeRel" "RelWithDebInfo") + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" + "MinSizeRel" "RelWithDebInfo") endif() # use HDF5 -option (SPINER_USE_HDF "Use HDF5 for I/O" OFF) +option(SPINER_USE_HDF "Use HDF5 for I/O" OFF) +option(SPINER_BUILD_TESTS "Compile Tests" OFF) # use Kokkos offloading in tests -option (SPINER_TEST_USE_KOKKOS "Use kokkos offloading for tests" OFF) -option (SPINER_TEST_USE_KOKKOS_CUDA "Use kokkos cuda offloading for tests" OFF) +cmake_dependent_option(SPINER_TEST_USE_KOKKOS "Use kokkos offloading for tests" + ON "SPINER_BUILD_TESTS" OFF) +cmake_dependent_option( + SPINER_TEST_USE_KOKKOS_CUDA "Use kokkos cuda offloading for tests" ON + "SPINER_TEST_USE_KOKKOS" ON) # CTest include(CTest) @@ -59,134 +69,145 @@ include(cmake/Format.cmake) add_library(spiner INTERFACE) add_library(spiner::spiner ALIAS spiner) -##################################### -# Dependencies # -##################################### +# ############################################################################## +# Dependencies # +# ############################################################################## include(FetchContent) -# If we are on version 3.24+, then set FetchContent to always try -# to `find_package` before trying a download method -if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0") +# If we are on version 3.24+, then set FetchContent to always try to +# `find_package` before trying a download method +if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0") set(FETCHCONTENT_TRY_FIND_PACKAGE_MODE ALWAYS) message(STATUS "FetchContent routines will try `find_package` first") else() - message(DEPRECATION - "Detected cmake version (${CMAKE_VERSION}) older then 3.24. `spiner`" - "will begin requiring this version soon. The current depedency " - "resolution is a soft-copy of the pattern of FetchContent introduced" - "in cmake 3.24." - ) + message( + DEPRECATION + "Detected cmake version (${CMAKE_VERSION}) older then 3.24. `spiner`" + "will begin requiring this version soon. The current depedency " + "resolution is a soft-copy of the pattern of FetchContent introduced" + "in cmake 3.24.") endif() set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake) # content is a wrapper to `FetchContent` calls include(content) -spiner_content_declare(ports-of-call - NAMESPACE spinerDeps - GIT_REPO https://github.com/lanl/ports-of-call +spiner_content_declare( + ports-of-call + NAMESPACE + spinerDeps + GIT_REPO + https://github.com/lanl/ports-of-call # most recent relase as of April 05, 2023 - GIT_TAG v1.5.1 -) + GIT_TAG + v1.5.1) if(SPINER_USE_HDF) - spiner_content_declare(HDF5 + spiner_content_declare( + HDF5 NO_FETCH - NAMESPACE spinerDeps - COMPONENTS C HL - EXPECTED_TARGETS hdf5::hdf5 hdf5::hdf5_hl - ) - target_compile_definitions(spiner - INTERFACE - SPINER_USE_HDF) + NAMESPACE + spinerDeps + COMPONENTS + C + HL + EXPECTED_TARGETS + hdf5::hdf5 + hdf5::hdf5_hl) + target_compile_definitions(spiner INTERFACE SPINER_USE_HDF) endif() -spiner_content_populate( - NAMESPACE spinerDeps -) +spiner_content_populate(NAMESPACE spinerDeps) -# We don't know about this until HDF5 is -# populated, so we need to delay until it's been -# (NB: newer versions of HDF5/CMake appear to fix this) +# We don't know about this until HDF5 is populated, so we need to delay until +# it's been (NB: newer versions of HDF5/CMake appear to fix this) if(HDF5_IS_PARALLEL) - spiner_content_declare(MPI + spiner_content_declare( + MPI NO_FETCH - COMPONENTS CXX - EXPECTED_TARGETS MPI::MPI_CXX - NAMESPACE spinerMPI - ) - spiner_content_populate( - NAMESPACE spinerMPI - ) + COMPONENTS + CXX + EXPECTED_TARGETS + MPI::MPI_CXX + NAMESPACE + spinerMPI) + spiner_content_populate(NAMESPACE spinerMPI) endif() -target_link_libraries(spiner - INTERFACE - ${spinerDeps_POPULATED_TARGETS} - ${spinerMPI_POPULATED_TARGETS} -) - -# Enables -# #include -target_include_directories(spiner - INTERFACE - $ - $ -) +target_link_libraries(spiner INTERFACE ${spinerDeps_POPULATED_TARGETS} + ${spinerMPI_POPULATED_TARGETS}) + +# Enables #include +target_include_directories( + spiner INTERFACE $ + $) # Option imported from `CTest` -if (BUILD_TESTING) +if(SPINER_BUILD_TESTING) message(STATUS "\nConfiguring tests") add_subdirectory(test) endif() +# ----------------------------------------------------------------------------# +# Generate config settings +# ----------------------------------------------------------------------------# + +# get all available `SPINER_` cmake cache variables set during configuration +get_cmake_property(_variableNames VARIABLES) +string(REGEX MATCHALL "(^|;)SPINER_[A-Za-z0-9_]*" _matchedVars + "${_variableNames}") + +# use config template to generate the configuration of the build not sure why +# CMake doesn't do this automatically, but w/e +foreach(_variableName ${_matchedVars}) + set(SPINER_CONFIG_CODE + "${SPINER_CONFIG_CODE}\nset(${_variableName} \"${${_variableName}}\")") +endforeach() + install( TARGETS spiner EXPORT spinerTargets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} -) + INCLUDES + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) configure_package_config_file( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/spinerConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/spinerConfig.cmake - INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/spiner -) - + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/spiner) + # ...and the version file write_basic_package_version_file( ${CMAKE_CURRENT_BINARY_DIR}/spinerConfigVersion.cmake VERSION ${SPINER_VERSION} - COMPATIBILITY SameMajorVersion -) - + COMPATIBILITY SameMajorVersion) + # Install the cmake configuration files install(FILES ${CMAKE_CURRENT_BINARY_DIR}/spinerConfig.cmake - ${CMAKE_CURRENT_BINARY_DIR}/spinerConfigVersion.cmake - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/spiner ) - + ${CMAKE_CURRENT_BINARY_DIR}/spinerConfigVersion.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/spiner) + # Install header files install( DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/spiner" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - FILES_MATCHING PATTERN "*.hpp" -) - -# Install the export target. This will define the CMake target -# for external projects when used with `find_package` -install(EXPORT spinerTargets + FILES_MATCHING + PATTERN "*.hpp") + +# Install the export target. This will define the CMake target for external +# projects when used with `find_package` +install( + EXPORT spinerTargets NAMESPACE spiner:: FILE "spinerTargets.cmake" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/spiner" -) - -# Export configuration for external projects that reference -# just our build-tree; e.g. for submodules. To use, ensure -# `CMAKE_PREFIX_PATH` points to this source directory. -# NOTE: This config will not be relocatable! -export(TARGETS spiner + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/spiner") + +# Export configuration for external projects that reference just our build-tree; +# e.g. for submodules. To use, ensure `CMAKE_PREFIX_PATH` points to this source +# directory. NOTE: This config will not be relocatable! +export( + TARGETS spiner NAMESPACE spiner:: - FILE "${CMAKE_CURRENT_BINARY_DIR}/spinerTargets.cmake" -) + FILE "${CMAKE_CURRENT_BINARY_DIR}/spinerTargets.cmake") diff --git a/cmake/spinerConfig.cmake.in b/cmake/spinerConfig.cmake.in index df8289481..9f2940776 100644 --- a/cmake/spinerConfig.cmake.in +++ b/cmake/spinerConfig.cmake.in @@ -1,5 +1,7 @@ @PACKAGE_INIT@ +@SPINER_CONFIG_CODE@ + include(CMakeFindDependencyMacro) find_dependency(ports-of-call) @@ -8,14 +10,13 @@ include("${CMAKE_CURRENT_LIST_DIR}/spinerTargets.cmake") check_required_components(spiner) -# © 2021. Triad National Security, LLC. All rights reserved. This -# program was produced under U.S. Government contract 89233218CNA000001 -# for Los Alamos National Laboratory (LANL), which is operated by Triad -# National Security, LLC for the U.S. Department of Energy/National -# Nuclear Security Administration. All rights in the program are -# reserved by Triad National Security, LLC, and the U.S. Department of -# Energy/National Nuclear Security Administration. The Government is -# granted for itself and others acting on its behalf a nonexclusive, -# paid-up, irrevocable worldwide license in this material to reproduce, -# prepare derivative works, distribute copies to the public, perform +# © 2021. Triad National Security, LLC. All rights reserved. This program was +# produced under U.S. Government contract 89233218CNA000001 for Los Alamos +# National Laboratory (LANL), which is operated by Triad National Security, LLC +# for the U.S. Department of Energy/National Nuclear Security Administration. +# All rights in the program are reserved by Triad National Security, LLC, and +# the U.S. Department of Energy/National Nuclear Security Administration. The +# Government is granted for itself and others acting on its behalf a +# nonexclusive, paid-up, irrevocable worldwide license in this material to +# reproduce, prepare derivative works, distribute copies to the public, perform # publicly and display publicly, and to permit others to do so. From 7c4fefc8bccab972b7adfb895a153166eeb79acd Mon Sep 17 00:00:00 2001 From: Christopher Mauney Date: Tue, 27 Jun 2023 14:34:12 -0600 Subject: [PATCH 4/9] updated spackage and CI --- .github/workflows/tests.yml | 2 +- .gitlab-ci.yml | 4 ++-- spack-repo/packages/spiner/package.py | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4e9299101..d40a992d3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -27,7 +27,7 @@ jobs: run: | mkdir -p bin cd bin - cmake -DSPINER_USE_HDF=ON -DBUILD_TESTING=ON .. + cmake -DSPINER_USE_HDF=ON -DSPINER_BUILD_TESTS=ON .. make -j make test valgrind --leak-check=yes --track-origins=yes ./test/test.bin diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 87b54dca7..909e81f89 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -84,7 +84,7 @@ before_script: - | if [[ ${CI_JOB_NAME} =~ "power9" ]]; then - export SPINER_SPACK_SPEC="${SPINER_SPACK_SPEC}+kokkos+cuda cuda_arch=70"; + export SPINER_SPACK_SPEC="${SPINER_SPACK_SPEC}+hdf5+mpi+kokkos+cuda cuda_arch=70"; fi - | if [[ "${CI_COMMIT_BRANCH}" == "${CI_DEFAULT_BRANCH}" ]]; @@ -115,7 +115,7 @@ before_script: - cd build - | cmake --log-level=DEBUG \ - -DBUILD_TESTING=ON \ + -DSPINER_BUILD_TESTS=ON \ -DCMAKE_INSTALL_PREFIX=${CI_PROJECT_DIR}/install \ -DSPINER_USE_HDF=ON \ -DSPINER_TEST_USE_KOKKOS=$([[ ${CI_JOB_NAME} =~ "power9" ]] && echo ON || echo OFF) \ diff --git a/spack-repo/packages/spiner/package.py b/spack-repo/packages/spiner/package.py index eacfd9d93..8d572027e 100644 --- a/spack-repo/packages/spiner/package.py +++ b/spack-repo/packages/spiner/package.py @@ -54,6 +54,7 @@ class Spiner(CMakePackage, CudaPackage): depends_on("catch2@2.13.4:2.13.9") depends_on("ports-of-call@1.2.0:", when="@:1.5.1") depends_on("ports-of-call@1.5.1:", when="@1.6.0:") + depends_on("ports-of-call@main", when="@main") # Currently the raw cuda backend of ports-of-call is not supported. depends_on("ports-of-call portability_strategy=Kokkos", when="@:1.5.1 +kokkos") From 8238c97a16dea031d739644d4d9ac3b84d0c6a24 Mon Sep 17 00:00:00 2001 From: Christopher Mauney Date: Tue, 27 Jun 2023 14:43:44 -0600 Subject: [PATCH 5/9] detune cmake version required --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ba842d81..00b9be8ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ # publicly and display publicly, and to permit others to do so. # ------------------------------------------------------------------------------# -cmake_minimum_required(VERSION 3.23) +cmake_minimum_required(VERSION 3.19) set(SPINER_VERSION 1.6.0) project(spiner VERSION ${SPINER_VERSION}) From 2fb3b4720e0c7339f2cebc3cf38234c5146b6025 Mon Sep 17 00:00:00 2001 From: Christopher Mauney Date: Tue, 27 Jun 2023 14:49:34 -0600 Subject: [PATCH 6/9] fixed var spelling --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 00b9be8ea..7c1830de0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -143,7 +143,7 @@ target_include_directories( spiner INTERFACE $ $) # Option imported from `CTest` -if(SPINER_BUILD_TESTING) +if(SPINER_BUILD_TESTS) message(STATUS "\nConfiguring tests") add_subdirectory(test) endif() From 9045c2536ff85c922c5893d5479b5541b0d691d5 Mon Sep 17 00:00:00 2001 From: Christopher Mauney Date: Tue, 27 Jun 2023 14:54:10 -0600 Subject: [PATCH 7/9] github CI turn off kokkos --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d40a992d3..7ad807e95 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -27,7 +27,7 @@ jobs: run: | mkdir -p bin cd bin - cmake -DSPINER_USE_HDF=ON -DSPINER_BUILD_TESTS=ON .. + cmake -DSPINER_USE_HDF=ON -DSPINER_BUILD_TESTS=ON -DSPINER_TEST_USE_KOKKOS .. make -j make test valgrind --leak-check=yes --track-origins=yes ./test/test.bin From f1ba3e85d77df0a16ed674636cdacf0bc6909483 Mon Sep 17 00:00:00 2001 From: Christopher Mauney Date: Tue, 27 Jun 2023 14:55:27 -0600 Subject: [PATCH 8/9] github CI turn off kokkos again --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7ad807e95..cfc9e4846 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -27,7 +27,7 @@ jobs: run: | mkdir -p bin cd bin - cmake -DSPINER_USE_HDF=ON -DSPINER_BUILD_TESTS=ON -DSPINER_TEST_USE_KOKKOS .. + cmake -DSPINER_USE_HDF=ON -DSPINER_BUILD_TESTS=ON -DSPINER_TEST_USE_KOKKOS=OFF .. make -j make test valgrind --leak-check=yes --track-origins=yes ./test/test.bin From 3468d91d6285d9f3083be022979824d86282d64e Mon Sep 17 00:00:00 2001 From: Daniel Holladay Date: Tue, 11 Jul 2023 11:25:29 -0600 Subject: [PATCH 9/9] Bumping spiner version in cmake to prepare new release. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c1830de0..8bff94438 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ cmake_minimum_required(VERSION 3.19) -set(SPINER_VERSION 1.6.0) +set(SPINER_VERSION 1.6.1) project(spiner VERSION ${SPINER_VERSION}) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")