Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compile warnings and refactor ftos_converter.cuh #1679

Merged
merged 3 commits into from
Jan 9, 2024

Conversation

thirtiseven
Copy link
Collaborator

Fixes #1678

Fix compile warnings in ftos_converter.cuh
Also do some refactoring according to comments from #1676

@thirtiseven thirtiseven self-assigned this Jan 5, 2024
@@ -461,7 +461,7 @@ __device__ inline uint32_t mulPow5divPow2(uint32_t const m, uint32_t const i, in

//===== d2s.c and f2s.c from ryu =====

__device__ inline uint32_t decimalLength17(uint64_t const v)
__device__ inline uint32_t decimalLength(uint64_t const v)
Copy link
Collaborator

@ttnghia ttnghia Jan 5, 2024

Choose a reason for hiding this comment

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

How about this? Combining both decimalLength functions into:

template<typename T>
__device inline uint32_t decimal_length(T const v) {
static_assert(std::is_integral_v<T> && !std::is_signed_v<T>);

if constexpr(sizeof(T) == sizeof(int64_t)) {
  // The average output length is 16.38 digits, so we check high-to-low.
  // Function precondition: v is not an 18, 19, or 20-digit number.
  // (17 digits are sufficient for round-tripping.)
 assert(v < 100000000000000000L);
 if (v >= 10000000000000000L) { return 17; }
  if (v >= 1000000000000000L) { return 16; }
  if (v >= 100000000000000L) { return 15; }
  if (v >= 10000000000000L) { return 14; }
  if (v >= 1000000000000L) { return 13; }
  if (v >= 100000000000L) { return 12; }
  if (v >= 10000000000L) { return 11; }
  if (v >= 1000000000L) { return 10; }
} else {
// Function precondition: v is not a 10-digit number.
  // (f2s: 9 digits are sufficient for round-tripping.)
  // (d2fixed: We print 9-digit blocks.)
  assert(v < 1000000000);
}

  if (v >= 100000000) { return 9; }
  if (v >= 10000000) { return 8; }
  if (v >= 1000000) { return 7; }
  if (v >= 100000) { return 6; }
  if (v >= 10000) { return 5; }
  if (v >= 1000) { return 4; }
  if (v >= 100) { return 3; }
  if (v >= 10) { return 2; }
  return 1;
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍 done

@@ -493,7 +493,7 @@ __device__ inline floating_decimal_64 d2d(uint64_t const ieeeMantissa, uint32_t
uint64_t m2;
if (ieeeExponent == 0) {
// We subtract 2 so that the bounds computation has 2 additional bits.
e2 = 1 - DOUBLE_BIAS - DOUBLE_MANTISSA_BITS - 2;
e2 = static_cast<int32_t>(1 - DOUBLE_BIAS - DOUBLE_MANTISSA_BITS - 2);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please also modify line 499 below, using static_cast instead of C-style cast.

Copy link
Collaborator

Choose a reason for hiding this comment

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

OMG, there are too many instances of such C-style cast :(

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Modified every C-style cast I found

* @param result: output string
* @param digits: number of digits after decimal point
*/
template <typename T, typename U>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since U depends on T, we can just remove it here, then:

__device__ to_formatted_chars(...) {
static_assert(std::is_same_v<T, floating_decimal_32> || std::is_same_v<T, floating_decimal_64>);
using U = std::conditional_t<std::is_same_v<T, floating_decimal_32>, uint32_t, uint64_t>;

Copy link
Collaborator

Choose a reason for hiding this comment

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

The same can be applied to the function format_size below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done.

thirtiseven and others added 2 commits January 8, 2024 09:40
Signed-off-by: Haoyang Li <[email protected]>
@thirtiseven
Copy link
Collaborator Author

build

@thirtiseven thirtiseven merged commit 4c6de74 into NVIDIA:branch-24.02 Jan 9, 2024
@thirtiseven thirtiseven deleted the format_float_fix2 branch January 9, 2024 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Compile warnings in ftos_converter.cuh
2 participants