Skip to content

Commit

Permalink
Merge pull request #1070 from LLNL/feature/gunney/deprecate-types
Browse files Browse the repository at this point in the history
Deprecate axom integer types
  • Loading branch information
gunney1 committed May 15, 2023
2 parents 6c79744 + b8087b4 commit 7059a36
Show file tree
Hide file tree
Showing 53 changed files with 475 additions and 423 deletions.
3 changes: 3 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ The Axom project release numbers follow [Semantic Versioning](http://semver.org/

## [Unreleased] - Release date yyyy-mm-dd

### Deprecated
- Integer types in `src/axom/core/Types.hpp` are deprecated because c++-11 supports their equivalents.

### Added
- Adds the following methods to `axom::Array` to conform more closely with the `std::vector` interface:
- `Array::front()`: returns a reference to the first element
Expand Down
9 changes: 9 additions & 0 deletions src/axom/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@
@INLINED_AXOM_EXPORTS@


/*
* For gradual removal of types that have been deprecated in favor of
* c++-11 types. Value can be 1 to allow with compiler warnings, 2 to
* allow silently, and -1 to disallow. Corresponds to cmake variable
* AXOM_DEPRECATED_TYPES values of WARN, ALLOW and ERROR.
*/
#cmakedefine AXOM_DEPRECATED_TYPES_N @AXOM_DEPRECATED_TYPES_N@


/*
* Compiler defines to configure the built-in fmt library
* Redefines AXOM_FMT_DEPRECATED to workaround nvcc compiler error
Expand Down
2 changes: 1 addition & 1 deletion src/axom/core/ArrayBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ struct ArrayOpsBase<T, true>
{
// Similar to fill(), except we can allocate stack memory and placement-new
// the object with a move constructor.
alignas(T) axom::uint8 host_buf[sizeof(T)];
alignas(T) std::uint8_t host_buf[sizeof(T)];
T* host_obj = ::new(&host_buf) T(std::forward<Args>(args)...);
axom::copy(array + i, host_obj, sizeof(T));
}
Expand Down
16 changes: 8 additions & 8 deletions src/axom/core/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ const MPI_Datatype mpi_traits<AxomType>::type = MPI_DATATYPE_NULL;
// Initialization of mpi_traits specializations
const MPI_Datatype mpi_traits<float64>::type = MPI_DOUBLE;
const MPI_Datatype mpi_traits<float32>::type = MPI_FLOAT;
const MPI_Datatype mpi_traits<int8>::type = MPI_INT8_T;
const MPI_Datatype mpi_traits<uint8>::type = MPI_UINT8_T;
const MPI_Datatype mpi_traits<int16>::type = MPI_INT16_T;
const MPI_Datatype mpi_traits<uint16>::type = MPI_UINT16_T;
const MPI_Datatype mpi_traits<int32>::type = MPI_INT32_T;
const MPI_Datatype mpi_traits<uint32>::type = MPI_UINT32_T;
const MPI_Datatype mpi_traits<std::int8_t>::type = MPI_INT8_T;
const MPI_Datatype mpi_traits<std::uint8_t>::type = MPI_UINT8_T;
const MPI_Datatype mpi_traits<std::int16_t>::type = MPI_INT16_T;
const MPI_Datatype mpi_traits<std::uint16_t>::type = MPI_UINT16_T;
const MPI_Datatype mpi_traits<std::int32_t>::type = MPI_INT32_T;
const MPI_Datatype mpi_traits<std::uint32_t>::type = MPI_UINT32_T;

#ifndef AXOM_NO_INT64_T
const MPI_Datatype mpi_traits<int64>::type = MPI_INT64_T;
const MPI_Datatype mpi_traits<uint64>::type = MPI_UINT64_T;
const MPI_Datatype mpi_traits<std::int64_t>::type = MPI_INT64_T;
const MPI_Datatype mpi_traits<std::uint64_t>::type = MPI_UINT64_T;
#endif /* end AXOM_NO_INT64_T */

#endif /* end AXOM_USE_MPI */
Expand Down
49 changes: 33 additions & 16 deletions src/axom/core/Types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@

namespace axom
{
using float32 = float;
using float64 = double;

/*
Axom integer types are deprecated.
Their use can trigger an warning or an error, or be quietly allowed,
by using CMake -DAXOM_DEPRECATED_TYPES=<WARN|ERROR|ALLOW>
Eventually, these types will be removed.
*/
#if AXOM_DEPRECATED_TYPES_N == 1 || AXOM_DEPRECATED_TYPES_N == 2
#if AXOM_DEPRECATED_TYPES_N == 1
#if defined(_MSC_VER)
#pragma message( \
"warning: Using deprecated Axom types. Please see CMake variable AXOM_DEPRECATED_TYPES")
#else
#warning \
"Using deprecated Axom types. Please see CMake variable AXOM_DEPRECATED_TYPES"
#endif
#endif
using int8 = std::int8_t; /*!< 8-bit signed integer type */
using uint8 = std::uint8_t; /*!< 8-bit unsigned integer type */

Expand All @@ -34,20 +53,18 @@ using uint16 = std::uint16_t; /*!< 16-bit unsigned integer type */
using int32 = std::int32_t; /*!< 32-bit signed integer type */
using uint32 = std::uint32_t; /*!< 32-bit unsigned integer type */

// Note: KW -- We assume that AXOM_NO_INT64_T will be defined
// on systems/compilers that do not support 64 bit integer types
#ifndef AXOM_NO_INT64_T
// Note: KW -- We assume that AXOM_NO_INT64_T will be defined
// on systems/compilers that do not support 64 bit integer types
#ifndef AXOM_NO_INT64_T
using int64 = std::int64_t; /*!< 64-bit signed integer type */
using uint64 = std::uint64_t; /*!< 64-bit unsigned integer type */
#endif
#endif

using float32 = float;
using float64 = double;

#if defined(AXOM_USE_64BIT_INDEXTYPE) && !defined(AXOM_NO_INT64_T)
using IndexType = int64;
using IndexType = std::int64_t;
#else
using IndexType = int32;
using IndexType = std::int32_t;
#endif

#ifdef AXOM_USE_MPI
Expand Down Expand Up @@ -83,57 +100,57 @@ struct mpi_traits<float32>

//------------------------------------------------------------------------------
template <>
struct mpi_traits<int8>
struct mpi_traits<std::int8_t>
{
static const MPI_Datatype type;
};

//------------------------------------------------------------------------------
template <>
struct mpi_traits<uint8>
struct mpi_traits<std::uint8_t>
{
static const MPI_Datatype type;
};

//------------------------------------------------------------------------------
template <>
struct mpi_traits<int16>
struct mpi_traits<std::int16_t>
{
static const MPI_Datatype type;
};

//------------------------------------------------------------------------------
template <>
struct mpi_traits<uint16>
struct mpi_traits<std::uint16_t>
{
static const MPI_Datatype type;
};

//------------------------------------------------------------------------------
template <>
struct mpi_traits<int32>
struct mpi_traits<std::int32_t>
{
static const MPI_Datatype type;
};

//------------------------------------------------------------------------------
template <>
struct mpi_traits<uint32>
struct mpi_traits<std::uint32_t>
{
static const MPI_Datatype type;
};

//------------------------------------------------------------------------------
#ifndef AXOM_NO_INT64_T
template <>
struct mpi_traits<int64>
struct mpi_traits<std::int64_t>
{
static const MPI_Datatype type;
};

//------------------------------------------------------------------------------
template <>
struct mpi_traits<uint64>
struct mpi_traits<std::uint64_t>
{
static const MPI_Datatype type;
};
Expand Down
34 changes: 17 additions & 17 deletions src/axom/core/tests/core_bit_utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ T random_int()
return static_cast<T>(val);
}

