Method and device for arranging bit groups in blocks based on intra-thread bundle shuffling algorithm

By sorting the bit arrays in the UGKWP method into blocks based on the intra-warp shuffling algorithm, the non-merged access problem caused by uncertainty in the distribution of particle marker arrays on the GPU architecture is solved, which improves computing efficiency and optimizes GPU resource utilization.

CN118567873BActive Publication Date: 2024-10-22NAT UNIV OF DEFENSE TECH
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411064385.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-05
Publication Date
2024-10-22
Estimated Expiration
2044-08-05

AI Technical Summary

Technical Problem

The UGKWP method is difficult to implement on the GPU architecture, which leads to non-merged access problems of particle marker arrays, affecting computing efficiency. Moreover, sorting the entire array will violate the high parallelism requirements of the GPU, resulting in a waste of computing resources.

Method used

The bit array is divided into blocks based on the shuffling algorithm within the thread warp. The data pairs are divided by marking the even thread warps and odd thread warps, and the functions such as __shfl_down_sync and __shfl_up_sync are used to adjust the data, and the effective data is concentrated into the array. In the first or second half, reduce data dependencies and the number of moves.

Benefits of technology

The computing efficiency on the GPU is optimized, the computing performance is improved by 1.65 times and 1.72 times, the register memory access speed of the GPU architecture is fully utilized, and the use of global memory is reduced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118567873B_ABST
    Figure CN118567873B_ABST
Patent Text Reader

Abstract

The present application relates to a method and device for block arrangement of bit groups based on a shuffle algorithm within a thread bundle, the method comprising: marking all thread bundles in a thread block running on the current GPU to obtain odd and even thread bundles, and determining the range of valid data in each thread bundle; dividing the valid data in the odd and even thread bundles into pairs, and calculating the identification of each data pair; adjusting part of the data according to the identification; moving the valid data in the even thread bundle and the odd thread bundle according to the data pair, and dividing the data in the thread bundle into two groups; treating two adjacent thread bundles in the thread block as a thread bundle pair, moving data with the thread bundle pair as the basic unit, and completing the arrangement of the marked bit group in the thread block on the current GPU. The method uses the shuffle algorithm within the thread bundle to realize the block arrangement of the marked bit binary array, optimizes the thread scheduling problem on the GPU, and improves the GPU computing efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computational fluid dynamics and high performance computing technology, and in particular to a method and device for arranging bit groups in blocks based on an intra-thread bundle shuffle algorithm. Background Art

[0002] A bit array, also known as a binary array, refers to an array that contains only 0 and 1. Since the elements of a bit array can be easily mapped to binary bits, which is consistent with the data representation inside the computer, it has a wide range of uses in computing science.

[0003] The UGKWP method, or the gas kinetic wave-particle method, is a multiscale mesoscopic method that has excellent performance in describing the nonequilibrium effects of gas. It can maintain accuracy in both rarefied and continuous flow domains and is an important tool in aerospace and other multiscale flow simulation fields. During the execution of the UGKWP method, the simulated particles are classified in each iteration according to the relationship between the flight time tf of the simulated particles and the time step dt. Particles with tf less than dt will collide in this time step and are called Pc particles. After the Pc particles collide, the physical information they carry will be merged into the macroscopic quantity; particles with tf greater than or equal to dt will fly freely at a specific speed throughout the time step without experiencing any collisions. They are called Pf particles, and the physical information they carry will be retained until the next time step. The memory space where the Pc particles are located will be marked as "0", and the memory space where the Pf particles are located will be marked as "1", so the mark bits of the simulated particles naturally constitute a binary array. In the next time step, the information of the newly sampled particles will be written to the memory location marked as "0".

[0004] The UGKWP method still needs to track a large number of particles, so the amount of calculation is large when dealing with rarefied flows. General-purpose computing GPUs have been increasingly used in various computationally intensive and memory-intensive scientific calculations. Because they contain a large number of computing cores, their data processing speed is not comparable to that of CPUs. Therefore, it is very appropriate to apply GPU parallel acceleration technology to the UGKWP method. However, due to the complexity of the UGKWP method itself, it is very difficult to implement this method on the GPU architecture.

[0005] Since the flight time of particles in the UGKWP method is random, the distribution of Pc particles in memory is also random, which leads to the uncertainty of the location of the element "0" in the array marked by the particle, and the spatial location where the new sampled particle should be written in the next time step is also uncertain. In the GPU architecture, the disorder of memory read and write locations will cause the problem of "non-merged access" of global memory, which will have a great impact on computing efficiency.

[0006] In order to reduce the impact of "non-merged access" on computing efficiency, the particle tag array should be sorted and the "0" elements should be concentrated in one or more continuous areas in the array. However, if the entire tag array is sorted, there will be serious data dependencies between the elements, which is contrary to the high parallelism requirements of the GPU and will cause a waste of computing resources. Summary of the invention

[0007] Based on this, it is necessary to provide a method and device for arranging bit group blocks based on a shuffle algorithm within a thread bundle to address the above technical problems.

[0008] A method for arranging bit groups in blocks based on a shuffle algorithm within a thread bundle, the method comprising:

