[libc-commits] [PATCH] D152923: [libc] Add support for FMA in the GPU utilities

Joseph Huber via Phabricator via libc-commits libc-commits at lists.llvm.org
Wed Jun 14 10:59:45 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rGf205fbbb011e: [libc] Add support for FMA in the GPU utilities (authored by jhuber6).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152923/new/

https://reviews.llvm.org/D152923

Files:
  libc/config/gpu/entrypoints.txt
  libc/src/__support/FPUtil/FMA.h
  libc/src/__support/FPUtil/gpu/FMA.h
  libc/src/__support/macros/properties/cpu_features.h


Index: libc/src/__support/macros/properties/cpu_features.h
===================================================================
--- libc/src/__support/macros/properties/cpu_features.h
+++ libc/src/__support/macros/properties/cpu_features.h
@@ -37,7 +37,7 @@
 #endif
 
 #if defined(__ARM_FEATURE_FMA) || (defined(__AVX2__) && defined(__FMA__)) ||   \
-    defined(__LIBC_RISCV_USE_FMA)
+    defined(__NVPTX__) || defined(__AMDGPU__) || defined(__LIBC_RISCV_USE_FMA)
 #define LIBC_TARGET_CPU_HAS_FMA
 #endif
 
Index: libc/src/__support/FPUtil/gpu/FMA.h
===================================================================
--- /dev/null
+++ libc/src/__support/FPUtil/gpu/FMA.h
@@ -0,0 +1,33 @@
+//===-- GPU implementations of the fma function -----------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_GPU_FMA_H
+#define LLVM_LIBC_SRC_SUPPORT_FPUTIL_GPU_FMA_H
+
+// These intrinsics map to the FMA instrunctions in the target ISA for the GPU.
+// The default rounding mode generated from these will be to the nearest even.
+static_assert(__has_builtin(__builtin_fma), "FMA builtins must be defined");
+static_assert(__has_builtin(__builtin_fmaf), "FMA builtins must be defined");
+
+namespace __llvm_libc {
+namespace fputil {
+
+template <typename T>
+LIBC_INLINE cpp::enable_if_t<cpp::is_same_v<T, float>, T> fma(T x, T y, T z) {
+  __builtin_fmaf(x, y, z);
+}
+
+template <typename T>
+LIBC_INLINE cpp::enable_if_t<cpp::is_same_v<T, double>, T> fma(T x, T y, T z) {
+  __builtin_fma(x, y, z);
+}
+
+} // namespace fputil
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_SUPPORT_FPUTIL_GPU_FMA_H
Index: libc/src/__support/FPUtil/FMA.h
===================================================================
--- libc/src/__support/FPUtil/FMA.h
+++ libc/src/__support/FPUtil/FMA.h
@@ -20,6 +20,8 @@
 #include "aarch64/FMA.h"
 #elif defined(LIBC_TARGET_ARCH_IS_RISCV64)
 #include "riscv64/FMA.h"
+#elif defined(LIBC_TARGET_ARCH_IS_GPU)
+#include "gpu/FMA.h"
 #endif
 
 #else
Index: libc/config/gpu/entrypoints.txt
===================================================================
--- libc/config/gpu/entrypoints.txt
+++ libc/config/gpu/entrypoints.txt
@@ -83,6 +83,8 @@
 
 set(TARGET_LIBM_ENTRYPOINTS
     # math.h entrypoints
+    libc.src.math.fma
+    libc.src.math.fmaf
     libc.src.math.sin
     libc.src.math.round
     libc.src.math.roundf


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152923.531430.patch
Type: text/x-patch
Size: 2654 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230614/9e078263/attachment.bin>


More information about the libc-commits mailing list