Method, apparatus, and computing device for stencil computation

By generating a judgment result vector and performing vector calculations in the stencil computation, the inefficiency caused by judgment in the stencil computation is solved, and efficient computation under both structured and unstructured grids is achieved.

CN119576409BActive Publication Date: 2025-11-21HUAWEI TECH CO LTD

Patent Information

Application Number
CN202311161061.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-09-07
Publication Date
2025-11-21
Estimated Expiration
2043-09-07

AI Technical Summary

Technical Problem

In stencil computation, there is a problem that the computation cannot be converted into vector computation because it is necessary to judge the node data and perform different computation operations, resulting in low efficiency, which is particularly evident in unstructured meshes.

Method used

By pre-calculating conditional judgments on node data, generating judgment result vectors, and using vector calculation instructions to execute corresponding calculation operations, stencil calculations are converted into vector calculations, including mapping node data in memory and reading it in traversal order.

Benefits of technology

It improves the efficiency of stencil computation, especially in structured and unstructured meshes, reduces non-continuous access, and increases computation speed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119576409B_ABST
    Figure CN119576409B_ABST
Patent Text Reader

Abstract

The embodiment disclosed by the application belongs to the technical field of computing, and particularly relates to a method and device for performing stencil calculation and a computing device. The method comprises the following steps: acquiring a plurality of node data included in a calculation region, and grouping the plurality of node data into a data vector. According to at least one calculation condition included in the stencil calculation, the plurality of node data are subjected to judgment processing, and a judgment result corresponding to each calculation condition is obtained for each node data. For each calculation condition, the judgment result corresponding to the calculation condition is grouped into a judgment result vector, and the judgment result vector is obtained. Based on the data vector and the judgment result vector corresponding to each calculation condition, a calculation operation corresponding to each calculation condition in the stencil calculation is performed, and a calculation result of the stencil calculation is obtained. The application can convert the stencil calculation into vector calculation, and can improve the efficiency of the stencil calculation.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computing, and particularly relates to a stencil computing method, device and computing equipment. BACKGROUND

[0002] Stencil computing is a common loop computing method, which is characterized by traversing node data in a computing region and performing similar computing processing on the node data traversed each time.

[0003] In stencil computing, the computing performed on the node data traversed each time is generally scalar computing, so that the scalar computing of the node data traversed multiple times can be converted into vector computing. In this way, the computing of batch node data can be implemented through vector computing, and the efficiency of stencil computing can be improved.

[0004] However, in stencil computing, the node data may also be judged according to a computing condition. Different computing needs to be performed on the node data corresponding to different judgment results. For example, when the node data is odd, the node data can be added by 1, and when the node data is even, the node data can be added by 2. In this way, the node data traversed each time needs to be sequentially subjected to judgment processing, and then the corresponding computing is performed according to the judgment result, so that the stencil computing cannot be converted into vector computing, resulting in low efficiency of executing the stencil computing. SUMMARY

[0005] Embodiments of the present application provide a stencil computing method, device and computing equipment, which can improve the efficiency of stencil computing. The corresponding technical solutions are as follows:

[0006] In a first aspect, a method for executing stencil computing is provided, the stencil computing including at least one computing condition and a corresponding computing operation, and the method includes:

[0007] A processor acquires a plurality of node data included in a computing region and groups the plurality of node data into a data vector. The processor performs judgment processing on the plurality of node data according to at least one computing condition included in the stencil computing, and obtains a judgment result corresponding to each computing condition for each node data. For each computing condition, the processor groups the judgment result corresponding to the computing condition for the plurality of node data into a judgment result vector, and obtains a judgment result vector corresponding to the computing condition. Based on the data vector and the judgment result vector corresponding to each computing condition, the processor performs the computing operation corresponding to each computing condition in the stencil computing, and obtains a computing result of the stencil computing.

[0008] In the scheme shown in the present application, each node data is judged and processed by each calculation condition in advance to obtain a judgment result vector corresponding to each calculation condition, and then the vector calculation is performed between the judgment result vector corresponding to each calculation condition and the data vector composed of the plurality of node data, and then the calculation operation corresponding to the calculation condition satisfied by each node data is implemented. It can be seen that the scheme shown in the present application can convert the stencil calculation including the calculation condition into vector calculation, and then the efficiency of executing the stencil calculation can be improved.

[0009] In an implementable manner, the calculation region is a structured grid or an unstructured grid. Thus, by using the scheme shown in the present application, the calculation efficiency of the stencil calculation under the structured grid or the unstructured grid can be further improved.

[0010] In an implementable manner, the calculation region is an unstructured grid, and the processing of composing the data vector by the plurality of node data includes: applying the memory storage space for the plurality of node data in the memory. The plurality of node data is mapped from the original storage space to the memory storage space according to the traversal order of the plurality of node data in the calculation region. The plurality of node data is read from the memory storage space based on the vector reading instruction to obtain the data vector.

[0011] In the scheme shown in the present application, for the unstructured grid, the node data can be mapped from the original storage space (such as a hard disk) to the memory storage space according to the traversal order of the node data. Thus, when the stencil calculation is performed on the unstructured grid, the node data continuously read from the memory storage space is the node data traversed according to the traversal order. Thus, it is not necessary to perform the non-continuous reading of the node data in the original storage space according to the traversal order each time, and then the unstructured grid stencil calculation can be converted into vector calculation, and the efficiency of the unstructured grid stencil calculation can be improved.

[0012] In an implementable manner, for each calculation condition, the judgment result of the plurality of node data corresponding to the calculation condition is composed into the judgment result vector to obtain the judgment result vector corresponding to the calculation condition, including: for each calculation condition, the judgment result of the plurality of node data corresponding to the calculation condition is composed into the judgment result vector according to the traversal order of the plurality of node data in the calculation region to obtain the judgment result vector corresponding to the calculation condition. Thus, the judgment result of each node data corresponding to each calculation condition can be composed into the judgment result vector according to the traversal order of each node data. The vector calculation can be performed between the composed judgment result vector and the data vector, and then the stencil calculation can be converted into vector calculation, and the efficiency of the stencil calculation can be improved.