[0009] All thread warps in the thread block currently running on the GPU are marked to obtain even thread warps and odd thread warps, and the range of valid data in each thread warp is determined.

[0010] The valid data in the even warp and the odd warp are divided into two pairs of data, and the identifier of each data pair is calculated, and part of the data is adjusted according to the identifier of the data pair.

[0011] Valid data in even warps and odd warps are moved according to data, and the data in the warps are divided into two groups.

[0012] Two adjacent thread warps in the thread block running on the current GPU are regarded as a thread warp pair, and data is moved with the thread warp pair as the basic unit to complete the arrangement of the mark bit array in the thread block on the current GPU;

[0013] The valid data in the even warp and the odd warp are divided into pairs of data, and the identifier of each data pair is calculated, including:

[0014] The function __shfl_down_sync in the warp is used to divide the valid data in the even warp and the odd warp into pairs of data, and the identifier of each pair of data is calculated.

[0015] Adjust some data according to the identifier of the data pair.

[0016] In one embodiment, the range of valid data refers to data between the minimum index and the maximum index whose mark bit is 1.

[0017] Mark all thread warps in the thread block running on the current GPU to obtain even thread warps and odd thread warps, and determine the range of valid data in each thread warp, including:

[0018] All thread warps in the thread block running on the current GPU are marked with consecutive integers starting from 1 to obtain even thread warps and odd thread warps.

[0019] In the even warp, the position of the least significant bit in the warp is determined by the built-in function __ffs in CUDA, and the mark bit array on the register is moved forward as a whole through the function __shfl_down_sync within the warp. Finally, the position of the most significant bit is determined by the built-in function __clz to obtain the range of valid data in the even warp.

[0020] In the odd warp, the position of the least significant bit in the warp is determined by the built-in function __ffs in CUDA, and the mark bit array on the register is shifted backward as a whole through the function __shfl_up_sync within the warp. Finally, the position of the most significant bit is determined by the built-in function __clz to obtain the range of valid data in the odd warp.

[0021] In one embodiment, when the data pair is (1,1), the data pair is identified as A; when the data pair is (0,0), the data pair is identified as B; when the data pair is (1,0), the data pair is identified as C; when the data pair is (0,1), the data pair is identified as D.

[0022] Adjust some data according to the identifier of the data pair, including:

[0023] For the data pairs identified as A and B, the data pairs are shifted forward by 0 bits and 2 bits respectively during subsequent shifts.

[0024] For the data pair identified as C and D, the two cases where the data pair is identified as C and D are merged, and the data pair is shifted forward by 1 bit during subsequent movement.

[0025] In one embodiment, the specific steps of merging the two cases of identifying the data pair as C and D include:

[0026] In the even warp, the data pair identified as D is taken out, and the positions of the two data are exchanged using the function __shfl_xor_sync within the warp, so as to adjust the data pair identified as D to the data pair identified as C.

[0027] In the odd thread warp, the data pair identified as C is taken out, and the position of the two data is exchanged using the function __shfl_xor_sync in the thread warp, so as to adjust the data pair identified as C to the data pair identified as D.

[0028] In one embodiment, valid data in even warps and odd warps are moved according to data, and data in warps are divided into two groups, including:

[0029] The valid data in the moved thread bundle is grouped, and each data group performs the data movement process independently. After all data groups complete the data movement, all data groups are merged to complete the data arrangement in the thread bundle. The specific steps of the data movement process include:

[0030] In an even warp: when the data pair is identified as A, the valid data after the data pair does not need to be moved; when the data pair is identified as B, the function __shfl_down_sync within the warp is used to move the valid data after the data pair forward by 2 bits as a whole; when the data pair is identified as C, the function __shfl_down_sync within the warp is used to move the data after the data pair forward by 1 bit as a whole; the move operation is performed in a loop until all valid data with the mark bit as "1" are concentrated in the first half of the data group.

[0031] In the odd thread warp: when the data pair is identified as A, the valid data after the data pair does not need to be moved; when the data pair is identified as B, the thread warp function __shfl_up_sync is used to move the valid data after the data pair backward by 2 bits as a whole; when the data pair is identified as C, the thread warp function __shfl_up_sync is used to move the data after the data pair backward by 1 bit as a whole; the move operation is performed in a loop until all valid data with the mark bit "1" are concentrated in the second half of the data group.

[0032] In one of the embodiments, valid data in the moved warps are grouped.

[0033] In one embodiment, valid data with a mark bit of "1" in an even warp is concentrated in the first half of the array, and valid data with a mark bit of "1" in an odd warp is concentrated in the second half of the array;

[0034] The two adjacent thread warps in the thread block running on the current GPU are regarded as a thread warp pair, and the data is moved with the thread warp pair as the basic unit to complete the arrangement of the mark bit array in the thread block on the current GPU, including:

[0035] Two adjacent warps in the thread block running on the current GPU are regarded as a warp pair, and the prefix sum of the empty element arrays in the warp pair is calculated.

[0036] The distance that the data in each thread warp should be moved after the 0th thread warp is determined according to the prefix sum, and the data in the thread warp is moved as a whole to complete the arrangement of the mark bit array in the entire thread block.

