Rate This Document
Findability
Accuracy
Completeness
Readability

Automatic FDO Compilation

Profile-guided optimization (PGO) is a compiler optimization technique that uses instrumentation to collect runtime profile of a program. The compiler then makes use of the runtime profile and leverages various compilation optimization technologies to make more accurate optimization decisions and generate more efficient programs.

Automatic feedback-directed optimization (FDO) is a technique that simplifies the PGO deployment process. It samples program runtime profile to indirectly obtain the program execution status.

Prerequisites

  • You have logged in to the Kunpeng DevKit.
  • The operating environment must meet the following requirements:
    • Architecture: Kunpeng Arm
    • OS (PRETTY_NAME): openEuler 22.03 LTS, openEuler 22.03 LTS SP1, openEuler 20.03 LTS SP2, openEuler 20.03 LTS SP3, Ubuntu 18.04.4 LTS, Ubuntu 20.04.2 LTS, Kylin Linux Advanced Server V10 (Tercel), UOS 20, UnionTech OS Server 20, or CentOS Linux 7 (AltArch)

      Note: If PRETTY_NAME is CentOS Linux 7 (AltArch), the value of redhat-release must be CentOS Linux release 7.6.1810 (AltArch).

    • Compiler: GCC for openEuler 2.3.2 or later

      If the GCC for openEuler version is correct when you set parameters for automatic FDO compilation as a common user, but the environment check result displays a message indicating that the compiler is not installed or the compiler version does not match, check whether the environment variables of GCC for openEuler are configured in the ~/.profile file.

    • Software packages: curl, perf, and A-FOT

Procedure

  1. Click in the navigation pane on the left, or click Development and then click Compile under Compiler and Debugger to display the compilation page.
  2. Select AutoFDO compilation and set the compilation parameters, as shown in Figure 1. Then, click Next.
    Figure 1 AutoFDO compilation
  3. Verify the server environment and download the script file.
    Figure 2 Selecting a target server

    The programming language of the program to be optimized can only be C, C++, or Fortran.

  4. After the verification is successful, set the other parameters, as shown in Figure 3 and Table 1. After the configuration is complete, click Start to verify the parameters and perform automatic FDO compilation.
    Figure 3 Configuration parameters
    Table 1 Automatic FDO compilation parameters

    Parameter

    Description

    Local Project Path

    Local path for storing the current project file.

    Compilation Type

    The compilation type can be:

    • Common compilation
    • AutoFDO compilation

    Configured Remote Server

    Remote server for completing the compilation.

    Use an existing server or add a target server. Click Add Target Server to go to the target server management page. .

    Linux Password

    Password of the Linux user.

    Remember password

    If this option is selected, the Linux user password of the current remote server will be remembered.

    Executable File Path

    Path to the executable file generated after installation from the binary file.

    This path is used to parse the profile in the profile generation phase.

    Build Script Path

    Path to the build script of the target application.

    You need to write the build script, which will be invoked to compile the application.

    Execution Script Path

    Path to the execution script of the target application.

    You need to write the execution script, which will be run by the tool in the background to execute the target application.

    Script Working Directory

    Working directory for storing the sampling file and profile.

    Optimization Mode

    The A-FOT tool improves automatic FDO of the GCC for openEuler. It supports the following modes:

    • AutoFDO is a simplified version of PGO that uses perf instead of instrumentation to obtain the program runtime profile. The optimization technologies include vectorization, loop unrolling, and loop fission.
    • AutoPrefetch is an enhanced prefetch optimizer. Based on the Dcache access and the cache miss rate of access instructions, AutoPrefetch obtains code blocks that can be used for data access optimization, optimizes the prefetch and prefetch lookahead. It is recommended that AutoPrefetch be used together with AutoFDO.
    • AutoBOLT is a post-link binary optimizer, which works excellently on programs with complex control flows. The optimization technologies include basic block reordering, function reordering, and function splitting (hot and cold blocks). AutoBOLT cannot be used together with AutoFDO and AutoPrefetch.

    Maximum Startup Duration (s)

    Maximum wait time for the target application to be started in binary mode.

    If the task name is detected, the binary startup is successful. The value ranges from 1 to 900 and the default value is 10.

    Sampling Duration (s)

    Sampling duration.

    The value ranges from 1 to 1800 and the default value is 100.

  5. Obtain the optimized compilation file in the path displayed after the automatic FDO task is successful. If the automatic FDO task fails, you can view the failure information on the terminal or view the opt.log file in the corresponding path on the target server.
    Figure 4 Execution success
    Figure 5 Execution failure
    • If automatic FDO compilation fails to be started, rectify the fault by following instructions in Failed to Start an Automatic FDO Compilation Task.
    • To perform automatic FDO compilation again, click in the navigation pane on the left or click Compile.
  6. To modify automatic FDO compilation parameters, choose > Project Settings > Compile. Set Compilation Type to AutoFDO compilation, modify the configuration parameters, and click Save.
    Figure 6 Modifying automatic FDO compilation parameters