This is an automated email from the ASF dual-hosted git repository.

tqchen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new 84fbd77468 [REFACTOR][RUNTIME] Phase out 
include/tvm/runtime/builtin_fp16.h (#19472)
84fbd77468 is described below

commit 84fbd77468f0cb69cd6e5a2f2c1161e37b9d1fe5
Author: Tianqi Chen <[email protected]>
AuthorDate: Wed Apr 29 13:22:36 2026 -0400

    [REFACTOR][RUNTIME] Phase out include/tvm/runtime/builtin_fp16.h (#19472)
    
    ## Summary
    
    `include/tvm/runtime/builtin_fp16.h` has been in the public include tree
    without serving a public-API purpose. The header declared fp16 ABI
    symbols (`__gnu_f2h_ieee`, `__gnu_h2f_ieee`, etc.) for compiler-side
    callers; `support/scalars.cc` was already phased out upstream, and this
    PR migrates the lone remaining caller
    (`src/relax/backend/contrib/cublas/codegen.cc`) to the 3rdparty inline
    header (`3rdparty/compiler-rt/builtin_fp16.h`, already on the CMake
    SYSTEM include path), then deletes the public header outright.
---
 include/tvm/runtime/builtin_fp16.h             | 39 --------------------------
 src/relax/backend/contrib/cublas/codegen.cc    |  5 ++--
 src/runtime/builtin_fp16.cc                    | 18 ++++++++++++
 src/runtime/contrib/random/mt_random_engine.cc |  3 +-
 4 files changed, 22 insertions(+), 43 deletions(-)

diff --git a/include/tvm/runtime/builtin_fp16.h 
b/include/tvm/runtime/builtin_fp16.h
deleted file mode 100644
index 30383df97a..0000000000
--- a/include/tvm/runtime/builtin_fp16.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/*!
- * \file builtin_fp16.h
- * \brief Functions for conversion between fp32 and fp16
- */
-#ifndef TVM_RUNTIME_BUILTIN_FP16_H_
-#define TVM_RUNTIME_BUILTIN_FP16_H_
-
-#include <tvm/runtime/base.h>
-
-#include <cstdint>
-
-extern "C" {
-TVM_RUNTIME_DLL uint16_t __gnu_f2h_ieee(float);
-TVM_RUNTIME_DLL float __gnu_h2f_ieee(uint16_t);
-TVM_RUNTIME_DLL uint16_t __truncsfhf2(float v);
-TVM_RUNTIME_DLL uint16_t __truncdfhf2(double v);
-TVM_RUNTIME_DLL float __extendhfsf2(uint16_t v);
-}
-
-#endif  // TVM_RUNTIME_BUILTIN_FP16_H_
diff --git a/src/relax/backend/contrib/cublas/codegen.cc 
b/src/relax/backend/contrib/cublas/codegen.cc
index 7e750e2ec8..2dc1518b56 100644
--- a/src/relax/backend/contrib/cublas/codegen.cc
+++ b/src/relax/backend/contrib/cublas/codegen.cc
@@ -21,9 +21,9 @@
  * \file src/relax/backend/contrib/cublas/codegen.cc
  * \brief Implementation of the CUBLAS JSON serializer.
  */
+#include <builtin_fp16.h>
 #include <tvm/ffi/reflection/registry.h>
 #include <tvm/ir/module.h>
-#include <tvm/runtime/builtin_fp16.h>
 
 #include <string>
 
@@ -86,7 +86,8 @@ class CublasJSONSerializer : public JSONSerializer {
         auto sinfo = Downcast<TensorStructInfo>(const_expr->struct_info_);
         float alpha = 1.0;
         if (sinfo->dtype == DataType::Float(16)) {
-          alpha = 
__gnu_h2f_ieee(static_cast<uint16_t*>(const_expr->data->data)[0]);
+          alpha = __extendXfYf2__<uint16_t, uint16_t, 10, float, uint32_t, 23>(
+              static_cast<uint16_t*>(const_expr->data->data)[0]);
         } else {
           TVM_FFI_ICHECK(sinfo->dtype == DataType::Float(32));
           alpha = static_cast<float*>(const_expr->data->data)[0];
diff --git a/src/runtime/builtin_fp16.cc b/src/runtime/builtin_fp16.cc
index 99797159bf..096bdadb26 100644
--- a/src/runtime/builtin_fp16.cc
+++ b/src/runtime/builtin_fp16.cc
@@ -20,6 +20,24 @@
 /*!
  * \file builtin_fp16.cc
  * \brief Functions for conversion between fp32 and fp16
+ *
+ * JIT-fallback rationale
+ * ----------------------
+ * This file exports TVM_RUNTIME_DLL symbols (__gnu_f2h_ieee, __gnu_h2f_ieee,
+ * __truncdfhf2) so that loaded/JIT-compiled modules can resolve fp16 ABI calls
+ * at load time.  In JIT and AOT-module-load scenarios the host process may not
+ * have libgcc or compiler-rt fp16 builtins linked in; TVM codegen emits calls
+ * to these symbols for fp16 ops, and without this fallback those calls would
+ * fail symbol resolution at load time on such platforms.
+ *
+ * The TVM_FFI_WEAK attribute means the OS dynamic linker prefers the 
platform's
+ * own compiler-rt symbols when they are present; TVM's copy only "wins" when 
no
+ * other implementation is linked into the process.
+ *
+ * The inline implementations are provided by
+ * 3rdparty/compiler-rt/builtin_fp16.h (included below as <builtin_fp16.h>,
+ * which is on the CMake SYSTEM include path).  This file is NOT a duplicate of
+ * that header -- it provides runtime symbol export, not inline-only usage.
  */
 #include <builtin_fp16.h>
 #include <tvm/runtime/base.h>
diff --git a/src/runtime/contrib/random/mt_random_engine.cc 
b/src/runtime/contrib/random/mt_random_engine.cc
index 506963df50..64c3ff66a7 100644
--- a/src/runtime/contrib/random/mt_random_engine.cc
+++ b/src/runtime/contrib/random/mt_random_engine.cc
@@ -21,6 +21,7 @@
  * \file random/mt_random_engine.cc
  * \brief mt19937 random engine
  */
+#include <builtin_fp16.h>
 #include <tvm/runtime/c_backend_api.h>
 #include <tvm/runtime/device_api.h>
 #include <tvm/runtime/logging.h>
@@ -31,8 +32,6 @@
 #include <random>
 #include <thread>
 
-#include "../3rdparty/compiler-rt/builtin_fp16.h"
-
 namespace tvm {
 namespace contrib {
 

Reply via email to