[0037] A device for arranging bit groups in blocks based on a shuffle algorithm within a thread bundle, the device comprising:

[0038] The module for determining the range of valid data in a thread warp is used to mark all thread warps in a thread block currently running on the GPU, obtain even thread warps and odd thread warps, and determine the range of valid data in each thread warp.

[0039] The data pair identification module is used to divide the valid data in the even warp and the odd warp into two pairs of data by using the function __shfl_down_sync in the warp, calculate the identification of each data pair, and adjust part of the data according to the identification of the data pair.

[0040] The data grouping module in the thread warp is used to move valid data in the even thread warp and the odd thread warp according to the data, and divide the data in the thread warp into two groups.

[0041] The module for arranging the number of marked bits in the thread block is used to treat two adjacent thread warps in the thread block running on the current GPU as a thread warp pair and move data with the thread warp pair as the basic unit to complete the arrangement of the number of marked bits in the thread block on the current GPU.

[0042] In one of the embodiments, the range of valid data refers to the data between the minimum index and the maximum index whose mark bit is 1; the module for determining the range of valid data in the thread warp is also used to mark all the thread warps in the thread block running on the current GPU with consecutive integers starting from 1 to obtain even thread warps and odd thread warps; in the even thread warp, the position of the least significant bit in the thread warp is determined by the built-in function __ffs in CUDA, the mark bit array on the register is moved forward as a whole through the function __shfl_down_sync within the thread warp, and finally the position of the most significant bit is determined by the built-in function __clz to obtain the range of valid data in the even thread warp; in the odd thread warp, the position of the least significant bit in the thread warp is determined by the built-in function __ffs in CUDA, the mark bit array on the register is moved backward as a whole through the function __shfl_up_sync within the thread warp, and finally the position of the most significant bit is determined by the built-in function __clz to obtain the range of valid data in the odd thread warp.

[0043] The above-mentioned method and device for block arrangement of bit groups based on the shuffle algorithm within the thread bundle, the method includes: marking all thread bundles in the thread block running on the current GPU, obtaining even thread bundles and odd thread bundles, and determining the range of valid data in each thread bundle; dividing the valid data in the even thread bundle and the odd thread bundle into pairs of data, and calculating the identifier of each data pair, and adjusting part of the data according to the identifier of the data pair; moving the valid data in the even thread bundle and the odd thread bundle according to the identifier of the data pair, and dividing the data in the thread bundle into two groups; taking two adjacent thread bundles in the thread block as a thread bundle pair, and moving data with the thread bundle pair as the basic unit, and completing the arrangement of the marked bit group in the thread block on the current GPU. This method uses the shuffle algorithm within the thread bundle to realize the block arrangement of the marked bit binary array, optimizes the thread scheduling problem on the GPU, and makes full use of the register memory with the fastest access speed on the GPU architecture. Compared with the block arrangement method using shared memory and global memory, the computing efficiency of the GPU is improved by 1.65 times and 1.72 times respectively. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] Figure 1 It is a flowchart of a method for arranging bit groups in blocks based on an intra-warp shuffle algorithm in one embodiment;

[0045] Figure 2 A schematic diagram of different sorting sequences of odd and even warps in another embodiment;

[0046] Figure 3 It is a schematic diagram of determining a valid data range in a warp in another embodiment;

[0047] Figure 4 is a schematic diagram of the content of a data pair and the corresponding identification result in another embodiment;

[0048] Figure 5 A schematic diagram of adjusting the internal order of a data pair marked as D in another embodiment;

[0049] Figure 6 is a schematic diagram of a data movement process of an even warp in another embodiment;

[0050] Figure 7 is a schematic diagram of a process of arranging thread warp pairs in another embodiment;

[0051] Figure 8 The structure block diagram of a device for arranging bit groups based on a shuffle algorithm within a thread warp in one embodiment. DETAILED DESCRIPTION

[0052] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0053] In order to avoid the problem of non-merged access caused by the particle pruning process of the UGKWP method on the GPU architecture, the particle array needs to be sorted. Compared with sorting the entire array, the half-rearrange method can better take advantage of the high concurrency of the GPU architecture. A new method is used to perform half-rearrange sorting on the bit array marked with the simulated particle state using the intra-warp shuffle algorithm. This method makes full use of the register file with the fastest memory access speed in the GPU memory structure.

[0054] In one embodiment, Figure 1 As shown, a method for arranging bit groups in blocks based on a shuffle algorithm within a thread bundle is provided. The method is suitable for a CPU / GPU heterogeneous platform. The method includes the following steps:

[0055] Step 100: Mark all thread warps in the thread block currently running on the GPU to obtain even thread warps and odd thread warps, and determine the range of valid data in each thread warp.

[0056] Specifically, the general programming model CUDA on the GPU has a thread hierarchy at the logical level. All threads called by the kernel function are organized into a thread grid. Each thread grid is composed of several thread blocks. Each thread block contains a certain number of threads. In this application, thread reuse is not considered, and each thread only indexes a data in the mark bit array. Due to the limited computing cores on the GPU, all threads in the thread block are not executed at the same time. Instead, 32 threads are organized into thread bundles (warps) and scheduled and run in units of thread bundles. Therefore, a thread block block can be logically divided into several thread bundles warps. All thread bundles in the thread block are marked, and different sorting orders will be used for odd and even thread bundles, such as Figure 2 As shown in the figure. For even warps, the data with the mark bit "1" is concentrated in the front, and for odd warps, the data with the mark bit "1" is concentrated in the second half of the 32 data. This warp interleaving sorting method can reduce the number of data movement times in the subsequent data sorting in the entire thread block by about half.

[0057] The range of valid data in the thread warp prevents invalid threads from participating in the subsequent data sorting process, avoids adding too many invalid thread synchronization steps, and improves efficiency.

[0058] The half-rearrange strategy of dividing the tag array into sub-arrays of size block (i.e., thread blocks in CUDA programming) and reordering the particle tag bits in each sub-array is more suitable for the GPU architecture.

[0059] Step 102: Divide the valid data in the even warp and the odd warp into pairs of data, calculate the identifier of each data pair, and adjust part of the data according to the identifier of the data pair.

[0060] Step 102 specifically includes: using the function __shfl_down_sync in the warp to divide the valid data in the even warp and the odd warp into pairs of data, and calculating the identifier of each pair of data; and adjusting part of the data according to the identifier of the data pair.

[0061] Specifically, taking an even warp as an example, the function __shfl_down_sync in the warp is used to divide the valid data in the warp into pairs of two data, and the identifiers of the data pairs are calculated.

[0062] Step 104: Move valid data in the even warp and the odd warp according to the identifier of the data pair, and divide the data in the warp into two groups.

[0063] Specifically, after the data pairs are marked, the valid data is moved according to the marks, the valid data in the thread bundle is grouped, and each group moves data independently, which reduces data dependency and is also for the purpose of giving full play to the high parallelism characteristics of the GPU.

[0064] Step 106: two adjacent thread warps in the thread block running on the current GPU are regarded as a thread warp pair, and data is moved with the thread warp pair as a basic unit to complete the arrangement of the mark bit array in the thread block on the current GPU.

[0065] Specifically, in order to minimize the number of data movements, two adjacent thread warps are grouped into a thread warp pair, and data is moved with two thread warps as basic units, and finally the arrangement of the mark bit array in the entire thread is completed.

[0066] The thread warps in the thread block are combined into different thread warp pairs, and the valid data and invalid data in different thread warps are concentrated in a continuous memory area as much as possible, which reduces the number of data movements and saves computing time.

[0067] In the above-mentioned method for arranging bit groups in blocks based on the shuffle algorithm within the thread bundle, the method includes: marking all thread bundles in the thread block running on the current GPU to obtain even thread bundles and odd thread bundles, and determining the range of valid data in each thread bundle; dividing the valid data in the even thread bundle and the odd thread bundle into pairs of data, and calculating the identifier of each data pair, and adjusting part of the data according to the identifier of the data pair; moving the valid data in the even thread bundle and the odd thread bundle according to the identifier of the data pair, and dividing the data in the thread bundle into two groups; taking two adjacent thread bundles in the thread block as a thread bundle pair, and moving data with the thread bundle pair as the basic unit, and completing the arrangement of the marked bit group in the thread block on the current GPU. This method uses the shuffle algorithm within the thread bundle to realize the block arrangement of the marked bit binary array, optimizes the thread scheduling problem on the GPU, and makes full use of the register memory with the fastest access speed on the GPU architecture. Compared with the block arrangement method using shared memory and global memory, the computing efficiency of the GPU is improved by 1.65 times and 1.72 times respectively.

[0068] In one of the embodiments, the range of valid data refers to the data between the minimum index and the maximum index whose mark bit is 1; step 100 includes: marking all thread warps in the thread block running on the current GPU with consecutive integers starting from 1 to obtain even thread warps and odd thread warps; in the even thread warp, determining the position of the least significant bit in the thread warp through the built-in function __ffs in CUDA, shifting the mark bit array on the register forward as a whole through the function __shfl_down_sync within the thread warp, and finally determining the position of the most significant bit through the built-in function __clz to obtain the range of valid data in the even thread warp; in the odd thread warp, determining the position of the least significant bit in the thread warp through the built-in function __ffs in CUDA, shifting the mark bit array on the register backward as a whole through the function __shfl_up_sync within the thread warp, and finally determining the position of the most significant bit through the built-in function __clz to obtain the range of valid data in the odd thread warp.

[0069] Specifically, after marking the thread bundle, it is necessary to determine the range of "valid data" in each thread bundle. Taking the even thread bundle as an example, the range of "valid data" refers to the data between the minimum index and the maximum index where the mark bit is "1". The built-in function __ffs in CUDA can be used to determine the position of the least significant bit in the thread bundle. The function __shfl_down_sync in the thread bundle can be used to move the mark bit array on the register forward as a whole. Finally, the built-in function __clz is used to determine the position of the most significant bit. The range of valid data in the thread bundle can be finally determined, as shown in the following example. Figure 3 For odd-thread warps, the process is similar, except that the marker bit array needs to be shifted back.

