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
- Prepare the Megahit source code.
- Use MobaXterm to log in to the server as the root user.
- 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.
mkdir -p /opt/DevKit/workspace/devadmin/porting/sourcecode/ chmod -R 700 /opt/DevKit/workspace/devadmin/porting/ chown -R devkit:devkit /opt/DevKit/workspace/devadmin/porting/
/opt indicates the DevKit installation path. Replace it with the actual one.
- Go to the source code porting directory and download the Megahit source code.
cd /opt/DevKit/workspace/devadmin/porting/sourcecode/ git clone https://github.com/voutcn/megahit.git
- Merge the code.
cd megahit/ && git submodule update --init
- Create a build folder and go to the folder.
mkdir build && cd build
- Generate Makefile.
cmake .. -DCMAKE_BUILD_TYPE=Release
- 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:
rm -rf /opt/DevKit/workspace/devadmin/porting/sourcecode/megahit
- 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 Analyze.Figure 1 Creating a task
- After the analysis is complete, click Porting Report and view the modification suggestions.Figure 2 Viewing the report
- Under Source Files to Be Ported, select a source file and click View Suggested Source Code in the Operation column.
The 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 definition has two nested layers and does not need to be modified.
Figure 3 Viewing files to be ported
- Based on the suggestions, modify the code. Click the embedded assembly code cpu_dispatch.h and you will see four points to be modified.Figure 4 Viewing the code to be modified
- Apply auto-modification to points 1 and 3:
Figure 5 Applying auto-modification (point 1)
After auto-modification:
Figure 6 After auto-modification (point 1)
- Apply auto-modification to points 2 and 4:
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)
- Click Save to confirm the file modification.
- Apply auto-modification to points 1 and 3:
- Move the cursor to the three highlighted code snippets of the megahit/src/kmlib/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.
- Apply auto-modification and the code is as follows:
Figure 13 After modification
- Click Save to confirm the file modification.
- Apply auto-modification and the code is as follows:
- Move the cursor to the megahit_core.dir/flags.make file. You can see two modification points.Figure 14 Code snippet to be modified
- 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
- Click Save to confirm the file modification.
- According to the suggestions (the Kunpeng platform does not support BMI2 or POPCNT instructions), manually modify the code. Delete the -mbmi2 and -mpopcnt instructions.
- Move the cursor to the megahit_core_popcnt.dir/flags.make file. You can see one modification point.Figure 17 Code snippet to be modified
- Apply auto-modification and the code is as follows:
Figure 18 After modification
- Click Save to confirm the file modification.
- Apply auto-modification and the code is as follows:
- Recompile the code after the migration.
- Add the KunpengTrans.h file to the /opt/DevKit/workspace/devadmin/porting/sourcecode/megahit/src/utils directory.
Run the following copy command:
cp /opt/DevKit/devkitplugins/inline_asm/config/KunpengTrans.h /opt/DevKit/workspace/devadmin/porting/sourcecode/megahit/src/utils
- Run the make command:
cd /opt/DevKit/workspace/devadmin/porting/sourcecode/megahit/build && make
- Add the KunpengTrans.h file to the /opt/DevKit/workspace/devadmin/porting/sourcecode/megahit/src/utils directory.
Parent topic: Practice 2: Porting Megahit Source Code