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
56 changes: 22 additions & 34 deletions include/openPMD/Datatype.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ namespace openPMD
enum class Datatype : int
{
CHAR,
UCHAR, // SCHAR,
UCHAR,
SCHAR,
SHORT,
INT,
LONG,
Expand Down Expand Up @@ -74,6 +75,7 @@ enum class Datatype : int
VEC_CFLOAT,
VEC_CDOUBLE,
VEC_CLONG_DOUBLE,
VEC_SCHAR,
VEC_STRING,
ARR_DBL_7,

Expand Down Expand Up @@ -124,6 +126,10 @@ inline constexpr Datatype determineDatatype()
{
return DT::UCHAR;
}
else if (decay_equiv<T, signed char>::value)
{
return DT::SCHAR;
}
else if (decay_equiv<T, short>::value)
{
return DT::SHORT;
Expand Down Expand Up @@ -208,6 +214,10 @@ inline constexpr Datatype determineDatatype()
{
return DT::VEC_UCHAR;
}
else if (decay_equiv<T, std::vector<signed char>>::value)
{
return DT::VEC_SCHAR;
}
else if (decay_equiv<T, std::vector<unsigned short>>::value)
{
return DT::VEC_USHORT;
Expand Down Expand Up @@ -276,6 +286,10 @@ inline constexpr Datatype determineDatatype(std::shared_ptr<T>)
{
return DT::UCHAR;
}
else if (decay_equiv<T, signed char>::value)
{
return DT::SCHAR;
}
else if (decay_equiv<T, short>::value)
{
return DT::SHORT;
Expand Down Expand Up @@ -360,6 +374,10 @@ inline constexpr Datatype determineDatatype(std::shared_ptr<T>)
{
return DT::VEC_UCHAR;
}
else if (decay_equiv<T, std::vector<signed char>>::value)
{
return DT::VEC_SCHAR;
}
else if (decay_equiv<T, std::vector<unsigned short>>::value)
{
return DT::VEC_USHORT;
Expand Down Expand Up @@ -434,9 +452,9 @@ inline size_t toBytes(Datatype d)
case DT::UCHAR:
case DT::VEC_UCHAR:
return sizeof(unsigned char);
// case DT::SCHAR:
// case DT::VEC_SCHAR:
// return sizeof(signed char);
case DT::SCHAR:
case DT::VEC_SCHAR:
return sizeof(signed char);
case DT::SHORT:
case DT::VEC_SHORT:
return sizeof(short);
Expand Down Expand Up @@ -776,36 +794,6 @@ inline bool isSame(openPMD::Datatype const d, openPMD::Datatype const e)
return false;
}

namespace detail
{
template <typename T>
struct BasicDatatypeHelper
{
Datatype m_dt = determineDatatype<T>();
};

template <typename T>
struct BasicDatatypeHelper<std::vector<T>>
{
Datatype m_dt = BasicDatatypeHelper<T>{}.m_dt;
};

template <typename T, std::size_t n>
struct BasicDatatypeHelper<std::array<T, n>>
{
Datatype m_dt = BasicDatatypeHelper<T>{}.m_dt;
};

struct BasicDatatype
{
template <typename T>
static Datatype call();

template <int n>
static Datatype call();
};
} // namespace detail

/**
* @brief basicDatatype Strip openPMD Datatype of std::vector, std::array et.
* al.
Expand Down
7 changes: 7 additions & 0 deletions include/openPMD/DatatypeHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ auto switchType(Datatype dt, Args &&...args)
case Datatype::UCHAR:
return Action::template call<unsigned char>(
std::forward<Args>(args)...);
case Datatype::SCHAR:
return Action::template call<signed char>(std::forward<Args>(args)...);
case Datatype::SHORT:
return Action::template call<short>(std::forward<Args>(args)...);
case Datatype::INT:
Expand Down Expand Up @@ -164,6 +166,9 @@ auto switchType(Datatype dt, Args &&...args)
case Datatype::VEC_UCHAR:
return Action::template call<std::vector<unsigned char> >(
std::forward<Args>(args)...);
case Datatype::VEC_SCHAR:
return Action::template call<std::vector<signed char> >(
std::forward<Args>(args)...);
case Datatype::VEC_USHORT:
return Action::template call<std::vector<unsigned short> >(
std::forward<Args>(args)...);
Expand Down Expand Up @@ -241,6 +246,8 @@ auto switchNonVectorType(Datatype dt, Args &&...args)
case Datatype::UCHAR:
return Action::template call<unsigned char>(
std::forward<Args>(args)...);
case Datatype::SCHAR:
return Action::template call<signed char>(std::forward<Args>(args)...);
case Datatype::SHORT:
return Action::template call<short>(std::forward<Args>(args)...);
case Datatype::INT:
Expand Down
114 changes: 114 additions & 0 deletions include/openPMD/Datatype_internal.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/* Copyright 2022 Franz Poeschel, Axel Huebl
*
* This file is part of openPMD-api.
*
* openPMD-api is free software: you can redistribute it and/or modify
* it under the terms of of either the GNU General Public License or
* the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* openPMD-api is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License and the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* and the GNU Lesser General Public License along with openPMD-api.
* If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
Comment thread
ax3l marked this conversation as resolved.

#include "openPMD/auxiliary/TypeTraits.hpp"

#include <array>
#include <cstddef>
#include <vector>

namespace openPMD
{
namespace detail
{
template <typename DoDetermineDatatype>
struct BasicDatatype
{
using DT = typename DoDetermineDatatype::DT_enum;

template <typename T>
constexpr static DT call()
{
if constexpr (auxiliary::IsVector_v<T>)
{
return DoDetermineDatatype::template call<
typename T::value_type>();
}
else if constexpr (auxiliary::IsArray_v<T>)
{
return DoDetermineDatatype::template call<
typename T::value_type>();
}
else
{
return DoDetermineDatatype::template call<T>();
}
#if defined(__INTEL_COMPILER)
/*
* ICPC has trouble with if constexpr, thinking that return statements are

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think NVCC 11.0 has a similar issue, potentially check and add a similar suppression?
Around 11.5+, the false warning is solved.

* missing afterwards. Deactivate the warning.
* Note that putting a statement here will not help to fix this since it will
* then complain about unreachable code.
* https://community.intel.com/t5/Intel-C-Compiler/quot-if-constexpr-quot-and-quot-missing-return-statement-quot-in/td-p/1154551
*/
#pragma warning(disable : 1011)
}
#pragma warning(default : 1011)
#else
}
#endif

constexpr static char const *errorMsg =
"basicDatatype: received unknown datatype.";
};

template <typename DoDetermineDatatype>
struct ToVectorType
{
using DT = typename DoDetermineDatatype::DT_enum;

template <typename T>
constexpr static DT call()
{
if constexpr (auxiliary::IsVector_v<T>)
{
return DoDetermineDatatype::template call<T>();
}
else if constexpr (auxiliary::IsArray_v<T>)
{
return DoDetermineDatatype::template call<
std::vector<typename T::value_type>>();
}
else
{
return DoDetermineDatatype::template call<std::vector<T>>();
}
#if defined(__INTEL_COMPILER)
/*
* ICPC has trouble with if constexpr, thinking that return statements are

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls see above note on NVCC

* missing afterwards. Deactivate the warning.
* Note that putting a statement here will not help to fix this since it will
* then complain about unreachable code.
* https://community.intel.com/t5/Intel-C-Compiler/quot-if-constexpr-quot-and-quot-missing-return-statement-quot-in/td-p/1154551
*/
#pragma warning(disable : 1011)
}
#pragma warning(default : 1011)
#else
}
#endif

constexpr static char const *errorMsg =
"toVectorType: received unknown datatype.";
};
} // namespace detail
} // namespace openPMD
2 changes: 2 additions & 0 deletions include/openPMD/IO/ADIOS/ADIOS1Auxiliary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ inline ADIOS_DATATYPES getBP1DataType(Datatype dtype)
{
case DT::CHAR:
case DT::VEC_CHAR:
case DT::SCHAR:
case DT::VEC_SCHAR:
return adios_byte;
case DT::UCHAR:
case DT::VEC_UCHAR:
Expand Down
16 changes: 10 additions & 6 deletions include/openPMD/IO/ADIOS/ADIOS2Auxiliary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ namespace detail
};