[0070] In one of the embodiments, when the data pair is (1,1), the data pair is identified as A; when the data pair is (0,0), the data pair is identified as B; when the data pair is (1,0), the data pair is identified as C; when the data pair is (0,1), the data pair is identified as D; and part of the data is adjusted according to the identification of the data pair, including: for data pairs identified as A and B, the data pairs are respectively shifted forward by 0 and 2 bits during subsequent movement; for data pairs identified as C and D, the two situations of identifying the data pair as C and D are combined, and the data pair is shifted forward by 1 bit during subsequent movement.

[0071] Specifically, the content of the data pairs and the corresponding identification results are shown in Table 1 and Figure 4 middle.

[0072] Table 1 Data pair identification

[0073]

[0074] The data pairs are identified as A, B, C, and D. For the data pairs identified as A and B, they are moved forward by 0 and 2 bits respectively in the subsequent movement, but for the data pairs identified as C and D, they need to be moved forward by 1 bit. In order to reduce the subsequent judgment branches, before the next step, the two cases identified as C and D are merged, that is, the data pair identified as D is taken out (for odd thread warps, the data pair identified as C is taken out), and the positions of the two data are swapped. The schematic diagram of adjusting the internal order of the data pair identified as D is as follows Figure 5 The data location is exchanged using the function __shfl_xor_sync in the thread bundle, which also directly operates the data in the register file without going through the global memory or shared memory, thus achieving higher efficiency.

[0075] The type of data pair is determined, and the data pair marked as D is preprocessed, which fully utilizes the high parallelism of the GPU architecture and prevents excessive judgments from occurring during data movement.

[0076] In one of the embodiments, the specific steps of merging the two cases where the data pair is identified as C and D include: in the even warp, taking out the data pair identified as D, using the function __shfl_xor_sync in the warp to exchange the positions of the two data, and adjusting the data pair identified as D to the data pair identified as C; in the odd warp, taking out the data pair identified as C, using the function __shfl_xor_sync in the warp to exchange the positions of the two data, and adjusting the data pair identified as C to the data pair identified as D.

[0077] In one embodiment, step 104 includes: grouping the valid data in the moved thread bundle, each data group independently performs the data movement process, and after all data groups complete the data movement, merge all data groups to complete the data sorting in the thread bundle; wherein the specific steps of the data movement process include: in the even thread bundle: when the data pair is identified as A, the valid data after the data pair does not need to be moved; when the data pair is identified as B, the thread bundle function __shfl_down_sync is used to move the valid data after the data pair forward by 2 bits as a whole; when the data pair is identified as C, the thread bundle function __shfl_down_sync is used to move the data after the data pair forward by 1 bit as a whole; and the movement operation is performed cyclically until all valid data with the mark bit as "1" are concentrated in the first half of the data group. In the odd thread warp: when the data pair is identified as A, the valid data after the data pair does not need to be moved; when the data pair is identified as B, the thread warp function __shfl_up_sync is used to move the valid data after the data pair backward by 2 bits as a whole; when the data pair is identified as C, the thread warp function __shfl_up_sync is used to move the data after the data pair backward by 1 bit as a whole; the move operation is performed in a loop until all valid data with the mark bit "1" are concentrated in the second half of the data group.

[0078] Specifically, taking the even warp as an example, when the data pair is identified as A, the valid data after this data pair does not need to be moved; when the data pair is identified as "B", the function __shfl_down_sync in the warp is used to move the valid data after this data pair forward by 2 bits; when the data pair is identified as C, the data after this data pair is moved forward by 1 bit. The process of the odd warp is similar, except that __shfl_up_sync needs to be used to move the data backward by the corresponding number of bits.

[0079] In order to fully utilize the parallel characteristics of the SIMT architecture, the valid data in the thread bundle is grouped again, and each group performs the data movement process independently. After all data groups are completed, the data of each group is merged to finally complete the arrangement of the data in this thread bundle. In order to prevent too many data groups from causing too little data to be operated in each group, the data in the thread bundle is only divided into two groups in this application, namely Group 0 and Group 1. Group 0 contains an even number of data pairs, and the size of Group 1 is all the data in the valid data that does not contain Group 0.

[0080] When moving data, you also need to define a variable "offset" to accumulate the number of bits of data moved in each cycle. For example, for a data pair marked as B, the value of offset increases by 2, and the value of offset increases by 1 for a data pair marked as C. The variable offset and the data pair type together determine the number of bits of effective data moved in each cycle. The data movement process of an even warp is as follows Figure 6 The execution process of the odd warp is similar to that of the even warp, except that the data is moved to the high bit through the __shfl_down_sync function.

[0081] In one of the embodiments, valid data in the moved warps are grouped.

[0082] In one of the embodiments, valid data with a mark bit of "1" in an even warp is concentrated in the first half of the array, and valid data with a mark bit of "1" in an odd warp is concentrated in the second half of the array; step 106 includes: taking two adjacent warps in a thread block running on the current GPU as a warp pair, calculating the prefix sum of the empty element array in the warp pair; determining the distance that the data in each warp after the 0th warp should be moved according to the prefix sum, moving the data in the warp as a whole, and completing the arrangement of the mark bit array in the entire thread block.

