Method and system for extending a general parallel program into a multi-core processor parallel program

By identifying CUDA kernel functions and parameters, mapping and allocating tasks, combined with MPI or DMA communication, the problem of CUDA programs running on the Sunway SW26010 processor is solved, efficient program transplantation and parallel computing are achieved, costs are reduced, and full utilization is achieved It improves the parallel acceleration capability of SW26010 processor.

CN118295819BActive Publication Date: 2024-09-24STATE OCEANIC ADMINISTRATION NORTH SEA INFORMATION CENT (STATE OCEANIC ADMINISTRATION BEIHAI ARCHIVES)
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410722062.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-05
Publication Date
2024-09-24
Estimated Expiration
2044-06-05

AI Technical Summary

Technical Problem

CUDA parallel programs cannot be run directly on the supercomputer of Sunway SW26010 processor, resulting in low code conversion efficiency and high cost, making it impossible to fully utilize tens of millions of many-cores for large-scale scientific calculations.

Method used

By identifying the kernel function in the CUDA main program, determining the position and parameter values ​​of the kernel function in the main function, mapping the host code of the CUDA program to the task main core code of the SW26010 processor, allocating computing data blocks and tasks to the computing main core and Perform parallel computations from the core array and communicate via MPI or DMA, merging the results.

Benefits of technology

It realizes the rapid conversion of CUDA parallel programs into SW26010 processor parallel programs, improves program transplantation efficiency, has good many-core scalability, reduces costs, and effectively takes advantage of the parallel acceleration advantages of the SW26010 processor.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118295819B
    Figure CN118295819B
Patent Text Reader

Abstract

The present invention belongs to the field of computer technology, and relates to a method and system for expanding a general parallel program into a multi-core processor parallel program, and the steps of the method are: determining the position of a kernel function in a CUDA main program in a main function; determining the kernel function input parameter value; mapping the host code of the CUDA program to the task main core code of the SW26010 processor, and clarifying the number of task main cores; determining the number of computing main cores of the SW26010 processor and the number of slave cores in a single computing main core according to the parameter value; the task main core assigns computing data blocks to the computing main core, and the computing main core assigns computing tasks to the slave core array; the slave core executes the computing task to obtain the computing result; the computing main core collects all the computing results in the slave core array; the task main core merges the collected data block computing results of all computing main cores into the final result. The present invention effectively improves the efficiency of program transplantation, and the cost is low.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method and system for expanding a general parallel program into a multi-core processor parallel program. Background Art

[0002] CUDA (Compute Unified Device Architecture) is a computing platform launched by graphics card manufacturer NVIDIA. CUDA is a general-purpose parallel computing architecture launched by NVIDIA that enables graphics processing units (GPUs) to solve complex computing problems. It includes the CUDA instruction set architecture (ISA) and the parallel computing engine inside the GPU. Developers can use C language to write programs for the CUDA architecture, and the programs written can run at ultra-high performance on processors that support CUDA. So far, the sales of CUDA-based GPUs have reached millions, and software developers, scientists, and researchers are using CUDA in various fields, including image and video processing, computational biology and chemistry, fluid dynamics simulation, CT image reconstruction, seismic analysis, and ray tracing.

[0003] GPU is not an independently operated computing platform, but needs to work with CPU and can be regarded as a coprocessor of CPU. Therefore, GPU parallel computing actually refers to the heterogeneous computing architecture of CPU+GPU. Figure 1 As shown in the figure, in a heterogeneous computing architecture, the GPU and CPU are connected together through the PCIe bus to work together. Among them: the CPU has fewer computing cores, but can implement complex logical operations and is suitable for control-intensive tasks. The GPU includes more computing cores and is suitable for data-parallel computing-intensive tasks. Therefore, the heterogeneous computing platform based on CPU+GPU can complement each other's advantages. The CPU is responsible for processing logically complex serial programs, while the GPU focuses on processing computing-intensive parallel programs.

[0004] In a CPU+GPU heterogeneous computing platform, the location of the CPU is called the host, and the location of the GPU is called the device. The typical CUDA program execution process is as follows:

[0005] (1) Allocate host memory and initialize data;

[0006] (2) Allocate device memory and copy data from the host to the device;