[0013] In an implementable manner, the judging processing of the plurality of node data according to the at least one calculation condition included in the stencil calculation obtains a judging result corresponding to each calculation condition for each node data, including: judging processing of the plurality of node data according to the at least one calculation condition included in the stencil calculation. For each node data, if the node data does not conform to the calculation condition, the judging result corresponding to the node data is determined as a first value, and if the node data conforms to the calculation condition, the judging result corresponding to the node data is determined as a second value. In an example, the first value is 0, and the second value is 1.

[0014] In the scheme shown in the present application, for the node data that does not conform to the calculation condition, the corresponding judging result can be set as the first value, and for the node data that conforms to the calculation condition, the corresponding judging result can be set as the second value. In this way, the first value and the second value are set in the judging result vector corresponding to the calculation condition, which can realize the execution of the corresponding calculation operation on the node data in the data vector that meets the calculation condition, and further realize the stencil calculation through vector calculation, thereby improving the efficiency of the stencil calculation.

[0015] In an implementable manner, the judging processing of the plurality of node data according to the at least one calculation condition included in the stencil calculation obtains a judging result corresponding to each calculation condition for each node data, including: judging processing of the plurality of node data according to the at least one calculation condition included in the stencil calculation. For each node data, if the node data does not conform to the calculation condition, the judging result corresponding to the node data is determined as a first value, and if the node data conforms to the calculation condition, the judging result corresponding to the node data is determined as a second value. In an example, the first value is 0, and the second value is 1.

[0016] In the scheme shown in the present application, the data vector can be used as the initial input vector for vector calculation with the judging result vector corresponding to the calculation condition. For the obtained calculation result vector, the input vector can be used as the judging result vector corresponding to the next calculation condition for vector calculation. In this way, the calculation result of the stencil calculation can be obtained after the vector calculation of the judging result vector corresponding to each calculation condition. Thus, the stencil calculation is converted into vector calculation, which can improve the efficiency of the stencil calculation.

[0017] In a second aspect, an apparatus for performing a stencil computation is provided, the stencil computation including at least one computation condition and a corresponding computation operation, and the apparatus comprising:

[0018] an obtaining module configured to obtain a plurality of node data included in a computation region, and to group the plurality of node data into a data vector;

[0019] a judging module configured to judge the plurality of node data according to the at least one computation condition included in the stencil computation, and to obtain a judging result corresponding to each computation condition for each node data;

[0020] a generating module configured to, for each computation condition, group the judging result corresponding to the computation condition for the plurality of node data into a judging result vector, and to obtain a judging result vector corresponding to the computation condition;

[0021] a computing module configured to, based on the data vector and the judging result vector corresponding to each computation condition, perform the computation operation corresponding to each computation condition in the stencil computation, and to obtain a computation result of the stencil computation.

[0022] In an implementable manner, the computation region is a structured grid or an unstructured grid.

[0023] In an implementable manner, the computation region is an unstructured grid, and the obtaining module is configured to: apply a memory storage space for the plurality of node data in a memory; map the plurality of node data from an original storage space to the memory storage space according to a traversal order of the plurality of node data in the computation region; and read the plurality of node data from the memory storage space based on a vector reading instruction, and obtain the data vector.

[0024] In an implementable manner, the generating module is configured to: for each computation condition, group the judging result corresponding to the computation condition for the plurality of node data into a judging result vector according to the traversal order of the plurality of node data in the computation region, and obtain the judging result vector corresponding to the computation condition.

[0025] In an implementable manner, the judging module is configured to: judge the plurality of node data according to the at least one computation condition included in the stencil computation; and for each node data, if the node data does not conform to the computation condition, determine the judging result corresponding to the node data as a first numerical value, and if the node data conforms to the computation condition, determine the judging result corresponding to the node data as a second numerical value.

[0026] In an implementable manner, the calculation module is configured to: for each calculation condition, perform vector calculation between the judgment result vector corresponding to each calculation condition and the input vector based on the vector calculation instruction, to obtain a calculation result vector corresponding to each calculation condition, wherein the input vector corresponding to the first calculation condition is the data vector, and the input vector corresponding to the calculation condition after the first calculation condition is the calculation result vector corresponding to the previous calculation condition; in the calculation result vector corresponding to each calculation condition, the element in the input vector that meets the calculation condition is the calculation result of performing the corresponding calculation operation on the node data in the input vector, and the calculation result vector corresponding to the last calculation condition is the calculation result of the stencil calculation.

[0027] In an implementable manner, the first numerical value is 0, and the second numerical value is 1.

[0028] In a third aspect, a computing device is provided, which includes a memory and a processor, the memory stores at least one instruction, and the processor executes the at least one instruction to perform the method in the first aspect and / or any implementable manner in the first aspect.

[0029] In a fourth aspect, a computer readable storage medium is provided, which stores computer program code, when the computer program code is executed by a computer device, the computer device performs the method in the first aspect and / or any implementable manner in the first aspect.

[0030] In a fifth aspect, a computer program product containing instructions is provided, when the computer program product is run on a computer device, the computer device performs the method in the first aspect and / or any implementable manner in the first aspect. BRIEF DESCRIPTION OF DRAWINGS

[0031] Figure 1 is a structural schematic diagram of a structured grid provided by an embodiment of the present application;

[0032] Figure 2 is a structural schematic diagram of an unstructured grid provided by an embodiment of the present application;

[0033] Figure 3 is a structural schematic diagram of a computing device provided by an embodiment of the present application;

[0034] Figure 4 is a flowchart of a method for performing stencil calculation provided by an embodiment of the present application;

[0035] Figure 5 is a flowchart of a method for performing stencil calculation provided by an embodiment of the present application;

