You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/learning-paths/servers-and-cloud-computing/cplusplus_compilers_flags/1.md
+24-19Lines changed: 24 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,20 @@
1
1
---
2
-
title: Basics of Compilers
2
+
title: Compiler basics
3
3
weight: 2
4
4
5
5
### FIXED, DO NOT MODIFY
6
6
layout: learningpathall
7
7
---
8
8
9
-
## Introduction to C++ and Compilers
9
+
## Introduction to C++ and compilers
10
10
11
-
The C++ language gives the programmer the freedom to be expressive in the way they write code - allowing low-level manipulation of memory and data structures. Compared to managed languages, such as Java, C++ source code is generally less portable, requiring recompilation to the target Arm architecture. In the context of optimizing C++ workloads on Arm, significant performance improvements can be achieved without modifying the source code, simply by using the compiler correctly.
11
+
The C++ language gives you the freedom to be expressive in the way you write code - allowing low-level manipulation of memory and data structures. Compared to managed languages, such as Java, C++ source code is generally less portable, requiring recompilation to the target Arm architecture. In the context of optimizing C++ workloads on Arm, significant performance improvements can be achieved without modifying the source code, simply by using the compiler correctly.
12
12
13
-
Writing performant C++ code is a topic in itself and out of scope for this learning path. Instead we will focus on how to effectively use the compiler to target Arm instances in a cloud environment.
13
+
Writing performant C++ code is a complex topic, but you can learn how to effectively use the compiler to target the Arm architecture for a Linux application.
14
14
15
-
## Purpose of a Compiler
15
+
## What is the purpose of a compiler?
16
16
17
-
The g++ compiler is part of the GNU Compiler Collection (GCC), which is a set of compilers for various programming languages, including C++. The primary objective of the g++ compiler is to translate C++ source code into machine code that can be executed by a computer. This process involves several high-level stages:
17
+
The G++ compiler is part of the GNU Compiler Collection (GCC), which is a set of compilers for various programming languages, including C++. The primary objective of the g++ compiler is to translate C++ source code into machine code that can be executed by a computer. This process involves several high-level stages:
18
18
19
19
- Preprocessing: In this initial stage, the preprocessor handles directives that start with a # symbol, such as `#include`, `#define`, and `#if`. It expands included header files, replaces macros, and processes conditional compilation statements.
20
20
@@ -24,19 +24,25 @@ The g++ compiler is part of the GNU Compiler Collection (GCC), which is a set of
24
24
25
25
- Linking: The final stage involves linking the object code with necessary libraries and other object files. The linker merges multiple object files and libraries, resolves external references, allocates memory addresses for functions and variables, and generates an executable file that can be run on the target platform.
26
26
27
-
An interesting fact about the g++ compiler is that it is designed to optimize both the performance and the size of the generated code. The compiler performs various optimizations based on the knowledge it has of the program, and it can be configured to prioritize reducing the size of the generated executable.
27
+
An interesting fact about the GNU compiler is that it is designed to optimize both the performance and the size of the generated code. The compiler performs various optimizations based on the knowledge it has of the program, and it can be configured to prioritize reducing the size of the generated executable.
28
28
29
+
### Compiler versions
29
30
30
-
### Compiler Versioning
31
+
Two popular compilers of C++ are the GNU Compiler Collection (GCC) and LLVM - both of which are open-source compilers and have contributions from Arm engineers to support the latest architectures. Proprietary or vendor-specific compilers, such as `nvcc` for compiling for NVIDIA GPUs, are often based on these open-source compilers. Alternative proprietary compilers are often designed for specific use cases. For example, safety-critical applications may need to comply with various ISO standards, which also include the compiler. The functional safety [Arm Compiler for Embedded](https://developer.arm.com/Tools%20and%20Software/Arm%20Compiler%20for%20Embedded%20FuSa) is an example of a C/C++ compiler.
31
32
32
-
Two popular compilers of C++ are the GNU Compiler Collection (GCC) and LLVM - both of which are open-source compilers and have contributions from Arm engineers to support the latest architectures. Proprietary or vendor-specific compilers, such as `nvcc` for compiling for NVIDIA GPUs, are often based on these open-source compilers. Alternative proprietary compilers are often designed for specific use cases. For example, safety-critical applications may need to comply with various ISO standards, which also include the compiler. The functional safety [Arm Compiler for Embedded](https://developer.arm.com/Tools%20and%20Software/Arm%20Compiler%20for%20Embedded%20FuSa) is such an example of a C/C++ compiler.
33
+
If you are an application developer who is not working in the safety qualification domain, you can use the open-source GCC/G++ compiler.
33
34
34
-
Most application developers are not in this safety qualification domain so we will be using the open-source GCC/G++ compiler for this learning path.
35
+
There are multiple Linux distributions available to choose from. Each Linux distribution has a default compiler.
35
36
36
-
There are multiple Linux distribtions available to choose from. Each Linux distribution and operating system has a default compiler. For example after installing the default g++ on an `r8g` AWS instance, the default g++ compiler as of January 2025 is below.
37
+
Print the version information for your compiler:
37
38
38
-
```output
39
+
```bash
39
40
g++ --version
41
+
```
42
+
43
+
For example, after installing `g++` on Ubuntu 24.04, the default compiler as of January 2025 is shown below.
44
+
45
+
```output
40
46
g++ (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
41
47
Copyright (C) 2023 Free Software Foundation, Inc.
42
48
This is free software; see the source for copying conditions. There is NO
@@ -59,9 +65,9 @@ Red Hat EL8 | 8*, 9, 10 | 10
59
65
SUSE Linux ES15 | 7*, 9, 10 | 7
60
66
61
67
62
-
The biggest and most simple performance gain can be achieved by using the most recent compiler available. The most recent optimisations and support will be available through the latest compiler.
68
+
The easiest way to achieve a performance gain is by using the most recent compiler available. The most recent optimizations and support are available through the latest compiler.
63
69
64
-
Looking at the g++ documentation as an example, the most recent version of GCC available at the time of writing, version 14.2, has the following support and optimisations listed on their website [change note](https://gcc.gnu.org/gcc-14/changes.html).
70
+
Looking at the G++ documentation as an example, the most recent version of GCC, version 14.2, has the following support and optimizations listed in the [release notes](https://gcc.gnu.org/gcc-14/changes.html).
65
71
66
72
```output
67
73
A number of new CPUs are supported through the -mcpu and -mtune options (GCC identifiers in parentheses).
@@ -70,14 +76,13 @@ A number of new CPUs are supported through the -mcpu and -mtune options (GCC ide
70
76
- Arm Cortex-A720 (cortex-a720).
71
77
- Arm Cortex-X4 (cortex-x4).
72
78
- Microsoft Cobalt-100 (cobalt-100).
73
-
...
74
79
```
75
80
76
-
Sufficient due diligence should be taken when updating your C++ compiler because the process may reveal bugs in your source code. These bugs are often undefined behaviour caused by not adhering to the C++ standard. It is rare that the compiler itself will introduced a bug. However, in such events known bugs are made publicly available in the compiler documentation.
81
+
Sufficient due diligence should be taken when updating your C++ compiler because the process may reveal bugs in your source code. These bugs are often undefined behavior caused by not adhering to the C++ standard. It is rare that the compiler itself will introduced a bug. However, in such events known bugs are made publicly available in the compiler documentation.
77
82
78
-
## Basic g++ Optimisation Levels
83
+
## Basic G++ optimization levels
79
84
80
-
Using the g++ compiler as an example, the most course-grained dial you can adjust is the optimisation level, denoted with `-O<x>`. This adjusts a variety of lower-level optimsation flags at the expense of increased computation time, memory use and debuggability. When aggresive optimisation is used, the optimised binary may not show expected behaviour when hooked up to a debugger such as `gdb`. This is because the generated code may not match the original source code or program order, for example from loop unrolling and vectorisation.
85
+
Using the G++ compiler as an example, the most course-grained dial you can adjust is the optimization level, denoted with `-O<x>`. This adjusts a variety of lower-level optimization flags at the expense of increased computation time, memory use and debuggability. When aggressive optimization is used, the optimized binary may not show expected behavior when hooked up to a debugger such as `gdb`. This is because the generated code may not match the original source code or program order, for example from loop unrolling and vectorization.
81
86
82
87
A few of the most common optimization levels are in the table below.
83
88
@@ -90,4 +95,4 @@ A few of the most common optimization levels are in the table below.
90
95
|`-Os`| Optimizes code size, reducing the overall binary size. |
91
96
|`-Ofast`| Enables optimizations that may not strictly adhere to standard compliance. |
92
97
93
-
Please refer to your compiler documentation for full details on the optimisation level, for example [GCC](https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Optimize-Options.html).
98
+
Please refer to your compiler documentation for full details on the optimization level, for example you can review the G++ [Options That Control Optimization ](https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Optimize-Options.html).
Copy file name to clipboardExpand all lines: content/learning-paths/servers-and-cloud-computing/cplusplus_compilers_flags/2.md
+33-22Lines changed: 33 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,22 +1,26 @@
1
1
---
2
-
title: Setup Your Environment
2
+
title: Set up Your Environment
3
3
weight: 3
4
4
5
5
### FIXED, DO NOT MODIFY
6
6
layout: learningpathall
7
7
---
8
8
9
-
If you are new to cloud computing, please refer to our learning path on [Getting started with Servers and Cloud Computing](https://learn.arm.com/learning-paths/servers-and-cloud-computing/intro/).
9
+
If you are new to cloud computing, please refer to [Getting started with Servers and Cloud Computing](https://learn.arm.com/learning-paths/servers-and-cloud-computing/intro/). It provides an introduction to the Arm servers available from various cloud service providers.
10
10
11
-
## Connect to an AWS Arm-based Instance
11
+
## Connect to an AWS Arm-based instance
12
12
13
-
In this example we will be building and running our C++ application on an AWS Graviton 4 (`r8g.xlarge`) instance running Ubuntu 24.04 LTS. Once connected run the following commands to confirm the operating system and archiecture version.
13
+
In this example you will build and run a C++ application on an AWS Graviton 4 (`r8g.xlarge`) instance running Ubuntu 24.04 LTS.
14
+
15
+
Create the AWS instance using your AWS account. Connect to the instance using SSH or AWS Session Manager so you can enter shell commands.
16
+
17
+
Once connected, run the following commands to confirm the operating system and architecture.
14
18
15
19
```bash
16
20
cat /etc/*lsb*
17
21
```
18
22
19
-
You will see an output such as the following:
23
+
You see output similar to:
20
24
21
25
```output
22
26
DISTRIB_ID=Ubuntu
@@ -25,58 +29,65 @@ DISTRIB_CODENAME=noble
25
29
DISTRIB_DESCRIPTION="Ubuntu 24.04.1 LTS"
26
30
```
27
31
28
-
Next, we will confirm we are using a 64-bit Arm-based system using the following command
32
+
Next, confirm we are using a 64-bit Arm-based system using the following command
29
33
30
34
```bash
31
35
uname -m
32
36
```
33
37
34
-
You will see the following output.
38
+
You see the following output:
35
39
36
40
```output
37
41
aarch64
38
42
```
39
43
40
-
## Enable Environment modules
44
+
## Enable environment modules
45
+
46
+
Environment modules is a tool to quickly modify your shell configuration and environment variables. For this activity, it allows you to quickly switch between different compiler versions to demonstrate potential improvements.
41
47
42
-
Environment modules are a tool to quickly modify your shell configuration and environment variables. For this learning path, it allows us to quickly switch between different compiler versions to demonstrate potential improvements.
48
+
First, you need to install the environment modules package.
43
49
44
-
Install Environment Modules
50
+
In your terminal and run the following command:
45
51
46
-
First, you need to install the environment modules package. Open your terminal and run the following command:
47
-
```bash
48
-
sudo apt update
49
-
sudo apt install environment-modules
50
-
```
52
+
```bash
53
+
sudo apt update
54
+
sudo apt install environment-modules
55
+
```
51
56
52
-
Load environment modules after the package is installed.
57
+
Load environment modules after the package is installed:
53
58
54
59
```bash
55
60
sudo chmod 755 /usr/share/modules/init/bash
56
61
source /usr/share/modules/init/bash
57
62
```
58
-
Reload your shell configuration.
63
+
64
+
Reload your shell configuration:
59
65
60
66
```bash
61
67
source~/.bashrc
62
68
```
63
69
64
-
Install various compiler version on your Ubuntu system. For this example we will install version 9 of the gcc/g++ compiler to demonstrate potential improvements your application could achieve.
70
+
Install multiple compiler versions on your Ubuntu system. For this example you can install GCC version 9 to demonstrate potential improvements your application could achieve.
0 commit comments