我要评分
获取效率
正确性
完整性
易理解

Calculation Precision Analysis

The calculation precision analysis tool is used to locate the precision difference of the Fortran language caused by x86 and Kunpeng instructions.

The tool supports the following items:

  • Platforms: Kunpeng and x86 (Intel and AMD)
  • Language versions and forms: fix-form and free-form, as well as Fortran 77, 90, 95, 03, 08, and 18
  • Instrumentation object types: a single variable of the REAL or COMPLEX type or an array whose shape and length can be obtained
  • Instrumentation positions: instrumentation of variables after actual value assignments and invoked statements
  • Compiler versions: GFortran 10.3.1 and BiSheng Compiler 4.0.0 Flang

The tool does not support the following items:

  • Some compiler instructions, such as the !dir$ unroll n instruction for loop unrolling and the !DIR$ ATTRIBUTES FORCEINLINE :: XXX instruction for inline operations.
  • Multi-node running environments.
  • Incapable of obtaining asterisk arrays, pointers, and user-defined structure types of lengths, and does not support instrumentation for their complex nested expressions
  • Only specified compiler versions recommended because the mod file formats of different Fortran compilers or different versions of the same Fortran compiler are incompatible

Command Function

Locates the precision difference between the Fortran language on the x86 and Kunpeng platforms.

Syntax

Compilation and instrumentation:

1
devkit advisor precision [-h | --help] {-instrument | --instrument} {-c COMMAND COMMANDS | --commands COMMANDS} {-p PROJECT | --project PROJECT} {-e ENTRY | --entry ENTRY} [-d DEPTH | --depth DEPTH] [-b BLACK_LIST | --black-list BLACK_LIST] [-L | --loops] [-l {0,1,2,3} | --log-level {0,1,2,3}] [--set-timeout TIMEOUT]

Log difference analysis:

1
devkit advisor precision [-h | --help] {-analysis | --analysis} {-i INPUT_LOG | --input INPUT_LOG} [-l {0,1,2,3} | --log-level {0,1,2,3}] [--set-timeout TIMEOUT]

To use the calculation precision analysis tool, you need to perform compilation and instrumentation on the different platforms (Kunpeng and x86). After the instrumentation is complete, analyze log differences.

Parameter Description

Table 1 Compilation and instrumentation parameters

Parameter

Option

Description

-h/--help

-

Obtains help information.

-instrument/--instrument

-

Compilation and instrumentation mode. This parameter is mandatory.

-c/--commands

COMMANDS

Builds source code. If there are multiple build commands, separate them with semicolons (;) and enclose them with double quotation marks ("). If a command contains spaces, enclose it with double quotation marks ("). This parameter is mandatory.

Example: "make all" or "cd /home/test;make"

NOTE:
  • Do not run the cmake command directly. You need to run the command in advance.
  • The source code build command in the command line tool does not support variable setting and environment variable export.

    Example: "CFLAGS='-O0 -g';make" or "export CFLAGS='-O0 -g';make"

-p/--project

PROJECT

Absolute path to the project source code. This parameter is mandatory.

Example: /home/test/project1/ or /home/project2/

-e/--entry

ENTRY

Instrumentation entry file and the corresponding function. This parameter is mandatory and can be entered multiple times. Use colons (:) to separate each file and the corresponding function. Use commas (,) to separate multiple functions. Enter the relative path (specified by -p/--project) to the entry file in the project path. The file is used for compilation and cannot be the source file before preprocessing. The function is Mainprogram, Function, or Subroutine that exists in the specified Fortran file.

Example: -e demo.f90:main -e demo2.f90:func

-d/--depth

DEPTH

Depth of continuous instrumentation from the entry function. The default value is 0. The value ranges from 0 to 99.

-b/--black-list

BLACK_LIST

Files excluded from instrumentation. The files cannot contain any files specified by the -e parameter.

Example: "/home/test/demo1.f90;/home/test/demo2.f90"

-L/--loops

-

Instrumentation inside loops. When this option is selected, the precision log file generated by running the executable file after instrumentation becomes larger. Properly arrange the instrumentation entry (entry file and function) and depth.

-l/--log-level

0/1/2/3

Log level, which defaults to 1.

  • 0: DEBUG
  • 1: INFO
  • 2: WARNING
  • 3: ERROR

--set-timeout

-

Timeout interval of a task, in minutes. If the execution duration exceeds the timeout interval, the task exits. By default, there is no timeout interval. The task will be executed until it is complete.

Table 2 Parameters of log difference analysis modes

Parameter

Option

Description

-h/--help

-

Obtains help information.

-analysis/--analysis

-

Log difference analysis mode. This parameter is mandatory.

-i/--input

INPUT_LOG

Log files. The sequence is the Kunpeng log first and then the x86 log (two logs). This parameter is mandatory.

Example: "/home/kp.log;/home/x86.log" or "/home/kp/;/home/x86/"

-l/--log-level

0/1/2/3

Log level, which defaults to 1.

  • 0: DEBUG
  • 1: INFO
  • 2: WARNING
  • 3: ERROR

--set-timeout

-

Timeout interval of a task, in minutes. If the execution duration exceeds the timeout interval, the task exits. By default, there is no timeout interval. The task will be executed until it is complete.

Example

In this example, the source files in the /home/test/demo1 directory are scanned. The compile commands are cmake .. and make. Replace the example directory or command with the actual one.

Directory structure of demo1

1
2
3
4
5
6
demo1
├── build
├── CMakeLists.txt
├── funcparam_utils.f90
├── shape_utils.f90
└── test.f90
  1. Perform compilation and instrumentation in the project directories in the Kunpeng and x86 environments.
    1
    2
    3
    cd /home/test/demo1/build
    cmake ..
    devkit advisor precision -instrument -c make -p /home/test/demo1 -e test.f90:main -d 1
    

    Command output:

    1
    2
    3
    4
    5
    6
    7
    Perform the instrumentation and compilation mode.
    Finish run precision check tool.
    For detail logs on the tool, see /Absolute-Path-to-DevKit-CLI/advisor/logs/preccheck.log and /home/test1/demo1/build/precision_20241106111820_6193.txt
    Please check whether error information exists in above two files to ensure that the project can run properly.
    Before running the project to get the log file, please add:
      1) the libcorrect.mod file path: export LD_LIBRARY_PATH=/Absolute-Path-to-DevKit-CLI/advisor/devkitplugins/affinity/tools/compileopt/libcruiser/gfortran_lib(or flang_lib):$LD_LIBRARY_PATH
      2) the log file path: export CRUISER_LOG=/absPATH/
    
    • Before executing compilation and instrumentation, ensure that the project has not been compiled. Otherwise, compile commands are not fully executed during incremental compilation, causing program execution failure.
    • /Path_to_Devkit_CLI/: DevKit command line tool path.
    • -p specifies the project source code path (/home/test1/demo1/), and -e specifies the instrumentation entry file and the corresponding function (test.f90:main) in the path.
    • After the compilation and instrumentation are complete, the .bak file (test.f90.bak) is generated in the directory where the instrumentation entry file is located, and an executable file is generated in the build directory.
    • If the TXT file contains error information during compilation and instrumentation, rectify the fault by following instructions in Errors Contained in the TXT File During Compilation and Instrumentation.
  2. Run the compiled binary files again in the Kunpeng and x86 environments.
    1. Add the libcruiser library path based on the compiler type.
      GFortran:
      export LD_LIBRARY_PATH=/Path_to_Devkit_CLI/advisor/devkitplugins/affinity/tools/compileopt/libcruiser/gfortran_lib:$LD_LIBRARY_PATH

      Flang:

      export LD_LIBRARY_PATH=/Path_to_Devkit_CLI/advisor/devkitplugins/affinity/tools/compileopt/libcruiser/flang_lib:$LD_LIBRARY_PATH
    2. Add the path to the generated log file.
      export CRUISER_LOG=/LOGPATH/

      /LOGPATH/: path to generated log files.

    3. Run the executable file.
      ./myprogram

      If the following information is displayed, the drive space of the log file path is less than 1 GB. In this case, clear the drive space.

      1
      [ERROR] Insufficient disk space in /home/test1/, please clean up the disk.
      

      myprogram: generated executable file.

      Ensure a sufficient drive space when generating logs.

    4. View the generated cruiser.log file.
      1
      2
      3
      4
      5
      6
      shape_utils.f90|absize|=|28|ins|998058|429d81ed2795e3c586906c6c335aa136
      shape_utils.f90|absize|=|28|ins|998058|429d81ed2795e3c586906c6c335aa136
      test.f90|main|absize|26|array1d|998058|22160b46bba283274412c4033f1f33fe
      shape_utils.f90|absize|=|28|ins|998058|429d81ed2795e3c586906c6c335aa136
      test.f90|main|xysize|35|x2|998058|5d5ebe7707f02dec747fd0d111d0f83c
      test.f90|main|submain|41|array1d|998058|22160b46bba283274412c4033f1f33fe
      

      Log file content description:

      1. Part 1: File name.
      2. Part 2: Name of the current minimum scope where the expression statement of part 3 is located, which may be a function, a subroutine, or a main program.
      3. Part 3: When the instrumentation variable is in the function call statement (as a function parameter), the value is the name of the invoked function. When the instrumentation variable is in the assignment statement, the value is an equal sign (=).
      4. Part 4: Line number.
      5. Part 5: Instrumentation variable name.
      6. Part 6: Thread ID.
      7. Part 7: Hash value.
  3. Analyze log differences between the Kunpeng or x86 platform.
    Change the name of the cruiser.log file generated on the Kunpeng platform to cruiser_kp.log, and the name of the cruiser.log file generated on the x86 platform to cruiser_x86.log. Save the two files on either of the platforms.
    1
    devkit advisor precision -analysis -i "/home/test1/cruiser_kp.log;/home/test1/cruiser_x86.log"
    

    Command output:

    1
    2
    3
    4
    Perform the logs analysis mode.
    Finish run precision check tool.
    For detail logs on the tool, see /Absolute-Path-to-DevKit-CLI/advisor/logs/preccheck.log
    The analysis result is in /home/test1/demo1/build/precision_20241106113405_5b7a.txt
    
  4. Check the TXT file generated in 3 to locate the source code and precision problems.