[0007] (3) Call the CUDA kernel function to complete the specified operation on the device;

[0008] (4) Copy the calculation results on the device to the host;

[0009] (5) Release the memory allocated on the device and host.

[0010] The most important process in the above process is to call the CUDA kernel function to perform parallel computing. The kernel function is a function that is executed in parallel in the device thread. When calling it, you need to use <<<grid, block> >> to specify the number of threads to be executed by the kernel function. Its thread structure is as follows Figure 2 As shown in the figure, all threads started by a kernel function are called a grid. Threads on the same grid share the same global memory space, and the grid can be divided into many thread blocks. A thread block contains multiple threads.

[0011] The Sunway TaihuLight supercomputer uses the Sunway 26010 processor. Figure 3 As shown in the figure, the processor adopts a master-slave core architecture. One processor contains four core groups (CGs), each of which contains one master core (MPE), one 8*8 slave core array (CPE) and one memory controller (MC). The peak computing power of a single processor is 3TFlops, and the theoretical peak performance of the whole machine reaches 125.4PFlops. The core operating frequency is 1.5GHz, and the memory access bandwidth is 130GB / s. The Sunway TaihuLight supercomputer has powerful heterogeneous multi-core parallel computing capabilities. A Sunway multi-core program usually consists of three parts:

[0012] (1) Main function: The main program before multi-core acceleration. It runs on the pure main core and calls the Shenwei main core function for multi-core acceleration.

[0013] (2) Shenwei main kernel function: declare the slave kernel function, set the slave kernel function parameters, spawn the slave kernel function to the slave kernel array and start the slave kernel array calculation.

[0014] (3) Shenwei slave core function: a function spawned by the master core function to the slave core and executed asynchronously by the slave core.

[0015] Both GPU and Shenwei SW26010 processor belong to heterogeneous many-core architecture. CUDA parallel programs based on GPU can realize multi-core parallel computing of kernel functions on GPU by calling CUDA parallel interface, while MPI+Athread programs based on Shenwei SW26010 processor can also realize many-core parallel accelerated computing on SW26010 heterogeneous many-core processor. However, due to the inconsistency between the two in many-core architecture, compiler and parallel acceleration library, CUDA parallel programs cannot be directly run on supercomputers based on Shenwei SW26010 processor. At present, there are a large number of GPU-based code programs in hot fields such as artificial intelligence and scientific computing. Converting these code programs into parallel programs running on Shenwei SW26010 processor can make full use of tens of millions of cores for large-scale scientific computing and effectively shorten the simulation calculation time.

[0016] Due to the inconsistency between GPU and Shenwei SW26010 processor in processor architecture, program compiler and parallel acceleration library, CUDA parallel programs cannot be directly run on supercomputers with Shenwei SW26010 processor. In hot fields such as artificial intelligence and scientific computing, there are a large number of GPU-based code programs. If these codes are converted into parallel code programs that can be run by Shenwei SW26010 processor, developers need to be familiar with both GPU parallel programming and Shenwei SW26010 processor parallel programming. The code conversion efficiency is low and the cost is high. Summary of the invention

[0017] The embodiment of the present invention provides a method and system for expanding a general parallel program into a multi-core processor parallel program, which can quickly convert a CUDA parallel program into a SW26010 processor parallel program, effectively improving the program porting efficiency, and has good multi-core scalability, can effectively give play to the parallel acceleration advantages of the SW26010 processor, and is low cost.

[0018] In a first aspect, the present invention provides a method for expanding a general parallel program into a multi-core processor parallel program, comprising the following steps:

[0019] S1. Identify the kernel function in the CUDA main program and determine the location of the kernel function in the main function;

[0020] S2. According to the call of the kernel function in the main function, determine the values ​​of the number of thread blocks grid_size in the parameter grid passed into the kernel function, the number of threads in the thread block block_size, and the data calculation length data_size;

[0021] S3, map the host code of the CUDA program to the task main core code of the SW26010 processor, and specify the number of task main cores;

[0022] S4, determine the number of computing master cores mpe_size of the SW26010 processor according to the grid_size value of the kernel function, and determine the number of slave cores cpe_size in a single computing master core of the SW26010 processor according to the block_size value of the kernel function;

