WRF transplantation and optimization method based on Huawei Kunpeng processor
By transplanting and optimizing the WRF model on Huawei Kunpeng processors, the problem of low operation efficiency of WRF models on domestic ARM processors is solved, efficient weather forecast calculation is achieved, replacing the monopoly of traditional x86 architecture processors.
Patent Information
- Application Number
- CN202210746651.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-28
- Publication Date
- 2025-05-02
- Estimated Expiration
- 2042-06-28
AI Technical Summary
The existing technology is difficult to efficiently run the WRF weather forecast model on domestic ARM processors, resulting in low computing resource utilization efficiency and cannot replace the monopoly of traditional x86 architecture processors.
Using the WRF migration and optimization method based on Huawei Kunpeng processor, the porting advisor is installed to detect the difference in the instruction set, compile instructions and dependency library, generate a port analysis report, and perform node optimization, compiler optimization and model application optimization based on the report, and finally generate a WRF executable program suitable for Kunpeng processor.
It realizes the efficient operation of the WRF model on the low-power and high-performance Kunpeng 920 processor, effectively replacing the traditional x86 architecture processor, and avoiding the monopoly of foreign processors on WRF scientific computing.
Smart Images

Figure CN115237470B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of processor performance transplantation and optimization, and in particular to a WRF transplantation and optimization method based on a Huawei Kunpeng processor. Background Art
[0002] As people rely more and more on real-time weather forecasts, WRF (Weather Research and Forecasting) has become an indispensable tool as a weather forecast model. Due to the complexity of atmospheric movement, WRF needs to process comprehensive parameters of the atmospheric environment, such as ground heat, snow cover effect, road radiation, number of soil layers under the surface, land temperature, sea temperature, ocean current movement and water vapor flux. Not only is the number large, but the simulation time period is also long, so running this model requires powerful computing resources, which places extremely high demands on the CPU's processing power.
[0003] In recent decades, the main work of scientific computing has been associated with Intel x86 architecture processors, so numerical simulation models such as WRF are mostly applied to x86 processors. However, many domestic ARM processors are also trying to become a substitute for traditional x86 architecture processors in HPC by virtue of their low power consumption and high performance. Summary of the invention
[0004] In order to transplant WRF on domestic ARM processors, the present invention proposes a WRF transplantation and optimization method based on Huawei Kunpeng processor.
[0005] The present invention comprises the following steps:
[0006] Step 1: Install Kunpeng porting analysis tool porting advisor to detect differences in WRF instruction sets, compilation instructions, and dependent libraries on ARM;
[0007] Step 2: Obtain the current Kunpeng processor system and compiler version for porting advisor detection to generate a porting analysis report that matches the system;
[0008] Step 3: Put the WRF-4.2 source code package into the porting advisor for porting analysis, specify the target system and compiler version, and get the porting analysis report;
[0009] Step 4: Find the instructions with differences in the file in the migration analysis report, and modify and optimize the WRF source code package according to the suggestions given in the report, including: node optimization, compiler optimization, and application optimization of the WRF model;
[0010] Step 5: Move the modified WRF source code package to the Kunpeng 920 processor;
[0011] Step 6: After decompressing the WRF source code package, compile it to get the WRF executable program wrf.exe.
[0012] Beneficial effects of the invention: The invention solves the performance problems caused by cross-architecture, allowing WRF to run perfectly on the low-power, high-performance Kunpeng 920 processor, which is a good substitute for the traditional x86 architecture processor in foreign HPC and avoids the monopoly of foreign processors on WRF scientific computing. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] Figure 1 This is a flow chart of the transplantation and optimization method of WRF on Kunpeng 920 processor;
[0014] Figure 2 Schematic diagram of fine-grained parallelization of code for OpenMP methods;
[0015] Figure 3 A screenshot of the results of parallel execution of the wrf.exe file using openMPI. DETAILED DESCRIPTION
[0016] The technical solution of the present invention will be further described in detail below in conjunction with the accompanying drawings in the embodiments of the present invention:
[0017] Step 1: Install Kunpeng porting analysis tool porting advisor to detect differences in WRF instruction sets, compilation instructions, and dependent libraries on ARM;
[0018] Step 2: Obtain the current Kunpeng processor system and compiler version for Porting advisor detection to generate a porting analysis report that matches the system;
[0019] Step 3: Put the WRF-4.2 source code package into the porting advisor for porting analysis, specify the target system and compiler version, and get the porting analysis report;
[0020] Step 4: In the migration analysis report, find the instructions with differences in the file, and modify and optimize the WRF source code package according to the suggestions given in the report, including: node optimization, compiler optimization, and application optimization for the WRF model.
[0021] Node optimization: Since Kunpeng processors support NUMA technology, they can coordinate data communication between CPUs and help applications access adjacent memory with lower latency. However, Kunpeng processors are not bound to NUMA nodes by default, so applications need to be modified to reduce the extra time overhead caused by accessing remote memory. To do this, you can add the -bind-to-core command when running the program to bind the core.
[0022] Compiler optimization, when the CPU executes instructions, it usually uses pipeline parallel execution to improve the execution speed of instructions, so the order of instruction arrangement will greatly affect the execution efficiency. By adding -mcpu=tsv110-march=armv8-a in the CFGLAS compilation option. Among them, -march=armv8-a specifies the processor architecture as ARMv8, so that the compiler generates executable programs according to the architecture of the Kunpeng processor. -mcpu=tsv110 can adapt to the tsv110 pipeline of the Kunpeng processor. The use of the tsv110 pipeline can make full use of instruction parallelism and thus improve execution efficiency.
[0023] Added -ffree-form compilation option to meet the free format encoding adopted by fotran90 compiler and later;
[0024] The free-line-length-none compilation option is added because the gfortran compiler has syntax restrictions and does not allow each line to exceed 132 characters in free format. Adding the compilation option free-line-length-none can make the free format have no line limit;
[0025] The -std=legacy compilation option is added because the standards supported by the gfortran compiler are F95, F2003, F2008, F2018, GNU or Legacy. The default -std option is GNU according to the latest standard, because the latest standard has stricter requirements for Fortran language planning. The number of input parameters is inconsistent with the interface definition, and an error occurs under the new specification. Using the -std=legacy compilation option means following the old F77 syntax specification, which can solve the error problem.
[0026] For the application optimization method of the WRF model, in the WRF model, the three-dimensional space is discretized into 3D grid points, and the two horizontal dimensions are i and j, so the horizontal coordinates can be written as (i, j). For each grid point, multiple altitude layer data will be processed. These altitude layer data represent the atmosphere. The height is the vertical height relative to the ground, and k is used to represent the vertical height. Therefore, there are a large number of three-dimensional arrays in the WRF code. These three-dimensional arrays are represented by the layout of (i, j, k), which represents the 3D grid points in the three-dimensional space.
[0027] The hotspot functions of the dynamic module of the WRF model are mostly concentrated in the module_advect_em.F file, and almost all the calculation hotspot parts are stencil type loops. Take a typical algorithm as an example, its pseudo code is as follows:
[0028]
[0029]
[0030] It can be further seen that the j loop in the algorithm contains two k and i loops, and the dimensions are roughly the same. Now put the two loops together to form a triple loop, which can calculate the values of the two variables vflux and tend at the same time, saving nearly half of the memory access time. The optimized code is as follows:
[0031]
[0032] Furthermore, we continue to optimize these hot functions at the thread level. Here we use the OpenMP method to perform fine-grained parallelism on the code. Figure 2 As shown, each block network is cut into multiple plane grid calculations along the k direction, and these block loops are called for calculation in the threads of each core.
[0033] Specifically, you need to add #pragma omp parallel for before the stencil function, which means that the for loops in the following code block are all parallel, and the number of threads depends on the number of CPU threads by default.
[0034] Optimize all stencil hotspot functions in the module_advect_em.F file that are similar to the above code.
[0035] Step 5: Move the modified WRF source code package to the Kunpeng 920 processor. Before this, you need to install the WRF dependencies, including openMPI, HDF5, NetCDF, and zlib.
[0036] Step 6: Unzip the WRF source code package and compile it. When compiling, you need to add the -fopenmp compilation option to get the WRF executable program wrf.exe. At this point, the transplantation and optimization of WRF are all completed. The whole process is as follows: Figure 1 shown.
[0037] Step 7: Execute time mpirun --allow-run-as-root-np 32. / wrf.exe to run the WRF official example:
[0038] The running results are as follows Figure 3 mpirun uses the openMPI software to execute the wrf.exe file in parallel, and -np 32 uses 32 processes to run the example. real represents the time from the start to the end of the run.
Claims
1. Based on the WRF transplantation and optimization method on Huawei Kunpeng processor, it is characterized by The method comprises the following steps: Step 1: Install the Kunpeng porting analysis tool porting advisor; Step 2: Get the current Kunpeng processor system and compiler version; Step 3: Put the WRF source code package into the porting advisor for porting analysis, specify the target system and compiler version, and obtain the porting analysis report; Step 4: Find the instructions with differences in the file in the migration analysis report, and modify and optimize the WRF source code package according to the suggestions given in the report, including: node optimization, compiler optimization, and application optimization of the WRF model; Step 5: Move the modified WRF source code package to the Kunpeng 920 processor; Step 6: Unzip the WRF source code package and compile it to get the WRF executable program wrf.exe; The node optimization method described in step 4 is as follows: Bind to core by adding the -bind-to-core command when running the program; The compiler optimization method described in step 4 is as follows: by adding the -mcpu=tsv110-march=armv8-a compilation option in the CFGLAS compilation option; Add -ffree-form compilation option; Add free-line-length-none compilation option; Add -std=legacy compilation option; The optimization method for the application of the WRF model described in step 4 is as follows: put the two loops of the stencil type together to form a triple loop; OpenMP is used to perform fine-grained parallelism on the code, and each block network is cut into multiple plane grid calculations along the k direction; Optimize all stencil hotspot functions in the module_advect_em.F file; The method of using OpenMP to perform fine-grained parallelization on the code is: add #pragma ompparallel for before the stencil function; The optimization of all stencil hotspot functions refers to thread-level optimization of stencil hotspot functions, and the number of threads depends on the number of CPU threads by default.
2. The WRF transplantation and optimization method based on Huawei Kunpeng processor according to claim 1 is characterized in that: In step 5, the WRF dependencies need to be installed in advance.
3. The WRF transplantation and optimization method based on Huawei Kunpeng processor according to claim 1 is characterized in that: In step 6, you need to add the -fopenmp compilation option during compilation.
4. The WRF transplantation and optimization method based on Huawei Kunpeng processor according to claim 1 is characterized in that: It also includes executing time mpirun --allow-run-as-root-np 32. / wrf.exe to run the WRF official example for verification.