[0036] Figure 6 is a schematic diagram of a method for performing stencil calculation provided by an embodiment of the present application;

[0037] Figure 7 is a schematic diagram of a device structure for performing stencil calculation provided by an embodiment of the present application. DETAILED DESCRIPTION

[0038] In order to make the purpose, technical solutions and advantages of the present application clearer, the embodiments of the present application will be further described in detail below with reference to the drawings.

[0039] Stencil calculation is a common calculation mode in high performance computing (HPC) and is widely applied in various fields such as image processing and differential equation solving. The characteristic of stencil calculation is to traverse the node data in the calculation region and perform similar calculation processing on the node data traversed each time.

[0040] A mesh is a network structure formed by connecting a plurality of mesh nodes with each other and is commonly used to describe geometric shapes, topological structures and related physical and mathematical problems. The mesh is often encountered as a calculation object in the fields of computer graphics, computational fluid dynamics and finite element method.

[0041] The mesh can be divided into a structured mesh and an unstructured mesh in structure. As shown in Figure 1 , the structured mesh generally refers to a mesh in which the edges between the mesh nodes form a quadrilateral or hexahedron structure. As shown in Figure 2 , the unstructured mesh generally refers to a mesh in which the edges between the mesh nodes form a structure other than a quadrilateral or hexahedron, such as a triangular or tetrahedral structure.

[0042] When performing stencil calculation on the structured mesh, since the storage order of the node data of each mesh node in the structured mesh is the same as the traversal order of each mesh node in the structured mesh (that is, the calculation order of each mesh node), the scalar calculation corresponding to each mesh node in the structured mesh can generally be converted into vector calculation corresponding to a plurality of mesh nodes. In this way, the scalar calculation of the node data in the plurality of mesh nodes can be realized by sequential vector calculation, and the efficiency of performing stencil calculation on the structured mesh can be improved.

[0043] When performing stencil calculation on the unstructured mesh, since the storage order of the node data of each mesh node in the unstructured mesh is not the same as the traversal order of each mesh node in the structured mesh. As shown in Figure 2As shown, the node data of the grid nodes in the disk is stored in the order of the subscript of the grid nodes, that is, the storage order of the node data is grid node 1, grid node 2, grid node 3, …, and grid node n. When traversing the grid nodes, the grid nodes in the unstructured grid are generally traversed in the order of the edges or the grid formed by the grid nodes. For example, the order of the grid nodes is grid node 2, grid node 8, grid node 14, …, and grid node m. In this way, if the Stencil calculation of the unstructured grid is converted into vector calculation, a large number of discontinuous accesses are required to form the data vector for vector calculation.

[0044] In the related art, when performing Stencil calculation on a structured grid, an unstructured grid, or other calculation fields, if the calculation condition needs to be judged for each traversed grid node, and different calculation operations need to be performed on the node data according to the judgment result. In this case, the scalar calculation corresponding to each grid node cannot be converted into vector calculation, resulting in low efficiency of performing Stencil calculation.

[0045] Figure 3 FIG. 1 is a structural schematic diagram of a computing device provided by an embodiment of the present application. The computing device can be used to perform the Stencil calculation method provided by the embodiment of the present application, can convert the Stencil calculation of an unstructured grid into vector calculation, and can also convert the Stencil calculation with a calculation condition into vector calculation, thereby improving the efficiency of performing Stencil calculation. Figure 3 As shown, the computing device 300 can include a bus 302, a processor 304, a memory 306, and optionally, a communication interface 308. The processor 304, the memory 306, and the communication interface 308 communicate through the bus 302. The computing device 300 can be a server or a terminal device. It should be understood that the number of processors and memories in the computing device 300 is not limited by the present application. The computing device 300 can be a device running a model, which can be a terminal or a server. When the computing device 300 is a terminal, the computing device 300 includes but is not limited to a desktop computer, a mobile phone, a notebook computer, a tablet computer, etc. When the computing device 300 is a server, the computing device 300 can be a single server or a server cluster composed of multiple servers, and can be a physical machine or a virtual machine, a container, etc. which is virtualized through virtual technology.

[0046] The bus 302 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 3 only one bus or one type of bus is represented by a single line, but this is not intended to limit the scope of the application. The bus 302 can include a path for transmitting information between various components (for example, the memory 306, the processor 304, the communication interface 308) of the computing device 300.

[0047] The processor 304 can include any one or more of a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a neural network processing unit (NPU), etc. Among them, the processor 304 can further include a vector operation unit for performing vector calculation after stencil calculation conversion to improve the efficiency of stencil calculation.

[0048] The memory 306 can include a volatile memory such as a random access memory (RAM). The memory 306 can also include a non-volatile memory such as a read-only memory (ROM), a flash memory, a mechanical hard disk drive (HDD), or a solid state drive (SSD). The memory 106 stores executable program code, and the processor 104 executes the executable program code to implement the stencil calculation method provided by the embodiments of the application.

[0049] The communication interface 308 uses a transceiver module such as but not limited to a network interface card, a transceiver, etc. to realize the communication between the computing device 300 and other devices or communication networks.

[0050] Figure 4 The method provided by the embodiments of the application is a method for performing stencil calculation. The method can be executed by the processor in the computing device shown in the above Figure 3 The method provided by the embodiments of the application is a method for performing stencil calculation. The method can be executed by the processor in the computing device shown in the above Figure 4The steps of the method for the processor to perform the stencil calculation include:

[0051] Step 401, the processor acquires a plurality of node data included in a calculation region, and groups the plurality of node data into a data vector.

[0052] The calculation region can be a structured grid, and the processor can read the node data of each grid node stored in the memory into the memory. Then the node data of each grid node stored in the memory can be read into a vector register through a vector read instruction.

[0053] In an example, the node data can be grouped into a data vector in a traversal order of the node data in the calculation region. When the node data in the unstructured grid or the structured grid is traversed, the node data can be traversed in an order of edges connecting the grid nodes, or the node data can be traversed in an order of polygons formed by the grid nodes. Correspondingly, there can be scalar calculation on each node data, or there can be scalar calculation between a plurality of grid nodes connected by each edge or each polygon. For example, summation processing can be performed on the node data corresponding to the two grid nodes connected by each edge.