[0023] S5, the task master core allocates the computing data block to the computing master core, and the computing master core allocates the computing task to the slave core array;

[0024] S6, the slave core performs the computing task according to the computing master core data transmitted by the computing master core to obtain the computing result;

[0025] S7, the computing master core collects all computing results in the slave core array, and the task master core collects the data block computing results of all computing master cores;

[0026] S8. The task master core combines the calculation results of all data blocks into the final result.

[0027] In some embodiments, in step S1, the kernel function is marked by a __global__ keyword.

[0028] In some embodiments, in step S3, if the host code is executed as a single thread, the number of task main cores is 1; if the host code opens n threads, the number of task main cores is n.

[0029] In some embodiments, in step S5, the specific method of the task master core allocating the computing data block to the computing master core is:

[0030] The length of data calculation data_size is defined in the task main core. Each calculation main core obtains the calculation data block length mpeDataSizei and the starting coordinates of the calculation data block allocated to the i-th calculation main core itself based on the data calculation length data_size and the calculation main core's own ID.

[0031] After determining the data starting coordinates and data block length of each computing main core, the task main core initializes the data and distributes the corresponding data blocks to each computing main core.

[0032] In some embodiments, the method for obtaining the length of the calculated data block mpeDataSizei and the starting coordinates of the calculated data block is:

[0033] The remainder of the calculated data is obtained by taking the modulus of the data calculation length data_size and the number of calculation main cores mpe_size;

[0034] If the remainder of the calculation data is equal to 0, the length of the calculation data block allocated to the i-th calculation main core is:

[0035] mpeDataSizei=data_size / mpe_size;

[0036] The starting coordinates of the calculation data block allocated by the i-th computing core are:

[0037] mpeDataBegini = data[0] + mpeDataSize * i;

[0038] If the calculation data remainder is not equal to 0, the number of calculation main cores is mpe_size+1, and the data calculation length of the mpe_size+1th calculation main core is the calculation data remainder.

[0039] In some embodiments, in step S5, the computing master core uses a polling algorithm to allocate computing tasks to the slave core array, and the specific steps are:

[0040] The i-th slave core obtains the i-th computing task, i satisfies i≥0 and i<64. If there are still unassigned tasks, the second round of polling begins;

[0041] The i-th slave core obtains the i+64th computing task, i satisfies i≥0 and i<64. If there are still unassigned tasks, the third round of polling begins;

[0042] … …

[0043] The i-th slave core obtains the i+64*(N-1)th computing task, where i satisfies i≥0 and i<64. If there are still unassigned tasks, the N+1th round of polling begins;

[0044] Until all the core tasks have been assigned.

[0045] In some embodiments, MPI communication is used between the task master core and the computing master core.

[0046] In some embodiments, DMA communication is used between the computing master core and the slave core.

[0047] In a second aspect, the present invention provides a system for expanding a general parallel program into a multi-core processor parallel program, which is used to implement the method for expanding a general parallel program into a multi-core processor parallel program described in the first aspect of the present invention, and is characterized by comprising:

[0048] The location determination module identifies the kernel function in the CUDA main program and determines the location of the kernel function in the main function;

[0049] The parameter value determination module determines the value of the parameter passed into the kernel function according to the call of the kernel function in the main function;

[0050] The task main core quantity determination module maps the host code of the CUDA program to the task main core code of the SW26010 processor to determine the number of task main cores;

[0051] The calculation main core number determination module determines the calculation main core number mpe_size of the SW26010 processor according to the grid_size value of the kernel function;

[0052] Slave core number determination module: Determine the number of slave cores cpe_size in a single computing master core of the SW26010 processor according to the block_size value of the kernel function;

[0053] The first allocation module is provided in the task main core and is used to allocate the computing data blocks to the computing main core.

[0054] A second allocation module, provided in the computing master core, is used to allocate computing tasks to the slave core array;

[0055] A data transmission module is provided in the computing master core and is used to transmit the computing master core data to the slave core memory space;

[0056] The task execution module is located in the slave core and is used to execute the calculation task according to the calculation data of the master core to obtain the calculation result;

[0057] A first collection module, provided in the computing master core, is used to collect all computing results in the slave core array and send the computing results of the data block;