axom::uint64 shifted(int bit) { return static_cast<axom::uint64>(1) << bit; }
std::uint64_t shifted(int bit) { return static_cast<std::uint64_t>(1) << bit; }

} // namespace

TEST(core_bit_utilities, trailingZeroes)
{
constexpr axom::uint64 ZERO = axom::uint64(0);
constexpr int BITS = axom::utilities::BitTraits<axom::uint64>::BITS_PER_WORD;
constexpr std::uint64_t ZERO = std::uint64_t(0);
constexpr int BITS = axom::utilities::BitTraits<std::uint64_t>::BITS_PER_WORD;
ASSERT_EQ(64, BITS);

// Axom's trailingZeros will return 64 when given 0
Expand All @@ -47,13 +47,13 @@ TEST(core_bit_utilities, trailingZeroes)
// Test with a known trailing bit
for(int i = 0; i < BITS; ++i)
{
axom::uint64 val = ::shifted(i);
std::uint64_t val = ::shifted(i);
EXPECT_EQ(i, axom::utilities::trailingZeros(val));

// Value doesn't change when you set bits to left of trailing bit
for(int j = i + 1; j < BITS; ++j)
{
axom::uint64 val2 = ::shifted(i) + ::shifted(j);
std::uint64_t val2 = ::shifted(i) + ::shifted(j);
EXPECT_EQ(axom::utilities::trailingZeros(val),
axom::utilities::trailingZeros(val2));
}
Expand All @@ -62,7 +62,7 @@ TEST(core_bit_utilities, trailingZeroes)
// Test trailing zeros on some random numbers
for(int n = 0; n < NRAND_SAMPLES; ++n)
{
axom::uint64 rand_val = ::random_int<axom::uint64>();
std::uint64_t rand_val = ::random_int<std::uint64_t>();

// Explicitly find first bit and check that it matches
int bit = 0;
Expand All @@ -76,8 +76,8 @@ TEST(core_bit_utilities, trailingZeroes)

TEST(core_bit_utilities, popCount)
{
constexpr axom::uint64 ZERO = axom::uint64(0);
constexpr int BITS = axom::utilities::BitTraits<axom::uint64>::BITS_PER_WORD;
constexpr std::uint64_t ZERO = std::uint64_t(0);
constexpr int BITS = axom::utilities::BitTraits<std::uint64_t>::BITS_PER_WORD;
ASSERT_EQ(64, BITS);

// Test pop count when zero bits are set
Expand All @@ -89,7 +89,7 @@ TEST(core_bit_utilities, popCount)
// Test pop count when one bit is set
for(int i = 0; i < BITS; ++i)
{
axom::uint64 val = ::shifted(i);
std::uint64_t val = ::shifted(i);
EXPECT_EQ(1, axom::utilities::popCount(val));
EXPECT_EQ(BITS - 1, axom::utilities::popCount(~val));
}
Expand All @@ -99,7 +99,7 @@ TEST(core_bit_utilities, popCount)
{
for(int j = 0; j < i; ++j)
{
axom::uint64 val = shifted(i) + shifted(j);
std::uint64_t val = shifted(i) + shifted(j);
EXPECT_EQ(2, axom::utilities::popCount(val));
EXPECT_EQ(BITS - 2, axom::utilities::popCount(~val));
}
Expand All @@ -112,7 +112,7 @@ TEST(core_bit_utilities, popCount)
{
for(int k = 0; k < j; ++k)
{
axom::uint64 val = shifted(i) + shifted(j) + shifted(k);
std::uint64_t val = shifted(i) + shifted(j) + shifted(k);
EXPECT_EQ(3, axom::utilities::popCount(val));
EXPECT_EQ(BITS - 3, axom::utilities::popCount(~val));
}
Expand All @@ -122,7 +122,7 @@ TEST(core_bit_utilities, popCount)
// Test pop count on some random numbers
for(int n = 0; n < NRAND_SAMPLES; ++n)
{
auto val = ::random_int<axom::uint64>();
auto val = ::random_int<std::uint64_t>();

int bits = 0;
for(int i = 0; i < BITS; ++i)
Expand All @@ -136,22 +136,22 @@ TEST(core_bit_utilities, popCount)

TEST(core_bit_utilities, leadingZeros)
{
constexpr axom::int32 ZERO = axom::int32(0);
constexpr int BITS = axom::utilities::BitTraits<axom::uint32>::BITS_PER_WORD;
constexpr std::int32_t ZERO = std::int32_t(0);
constexpr int BITS = axom::utilities::BitTraits<std::uint32_t>::BITS_PER_WORD;
ASSERT_EQ(32, BITS);

// Axom's leadingZeros will return 32 when given 0
EXPECT_EQ(BITS, axom::utilities::leadingZeros(ZERO));

for(int i = 0; i < BITS; ++i)
{
axom::int32 val = ::shifted(i);
std::int32_t val = ::shifted(i);
EXPECT_EQ(BITS - i - 1, axom::utilities::leadingZeros(val));

// Value doesn't change if you set bits to right of leading zero
for(int j = 0; j < i; ++j)
{
axom::int32 val2 = ::shifted(i) + ::shifted(j);
std::int32_t val2 = ::shifted(i) + ::shifted(j);
EXPECT_EQ(axom::utilities::leadingZeros(val),
axom::utilities::leadingZeros(val2));
}
Expand All @@ -160,7 +160,7 @@ TEST(core_bit_utilities, leadingZeros)
// Test leading zeros on some random numbers
for(int n = 0; n < NRAND_SAMPLES; ++n)
{
axom::int32 rand_val = ::random_int<axom::int32>();
std::int32_t rand_val = ::random_int<std::int32_t>();

// Explicitly find first bit and check that it matches
int bit = 0;
Expand Down
20 changes: 10 additions & 10 deletions src/axom/core/tests/core_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ TEST(core_types, check_int8)
constexpr int NUM_DIGITS = 7;
constexpr bool IS_SIGNED = true;

check_integral_type<axom::int8>(EXP_BYTES, IS_SIGNED, NUM_DIGITS, MPI_INT8_T);
check_integral_type<std::int8_t>(EXP_BYTES, IS_SIGNED, NUM_DIGITS, MPI_INT8_T);
}

//------------------------------------------------------------------------------
Expand All @@ -103,7 +103,7 @@ TEST(core_types, check_uint8)
constexpr int NUM_DIGITS = 8;
constexpr bool IS_SIGNED = false;

check_integral_type<axom::uint8>(EXP_BYTES, IS_SIGNED, NUM_DIGITS, MPI_UINT8_T);
check_integral_type<std::uint8_t>(EXP_BYTES, IS_SIGNED, NUM_DIGITS, MPI_UINT8_T);
}

//------------------------------------------------------------------------------
Expand All @@ -113,7 +113,7 @@ TEST(core_types, check_int16)
constexpr int NUM_DIGITS = 15;
constexpr bool IS_SIGNED = true;

check_integral_type<axom::int16>(EXP_BYTES, IS_SIGNED, NUM_DIGITS, MPI_INT16_T);
check_integral_type<std::int16_t>(EXP_BYTES, IS_SIGNED, NUM_DIGITS, MPI_INT16_T);
}

//------------------------------------------------------------------------------
Expand All @@ -123,7 +123,7 @@ TEST(core_types, check_uint16)
constexpr int NUM_DIGITS = 16;
constexpr bool IS_SIGNED = false;

check_integral_type<axom::uint16>(EXP_BYTES, IS_SIGNED, NUM_DIGITS, MPI_UINT16_T);
check_integral_type<std::uint16_t>(EXP_BYTES, IS_SIGNED, NUM_DIGITS, MPI_UINT16_T);
}

//------------------------------------------------------------------------------
Expand All @@ -133,7 +133,7 @@ TEST(core_types, check_int32)
constexpr int NUM_DIGITS = 31;
constexpr bool IS_SIGNED = true;

check_integral_type<axom::int32>(EXP_BYTES, IS_SIGNED, NUM_DIGITS, MPI_INT32_T);
check_integral_type<std::int32_t>(EXP_BYTES, IS_SIGNED, NUM_DIGITS, MPI_INT32_T);
}

//------------------------------------------------------------------------------
Expand All @@ -143,7 +143,7 @@ TEST(core_types, check_uint32)
constexpr int NUM_DIGITS = 32;
constexpr bool IS_SIGNED = false;

check_integral_type<axom::uint32>(EXP_BYTES, IS_SIGNED, NUM_DIGITS, MPI_UINT32_T);
check_integral_type<std::uint32_t>(EXP_BYTES, IS_SIGNED, NUM_DIGITS, MPI_UINT32_T);
}

#ifndef AXOM_NO_INT64_T
Expand All @@ -155,7 +155,7 @@ TEST(core_types, check_int64)
constexpr int NUM_DIGITS = 63;
constexpr bool IS_SIGNED = true;

check_integral_type<axom::int64>(EXP_BYTES, IS_SIGNED, NUM_DIGITS, MPI_INT64_T);
check_integral_type<std::int64_t>(EXP_BYTES, IS_SIGNED, NUM_DIGITS, MPI_INT64_T);
}

//------------------------------------------------------------------------------
Expand All @@ -165,7 +165,7 @@ TEST(core_types, check_uint64)
constexpr int NUM_DIGITS = 64;
constexpr bool IS_SIGNED = false;

check_integral_type<axom::uint64>(EXP_BYTES, IS_SIGNED, NUM_DIGITS, MPI_UINT64_T);
check_integral_type<std::uint64_t>(EXP_BYTES, IS_SIGNED, NUM_DIGITS, MPI_UINT64_T);
}

//------------------------------------------------------------------------------
Expand All @@ -191,7 +191,7 @@ TEST(core_types, check_indextype)

#ifdef AXOM_USE_64BIT_INDEXTYPE

constexpr bool is_int64 = std::is_same<axom::IndexType, axom::int64>::value;
constexpr bool is_int64 = std::is_same<axom::IndexType, std::int64_t>::value;
EXPECT_TRUE(is_int64);

constexpr std::size_t EXP_BYTES = 8;
Expand All @@ -202,7 +202,7 @@ TEST(core_types, check_indextype)
MPI_INT64_T);
#else

constexpr bool is_int32 = std::is_same<axom::IndexType, axom::int32>::value;
constexpr bool is_int32 = std::is_same<axom::IndexType, std::int32_t>::value;
EXPECT_TRUE(is_int32);

constexpr std::size_t EXP_BYTES = 4;
Expand Down

0 comments on commit 7059a36

Please sign in to comment.