-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] bun
should prefer bun-baseline
#879
Comments
It should auto-detect the CPU target instead of always choosing baseline. We have a bunch of SIMD optimizations that are disabled on the baseline build |
@Jarred-Sumner We don't yet have a standard method for detecting cpu-level features, but I have some ideas for how to implement it when I have time. |
Probably not 100% accurate, but here's a starter:
Explanation of CPU Feature Detection:
Additional Notes:
Drafts ScriptsPerhaps we could template out OS-specific functions for the webi script post-boostrap. #!/bin/sh
set -e
set -u
# Detect the OS
os="$(uname)"
detect_linux() {
if grep -q avx512 /proc/cpuinfo; then
echo "Detected AMDv4 (AVX-512)"
elif grep -q avx2 /proc/cpuinfo; then
echo "Detected AMDv3 (AVX2)"
elif grep -q avx /proc/cpuinfo; then
echo "Detected AMDv2 (AVX)"
else
echo "Unknown CPU features or unsupported CPU"
fi
}
detect_macos() {
features=$(sysctl -a 2>/dev/null | grep machdep.cpu.features)
if echo "$features" | grep -q AVX512F; then
echo "Detected AMDv4 (AVX-512)"
elif echo "$features" | grep -q AVX2.0; then
echo "Detected AMDv3 (AVX2)"
elif echo "$features" | grep -q AVX1.0; then
echo "Detected AMDv2 (AVX)"
else
echo "Unknown CPU features or unsupported CPU"
fi
}
detect_freebsd() {
features=$(dmesg | grep -i avx)
if echo "$features" | grep -q AVX512; then
echo "Detected AMDv4 (AVX-512)"
elif echo "$features" | grep -q AVX2; then
echo "Detected AMDv3 (AVX2)"
elif echo "$features" | grep -q AVX; then
echo "Detected AMDv2 (AVX)"
else
echo "Unknown CPU features or unsupported CPU"
fi
}
detect_openbsd() {
features=$(sysctl -a 2>/dev/null | grep hw.features)
if echo "$features" | grep -q AVX512; then
echo "Detected AMDv4 (AVX-512)"
elif echo "$features" | grep -q AVX2; then
echo "Detected AMDv3 (AVX2)"
elif echo "$features" | grep -q AVX; then
echo "Detected AMDv2 (AVX)"
else
echo "Unknown CPU features or unsupported CPU"
fi
}
detect_netbsd() {
features=$(cpuctl identify 0)
if echo "$features" | grep -q AVX512; then
echo "Detected AMDv4 (AVX-512)"
elif echo "$features" | grep -q AVX2; then
echo "Detected AMDv3 (AVX2)"
elif echo "$features" | grep -q AVX; then
echo "Detected AMDv2 (AVX)"
else
echo "Unknown CPU features or unsupported CPU"
fi
}
# Call the appropriate function based on OS
case "$os" in
Linux)
detect_linux
;;
Darwin)
detect_macos
;;
FreeBSD)
detect_freebsd
;;
OpenBSD)
detect_openbsd
;;
NetBSD)
detect_netbsd
;;
*)
echo "Unsupported OS: $os"
exit 1
;;
esac # Detect CPU features on Windows: AVX, AVX2, AVX-512
# Run WMIC command to get CPU capabilities
$cpuInfo = wmic cpu get Caption
# Check for AVX, AVX2, AVX-512 support
$avx = $cpuInfo -match "AVX"
$avx2 = $cpuInfo -match "AVX2"
$avx512 = $cpuInfo -match "AVX-512"
# Determine which AMDv version is supported
if ($avx512) {
Write-Host "Detected AMDv4 (AVX-512)"
} elseif ($avx2) {
Write-Host "Detected AMDv3 (AVX2)"
} elseif ($avx) {
Write-Host "Detected AMDv2 (AVX)"
} else {
Write-Host "Unknown CPU features or unsupported CPU"
} |
linux
(vm, container, NOT desktop)macos
windows
Containers often play to the lowest common denominator for CPU virtualization. That leads to this:
We either need to either figure out what specific CPU features pertain to "profile" vs "" vs "baseline" and detect them, or just serve baseline, for Linux at least.
Update here's how we find out:
cat /proc/cpuinfo | grep avx2
More: oven-sh/bun#7607 (comment)
The text was updated successfully, but these errors were encountered: