Rate This Document
Findability
Accuracy
Completeness
Readability

Fortran

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

Environment Requirements

  • Supported
    • Platforms: Kunpeng and x86 (Intel and AMD)
    • Language versions and forms: fixed-form and free-form, as well as Fortran 77, 90, 95, 03, 08, and 18
    • Source file name extensions: f77, f, F, ff, for, FOR, fpp, FPP, f90, F90, ff90, f95, F95, ff95, f03, F03, f08, F08, f18, and F18
    • 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 by default. If you want to use the BiSheng Flang or the Intel ifort or ifx compiler, recompile libcruiser.
  • Not supported
    • Some compiler instructions, such as the !DIR$ UNROLL N instruction for loop unrolling and the !DIR$ ATTRIBUTES FORCEINLINE :: XXX instruction for inline operations.
    • 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

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:

    Perform the instrumentation and compilation mode.
    Finish run precision check tool.
    For detail logs on the tool, see /Path_to_DevKit_CLI/advisor/logs/preccheck.log and /home/test/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=/Path_to_DevKit_CLI/advisor/devkitplugins/affinity/tools/compileopt/libcruiser/gnu_lib:$LD_LIBRARY_PATH
      2) the log file path: export CRUISER_LOG=/LOGPATH/
      3) run the executable file: LD_PRELOAD=libcruiser.so.2:/usr/lib64/libcrypto.so.1.1 ./XXX
    • If the BiSheng Flang or the Intel ifort or ifx compiler is used, recompile libcruiser (go to the libcruiser repository to view the README file).
    • 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/test/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 the compilation database file (dev_compile_commands.json), an executable file, and other necessary files are generated in the build directory.
    • If the TXT file (precision_timestamp.txt) contains error information during compilation and instrumentation, rectify the fault by following instructions in Rank Mismatch Error During Compilation with GFortran.
  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/gnu_lib:$LD_LIBRARY_PATH

      Flang:

      export LD_LIBRARY_PATH=/Path_to_DevKit_CLI/advisor/devkitplugins/affinity/tools/compileopt/libcruiser/bisheng_lib:$LD_LIBRARY_PATH

      ifort or ifx:

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

      /LOGPATH/: path for storing generated log files. The path must be empty.

    3. Run the executable file.
      1
      ./myprogram
      

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

      1
      [WARNING] The remaining space is less than 5 GB in /home/test, please clear enough space and run the program again.
      
      • myprogram: generated executable file.
      • Ensure a sufficient drive space when generating logs.
    4. View the generated 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
      

      Each log in the log file consists of seven parts. The following uses the two logs as an example to describe each part:

      1. File name.

      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: 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: Line number.

      5: Instrumentation variable name.

      6: Thread ID.

      7: Hash value corresponding to the instrumentation variable value.

  3. Analyze log differences between the Kunpeng or x86 platform.
    Change the name of the log file generated on the Kunpeng platform to kunpeng, and the name of the log file generated on the x86 platform to x86. Save the two files on either of the platforms.
    1
    devkit advisor precision -analysis -i "/home/kunpeng;/home/x86"
    

    Command output:

    1
    2
    3
    4
    Perform the logs analysis mode.
    Finish run precision check tool.
    For detail logs on the tool, see /Path_to_DevKit_CLI/advisor/logs/preccheck.log and /home/test/demo1/build/precision_20250213110835_5b7a.txt
    The analysis result is in /home/test/demo1/build/analysis_diff_20250213110840_935b.txt
    
  4. Check the TXT file generated in 3 to locate the source code and potential precision difference problems. If there are any differences, locate problems in the following format:
    file [relative file path]: // file with a potential precision difference
        function [function name]: // function with a potential precision difference
            variable [variable name]: // variable with a potential precision difference
                arm line [line number] // The difference-related variable is located in an assignment statement.
                arm line [line number] called function: [called function]  // The difference-related variable is located in a function call.
                x86 line [line number]
                x86 line [line number] called function: [called function]