An automatic load balancing method for CPU-GPU two-level parallel computing
By obtaining hardware performance parameters and calculating the number of threads and task times on the CPU and GPU, and using formulas to allocate the number of tasks, the problem of low computational efficiency in CPU-GPU two-level parallel computing is solved and the optimal balance between CPU and GPU is achieved. Optimal task allocation ensures the shortest total execution time and improves computing efficiency.
Patent Information
- Application Number
- CN202111464876.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-03
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2041-12-03
AI Technical Summary
In the existing technology, CPU-GPU two-level parallel computing is prone to encounter performance bottlenecks when processing a large number of tasks, resulting in low computing efficiency.
By obtaining hardware performance parameters, calculating the number of threads and task times on the CPU and GPU, and using a formula to allocate the number of tasks, to achieve optimal task distribution between the CPU and GPU and ensure the shortest total execution time.
The task allocation efficiency of the CPU and GPU is improved, allowing two-level parallel computing to complete tasks at the same time, reducing the total execution time and improving computing efficiency.
Smart Images

Figure CN114398167B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to an automatic load balancing method for CPU-GPU two-level parallel computing. Background Art
[0002] In 1971, Intel launched the world's first general-purpose microprocessor. Gordon Moore, one of the company's co-founders, proposed "Moore's Law" - every 18 months, the number of transistors that can be integrated on a chip will double. The more transistors integrated on a chip, the faster the computing speed, that is, the main frequency. But in 2005, when the main frequency approached 4GHz, Intel and AMD found that the speed would also encounter its own limit: that is, simply increasing the main frequency could no longer significantly improve the overall performance of the system, so Intel / AMD began to produce dual-core and multi-core CPUs.
[0003] Increasing the number of cores is to increase the number of threads. The operating system executes tasks through threads. Generally, they have a 1:1 correspondence, that is, a quad-core CPU generally has four threads. However, after Intel introduced hyperthreading technology, the number of cores and threads formed a 1:2 relationship. For example, the quad-core Core i7 supports eight threads (or eight logical cores), which greatly improves its multi-tasking and multi-threading performance.
[0004] In existing plans, when the number of tasks to be processed is large, the multi-threaded CPU may encounter performance bottlenecks, and the GPU can also process tasks in parallel, resulting in low computing efficiency. Summary of the invention
[0005] The present invention proposes an automatic load balancing method for CPU-GPU two-level parallel computing, which is used to solve or at least partially solve the technical problem of low computing efficiency existing in the prior art.
[0006] In order to solve the above technical problems, the present invention provides an automatic load balancing method for CPU-GPU two-level parallel computing, comprising:
[0007] S1: Get the hardware performance parameter, which is the number of CPU cores.
[0008] S2: Get the number of threads created in the CPU according to the number of CPU cores;
[0009] S3: Obtain the total number of parallel computing tasks and multi-threaded calibration parameters, and calculate the execution time of a single task on the CPU and GPU respectively;
[0010] S4: When the total execution time is the shortest, calculate the number of tasks assigned to the CPU and the number of tasks assigned to the GPU based on the number of threads created in the CPU, the total number of tasks for parallel computing, the multi-threading correction parameter, the time required for a single task to execute on the CPU, and the time required for a single task to execute on the GPU, wherein the sum of the number of tasks assigned to the CPU and the number of tasks assigned to the GPU is the total number of tasks.
[0011] In one embodiment, step S4 includes:
[0012] The number of tasks assigned to the CPU is calculated according to the formula:
[0013]
[0014] The number of tasks assigned to the GPU is calculated according to the formula:
[0015]
[0016] Where s1 represents the number of tasks assigned to the CPU, s2 represents the number of tasks assigned to the GPU, k represents the number of threads created in the CPU, s represents the total number of tasks for parallel computing, α represents the multithreading correction parameter, and r gpu Indicates the computational acceleration ratio of a single task on the GPU. t cpu Indicates the time required for a single task to execute on the CPU, t gpu Indicates the time required for a single task to execute on the GPU.
[0017] The above one or more technical solutions in the embodiments of the present application have at least one or more of the following technical effects:
[0018] The invention provided by the present invention relates to an automatic load balancing method for CPU-GPU two-level parallel computing, which first obtains the number of CPU cores, and obtains the number of threads created in the CPU according to the number of CPU cores; obtains the total number of tasks and multi-threading correction parameters of the parallel computing, and calculates the time required for a single task to be executed on the CPU and GPU respectively; calculates the optimal task allocation between the CPU and the GPU when the total execution time is the shortest, so as to ensure that the CPU and the GPU complete the tasks at the same time, thereby improving the computing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0020] Figure 1 A flow chart of an automatic load balancing method for CPU-GPU two-level parallel computing provided by an embodiment of the present invention;
[0021] Figure 2 This is a calculation time diagram of the CPU and GPU when the total calculation time is the shortest in an embodiment of the present invention. DETAILED DESCRIPTION
[0022] The present invention provides an automatic load balancing method for CPU-GPU two-level parallel computing. The balance of two-level parallel computing is affected by many factors, such as task volume, computational complexity, CPU performance, multithreading overhead and GPU performance. Therefore, the present invention proposes an optimal task allocation strategy to achieve the shortest total execution time. For the load balancing problem, it is necessary to calculate the optimal task allocation between the CPU and the GPU to ensure that the CPU and the GPU complete the tasks at the same time and reduce the total execution time as much as possible.
[0023] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0024] The embodiment of the present invention provides an automatic load balancing method for CPU-GPU two-level parallel computing, including:
[0025] S1: Get the hardware performance parameter, which is the number of CPU cores.
[0026] S2: Get the number of threads created in the CPU according to the number of CPU cores;
[0027] S3: Obtain the total number of parallel computing tasks and multi-threaded calibration parameters, and calculate the execution time of a single task on the CPU and GPU respectively;
[0028] S4: When the total execution time is the shortest, calculate the number of tasks assigned to the CPU and the number of tasks assigned to the GPU based on the number of threads created in the CPU, the total number of tasks for parallel computing, the multi-threading correction parameter, the time required for a single task to execute on the CPU, and the time required for a single task to execute on the GPU, wherein the sum of the number of tasks assigned to the CPU and the number of tasks assigned to the GPU is the total number of tasks.
[0029] The inventor of this application has found through extensive research and practice that in the process of multi-threaded CPU and GPU two-level parallel computing, in order to improve the operating efficiency, it is necessary to reasonably divide the distribution ratio of tasks. By using the idea of load balancing and task scheduling, the task load on the multi-threaded CPU and GPU can be balanced, and the execution time required for both to complete their respective tasks is equal. At this time, the total execution time of the task is the shortest, and the CPU and GPU two-level parallel computing efficiency is maximized.
[0030] Load balancing is a computer technology used to distribute loads among multiple computers (computer clusters), network connections, CPUs, disk drives, or other resources to optimize resource usage, maximize throughput, minimize response time, and avoid overload. In CPU-GPU two-level parallel computing, the load (work tasks, access requests) is balanced and distributed to multiple operation units (multi-threaded CPUs and GPUs) for execution. It is the ultimate solution to improve computer operating efficiency and achieve high-performance computing.
[0031] See also Figure 1 , is a flow chart of an automatic load balancing method for CPU-GPU two-level parallel computing provided by an embodiment of the present invention. The balance of two-level parallel computing is affected by many factors, such as task volume, computational complexity, CPU performance, multi-threading overhead, and GPU performance. Therefore, an optimal task allocation strategy is proposed to achieve the shortest total execution time. For the load balancing problem, it is necessary to calculate the optimal task allocation between the CPU and the GPU to ensure that the CPU and the GPU complete the tasks at the same time and minimize the total execution time.
[0032] In one embodiment, step S4 includes:
[0033] The number of tasks assigned to the CPU is calculated according to the formula:
[0034]
[0035] The number of tasks assigned to the GPU is calculated according to the formula:
[0036]
[0037] Among them, s1 represents the number of tasks assigned to the CPU, k represents the number of threads created in the CPU, s represents the total number of tasks for parallel computing, α represents the multithreading correction parameter, and r gpu Indicates the computational acceleration ratio of a single task on the GPU. t cpu Indicates the time required for a single task to execute on the CPU, t gpu Indicates the time required for a single task to execute on the GPU.
[0038] Specifically, for the load balancing problem, it is necessary to calculate the optimal task allocation between the CPU and GPU to ensure that the CPU and GPU complete their tasks at the same time and minimize the total execution time. As shown in Table 1, many factors affect the execution time, including the amount of data (S), computational complexity (O), CPU (H cpu ) and GPU (H gpu )’s hardware performance and CPU multithreading overhead (A).
[0039] Table 1 shows the key factors affecting the total execution time.
[0040]
[0041]
[0042] (S), (O) may vary in different tasks. Hardware performance may be affected by many complex factors, such as CPU frequency, number of CPU cores, bus frequency, GPU computing power, bandwidth, and cache and memory size. Considering the complexity of measuring these factors, the computing time of a data block is used to measure hardware performance (as shown in Table 2). Table 3 lists other variables used later.
[0043] Table 2 Variables measuring key factors
[0044]
[0045] Table 3 Other variables
[0046] variable meaning <![CDATA[s1]]> <![CDATA[s1 + s2 = s, the number of blocks (tasks) allocated to the CPU]]> <![CDATA[s2]]> <![CDATA[s1 + s2 = s, the number of blocks allocated to the GPU]]> k The number of threads created on the CPU <![CDATA[T mt ]]> <![CDATA[Time taken by CPU multi-threading to calculate on s1]]> <![CDATA[T gpu ]]> <![CDATA[Time taken by GPU to compute on s2]]> <![CDATA[T hybrid ]]> The total execution time of two-level parallelism on the data volume s <![CDATA[min{T hybrid }]]> <![CDATA[T hybrid Minimum value of]]> <![CDATA[r mt ]]> The speedup ratio of a single block of calculations executed by CPU multithreading <![CDATA[r gpu ]]> GPU single block computing speedup ratio <![CDATA[max{R hybrid }]]> Maximum speedup of two-level parallel computing on s blocks
[0047] The derivation and implementation process of the load balancing provided by the present invention is described in detail below.
[0048] The automatic load balancing method of the present application is essentially task allocation, and task allocation is a calculation triple, which consists of the number of tasks assigned to the CPU, the number of tasks assigned to the GPU, and the number of threads created on the CPU. The ultimate goal is to use this triple task allocation strategy to shorten the total execution time as much as possible. Define s1 as the number of tasks assigned to the CPU, s2 as the number of tasks assigned to the GPU, and k as the number of threads created in the CPU. The triple can be expressed as
[0049] {s1, s2, k} (1)
[0050] Among them, s1+s2=s and 0≤k≤min{s1,n-1}.
[0051] Then, under two-level parallelism, the CPU multi-threaded computing time of task s1 is
[0052] T mt =αs1t cpu / k (2)
[0053] The GPU computing time of the s2 task is
[0054] T gpu =s2t gpu (3)
[0055] Therefore, the total execution time of the two-level parallel data S is expressed as
[0056] T hybrid =max{T mt ,T gpu} (4)
[0057] =max{αs1t cpu / k,s2t gpu} (5)
[0058] It can be seen that the total execution time is the longest of the multi-threaded CPU and GPU running time if and only if T mt =T gpu When the execution time on the multithreaded CPU and GPU is equal, the total execution time is the shortest.
[0059] Compared with serial execution, the speedup of a task based on CPU multithreading is
[0060]
[0061] The speedup of a task performed on a GPU is
[0062]
[0063] The shortest time can be expressed as
[0064]
[0065] In this case, the number of tasks assigned to the CPU and GPU is determined to be
[0066]
[0067]
[0068] The above formula can be used to obtain the number of tasks assigned to the CPU and GPU when the total execution time is the shortest, and the shortest total execution time can be calculated.
[0069] See also Figure 2 , given by T mt and T gpu Computation time plot when total computation time is the shortest.
[0070] According to the method provided by the present invention, the following conclusions can be drawn:
[0071] Conclusion 1
[0072] Compared with serial execution, the maximum speedup of s tasks based on two-level parallelism is
[0073]
[0074] Equation (11) can be derived from equations (6), (7) and (8).
[0075] From this formula, we can get the speedup ratio of two-level parallel operation and serial operation when only using CPU.
[0076] Conclusion 2
[0077] s1,s2,s3∈N, if and only if and When T hybrid Reached minimum value. The symbol means rounding down to the nearest integer not greater than the expression in the brackets.
[0078] In a multi-core CPU environment, the number of threads is determined by the number of cores and tasks assigned to the CPU. If the number of CPU threads exceeds the number of CPU cores, it will incur additional overhead for kernel context switching. At the same time, the GPU occupies a CPU thread and is responsible for scheduling the GPU. Therefore, the number of threads k created on the CPU should be less than or equal to the number of CPU cores - 1. Each thread on the CPU processes a task, so k should be less than or equal to the number of tasks assigned to the CPU. s1 satisfies the condition
[0079] 0≤k≤min{s1,n-1} (12) Because s1 is related to k, and k≤s1, we get
[0080]
[0081] therefore
[0082]
[0083] This gives the number of threads created on the CPU.
[0084] Finally, the triplet of equation (1) is calculated.
[0085] {s1, s2, k}(14) where and
[0086] Finally, we get the number of tasks assigned to the CPU and GPU, s1 and s2, and the number of threads k divided by the CPU.
[0087] The implementation process of the method provided by the present invention is described below by a specific example.
[0088] First, get the number of CPU cores according to the CPU model. The number of cores is the maximum number of parallel threads of the CPU. One thread is used as the main thread to schedule tasks, and the remaining threads execute tasks.
[0089] Get the number of threads created in the CPU according to the number of CPU cores. For example, if a CPU has 4 cores, the number of threads k created in the CPU is 3.
[0090] Get the total number of parallel computing tasks and multi-threaded calibration parameters, and calculate the time required for a single task to execute on the CPU and GPU. For example, use Nvidia Tesla C2075 GPU, use Gaussian filtering algorithm as the computing task, the image size of the input data is 370*670, the number of images, i.e. the total number of tasks s, is 1000, and the multi-threaded calibration parameter α can be preset, for example, to 1.15. Run a single task on the CPU and GPU to get t cpu is 0.079s and t gpu 0.005s;
[0091] According to formulas (9) and (10), s1 and s2 are obtained, which are 159 and 841 respectively. The number of threads on the CPU is 3, and each thread is assigned 53 tasks.
[0092] According to the above method, the acceleration ratio is 18.108 according to formula (11), and the total task calculation time is 4.412s according to formula (13). At this time, the acceleration ratio is the largest, the total task calculation time is the smallest, and the allocation scheme is optimal.
[0093] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. An automatic load balancing method for CPU-GPU two-level parallel computing, characterized in that: include: S1: Get the hardware performance parameter, which is the number of CPU cores. S2: Get the number of threads created in the CPU according to the number of CPU cores; S3: Obtain the total number of parallel computing tasks and multi-threaded calibration parameters, and calculate the execution time of a single task on the CPU and GPU respectively; S4: when the total execution time is the shortest, the number of tasks assigned to the CPU and the number of tasks assigned to the GPU are calculated according to the number of threads created in the CPU, the total number of tasks in parallel calculation, the multithreading correction parameter, the time required for a single task to be executed on the CPU, and the time required for a single task to be executed on the GPU, wherein the sum of the number of tasks assigned to the CPU and the number of tasks assigned to the GPU is the total number of tasks; Step S4 includes: The number of tasks assigned to the CPU is calculated according to the formula: The number of tasks assigned to the GPU is calculated according to the formula: in, Indicates the number of tasks assigned to the CPU. Indicates the number of tasks assigned to the GPU, Indicates the number of threads created in the CPU. Indicates the total number of parallel computing tasks, Indicates multi-threaded calibration parameters, Indicates the computational acceleration ratio of a single task on the GPU. , Indicates the time required for a single task to execute on the CPU. Indicates the time required for a single task to execute on the GPU.