[0054] When scalar calculation is required between a plurality of grid nodes connected by each edge or each polygon, the traversed node data can be grouped into a plurality of data vectors. Each data vector corresponds to a grid node at a certain position connected by each edge or each polygon. For example, when summation processing is required on the node data corresponding to the two grid nodes connected by each edge, the node data corresponding to the left grid node connected by each edge can be grouped into a data vector, and the node data corresponding to the right grid node connected by each edge can be grouped into a data vector. In this way, the addition operation between the grid nodes connected by each edge can be realized by performing vector addition operation on the two data vectors.

[0055] Step 402, according to at least one calculation condition included in the stencil calculation, the plurality of node data is judged to obtain a judgment result corresponding to each calculation condition of each node data.

[0056] The calculation condition can be an if judgment statement. The calculation condition included in the stencil calculation can be one or multiple. In the process of stencil calculation, for each calculation node in each iteration, the calculation condition included in the stencil calculation is judged, and then a corresponding calculation operation is performed on the calculation node in the iteration according to the judgment result. When the calculation condition included in the stencil calculation is multiple, the node data can only satisfy one of the calculation conditions. For example, the stencil calculation includes two calculation conditions, which are to judge whether the node data is odd or even. When the node data is odd, the node data can be added by 1, and when the node data is even, the node data can be added by 2.

[0057] In an example, the judgment object of the calculation condition can be node data, for example, the calculation condition can judge whether the node data is odd, even or greater than a specified value. Or the calculation condition can also be to determine whether the calculation result is in a specified numerical range after a specified calculation on the node data. It should be noted that the setting of the calculation condition is related to the specific business involving the stencil calculation, and the examples provided by the embodiments of the present application are only exemplary examples for understanding the scheme.

[0058] In implementation, the judgment results of each node data corresponding to each calculation condition can be judged in turn according to the order of traversal of the node data. Among them, for each node data, if the node data does not meet the calculation condition, the judgment result corresponding to the node data is determined as a first numerical value, and if the node data meets the calculation condition, the judgment result corresponding to the node data is determined as a second numerical value. In an example, the first numerical value can be 0, and the second numerical value can be 1, or the first numerical value can be 1, and the second numerical value can be 0, etc.

[0059] Step 403, for each calculation condition, the judgment results of the multiple node data corresponding to the calculation condition are combined to form a judgment result vector, and a judgment result vector corresponding to the calculation condition is obtained.

[0060] In implementation, for any calculation condition, the multiple node data can be judged according to the order of traversal of the node data, and the judgment result of each node data corresponding to the calculation condition is obtained. After obtaining the judgment result of each node data corresponding to the calculation condition, the judgment result of each node data corresponding to the calculation condition can be combined in order to form a judgment result vector, and then the judgment result vector corresponding to the calculation condition can be obtained. In an example, the judgment result obtained for each calculation condition can be combined in order to form a judgment result vector according to the order of traversal of the node data.

[0061] In addition, corresponding to the example of step 401, when the data vector composed of multiple node data is multiple, the determination results corresponding to each calculation condition of the multiple node data can be composed into a determination result vector corresponding to each data vector in step 403. That is, each data vector and the corresponding determination result vector have the same length, and the value of each position in the determination result vector can be used to indicate whether the node data at the same position in the corresponding data vector satisfies the calculation condition.

[0062] Step 404, based on the data vector and the determination result vector corresponding to each calculation condition, performing the calculation operation corresponding to each calculation condition in the stencil calculation to obtain the calculation result of the stencil calculation.

[0063] In implementation, after obtaining the data vector and the determination result vector corresponding to each calculation condition in the stencil calculation, the vector calculation instruction can be used to perform the vector calculation on the data vector and the determination result vector corresponding to each calculation condition in the vector operation unit in the processor, so that each node data performs the calculation operation corresponding to the calculation condition it satisfies. After completing the stencil calculation, the memory storage space applied for in step 401 can be released.

[0064] The processor performing step 404 can be the same as or different from the processor performing steps 401-403. For example, the processor performing steps 401-404 can all be CPUs, and the vector operation unit performing the operation of the determination result vector and the data vector can be a vector operation unit included in the CPU. Alternatively, the processor performing steps 401-403 can be a CPU, and the processor performing step 404 can be an NPU, a GPU, etc., that is, the vector operation unit performing the operation of the determination result vector and the data vector can be a vector operation unit included in the NPU or the GPU. In this case, the determination result vector and the data vector to be calculated can be operated to the NPU or the GPU by the CPU before step 404.

[0065] In an example, for each calculation condition, the vector calculation instruction is used to sequentially perform the vector calculation of the determination result vector corresponding to each calculation condition and the input vector to obtain the calculation result vector corresponding to each calculation condition, wherein the input vector corresponding to the first calculation condition is the data vector, and the input vector corresponding to the calculation condition after the first calculation condition is the calculation result vector corresponding to the previous calculation condition; in the calculation result vector corresponding to each calculation condition, the calculation result of the corresponding calculation operation performed on the node data in the input vector that satisfies the calculation condition is the element in the input vector that is updated, and the calculation result vector corresponding to the last calculation condition is the calculation result of the stencil calculation.

[0066] In implementation, the computing operation corresponding to each computing condition can be executed in sequence according to the data vector and the judgment result vector corresponding to each computing condition, and the execution sequence of the computing operation corresponding to multiple computing conditions is not limited.

[0067] In the process of executing the computing operation corresponding to each computing condition in sequence, the computing operation corresponding to the first computing condition can be implemented through vector calculation of the judgment result vector of the first computing condition and the data vector. Through the vector calculation of the judgment result vector of the first computing condition and the data vector, the node data in the data vector satisfying the first computing condition can be executed to perform the corresponding computing operation.

