feat: Migrate codebase from x86 AVX2 to ARM64 NEON#1
Open
Conversation
- Replace centos:6 base image with ubuntu:22.04 (ARM64 compatible) - Convert AVX2 intrinsics to ARM NEON equivalents in matrix_operations.cpp - Add architecture detection for portable builds (ARM64, x86-64, generic) - Use vfmaq_f64 (fused multiply-add) for better ARM64 performance - Add multi-arch Docker build support with TARGETARCH Intrinsic mappings: - _mm256_setzero_pd -> vdupq_n_f64(0.0) - _mm256_loadu_pd -> vld1q_f64 - _mm256_mul_pd + _mm256_add_pd -> vfmaq_f64 (FMA) - Horizontal sum via AVX extract -> vpaddd_f64 Tools used: migrate-ease-scan, skopeo, knowledge_base_search
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR migrates the matrix operations codebase from x86-only (AVX2) to support ARM64 (NEON) architecture, enabling deployment on ARM-based infrastructure like AWS Graviton, Ampere Altra, Azure Cobalt, and Apple Silicon.
Changes Made
1. Docker Configuration
centos:6(x86-only, EOL) withubuntu:22.04(multi-arch supported)TARGETARCHbuild argument for multi-architecture Docker builds-march=armv8-a+simdfor NEON SIMD-mavx2for AVX2 (unchanged)2. Code Changes
matrix_operations.cpp
_mm256_setzero_pd()vdupq_n_f64(0.0)_mm256_loadu_pd()vld1q_f64()_mm256_mul_pd() + _mm256_add_pd()vfmaq_f64()_mm256_extractf128_pd()+ horizontal addvpaddd_f64()main.cpp
#errorthat blocked non-x86 compilation3. Architecture Support
The code now supports three compilation modes:
__aarch64__): NEON SIMD (128-bit, 2 doubles)__x86_64__): AVX2 SIMD (256-bit, 4 doubles)Performance Predictions
ARM64 (NEON) vs x86 (AVX2)
vfmaq_f64fused multiply-add reduces instruction countExpected Performance
For 200x200 matrix multiplication:
Cost Savings (AWS)
Migrating from x86 to ARM (Graviton) typically provides:
Tools Used
migrate-ease-scan (cpp)skopeoknowledge_base_searchValidation Steps
Build Test (ARM64):
docker buildx build --platform linux/arm64 -t benchmark:arm64 .Build Test (x86-64):
docker buildx build --platform linux/amd64 -t benchmark:amd64 .Multi-arch Build:
docker buildx build --platform linux/amd64,linux/arm64 -t benchmark:multi .Runtime Verification:
docker run --rm benchmark:arm64 # Should output: "Running on ARM64 architecture with NEON optimizations"Migration Scan Results
Breaking Changes
None - the code maintains full backward compatibility with x86-64 systems.
Future Enhancements