Skip to content

Commit

Permalink
Add fastdivmod support for SYCL
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiqunZhang committed Feb 2, 2024
1 parent 1229ef4 commit 17ebf48
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions Src/Base/AMReX_Math.H
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,19 @@ constexpr T powi (T x) noexcept
}
}

#if defined(AMREX_INT128_SUPPORTED)
AMREX_GPU_DEVICE AMREX_FORCE_INLINE
std::uint64_t umulhi (std::uint64_t a, std::uint64_t b)
{
#if defined(AMREX_USE_CUDA) || defined(AMREX_USE_HIP)
return __umul64hi(a, b);
#else
auto tmp = amrex::UInt128_t(a) * amrex::UInt128_t(b);
return std::uint64_t(tmp >> 64);
#endif
}
#endif

/***************************************************************************************************
* Copyright (c) 2017 - 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
Expand Down Expand Up @@ -312,11 +325,11 @@ struct FastDivmodU64
AMREX_GPU_HOST_DEVICE
std::uint64_t divide (std::uint64_t dividend) const
{
#if defined(AMREX_INT128_SUPPORTED) && (defined(AMREX_USE_CUDA) || defined(AMREX_USE_HIP))
#if defined(AMREX_INT128_SUPPORTED)
AMREX_IF_ON_DEVICE((
auto x = dividend;
if (multiplier) {
x = __umul64hi(dividend + round_up, multiplier);
x = amrex::Math::umulhi(dividend + round_up, multiplier);
}
return (x >> shift_right);
))
Expand Down

0 comments on commit 17ebf48

Please sign in to comment.