[0068] Wherein, the specific execution process of the vector calculation corresponding to each computing condition is not introduced here.

[0069] For the node data in the data vector satisfying the first computing condition, after executing the vector operation, the corresponding calculation result in the calculation result vector is located at the same position as the node data in the data vector, and the calculation result is the calculation result of the node data executing the corresponding computing operation. For the node data in the data vector not satisfying the first computing condition, after executing the vector operation, the corresponding calculation result in the calculation result vector is located at the same position as the node data in the data vector, and the value corresponding to the calculation result is still the value of the node data.

[0070] In this way, after executing the vector calculation corresponding to the first computing condition, the execution result of the node data satisfying the first computing condition executing the corresponding computing operation can be obtained. Then, the calculation result vector corresponding to the first computing condition and the judgment result vector corresponding to the second computing condition can be calculated. The calculation result vector corresponding to the second computing condition obtained in this way can include the calculation result of the node data satisfying the second computing condition executing the corresponding computing operation. That is, the calculation result vector corresponding to the second computing condition has updated elements relative to the calculation result vector of the first computing condition, that is, the calculation result of the node data satisfying the second computing condition executing the corresponding computing operation in the calculation result vector of the first computing condition. That is, the calculation result vector corresponding to the second computing condition includes the calculation result of the node data executing the computing operation satisfying the first computing condition, the calculation result of the node data executing the computing operation satisfying the second computing condition, and the node data not satisfying the first computing condition and the second computing condition.

[0071] Similarly, for each calculation condition after the first calculation condition, the calculation operation corresponding to the node data meeting the current calculation condition can be realized by performing vector calculation of the calculation result vector corresponding to the previous calculation condition and the judgment result vector corresponding to the current calculation condition. In this way, the calculation result vector corresponding to the last calculation condition obtained includes the result data of each node data performing the corresponding calculation operation.

[0072] In addition, corresponding to the example of step 401, when the data vector composed of multiple node data is multiple, after performing vector operation on each data vector and multiple judgment result vectors, the obtained multiple calculation result vectors can be subjected to corresponding vector operation to realize the scalar calculation between multiple grid nodes connected by each edge or each polygon described in step 401.

[0073] In an example, three calculation conditions are included in the stencil calculation, and the corresponding data vector can be [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]. Among them, the first three elements in the data vector meet the first calculation condition, the middle four elements in the data vector meet the second calculation condition, and the last three elements in the data vector meet the third calculation condition. The judgment result vector corresponding to the first calculation condition can be [1, 1, 1, 0, 0, 0, 0, 0, 0, 0], the judgment result vector corresponding to the second calculation condition can be [0, 0, 0, 1, 1, 1, 1, 0, 0, 0], and the judgment result vector corresponding to the third calculation condition can be [0, 0, 0, 0, 0, 0, 0, 1, 1, 1].

[0074] After performing vector calculation of the judgment result vector corresponding to the first calculation condition and the data vector, the first calculation result vector [a1, a2, a3, 3, 4, 5, 6, 7, 8, 9] can be obtained, wherein “a1”, “a2”, “a3” are respectively the calculation results obtained by performing the calculation operation corresponding to the first calculation condition on the first three elements in the data vector.

[0075] After performing vector calculation of the judgment result vector corresponding to the second calculation condition and the first calculation result vector, the second calculation result vector [a1, a2, a3, b1, b2, b3, b4, 7, 8, 9] can be obtained, wherein “b1”, “b2”, “b3”, “b4” are respectively the calculation results obtained by performing the calculation operation corresponding to the second calculation condition on the middle four elements in the data vector.

[0076] The third calculation condition corresponds to the judgment result vector and the second calculation result vector after vector calculation, and the third calculation result vector [a1, a2, a3, b1, b2, b3, b4, c1, c2, c3] can be obtained, wherein "c1", "c2", "c3", "c4" are respectively the calculation results obtained by performing the calculation operation corresponding to the third calculation condition on the last three elements in the data vector. In this way, the third calculation result vector obtained is the calculation result of performing the stencil calculation.

[0077] The vector calculation corresponding to each calculation condition is illustrated as follows:

[0078] 1. Add operation changes to multiply-accumulate operation

[0079] If the calculation operation corresponding to the calculation condition is to add the node data to the specified value, the corresponding vector calculation can be the multiply-accumulate of the specified value vector composed of the input vector, the judgment result vector and the specified value. For example, the judgment result vector A can be [1, 1, 1, 0, 0, 0, 0, 0, 0, 0], the specified value vector B is [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], and the input vector C is [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]. Among them, the first three elements of the input vector satisfy the calculation condition, that is, the first three elements of the input vector need to be added by 1. The corresponding vector calculation can be the multiplication of the judgment result vector A and the specified value vector B, and then added to the input vector C. That is, the calculation result vector S[i] = A[i]*B[i]+C[i], and the calculation result vector S = [1, 2, 3, 3, 4, 5, 6, 7, 8, 9].

[0080] 2. Assignment changes to exclusive weighting

[0081] If the calculation operation corresponding to the calculation condition is to assign the node data, the corresponding vector calculation can be the exclusive weighting of the input vector, the judgment result vector and the assignment data composed of the assignment vector. For example, the judgment result vector A can be [0, 0, 0, 1, 1, 1, 1, 0, 0, 0], the assignment vector B is [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], and the input vector C is [1, 2, 3, 3, 4, 5, 6, 7, 8, 9]. Among them, the middle four elements of the input vector satisfy the calculation condition, that is, the middle four elements of the input vector are assigned to 1. The corresponding vector calculation can be the exclusive weighting of the assignment vector B and the corresponding elements of the input vector C, that is, S[i] = (1-A[i])*C[i]+A[i]*B[i]. The calculation result vector S = [1, 2, 3, 1, 1, 1, 1, 7, 8, 9].

[0082] 3. Multiplication changes to multi-step multiplication

