|
| 1 | +--- |
| 2 | +title: Run the AI-driven Arm migration |
| 3 | +weight: 5 |
| 4 | + |
| 5 | +### FIXED, DO NOT MODIFY |
| 6 | +layout: learningpathall |
| 7 | +--- |
| 8 | + |
| 9 | +## Open the project in VS Code |
| 10 | + |
| 11 | +Open the cloned `docker-blog-arm-migration` directory in VS Code: |
| 12 | + |
| 13 | +```bash |
| 14 | +cd docker-blog-arm-migration |
| 15 | +code . |
| 16 | +``` |
| 17 | + |
| 18 | +Make sure the MCP_DOCKER server is running in VS Code (check **Extensions** > **MCP_DOCKER** > **Start Server** if needed). |
| 19 | + |
| 20 | +## Give GitHub Copilot migration instructions |
| 21 | + |
| 22 | +Open GitHub Copilot Chat in VS Code and paste the following prompt: |
| 23 | + |
| 24 | +```text |
| 25 | +Your goal is to migrate this codebase from x86 to Arm64. Use the Arm MCP |
| 26 | +Server tools to help you with this migration. |
| 27 | +
|
| 28 | +Steps to follow: |
| 29 | +1. Check all Dockerfiles - use check_image and/or skopeo tools to verify |
| 30 | + Arm compatibility, changing the base image if necessary |
| 31 | +2. Scan the codebase - run migrate_ease_scan with the appropriate language |
| 32 | + scanner and apply the suggested changes |
| 33 | +3. Use knowledge_base_search when you need Arm architecture guidance or |
| 34 | + intrinsic equivalents |
| 35 | +4. Update compiler flags and dependencies for Arm64 compatibility |
| 36 | +5. Create a pull request with all changes using GitHub MCP Server |
| 37 | +
|
| 38 | +Important notes: |
| 39 | +- Your current working directory is mapped to /workspace on the MCP server |
| 40 | +- NEON lane indices must be compile-time constants, not variables |
| 41 | +- If unsure about Arm equivalents, use knowledge_base_search to find docs |
| 42 | +- Be sure to find out from the user or system what the target machine is, |
| 43 | + and use the appropriate intrinsics. For instance, if neoverse (Graviton, |
| 44 | + Axion, Cobalt) is targeted, use the latest SME/SME2. |
| 45 | +
|
| 46 | +After completing the migration: |
| 47 | +- Create a pull request with a detailed description of changes |
| 48 | +- Include performance predictions and cost savings in the PR description |
| 49 | +- List all tools used and validation steps needed |
| 50 | +``` |
| 51 | + |
| 52 | +## Watch the migration execute |
| 53 | + |
| 54 | +GitHub Copilot orchestrates the migration through four phases using the Docker MCP Toolkit. |
| 55 | + |
| 56 | +### Phase 1: Image analysis |
| 57 | + |
| 58 | +Copilot uses the `skopeo` tool from the Arm MCP Server to analyze the base image: |
| 59 | + |
| 60 | +```text |
| 61 | +Checking centos:6 for arm64 support... |
| 62 | +``` |
| 63 | + |
| 64 | +The tool reports that `centos:6` has no `linux/arm64` build available. This is the first blocker identified. Copilot determines that the base image must be replaced. |
| 65 | + |
| 66 | +### Phase 2: Code scanning |
| 67 | + |
| 68 | +Copilot runs the `migrate_ease_scan` tool with the C++ scanner: |
| 69 | + |
| 70 | +```text |
| 71 | +Running migrate_ease_scan with scanner: cpp |
| 72 | +``` |
| 73 | + |
| 74 | +The scan detects: |
| 75 | + |
| 76 | +- AVX2 intrinsics (`_mm256_*` functions) in `matrix_operations.cpp`. |
| 77 | +- The `-mavx2` compiler flag in the Dockerfile. |
| 78 | +- The x86-specific header `<immintrin.h>`. |
| 79 | + |
| 80 | +Each issue includes the file location, line number, and specific code requiring modification. |
| 81 | + |
| 82 | +### Phase 3: Knowledge base lookup and code conversion |
| 83 | + |
| 84 | +For each x86 intrinsic found, Copilot queries the Arm MCP Server knowledge base: |
| 85 | + |
| 86 | +```text |
| 87 | +Searching knowledge base for: AVX2 to NEON intrinsic conversion |
| 88 | +``` |
| 89 | + |
| 90 | +The knowledge base returns Arm documentation with the conversions: |
| 91 | + |
| 92 | +| x86 AVX2 Intrinsic | Arm NEON Equivalent | |
| 93 | +|---------------------|---------------------| |
| 94 | +| `_mm256_setzero_pd()` | Two `vdupq_n_f64(0.0)` operations | |
| 95 | +| `_mm256_loadu_pd()` | Two `vld1q_f64()` loads | |
| 96 | +| `_mm256_add_pd()` | Two `vaddq_f64()` operations | |
| 97 | +| `_mm256_mul_pd()` | Two `vmulq_f64()` operations | |
| 98 | + |
| 99 | +The knowledge base also explains that AVX2 uses 256-bit vectors processing 4 doubles at once, while NEON uses 128-bit vectors processing 2 doubles. Loop strides must be adjusted accordingly. |
| 100 | + |
| 101 | +Copilot rewrites the code using this information: |
| 102 | + |
| 103 | +- Replaces `<immintrin.h>` with `<arm_neon.h>` inside `#ifdef __aarch64__` guards. |
| 104 | +- Converts the AVX2 loop structure (stride 4) to NEON (stride 2). |
| 105 | +- Rewrites the horizontal reduction for NEON. |
| 106 | +- Updates the Dockerfile to use `ubuntu:22.04` with `TARGETARCH` for multi-arch builds. |
| 107 | +- Changes the compiler flag from `-mavx2` to `-march=armv8-a+simd`. |
| 108 | + |
| 109 | +### Phase 4: Create the pull request |
| 110 | + |
| 111 | +Copilot uses the GitHub MCP Server to create a pull request with: |
| 112 | + |
| 113 | +- All code changes (source files and Dockerfile). |
| 114 | +- A detailed description of what was changed and why. |
| 115 | +- Performance predictions for Arm. |
| 116 | +- A list of all MCP tools used during the migration. |
| 117 | + |
| 118 | +You can see an example PR at [github.com/JoeStech/docker-blog-arm-migration/pull/1](https://github.com/JoeStech/docker-blog-arm-migration/pull/1). |
| 119 | + |
| 120 | +## Summary of changes |
| 121 | + |
| 122 | +The migration produces these key changes: |
| 123 | + |
| 124 | +**Dockerfile**: |
| 125 | +- Replaced `centos:6` with `ubuntu:22.04`. |
| 126 | +- Added `TARGETARCH` for multi-architecture builds. |
| 127 | +- Changed `-mavx2` to `-march=armv8-a+simd` for Arm builds. |
| 128 | + |
| 129 | +**Source code**: |
| 130 | +- Added `#ifdef __aarch64__` architecture guards. |
| 131 | +- Replaced all `_mm256_*` AVX2 intrinsics with NEON equivalents (`vld1q_f64`, `vaddq_f64`, `vmulq_f64`). |
| 132 | +- Adjusted loop strides from 4 (AVX2) to 2 (NEON). |
| 133 | +- Rewrote horizontal reduction using NEON pair-wise addition. |
| 134 | + |
| 135 | +In the next section, you will build, test, and validate the migrated application on Arm. |
0 commit comments