From bfbbf77cf4db12549e06b966351d4e55f4c55668 Mon Sep 17 00:00:00 2001 From: Yifei Wu Date: Wed, 3 Sep 2025 16:57:24 -0700 Subject: [PATCH] add support for nvhpc compiler --- CMakeLists.txt | 1 + src/engines/ioda/CMakeLists.txt | 1 + .../ioda/include/ioda/Attributes/Attribute.h | 8 ++++---- .../ioda/include/ioda/Attributes/Has_Attributes.h | 4 ++-- .../ioda/include/ioda/Variables/Has_Variables.h | 4 ++-- .../ioda/include/ioda/Variables/Variable.h | 14 +++++++------- src/engines/ioda/src/ioda/C/ioda_variable_c.cpp | 7 ++++--- .../ioda/src/ioda/Engines/HH/HH-groups.cpp | 15 +++++++++++---- .../ioda/src/ioda/Engines/HH/HH/HH-variables.h | 4 ++-- src/engines/ioda/src/ioda/Has_Variables.cpp | 2 +- src/engines/ioda/src/ioda/Type.cpp | 2 +- src/ioPool/ReaderPoolUtils.cpp | 4 ++-- 12 files changed, 38 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 206b279f..2c5e2bf3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,7 @@ find_package( Eigen3 REQUIRED NO_MODULE HINTS $ENV{Eigen3_PATH} $ENV{EIGEN3_PATH} $ENV{Eigen_PATH} $ENV{EIGEN_PATH} ) find_package( gsl-lite REQUIRED HINTS $ENV{gsl_lite_DIR} ) find_package( udunits 2.2.0 REQUIRED ) +find_package( EXPAT REQUIRED ) find_package( Boost 1.64.0 REQUIRED ) # Optional diff --git a/src/engines/ioda/CMakeLists.txt b/src/engines/ioda/CMakeLists.txt index 93cb37a0..24bec1c7 100644 --- a/src/engines/ioda/CMakeLists.txt +++ b/src/engines/ioda/CMakeLists.txt @@ -343,6 +343,7 @@ target_link_libraries(ioda_engines PUBLIC gsl::gsl-lite) target_link_libraries(ioda_engines PUBLIC Eigen3::Eigen) target_link_libraries(ioda_engines PUBLIC udunits::udunits) target_link_libraries(ioda_engines PUBLIC eckit) +target_link_libraries(ioda_engines PUBLIC EXPAT::EXPAT) if(BUILD_PYTHON_BINDINGS) target_link_libraries(ioda_engines PRIVATE Python3::Python pybind11::headers) diff --git a/src/engines/ioda/include/ioda/Attributes/Attribute.h b/src/engines/ioda/include/ioda/Attributes/Attribute.h index da507b2d..80916401 100644 --- a/src/engines/ioda/include/ioda/Attributes/Attribute.h +++ b/src/engines/ioda/include/ioda/Attributes/Attribute.h @@ -104,7 +104,7 @@ class Attribute_Base { auto d = m.serialize(data); auto spn = gsl::make_span(reinterpret_cast(d->DataPointers.data()), d->DataPointers.size() * Marshaller::bytesPerElement_); - write(spn, TypeWrapper::GetType(getTypeProvider())); + write(spn, TypeWrapper::GetType(gsl::not_null(getTypeProvider()))); return Attribute_Implementation{backend_}; } catch (...) { std::throw_with_nested(Exception(ioda_Here())); @@ -259,7 +259,7 @@ class Attribute_Base { auto p = m.prep_deserialize(numObjects); read(gsl::make_span(reinterpret_cast(p->DataPointers.data()), p->DataPointers.size() * Marshaller::bytesPerElement_), - TypeWrapper::GetType(getTypeProvider())); + TypeWrapper::GetType(gsl::not_null(getTypeProvider()))); m.deserialize(p, data); return Attribute_Implementation{backend_}; @@ -445,7 +445,7 @@ class Attribute_Base { /// \throws ioda::Exception if an error occurred. template bool isA() const { - Type templateType = Types::GetType_Wrapper::GetType(getTypeProvider()); + Type templateType = Types::GetType_Wrapper::GetType(gsl::not_null(getTypeProvider())); return isA(templateType); } @@ -453,7 +453,7 @@ class Attribute_Base { virtual bool isA(Type lhs) const; /// Python compatability function - inline bool isA(BasicTypes dataType) { return isA(Type(dataType, getTypeProvider())); } + inline bool isA(BasicTypes dataType) { return isA(Type(dataType, gsl::not_null<::ioda::detail::Type_Provider*>(getTypeProvider()))); } /// \internal pybind11 inline bool _py_isA2(BasicTypes dataType) { return isA(dataType); } diff --git a/src/engines/ioda/include/ioda/Attributes/Has_Attributes.h b/src/engines/ioda/include/ioda/Attributes/Has_Attributes.h index 2a24b7cf..dd337263 100644 --- a/src/engines/ioda/include/ioda/Attributes/Has_Attributes.h +++ b/src/engines/ioda/include/ioda/Attributes/Has_Attributes.h @@ -332,7 +332,7 @@ class IODA_DL Has_Attributes_Base { /// Python compatability function inline Attribute _create_py(const std::string& attrname, BasicTypes dataType, const std::vector& dimensions = {1}) { - return create(attrname, ::ioda::Type(dataType, getTypeProvider()), dimensions); + return create(attrname, ::ioda::Type(dataType, gsl::not_null<::ioda::detail::Type_Provider*>(getTypeProvider())), dimensions); } /// \brief Create an Attribute without setting its data. @@ -345,7 +345,7 @@ class IODA_DL Has_Attributes_Base { Attribute create(const std::string& attrname, const std::vector& dimensions = {1}) { try { - Type in_memory_dataType = TypeWrapper::GetType(getTypeProvider()); + Type in_memory_dataType = TypeWrapper::GetType(gsl::not_null(getTypeProvider())); auto att = create(attrname, in_memory_dataType, dimensions); return att; } catch (...) { diff --git a/src/engines/ioda/include/ioda/Variables/Has_Variables.h b/src/engines/ioda/include/ioda/Variables/Has_Variables.h index ecceabaa..bcf2a18c 100644 --- a/src/engines/ioda/include/ioda/Variables/Has_Variables.h +++ b/src/engines/ioda/include/ioda/Variables/Has_Variables.h @@ -309,7 +309,7 @@ class IODA_DL Has_Variables_Base { try { VariableCreationParameters params2 = params; FillValuePolicies::applyFillValuePolicy(getFillValuePolicy(), params2.fillValue_); - Type in_memory_dataType = Types::GetType(getTypeProvider()); + Type in_memory_dataType = Types::GetType(gsl::not_null(getTypeProvider())); auto var = create(name, in_memory_dataType, dimensions, max_dimensions, params2); return var; @@ -343,7 +343,7 @@ class IODA_DL Has_Variables_Base { const VariableCreationParameters& params = VariableCreationParameters::defaulted()) { try { - Type in_memory_dataType = Types::GetType(getTypeProvider()); + Type in_memory_dataType = Types::GetType(gsl::not_null(getTypeProvider())); NewVariables_t newvars{NewVariable(name, in_memory_dataType, dimension_scales, params)}; createWithScales(newvars); diff --git a/src/engines/ioda/include/ioda/Variables/Variable.h b/src/engines/ioda/include/ioda/Variables/Variable.h index 06319617..d76eccd6 100644 --- a/src/engines/ioda/include/ioda/Variables/Variable.h +++ b/src/engines/ioda/include/ioda/Variables/Variable.h @@ -100,7 +100,7 @@ class Variable_Base { /// \throws ioda::Exception if an error occurred. template bool isA() const { - Type templateType = Types::GetType_Wrapper::GetType(getTypeProvider()); + Type templateType = Types::GetType_Wrapper::GetType(gsl::not_null(getTypeProvider())); return isA(templateType); } @@ -108,7 +108,7 @@ class Variable_Base { virtual bool isA(Type lhs) const; /// Python compatability function - inline bool isA(BasicTypes dataType) const { return isA(Type(dataType, getTypeProvider())); } + inline bool isA(BasicTypes dataType) const { return isA(Type(dataType, gsl::not_null<::ioda::detail::Type_Provider*>(getTypeProvider()))); } /// \internal pybind11 inline bool _py_isA2(BasicTypes dataType) { return isA(dataType); } /// Convenience function to query type @@ -293,7 +293,7 @@ class Variable_Base { return write(gsl::make_span( reinterpret_cast(d->DataPointers.data()), d->DataPointers.size() * Marshaller::bytesPerElement_), - TypeWrapper::GetType(getTypeProvider()), mem_selection, file_selection); + TypeWrapper::GetType(gsl::not_null(getTypeProvider())), mem_selection, file_selection); } catch (...) { std::throw_with_nested(Exception(ioda_Here())); } @@ -309,7 +309,7 @@ class Variable_Base { return parallelWrite(gsl::make_span( reinterpret_cast(d->DataPointers.data()), d->DataPointers.size() * Marshaller::bytesPerElement_), - TypeWrapper::GetType(getTypeProvider()), mem_selection, file_selection); + TypeWrapper::GetType(gsl::not_null(getTypeProvider())), mem_selection, file_selection); } catch (...) { std::throw_with_nested(Exception(ioda_Here())); } @@ -339,7 +339,7 @@ class Variable_Base { return write(gsl::make_span( reinterpret_cast(d->DataPointers.data()), d->DataPointers.size() * Marshaller::bytesPerElement_), - TypeWrapper::GetType(getTypeProvider()), mem_selection, file_selection); + TypeWrapper::GetType(gsl::not_null(getTypeProvider())), mem_selection, file_selection); } catch (...) { std::throw_with_nested(Exception(ioda_Here())); } @@ -355,7 +355,7 @@ class Variable_Base { return parallelWrite(gsl::make_span( reinterpret_cast(d->DataPointers.data()), d->DataPointers.size() * Marshaller::bytesPerElement_), - TypeWrapper::GetType(getTypeProvider()), mem_selection, file_selection); + TypeWrapper::GetType(gsl::not_null(getTypeProvider())), mem_selection, file_selection); } catch (...) { std::throw_with_nested(Exception(ioda_Here())); } @@ -531,7 +531,7 @@ class Variable_Base { // reading in a string, then mutable data type is char*, // which works because address pointers have the same size. p->DataPointers.size() * Marshaller::bytesPerElement_), - TypeWrapper::GetType(getTypeProvider()), mem_selection, file_selection); + TypeWrapper::GetType(gsl::not_null(getTypeProvider())), mem_selection, file_selection); m.deserialize(p, data, &atts); return Variable_Implementation{backend_}; diff --git a/src/engines/ioda/src/ioda/C/ioda_variable_c.cpp b/src/engines/ioda/src/ioda/C/ioda_variable_c.cpp index e08d7195..7ec72aa6 100644 --- a/src/engines/ioda/src/ioda/C/ioda_variable_c.cpp +++ b/src/engines/ioda/src/ioda/C/ioda_variable_c.cpp @@ -302,7 +302,8 @@ bool ioda_variable_c_write_char(ioda_variable_t p,int64_t n,const char * vptr) { throw std::exception(); } std::string s(str,n); - auto v = var->write< std::string >(s); + std::vector vs = {s}; + auto v = var->write< std::string >(vs); return true; } catch (std::exception& e) { std::cerr << "ioda_variable_c_write_char failed\n"; @@ -323,7 +324,7 @@ bool ioda_variable_c_write_str(ioda_variable_t p,cxx_vector_string_t vstr_p) { std::cerr << "ioda_variable_c_write_str vecstring pointer is null\n"; fatal_error(); } - ioda::Variable v = var->write< std::vector< std::string > >(*vstr); + ioda::Variable v = var->write< std::string >(*vstr); return true; } catch (std::exception& e) { std::cerr << "ioda_variable_c_write_str_full failed "; @@ -411,7 +412,7 @@ bool ioda_variable_c_read_str(void *p,int64_t n,cxx_vector_string_t *vstr) { vs_p = reinterpret_cast(new std::vector()); } VOID_TO_CXX(std::vector,vs_p,vs); - auto vr = var->read< std::vector >(*vs); + auto vr = var->read< std::string >(*vs); // make sure that vstr points to correct char * *vstr = reinterpret_cast(vs); return true; diff --git a/src/engines/ioda/src/ioda/Engines/HH/HH-groups.cpp b/src/engines/ioda/src/ioda/Engines/HH/HH-groups.cpp index 9ba1d3bf..1264dea2 100644 --- a/src/engines/ioda/src/ioda/Engines/HH/HH-groups.cpp +++ b/src/engines/ioda/src/ioda/Engines/HH/HH-groups.cpp @@ -178,10 +178,17 @@ std::map> HH_Group::listObjects(ObjectType herr_t search_res = (recurse) - ? H5Lvisit(backend_(), idxclass, H5_ITER_NATIVE, iterate_find_by_link, - reinterpret_cast(&iter_data)) - : H5Literate(backend_(), idxclass, H5_ITER_NATIVE, 0, iterate_find_by_link, - reinterpret_cast(&iter_data)); // NOLINT: 0 is not a nullptr here. +#if H5_VERSION_GE(1, 12, 0) + ? H5Lvisit2(backend_(), idxclass, H5_ITER_NATIVE, iterate_find_by_link, + reinterpret_cast(&iter_data)) + : H5Literate2(backend_(), idxclass, H5_ITER_NATIVE, 0, iterate_find_by_link, + reinterpret_cast(&iter_data)); // NOLINT: 0 is not a nullptr here. +#else + ? H5Lvisit1(backend_(), idxclass, H5_ITER_NATIVE, iterate_find_by_link, + reinterpret_cast(&iter_data)) + : H5Literate1(backend_(), idxclass, H5_ITER_NATIVE, 0, iterate_find_by_link, + reinterpret_cast(&iter_data)); // NOLINT: 0 is not a nullptr here. +#endif if (search_res < 0) throw Exception("H5Lvisit / H5Literate failed.", ioda_Here()) .add("recurse", recurse); diff --git a/src/engines/ioda/src/ioda/Engines/HH/HH/HH-variables.h b/src/engines/ioda/src/ioda/Engines/HH/HH/HH-variables.h index 0e3ef5e0..82756ff7 100644 --- a/src/engines/ioda/src/ioda/Engines/HH/HH/HH-variables.h +++ b/src/engines/ioda/src/ioda/Engines/HH/HH/HH-variables.h @@ -70,7 +70,7 @@ class IODA_HIDDEN HH_Variable : public ioda::detail::Variable_Backend, /// \returns <0 if an error occurred. template bool isA() const { - auto ttype = Types::GetType(getTypeProvider()); + auto ttype = Types::GetType(gsl::not_null(getTypeProvider())); return isA(ttype); } @@ -86,7 +86,7 @@ class IODA_HIDDEN HH_Variable : public ioda::detail::Variable_Backend, /// \returns <0 if an error occurred. template bool isExactlyA() const { - auto ttype = Types::GetType(getTypeProvider()); + auto ttype = Types::GetType(gsl::not_null(getTypeProvider())); HH_hid_t otype = internalType(); auto ret = H5Tequal(ttype(), otype()); if (ret < 0) throw Exception("Cannot check type equality. General failure.", ioda_Here()); diff --git a/src/engines/ioda/src/ioda/Has_Variables.cpp b/src/engines/ioda/src/ioda/Has_Variables.cpp index bf4b42da..88169dc5 100644 --- a/src/engines/ioda/src/ioda/Has_Variables.cpp +++ b/src/engines/ioda/src/ioda/Has_Variables.cpp @@ -162,7 +162,7 @@ Variable Has_Variables_Base::_create_py(const std::string& name, BasicTypes data const VariableCreationParameters& params ) { try { - Type typ = Type(dataType, getTypeProvider()); + Type typ = Type(dataType, gsl::not_null<::ioda::detail::Type_Provider*>(getTypeProvider())); if (dimension_scales.size()) { std::vector c_d, m_d, chunking_hints; diff --git a/src/engines/ioda/src/ioda/Type.cpp b/src/engines/ioda/src/ioda/Type.cpp index 8ed3e91b..57e1b3b3 100644 --- a/src/engines/ioda/src/ioda/Type.cpp +++ b/src/engines/ioda/src/ioda/Type.cpp @@ -178,7 +178,7 @@ Type::Type(std::shared_ptr b, std::type_index t) : Type_Base(b, b->provider_), as_type_index_(t) {} Type::Type(BasicTypes typ, gsl::not_null<::ioda::detail::Type_Provider*> t) - : Type_Base(nullptr, t.get()), as_type_index_(typeid(void)) { + : Type_Base(nullptr, static_cast<::ioda::detail::Type_Provider*>(t)), as_type_index_(typeid(void)) { static const std::map workable_types = {{BasicTypes::float_, typeid(float)}, // NOLINT: cpplint doesn't understand this! {BasicTypes::double_, typeid(double)}, // NOLINT diff --git a/src/ioPool/ReaderPoolUtils.cpp b/src/ioPool/ReaderPoolUtils.cpp index 95e71f0c..ff18af20 100644 --- a/src/ioPool/ReaderPoolUtils.cpp +++ b/src/ioPool/ReaderPoolUtils.cpp @@ -1958,7 +1958,7 @@ void readerLoadSourceVarReplaceFill(const ReaderPoolBase & ioPool, [&](auto typeDiscriminator) { typedef decltype(typeDiscriminator) T; const Type srcType = - Types::GetType_Wrapper::GetType(srcVar.getTypeProvider()); + Types::GetType_Wrapper::GetType(gsl::not_null(srcVar.getTypeProvider())); srcVar.read(srcBuffer, srcType, srcSelect, srcSelect); const ioda::Dimensions_t numElements = srcVar.getDimensions().numElements; replaceFillWithMissing(ioPool, srcVar, numElements, srcBuffer); @@ -2016,7 +2016,7 @@ void readerSaveDestVar(const std::string & varName, const std::vector & de [&](auto typeDiscriminator) { typedef decltype(typeDiscriminator) T; const Type destType = - Types::GetType_Wrapper::GetType(destVar.getTypeProvider()); + Types::GetType_Wrapper::GetType(gsl::not_null(destVar.getTypeProvider())); destVar.write(destBuffer, destType, destSelect, destSelect); }, VarUtils::ThrowIfVariableIsOfUnsupportedType(varName));