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 12, 23:30 UTC
[CI/Build] Fix broken build on Apple M1 (#28999)
Signed-off-by: Kan Zhu <j20120307@gmail.com>
j20120307 committed
Nov 19, 2025 at 03:07 UTC
bbc6c2f1e5bc856a9265dfa2b379ed1d242adc33
1 file changed
+18
csrc/cpu/utils.hpp
+18
@@ -6,6 +6,10 @@
6
#include <cstdint>
7
#include <unistd.h>
8
9
+#if defined(__APPLE__)
10
+ #include <sys/sysctl.h>
11
+#endif
12
+
13
#include "cpu_types.hpp"
14
15
namespace cpu_utils {
@@ -21,10 +25,12 @@ struct VecTypeTrait<float> {
25
using vec_t = vec_op::FP32Vec16;
26
};
27
28
+#if !defined(__aarch64__) || defined(ARM_BF16_SUPPORT)
29
template <>
30
struct VecTypeTrait<c10::BFloat16> {
31
using vec_t = vec_op::BF16Vec16;
32
};
33
+#endif
34
35
template <>
36
struct VecTypeTrait<c10::Half> {
@@ -44,9 +50,21 @@ struct Counter {
50
51
inline int64_t get_l2_size() {
52
static int64_t size = []() {
53
+#if defined(__APPLE__)
54
+ // macOS doesn't have _SC_LEVEL2_CACHE_SIZE. Use sysctlbyname.
55
+ int64_t l2_cache_size = 0;
56
+ size_t len = sizeof(l2_cache_size);
57
+ if (sysctlbyname("hw.l2cachesize", &l2_cache_size, &len, NULL, 0) == 0 &&
58
+ l2_cache_size > 0) {
59
+ return l2_cache_size >> 1; // use 50% of L2 cache
60
+ }
61
+ // Fallback if sysctlbyname fails
62
+ return 128LL * 1024 >> 1; // use 50% of 128KB
63
+#else
64
long l2_cache_size = sysconf(_SC_LEVEL2_CACHE_SIZE);
65
assert(l2_cache_size != -1);
66
return l2_cache_size >> 1; // use 50% of L2 cache
67
+#endif
68
}();
69
return size;
70
}