A GPU parallel computing data double mapping method and system

By determining the number of thread bundles based on the number of instances and the maximum number of branches in GPU parallel computing and redirecting the references of the thread bundles, the problem of low computing efficiency caused by thread bundle differentiation is solved, efficient parallel computing is achieved, the overhead caused by CPU core splitting is avoided, and the overall computing efficiency is improved.

CN119597487BActive Publication Date: 2025-10-17BEIJING RESEARCH INSTITUTE OF MECHANICAL & ELECTRICAL TECHNOLOGY CO LTD CAM
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411801036.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-09
Publication Date
2025-10-17
Estimated Expiration
2044-12-09

AI Technical Summary

Technical Problem

In GPU parallel computing, the problem of low computing efficiency caused by thread bundle differentiation, especially the branch divergence problem caused by executing complex logical branches, is solved by the existing technology through the CPU-side TDR method, which brings the overhead of additional kernel startup and round-trip data transmission.

Method used

By determining the number of thread bundles based on the number of parallel computing instances and the maximum number of branches in the kernel function, and adopting the data double mapping method, thread bundle references are redirected to ensure that there are enough thread bundles for parallel computing during branch computing. The original ID is restored at the end of the branch computing, avoiding the conversion of thread bundles from parallel to serial and reducing the overhead caused by kernel splitting.

Benefits of technology

It improves the efficiency of GPU parallel computing, shortens computing time, avoids the additional overhead caused by core splitting on the CPU side, and ensures efficient parallel execution during branch calculations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119597487B_ABST
    Figure CN119597487B_ABST
Patent Text Reader

Abstract

A GPU parallel computing data double mapping method and system belong to the technical field of parallel computing, and solve the problem of low parallel computing efficiency in the prior art. The method comprises the following steps: determining the number of thread bundles required by the kernel function, generating threads for parallel computing and determining the original ID and index ID of the threads; if the current to-be-executed instruction is a branch computing instruction, each valid thread currently determines the group, block and position in the block to which the instance corresponding to the index ID of the valid thread currently belongs according to the branch judgment condition; reference redirection is performed on each thread bundle; each thread performs reference redirection on the thread according to the group corresponding to the thread bundle to which the thread belongs to obtain a new index ID of the thread; if the current to-be-executed instruction is a branch computing end instruction, the index ID value of each thread is modified to the original ID value; otherwise, each valid thread determines the corresponding instance according to the index ID to perform the current to-be-executed instruction. Efficient parallel computing is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of parallel computing technology, 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 Thread) parallel computing architecture, that is, the same instruction is executed in parallel within the thread bundle. This computing architecture will cause thread bundle differentiation during the branch selection stage of the model, converting full parallel execution to grouped serial execution, reducing computing efficiency. In GPU parallel computing, the branch divergence problem caused by executing complex logical branches has been a problem that many researchers have been committed to solving. Currently, the main problem is thread data remapping (TDR) on the CPU. TDR on the CPU uses a kernel splitting method to establish a feedback-optimization loop to solve the two problems of branch condition dependence on GPU calculation results and multi-conditional branches. However, this method will undoubtedly bring additional kernel startup and round-trip data transmission overhead, resulting in low parallel computing efficiency. Summary of the Invention

[0004] In view of the above analysis, embodiments of the present invention aim to provide a method and system for dual mapping of GPU parallel computing data, so as to solve the problem of low parallel computing efficiency caused by existing warp differentiation.

[0005] In one aspect, an embodiment of the present invention provides a method for dual mapping of GPU parallel computing data, comprising the following steps:

[0006] Determine the number of thread bundles required by the kernel function based on 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 thread index ID 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 active thread determines the group, block, and position in the block to which the instance corresponding to the current index ID of the active thread belongs according to the branch judgment condition;

[0008] Redirect references to each warp to determine the group to which each warp corresponds. Redirect references to each thread based on the group to which the warp belongs to determine the block to which the thread corresponds and its position within the block, obtaining a new index ID for the thread.

[0009] If the current to-be-executed instruction is a branch computation 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, and if so, determines the instance corresponding to the thread according to the index ID, and performs the computation of the current to-be-executed instruction.

[0011] Based on the further improvement of the above method, the number of thread bundles required by the kernel function is determined according to the number of parallel computation instances and the maximum number of branches of the kernel function using the following formula:

[0012]

[0013] wherein g represents the number of thread bundles, x represents the number of instances, w c represents the size of the thread bundle, and n represents the maximum number of branches of the kernel function.

[0014] Based on the further improvement of the above method, the instance to which the current index ID of the valid thread belongs is determined according to the branch judgment condition, including:

[0015] The instance to which the current index ID of the valid thread belongs is determined according to the branch judgment condition.

[0016] The block to which the instance belongs in the group is determined according to the instance ID.

[0017] The position of the instance in the block is calculated in an atomic manner.

[0018] Based on the further improvement of the above method, reference redirection is performed for each thread bundle to determine the group corresponding to each thread bundle, including:

[0019] The number of thread bundles required by each group and the starting index and ending index of the thread bundle of each group are determined according to the number of instances in each block in each group.

[0020] The group corresponding to each thread bundle is obtained according to the starting index and ending index of the thread bundle of each group.

[0021] Based on the further improvement of the above method, the number of thread bundles required by each group is determined according to the number of instances in each block in each group using the following formula:

[0022]

[0023] wherein b ij represents the number of instances in the jth block in the ith group, m i represents the number of blocks in the ith group, and w iw represents the number of thread bundles required by the i-th group c w represents the thread bundle size.

[0024] Based on the further improvement of the above method, the thread bundle start index and the thread bundle start index of each group are calculated by the following formula:

[0025]

[0026] wherein w j w represents the number of thread bundles required by the j-th group, gS i w represents the thread bundle start index of the i-th group, gE i w represents the thread bundle end index of the i-th group.

[0027] Based on the further improvement of the above method, each thread is redirected according to the group corresponding to the thread bundle to which the thread belongs, the block corresponding to the thread and the position in the block are determined, and the new index ID of the thread is obtained, including:

[0028] Each thread calculates the thread start index and the thread end index corresponding to each block in the group corresponding to the thread bundle to which the thread belongs;

[0029] According to the thread bundle start index of the group corresponding to the thread bundle to which the thread belongs, the neighborhood index of the thread is calculated;

[0030] According to the thread start index and the thread end index corresponding to each block in the group corresponding to the thread bundle to which the thread belongs, and the neighborhood index of the thread, the block corresponding to the thread is determined;

[0031] According to the neighborhood index of the thread and the thread start index of the block corresponding to the thread, the position in the block corresponding to the thread is determined, and the 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] wherein nid kw represents the neighborhood index corresponding to the w-th thread of the k-th thread bundle, wid k represents the index of the k-th thread bundle, gS i w represents the thread bundle start index of the i-th group, w c w represents the thread bundle size, twid kwindicates the number of the thread in the wth thread bundle of the kth thread bundle.

[0035] Based on the further improvement of the above method, the thread start index and the thread end index corresponding to each block in the group corresponding to the thread bundle to which the thread belongs are calculated by using the following formula:

[0036]

[0037] wherein, b il indicates the number of instances in the jth block in the ith group, bS ij indicates the thread start index of the jth block in the ith group, bE ij indicates the thread end index of the jth block in the ith group.

[0038] In another aspect, the embodiment of the present application provides a GPU parallel computing data double mapping system, comprising the following modules:

[0039] A thread grid determination module is configured to determine the number of thread bundles required by the kernel function according to the number of parallel computing instances and the maximum branch number of the kernel function, generate threads for parallel computing and determine the original ID and index ID of the threads, and the index ID of the threads is used to determine the instance corresponding to the thread.

[0040] A grouping module is configured to, if the current to-be-executed instruction is a branch computing instruction, determine the group, block and position in the block to which the instance corresponding to the current index ID of each active thread belongs according to the branch judgment condition.

[0041] A remapping module is configured to perform reference redirection on each thread bundle and determine the group corresponding to each thread bundle; each thread performs reference redirection on 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.

[0042] An index restoration module is configured to, if the current to-be-executed instruction is a branch computing end instruction, modify the index ID value of each thread to the original ID value.

[0043] A computing module is configured to, if the current to-be-executed instruction is not a branch computing instruction and a branch computing end instruction, each thread determines whether the thread is valid according to the index ID, and if so, determines the instance corresponding to the thread according to the index ID and performs the calculation of the current to-be-executed instruction.

[0044] Compared with the prior art, the application determines the required number of thread bundles according to the number of parallel computing instances and the maximum branch number in the kernel function, thereby ensuring that there are enough thread bundles for parallel computing at each branch computing time, improving the computing efficiency; before the thread executes the instruction, if the to-be-executed instruction is a branch computing instruction, the instance corresponding to the thread index ID is grouped, blocked and the position in the block is determined according to the branch judgment condition, then the thread bundle is referenced and redirected, and the thread is referenced and redirected, the new index ID of the thread is determined, and when the branch computing ends, 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, thereby being able to perform parallel computing on all instances, shortening the computing time, improving the computing efficiency, avoiding the problem that the differentiation causes the thread bundle to change from full parallel execution to partial thread serial execution, increasing the computing time, and because the thread remapping is performed in the GPU, the problem of the overhead of additional kernel start and round-trip data transmission caused by kernel splitting in the CPU end is avoided, thereby improving the efficiency of parallel computing.

[0045] In the application, the above technical solutions can be combined with each other to realize more preferred combination solutions. Other features and advantages of the application will be described in the subsequent description, and some advantages will become apparent from the description, or will be understood by implementing the application. The purposes and other advantages of the application can be realized and obtained from the contents specifically indicated in the description and the drawings. BRIEF DESCRIPTION OF DRAWINGS

[0046] The accompanying drawings are included to provide a further understanding of the application and are incorporated in and constitute a part of this specification, illustrate embodiments of the application and serve to explain the principles of the application, and are not intended to limit the scope of the application.

[0047] Figure 1 The flowchart of the GPU parallel computing data double mapping method of the embodiment of the application;

[0048] Figure 2 The working flowchart of the CPU and the GPU;

[0049] Figure 3 The GPU computing framework diagram;

[0050] Figure 4 The block diagram of the GPU parallel computing data double mapping system of the embodiment of the application. DETAILED DESCRIPTION

[0051] The preferred embodiments of the application will be specifically described below in combination with the drawings, wherein the drawings constitute a part of this application, and are used to illustrate the principles of the embodiments of the application, and are not intended to limit the scope of the application.

[0052] The GPU cannot perform independent computing and can only be used as a coprocessor to form a heterogeneous computing platform with the CPU to complete computing tasks. The collaborative work of the two lays the foundation for asynchronous computing. The CPU plays a controlling 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 issues a kernel function calculation instruction 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. An 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 between the thread bundle and the SP array. Each SP array can correspond to multiple thread bundles of the same thread block or different thread blocks. Figure 3 As shown, the mapping between the SP array and multiple warps is achieved through the warp scheduler and the instruction transmitter.

[0054] Each warp executes computations using a SIMD (Single Instruction Multiple Thread) parallel computing architecture, meaning the same instruction is executed in parallel within the warp. This architecture can cause warps to split during branch selection, shifting from fully parallel execution to grouped serial execution, reducing computational 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 based on 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.

[0057] S2. If the current instruction to be executed is a branch calculation instruction, each current active thread determines the group, block, and position in the block to which the instance corresponding to the current index ID of the active thread belongs according to the branch judgment condition;

[0058] reference redirection is performed on each thread bundle to determine a corresponding group for each thread bundle;

[0059] Each thread performs reference redirection on the thread according to the group corresponding to the thread bundle to which the thread belongs, to determine a corresponding tile and a position in the tile for the thread, and to obtain a new index ID for the thread.

[0060] If the current to-be-executed instruction is a branch computation 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, and if so, determines the instance corresponding to the thread according to the index ID, and performs computation of the current to-be-executed instruction.

[0062] It should be noted that an instance, i.e., an object that needs to be computed in parallel, for example, when performing parallel computation of a car cluster simulation, a basic operator unit in a car model (e.g., a car loss torque computation unit) is an instance. When performing parallel computation, the number of instances of the basic operator unit needs to be equal to the number of cars in the cluster.

[0063] It should be noted that the original ID and the index ID of a thread are the same at the beginning, and are both instance IDs. The number of generated threads may exceed the number of instances, and according to the thread number order, the original ID and the index ID of the threads with numbers greater than the number of instances can be assigned other values, which are different from the instance IDs.

[0064] In implementation, whether a thread is a valid ID is determined by the index ID. If the index ID of a thread is the same as a certain instance ID, the thread is a valid thread, otherwise it is not a valid thread.

[0065] A branch computation instruction, for example, an if-else statement, executes instructions of different branches according to different judgment conditions.

[0066] Reference redirection is to redirect the reference index of a group of threads to data in the same data group. In GPU programming, threads obtain input data from corresponding positions in a data set according to reference indexes. The reference index is usually a thread ID or an arithmetic expression thereof. By changing the index, threads in a thread bundle can obtain data from the same data group in the data set.

[0067] Compared with the prior art, the GPU parallel computing data double mapping method provided by the embodiment ensures that there are enough thread bundles for parallel computing when branch computing is performed each time, thereby improving the computing efficiency; before the thread executes an instruction, if the to-be-executed instruction is a branch computing instruction, the instance corresponding to the thread index ID is grouped, blocked and the position in the block is determined according to the branch judgment condition, then the thread bundle is referenced and redirected, and the thread is referenced and redirected, the new index ID of the thread is determined, and when the branch computing ends, 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, and it is ensured that the same thread bundle executes the same branch path, thereby parallel computing can be performed on all instances, the computing time is shortened, the computing efficiency is improved, the problem of differentiation is avoided, the problem of increasing the computing time caused by the change of the thread bundle from full parallel execution to partial thread serial execution is avoided, and since the thread remapping is performed in the GPU, the problem of the overhead of additional kernel start and round-trip data transmission caused by kernel splitting in the CPU end is avoided, and therefore, the efficiency of parallel computing is improved.

[0068] When one parallel computing is performed, first, the instances needing parallel computing are encapsulated as a kernel function, and the thread grid of the kernel function is determined, and then a sufficient amount of threads are generated on the GPU end to complete the parallel computing. The existing thread bundle optimization algorithm determines the number of threads according to the number of instances of parallel computing, that is, as many threads as instances are generated, and therefore, even after optimization, the differentiation problem still cannot be avoided. According to the number of instances of parallel computing and the maximum branch number of the kernel function, the number of thread bundles required by the kernel function is determined, so that when a branch is encountered each time, there are enough thread bundles for parallel computing, thereby the computing time is shortened and the computing efficiency is improved.

[0069] Specifically, the number of thread bundles required by the kernel function is determined according to the number of instances of parallel computing and the maximum branch number of the kernel function by using the following formula:

[0070]

[0071] wherein g represents the number of thread bundles, x represents the number of instances, w c represents the thread bundle size, and n represents the maximum branch number of the kernel function. The thread bundle size is the number of threads in the thread bundle.

[0072] The thread grid is mainly used to determine the number of threads started by the kernel function. In order to ensure that no differentiation occurs in each thread bundle, the number of thread bundles required is determined by using formula (1) according to the number of instances of parallel computing and the maximum branch number of the kernel function.

[0073] For example, there is a group of branch computations in the kernel function as follows:

[0074] if(yy1>0){

[0075] }

[0076] else{

[0077] }

[0078] Another set of branch calculations is:

[0079] if(yy2>16){

[0080] }

[0081] else if(yy2>0){

[0082] }

[0083] else{

[0084] }

[0085] The maximum number of branches, i.e., the number of branches calculated in the second set of branch calculations, is 3.

[0086] If the number of thread bundles required to calculate the kernel function according to formula (1) is 3, i.e., 3 thread bundles need to be started, so as to ensure that the thread bundles are executed in parallel without differentiation problems.

[0087] After generating the threads, the threads execute the calculation instructions of the kernel function in parallel.

[0088] If the to-be-executed instruction is not a branch calculation instruction, each thread first determines whether it is a valid thread according to its index ID, and if so, directly takes 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 waits.

[0089] If the to-be-executed instruction is a branch calculation instruction, reference remapping needs to be performed.

[0090] The branch calculation instruction, for example, if, else statement.

[0091] If the current to-be-executed instruction is a branch calculation instruction, each valid thread currently determines the group, block and position in the block to which the instance corresponding to the index ID of the valid thread currently belongs according to the branch judgment condition, which specifically includes:

[0092] S211, determining the group to which the instance corresponding to the index ID of the valid thread currently 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, calculating the position of the instance in the block to which it belongs in an atomic manner.

[0095] The above is described by taking the first branch calculation as an example. The judgment object yy1 is a certain data of an instance, and the instance is divided into two groups according to the data yy1 of the instance, 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 that differentiation does not occur.

[0096] It should be noted that since all instances can be divided into a 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 instance ID is used to determine the block to which the instance belongs in the group. The effective thread uses an atomic method to calculate the position of the instance corresponding to the current index ID of the effective thread in the block, thereby improving the calculation efficiency.

[0098] In implementation, for example, the number of blocks is determined to be m, and the reserved length of the group is x, then the instances with instance ID 1-x / m belong to the first block (according to the branch judgment condition, they can belong to the first block of the first group or the first block of the second group), the instances with sequence number x / m+1-2(x / m) belong to the second block (according to the branch judgment condition, they can belong to the second block of the first group or the second block of the second group), and so on.

[0099] In implementation, after each effective thread determines which group and which block the instance corresponding to its current index ID belongs to, the atomic method is used to calculate 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] Where G_RR_Order[i][j] represents the number of instances in the jth block of the ith group, G_RR ij represents an array storing the instance ID of the jth block of the ith group, and count represents the position of the instance in the jth block of the ith group, that is, the index position in the array G_RR ij . The instance ID (fid) is stored in the corresponding position of the array G_RR ij , so as to facilitate accurate reference redirection in the future.

[0103] Since the threads of the same thread bundle use atomic parallel calculation of the block index, i.e. the position in the block, a continuous index number is obtained, and thus the memory merge access overhead can be reduced and the calculation efficiency can be improved during multi-thread parallel calculation after reference redirection.

[0104] After determining the group, the block and the block index to which the instance belongs, reference redirection is needed for the thread bundle according to the instance group, i.e. determining which group of instance data the thread bundle calculates. In implementation, each thread corresponding to the kernel function is remapped.

[0105] Specifically, reference redirection is performed for each thread bundle to determine the group corresponding to each thread bundle, including:

[0106] S221, determining the number of thread bundles required by each group and the thread bundle start index and thread bundle end index of each group according to the number of instances in each block in each group;

[0107] S222, obtaining the group corresponding to each thread bundle according to the thread bundle start index and the thread bundle end index of each group.

[0108] Specifically, the number of thread bundles required by each group is determined according to the number of instances in each block in each group using the following formula:

[0109]

[0110] wherein, b ij represents the number of instances in the jth block in the ith group, m i represents the number of blocks in the ith group, w i represents the number of thread bundles required by the ith group, w c represents the size of the thread bundle.

[0111] In implementation, the number of thread bundles required by 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 by each group, the thread bundles are sorted by index to determine the thread bundle start index and the thread bundle end index of each group, so as to determine which group each thread bundle corresponds to.

[0113] Specifically, the thread bundle start index and the thread bundle end index of each group are calculated using the following formula:

[0114]

[0115] wherein, w j represents the number of thread bundles required by the jth group, gS i represents the thread bundle start index of the ith group, gEi Indicates the warp end index of the i-th group.

[0116] The group corresponding to each warp is obtained according to the warp start index and warp end index of each group, that is, if the index wid of the kth warp is k ∈[gS i ,gE i ), then the kth 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 warp needs to determine the group corresponding to the warp according to steps S221 to S222. The other threads in the same warp can obtain the group ID corresponding to the warp, that is, the group number gid corresponding to the kth 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 grouping corresponding to the warp, it is necessary to further determine which instance data each thread executes. Therefore, each thread redirects its reference based on the grouping corresponding to the warp to which it belongs, determines the corresponding block and its position within the block, and obtains the new index ID for the thread. This includes:

[0119] S41, 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;

[0120] S42. Calculate the neighborhood index of the thread according to the warp start index of the group corresponding to the 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 thread in the block 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 neighborhood index nid of the thread in the neighborhood is determined by kw , then according to nid kw Determine the location of its reference index, that is, the location 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 the thread is calculated according to the following formula:

[0126] nid kw = (wid k -gS i )*w c +twid kw (7)

[0127] wherein nid kw represents the neighborhood index corresponding to the wth thread of the kth thread bundle, wid k represents the index of the kth thread bundle, gS i represents the thread bundle start index of the ith group, w c represents the thread bundle size, and twid kw represents the number of the wth thread of the kth thread bundle in the kth thread bundle.

[0128] Specifically, the thread start index and the thread end index corresponding to each block in the group corresponding to the thread bundle to which the thread belongs are calculated according to the following formula:

[0129]

[0130] wherein b il represents the number of instances in the jth block in the ith group, bS ij represents the thread start index of the jth block in the ith group, and bE ij represents the thread end index of the jth block in the ith group.

[0131] Further, the block corresponding to the thread is determined according to the thread start index and the thread end index corresponding to each block in the group corresponding to the thread bundle to which the thread belongs, and the neighborhood index of the thread. For the wth thread of the kth thread bundle, if the neighborhood index nid kw ∈ [bS ij ,bE ij ), the wth thread of the kth thread bundle corresponds to the jth block in the ith group, and thus the block ID corresponding to the thread is obtained, denoted 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] In implementation, the position in the block corresponding to the thread is obtained according to nid kw -bS ij , and the array G_RRij stores the value stored in the array

[0134] It should be noted that if the kth thread bundle corresponds to the ith group, the neighborhood index of the wth thread of the kth thread bundle is not in the thread index range corresponding to any block of the ith group, 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 the index ID to perform calculation, thereby improving the efficiency of parallel calculation.

[0136] When the branch calculation ends, that is, the to-be-executed instruction is a branch calculation end instruction, the index ID value of the thread is still modified to the original ID value, thereby facilitating accurate determination of the instance corresponding to the thread when the next branch calculation is performed, and reducing memory merging access and improving memory reading efficiency.

[0137] In implementation, a basic calculation unit in automobile model simulation, that is, an automobile loss torque calculation unit, is taken as an example to illustrate the effect of the application. Different automobiles need to perform different calculations at different stages, and therefore, 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 of data does not cause the thread bundle to execute different branches, and one group of data causes the thread bundle to execute different branches. The result obtained by directly performing parallel calculation on the first group of data is shown in the first row of Table 1. For the second group of data, two ways of parallel calculation are adopted: parallel calculation using the data double mapping of the application and parallel calculation without using the data double mapping of the application, and the results are shown in the second row and the third row of Table 1, respectively. It can be seen that the method of the application can well solve the differentiation problem, improve the calculation efficiency, and the consumption time is close to the calculation time of the data without differentiation.

[0139] Table 1: Test results

[0140]

[0141] One specific embodiment of the application discloses a GPU parallel calculation data double mapping system, as shown in Figure 4 The system comprises the following modules:

[0142] ​The thread grid determination module is configured to determine the number of thread bundles required by the kernel function according to the number of parallel computing instances and the maximum branch number of the kernel function, generate threads for parallel computing, and determine original IDs and index IDs of the threads, the index IDs of the threads being used to determine instances corresponding to the threads;

[0143] The grouping module is configured to, if the current to-be-executed instruction is a branch computing instruction, determine, by each valid thread, a group to which an instance corresponding to the index ID of the valid thread currently belongs, a block, and a position in the block, according to a branch judgment condition;

[0144] The remapping module is configured to perform reference redirection on each thread bundle, and determine a group corresponding to each thread bundle; each thread performs reference redirection on the thread according to the group corresponding to the thread bundle to which the thread belongs, determines a block and a position in the block corresponding to the thread, and obtains a new index ID of the thread;

[0145] The index restoring module is configured to, if the current to-be-executed instruction is a branch computing end instruction, modify the index ID value of each thread to the original ID value.

[0146] The computing module is configured to, if the current to-be-executed instruction is neither a branch computing instruction nor a branch computing end instruction, determine, by each thread, whether the thread is valid according to the index ID, and if so, determine an instance corresponding to the thread according to the index ID, and perform computation of the current to-be-executed instruction.

[0147] The method embodiment and the system embodiment described above are based on the same principle, can be mutually referenced in relation, and can achieve the same technical effects. For a specific implementation process, refer to the foregoing embodiments, which will not be described here again.

[0148] Those skilled in the art can understand that all or part of the processes of the foregoing embodiments can be completed by a computer program instructing related hardware, and the program can be stored in a computer readable storage medium. The computer readable storage medium includes a disk, an optical disk, a read-only memory, a random access memory, and the like.

[0149] The above description is only a preferred embodiment of the present application, but the protection scope of the present application is not limited to this. Any changes or replacements within the technical scope disclosed by the present application can be easily thought of by those skilled in the art, and should be covered within the protection scope of the present application.

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 based on 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 thread index ID is used to determine the instance corresponding to the thread; If the current instruction to be executed is a branch calculation instruction, each current active thread determines the group, block, and position in the block to which the instance corresponding to the current index ID of the active thread belongs according to the branch judgment condition; Redirect references to each warp to determine the group to which each warp corresponds. Redirect references to each thread based on the group to which the warp belongs to determine the block to which the thread corresponds and its position within the block, obtaining 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 based on the index ID. If so, it determines the instance corresponding to the thread based on the index ID and calculates the current instruction to be executed; 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 based on the number of instances of each block in each group; Obtain the group corresponding to each warp according to the warp start index and warp end index of each group; Each thread redirects its reference based on the grouping corresponding to the warp to which it belongs, determines the block corresponding to the thread and its 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 warp start index of the group corresponding to the 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 thread 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.

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: ; in, represents the number of thread warps, x represents the number of instances, 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 based on 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 based on 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: 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: ; in, represents the number of instances in the jth block in the i-th group, represents the number of blocks in the i-th group, represents the number of thread warps required for the i-th group, Indicates the warp size.

5. The GPU parallel computing data dual mapping method according to claim 1, characterized in that: The warp start index and warp start index for each group are calculated using the following formula: ; ; in, represents the number of thread warps required for the jth group, represents the starting index of the thread warp of the i-th group, Indicates the warp end index of the i-th group.

6. The GPU parallel computing data dual mapping method according to claim 1, characterized in that: The neighborhood index of the thread is calculated according to the following formula: ; in, represents the neighborhood index corresponding to the wth thread of the kth warp, represents the index of the k-th warp, represents the starting index of the thread warp of the i-th group, Indicates the warp size, Indicates the The first thread of the The number of the thread in the kth warp.

7. The GPU parallel computing data dual mapping method according to claim 1, 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: ; ; in, represents the number of instances in the jth block in the i-th group, Indicates the thread starting index of the j-th block of the i-th group, Indicates the thread end index of the j-th block of the i-th group.

8. A GPU parallel computing data dual mapping system, characterized in that: Includes the following modules: The thread grid determination module is used to determine the number of thread bundles required by the kernel function based on 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; A grouping module is used to determine, 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 active thread belongs based on the branch judgment condition; A remapping module is used to redirect references to each warp and determine the group to which each warp corresponds. Each thread is redirected based on the group to which the warp belongs, determines the block to which the thread corresponds and its position within the block, and obtains a new index ID for the thread. An index restoration module is 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; A calculation module, configured to determine, for each thread, whether the thread is valid based on the index ID if the current instruction to be executed is not a branch calculation instruction or a branch calculation end instruction; if so, determine the instance corresponding to the thread based on the index ID and perform calculation on the current instruction to be executed; 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 based on the number of instances of each block in each group; Obtain the group corresponding to each warp according to the warp start index and warp end index of each group; Each thread redirects its reference based on the grouping corresponding to the warp to which it belongs, determines the block corresponding to the thread and its 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 warp start index of the group corresponding to the 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 thread 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.

Citation Information

Patent Citations

  • 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