GPU parallel computing data double mapping method and system
By determining the number of thread beams based on parallel calculation of instances and maximum number of kernel functions on the GPU, and performing data double-mapping, the problem of low computing efficiency caused by thread beam differentiation is solved, and efficient GPU parallel computing is achieved.
Patent Information
- Application Number
- CN202411801036.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-09
- Publication Date
- 2025-03-11
- Estimated Expiration
- 2044-12-09
AI Technical Summary
In parallel GPU computing, thread beam differentiation leads to low computing efficiency, and the thread data remapping method on the existing CPU side brings additional core startup and data transmission overhead.
By determining the required number of thread beams based on the number of instances and the maximum number of branches of the kernel function, and performing data double-mapping on the GPU, including grouping, chunking and reference redirection, ensure that the thread beam remains executed in parallel during branch calculations.
It improves the efficiency of GPU parallel computing, avoids the increase in computing time caused by the thread bundle from parallel to serial execution, and reduces the overhead caused by core splitting on the CPU side.
Smart Images

Figure CN119597487A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of parallel computing, and in particular to a GPU parallel computing data dual mapping method and system. Background Art
[0002] In recent years, GPU parallel computing has been widely used in many fields such as neural networks, image processing, radar simulation and complex control system simulation, and has achieved remarkable results.
[0003] Each thread bundle performs calculations according to the SIMD (Single Instruction Multiple Date) parallel computing architecture, that is, the same instruction is executed in parallel within the thread bundle. This computing architecture will cause thread bundle differentiation in the branch selection stage of the model, converting from full parallel execution to grouped serial execution, reducing computing efficiency. In GPU parallel computing, the branch divergence problem generated when executing complex logical branches has always been a problem that many researchers have been committed to solving. Currently, it is mainly thread data remapping (TDR) on the CPU. The CPU-side TDR uses a kernel splitting method to establish a feedback-optimization loop to solve the two problems of branch conditional dependence on GPU computing results and multi-conditional branches. However, this method will undoubtedly bring additional kernel startup and round-trip data transmission overhead, and the parallel computing efficiency is low. Summary of the invention
[0004] In view of the above analysis, the embodiments of the present invention aim to provide a GPU parallel computing data dual mapping method and system to solve the problem of low parallel computing efficiency caused by existing thread warp differentiation.
[0005] On the one hand, an embodiment of the present invention provides a GPU parallel computing data dual mapping method, comprising the following steps:
[0006] Determine the number of thread bundles required by the kernel function according to the number of parallel computing instances and the maximum number of branches of the kernel function, generate parallel computing threads and determine the original ID and index ID of the thread. The index ID of the thread is used to determine the instance corresponding to the thread.
[0007] If the current instruction to be executed is a branch calculation instruction, each current valid thread determines the group, block and position in the block to which the instance corresponding to the current index ID of the valid thread belongs according to the branch judgment condition;
[0008] Redirect references to each thread bundle and determine the grouping corresponding to each thread bundle; redirect references to each thread according to the grouping corresponding to the thread bundle to which the thread belongs, determine the block corresponding to the thread and the position in the block, and obtain a new index ID for the thread;
[0009] If the current instruction to be executed is a branch calculation end instruction, the index ID value of each thread is modified to the original ID value;
[0010] Otherwise, each thread determines whether the thread is valid according to the index ID. If so, the instance corresponding to the thread is determined according to the index ID, and the current instruction to be executed is calculated.
[0011] Based on the further improvement of the above method, the number of thread warps required by the kernel function is determined by the following formula according to the number of parallel computing instances and the maximum number of branches of the kernel function:
[0012]
[0013] Where g represents the number of thread warps, x represents the number of instances, and w c Indicates the warp size, and n indicates the maximum number of branches of the kernel function.
[0014] Based on the further improvement of the above method, the group, block and position in the block to which the instance corresponding to the current index ID of the valid thread belongs are determined according to the branch judgment condition, including:
[0015] Determine the group to which the instance corresponding to the current index ID of the valid thread belongs according to the branch judgment condition;
[0016] Determine the block to which the instance belongs in the group according to the instance ID;
[0017] The position of an instance in its corresponding block is calculated atomically.
[0018] Based on the further improvement of the above method, reference redirection is performed on each thread warp to determine the group corresponding to each thread warp, including:
[0019] Determine the number of warps required for each group and the warp start index and warp end index of each group according to the number of instances of each block in each group;
[0020] The group corresponding to each warp is obtained according to the warp start index and the warp end index of each group.
[0021] Based on the further improvement of the above method, the number of thread warps required for each group is determined by the following formula according to the number of instances of each block in each group:
[0022]
[0023] Among them, b ij represents the number of instances in the jth block in the i-th group, m i represents the number of blocks in the i-th group, w irepresents the number of thread warps required for the i-th group, w c Indicates the warp size.
[0024] Based on the further improvement of the above method, the following formula is used to calculate the thread warp start index and thread warp start index of each group:
[0025]
[0026] Among them, w j represents the number of thread warps required for the jth group, gS i represents the starting index of the thread warp of the i-th group, gE i Indicates the warp end index of the i-th group.
[0027] Based on the further improvement of the above method, each thread redirects the reference of the thread according to the group corresponding to the thread warp to which the thread belongs, determines the block corresponding to the thread and the position in the block, and obtains the new index ID of the thread, including:
[0028] Each thread calculates the thread start index and thread end index corresponding to each block in the group corresponding to the thread warp to which the thread belongs;
[0029] Calculate the neighborhood index of the thread according to the thread warp start index of the group corresponding to the thread warp to which the thread belongs;
[0030] Determine the block corresponding to the thread according to the thread start index and thread end index corresponding to each block in the group corresponding to the thread warp to which the thread belongs, and the neighborhood index of the thread;
[0031] The position of the block corresponding to the thread is determined according to the neighborhood index of the thread and the thread start index of the block corresponding to the thread, and a new index ID of the thread is obtained.
[0032] Based on the further improvement of the above method, the neighborhood index of the thread is calculated according to the following formula:
[0033] nid kw =(wid k -gS i ))*w c +twid kw
[0034] Among them, nid kw Indicates the neighborhood index corresponding to the wth thread of the kth thread warp, wid k represents the index of the kth warp, gS i represents the starting index of the thread warp of the i-th group, w c Indicates the thread bundle size, twid kwIndicates the number of the wth thread in the kth warp.
[0035] Based on the further improvement of the above method, the following formula is used to calculate the thread start index and thread end index corresponding to each block in the group corresponding to the thread warp to which the thread belongs:
[0036]
[0037] Among them, b il represents the number of instances in the jth block in the i-th group, bS ij represents the thread start index of the jth block of the i-th group, bE ij Indicates the thread end index of the j-th block of the i-th group.
[0038] On the other hand, an embodiment of the present invention provides a GPU parallel computing data dual mapping system, including the following modules:
[0039] A thread grid determination module is used to determine the number of thread bundles required by the kernel function according to the number of parallel computing instances and the maximum number of branches of the kernel function, generate parallel computing threads and determine the original ID and index ID of the thread, and the index ID of the thread is used to determine the instance corresponding to the thread;
[0040] A grouping module, which is used for determining, if the current instruction to be executed is a branch calculation instruction, the group, block and position in the block to which the instance corresponding to the current index ID of each current valid thread belongs according to the branch judgment condition;
[0041] A remapping module is used to redirect references to each thread bundle and determine the group corresponding to each thread bundle; each thread redirects references to the thread according to the group corresponding to the thread bundle to which the thread belongs, determines the block corresponding to the thread and the position in the block, and obtains a new index ID of the thread;
[0042] An index restoration module, used to modify the index ID value of each thread to the original ID value if the current instruction to be executed is a branch calculation end instruction;
[0043] The calculation module is used to determine whether each thread is valid according to the index ID if the current instruction to be executed is not a branch calculation instruction or a branch calculation end instruction. If so, the instance corresponding to the thread is determined according to the index ID to calculate the current instruction to be executed.
[0044] Compared with the prior art, the present invention determines the required number of thread bundles according to the number of parallel computing instances and the maximum number of branches in the kernel function, thereby ensuring that there are enough thread bundles for parallel computing in each branch computing, thereby improving computing efficiency; before the thread executes an instruction, if the instruction to be executed is a branch computing instruction, the instance corresponding to the thread index ID is grouped and blocked according to the branch judgment condition, and the position in the block is determined, and then the thread bundle is referenced and redirected, and the thread is referenced and redirected, and the new index ID of the thread is determined. When the branch computing is completed, the index ID of the thread is still modified to the original ID, so that when the instruction in the branch is executed, the corresponding instance is determined according to the index ID, ensuring that the same thread bundle executes the same branch path, so that all instances can be calculated in parallel, shortening the computing time, improving computing efficiency, avoiding the problem of differentiation problem that causes the thread bundle to be converted from all parallel execution to partial thread serial execution to increase the computing time, and because the thread remapping is performed in the GPU, the problem of additional kernel startup and round-trip data transmission overhead caused by kernel splitting on the CPU side is avoided, thereby improving the efficiency of parallel computing.
[0045] In the present invention, the above-mentioned technical solutions can also be combined with each other to achieve more preferred combination solutions. Other features and advantages of the present invention will be described in the subsequent description, and some advantages can become obvious from the description, or can be understood by practicing the present invention. The purpose and other advantages of the present invention can be realized and obtained through the contents particularly pointed out in the description and the drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] The accompanying drawings are only used for the purpose of illustrating specific embodiments and are not to be considered as limiting the present invention. In the entire drawings, the same reference symbols represent the same components;
[0047] Figure 1 This is a flow chart of a GPU parallel computing data dual mapping method according to an embodiment of the present invention;
[0048] Figure 2 This is a schematic diagram of the CPU and GPU workflow;
[0049] Figure 3 It is a GPU computing framework diagram;
[0050] Figure 4 The block diagram of the GPU parallel computing data dual mapping system according to an embodiment of the present invention. DETAILED DESCRIPTION
[0051] The preferred embodiments of the present invention are described in detail below in conjunction with the accompanying drawings, wherein the accompanying drawings constitute a part of this application and are used together with the embodiments of the present invention to illustrate the principles of the present invention, but are not used to limit the scope of the present invention.
[0052] GPU cannot perform independent computing, but can only be used as a coprocessor to form a heterogeneous computing platform with CPU to complete computing tasks. The collaborative work of the two lays the foundation for asynchronous computing. The CPU plays a control role and is called the host, while the GPU completes the computing and is called the device. The workflow of the two is as follows: Figure 2 After the host transfers the model and data to the device, it sends kernel function calculation instructions to complete the calculation and transmits the calculation results back to the host.
[0053] The framework of CUDA-based GPU computing is divided into two layers: software and hardware. The software layer encapsulates computing tasks into kernel functions. The kernel function thread grid is composed of threads, thread blocks, and grids from small to large. All threads are executed concurrently. The hardware layer can be simply viewed as stream processors (SP), stream processor arrays, and stream multiprocessors (SM). There is a mapping relationship from the software layer to the hardware layer. First, the software layer uses thread blocks as allocation units, and the hardware layer uses SM as allocation units. One SM can correspond to multiple thread blocks of the same kernel function or different kernel functions. Secondly, the threads in the thread block are organized into thread bundles according to their numbers. Each thread bundle contains up to 32 threads, completing the mapping of thread bundles and SP arrays. Each SP array can correspond to multiple thread bundles of the same thread block or different thread blocks, such as Figure 3 As shown, the mapping between the SP array and multiple thread warps is implemented through the thread warp scheduler and the instruction transmitter.
[0054] Each thread warp performs calculations according to the SIMD (Single Instruction Multiple Thread) parallel computing architecture, that is, the same instruction is executed in parallel within the thread warp. This computing architecture will cause thread warp differentiation when encountering branch selection, converting from full parallel execution to grouped serial execution, reducing computing efficiency.
[0055] Based on this, a specific embodiment of the present invention discloses a GPU parallel computing data dual mapping method, such as Figure 1 As shown, the following steps are included:
[0056] S1. Determine the number of thread bundles required by the kernel function according to the number of parallel computing instances and the maximum number of branches of the kernel function, generate parallel computing threads and determine the original ID and index ID of the thread, where the index ID of the thread is used to determine the instance corresponding to the thread;
[0057] S2. If the current instruction to be executed is a branch calculation instruction, each current valid thread determines the group, block and position in the block to which the instance corresponding to the current index ID of the valid thread belongs according to the branch judgment condition;
[0058] Redirect references to each thread warp and determine the grouping corresponding to each thread warp;
[0059] Each thread redirects the reference of the thread according to the group corresponding to the thread bundle to which the thread belongs, determines the block corresponding to the thread and the position in the block, and obtains the new index ID of the thread;
[0060] If the current instruction to be executed is a branch calculation end instruction, the index ID value of each thread is modified to the original ID value;
[0061] Otherwise, each thread determines whether the thread is valid according to the index ID. If so, the instance corresponding to the thread is determined according to the index ID, and the current instruction to be executed is calculated.
[0062] It should be noted that an instance is an object that needs to be calculated in parallel. For example, when performing parallel calculation of a car cluster simulation, a basic operator unit in the car model (such as a car torque loss calculation unit) is an instance. When performing parallel calculation, there must be as many instances of the basic operator unit as there are cars in the cluster.
[0063] It should be noted that the original ID and index ID of the thread are initially the same, both are instance IDs. The number of generated threads may exceed the number of instances. According to the thread number sequence, the original ID and index ID of the thread whose number is greater than the number of instances can be assigned other values, as long as they are different from the instance ID.
[0064] During implementation, the index ID is used to determine whether the thread is a valid ID. If the index ID of the thread is the same as an instance ID, it is a valid thread; otherwise, it is not a valid thread.
[0065] Branch calculation instructions, such as if-else statements, execute different branch instructions based on different judgment conditions.
[0066] Reference redirection is to redirect the reference index of a group of threads to the data in the same data group. In GPU programming, threads go to the corresponding position in the data set to obtain input data based on the reference index. The reference index is usually the thread ID or its arithmetic expression. By changing the index, the threads in the thread bundle can obtain data from the same data group from the data set.
[0067] Compared with the prior art, the GPU parallel computing data dual mapping method provided by the present embodiment determines the required number of thread bundles according to the number of parallel computing instances and the maximum number of branches in the kernel function, thereby ensuring that there are enough thread bundles for parallel computing in each branch computing, thereby improving computing efficiency; before the thread executes an instruction, if the instruction to be executed is a branch computing instruction, the instance corresponding to the thread index ID is grouped and blocked according to the branch judgment condition, and the position in the block is determined, and then the thread bundle is referenced and redirected, and then the thread is referenced and redirected, and the new index ID of the thread is determined. When the branch computing is completed, the index ID of the thread is still modified to the original ID, so that when the instruction in the branch is executed, the corresponding instance is determined according to the index ID, ensuring that the same thread bundle executes the same branch path, so that all instances can be calculated in parallel, shortening the computing time, improving computing efficiency, avoiding the problem of differentiation causing the thread bundle to be converted from all parallel execution to partial thread serial execution, which increases the computing time, and because the thread remapping is performed in the GPU, the problem of additional kernel startup and round-trip data transmission overhead caused by kernel splitting on the CPU side is avoided, thereby improving the efficiency of parallel computing.
[0068] When executing a parallel calculation, first encapsulate the instance that needs parallel calculation into a kernel function, determine the thread grid of the kernel function, and then generate a sufficient number of threads on the GPU side to complete the parallel calculation. The existing thread bundle optimization algorithm determines the number of threads according to the number of instances of parallel calculation, that is, as many threads as there are instances, so even after optimization, the differentiation problem is still inevitable. The present invention determines the number of thread bundles required for the kernel function according to the number of parallel calculation instances and the maximum number of branches of the kernel function, thereby ensuring that there are enough thread bundles for parallel calculation every time a branch is encountered, thereby shortening the calculation time and improving the calculation efficiency.
[0069] Specifically, the number of thread warps required by the kernel function is determined using the following formula based on the number of parallel computing instances and the maximum number of branches of the kernel function:
[0070]
[0071] Where g represents the number of thread warps, x represents the number of instances, and w c Indicates the warp size, n indicates the maximum number of branches in the kernel function. The warp size is the number of threads in the warp.
[0072] The thread grid is mainly used to determine the number of threads started by the kernel function. To ensure that each thread bundle does not split, the required number of thread bundles is determined using formula (1) based on the number of parallel computing instances and the maximum number of branches of the kernel function.
[0073] For example, there is a set of branches inside the kernel function calculated as:
[0074] if(yy1>0){
[0075] }
[0076] else{
[0077] }
[0078] Another set of branches is calculated as:
[0079] if(yy2>16){
[0080] }
[0081] else if(yy2>0){
[0082] }
[0083] else{
[0084] }
[0085] Then the maximum number of branches is the number of branches calculated by the second set of branches, 3.
[0086] If the number of thread warps required for the kernel function is calculated as 3 according to formula (1), then 3 thread warps need to be started to ensure that no differentiation problem occurs when the thread warps are executed in parallel.
[0087] After the threads are generated, they execute the computation instructions of the kernel function in parallel.
[0088] If the instruction to be executed is not a branch calculation instruction, each thread first determines whether it is a valid thread based on its index ID. If so, it directly obtains the data of the corresponding instance from the corresponding position in the data set according to its index ID (i.e., reference index) to perform the corresponding calculation. Otherwise, it waits.
[0089] If the instruction to be executed is a branch calculation instruction, reference remapping is required.
[0090] Branch calculation instructions, such as if, else statements.
[0091] If the current instruction to be executed is a branch calculation instruction, each current valid thread determines the group, block and position in the block to which the instance corresponding to the current index ID of the valid thread belongs according to the branch judgment condition, specifically including:
[0092] S211, determining the group to which the instance corresponding to the current index ID of the valid thread belongs according to the branch judgment condition;
[0093] S212, determining the block to which the instance belongs in the group according to the instance ID;
[0094] S213: Calculate the position of the instance in the corresponding block in an atomic manner.
[0095] The first group of branch calculations is used as an example for explanation. The judgment object yy1 is a certain data of the instance. According to the data yy1 of the instance, the instance is divided into two groups, that is, the instances with yy1 greater than 0 are in one group, and the instances with yy1 less than or equal to 0 are in another group. Each group is executed by one or more thread bundles, that is, the threads in each thread bundle execute the instructions of the same branch path, so there is no differentiation.
[0096] It should be noted that, since all instances may be grouped into one group, the reserved length of each group is the number of instances x.
[0097] Since the atomic operation of multi-threading is a serial process, in order to further improve efficiency, the group is further divided into blocks, and the block to which the instance belongs in the group is determined according to the instance ID. The effective thread uses atomic method to calculate the position of the instance corresponding to the current index ID of the effective thread in the corresponding block, thereby improving computing efficiency.
[0098] During implementation, for example, if the number of blocks is determined to be m and the reserved length of the group is x, then the instances with instance IDs of 1 to x / m belong to the first block (according to the branch judgment condition, they may be included in the first block of the first group or the first block of the second group), and the instances with serial numbers of x / m+1 to 2 (x / m) belong to the second block (according to the branch judgment condition, they may be included in the second block of the first group or the second block of the second group), and so on.
[0099] During implementation, each valid thread determines which group and which block the instance corresponding to its current index ID belongs to, and then atomically calculates the position of the instance in the block:
[0100] count=atomic(G_RR_Order[i][j],1) (2)
[0101] G_RR ij [count] = fid (3)
[0102] Among them, G_RR_Order[i][j] represents the number of instances of the jth block in the current i-th group, G_RR ij represents an array storing the instance ID of the jth block of the i-th group, and count represents the position of the instance in the jth block of the i-th group, that is, in the array G_RR ij The instance ID (fid) is stored in the array G_RR at the index position in ij The corresponding position of the reference is convenient for subsequent accurate reference redirection.
[0103] Since threads in the same warp use atomic methods to parallelly calculate the block index, that is, the position in the block, they can obtain continuous index numbers, which can reduce the memory merging access overhead and improve computing efficiency during multi-threaded parallel computing after reference redirection.
[0104] After determining the group, block, and block index to which the instance belongs, it is necessary to redirect the references of the thread warp according to the instance group, that is, to determine which group of instance data the thread warp will calculate. During implementation, each thread corresponding to the kernel function is remapped.
[0105] Specifically, reference redirection is performed on each thread bundle to determine the group corresponding to each thread bundle, including:
[0106] S221, determining the number of warps required for each group and the warp start index and warp end index of each group according to the number of instances of each block in each group;
[0107] S222: Obtain the group corresponding to each warp according to the warp start index and the warp end index of each group.
[0108] Specifically, the number of thread warps required for each group is determined using the following formula according to the number of instances of each block in each group:
[0109]
[0110] Among them, b ij represents the number of instances in the jth block in the i-th group, m i represents the number of blocks in the i-th group, w i represents the number of thread warps required for the i-th group, w c Indicates the warp size.
[0111] During implementation, the number of warps required for each group is determined according to the number of instances corresponding to each block of each group.
[0112] After calculating the number of thread bundles required for each group, the thread bundles are sorted by index, and the thread bundle start index and thread bundle end index of each group are determined, so as to determine which group each thread bundle corresponds to.
[0113] Specifically, the following formula is used to calculate the thread warp start index and thread warp end index of each group:
[0114]
[0115] Among them, w j represents the number of thread warps required for the jth group, gS i represents the starting index of the thread warp of the i-th group, gEi Indicates the warp end index of the i-th group.
[0116] The group corresponding to each thread bundle is obtained according to the thread bundle start index and thread bundle end index of each group, that is, if the index wid of the kth thread bundle is k ∈[gS i ,gE i ), then the kth thread warp corresponds to the i-th group.
[0117] During implementation, in order to reduce the amount of calculation, with the help of the shared memory variables of the GPU, only one thread in each thread warp needs to determine the group corresponding to the thread warp according to steps S221 to S222, and other threads in the same thread warp can obtain the group ID corresponding to the thread warp, that is, the group number gid corresponding to the kth thread warp k is a shared memory variable. In addition, the starting index gS of the thread warp of the i-th group i It is also a shared memory variable, thus reducing the amount of calculation.
[0118] After determining the group corresponding to the thread warp, it is necessary to further determine which instance data each thread executes the calculation for. Therefore, each thread redirects the reference to the thread according to the group corresponding to the thread warp to which the thread belongs, determines the block corresponding to the thread and the position in the block, and obtains the new index ID of the thread. Specifically, it includes:
[0119] S41, each thread calculates a thread start index and a thread end index corresponding to each block in a group corresponding to a thread warp to which the thread belongs;
[0120] S42, calculating the neighborhood index of the thread according to the thread warp start index of the group corresponding to the thread warp to which the thread belongs;
[0121] S43, determining the block corresponding to the thread according to the thread start index and thread end index corresponding to each block in the group corresponding to the thread warp to which the thread belongs, and the neighborhood index of the thread;
[0122] S44. Determine the position of the block corresponding to the thread according to the neighborhood index of the thread and the thread start index of the block corresponding to the thread, and obtain a new index ID of the thread.
[0123] In implementation, warps corresponding to the same group are called neighborhoods.
[0124] When implemented, the thread is identified by its neighborhood index nid in the neighborhood. kw , then according to nid kw Determine the position of its reference index, that is, the position of the reference index in the block, so as to find its corresponding instance and complete the corresponding calculation of the instance data.
[0125] Specifically, the neighborhood index of a thread is calculated according to the following formula:
[0126] nid kw =(wid k -gS i )*w c +twid kw (7)
[0127] Among them, nid kw Indicates the neighborhood index corresponding to the wth thread of the kth thread warp, wid k The index of the kth warp, gS i represents the starting index of the thread warp of the i-th group, w c Indicates the thread bundle size, twid kw Indicates the number of the wth thread in the kth warp.
[0128] Specifically, the following formula is used to calculate the thread start index and thread end index corresponding to each block in the group corresponding to the thread warp to which the thread belongs:
[0129]
[0130] Among them, b il represents the number of instances in the jth block in the i-th group, bS ij represents the thread start index of the jth block of the i-th group, bE ij Indicates the thread end index of the j-th block of the i-th group.
[0131] Then, the block corresponding to the thread is determined according to the thread start index and thread end index corresponding to each block in the group corresponding to the thread warp to which the thread belongs, as well as the neighborhood index of the thread. kw ∈[bS ij ,bE ij ), then the wth thread of the kth thread bundle corresponds to the jth block of the ith group, so the block ID corresponding to the thread is obtained, which is expressed as bid kw .
[0132] After obtaining the block corresponding to the thread, the position in the block corresponding to the thread is determined according to the neighborhood index of the thread and the thread start index of the block corresponding to the thread, and a new index ID of the thread is obtained.
[0133] During implementation, according to nid kw -bS ij Get the position of the thread in the block, array G_RRij To store the instance ID of the jth block of the i-th group, take the array The value stored in is used to obtain the new index ID of the wth thread of the kth thread warp.
[0134] It should be noted that if the kth thread bundle corresponds to the ith group, and the neighborhood index of the wth thread of the kth thread bundle is not within the thread index range corresponding to any block of the ith group, then the index ID of the wth thread of the kth thread bundle is set to a value different from the instance ID, that is, the thread does not correspond to a real instance.
[0135] After obtaining the new index ID, the thread obtains the data of the corresponding instance according to its index ID for calculation, thereby improving the efficiency of parallel computing.
[0136] When the branch calculation is completed, that is, the instruction to be executed is the branch calculation end instruction, the index ID value of the thread is still modified to the original ID value, so as to accurately determine the corresponding instance of the thread when the branch calculation is performed next time, and at the same time reduce memory merge access and improve the efficiency of memory reading.
[0137] During implementation, the effect of the present invention is explained by taking a basic calculation unit in automobile model simulation, namely, an automobile loss torque calculation unit, as an example. Different automobiles need to perform different calculations at different stages, so there are different calculation branches in the calculation part of the automobile loss torque calculation unit.
[0138] Two groups of data are generated, one group is data that will not cause the thread bundle to execute different branches, and the other group is data that will cause the thread bundle to execute different branches. The results obtained by directly performing parallel calculations on the first group of data are shown in the first row of Table 1. For the second group of data, two methods are used for parallel calculations: parallel calculations using the data dual mapping of the present invention and parallel calculations without using the data dual mapping of the present invention. The results are shown in the second and third rows of Table 1, respectively. It can be seen that the method of the present invention can solve the differentiation problem well, improve the calculation efficiency, and the time consumed is close to the calculation time of the data without differentiation.
[0139] Table 1: Test results
[0140]
[0141] A specific embodiment of the present invention discloses a GPU parallel computing data dual mapping system, such as Figure 4 As shown, it includes the following modules:
[0142] A thread grid determination module is used to determine the number of thread bundles required by the kernel function according to the number of parallel computing instances and the maximum number of branches of the kernel function, generate parallel computing threads and determine the original ID and index ID of the thread, and the index ID of the thread is used to determine the instance corresponding to the thread;
[0143] A grouping module, which is used for determining, if the current instruction to be executed is a branch calculation instruction, the group, block and position in the block to which the instance corresponding to the current index ID of each current valid thread belongs according to the branch judgment condition;
[0144] A remapping module is used to redirect references to each thread bundle and determine the group corresponding to each thread bundle; each thread redirects references to the thread according to the group corresponding to the thread bundle to which the thread belongs, determines the block corresponding to the thread and the position in the block, and obtains a new index ID of the thread;
[0145] An index restoration module, used to modify the index ID value of each thread to the original ID value if the current instruction to be executed is a branch calculation end instruction;
[0146] The calculation module is used to determine whether each thread is valid according to the index ID if the current instruction to be executed is not a branch calculation instruction or a branch calculation end instruction. If so, the instance corresponding to the thread is determined according to the index ID to calculate the current instruction to be executed.
[0147] The above method embodiments and system embodiments are based on the same principle, and their related parts can be used for reference, and can achieve the same technical effect. The specific implementation process refers to the above embodiment, which will not be repeated here.
[0148] Those skilled in the art will appreciate that all or part of the processes of the above-mentioned embodiments can be implemented by instructing related hardware through a computer program, and the program can be stored in a computer-readable storage medium, wherein the computer-readable storage medium is a disk, an optical disk, a read-only storage memory, or a random access memory, etc.
[0149] The above description is only a preferred specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily conceived by any technician familiar with the technical field within the technical scope disclosed by the present invention should be covered within the protection scope of the present invention.
Claims
1. A GPU parallel computing data dual mapping method, characterized in that: The following steps are involved: Determine the number of thread bundles required by the kernel function according to the number of parallel computing instances and the maximum number of branches of the kernel function, generate parallel computing threads and determine the original ID and index ID of the thread. The index ID of the thread is used to determine the instance corresponding to the thread. If the current instruction to be executed is a branch calculation instruction, each current valid thread determines the group, block and position in the block to which the instance corresponding to the current index ID of the valid thread belongs according to the branch judgment condition; Redirect references to each thread bundle and determine the grouping corresponding to each thread bundle; redirect references to each thread according to the grouping corresponding to the thread bundle to which the thread belongs, determine the block corresponding to the thread and the position in the block, and obtain a new index ID for the thread; If the current instruction to be executed is a branch calculation end instruction, the index ID value of each thread is modified to the original ID value; Otherwise, each thread determines whether the thread is valid according to the index ID. If so, the instance corresponding to the thread is determined according to the index ID, and the current instruction to be executed is calculated.
2. The GPU parallel computing data dual mapping method according to claim 1, characterized in that: The number of thread warps required by the kernel function is determined using the following formula based on the number of parallel computing instances and the maximum number of branches of the kernel function: Where g represents the number of thread warps, x represents the number of instances, and w c Indicates the warp size, and n indicates the maximum number of branches of the kernel function.
3. The GPU parallel computing data dual mapping method according to claim 1, characterized in that: Determine the group, block and position in the block to which the instance corresponding to the current index ID of the valid thread belongs according to the branch judgment condition, including: Determine the group to which the instance corresponding to the current index ID of the valid thread belongs according to the branch judgment condition; Determine the block to which the instance belongs in the group according to the instance ID; The position of an instance in its corresponding block is calculated atomically.
4. The GPU parallel computing data dual mapping method according to claim 1, characterized in that: Redirect references to each warp and determine the grouping corresponding to each warp, including: Determine the number of warps required for each group and the warp start index and warp end index of each group according to the number of instances of each block in each group; The group corresponding to each warp is obtained according to the warp start index and the warp end index of each group.
5. The GPU parallel computing data dual mapping method according to claim 4, characterized in that: The number of warps required for each group is determined using the following formula based on the number of instances of each block in each group: Among them, b ij represents the number of instances in the jth block in the i-th group, m i represents the number of blocks in the i-th group, w i represents the number of thread warps required for the i-th group, w c Indicates the warp size.
6. The GPU parallel computing data dual mapping method according to claim 4, characterized in that: The warp start index and warp start index of each group are calculated using the following formula: Among them, w j represents the number of thread warps required for the jth group, gS i represents the starting index of the thread warp of the i-th group, gE i Indicates the warp end index of the i-th group.
7. The GPU parallel computing data dual mapping method according to claim 1, characterized in that: Each thread redirects the reference of the thread according to the group corresponding to the thread warp to which the thread belongs, determines the block corresponding to the thread and the position in the block, and obtains the new index ID of the thread, including: Each thread calculates the thread start index and thread end index corresponding to each block in the group corresponding to the thread warp to which the thread belongs; Calculate the neighborhood index of the thread according to the thread warp start index of the group corresponding to the thread warp to which the thread belongs; Determine the block corresponding to the thread according to the thread start index and thread end index corresponding to each block in the group corresponding to the thread warp to which the thread belongs, and the neighborhood index of the thread; The position of the block corresponding to the thread is determined according to the neighborhood index of the thread and the thread start index of the block corresponding to the thread, and a new index ID of the thread is obtained.
8. The GPU parallel computing data dual mapping method according to claim 7, characterized in that: The neighborhood index of the thread is calculated according to the following formula: not kw =(wide k -gS i )*w c +tweed kw Among them, nid kw Indicates the neighborhood index corresponding to the wth thread of the kth thread warp, wid k represents the index of the kth warp, gS i represents the starting index of the thread warp of the i-th group, w c Indicates the thread bundle size, twid kw Indicates the number of the wth thread in the kth warp.
9. The GPU parallel computing data dual mapping method according to claim 7, characterized in that: The following formula is used to calculate the thread start index and thread end index corresponding to each block in the group corresponding to the thread warp to which the thread belongs: Among them, b il represents the number of instances in the jth block in the i-th group, bS ij represents the thread start index of the jth block of the i-th group, bE ij Indicates the thread end index of the j-th block of the i-th group.
10. A GPU parallel computing data dual mapping system, characterized in that: Includes the following modules: A thread grid determination module is used to determine the number of thread bundles required by the kernel function according to the number of parallel computing instances and the maximum number of branches of the kernel function, generate parallel computing threads and determine the original ID and index ID of the thread, and the index ID of the thread is used to determine the instance corresponding to the thread; A grouping module, which is used for determining, if the current instruction to be executed is a branch calculation instruction, the group, block and position in the block to which the instance corresponding to the current index ID of each current valid thread belongs according to the branch judgment condition; A remapping module is used to redirect references to each thread bundle and determine the group corresponding to each thread bundle; each thread redirects references to the thread according to the group corresponding to the thread bundle to which the thread belongs, determines the block corresponding to the thread and the position in the block, and obtains a new index ID of the thread; An index restoration module, used to modify the index ID value of each thread to the original ID value if the current instruction to be executed is a branch calculation end instruction; The calculation module is used to determine whether each thread is valid according to the index ID if the current instruction to be executed is not a branch calculation instruction or a branch calculation end instruction. If so, the instance corresponding to the thread is determined according to the index ID to calculate the current instruction to be executed.
Citation Information
Patent Citations
Parallelism constraint detection method based on GPUs
CN104123178A
Self-adaptive thread based GPU parallel particle swarm optimization method
CN106502632A
Radar MTI and MTD implementation method based on CUDA heterogeneous parallel acceleration
CN112986944A
Feedback type dynamic optimization method for CUDA (Compute Unified Device Architecture) program
CN116450209A
Thread bundle size measuring and calculating method based on reconfigurable thread divergence
CN118733473A