We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
libcu++
The following patterns are very common:
floor(a / b) * b
ceil(a / b) * b
Introduce two functions to compute round up/down to a given multiple
template<typename T> //HOST_DEVICE_NODISCARD constexpr T round_up_to_multiple(T value, T mul) { static_assert(::cuda::is_integral<T>::value); //ASSERT_OR_ASSUME(value >= 0) //ASSERT_OR_ASSUME(mul > 0) auto cdiv = ceil_div(value, mul); //ASSERT(!is_mul_overflow(cdiv, mul)) using U = ::cuda::std::__make_unsigned_t<T>; auto mul1 = static_cast<U>(mul); // for optimization purposes auto ret = static_cast<T>(cdiv * mul1); //ASSERT_OR_ASSUME(ret >= value) return ret; }
template<typename T> //HOST_DEVICE_NODISCARD constexpr T round_down_to_multiple(T value, T mul) { static_assert(::cuda::is_integral<T>::value); //ASSERT_OR_ASSUME(value >= 0) //ASSERT_OR_ASSUME(mul > 0) //ASSERT_OR_ASSUME(mul <= value) using U = ::cuda::std::__make_unsigned_t<T>; auto value1 = static_cast<U>(value); // for optimization purposes auto mul1 = static_cast<U>(mul); // for optimization purposes auto ret = static_cast<T>((value1 / mul1) * mul1); //ASSERT_OR_ASSUME(ret >= value - mul) return ret; }
round_up_to_multiple(T, U); round_down_to_multiple(T, U);
#1517 #2375
The text was updated successfully, but these errors were encountered:
@bernhardmgruber @pauleonix for visibility
Sorry, something went wrong.
Thx a lot for these suggestion! I would love to see those in libcu++!
fbusato
Successfully merging a pull request may close this issue.
Is this a duplicate?
Area
libcu++
Is your feature request related to a problem? Please describe.
The following patterns are very common:
floor(a / b) * b
ceil(a / b) * b
Introduce two functions to compute round up/down to a given multiple
Describe the solution you'd like
Describe alternatives you've considered
Additional context
#1517
#2375
The text was updated successfully, but these errors were encountered: