[all-commits] [llvm/llvm-project] 7d057e: [CUDA] Work around a bug in rint/nearbyint caused ...

Artem Belevich via All-commits all-commits at lists.llvm.org
Wed Aug 5 13:14:45 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 7d057efddc00ba7d03e6e684f23dd9b09fbd0527
      https://github.com/llvm/llvm-project/commit/7d057efddc00ba7d03e6e684f23dd9b09fbd0527
  Author: Artem Belevich <tra at google.com>
  Date:   2020-08-05 (Wed, 05 Aug 2020)

  Changed paths:
    M clang/lib/Headers/__clang_cuda_math.h

  Log Message:
  -----------
  [CUDA] Work around a bug in rint/nearbyint caused by a broken implementation provided by CUDA.

Normally math functions are forwarded to __nv_* counterparts provided by CUDA's
libdevice bitcode. However, __nv_rint*()/__nv_nearbyint*() functions there have
a bug -- they use round() which rounds *up* instead of rounding towards the
nearest integer, so we end up with rint(2.5f) producing 3.0 instead of expected
2.0. The broken bitcode is not actually used by NVCC itself, which has both a
work-around in CUDA headers and, in recent versions, uses correct
implementations in NVCC's built-ins.

This patch implements equivalent workaround and directs rint*/nearbyint* to
__builtin_* variants that produce correct results.

Differential Revision: https://reviews.llvm.org/D85236




More information about the All-commits mailing list