[0083] If the calculation operation corresponding to the calculation condition is multiplication of the node data and a specified value, the corresponding vector calculation can be multi-step multiplication of the input vector, the judgment result vector and the specified value vector. For example, the judgment result vector A can be [0, 0, 0, 0, 0, 0, 0, 1, 1, 1], the assignment vector B is [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], and the input vector C is [1, 2, 3, 1, 1, 1, 1, 7, 8, 9]. Among them, the last three elements of the input vector satisfy the calculation condition, that is, the last three elements of the input vector need to be multiplied by 2. The corresponding vector calculation can be the multiplication of the judgment result vector A, the assignment vector B and the input vector C, and then the mutual exclusive weighting with the input vector C, that is, S[i] = C[i] * A[i] * B[i] + (1-A[i])*C[i]. The calculation result vector S = [1, 2, 3, 1, 1, 1, 1, 14, 16, 18].

[0084] It can be seen that the vector calculation of the input vector, the judgment result vector and the like can replace the sequential judgment processing of the original node data and the execution of the scalar calculation of the node data according to the judgment result, so that the efficiency of the stencil calculation can be improved.

[0085] The above is an exemplary example of converting the scalar calculation in the original stencil calculation into vector calculation. According to different businesses involved in the stencil calculation, other types of scalar calculations can also be included in the stencil calculation. However, for any type of scalar calculation, after being converted into vector calculation, the value corresponding to the node data in the calculation result vector that does not satisfy the calculation condition in the data vector can be kept unchanged by the judgment result vector, and the value corresponding to the node data in the calculation result vector that satisfies the calculation condition in the data vector is the calculation result of the original scalar calculation performed on the node data.

[0086] In the embodiments of the present application, each node data is judged by each calculation condition in advance to obtain the judgment result vector corresponding to each calculation condition, and then the vector calculation is performed on the data vector composed of the multiple node data by the judgment result vector corresponding to each calculation condition, so that each node data performs the calculation operation corresponding to the calculation condition it satisfies. It can be seen that the method for executing the stencil calculation provided by the embodiments of the present application can convert the stencil calculation including the calculation condition into vector calculation, and thus the efficiency of executing the stencil calculation can be improved.

[0087] Figure 5 is a flow chart of a method for converting the stencil calculation of the unstructured grid into vector calculation provided by the embodiments of the present application. Correspondingly, the calculation region in the step 401 can also be an unstructured grid, and the processing of the method includes:

[0088] Step 501: Allocate memory storage space for data from multiple nodes in memory.

[0089] The size of the memory storage space allocated for multiple node data in memory can be consistent with the size of the storage space occupied by the multiple node data in the storage device (such as a hard disk).

[0090] Step 502: Map the data of multiple nodes from the original storage space to the memory storage space according to the traversal order of the data of multiple nodes in the computing area.

[0091] After allocating memory storage space in memory, the storage address of each node's data in the original storage space can be obtained sequentially according to the traversal order of the data from multiple nodes, and then the storage address of each node's data in the memory storage space can be determined accordingly. The data from multiple nodes is stored contiguously in the memory storage space according to the traversal order.

[0092] After obtaining the storage address of each node's data in the original storage space and the storage address of each node's data in the memory storage space, a mapping relationship between the node data in the original storage space and the memory storage space can be established. Then, the multiple node data stored in the original storage space can be mapped to the memory storage space in traversal order. The mapping process is prior art, and will not be described in detail in this embodiment.

[0093] Step 503: Based on the vector read instruction, read data from multiple nodes in the memory storage space to obtain a data vector.

[0094] After mapping multiple node data to the memory storage space, the processor can continuously read multiple node data from the memory storage space through vector read instructions, and store the multiple node data into the vector register, thereby obtaining vector data composed of multiple node data.

[0095] like Figure 6 As shown, the storage order of the node data corresponding to the grid on the hard disk is b, d, c, a, and the corresponding traversal order is a, b, c, d. The CPU can rearrange b, d, c, a into memory according to the traversal order. In this way, the NPU can use vector loading instructions to load a, b, c, d into the NPU's vector register according to the storage addresses of a, b, c, d in memory, and then perform vector operations on the data vector composed of a, b, c, d.

[0096] In an example, the processor can also record a mapping order of the node data, and after obtaining a vector calculation corresponding to the stencil calculation performed on the data vector, each result data in the calculation result vector can be remapped to the memory according to the mapping order, and then the result data can be stored in the memory according to the storage order of the node data in the original storage space.

[0097] In implementation, the method provided by the embodiments of the present application can be set as a function added to a corresponding mathematical library or an application involving stencil calculation. The function can provide a mapping interface, a remapping interface, a carrying interface, a conditional judgment interface, and the like. The application involving stencil calculation can realize the node data mapping, remapping, carrying, and the like involved in the above embodiments by calling the interfaces provided by the function.

[0098] The method for converting the stencil calculation of the unstructured grid to the vector calculation provided by the embodiments of the present application can map the plurality of node data to be subjected to the stencil calculation to the memory according to the traversal order. In this way, the non-continuous access to the plurality of node data can be avoided, and then the stencil calculation of the unstructured grid can be realized through the vector calculation, and the efficiency of the stencil calculation can be improved.

[0099] For the stencil calculation, the node data in the grid can need to be calculated multiple times. In this way, according to the embodiments of the present application, after the node data is mapped to the memory, the node data can be continuously accessed through the mapping address of the node data in the memory in each traversal, and in this way, the non-continuous access to the node data in each traversal can be avoided, and the efficiency of the stencil calculation can be further improved.

[0100] Based on the same inventive concept, the embodiments of the present application also provide a device for performing a stencil calculation, the stencil calculation including at least one calculation condition and a corresponding calculation operation. The device can be a computing device for performing the stencil calculation method. Figure 7 is a structural schematic diagram of a device for performing a stencil calculation provided by the embodiments of the present application, as shown in Figure 7 The device includes:

