-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Patch fp16 to fix Xcode 16 builds with XNNPACK EP targeting x86_64. (#…
- Loading branch information
Showing
4 changed files
with
121 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# remove_math_h_dependency_from_fp16_h.patch | ||
|
||
Remove dependency on math.h (with fabsf()) to work around Xcode 16 build error for iphonesimulator x86_64 target: | ||
|
||
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/math.h:614:27: error: | ||
_Float16 is not supported on this target | ||
614 | extern _Float16 __fabsf16(_Float16) __API_AVAILABLE(macos(15.0), ios(18.0), watchos(11.0), tvos(18.0)); | ||
| | ||
|
||
This patch was adapted from this PR: https://github.com/Maratyszcza/FP16/pull/32 | ||
See also: https://github.com/google/XNNPACK/issues/6989 |
29 changes: 29 additions & 0 deletions
29
cmake/patches/fp16/remove_math_h_dependency_from_fp16_h.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
diff --git a/include/fp16/fp16.h b/include/fp16/fp16.h | ||
index 2b61fff..1947805 100644 | ||
--- a/include/fp16/fp16.h | ||
+++ b/include/fp16/fp16.h | ||
@@ -4,10 +4,8 @@ | ||
|
||
#if defined(__cplusplus) && (__cplusplus >= 201103L) | ||
#include <cstdint> | ||
- #include <cmath> | ||
#elif !defined(__OPENCL_VERSION__) | ||
#include <stdint.h> | ||
- #include <math.h> | ||
#endif | ||
|
||
#ifdef _MSC_VER | ||
@@ -228,9 +226,11 @@ static inline uint16_t fp16_ieee_from_fp32_value(float f) { | ||
const float scale_to_inf = fp32_from_bits(UINT32_C(0x77800000)); | ||
const float scale_to_zero = fp32_from_bits(UINT32_C(0x08800000)); | ||
#endif | ||
- float base = (fabsf(f) * scale_to_inf) * scale_to_zero; | ||
- | ||
const uint32_t w = fp32_to_bits(f); | ||
+ const float abs_f = fp32_from_bits(w & UINT32_C(0x7FFFFFFF)); | ||
+ | ||
+ float base = (abs_f * scale_to_inf) * scale_to_zero; | ||
+ | ||
const uint32_t shl1_w = w + w; | ||
const uint32_t sign = w & UINT32_C(0x80000000); | ||
uint32_t bias = shl1_w & UINT32_C(0xFF000000); |