[0083] Specifically, the process of organizing the thread bundle pair is as follows: Figure 7 As shown, Warp 0~Warp 2 occupy a continuous memory area. Warp 0 and Warp 1 are a thread warp pair. Since the valid data with the mark bit "1" in the even thread warp is concentrated in the first half of the array, and the valid data in the odd thread warp is concentrated in the second half of the array, the invalid data in the two thread warps is concentrated in a continuous memory. The shared memory array emptyAmt[i] records the total memory width occupied by the invalid data in the i-th thread warp pair. The valid data of Warp 1 and Warp 2 also occupy a continuous memory area, and the distance to be moved is the length of the invalid data in the first thread warp pair. Therefore, by calculating the prefix sum (prefix sum, that is, the sum from the first element to the current element) of emptyAmt[i], the distance that the data in each thread warp after the 0th thread warp should be moved can be determined, and finally the arrangement of the mark bit array in the entire thread block is completed.

[0084] It should be understood that although Figure 1 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 1At least part of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least part of the sub-steps or stages of other steps.

[0085] In one embodiment, Figure 8 As shown, a device for arranging bit groups in blocks based on a shuffle algorithm within a thread warp is provided, comprising: a valid data range determination module in a thread warp, a data pair identification module, a data grouping module within a thread warp, and an arranging module for marking bit groups within a thread block, wherein:

[0086] The module for determining the range of valid data in a thread warp is used to mark all thread warps in a thread block currently running on the GPU, obtain even thread warps and odd thread warps, and determine the range of valid data in each thread warp.

[0087] The data pair identification module is used to divide the valid data in the even warp and the odd warp into two pairs of data by using the function __shfl_down_sync in the warp, calculate the identification of each data pair, and adjust part of the data according to the identification of the data pair.

[0088] The data grouping module in the thread warp is used to move valid data in the even thread warp and the odd thread warp according to the data, and divide the data in the thread warp into two groups.

[0089] The module for arranging the number of marked bits in the thread block is used to treat two adjacent thread warps in the thread block running on the current GPU as a thread warp pair and move data with the thread warp pair as the basic unit to complete the arrangement of the number of marked bits in the thread block on the current GPU.

[0090] In one of the embodiments, the range of valid data refers to the data between the minimum index and the maximum index whose marking bit is 1; the module for determining the range of valid data in the thread warp is used to mark all the thread warps in the thread block running on the current GPU with consecutive integers starting from 1 to obtain even thread warps and odd thread warps.

[0091] In the even warp, the position of the least significant bit in the warp is determined by the built-in function __ffs in CUDA, and the mark bit array on the register is moved forward as a whole through the function __shfl_down_sync within the warp. Finally, the position of the most significant bit is determined by the built-in function __clz to obtain the range of valid data in the even warp.

[0092] In the odd warp, the position of the least significant bit in the warp is determined by the built-in function __ffs in CUDA, and the mark bit array on the register is shifted backward as a whole through the function __shfl_up_sync within the warp. Finally, the position of the most significant bit is determined by the built-in function __clz to obtain the range of valid data in the odd warp.

[0093] In one embodiment, the range of valid data refers to data between the minimum index and the maximum index whose mark bit is 1.

[0094] Mark all thread warps in the thread block running on the current GPU to obtain even thread warps and odd thread warps, and determine the range of valid data in each thread warp, including:

[0095] All thread warps in the thread block running on the current GPU are marked with consecutive integers starting from 1 to obtain even thread warps and odd thread warps.

[0096] In the even warp, the position of the least significant bit in the warp is determined by the built-in function __ffs in CUDA, and the mark bit array on the register is moved forward as a whole through the function __shfl_down_sync within the warp. Finally, the position of the most significant bit is determined by the built-in function __clz to obtain the range of valid data in the even warp.

[0097] In the odd warp, the position of the least significant bit in the warp is determined by the built-in function __ffs in CUDA, and the mark bit array on the register is shifted backward as a whole through the function __shfl_up_sync within the warp. Finally, the position of the most significant bit is determined by the built-in function __clz to obtain the range of valid data in the odd warp.

[0098] In one of the embodiments, when the data pair is (1,1), the data pair is identified as A; when the data pair is (0,0), the data pair is identified as B; when the data pair is (1,0), the data pair is identified as C; when the data pair is (0,1), the data pair is identified as D; the data pair identification module is also used for, for data pairs identified as A and B, to shift the data pairs forward by 0 and 2 bits respectively during subsequent movement; for data pairs identified as C and D, the two situations of identifying the data pairs as C and D are combined, and the data pairs are shifted forward by 1 bit during subsequent movement.

[0099] In one embodiment, the specific steps of merging the two situations of identifying the data pair as C and D in the data pair identification module include:

[0100] In the even warp, the data pair identified as D is taken out, and the positions of the two data are exchanged using the function __shfl_xor_sync within the warp, and the data pair identified as D is adjusted to the data pair identified as C; in the odd warp, the data pair identified as C is taken out, and the positions of the two data are exchanged using the function __shfl_xor_sync within the warp, and the data pair identified as C is adjusted to the data pair identified as D.