template <typename T>
struct ToDatatypeHelper<std::vector<T> >
struct ToDatatypeHelper<std::vector<T>>
{
static std::string type();
};

template <typename T, size_t n>
struct ToDatatypeHelper<std::array<T, n> >
struct ToDatatypeHelper<std::array<T, n>>
{
static std::string type();
};
Expand Down Expand Up @@ -149,6 +149,8 @@ auto switchAdios2AttributeType(Datatype dt, Args &&...args)
case Datatype::UCHAR:
return Action::template call<unsigned char>(
std::forward<Args>(args)...);
case Datatype::SCHAR:
return Action::template call<signed char>(std::forward<Args>(args)...);
case Datatype::SHORT:
return Action::template call<short>(std::forward<Args>(args)...);
case Datatype::INT:
Expand All @@ -175,10 +177,10 @@ auto switchAdios2AttributeType(Datatype dt, Args &&...args)
case Datatype::LONG_DOUBLE:
return Action::template call<long double>(std::forward<Args>(args)...);
case Datatype::CFLOAT:
return Action::template call<std::complex<float> >(
return Action::template call<std::complex<float>>(
std::forward<Args>(args)...);
case Datatype::CDOUBLE:
return Action::template call<std::complex<double> >(
return Action::template call<std::complex<double>>(
std::forward<Args>(args)...);
// missing std::complex< long double > type in ADIOS2 v2.6.0
// case Datatype::CLONG_DOUBLE:
Expand Down Expand Up @@ -227,6 +229,8 @@ auto switchAdios2VariableType(Datatype dt, Args &&...args)
case Datatype::UCHAR:
return Action::template call<unsigned char>(
std::forward<Args>(args)...);
case Datatype::SCHAR:
return Action::template call<signed char>(std::forward<Args>(args)...);
case Datatype::SHORT:
return Action::template call<short>(std::forward<Args>(args)...);
case Datatype::INT:
Expand All @@ -253,10 +257,10 @@ auto switchAdios2VariableType(Datatype dt, Args &&...args)
case Datatype::LONG_DOUBLE:
return Action::template call<long double>(std::forward<Args>(args)...);
case Datatype::CFLOAT:
return Action::template call<std::complex<float> >(
return Action::template call<std::complex<float>>(
std::forward<Args>(args)...);
case Datatype::CDOUBLE:
return Action::template call<std::complex<double> >(
return Action::template call<std::complex<double>>(
std::forward<Args>(args)...);
// missing std::complex< long double > type in ADIOS2 v2.6.0
// case Datatype::CLONG_DOUBLE:
Expand Down
14 changes: 7 additions & 7 deletions include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ namespace detail
detail::BufferedAttributeWrite &params,
T value);

static void readAttribute(
static Datatype readAttribute(
detail::PreloadAdiosAttributes const &,
std::string name,
std::shared_ptr<Attribute::resource> resource);
Expand Down Expand Up @@ -614,7 +614,7 @@ namespace detail
"attribute types");
}

static void readAttribute(
static Datatype readAttribute(
detail::PreloadAdiosAttributes const &,
std::string,
std::shared_ptr<Attribute::resource>)
Expand Down Expand Up @@ -647,7 +647,7 @@ namespace detail
"vector attribute types");
}

static void readAttribute(
static Datatype readAttribute(
detail::PreloadAdiosAttributes const &,
std::string,
std::shared_ptr<Attribute::resource>)
Expand Down Expand Up @@ -675,7 +675,7 @@ namespace detail
detail::BufferedAttributeWrite &params,
const std::vector<T> &value);

static void readAttribute(
static Datatype readAttribute(
detail::PreloadAdiosAttributes const &,
std::string name,
std::shared_ptr<Attribute::resource> resource);
Expand Down Expand Up @@ -713,7 +713,7 @@ namespace detail
detail::BufferedAttributeWrite &params,
const std::vector<std::string> &vec);

static void readAttribute(
static Datatype readAttribute(
detail::PreloadAdiosAttributes const &,
std::string name,
std::shared_ptr<Attribute::resource> resource);
Expand Down Expand Up @@ -751,7 +751,7 @@ namespace detail
detail::BufferedAttributeWrite &params,
const std::array<T, n> &value);

static void readAttribute(
static Datatype readAttribute(
detail::PreloadAdiosAttributes const &,
std::string name,
std::shared_ptr<Attribute::resource> resource);
Expand Down Expand Up @@ -816,7 +816,7 @@ namespace detail
detail::BufferedAttributeWrite &params,
bool value);

static void readAttribute(
static Datatype readAttribute(
detail::PreloadAdiosAttributes const &,
std::string name,
std::shared_ptr<Attribute::resource> resource);
Expand Down
Loading