[0058] The second collection module is provided in the task main core and is used to collect the data block calculation results of all calculation main cores;

[0059] The merging module is located in the task main core and is used to merge the calculation results of all data blocks into the final result.

[0060] Compared with the related art, the method and system for expanding a general parallel program into a multi-core processor parallel program provided by the present invention can quickly convert a CUDA parallel program into a SW26010 processor parallel program, effectively improving the program porting efficiency, and has good multi-core scalability, can effectively give play to the parallel acceleration advantages of the SW26010 processor, and is low cost. BRIEF DESCRIPTION OF THE DRAWINGS

[0061] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:

[0062] Figure 1 It is a schematic diagram of the existing CPU+CUDA heterogeneous architecture;

[0063] Figure 2 It is a two-dimensional schematic diagram of the existing CUDA thread structure;

[0064] Figure 3 It is a schematic diagram of the existing SW26010 processor structure;

[0065] Figure 4 A flowchart of a method for expanding a general parallel program into a multi-core processor parallel program according to an embodiment of the present invention;

[0066] Figure 5 This is a structural block diagram of a system for expanding a general parallel program into a multi-core processor parallel program according to an embodiment of the present invention.

[0067] In the figure: 1. Arithmetic logic unit, 2. Controller, 3. Cache, 4. Position determination module, 5. Parameter value determination module, 6. Task main core number determination module, 7. Computing main core number determination module, 8. Slave core number determination module, 9. First allocation module, 10. Second allocation module, 11. Data transmission module, 12. Task execution module, 13. First collection module, 14. Second collection module, 15. Merge module, 16. Task main core, 17. Computing main core, 18. Slave core. DETAILED DESCRIPTION

[0068] In order to make the purpose, technical scheme and advantages of the present invention more clearly understood, the present invention is described and illustrated below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. Based on the embodiments provided by the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work belong to the scope of protection of the present invention.

[0069] Obviously, the drawings described below are only some examples or embodiments of the present invention. For ordinary technicians in this field, the present invention can also be applied to other similar scenarios based on these drawings without creative work. In addition, it can also be understood that although the efforts made in this development process may be complicated and lengthy, for ordinary technicians in this field related to the content disclosed by the present invention, some changes in design, manufacturing or production based on the technical content disclosed by the present invention are just conventional technical means, and should not be understood as insufficient content disclosed by the present invention.

[0070] Reference to "embodiments" in the present invention means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present invention. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those of ordinary skill in the art that the embodiments described in the present invention may be combined with other embodiments without conflict.

[0071] Unless otherwise defined, the technical terms or scientific terms involved in the present invention shall have the usual meanings understood by persons with ordinary skills in the technical field to which the present invention belongs. The words "one", "a", "a", "the" and the like involved in the present invention do not indicate a quantity limitation and may indicate the singular or plural. The terms "include", "comprise", "have" and any of their variations involved in the present invention are intended to cover non-exclusive inclusions; for example, a process, method, system, product or device including a series of steps or modules (units) is not limited to the listed steps or units, but may also include steps or units that are not listed, or may also include other steps or units inherent to these processes, methods, products or devices. The words "connect", "connected", "coupled" and the like involved in the present invention are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The "multiple" involved in the present invention refers to two or more. "And / or" describes the association relationship of associated objects, indicating that there may be three relationships. For example, "A and / or B" may indicate: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the objects in the front and back relation are in an "or" relationship. The terms "first", "second", "third" and the like involved in the present invention are only used to distinguish similar objects and do not represent a specific ordering of the objects.

[0072] An embodiment of the present invention provides a method for expanding a general parallel program into a multi-core processor parallel program. Figure 4 is a flow chart of a method for expanding a general parallel program into a multi-core processor parallel program according to an embodiment of the present invention. Figure 4 As shown, the process includes the following steps:

[0073] S1. Identify the kernel function in the CUDA main program and determine the location of the kernel function in the main function. Specifically, the kernel function is marked by the __global__ keyword.

[0074] S2. According to the call of the kernel function in the main function, determine the values ​​of the number of thread blocks grid_size in the parameter grid passed into the kernel function, the number of threads in the thread block block_size, and the data calculation length data_size.

[0075] S3. Map the host code of the CUDA program to the task main core code of the SW26010 processor and specify the number of task main cores.