[0101] In one of the embodiments, a data grouping module within a thread bundle is used to group valid data within the thread bundle after the movement, and each data group independently performs a data movement process. After all data groups complete the data movement, all data groups are merged to complete the data arrangement within the thread bundle; wherein the specific steps of the data movement process include: in an even thread bundle: when the data pair is identified as A, the valid data after the data pair does not need to be moved; when the data pair is identified as B, the valid data after the data pair is moved forward by 2 bits as a whole using the thread bundle function __shfl_down_sync; when the data pair is identified as C, the data after the data pair is moved forward by 1 bit as a whole using the thread bundle function __shfl_down_sync; and the movement operation is performed cyclically until all valid data with the mark bit as "1" are concentrated in the first half of the data group. In the odd thread warp: when the data pair is identified as A, the valid data after the data pair does not need to be moved; when the data pair is identified as B, the thread warp function __shfl_up_sync is used to move the valid data after the data pair backward by 2 bits as a whole; when the data pair is identified as C, the thread warp function __shfl_up_sync is used to move the data after the data pair backward by 1 bit as a whole; the move operation is performed in a loop until all valid data with the mark bit "1" are concentrated in the second half of the data group.

[0102] In one of the embodiments, valid data in the moved warps are grouped.

[0103] In one embodiment, valid data with a mark bit of "1" in an even warp is concentrated in the first half of the array, and valid data with a mark bit of "1" in an odd warp is concentrated in the second half of the array. The module for arranging the mark bit array in a thread block is also used to treat two adjacent warps in a thread block running on the current GPU as a warp pair, calculate the prefix sum of the empty element array in the warp pair; determine the distance that the data in each warp after the 0th warp should be moved based on the prefix sum, move the data in the warp as a whole, and complete the arrangement of the mark bit array in the entire thread block.

[0104] For the specific definition of the bit group block sorting device based on the shuffle algorithm within the thread bundle, please refer to the definition of the bit group block sorting method based on the shuffle algorithm within the thread bundle, which will not be repeated here. Each module in the above-mentioned bit group block sorting device based on the shuffle algorithm within the thread bundle can be fully or partially implemented by software, hardware and their combination. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.

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

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

Claims

1. A method for arranging bit groups based on a shuffle algorithm within a thread bundle, characterized in that: The method comprises: Mark all thread warps in the thread block currently running on the GPU to obtain even thread warps and odd thread warps, and determine the range of valid data in each thread warp; Divide the valid data in the even warp and the odd warp into pairs of data, calculate the identifier of each data pair, and adjust part of the data according to the identifier of the data pair; wherein, when the data pair is (1,1), the data pair identifier is A; when the data pair is (0,0), the data pair identifier is B; when the data pair is (1,0), the data pair identifier is C; when the data pair is (0,1), the data pair identifier is D; Moving valid data in the even warp and the odd warp according to the identifier of the data pair, and dividing the data in the warp into two groups; Two adjacent thread warps in the thread block running on the current GPU are regarded as a thread warp pair, and data is moved with the thread warp pair as the basic unit to complete the arrangement of the mark bit array in the thread block on the current GPU; The valid data in the even warp and the odd warp are divided into pairs of data, and the identifier of each data pair is calculated, including: Using the function __shfl_down_sync in the warp, respectively divide the valid data in the even warp and the odd warp into pairs of data, and calculate the identifier of each pair of data; Adjust some data according to the identification of the data pair; Among them, some data are adjusted according to the identification of the data pair, including: For data pairs identified as A and B, the data pairs are shifted forward by 0 and 2 bits respectively during subsequent shifts; For the data pair identified as C and D, the two cases where the data pair is identified as C and D are merged, and the data pair is shifted forward by 1 bit during subsequent movement.

2. The method according to claim 1, characterized in that: The range of valid data refers to the data between the minimum index and the maximum index where the mark bit is 1; Mark all thread warps in the thread block running on the current GPU to obtain even thread warps and odd thread warps, and determine the range of valid data in each thread warp, including: All thread warps in the thread block currently running on the GPU are marked with consecutive integers starting from 1 to obtain even thread warps and odd thread warps; In the even warp, the position of the least significant bit in the warp is determined by the built-in function __ffs in CUDA, and the marker bit array on the register is moved forward as a whole by the function __shfl_down_sync in the warp. Finally, the position of the most significant bit is determined by the built-in function __clz to obtain the range of valid data in the even warp. In the odd warp, the position of the least significant bit in the warp is determined by the built-in function __ffs in CUDA, and the mark bit array on the register is shifted backward as a whole through the function __shfl_up_sync within the warp. Finally, the position of the most significant bit is determined by the built-in function __clz to obtain the range of valid data in the odd warp.

3. The method according to claim 1, characterized in that The specific steps of merging the data pairs identified as C and D include: In the even warp, the data pair identified as D is taken out, and the positions of the two data are exchanged using the function __shfl_xor_sync in the warp, so as to adjust the data pair identified as D to the data pair identified as C. In the odd thread warp, the data pair identified as C is taken out, and the position of the two data is exchanged using the function __shfl_xor_sync in the thread warp, so as to adjust the data pair identified as C to the data pair identified as D.

