A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 13, 05:45 UTC
[CPU][Bugfix] Fix Apple Silicon M1 compilation failure (#28681)
Signed-off-by: mgoin <mgoin64@gmail.com>
Michael Goin committed
Nov 13, 2025 at 20:49 UTC
622e6106a9e3d64fb4927e3d9dc6e4f5289d174c
1 file changed
+28
csrc/cpu/cpu_attn_impl.hpp
+28
@@ -5,6 +5,10 @@
5
#include <type_traits>
6
#include <cstddef>
7
8
+#if defined(__APPLE__)
9
+ #include <sys/sysctl.h>
10
+#endif
11
+
12
#include "cpu_types.hpp"
13
#include "scratchpad_manager.h"
14
#include "cpu_attn_macros.h"
@@ -741,9 +745,21 @@ class AttentionScheduler {
745
746
static int64_t get_available_l2_size() {
747
static int64_t size = []() {
748
+#if defined(__APPLE__)
749
+ // macOS doesn't have _SC_LEVEL2_CACHE_SIZE. Use sysctlbyname.
750
+ int64_t l2_cache_size = 0;
751
+ size_t len = sizeof(l2_cache_size);
752
+ if (sysctlbyname("hw.l2cachesize", &l2_cache_size, &len, NULL, 0) == 0 &&
753
+ l2_cache_size > 0) {
754
+ return l2_cache_size >> 1; // use 50% of L2 cache
755
+ }
756
+ // Fallback if sysctlbyname fails
757
+ return 128 * 1024 >> 1; // use 50% of 128KB
758
+#else
759
long l2_cache_size = sysconf(_SC_LEVEL2_CACHE_SIZE);
760
TORCH_CHECK_NE(l2_cache_size, -1);
761
return l2_cache_size >> 1; // use 50% of L2 cache
762
+#endif
763
}();
764
return size;
765
}
@@ -816,10 +832,14 @@ struct VecTypeTrait<float> {
832
using vec_t = vec_op::FP32Vec16;
833
};
834
835
+// ARM only supports BF16 with ARMv8.6-A extension
836
+#if (defined(__aarch64__) && !defined(ARM_BF16_SUPPORT))
837
+#else
838
template <>
839
struct VecTypeTrait<c10::BFloat16> {
840
using vec_t = vec_op::BF16Vec16;
841
};
842
+#endif
843
844
#if !defined(__powerpc__)
845
template <>
@@ -1588,9 +1608,17 @@ class AttentionMainLoop {
1608
1609
if (use_sink) {
1610
alignas(64) float s_aux_fp32[16];
1611
+#if defined(__aarch64__) && !defined(ARM_BF16_SUPPORT)
1612
+ // ARM without native BF16 support: manual conversion
1613
+ for (int i = 0; i < 16; ++i) {
1614
+ s_aux_fp32[i] = static_cast<float>(curr_s_aux[i]);
1615
+ }
1616
+#else
1617
+ // All other platforms have BF16Vec16 available
1618
vec_op::BF16Vec16 vec_bf16(curr_s_aux);
1619
vec_op::FP32Vec16 vec_fp32(vec_bf16);
1620
vec_fp32.save(s_aux_fp32);
1621
+#endif
1622
1623
float* __restrict__ curr_sum_buffer = sum_buffer;
1624
float* __restrict__ curr_max_buffer = max_buffer;