[0076] Specifically, if the host code is executed as a single thread, the number of task main cores is 1; if the host code opens n threads, the number of task main cores is n.

[0077] S4. Determine the number of computing main cores mpe_size of the SW26010 processor according to the grid_size value of the kernel function (for example: dim3 grid_size(12, 6, 8), which represents 576 (12*6*8) thread blocks in the CUDA program, and maps to the computing main core of the SW26010 processor, which needs to be expanded to 576 computing main cores to complete.). Determine the number of slave cores cpe_size in a single computing main core of the SW26010 processor according to the block_size value of the kernel function.

[0078] It should be noted that the maximum number of slave cores in a single computing master core is 64, so it is possible for a single slave core to execute multiple thread tasks. For example: dim3 block_size (5, 6, 2) means that there are 60 threads in a single thread block in the CUDA program. If it is mapped to a single computing master core of the SW26010 processor, it needs to be expanded to 60 slave cores to complete. If the number of threads in a single thread block exceeds 64, the 64 slave cores in the single computing master core will perform polling calculations.

[0079] S5, the task master core allocates the computing data block to the computing master core, and the computing master core allocates the computing task to the slave core array. It should be noted that after the computing master core obtains the computing data block, it allocates the computing task to the slave core array.

[0080] Specifically, in some embodiments, the specific method of the task master core allocating the computing data block to the computing master core is:

[0081] S51. Define the length data_size of data calculation in the task main core, and each calculation main core obtains the calculation data block length mpeDataSizei and the starting coordinates of the calculation data block allocated to the i-th calculation main core itself based on the data calculation length data_size and the calculation main core's own ID.

[0082] Specifically, the method for calculating the data block length mpeDataSizei and the starting coordinates of the data block is:

[0083] The remainder of the calculated data is obtained by taking the modulus of the data calculation length data_size and the number of calculation main cores mpe_size;

[0084] If the remainder of the calculation data is equal to 0, the length of the calculation data block allocated to the i-th calculation main core is:

[0085] mpeDataSizei=data_size / mpe_size;

[0086] The starting coordinates of the calculation data block allocated by the i-th computing core are:

[0087] mpeDataBegini = data[0] + mpeDataSize * i;

[0088] If the calculation data remainder is not equal to 0, the number of calculation main cores is mpe_size+1, and the data calculation length of the mpe_size+1th calculation main core is the calculation data remainder.

[0089] S52: After determining the data starting coordinates and data block lengths of each computing main core, the task main core initializes the data and distributes the corresponding data blocks to each computing main core.

[0090] Since the number of slave cores in the slave core array is fixed at 64, specifically, in some embodiments, the computing master core uses a polling algorithm to allocate computing tasks to the slave core array, and the specific steps are:

[0091] The i-th slave core obtains the i-th computing task, i satisfies i≥0 and i<64. If there are still unassigned tasks, the second round of polling begins;

[0092] The i-th slave core obtains the i+64th computing task, i satisfies i≥0 and i<64. If there are still unassigned tasks, the third round of polling begins;

[0093] … …

[0094] The i-th slave core obtains the i+64*(N-1)th computing task, where i satisfies i≥0 and i<64. If there are still unassigned tasks, the N+1th round of polling begins;

[0095] Until all the core tasks have been assigned.

[0096] S6. The slave core performs the computing task according to the computing master core data transmitted by the computing master core to obtain the computing result.

[0097] Specifically, after the slave core tasks in the computing master core are assigned, the computing master core transfers the computing master core data to the slave core memory space, and then the slave core performs the computing tasks. After the slave core computing tasks are completed, the computing results are returned to the computing master core.

[0098] S7, the computing main core collects all the calculation results in the slave core array. After the computing main core completes the collection of all the calculation results in the slave core array, it returns the calculation results of the data block to the task main core. The task main core collects the data block calculation results of all the computing main cores.

[0099] S8. The task master core combines the calculation results of all data blocks into the final result.

[0100] The method for expanding the above-mentioned general parallel program into a multi-core processor parallel program in the embodiment of the present invention can quickly convert the CUDA parallel program into a SW26010 processor parallel program, effectively improving the program porting efficiency, and has good multi-core scalability, can effectively give play to the parallel acceleration advantages of the SW26010 processor, and is low cost.

