Skip to content

Commit dce6ad6

Browse files
authored
Update 3-understand-the-demo.md
1 parent f179bc6 commit dce6ad6

1 file changed

Lines changed: 35 additions & 18 deletions

File tree

content/learning-paths/servers-and-cloud-computing/docker-mcp-toolkit/3-understand-the-demo.md

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,25 @@ layout: learningpathall
88

99
## Clone the demo repository
1010

11-
The demo application is a matrix multiplication benchmark written in C++ with AVX2 intrinsics. Clone it:
12-
11+
The demo application is a matrix multiplication benchmark written in C++ using AVX2 intrinsics for vectorized performance on x86 processors.
12+
Clone the repository:
1313
```bash
1414
git clone https://github.com/JoeStech/docker-blog-arm-migration
1515
cd docker-blog-arm-migration
1616
```
17+
This example is intentionally optimized for x86 so that you can see how architecture-specific code appears in practice and how it can be adapted for Arm.
1718

1819
## Examine the Dockerfile
1920

20-
Open the `Dockerfile`. There are two immediate blockers for Arm migration:
21+
Open the `Dockerfile`. There are two areas that require updates for Arm compatibility.
22+
23+
**Add Arm64 support in the base image**: The centos:6 image was published for x86 architecture and does not provide a `linux/arm64` variant. To run on Arm hardware, the base image must support Arm64.
2124

22-
**No Arm64 support in the base image**: The `centos:6` image was built for x86 only. This container will not start on Arm hardware.
25+
Modern multi-architecture base images typically publish both `linux/amd64` and `linux/arm64` manifests. Updating the base image is the first step toward portability.
2326

24-
**x86-specific compiler flag**: The `-mavx2` flag tells the compiler to use AVX2 vector instructions, which do not exist on Arm processors.
27+
**Update compiler flags**: The `-mavx2` flag enables AVX2 vector instructions on x86. Arm processors use different SIMD instruction sets (NEON or SVE), so this flag must be removed or replaced when compiling for Arm.
2528

29+
Here is the full Dockerfile for reference:
2630
```dockerfile
2731
FROM centos:6
2832

@@ -45,12 +49,15 @@ CMD ["./benchmark"]
4549
```
4650

4751
## Examine the source code
48-
49-
Open `matrix_operations.cpp`. The code uses x86 AVX2 intrinsics throughout:
52+
Open `matrix_operations.cpp`. At the top of the file:
5053

5154
```cpp
5255
#include <immintrin.h> // x86-only header
56+
```
57+
The <immintrin.h> header provides Intel SIMD intrinsics, including AVX and AVX2. On Arm systems, SIMD intrinsics are provided through <arm_neon.h> instead.
5358

59+
Inside the matrix multiplication routine, you will see AVX2 intrinsics such as:
60+
```cpp
5461
// Inside the multiply function:
5562
__m256d sum_vec = _mm256_setzero_pd();
5663
__m256d a_vec = _mm256_loadu_pd(&data[i][k]);
@@ -60,27 +67,37 @@ sum_vec = _mm256_add_pd(sum_vec, _mm256_mul_pd(a_vec, b_vec));
6067
__m128d sum_high = _mm256_extractf128_pd(sum_vec, 1);
6168
__m128d sum_low = _mm256_castpd256_pd128(sum_vec);
6269
```
70+
These _mm256_* functions map directly to 256-bit AVX2 instructions.
6371

64-
## Why this code cannot run on Arm
72+
## Architecture considerations for Arm
6573

66-
There are several specific blockers:
74+
To run this code on Arm, several adjustments are required:
6775

68-
1. **x86-exclusive header**: `#include <immintrin.h>` only exists on x86 systems. Arm uses `<arm_neon.h>` instead.
76+
1. **SIMD header replacement**: x86 uses `#include <immintrin.h>`. Arm uses `<arm_neon.h>` instead.
6977

70-
2. **AVX2 intrinsics throughout**: Every `_mm256_*` function is Intel-specific:
71-
- `_mm256_setzero_pd()` creates a 256-bit zero vector (Arm NEON is 128-bit).
78+
2. **Intrinsic mapping**: Each AVX2 intrinsic must be mapped to an Arm equivalent.
79+
For example:
80+
- `_mm256_setzero_pd()` creates a 256-bit zero vector of four doubles(Arm NEON is 128-bit).
7281
- `_mm256_loadu_pd()` loads 4 doubles at once (NEON loads 2 with `vld1q_f64`).
7382
- `_mm256_add_pd()` and `_mm256_mul_pd()` are 256-bit operations (NEON uses 128-bit equivalents).
7483
- `_mm256_extractf128_pd()` extracts the high 128 bits (not needed on NEON).
7584

76-
3. **Vector width mismatch**: AVX2 processes 4 doubles per operation. Arm NEON processes 2 doubles per operation. The entire loop structure needs adjustment.
85+
4. **Vector width differences**: AVX2 operates on 256-bit registers (four double-precision values). NEON operates on 128-bit registers (two double-precision values). This affects:
86+
- Loop stride
87+
- Accumulation logic
88+
- Horizontal reduction patterns
7789

78-
{{% notice Note %}}
79-
SVE/SVE2 on newer Arm cores (Neoverse V1/V2, Graviton 3/4) provides 256-bit or wider vector-length agnostic (VLA) registers, matching or exceeding AVX2 width. The Arm MCP Server knowledge base can help determine the best approach for your target hardware.
80-
{{% /notice %}}
90+
4. **Horizontal reduction logic**: The AVX2 pattern:
8191

82-
4. **Horizontal reduction logic**: The pattern using `_mm256_extractf128_pd` and `_mm256_castpd256_pd128` is x86-specific and must be completely rewritten.
92+
```cpp
93+
_mm256_extractf128_pd(...)
94+
_mm256_castpd256_pd128(...)
95+
```
96+
is specific to x86 register structure. On Arm, reduction is implemented using NEON reduction or pairwise-add instructions instead.
8397
84-
Manual conversion requires rewriting 30+ lines of intrinsic code, adjusting loop strides, and testing numerical accuracy. This is exactly where the Docker MCP Toolkit with the Arm MCP Server becomes essential.
98+
{{% notice Note %}}
99+
On newer Arm platforms supporting SVE or SVE2 (for example Neoverse V1/V2 based platforms), wider vector lengths may be available. SVE uses a vector-length-agnostic (VLA) model, which differs from fixed-width AVX2 and NEON programming. The Arm MCP Server knowledge base can help determine the appropriate approach for your target platform.
100+
{{% /notice %}}
85101
102+
In the next section, you will use GitHub Copilot together with the Docker MCP Toolkit to analyze these elements automatically and generate Arm-compatible updates.
86103
In the next section, you will use GitHub Copilot with the Docker MCP Toolkit to automate the entire migration.

0 commit comments

Comments
 (0)