[0101] The obtaining module 710 is configured to obtain a plurality of node data included in a calculation region, and group the plurality of node data into a data vector. The obtaining module 710 can be specifically configured to realize the obtaining function in the above step 401 and the implicit steps thereof.

[0102] The judging module 720 is configured to perform judging processing on the plurality of node data according to at least one calculation condition included in the stencil calculation, to obtain a judging result corresponding to each calculation condition for each node data. The judging module 720 can be specifically configured to implement the judging function in the step 402 and the implied steps.

[0103] The generating module 730 is configured to, for each calculation condition, compose a judging result vector by using the judging result corresponding to the calculation condition for the plurality of node data, to obtain a judging result vector corresponding to the calculation condition. The generating module 730 can be specifically configured to implement the generating function in the step 403 and the implied steps.

[0104] The calculating module 740 is configured to perform a calculation operation corresponding to each calculation condition in the stencil calculation based on the data vector and the judging result vector corresponding to each calculation condition, to obtain a calculation result of the stencil calculation. The calculating module 740 can be specifically configured to implement the calculating function in the step 404 and the implied steps.

[0105] In an implementable manner, the calculation region is a structured grid or an unstructured grid.

[0106] In an implementable manner, the calculation region is an unstructured grid, and the obtaining module 710 is configured to:

[0107] apply a memory storage space in the memory for the plurality of node data;

[0108] map the plurality of node data from an original storage space to the memory storage space according to a traversal order of the plurality of node data in the calculation region;

[0109] read the plurality of node data from the memory storage space based on a vector reading instruction, to obtain the data vector.

[0110] In an implementable manner, the generating module 730 is configured to:

[0111] for each calculation condition, compose a judging result vector by using the judging result corresponding to the calculation condition for the plurality of node data according to a traversal order of the plurality of node data in the calculation region, to obtain a judging result vector corresponding to the calculation condition.

[0112] In an implementable manner, the judging module 720 is configured to:

[0113] perform judging processing on the plurality of node data according to at least one calculation condition included in the stencil calculation;

[0114] For each node data, if the node data does not satisfy the calculation condition, a determination is made that the judgment result corresponding to the node data is a first numerical value, and if the node data satisfies the calculation condition, a determination is made that the judgment result corresponding to the node data is a second numerical value.

[0115] In an implementable manner, the calculation module 740 is configured to:

[0116] For each calculation condition, based on the vector calculation instruction, a vector calculation is performed between the judgment result vector corresponding to the calculation condition and the input vector in sequence, to obtain a calculation result vector corresponding to the calculation condition, wherein the input vector corresponding to the first calculation condition is the data vector, and the input vector corresponding to the calculation condition after the first calculation condition is the calculation result vector corresponding to the previous calculation condition; in the calculation result vector corresponding to each calculation condition, with respect to an element existing in the corresponding input vector, the calculation result of the corresponding calculation operation performed on the node data satisfying the calculation condition in the input vector, and the calculation result vector corresponding to the last calculation condition is the calculation result of the stencil calculation.

[0117] In an implementable manner, the first numerical value is 0, and the second numerical value is 1.

[0118] It should be noted that the apparatus for performing stencil calculation provided in the above embodiments is only used as an example for performing stencil calculation by dividing the above functional modules, and in actual applications, the above functions can be completed by different functional modules according to needs, that is, the internal structure of the calculation device or program for performing stencil calculation is divided into different functional modules to complete all or part of the functions described above. In addition, the apparatus for performing stencil calculation provided in the above embodiments and the method embodiment for performing stencil calculation belong to the same concept, and the specific implementation process is described in detail in the method embodiment, which will not be repeated here.

[0119] The embodiments of the present application further provide a computer program product containing instructions. The computer program product can be a software or program product containing instructions, which can run on a calculation device or be stored in any available medium. When the computer program product runs on at least one calculation device, the at least one calculation device is caused to execute the method for performing stencil calculation provided in the embodiments of the present application.

[0120] The embodiments of the present application further provide a computer readable storage medium. The computer readable storage medium can be any available medium or data storage device that can be accessed by a computing device and includes one or more available media or data storage devices. The available medium can be a magnetic medium, (e.g., a floppy diskette, a hard disk drive, a magnetic tape), an optical medium, (e.g., a DVD), or a semiconductor medium, (e.g., a solid state hard drive), etc. The computer readable storage medium includes instructions that instruct the computing device to perform the method of performing stencil computation according to the embodiments of the present application.

[0121] The terms "first", "second", and the like in the present application are used to distinguish between similar or identical items or elements having substantially the same function, and it should be understood that there is no logical or chronological dependency between "first" and "second", and the number and execution order are not limited. It should also be understood that although the following description uses the terms first, second, and the like to describe various elements, these elements should not be limited by the terms. These terms are only used to distinguish one element from another. For example, without departing from the scope of various examples, a first value can be referred to as a second value, and similarly, a second value can be referred to as a first value. The first value and the second value can both be referred to as a value, and in some cases, can be separate and distinct values.

[0122] The term "at least one" in the present application means one or more, and the term "a plurality" in the present application means two or more.

[0123] The above description is only a specific embodiment of the present application, but the protection scope of the present application is not limited thereto, and any skilled person in the art can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present application, and these modifications or replacements should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

Claims

1. A method of performing a stencil computation, the method comprising: The stencil calculation includes at least one calculation condition and a corresponding calculation operation, and the method includes: Obtaining a plurality of node data included in a calculation region, and in a case where the calculation region is a structured grid, grouping the plurality of node data into a data vector according to a storage order of the plurality of node data; or in a case where the calculation region is an unstructured grid, applying memory storage space to the plurality of node data in the memory, and mapping the plurality of node data from original storage space to the memory storage space according to a traversal order of the plurality of node data in the calculation region; reading the plurality of node data from the memory storage space based on a vector reading instruction to obtain the data vector; Judging the plurality of node data according to at least one calculation condition included in the stencil calculation to obtain a judgment result corresponding to each calculation condition for each node data; For each calculation condition, grouping the judgment result corresponding to the calculation condition for the plurality of node data into a judgment result vector to obtain a judgment result vector corresponding to the calculation condition; Based on the data vector and the judgment result vector corresponding to each calculation condition, performing a calculation operation corresponding to each calculation condition in the stencil calculation to obtain a calculation result of the stencil calculation.