4. The method according to claim 1, characterized in that: The valid data in the even warp and the odd warp are moved according to the identifier of the data pair, and the data in the warp is divided into two groups, including: The valid data in the moved thread bundle is grouped, and each data group performs the data movement process independently. After all data groups complete the data movement, all data groups are merged to complete the data arrangement in the thread bundle. The specific steps of the data movement process include: In an even warp: when the data pair is identified as A, the valid data behind the data pair does not need to be moved; when the data pair is identified as B, the function __shfl_down_sync in the warp is used to move the valid data behind the data pair forward by 2 bits as a whole; when the data pair is identified as C, the function __shfl_down_sync in the warp is used to move the data behind the data pair forward by 1 bit as a whole; the move operation is performed cyclically until all valid data with the mark bit "1" are concentrated in the first half of the data group; In the odd thread warp: when the data pair is marked as A, the valid data after the data pair does not need to be moved; when the data pair is marked as B, the thread warp function __shfl_up_sync is used to move the valid data after the data pair backward by 2 bits as a whole; when the data pair is marked as C, the thread warp function __shfl_up_sync is used to move the data after the data pair backward by 1 bit as a whole; the move operation is performed cyclically until all valid data with the mark bit "1" are concentrated in the second half of the data group.

5. The method according to claim 4, characterized in that Group the valid data in the moved warp.

6. The method according to claim 1, characterized in that The valid data with the mark bit "1" in the even warp is concentrated in the first half of the array, and the valid data with the mark bit "1" in the odd warp is concentrated in the second half of the array; The two adjacent thread warps in the thread block running on the current GPU are regarded as a thread warp pair, and the data is moved with the thread warp pair as the basic unit to complete the arrangement of the mark bit array in the thread block on the current GPU, including: Take two adjacent thread warps in the thread block running on the current GPU as a thread warp pair, and calculate the prefix sum of the empty element array in the thread warp pair; The distance that the data in each thread warp should be moved after the 0th thread warp is determined according to the prefix sum, and the data in the thread warp is moved as a whole to complete the arrangement of the mark bit array in the entire thread block.

7. A device for arranging bit groups based on a shuffle algorithm within a thread bundle, characterized in that: The device comprises: A module for determining the range of valid data in a thread warp is used to mark all thread warps in a thread block currently running on the GPU, obtain even thread warps and odd thread warps, and determine the range of valid data in each thread warp; A data pair identification module, used to use the thread warp function __shfl_down_sync to divide the valid data in the even thread warp and the odd thread warp into pairs of data pairs, calculate the identification of each data pair, and adjust part of the data according to the identification of the data pair; wherein, when the data pair is (1,1), the data pair identification is A; when the data pair is (0,0), the data pair identification is B; when the data pair is (1,0), the data pair identification is C; when the data pair is (0,1), the data pair identification is D; A data grouping module within a thread warp, used to move valid data within the even thread warp and the odd thread warp according to identifiers of the data pairs, and divide the data within the thread warp into two groups; A module for arranging the number of marked bits in a thread block, which is used to treat two adjacent thread warps in a thread block running on the current GPU as a thread warp pair, and to move data using the thread warp pair as a basic unit, so as to complete the arrangement of the number of marked bits in the thread block on the current GPU; Among them, the data pair identification module is also used to shift the data pairs identified as A and B forward 0 and 2 bits respectively during subsequent movement; for data pairs identified as C and D, the two cases of identifying the data pairs as C and D are combined, and the data pairs are shifted forward 1 bit during subsequent movement.

8. The device according to claim 7, characterized in that The range of valid data refers to the data between the minimum index and the maximum index whose mark bit is 1; the module for determining the range of valid data in the thread warp is also used to mark all the thread warps in the thread block running on the current GPU with consecutive integers starting from 1 to obtain even thread warps and odd thread warps; in the even thread warp, the position of the least significant bit in the thread warp is determined by the built-in function __ffs in CUDA, the mark bit array on the register is moved forward as a whole through the function __shfl_down_sync within the thread warp, and finally the position of the most significant bit is determined by the built-in function __clz to obtain the range of valid data in the even thread warp; in the odd thread warp, the position of the least significant bit in the thread warp is determined by the built-in function __ffs in CUDA, the mark bit array on the register is moved backward as a whole through the function __shfl_up_sync within the thread warp, and finally the position of the most significant bit is determined by the built-in function __clz to obtain the range of valid data in the odd thread warp.

Citation Information

Patent Citations

  • Method for parallelly realizing large integer multiplication in cryptographic technology based on GPU (Graphics Processing Unit)

    CN117155572A

  • Method and device for optimizing protocol operation with mask, equipment and medium

    CN117311988A

  • Method and system for performing segmentation processing on Softmax function of CUDA (Compute Unified Device Architecture) kernel

    CN117632474A

  • Dynamic Scheduling in a Graphics Processor

    US20100123717A1