Task processing method and heterogeneous system
By processing the subtasks of tasks in parallel in heterogeneous systems and performing round-robin calculations, the problem of low CPU and GPU utilization in heterogeneous computing is solved, and the computing efficiency and throughput are improved.
Patent Information
- Application Number
- CN202411194429.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-28
- Publication Date
- 2024-12-20
AI Technical Summary
In heterogeneous computing systems, the utilization rate of CPU and GPU is low, resulting in low computing efficiency.
By dividing pending tasks into multiple subtasks for pre-processing and post-processing in parallel, and performing round-robin calculations of the subtask results based on the number of task samples in a heterogeneous system, we ensure that the number of subtasks calculated in each round is the same as the number of task samples. , to improve CPU and GPU utilization.
It improves the utilization rate of CPU and GPU, improves the computing efficiency and throughput of heterogeneous systems, and can process data of multiple subtasks at the same time, enhancing the computing utilization rate.
Smart Images

Figure CN119166336A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a task processing method and a heterogeneous system. Background Art
[0002] Heterogeneous computing refers to a computing method that uses computing units with different types of instruction sets and architectures to form a system, such as a central processing unit (CPU) and a graphics processing unit (GPU), a CPU and a neural network processing unit (NPU), etc.
[0003] Taking the heterogeneous system of CPU and GPU as an example, in the related art, when the heterogeneous system of CPU and GPU performs heterogeneous computing tasks, the tasks are usually performed in sequence. For example, the heterogeneous system of CPU and GPU performs conventional algorithm reasoning process, which may be that the CPU performs pre-processing first, the GPU performs calculation, and then the CPU performs post-processing.
[0004] However, when executing heterogeneous computing tasks in related technologies, there is a problem of low utilization of the CPU and GPU. Summary of the invention
[0005] Based on this, it is necessary to provide a task processing method and a heterogeneous system to address the above technical problems, which can improve the utilization of the CPU and GPU.
[0006] In a first aspect, the present application provides a task processing method, which is applied to a first processor in a heterogeneous system, and the method includes:
[0007] Perform pre-processing on multiple sub-tasks divided by the task to be processed in parallel;
[0008] The second processor in the heterogeneous system is called to perform round-robin calculations on the pre-processing results of each subtask according to the number of task samples, and performs parallel post-processing of the subtask calculation results once each round of subtask calculation results are obtained; the number of subtasks in each round of calculation is the same as the number of task samples;
[0009] The task processing result of the task to be processed is determined according to the post-processing result of each subtask.
[0010] The task processing method provided in the embodiment of the present application is applied to the first processor in a heterogeneous system, by performing pre-processing in parallel on multiple subtasks divided into the task to be processed; calling the second processor in the heterogeneous system to perform round-robin calculation on the pre-processing results of each subtask according to the number of task samples, and performing parallel post-processing of the subtask calculation results once each time a round of subtask calculation results are obtained; the number of subtasks calculated in each round is the same as the number of task samples; and determining the task processing result of the task to be processed according to the post-processing results of each subtask. In this method, multiple subtasks are pre-processed in parallel, and the calculation results of multiple subtasks are post-processed in parallel, which can improve the utilization rate of the first processor; and calling the second processor to perform round-robin calculation on the pre-processing results of each subtask according to the number of task samples, and performing parallel post-processing on the subtask calculation results at the same time, which can improve the utilization rate of the second processor. In addition, the second processor calculates the pre-processing results of each subtask according to the number of task samples, so that the second processor can process the data in multiple subtasks at the same time, which can improve the calculation utilization rate of the second processor.
[0011] In one embodiment, the first processor includes a plurality of processing units; the number of the plurality of subtasks is the same as the number of the plurality of processing units; and the plurality of subtasks divided into the task to be processed are pre-processed in parallel, including:
[0012] When the processing unit is a thread, or when the processing unit is a thread and a process, multiple threads are called to perform pre-processing on multiple subtasks in parallel;
[0013] When the processing unit is a process, multiple processes are called to perform pre-processing on multiple subtasks in parallel.
[0014] The task processing method provided in this embodiment, when the processing unit is a thread, or the processing unit is a thread and a process, calls multiple threads to perform pre-processing on multiple subtasks in parallel; when the processing unit is a process, calls multiple processes to perform pre-processing on multiple subtasks in parallel. In this method, a method for performing pre-processing on multiple subtasks divided from a task to be processed in parallel is provided when the processing unit is a thread, a process, or a thread and a process, so that users can choose according to actual applications, making the task processing method more practical.
[0015] In one embodiment, pre-processing is performed in parallel on multiple subtasks divided from the task to be processed, including:
[0016] The first processor performs pre-processing on each subtask in parallel; or,
[0017] The first processor calls the second processor to perform pre-processing on each subtask in parallel.
[0018] The task processing method provided in the embodiment of the present application performs pre-processing on each subtask in parallel by the first processor; or the first processor calls the second processor to perform pre-processing on each subtask in parallel. In this method, two ways of pre-processing each subtask in parallel are provided, and the user can choose according to the actual application scenario, which makes the task processing method more practical. Moreover, whether the first processor performs pre-processing on each subtask or the second processor performs pre-processing on each subtask, it is parallel processing, which can improve the utilization rate of the first processor and the second processor.
[0019] In one embodiment, the subtask calculation results obtained in each round are obtained by dividing the second processor into multiple execution units based on the number of task samples to calculate the pre-processing results of the corresponding subtasks; in each round of calculation, each execution unit performs a pre-processing result calculation operation for a subtask.
[0020] In the task processing method provided by this embodiment, the subtask calculation results obtained in each round are obtained by the second processor dividing multiple execution units based on the number of task samples to calculate the pre-processing results of the corresponding subtasks, and each execution unit in each round of calculation corresponds to the pre-processing result calculation operation of one subtask. In this method, when the second processor performs calculation operations on the pre-processing results of each subtask, it is calculated by multiple execution units in the second processor, and the number of execution units is the same as the number of pre-processing results of the subtasks that need to be processed, which can improve the efficiency of the second processor in calculating the pre-processing results of each subtask, thereby improving the utilization rate of the second processor.
[0021] In one embodiment, the method further comprises:
[0022] Before the multiple execution units in the second processor perform each round of calculation, performing a locking operation on the multiple execution units;
[0023] When it is detected that each round of calculation of the plurality of execution units is completed, a lock release operation is performed on the plurality of execution units.
[0024] The task processing method provided in this embodiment performs a locking operation on the multiple execution units before each round of calculation in the second processor; and releases the locks on the multiple execution units when it is detected that each round of calculation of the multiple execution units is completed. In this method, the second processor performs locking when performing each round of calculation on the pre-processing results of the subtasks of the number of task samples, and releases the locks after the calculation is completed, which can prevent the competition between the subtasks when the multiple execution units in the second processor perform each round of calculation, thereby avoiding calculation errors, improving the accuracy of the task processing results finally obtained, and making the task processing method more reliable.
[0025] In one embodiment, when each round of subtask calculation results is obtained, parallel post-processing of the subtask calculation results is performed once, including:
[0026] Each time a round of subtask calculation results is obtained, the first processor performs a parallel post-processing of the subtask calculation results; or,
[0027] Each time a round of subtask calculation results is obtained, the second processor performs parallel post-processing of the subtask calculation results.
[0028] The task processing method provided in this embodiment can perform parallel post-processing of the subtask calculation results once by the first processor or once by the second processor each time a round of subtask calculation results are obtained. In this method, two methods of performing parallel post-processing of the subtask calculation results are provided, and the user can choose according to the actual application scenario, so that the task processing method has higher practicality.
[0029] In one embodiment, the first processor includes a plurality of processing units; the first processor performs a parallel post-processing of a subtask calculation result, including:
[0030] When the processing unit is a thread, or when the processing unit is a thread and a process, the first processor calls multiple threads to perform a parallel post-processing of the subtask calculation result;
[0031] When the processing unit is a process, the first processor calls multiple processes to perform parallel post-processing of the calculation results of the subtasks.
[0032] In the task processing method provided by this embodiment, when the processing unit is a thread, or the processing unit is a thread and a process, multiple threads are called to perform post-processing on multiple subtask calculation results in parallel; when the processing unit is a process, multiple processes are called to perform pre-processing on multiple subtask calculation results in parallel. In this method, a method for post-processing the calculation results of multiple subtasks divided by the task to be processed in parallel is provided when the processing unit is a thread, a process, and a thread and a process. In this way, the user can choose according to the actual application, so that the task processing method has higher practicality.
[0033] In one embodiment, the method further comprises:
[0034] Determine the initial process number corresponding to each initial task sample number according to the video memory size of the second processor and a plurality of initial task sample numbers preset for the second processor;
[0035] The number of samples of each initial task and the corresponding number of initial processes are determined as a task search space;
[0036] Based on each task search space, the number of task samples and the number of processing units in the first processor are determined.
[0037] The task processing method provided in this embodiment determines the initial process number corresponding to each initial task sample number according to the video memory size of the second processor and multiple initial task sample numbers preset for the second processor; determines each initial task sample number and the corresponding initial process number as a task search space; and determines multiple processing units and task sample numbers based on each task search space. In this method, the optimal number of task samples and the number of processing units are determined by searching, which can fully utilize the hardware resources of the first processor and the second processor, improve the utilization rate of the first processor and the second processor, and thus improve the performance of the entire heterogeneous system.
[0038] In one embodiment, determining the number of task samples and the number of processing units in the first processor based on each task search space includes:
[0039] According to the number of cores of the first processor, obtaining multiple initial numbers of threads in each task search space;
[0040] Determine the target thread task time corresponding to each task search space according to multiple initial thread numbers in each task search space;
[0041] The number of threads corresponding to the minimum target thread task duration is determined as the number of processing units, and the number of initial task samples in the task search space corresponding to the minimum target thread task duration is determined as the number of task samples.
[0042] The task processing method provided by the embodiment of the present application obtains multiple initial thread numbers in each task search space according to the core number of the first processor; determines the target thread task time corresponding to each task search space according to the multiple initial thread numbers in each task search space; obtains the initial sample number in the task search space corresponding to the minimum target thread task time and determines it as the task sample number of the second processor. In this method, by determining the target thread task time corresponding to each initial thread, the initial thread number, initial task sample and initial process number corresponding to the minimum task time are determined as the final thread number, process number and task sample number, so that the number of processing units in the first processor can be determined, so that the thread number, process number and task sample number with the minimum task processing time can be obtained, and the use of the thread number, process number and task sample number can improve the efficiency of using heterogeneous systems to process tasks.
[0043] In one embodiment, determining the target thread task duration corresponding to each task search space according to multiple initial thread numbers in each task search space includes:
[0044] For multiple initial thread numbers in any task search space, determine the thread task time consumption corresponding to each initial thread number in the task search space;
[0045] The minimum thread task duration among the determined multiple thread task durations is determined as the target thread task duration corresponding to the task search space.
[0046] The task processing method provided in this embodiment determines the thread task time consumption corresponding to each initial thread number in the task search space for multiple initial thread numbers in any task search space; and determines the minimum thread task time consumption among the determined multiple thread task time consumptions as the target thread task time consumption corresponding to the task search space. In this method, the minimum thread task time consumption corresponding to multiple initial thread numbers in any task search space is determined as the target thread task corresponding to the task search space, so that the task time consumptions of each target thread are directly compared later, and the initial thread number and the initial task sample number corresponding to the minimum target thread task time consumption are respectively determined as the thread number of the first processor and the task sample number of the second processor, so that the efficiency of determining the number of threads and the number of task samples can be improved, and the method of determining the number of threads and the number of task samples is fast and easy to implement, so that the task processing method has higher practicality.
[0047] In one embodiment, determining the task processing result of the task to be processed according to the post-processing result of each subtask includes:
[0048] The post-processing results of each subtask are integrated to obtain the task processing result of the task to be processed.
[0049] The task processing method provided in the embodiment of the present application obtains the task processing result of the task to be processed by fusing the post-processing results of each subtask, which can improve the accuracy and reliability of the determined task processing result.
[0050] In a second aspect, an embodiment of the present application further provides a task processing method, which is applied to a second processor in a heterogeneous system, and the method includes:
[0051] According to the call instruction of the first processor in the heterogeneous system, the pre-processing results of the plurality of subtasks are calculated in a round-robin manner according to the number of task samples; the plurality of subtasks are obtained by dividing the tasks to be processed;
[0052] When a round of subtask calculation results is obtained, parallel post-processing of the subtask calculation results is performed once; the number of subtasks in each round of calculation is the same as the number of task samples;
[0053] The task processing result of the task to be processed is determined according to the post-processing result of each subtask.
[0054] The task processing method provided in the embodiment of the present application is applied to the second processor in a heterogeneous system, and the pre-processing results of multiple subtasks are calculated in a round-robin manner according to the number of task samples according to the call instruction of the first processor in the heterogeneous system; multiple subtasks are obtained by dividing the tasks to be processed; when each round of subtask calculation results is obtained, the parallel post-processing of the subtask calculation results is performed once, and the number of subtasks calculated in each round is the same as the number of task samples; according to the post-processing results of each subtask, the task processing result of the task to be processed is determined. In this method, multiple subtasks are pre-processed in parallel, and the calculation results of multiple subtasks are post-processed in parallel, which can improve the utilization rate of the first processor; and the second processor is called to perform round-robin calculations on the pre-processing results of each subtask according to the number of task samples, and the parallel post-processing of the calculation results of each subtask is performed simultaneously, which can improve the utilization rate of the second processor. In addition, the second processor calculates the pre-processing results of each subtask according to the number of task samples, so that the second processor can process the data in multiple subtasks at the same time, which can improve the calculation utilization rate of the second processor.
[0055] In a third aspect, an embodiment of the present application further provides a heterogeneous system, comprising a first processor and a second processor, wherein the first processor is used to execute the steps in any one of the embodiments of the first aspect described above; and the second processor is used to execute the steps in any one of the embodiments of the second aspect described above.
[0056] In a fourth aspect, an embodiment of the present application further provides a task processing device, the device comprising:
[0057] A pre-processing module is used to perform pre-processing on multiple sub-tasks divided by the task to be processed in parallel;
[0058] The first computing module is used to call the second processor in the heterogeneous system to perform round-robin calculations on the pre-processing results of each subtask according to the number of task samples, and to perform parallel post-processing of the subtask calculation results once each time a round of subtask calculation results are obtained; the number of subtasks in each round of calculation is the same as the number of task samples;
[0059] The first determination module is used to determine the task processing result of the task to be processed according to the post-processing result of each subtask.
[0060] In a fifth aspect, an embodiment of the present application further provides a task processing device, the device comprising:
[0061] The second calculation module is used to perform round-robin calculations on pre-processing results of multiple subtasks according to the number of task samples according to the call instruction of the first processor in the heterogeneous system; the multiple subtasks are obtained by dividing the tasks to be processed;
[0062] A post-processing module, used for performing parallel post-processing of sub-task calculation results once each time a round of sub-task calculation results are obtained. The number of sub-tasks in each round of calculation is the same as the number of task samples;
[0063] The second determining module is used to determine the task processing result of the task to be processed according to the post-processing result of each subtask.
[0064] In a sixth aspect, an embodiment of the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the steps in any one of the embodiments of the first and second aspects above are implemented.
[0065] In the seventh aspect, an embodiment of the present application further provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps in any one of the embodiments of the first aspect and the second aspect are implemented.
[0066] In an eighth aspect, an embodiment of the present application further provides a computer program product, including a computer program, which implements the steps in any one of the embodiments of the first and second aspects above when the computer program is executed by a processor.
[0067] The above-mentioned task processing method and heterogeneous system, the method is applied to the first processor in the heterogeneous system, by parallel pre-processing the multiple subtasks divided by the task to be processed; calling the second processor in the heterogeneous system to perform round-robin calculations on the pre-processing results of each subtask according to the number of task samples, and performing parallel post-processing of the subtask calculation results once each time a round of subtask calculation results are obtained; the number of subtasks calculated in each round is the same as the number of task samples; the task processing result of the task to be processed is determined according to the post-processing results of each subtask. In this method, the pre-processing of multiple subtasks is performed in parallel, and the post-processing of the calculation results of multiple subtasks is performed in parallel, which can improve the utilization rate of the first processor; and calling the second processor to perform round-robin calculations on the pre-processing results of each subtask according to the number of task samples, and performing parallel post-processing on the subtask calculation results at the same time, which can improve the utilization rate of the second processor. In addition, the second processor calculates the pre-processing results of each subtask according to the number of task samples, so that the second processor can process the data in multiple subtasks at the same time, which can improve the calculation utilization rate of the second processor. BRIEF DESCRIPTION OF THE DRAWINGS
[0068] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the drawings required for use in the embodiments or the related technical descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0069] Figure 1 A schematic diagram of the structure of a heterogeneous system in one embodiment;
[0070] Figure 2 is a flowchart of a task processing method in one embodiment;
[0071] Figure 3 is a flowchart of a task processing method in another embodiment;
[0072] Figure 4 is a flowchart of a task processing method in another embodiment;
[0073] Figure 5 is a flowchart of a task processing method in another embodiment;
[0074] Figure 6 is a flowchart of a task processing method in another embodiment;
[0075] Figure 7 is a flowchart of a task processing method in another embodiment;
[0076] Figure 8 is a flowchart of a task processing method in another embodiment;
[0077] Fig. 9 is a flowchart of a task processing method in another embodiment;
[0078] Fig.10 is a flowchart of a task processing method in another embodiment;
[0079] Fig.11 is a flowchart of a task processing method in another embodiment;
[0080] Fig.12 is a flowchart of a task processing method in another embodiment;
[0081] Fig.13 A structural block diagram of a heterogeneous system processing a task to be processed in one embodiment;
[0082] Fig.14 is a schematic diagram of the structure of a task processing device in one embodiment;
[0083] Fig.15 is a schematic diagram of the structure of a task processing device in another embodiment;
[0084] Fig.16 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0085] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail 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 application and are not used to limit the present application.
[0086] The task processing method provided in the embodiment of the present application can be applied to Figure 1 The heterogeneous system shown includes a first processor and a second processor. The second processor is communicatively connected to the second processor. The first processor may be a central processing unit (CPU). The second processor may be a graphics processing unit (GPU) or a neural network processing unit (NPU). This embodiment does not limit the specific types of the first processor and the second processor, as long as their functions can be realized. Heterogeneous computing can be performed using a heterogeneous system. Heterogeneous computing refers to a computing method in which computing units of different types of instruction sets and architectures are used to form a system.
[0087] Taking the heterogeneous system of CPU and GPU as an example, in the related art, when the heterogeneous system of CPU and GPU performs heterogeneous computing tasks, the tasks are usually performed in sequence. For example, the heterogeneous system of CPU and GPU performs conventional algorithm reasoning process, which may be that the CPU performs pre-processing first, the GPU performs calculation, and then the CPU performs post-processing.
[0088] However, when executing heterogeneous computing tasks in related technologies, there is a problem of low utilization of the CPU and GPU.
[0089] Based on this, the present application provides a task processing method, which is applied to the first processor in a heterogeneous system, by performing pre-processing in parallel on multiple subtasks divided into the task to be processed; calling the second processor in the heterogeneous system to perform round-robin calculations on the pre-processing results of each subtask according to the number of task samples, and performing parallel post-processing of the subtask calculation results once each time a round of subtask calculation results are obtained; the number of subtasks calculated in each round is the same as the number of task samples; and determining the task processing result of the task to be processed according to the post-processing results of each subtask. In this way, the pre-processing of multiple subtasks is performed in parallel, and the post-processing of the calculation results of multiple subtasks is performed in parallel, which can improve the utilization rate of the first processor; and calling the second processor to perform round-robin calculations on the pre-processing results of each subtask according to the number of task samples, and performing parallel post-processing on the subtask calculation results at the same time, which can improve the utilization rate of the second processor.
[0090] It should be noted that the beneficial effects brought about by the embodiments of the present application or the technical problems solved are not limited to this one, but may also include other implicit or related problems. For details, please refer to the description of the following embodiments.
[0091] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0092] In an exemplary embodiment, Figure 2 As shown, a task processing method is provided, which is applied to Figure 1 The first processor in the example is used as an example to illustrate, including the following S201 to S203. Among them:
[0093] S201, pre-processing multiple subtasks divided by the task to be processed in parallel;
[0094] Pre-processing can be pre-processing of the acquired data in the subtask, including but not limited to data cleaning, feature extraction, feature scaling, data sampling, etc. By pre-processing the data in the subtask, the quality and consistency of the data in the subtask can be ensured, thereby improving the accuracy of subsequent task processing.
[0095] In one embodiment, it is assumed that the task to be processed may be to use a trained model to process the task to be processed, that is, to perform deep learning reasoning. Exemplarily, the trained model is an image recognition model, the task to be processed includes multiple images, and the multiple subtasks are multiple image groups after the multiple images are divided, and each image group includes at least one image. Pre-processing of the subtasks refers to pre-processing the images in each image group, for example, cropping the images in each image group to ensure consistent size; extracting features from the images in each image group; sampling the images in each image group, etc.
[0096] The task to be processed may be input by a user. After obtaining the task to be processed, the first processor divides the task to be processed into multiple subtasks. This embodiment does not limit the specific division method and the number of the divided subtasks.
[0097] In one embodiment, the first processor can divide the task to be processed into a plurality of subtasks according to the number preset by the user, and the number after division is the preset number. The data in each subtask can be the same or different, that is, the task to be processed can be divided evenly or randomly.
[0098] After obtaining the divided multiple subtasks, the first processor performs pre-processing on the multiple subtasks in parallel, that is, performs pre-processing on the corresponding subtasks at the same time.
[0099] In one embodiment, the first processor may perform pre-processing on the divided subtasks in parallel by itself, or may call the second processor in the heterogeneous system to perform pre-processing on the divided subtasks in parallel.
[0100] S202, calling the second processor in the heterogeneous system to perform round-robin calculations on the pre-processing results of each subtask according to the number of task samples, and performing parallel post-processing of the subtask calculation results once each time a round of subtask calculation results is obtained; the number of subtasks calculated in each round is the same as the number of task samples.
[0101] The number of task samples can be preset by the staff based on experience and stored in the first processor. The number of task samples refers to the amount of data that can be processed by the second processor at one time. The number of task samples is greater than the amount of data included in each subtask.
[0102] Post-processing refers to post-processing the acquired data in the subtask, including but not limited to removing noise, resolving errors and inconsistencies in the data in the subtask. Post-processing the acquired data in the subtask can improve the accuracy and interpretability of the final processing results.
[0103] In one embodiment, the task to be processed may be model inference, that is, using a trained model to process the task to be processed. Exemplarily, post-processing is commonly used for tasks such as classification, regression, segmentation, and detection, that is, the trained model is a classification model, a segmentation model, and a detection model.
[0104] After obtaining the pre-processing results of pre-processing multiple subtasks in parallel, the first processor calls the second processor in the heterogeneous system to perform round-robin calculations on each pre-processing result according to the preset number of task samples. That is, when the number of pre-processing results obtained by the first processor reaches the number of task samples, the pre-processing results of the number of task samples will be sent to the second processor, and the second processor will calculate the received pre-processing results; after the second processor completes the calculation of the pre-processing results of the received number of task samples, it will continue to receive the pre-processing results of the number of task samples sent by the first processor for calculation; until all pre-processing results are calculated.
[0105] After the second processor completes the calculation of each received pre-processing result, it will perform parallel post-processing on the calculation results of each pre-processing result, that is, the calculation results of each subtask. That is to say, while the second processor calculates the pre-processing results of each subtask received in the next round, it performs parallel post-processing on the calculation results of each subtask obtained in the current round.
[0106] In one embodiment, the second processor may post-process the calculation results of each subtask in parallel, or the second processor may send the calculation results of each subtask to the first processor, and the first processor may post-process the calculation results of each subtask in parallel.
[0107] S203: Determine the task processing result of the task to be processed according to the post-processing result of each subtask.
[0108] After obtaining the post-processing results of the parallel post-processing of the calculation results of each subtask, the first processor determines the task processing result of the task to be processed according to the post-processing results of each subtask. In other words, the post-processing results of each subtask are comprehensively analyzed to obtain the task processing result corresponding to the task to be processed. The specific method of determining the task processing result of the task to be processed according to the post-processing results of each subtask is different for different tasks to be processed, and this embodiment does not limit this, as long as its function can be achieved.
[0109] In one embodiment, if the task to be processed is to classify multiple images, that is, to distinguish abnormal images from normal images, the task to be processed includes multiple images to be processed, and each subtask includes image groups after the multiple images are divided. The post-processing result of each subtask is the type of image in each image group, and the post-processing results of all subtasks are statistically analyzed to determine the normal images and abnormal images in all subtasks.
[0110] The task processing method provided in the embodiment of the present application is applied to the first processor in a heterogeneous system, by performing pre-processing in parallel on multiple subtasks divided into the task to be processed; calling the second processor in the heterogeneous system to perform round-robin calculation on the pre-processing results of each subtask according to the number of task samples, and performing parallel post-processing of the subtask calculation results once each time a round of subtask calculation results are obtained; the number of subtasks calculated in each round is the same as the number of task samples; and determining the task processing result of the task to be processed according to the post-processing results of each subtask. In this method, multiple subtasks are pre-processed in parallel, and the calculation results of multiple subtasks are post-processed in parallel, which can improve the utilization rate of the first processor; and calling the second processor to perform round-robin calculation on the pre-processing results of each subtask according to the number of task samples, and performing parallel post-processing on the subtask calculation results at the same time, which can improve the utilization rate of the second processor. In addition, the second processor calculates the pre-processing results of each subtask according to the number of task samples, so that the second processor can process the data in multiple subtasks at the same time, which can improve the calculation utilization rate of the second processor.
[0111] In addition, when executing the task processing method provided in the present application, for a heterogeneous system, the utilization rate of the first processor and the second processor can be improved without significantly modifying the source code, thereby improving the throughput of the heterogeneous system.
[0112] In an exemplary embodiment, the first processor includes a plurality of processing units, and the number of the plurality of subtasks is the same as the number of the plurality of processing units. In other words, the first processor divides the tasks to be processed according to the number of processing units. The number of the plurality of processing units in the first processor may be pre-stored in the first processor.
[0113] The multiple processing units may be threads in the first processor, processes in the first processor, or processes and threads in the first processor. When the processing units are threads, the number of the multiple subtasks is the number of threads; when the processing units are processes, the number of the multiple subtasks is the number of processes; when the processing units are processes and threads, the number of the multiple subtasks is the product of the number of processes and the number of threads.
[0114] In this case, if Figure 3 As shown, multiple subtasks divided from the task to be processed are pre-processed in parallel, including:
[0115] S301, when the processing unit is a thread, or the processing unit is a thread and a process, calling multiple threads to perform pre-processing on multiple subtasks in parallel.
[0116] When the processing unit in the first processor is a thread, the first processor calls multiple threads to perform pre-processing on multiple subtasks in parallel. The number of threads is the same as the number of subtasks, that is, one thread can process one subtask. In other words, a thread pool is created in the first processor, and the thread pool includes multiple threads.
[0117] In the case where the processing unit in the first processor is a thread and a process, the first processor calls multiple threads to perform pre-processing on multiple subtasks in parallel. The number of subtasks is the same as the product of the number of processes and the number of threads. In other words, a process pool is created in the first processor, the process pool includes multiple processes, each process has a thread pool created, and the thread pool includes multiple threads.
[0118] S302: When the processing unit is a process, multiple processes are called to perform pre-processing on multiple subtasks in parallel.
[0119] In the case where the processing unit is a process, the first processor calls multiple processes to perform pre-processing on multiple subtasks in parallel. The number of processes is the same as the number of subtasks, that is, one process processes one subtask. In other words, a process pool is created in the first processor, and the process pool includes multiple processes.
[0120] The task processing method provided in this embodiment, when the processing unit is a thread, or the processing unit is a thread and a process, calls multiple threads to perform pre-processing on multiple subtasks in parallel; when the processing unit is a process, calls multiple processes to perform pre-processing on multiple subtasks in parallel. In this method, a method for performing pre-processing on multiple subtasks divided from a task to be processed in parallel is provided when the processing unit is a thread, a process, or a thread and a process, so that users can choose according to actual applications, making the task processing method more practical.
[0121] In an exemplary embodiment, Figure 4 As shown, the pre-processing of the multiple subtasks divided by the task to be processed in parallel includes any of the following methods:
[0122] S401: The first processor performs pre-processing on each subtask in parallel.
[0123] After the first processor obtains the task to be processed and divides the task to be processed into multiple subtasks, the first processor directly pre-processes each subtask in parallel, that is, multiple processing units in the first processor pre-process each subtask in parallel.
[0124] S402: The first processor calls the second processor to perform pre-processing on each subtask in parallel.
[0125] After the first processor obtains multiple subtasks, it calls the second processor to perform pre-processing on each subtask in parallel. In other words, the first processor sends the obtained multiple subtasks to the second processor, and the second processor processes each subtask in parallel.
[0126] In one embodiment, the second processor may include multiple threads, and each thread processes each subtask in parallel. The second processor may include multiple processes, and each process processes each subtask in parallel.
[0127] The task processing method provided in the embodiment of the present application performs pre-processing on each subtask in parallel by the first processor; or the first processor calls the second processor to perform pre-processing on each subtask in parallel. In this method, two ways of pre-processing each subtask in parallel are provided, and the user can choose according to the actual application scenario, which makes the task processing method more practical. Moreover, whether the first processor performs pre-processing on each subtask or the second processor performs pre-processing on each subtask, it is parallel processing, which can improve the utilization rate of the first processor and the second processor.
[0128] In an exemplary embodiment, the subtask calculation results obtained in each round are obtained by the second processor dividing multiple execution units based on the number of task samples to calculate the pre-processing results of the corresponding subtasks; in each round of calculation, each execution unit performs a pre-processing result calculation operation for a subtask.
[0129] The second processor is divided into multiple execution units according to the number of task samples, and the number of execution units is the same as the number of task samples. After the second processor receives the pre-processing results of each subtask, the multiple execution units respectively calculate the pre-processing results of the corresponding subtasks to obtain the calculation results of each subtask. In other words, one execution unit in the second processor performs an operation on the pre-processing result of one subtask.
[0130] In the task processing method provided by this embodiment, the subtask calculation results obtained in each round are obtained by the second processor dividing multiple execution units based on the number of task samples to calculate the pre-processing results of the corresponding subtasks, and each execution unit in each round of calculation corresponds to the pre-processing result calculation operation of one subtask. In this method, when the second processor performs calculation operations on the pre-processing results of each subtask, it is calculated by multiple execution units in the second processor, and the number of execution units is the same as the number of pre-processing results of the subtasks that need to be processed, which can improve the efficiency of the second processor in calculating the pre-processing results of each subtask, thereby improving the utilization rate of the second processor.
[0131] In an exemplary embodiment, Figure 5As shown, the task processing method also includes:
[0132] S501, before the multiple execution units in the second processor perform each round of calculation, a locking operation is performed on the multiple execution units.
[0133] Before the first processor calls the second processor to perform each round of calculation, that is, before obtaining the pre-processing results of the subtasks of the task sample number each time and performing the calculation operation on the pre-processing results of the subtasks of the task sample number, the second processor is locked, that is, the multiple execution units in the second processor are locked. In other words, the thread lock is obtained and the second processor is locked.
[0134] S502: When it is detected that each round of calculation of the plurality of execution units is completed, a lock release operation is performed on the plurality of execution units.
[0135] After the second processor detects that the second processor has completed this round of calculation, that is, multiple execution units have respectively calculated the pre-processing results of each subtask, a lock release operation is performed on the second processor, that is, the locks added to the multiple execution units in the second processor are released, so that the second processor can perform the next round of calculation.
[0136] The task processing method provided in this embodiment performs a locking operation on the multiple execution units before each round of calculation in the second processor; and releases the locks on the multiple execution units when it is detected that each round of calculation of the multiple execution units is completed. In this method, the second processor performs locking when performing each round of calculation on the pre-processing results of the subtasks of the number of task samples, and releases the locks after the calculation is completed, which can prevent the competition between the subtasks when the multiple execution units in the second processor perform each round of calculation, thereby avoiding calculation errors, improving the accuracy of the task processing results finally obtained, and making the task processing method more reliable.
[0137] In an exemplary embodiment, Figure 6 As shown, when each round of subtask calculation results is obtained, performing a parallel post-processing of the subtask calculation results includes any of the following methods:
[0138] S601, when each round of subtask calculation results is obtained, the first processor performs parallel post-processing of the subtask calculation results.
[0139] After the second processor performs each round of calculation on the pre-processing of each subtask and obtains the calculation results of each subtask, the calculation results of each subtask can be sent to the first processor, and the first processor performs parallel post-processing operations on the received calculation results of each subtask.
[0140] S602: Each time a round of subtask calculation results is obtained, the second processor performs a parallel post-processing of the subtask calculation results.
[0141] After the second processor performs each round of calculation on the pre-processing of each subtask and obtains the calculation results of each subtask, it can directly perform parallel post-processing operations on the calculation results of each subtask. In other words, the second processor directly performs parallel post-processing on the calculation results of each subtask.
[0142] In one embodiment, the second processor includes multiple threads, and the second processor performs parallel post-processing on the calculation results of each subtask by calling the multiple threads respectively.
[0143] The task processing method provided in this embodiment can perform parallel post-processing of the subtask calculation results once by the first processor or once by the second processor each time a round of subtask calculation results are obtained. In this method, two methods of performing parallel post-processing of the subtask calculation results are provided, and the user can choose according to the actual application scenario, so that the task processing method has higher practicality.
[0144] In an exemplary embodiment, the first processor includes a plurality of processing units, and the processing units may be threads, processes, or both threads and processes. Figure 7 As shown, the first processor performs a parallel post-processing of the subtask calculation results, including:
[0145] S701: When the processing unit is a thread, or the processing unit is a thread and a process, the first processor calls multiple threads to perform parallel post-processing of a subtask calculation result.
[0146] When the processing unit in the first processor is a thread, the first processor calls multiple threads to perform post-processing on multiple subtask calculation results in parallel. The number of threads is the same as the number of subtasks, that is, one thread can process one subtask calculation result.
[0147] In one embodiment, the thread called by the first processor to perform post-processing on the calculation results of multiple subtasks in parallel may be the same as the thread called by the first processor to perform pre-processing on the corresponding subtasks.
[0148] In the case where the processing units in the first processor are threads and processes, the first processor calls multiple threads to perform post-processing on multiple subtask calculation results in parallel, respectively. The number of subtasks is the same as the product of the number of processes and the number of threads.
[0149] S702: When the processing unit is a process, the first processor calls multiple processes to perform parallel post-processing of a subtask calculation result.
[0150] When the processing unit is a process, the first processor calls multiple processes to perform post-processing on multiple subtask calculation results in parallel. The number of processes is the same as the number of subtasks, that is, one process processes one subtask calculation result.
[0151] In the task processing method provided by this embodiment, when the processing unit is a thread, or the processing unit is a thread and a process, multiple threads are called to perform a parallel post-processing of multiple subtask calculation results; when the processing unit is a process, multiple processes are called to perform a parallel pre-processing of multiple subtask calculation results. In this method, a method for parallel post-processing of multiple subtask calculation results divided by the task to be processed is provided when the processing unit is a thread, a process, and a thread and a process, so that users can choose according to actual applications, making the task processing method more practical.
[0152] In an exemplary embodiment, Figure 8 As shown, the task processing method also includes:
[0153] S801, determining an initial process number corresponding to each initial task sample number according to a video memory size of a second processor and a plurality of initial task sample numbers preset for the second processor.
[0154] The video memory size of the second processor may be pre-stored in the first processor. The number of initial task samples may be pre-set by a staff member and stored in the first processor.
[0155] After the first processor obtains the video memory size of the second processor and the multiple initial task sample numbers, the first processor determines the initial process number corresponding to each initial task sample number according to the video memory size and the multiple initial task sample numbers. Specifically, the maximum video memory size consumed when executing the task sample with each initial task sample number is determined to determine the initial process number corresponding to the initial task sample.
[0156] S802, determine each initial task sample number and the corresponding initial process number as a task search space.
[0157] After the first processor obtains the initial process number corresponding to each initial task sample number, each initial task sample number and the corresponding initial process number form a task search space. One initial task sample number corresponds to one task search space.
[0158] Assume that the video memory size of the second processor is 32G, the initial task sample numbers are 1, 2, 3, 4, and the thread number is 1. When the initial task sample number is 1, the process number is 1, and the thread number is 1, the maximum video memory consumed when executing the task sample is 4G, and the 32G video memory can support up to 8 processes. When the initial task sample number is 1, the corresponding initial process number is 8. When the initial task sample number is 2, the process number is 1, and the thread number is 1, the maximum thread consumed when executing the task sample is 8G, and the 32G video memory can support up to 4 processes. When the initial task sample number is 2, the corresponding initial process number is 4. When the initial task sample number is 3, the process number is 1, and the thread number is 1, the maximum thread consumed when executing the task sample is 16G, and the 32G video memory can support up to 2 processes. When the initial task sample number is 3, the corresponding initial process number is 2. When the number of initial task samples is 4, the number of processes is 1, and the number of threads is 1, the maximum thread consumed when executing the task sample is 32G, and 32G of video memory can support up to 2 processes. When the number of initial task samples is 4, the corresponding initial number of processes is 1. The task search space composed of the initial number of task samples and the initial number of processes can include [1, 8], [2, 3], [3, 2], and [4, 1].
[0159] S803: Determine the number of task samples and the number of processing units in the first processor based on the search space of each task.
[0160] After determining multiple task search spaces, the first processor searches based on each task search space to determine the optimal number of threads, thereby determining the number of processing units. The initial number of task samples in the search space corresponding to the optimal number of threads is the number of task samples.
[0161] The task processing method provided in this embodiment determines the initial number of processes corresponding to each initial number of task samples according to the video memory size of the second processor and multiple initial number of task samples preset for the second processor; determines each initial number of task samples and the corresponding initial number of processes as a task search space; and determines the number of task samples and the number of processing units in the first processor based on each task search space. In this method, the optimal number of task samples and the number of processing units are determined by searching, which can fully utilize the hardware resources of the first processor and the second processor, improve the utilization rate of the first processor and the second processor, and thus improve the performance of the entire heterogeneous system.
[0162] In an exemplary embodiment, Fig. 9 As shown, based on each task search space, determining the number of task samples and the number of processing units in the first processor includes:
[0163] S901, obtaining multiple initial numbers of threads in each task search space according to the number of cores of the first processor.
[0164] The number of cores of the first processor may be pre-stored in the first processor. After obtaining the number of cores, the first processor determines the number of initial threads in each task search space according to the number of cores. The number of initial threads in each task search space may be the same or different.
[0165] In one embodiment, the first processor may obtain multiple initial thread numbers in each task search space according to the number of its cores and a preset search method. The search method may be, but is not limited to, a binary search method, an exhaustive search method, a random search method, etc. Optionally, the binary search method may reduce the search space and the number of searches while improving the subsequent rapid and accurate determination of the optimal number of task samples, number of threads, and number of processes.
[0166] Assume that the number of cores of the first processor is 48. For the task search space [1, 8], the binary search method can be used to determine multiple initial thread numbers. Specifically, the first initial thread number is 48, the second initial thread number is 24, the third initial thread number is 12, the fourth initial thread number is 6, the fifth initial thread number is 3, and the sixth initial thread number is 1. For other task search spaces, the initial thread number can be the same as that of the task search space [1, 8], or other search methods can be used to determine the corresponding multiple initial thread numbers.
[0167] S902, determining the target thread task consumption corresponding to each task search space according to multiple initial thread numbers in each task search space.
[0168] For each task search space, based on each initial number of threads in the task search space, determine the target thread task time corresponding to each initial number of threads. That is, execute the preset task with the initial number of task samples, the number of processes and an initial number of threads in the task search space, and obtain the total time consumed when executing the preset task, that is, the thread task time corresponding to the initial number of threads. According to the thread task time corresponding to each initial number of threads in the task search space, determine the target thread task time corresponding to the task search space.
[0169] S903, determining the minimum target thread task time consumption as the number of processing units, and determining the initial task sample number in the task search space corresponding to the minimum target thread task time consumption as the task sample number.
[0170] After determining the target thread task consumption corresponding to each initial number of threads in each task search space, the first processor compares all target thread task consumptions, determines the minimum target thread task consumption, and determines the number of threads corresponding to the minimum target thread task consumption as the number of processing units, where each thread is a plurality of processing units.
[0171] After determining the number of threads corresponding to the minimum target thread task duration, the first processor determines the initial number of task samples in the task search space corresponding to the number of threads as the number of task samples of the second processor, and determines the initial number of processes in the task search space corresponding to the number of threads as the number of processes of the first processor.
[0172] The task processing method provided by the embodiment of the present application obtains multiple initial thread numbers in each task search space according to the core number of the first processor; determines the target thread task time corresponding to each task search space according to the multiple initial thread numbers in each task search space; determines the number of threads corresponding to the minimum target thread task time as the number of processing units, and determines the initial number of samples in the task search space corresponding to the minimum target thread task time as the number of task samples of the second processor. In this method, by determining the target thread task time corresponding to each initial thread, the initial number of threads, initial task samples and initial number of processes corresponding to the minimum task time are determined as the final number of threads, number of processes and number of task samples, so that the number of processing units in the first processor can be determined, so that the number of threads, number of processes and number of task samples with the minimum task processing time can be obtained, and the use of the number of threads, number of processes and number of task samples can improve the efficiency of using heterogeneous systems to process tasks.
[0173] In one embodiment, the first processor can determine the thread task duration corresponding to each initial thread number based on multiple initial thread numbers in each task search space, determine the thread number corresponding to the smallest thread task duration among the thread task durations corresponding to all initial thread numbers as the number of processing units, and determine the initial task sample number in the task search space corresponding to the smallest thread task duration as the task sample number of the second processor, and determine the initial process number as the process number of the first processor.
[0174] In an exemplary embodiment, Fig.10 As shown, according to the multiple initial thread numbers in each task search space, the target thread task time corresponding to each task search space is determined, including:
[0175] S1001, for a plurality of initial thread numbers in any task search space, determining the thread task consumption corresponding to each initial thread number in the task search space.
[0176] For each task search space, the first processor obtains the target thread task time corresponding to each initial thread number in the task search space. The description of the target thread task time corresponding to each initial thread number can refer to the specific description of the above example, which will not be repeated here.
[0177] S1002: Determine the minimum thread task duration among the determined multiple thread task durations as the target thread task duration corresponding to the task search space.
[0178] After obtaining the thread task durations corresponding to the multiple initial thread numbers in each task search space, the first processor compares the thread task durations corresponding to the multiple initial thread numbers and determines the minimum thread task duration as the target thread task duration corresponding to the task search space.
[0179] The task processing method provided in this embodiment determines the thread task time consumption corresponding to each initial thread number in the task search space for multiple initial thread numbers in any task search space; and determines the minimum thread task time consumption among the determined multiple thread task time consumptions as the target thread task time consumption corresponding to the task search space. In this method, the minimum thread task time consumption corresponding to multiple initial thread numbers in any task search space is determined as the target thread task corresponding to the task search space, so that the task time consumptions of each target thread are directly compared later, and the initial thread number and the initial task sample number corresponding to the minimum target thread task time consumption are respectively determined as the thread number of the first processor and the task sample number of the second processor, so that the efficiency of determining the number of threads and the number of task samples can be improved, and the method of determining the number of threads and the number of task samples is fast and easy to implement, so that the task processing method has higher practicality.
[0180] In one embodiment, according to actual experience, the thread task time consumption usually appears in the form of a quadratic function. If there is no fixed form, a binary search is performed. For the task search space [1, 8], and multiple initial thread numbers 48, 24, 12, 6, 3 and 1 in the task search space. If the rule of change of the thread task time consumption is approximately a quadratic function that opens upward, then when the thread task time consumption changes from high to low and then to high, a binary search can be performed again. For example, the thread task time consumption corresponding to the initial thread number 48 is 100 seconds, the thread task time consumption corresponding to the initial thread number 24 is 80 seconds, the thread task time consumption corresponding to the initial thread number 12 is 70 seconds, and the thread task time consumption corresponding to the initial thread number 6 is 90 seconds. At this time, if the thread task time consumption changes from high to low and then to high, the binary search will continue. For the initial number of threads 12 and the initial number of threads 6, the median of the two initial number of threads is calculated, that is, 9, the thread task time corresponding to the initial number of threads 9 is obtained, and the thread task time of the two smaller numbers of threads 12, 9 and 6 is determined. Assume that the thread task time of the initial number of threads 12 and the initial number of threads 9 is smaller. Continue to perform the binary search, take the median of the initial number of threads 12 and the initial number of threads 9, that is, 10, and determine the thread task time of the two smaller numbers of threads 12, 10 and 9. Assume that the thread task time of the initial number of threads 10 and the initial number of threads 9 is smaller, and the binary search cannot be performed at this time, then the initial number of threads with the smallest thread task time among the initial number of threads 10 and the initial number of threads 9 is determined as the number of threads of the first processor.
[0181] In an exemplary embodiment, determining the task processing result of the task to be processed according to the post-processing result of each subtask includes:
[0182] The post-processing results of each subtask are integrated to obtain the task processing result of the task to be processed.
[0183] The task to be processed includes multiple subtasks. After obtaining the post-processing results of each subtask, the first processor performs fusion processing on the post-processing results of each subtask to determine the task processing result of the task to be processed. This embodiment does not limit the specific method of fusion processing of the post-processing results of each subtask, as long as its function can be achieved.
[0184] The task processing method provided in the embodiment of the present application obtains the task processing result of the task to be processed by fusing the post-processing results of each subtask, which can improve the accuracy and reliability of the determined task processing result.
[0185] In an exemplary embodiment, Fig.11 As shown, a task processing method is provided, which is applied to Figure 1The second processor in the example is used for explanation. It includes the following S1101 to S1103. Among them:
[0186] S1101, according to the call instruction of the first processor in the heterogeneous system, perform round-robin calculation on the pre-processing results of multiple subtasks according to the number of task samples; the multiple subtasks are obtained by dividing the task to be processed.
[0187] The description of the number of task samples, pre-processing, and the method of treating task division can refer to the specific description in the above embodiment, which will not be repeated here.
[0188] After receiving the call instruction from the first processor, the second processor in the heterogeneous system performs round-robin calculations on the pre-processing results of the received multiple subtasks according to the number of task samples. The processing results of each subtask can be obtained by the first processor performing parallel pre-processing on the multiple subtasks divided by the task to be processed and sending them to the second processor; or the first processor divides the task to be processed into multiple subtasks, sends the multiple subtasks to the second processor, and the second processor performs parallel pre-processing on the multiple subtasks.
[0189] For a specific description of the second processor performing round-robin calculations on the pre-processing results of multiple subtasks according to the number of task samples, reference may be made to the description in the above embodiment, which will not be repeated here.
[0190] S1102, when each round of subtask calculation results is obtained, parallel post-processing of the subtask calculation results is performed once, and the number of subtasks in each round of calculation is the same as the number of task samples.
[0191] After the second processor completes the calculation of the pre-processing results of each subtask, it will perform parallel post-processing on the calculation results of each pre-processing result, that is, the calculation results of each subtask. That is to say, while the second processor calculates the pre-processing results of each subtask received in the next round, it will post-process the calculation results of each subtask obtained in the current round in parallel.
[0192] In one embodiment, the second processor may post-process the calculation results of each subtask in parallel, or the second processor may send the calculation results of each subtask to the first processor, and the first processor may post-process the calculation results of each subtask in parallel.
[0193] For the description of post-processing, reference may be made to the specific description in the above embodiments, which will not be repeated here.
[0194] S1103, determining the task processing result of the task to be processed according to the post-processing result of each subtask.
[0195] After obtaining the post-processing results of the parallel post-processing of the calculation results of each subtask, the first processor determines the task processing result of the task to be processed according to the post-processing results of each subtask. In other words, the post-processing results of each subtask are comprehensively analyzed to obtain the task processing result corresponding to the task to be processed. The specific method of determining the task processing result of the task to be processed according to the post-processing results of each subtask is different for different tasks to be processed, and this embodiment does not limit this, as long as its function can be achieved.
[0196] The task processing method provided in the embodiment of the present application is applied to the second processor in a heterogeneous system, and the pre-processing results of multiple subtasks are calculated in a round-robin manner according to the number of task samples according to the call instruction of the first processor in the heterogeneous system; multiple subtasks are obtained by dividing the tasks to be processed; when each round of subtask calculation results is obtained, the parallel post-processing of the subtask calculation results is performed once, and the number of subtasks calculated in each round is the same as the number of task samples; according to the post-processing results of each subtask, the task processing result of the task to be processed is determined. In this method, multiple subtasks are pre-processed in parallel, and the calculation results of multiple subtasks are post-processed in parallel, which can improve the utilization rate of the first processor; and the second processor is called to perform round-robin calculations on the pre-processing results of each subtask according to the number of task samples, and the parallel post-processing of the calculation results of each subtask is performed simultaneously, which can improve the utilization rate of the second processor. In addition, the second processor calculates the pre-processing results of each subtask according to the number of task samples, so that the second processor can process the data in multiple subtasks at the same time, which can improve the calculation utilization rate of the second processor.
[0197] In an exemplary embodiment, the subtask calculation results obtained in each round are obtained by the second processor dividing multiple execution units based on the number of task samples to calculate the pre-processing results of the corresponding subtasks; in each round of calculation, each execution unit performs a pre-processing result calculation operation for a subtask.
[0198] In an exemplary embodiment, the task processing method further includes:
[0199] Before the multiple execution units in the second processor perform each round of calculation, a locking operation is performed on the multiple execution units; when it is detected that each round of calculation of the multiple execution units is completed, a locking release operation is performed on the multiple execution units.
[0200] In an exemplary embodiment, when each round of subtask calculation results is obtained, parallel post-processing of the subtask calculation results is performed once, including:
[0201] Each time a round of subtask calculation results is obtained, the first processor performs parallel post-processing of the subtask calculation results once; or, each time a round of subtask calculation results is obtained, the second processor performs parallel post-processing of the subtask calculation results once.
[0202] For the specific description of the above-mentioned embodiments, reference may be made to the description of the above-mentioned embodiments when applied to the first processor in a heterogeneous system, which will not be repeated here.
[0203] In addition, in an exemplary embodiment, the present application also provides an optional example of applying a task processing method to a heterogeneous system, such as Fig.12 As shown, the following steps may be included:
[0204] S1201, determining the number of initial processes corresponding to the number of samples of each initial task according to the video memory size of the second processor and a plurality of initial task oxygen numbers preset for the second processor.
[0205] S1202: Determine each initial task sample number and the corresponding initial process number as a task search space.
[0206] S1203: Obtain multiple initial numbers of threads in each task search space according to the number of cores of the first processor.
[0207] S1204: for a plurality of initial thread numbers in any task search space, determine the thread task duration corresponding to each initial thread number in the task search space.
[0208] S1205: Determine the minimum thread task duration among the determined multiple thread task durations as the target thread task duration corresponding to the task search space.
[0209] S1206, determining the number of processing units according to the number of threads and the number of processes corresponding to the minimum target thread task duration, and determining the number of initial task samples in the task search space corresponding to the minimum target thread task duration as the number of task samples.
[0210] S1207, the first processor calls each thread to perform pre-processing on multiple subtasks divided from the task to be processed in parallel; the number of the multiple subtasks is the same as the number of all threads in the multiple process pools.
[0211] S1208, calling the second processor in the heterogeneous system to perform round-robin calculation on the pre-processing result of each subtask according to the number of task samples.
[0212] Before executing each round of calculation, a locking operation is performed on the second processor, and after each round of calculation, a locking release operation is performed.
[0213] S1209, when each round of subtask calculation results is obtained, each subtask calculation result is sent to the first processor, and the first processor calls each thread to perform parallel post-processing on each received subtask calculation result;
[0214] S1210, the first processor calls each process to process the post-processing results of each subtask in the corresponding thread pool to obtain an intermediate processing result;
[0215] S1211: The first processor merges the intermediate processing results corresponding to each process to obtain a task processing result of the task to be processed.
[0216] The above-mentioned processes of S1201-S1211 can refer to the description of the above-mentioned method embodiment, and the implementation principles and technical effects thereof are similar and will not be repeated here.
[0217] In one embodiment, if Fig.13 As shown, a process pool is created in the first processor, and the process pool includes multiple processes, namely process 1 to process n. A thread pool is created in each process, and the thread pool includes multiple threads, namely thread 1 to thread m. The number of multiple processes included in the process pool is the same as the determined number of processes, and the number of multiple threads included in the thread pool is the same as the determined number of threads. The block diagram of the heterogeneous system processing the pending tasks is shown in FIG. Fig.13 As shown, each thread in each thread pool is called to obtain the post-processing results of each subtask, and the thread pool includes the post-processing results of all subtasks; each process in the process pool integrates the post-processing results of all subtasks in the corresponding thread pool to obtain the intermediate processing results, and the process pool includes the intermediate processing results corresponding to all processes. Specifically, through experiments, it can be seen that in the paddleNLP environment, the second processor can increase the throughput by nearly 4 times.
[0218] In another embodiment, the task processing method provided in the embodiment of the present application can be implemented based on open source tools such as k8s (Kubernetes) or slurm. In other words, a corresponding cluster environment is deployed in the heterogeneous system.
[0219] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0220] In an exemplary embodiment, a heterogeneous system is provided, including a first processor and a second processor, wherein the first processor is used to execute the steps of the task processing method in any embodiment described above with the first processor as the execution subject; and the second processor is used to execute the steps of the task processing method in any embodiment described above with the second processor as the execution subject.
[0221] The first processor and the second processor in the heterogeneous system provided in the embodiment of the present application are used to execute the task processing method provided in any of the above embodiments. Then, the heterogeneous system has all the beneficial effects of the task processing method provided in the above embodiments, which will not be described in detail in this embodiment.
[0222] Based on the same inventive concept, the embodiment of the present application also provides a task processing device for implementing the task processing method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more task processing device embodiments provided below can refer to the limitations on the task processing method above, and will not be repeated here.
[0223] In an exemplary embodiment, Fig.14 As shown, a task processing device 140 is provided, comprising: a pre-processing module 1401, a first calculation module 1402 and a first determination module 1403, wherein:
[0224] The pre-processing module 1401 is used to perform pre-processing on multiple sub-tasks divided from the task to be processed in parallel.
[0225] The first computing module 1402 is used to call the second processor in the heterogeneous system to perform round-robin calculations on the pre-processing results of each subtask according to the number of task samples, and to perform parallel post-processing of the subtask calculation results once each time a round of subtask calculation results is obtained; the number of subtasks calculated in each round is the same as the number of task samples.
[0226] The first determining module 1403 is used to determine the task processing result of the task to be processed according to the post-processing result of each subtask.
[0227] In one embodiment, the first processor includes a plurality of processing units, the number of the plurality of subtasks is the same as the number of the plurality of processing units, and the pre-processing module 1401 is specifically used for:
[0228] When the processing unit is a thread, or when the processing unit is a thread and a process, multiple threads are called to perform pre-processing on multiple subtasks in parallel;
[0229] When the processing unit is a process, multiple processes are called to perform pre-processing on multiple subtasks in parallel.
[0230] In one embodiment, the pre-processing module 1401 is further used for:
[0231] The first processor performs pre-processing on each subtask in parallel;
[0232] Alternatively, the first processor calls the second processor to perform pre-processing on each subtask in parallel.
[0233] In one embodiment, the subtask calculation results obtained in each round are obtained by dividing the second processor into multiple execution units based on the number of task samples to calculate the pre-processing results of the corresponding subtasks; in each round of calculation, each execution unit performs a pre-processing result calculation operation for a subtask.
[0234] In one embodiment, the task processing device 140 further includes:
[0235] A locking module, used for performing a locking operation on the multiple execution units before the multiple execution units in the second processor perform each round of calculation;
[0236] The lock release module is used to perform a lock release operation on the multiple execution units when it is detected that each round of calculation of the multiple execution units is completed.
[0237] In one embodiment, the first calculation module 1402 is specifically used for:
[0238] Each time a round of subtask calculation results is obtained, the first processor performs a parallel post-processing of the subtask calculation results; or,
[0239] Each time a round of subtask calculation results is obtained, the second processor performs parallel post-processing of the subtask calculation results.
[0240] In one embodiment, the first processor includes a plurality of processing units; the first calculation module 1402 is further configured to:
[0241] When the processing unit is a thread, or when the processing unit is a thread and a process, the first processor calls multiple threads to perform a parallel post-processing of the subtask calculation result;
[0242] When the processing unit is a process, the first processor calls multiple processes to perform parallel post-processing of the calculation results of the subtasks.
[0243] In one embodiment, the task processing device 140 further includes:
[0244] A process number determination module, used to determine the initial process number corresponding to each initial task sample number according to the video memory size of the second processor and a plurality of initial task sample numbers preset for the second processor;
[0245] A search space determination module, used for determining each initial task sample number and the corresponding initial process number as a task search space;
[0246] The sample number determination module is used to determine the number of task samples and the number of processing units based on the search space of each task.
[0247] In one embodiment, the sample number determination module is specifically used to:
[0248] According to the number of cores of the first processor, obtaining multiple initial numbers of threads in each task search space;
[0249] Determine the target thread task time corresponding to each task search space according to multiple initial thread numbers in each task search space;
[0250] The number of threads corresponding to the minimum target thread task duration is determined as the number of processing units, and the number of initial task samples in the task search space corresponding to the minimum target thread task duration is determined as the number of task samples.
[0251] In one embodiment, the sample number determination module is further configured to:
[0252] For multiple initial thread numbers in any task search space, determine the thread task time consumption corresponding to each initial thread number in the task search space;
[0253] The minimum thread task duration among the determined multiple thread task durations is determined as the target thread task duration corresponding to the task search space.
[0254] In one embodiment, the first determining module 1403 is specifically used to:
[0255] The post-processing results of each subtask are integrated to obtain the task processing result of the task to be processed.
[0256] In an exemplary embodiment, Fig.15 As shown, a task processing device 150 is provided, comprising: a second calculation module 1501, a post-processing module 1502, and a second determination module 1503, wherein:
[0257] The second calculation module 1501 is used to perform round-robin calculations on the pre-processing results of multiple subtasks according to the number of task samples according to the call instruction of the first processor in the heterogeneous system; the multiple subtasks are obtained by dividing the tasks to be processed;
[0258] The post-processing module 1502 is used to perform parallel post-processing of the sub-task calculation results once each time a round of sub-task calculation results are obtained. The number of sub-tasks in each round of calculation is the same as the number of task samples;
[0259] The second determining module 1503 is used to determine the task processing result of the task to be processed according to the post-processing result of each subtask.
[0260] In one embodiment, the subtask calculation results obtained in each round are obtained by dividing the second processor into multiple execution units based on the number of task samples to calculate the pre-processing results of the corresponding subtasks; in each round of calculation, each execution unit performs a pre-processing result calculation operation for a subtask.
[0261] In one embodiment, the task processing device 150 further includes:
[0262] A locking module, used for performing a locking operation on the multiple execution units before the multiple execution units in the second processor perform each round of calculation;
[0263] The lock release module is used to perform a lock release operation on the multiple execution units when it is detected that each round of calculation of the multiple execution units is completed.
[0264] In one embodiment, the post-processing module 1502 is specifically used for:
[0265] Each time a round of subtask calculation results is obtained, the first processor performs parallel post-processing of the subtask calculation results once; or, each time a round of subtask calculation results is obtained, the second processor performs parallel post-processing of the subtask calculation results once.
[0266] Each module in the above task processing device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0267] In one embodiment, a computer device is provided, whose internal structure diagram can be as follows: Fig.16 As shown. The computer device includes a processor, a memory, a communication interface, a display screen and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be achieved through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, a task processing method is implemented. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covered on the display screen, or a key, trackball or touchpad set on the computer device housing, or an external keyboard, touchpad or mouse, etc.
[0268] Those skilled in the art will understand that Fig.16 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0269] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the following steps are implemented:
[0270] Perform pre-processing on multiple sub-tasks divided by the task to be processed in parallel;
[0271] The second processor in the heterogeneous system is called to perform round-robin calculations on the pre-processing results of each subtask according to the number of task samples, and performs parallel post-processing of the subtask calculation results once each round of subtask calculation results are obtained; the number of subtasks in each round of calculation is the same as the number of task samples;
[0272] The task processing result of the task to be processed is determined according to the post-processing result of each subtask.
[0273] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0274] According to the call instruction of the first processor in the heterogeneous system, the pre-processing results of the plurality of subtasks are calculated in a round-robin manner according to the number of task samples; the plurality of subtasks are obtained by dividing the tasks to be processed;
[0275] When a round of subtask calculation results is obtained, parallel post-processing of the subtask calculation results is performed once; the number of subtasks in each round of calculation is the same as the number of task samples;
[0276] The task processing result of the task to be processed is determined according to the post-processing result of each subtask.
[0277] The implementation principles and technical effects of each step implemented by the processor in the embodiment of the present application are similar to the principles of the above-mentioned violator prediction method, and will not be repeated here.
[0278] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0279] Perform pre-processing on multiple sub-tasks divided by the task to be processed in parallel;
[0280] The second processor in the heterogeneous system is called to perform round-robin calculations on the pre-processing results of each subtask according to the number of task samples, and performs parallel post-processing of the subtask calculation results once each round of subtask calculation results are obtained; the number of subtasks in each round of calculation is the same as the number of task samples;
[0281] The task processing result of the task to be processed is determined according to the post-processing result of each subtask.
[0282] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0283] According to the call instruction of the first processor in the heterogeneous system, the pre-processing results of the plurality of subtasks are calculated in a round-robin manner according to the number of task samples; the plurality of subtasks are obtained by dividing the tasks to be processed;
[0284] When a round of subtask calculation results is obtained, parallel post-processing of the subtask calculation results is performed once; the number of subtasks in each round of calculation is the same as the number of task samples;
[0285] The task processing result of the task to be processed is determined according to the post-processing result of each subtask.
[0286] The implementation principles and technical effects of the various steps implemented when the computer program in the embodiment of the present application is executed by the processor are similar to the principles of the above-mentioned violator prediction method, and will not be repeated here.
[0287] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the following steps:
[0288] Perform pre-processing on multiple sub-tasks divided by the task to be processed in parallel;
[0289] The second processor in the heterogeneous system is called to perform round-robin calculations on the pre-processing results of each subtask according to the number of task samples, and performs parallel post-processing of the subtask calculation results once each round of subtask calculation results are obtained; the number of subtasks in each round of calculation is the same as the number of task samples;
[0290] The task processing result of the task to be processed is determined according to the post-processing result of each subtask.
[0291] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0292] According to the call instruction of the first processor in the heterogeneous system, the pre-processing results of the plurality of subtasks are calculated in a round-robin manner according to the number of task samples; the plurality of subtasks are obtained by dividing the tasks to be processed;
[0293] When a round of subtask calculation results is obtained, parallel post-processing of the subtask calculation results is performed once; the number of subtasks in each round of calculation is the same as the number of task samples;
[0294] The task processing result of the task to be processed is determined according to the post-processing result of each subtask.
[0295] The implementation principles and technical effects of the various steps implemented when the computer program in the embodiment of the present application is executed by the processor are similar to the principles of the above-mentioned violator prediction method, and will not be repeated here.
[0296] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0297] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above 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.
[0298] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A task processing method, characterized in that: Applied to a first processor in a heterogeneous system, the method comprises: Perform pre-processing on multiple sub-tasks divided by the task to be processed in parallel; Calling the second processor in the heterogeneous system to perform round-robin calculations on the pre-processing results of each subtask according to the number of task samples, and performing parallel post-processing of the subtask calculation results once each time a round of subtask calculation results are obtained; the number of subtasks in each round of calculation is the same as the number of task samples; The task processing result of the task to be processed is determined according to the post-processing result of each of the subtasks.
2. The method according to claim 1, characterized in that The first processor includes a plurality of processing units; the number of the plurality of subtasks is the same as the number of the plurality of processing units; the pre-processing of the plurality of subtasks divided into the task to be processed in parallel includes: When the processing unit is a thread, or when the processing unit is a thread and a process, calling multiple threads to perform pre-processing on the multiple subtasks in parallel; When the processing unit is a process, multiple processes are called to perform pre-processing on the multiple subtasks in parallel.
3. The method according to claim 1, characterized in that The pre-processing of the multiple subtasks divided into the task to be processed in parallel includes: The first processor performs pre-processing on each of the subtasks in parallel; or, The first processor calls the second processor to perform pre-processing on each of the subtasks in parallel.
4. The method according to any one of claims 1 to 3, characterized in that The subtask calculation results obtained in each round are obtained by dividing the second processor into multiple execution units based on the number of task samples to calculate the pre-processing results of the corresponding subtasks; In each round of calculation, each execution unit performs a pre-processing result calculation operation of a subtask.
5. The method according to claim 4, characterized in that The method further comprises: Before the plurality of execution units in the second processor perform each round of calculation, performing a locking operation on the plurality of execution units; When it is detected that each round of calculation of the plurality of execution units is completed, a lock release operation is performed on the plurality of execution units.
6. The method according to any one of claims 1 to 3, characterized in that The method of performing parallel post-processing of the subtask calculation results each time a round of subtask calculation results is obtained includes: Each time a round of subtask calculation results is obtained, the first processor performs a parallel post-processing of the subtask calculation results; or, Each time a round of subtask calculation results is obtained, the second processor performs parallel post-processing of the subtask calculation results.
7. The method according to claim 6, characterized in that The first processor includes a plurality of processing units; The first processor performs a parallel post-processing of a subtask calculation result, including: When the processing unit is a thread, or when the processing unit is a thread and a process, the first processor calls multiple threads to perform a parallel post-processing of the subtask calculation result once; In the case where the processing unit is a process, the first processor calls multiple processes to perform parallel post-processing of the subtask calculation results once.
8. The method according to any one of claims 1 to 3, characterized in that The method further comprises: Determine the initial process number corresponding to each initial task sample number according to the video memory size of the second processor and a plurality of initial task sample numbers preset for the second processor; The number of samples of each initial task and the corresponding number of initial processes are determined as a task search space; Based on each of the task search spaces, the number of task samples and the number of processing units in the first processor are determined.
9. The method according to claim 8, characterized in that The determining, based on each of the task search spaces, the number of task samples and the number of processing units in the first processor comprises: According to the number of cores of the first processor, obtaining multiple initial numbers of threads in each of the task search spaces; Determine the target thread task time corresponding to each task search space according to the multiple initial thread numbers in each task search space; The number of threads corresponding to the minimum target thread task duration is determined as the number of processing units; and the number of initial task samples in the task search space corresponding to the minimum target thread task duration is determined as the number of task samples.
10. The method according to claim 8, characterized in that The step of determining the target thread task duration corresponding to each task search space according to the multiple initial thread numbers in each task search space includes: For a plurality of initial thread numbers in any task search space, determining the thread task consumption corresponding to each initial thread number in the task search space; The minimum thread task duration among the determined multiple thread task durations is determined as the target thread task duration corresponding to the task search space.
11. The method according to any one of claims 1 to 3, characterized in that: Determining the task processing result of the task to be processed according to the post-processing result of each of the subtasks includes: The post-processing results of each of the subtasks are fused to obtain the task processing result of the task to be processed.
12. A task processing method, characterized in that: Applied to a second processor in a heterogeneous system, the method comprises: According to the calling instruction of the first processor in the heterogeneous system, performing round-robin calculation on the pre-processing results of a plurality of subtasks according to the number of task samples; the plurality of subtasks are obtained by dividing the tasks to be processed; When each round of subtask calculation results is obtained, parallel post-processing of the subtask calculation results is performed once; the number of subtasks in each round of calculation is the same as the number of task samples; The task processing result of the task to be processed is determined according to the post-processing result of each of the subtasks.
13. A heterogeneous system, characterized in that: comprising a first processor and a second processor, wherein the first processor is configured to execute the steps of the method according to any one of claims 1 to 11; The second processor is configured to execute the steps of the method as claimed in claim 12.
Citation Information
Cited By
Iterative task processing method, photoelectric hybrid equipment medium and product
CN120256129A
A processing method for iterative tasks, an optoelectronic hybrid device medium, and a product
CN120256129B
