Skip to content

Commit

Permalink
Use string literals in fixed_point release_asserts (#7303)
Browse files Browse the repository at this point in the history
`release_assert` is only happy with string literals, not `const car*` and not `std::string`. Solution is to remove `print_rep` and just use a string literal.

Authors:
  - Conor Hoekstra (@codereport)

Approvers:
  - Devavret Makkar (@devavret)
  - Paul Taylor (@trxcllnt)

URL: #7303
  • Loading branch information
codereport authored Feb 4, 2021
1 parent 08166d3 commit a8f0a9b
Showing 1 changed file with 8 additions and 26 deletions.
34 changes: 8 additions & 26 deletions cpp/include/cudf/fixed_point/fixed_point.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, NVIDIA CORPORATION.
* Copyright (c) 2020-2021, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,6 +25,7 @@
#include <cuda/std/type_traits> // add cuda namespace

#include <algorithm>
#include <cassert>
#include <cmath>
#include <string>

Expand Down Expand Up @@ -550,22 +551,6 @@ class fixed_point {
}
}; // namespace numeric

/** @brief Function that converts Rep to `std::string`
*
* @tparam Rep Representation type
* @return String-ified Rep
*/
template <typename Rep>
std::string print_rep()
{
if (cuda::std::is_same<Rep, int32_t>::value)
return "int32_t";
else if (cuda::std::is_same<Rep, int64_t>::value)
return "int64_t";
else
return "unknown type";
}

/** @brief Function for identifying integer overflow when adding
*
* @tparam Rep Type of integer to check for overflow on
Expand Down Expand Up @@ -641,8 +626,8 @@ CUDA_HOST_DEVICE_CALLABLE fixed_point<Rep1, Rad1> operator+(fixed_point<Rep1, Ra

#if defined(__CUDACC_DEBUG__)

release_assert(!addition_overflow<Rep1>(lhs.rescaled(scale)._value, rhs.rescaled(scale)._value) &&
"fixed_point overflow of underlying representation type " + print_rep<Rep1>());
assert(!addition_overflow<Rep1>(lhs.rescaled(scale)._value, rhs.rescaled(scale)._value) &&
"fixed_point overflow");

#endif

Expand All @@ -659,9 +644,8 @@ CUDA_HOST_DEVICE_CALLABLE fixed_point<Rep1, Rad1> operator-(fixed_point<Rep1, Ra

#if defined(__CUDACC_DEBUG__)

release_assert(
!subtraction_overflow<Rep1>(lhs.rescaled(scale)._value, rhs.rescaled(scale)._value) &&
"fixed_point overflow of underlying representation type " + print_rep<Rep1>());
assert(!subtraction_overflow<Rep1>(lhs.rescaled(scale)._value, rhs.rescaled(scale)._value) &&
"fixed_point overflow");

#endif

Expand All @@ -675,8 +659,7 @@ CUDA_HOST_DEVICE_CALLABLE fixed_point<Rep1, Rad1> operator*(fixed_point<Rep1, Ra
{
#if defined(__CUDACC_DEBUG__)

release_assert(!multiplication_overflow<Rep1>(lhs._value, rhs._value) &&
"fixed_point overflow of underlying representation type " + print_rep<Rep1>());
assert(!multiplication_overflow<Rep1>(lhs._value, rhs._value) && "fixed_point overflow");

#endif

Expand All @@ -691,8 +674,7 @@ CUDA_HOST_DEVICE_CALLABLE fixed_point<Rep1, Rad1> operator/(fixed_point<Rep1, Ra
{
#if defined(__CUDACC_DEBUG__)

release_assert(!division_overflow<Rep1>(lhs._value, rhs._value) &&
"fixed_point overflow of underlying representation type " + print_rep<Rep1>());
assert(!division_overflow<Rep1>(lhs._value, rhs._value) && "fixed_point overflow");

#endif

Expand Down

0 comments on commit a8f0a9b

Please sign in to comment.