[0101] Specifically, in some embodiments, MPI communication is used between the task master core and the computing master core. MPI communication can achieve efficient data transmission and computing, and by optimizing the message passing mechanism, data can be quickly exchanged in parallel computing, thereby improving computing efficiency.

[0102] In some embodiments, DMA communication is used between the computing master core and the slave core. Using DMA communication can greatly improve the efficiency and speed of data transmission and reduce the load of the CPU.

[0103] It should be noted that the steps shown in the above process or the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0104] A second aspect of the present invention provides a system for expanding a general parallel program into a parallel program for many-core processors, which is used to implement the method for expanding a general parallel program into a parallel program for many-core processors described in the first aspect of the present invention. Figure 5 1 is a system structure block diagram of a general parallel program expanded into a multi-core processor parallel program according to an embodiment of the present invention. The system for expanding the general parallel program into a multi-core processor parallel program includes:

[0105] Position determination module 4, identifying the kernel function in the CUDA main program and determining the position of the kernel function in the main function;

[0106] Parameter value determination module 5, determines the value of the parameter passed into the kernel function according to the call of the kernel function in the main function;

[0107] The task main core quantity determination module 6 maps the host code of the CUDA program to the task main core code of the SW26010 processor to determine the number of task main cores;

[0108] The calculation main core quantity determination module 7 determines the calculation main core quantity mpe_size of the SW26010 processor according to the grid_size value of the kernel function;

[0109] The slave core number determination module 8 determines the number of slave cores cpe_size in a single computing master core of the SW26010 processor according to the block_size value of the kernel function;

[0110] The first allocation module 9 is provided in the task master core 16 and is used to allocate the computing data blocks to the computing master core 17.

[0111] The second allocation module 10 is provided in the computing master core 17 and is used to allocate computing tasks to the slave core array;

[0112] The data transmission module 11 is provided in the computing master core 17 and is used to transmit the computing master core data to the slave core memory space;

[0113] The task execution module 12 is provided in the slave core 18 and is used to execute the calculation task according to the calculation data of the master core to obtain the calculation result;

[0114] The first collection module 13 is provided in the computing master core 17 and is used to collect all the computing results in the slave core array and send the computing results of the data block;

[0115] The second collection module 14 is provided in the task master core 16 and is used to collect the data block calculation results of all calculation master cores;

[0116] The merging module 15 is disposed in the task master core 16 and is used to merge the calculation results of all data blocks into a final result.

[0117] The system for expanding the above-mentioned general parallel program into a multi-core processor parallel program in the embodiment of the present invention can quickly convert the CUDA parallel program into a SW26010 processor parallel program, effectively improving the program porting efficiency, and has good multi-core scalability, which can effectively give play to the parallel acceleration advantages of the SW26010 processor at low cost.

[0118] The technical features of the above-described embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above-described embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0119] The above-mentioned embodiments only express several implementation methods of the present invention, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for ordinary technicians in this field, several variations and improvements can be made without departing from the concept of the present invention, and these all belong to the protection scope of the present invention. Therefore, the protection scope of the patent of the present invention shall be subject to the attached claims.

Claims

1. A method for expanding a general parallel program into a multi-core processor parallel program, characterized in that: The following steps are involved: S1. Identify the kernel function in the CUDA main program and determine the location of the kernel function in the main function; S2. According to the call of the kernel function in the main function, determine the values ​​of the number of thread blocks grid_size in the parameter grid passed into the kernel function, the number of threads in the thread block block_size, and the data calculation length data_size; S3, map the host code of the CUDA program to the task main core code of the SW26010 processor, and specify the number of task main cores; S4, determine the number of computing master cores mpe_size of the SW26010 processor according to the grid_size value of the kernel function, and determine the number of slave cores cpe_size in a single computing master core of the SW26010 processor according to the block_size value of the kernel function; S5, the task master core allocates the computing data block to the computing master core, and the computing master core allocates the computing task to the slave core array; S6, the slave core performs the computing task according to the computing master core data transmitted by the computing master core to obtain the computing result; S7, the computing master core collects all computing results in the slave core array, and the task master core collects the data block computing results of all computing master cores; S8. The task master core combines the calculation results of all data blocks into the final result.

