Rate This Document
Findability
Accuracy
Completeness
Readability

Porting Source Code

Prerequisites

  • The Kunpeng DevKit has been successfully installed and the required tools have been installed.
  • Git has been installed and the environment variables have been configured.

Procedure

  1. Prepare the Megahit source code.
    1. Use MobaXterm to log in to the server as the root user.
    2. If the source code porting directory exists, skip this step. Otherwise, manually create a source code porting directory. The following uses devadmin as an example.
      1
      2
      3
      mkdir -p /opt/DevKit/workspace/devadmin/porting/sourcecode/
      chmod -R 700 /opt/DevKit/workspace/devadmin/porting/
      chown -R username:username /opt/DevKit/workspace/devadmin/porting/
      
      • /opt indicates the DevKit installation path. Replace it with the actual one.
      • username indicates the DevKit installation user. Replace it with the actual user.
    3. Obtain the Megahit source code from GitHub, upload it to the directory, and decompress it.
      1
      2
      tar -zxvf megahit-1.2.9.tar.gz
      cd megahit-1.2.9
      
    4. Create a build folder and go to the folder.
      1
      mkdir build && cd build
      
    5. Generate Makefile.
      1
      cmake .. -DCMAKE_BUILD_TYPE=Release
      
    6. Download the updated Megahit source code to the local PC and run the following command to delete the Megahit source code in the source code porting directory:
      1
      rm -rf /opt/DevKit/workspace/devadmin/porting/sourcecode/megahit-1.2.9
      
  2. Return to the page of creating a source code porting task. Upload the Megahit source code folder. Select BiSheng Compiler 2.5.0.1 for Compiler Version and make -C build for Compile Command. Retain the default values for the other parameters. Then click Start.
    Figure 1 Creating a task
  3. After the analysis is complete, click Porting Report and view the modification suggestions.
    Figure 2 Viewing the report
  4. Under Source Files to Be Ported, select a source file and click View Suggested Source Code in the Operation column.
    Figure 3 Viewing files to be ported

    This project is compiled using CMake and the CMake middleware is used to demonstrate the Makefile scan function. As a result, some false scan information may appear. You do not need to modify these suggestions in this best practice. The detailed suggestions are as follows:

    • The phmap.h, phmap_bits.h, phmap_config.h, and xxh3.h source files already have macro definitions. The header files are defined only when SSE2 and SSSE3 exist in the source code structure. The macro definitions have two nested layers and do not need to be modified.
    • Except the flags.make file that needs to be modified in the following steps, other .make files do not need to be modified.
  5. Based on the suggestions, modify the code. Click the embedded assembly code cpu_dispatch.h and you will see that five points need to be modified while one does not.
    Figure 4 Viewing the code to be modified
    1. Apply auto-modification to points 1 and 4:
      Figure 5 Applying auto-modification (point 1)

      After auto-modification:

      Figure 6 After auto-modification (point 1)
    2. Modification points 3 and 5: Click Quick Fix > Batch Apply This Suggestion to apply the automatic modification.
      Figure 7 Applying auto-modification (point 2)

      After auto-modification:

      Figure 8 After auto-modification (point 2)
      Figure 9 After auto-modification (point 3)

      You can see that specific suggestions have been provided after automatic modification is applied. The suggestions provided for the two points are correct.

      Figure 10 Modification result (point 1)
      Figure 11 Modification result (point 2)
    1. After the modification is complete, press Ctrl+S to save the file.
  6. Move the cursor to the three highlighted code snippets of the kmrns.h file. One of the code snippets needs to be modified and the other two do not.
    Figure 12 Code snippet to be modified

    Megahit has been partially adapted to Arm. Therefore, you only need to use the automatic modification function and do not need to use the avx2ki.h header file.

    1. Apply auto-modification and the code is as follows:
      Figure 13 After modification
    2. After the modification is complete, press Ctrl+S to save the file.
  7. Move the cursor to the megahit_core.dir/flags.make file. You can see two modification points, but only one needs to be modified.
    Figure 14 Code snippet to be modified
    1. According to the suggestions (the Kunpeng platform does not support BMI2 or POPCNT instructions), manually modify the code. Delete the -mbmi2 and -mpopcnt instructions.
      Figure 15 Manual modification

      After modification:

      Figure 16 After manual modification
    2. After the modification is complete, press Ctrl+S to save the file.
  8. Move the cursor to the megahit_core_popcnt.dir/flags.make file. You can see two modification points, but only one needs to be modified.
    Figure 17 Code snippet to be modified
    1. Apply auto-modification and the code is as follows:
      Figure 18 After modification
    2. After the modification is complete, press Ctrl+S to save the file.
  9. Recompile the code after the migration.
    1. Add the KunpengTrans.h file to the /opt/DevKit/workspace/devadmin/porting/sourcecode/megahit-1.2.9/src/utils directory.

      Run the following copy command:

      1
      cp /opt/DevKit/devkitplugins/inline_asm/config/KunpengTrans.h /opt/DevKit/workspace/devadmin/porting/sourcecode/megahit-1.2.9/src/utils
      
    2. Run the make command:
      1
      cd /opt/DevKit/workspace/devadmin/porting/sourcecode/megahit-1.2.9/build && make