2. The method of claim 1, wherein, The grouping of the judgment result corresponding to the calculation condition for the plurality of node data into a judgment result vector to obtain a judgment result vector corresponding to the calculation condition for each calculation condition includes: For each calculation condition, grouping the judgment result corresponding to the calculation condition for the plurality of node data into a judgment result vector according to a traversal order of the plurality of node data in the calculation region to obtain a judgment result vector corresponding to the calculation condition.

3. The method according to claim 1 or 2, characterized in that, The judging of the plurality of node data according to at least one calculation condition included in the stencil calculation to obtain a judgment result corresponding to each calculation condition for each node data includes: Judging the plurality of node data according to at least one calculation condition included in the stencil calculation; For each node data, if the node data does not meet the calculation condition, determining that a judgment result corresponding to the node data is a first numerical value, and if the node data meets the calculation condition, determining that the judgment result corresponding to the node data is a second numerical value.

4. The method according to claim 1 or 2, characterized in that, The performing of a calculation operation corresponding to each calculation condition in the stencil calculation based on the data vector and the judgment result vector corresponding to each calculation condition to obtain a calculation result of the stencil calculation includes: For each calculation condition, sequentially performing vector calculation of an input vector and a judgment result vector corresponding to the calculation condition based on a vector calculation instruction to obtain a calculation result vector corresponding to each calculation condition, wherein, The input vector corresponding to the first calculation condition is the data vector, and the input vector corresponding to the calculation condition after the first calculation condition is the calculation result vector corresponding to the previous calculation condition; in the calculation result vector corresponding to each calculation condition, the element existing in the corresponding input vector is updated, and the calculation result of the corresponding calculation operation performed on the node data in the input vector satisfying the calculation condition is the calculation result of the corresponding calculation operation, and the calculation result vector corresponding to the last calculation condition is the calculation result of the stencil calculation.

5. The method of claim 3, wherein, The first numerical value is 0, and the second numerical value is 1.

6. An apparatus for performing a stencil computation, the apparatus comprising: The stencil calculation includes at least one calculation condition and a corresponding calculation operation, and the device includes: An acquisition module is configured to acquire a plurality of node data included in a calculation region, and in a case where the calculation region is a structured grid, the plurality of node data is grouped into a data vector according to a storage order of the plurality of node data; or in a case where the calculation region is an unstructured grid, memory storage space is applied for the plurality of node data in the memory, and the plurality of node data is mapped from original storage space to the memory storage space according to a traversal order of the plurality of node data in the calculation region; and the plurality of node data is read from the memory storage space based on a vector reading instruction to obtain the data vector; A judgment module is configured to perform judgment processing on the plurality of node data according to at least one calculation condition included in the stencil calculation to obtain a judgment result corresponding to each calculation condition for each node data. A generation module is configured to group the judgment result corresponding to each calculation condition for the plurality of node data into a judgment result vector to obtain a judgment result vector corresponding to the calculation condition for each calculation condition. A calculation module is configured to perform a calculation operation corresponding to each calculation condition in the stencil calculation based on the data vector and the judgment result vector corresponding to each calculation condition to obtain a calculation result of the stencil calculation.

7. The apparatus of claim 6, wherein, The generation module is configured to: For each calculation condition, the judgment result corresponding to the calculation condition for the plurality of node data is grouped into a judgment result vector according to the traversal order of the plurality of node data in the calculation region to obtain the judgment result vector corresponding to the calculation condition.

8. The apparatus of claim 6 or 7, wherein, The judgment module is configured to: Perform judgment processing on the plurality of node data according to at least one calculation condition included in the stencil calculation; For each node data, if the node data does not meet the calculation condition, the judgment result corresponding to the node data is determined as a first numerical value, and if the node data meets the calculation condition, the judgment result corresponding to the node data is determined as a second numerical value.

9. The apparatus of claim 6 or 7, wherein, The calculation module is configured to: For each calculation condition, the judgment result vector corresponding to each calculation condition and the input vector are sequentially subjected to vector calculation based on a vector calculation instruction to obtain a calculation result vector corresponding to each calculation condition, wherein The input vector corresponding to the first calculation condition is the data vector, and the input vector corresponding to the calculation condition after the first calculation condition is the calculation result vector corresponding to the previous calculation condition; in the calculation result vector corresponding to each calculation condition, the element existing in the corresponding input vector is updated, and the calculation result of the corresponding calculation operation performed on the node data satisfying the calculation condition in the input vector is the calculation result of the corresponding calculation operation, and the calculation result vector corresponding to the last calculation condition is the calculation result of the stencil calculation.

10. The apparatus of claim 8, wherein, The first numerical value is 0, and the second numerical value is 1.

11. A computing device, comprising: The computing device comprises a memory and a processor, the memory stores at least one instruction, and the processor executes the at least one instruction to execute the method in any one of claims 1 to 5.

12. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer program code, when the computer program code is executed by the computer device, the computer device executes the method in any one of claims 1 to 5.

13. A computer program product comprising instructions, characterized in that, When the computer program product runs on the computer device, the computer device executes the method in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Method and system for accelerating uniform grid Stencil calculation based on GPU (Graphics Processing Unit) mixing precision

    CN115660936A

  • Stencil mask and method of producing the same, semiconductor device produced using the stencil mask and method of producing the semiconductor device

    US20030022496A1

Cited By

  • Method and apparatus for stencil computation, and computation device

    EP4764842A1

  • Method and apparatus for stencil computation, and computation device

    WO2025050763A1