2. The method for expanding a general parallel program into a multi-core processor parallel program as claimed in claim 1, characterized in that: In the step S1, the kernel function is marked by the __global__ keyword.

3. The method for expanding a general parallel program into a multi-core processor parallel program as claimed in claim 2, characterized in that: In step S3, if the host code is executed as a single thread, the number of task main cores is 1; if the host code opens n threads, the number of task main cores is n.

4. The method for expanding a general parallel program into a multi-core processor parallel program as claimed in claim 1, characterized in that: In step S5, the specific method of the task master core allocating the computing data block to the computing master core is: Define the length of data calculation data_size in the task master core. Each master core obtains the length of the calculation data block mpeDataSize allocated to the i-th master core based on the data calculation length data_size and the master core ID. i And calculate the starting coordinates of the data block; After determining the data starting coordinates and data block length of each computing main core, the task main core initializes the data and distributes the corresponding data blocks to each computing main core.

5. The method for expanding a general parallel program into a multi-core processor parallel program as claimed in claim 4, characterized in that: Get the calculated data block length mpeDataSize i And the method to calculate the starting coordinates of the data block is: The remainder of the calculated data is obtained by taking the modulus of the data calculation length data_size and the number of calculation main cores mpe_size; If the remainder of the calculation data is equal to 0, the length of the calculation data block allocated to the i-th calculation main core is: mpeDataSize i =data_size / mpe_size; The starting coordinates of the calculation data block allocated by the i-th computing core are: mpeDataBegin i = data[0] + mpeDataSize * i; If the calculation data remainder is not equal to 0, the number of calculation main cores is mpe_size+1, and the data calculation length of the mpe_size+1th calculation main core is the calculation data remainder.

6. The method for expanding a general parallel program into a multi-core processor parallel program as claimed in claim 1, characterized in that: In step S5, the computing master core uses a polling algorithm to distribute computing tasks to the slave core array, and the specific steps are as follows: The i-th slave core obtains the i-th computing task, i satisfies i≥0 and i<64. If there are still unassigned tasks, the second round of polling begins; The i-th slave core obtains the i+64th computing task, i satisfies i≥0 and i<64. If there are still unassigned tasks, the third round of polling begins; … … The i-th slave core obtains the i+64*(N-1)th computing task, where i satisfies i≥0 and i<64. If there are still unassigned tasks, the N+1th round of polling begins; Until all the core tasks have been assigned.

7. The method for expanding a general parallel program into a multi-core processor parallel program as claimed in claim 1, characterized in that: MPI communication is used between the task master core and the computing master core.

8. The method for expanding a general parallel program into a multi-core processor parallel program as claimed in claim 1, characterized in that: DMA communication is used between the computing master core and the slave core.

9. A system for expanding a general parallel program into a multi-core processor parallel program, used to implement the method for expanding a general parallel program into a multi-core processor parallel program as claimed in any one of claims 1 to 8, characterized in that: include: The location determination module identifies the kernel function in the CUDA main program and determines the location of the kernel function in the main function; The parameter value determination module determines the value of the parameter passed into the kernel function according to the call of the kernel function in the main function; The task main core quantity determination module maps the host code of the CUDA program to the task main core code of the SW26010 processor to determine the number of task main cores; The calculation main core number determination module determines the calculation main core number mpe_size of the SW26010 processor according to the grid_size value of the kernel function; Slave core number determination module: Determine the number of slave cores cpe_size in a single computing master core of the SW26010 processor according to the block_size value of the kernel function; The first allocation module is provided in the task main core and is used to allocate the computing data blocks to the computing main core. A second allocation module, provided in the computing master core, is used to allocate computing tasks to the slave core array; A data transmission module is provided in the computing master core and is used to transmit the computing master core data to the slave core memory space; The task execution module is located in the slave core and is used to execute the calculation task according to the calculation data of the master core to obtain the calculation result; A first collection module, provided in the computing master core, is used to collect all computing results in the slave core array and send the computing results of the data block; The second collection module is provided in the task main core and is used to collect the data block calculation results of all calculation main cores; The merging module is located in the task main core and is used to merge the calculation results of all data blocks into the final result.