Thread divergence processing method, device and equipment
By storing an ordered list in the processor and updating it in real time, it solves the problem of low execution efficiency caused by thread divergence in SIMT execution mode, and achieves automatic thread convergence and efficiency improvement.
Patent Information
- Application Number
- CN202410782772.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-18
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2044-06-18
AI Technical Summary
In the single instruction multi-thread (SIMT) execution mode, thread divergence leads to low execution efficiency. Especially in unstructured programs with single entry and multiple exits such as sub-processes, function calls, and recursion, bypass and deadlock problems may occur.
By storing an ordered list in the processor, recording instruction-related information and thread execution masks, the next instruction of the currently executed instruction is determined, and based on the value of the instruction-related information, the position to be inserted and the movement information of the sub-item information are determined in real time. Update the ordered list to implement automatic convergence of threads.
It improves thread execution efficiency, avoids deadlock and bypass, and optimizes the dynamic execution characteristics of the program.
Smart Images

Figure CN118349281B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of processor technology, and in particular to a thread divergence processing method, device and equipment. Background Art
[0002] At the same time, threads in a thread bundle can only execute a common instruction or be idle. This is the single instruction multiple thread (SIMT) execution mode. Since threads in the same thread cluster execute the same instruction in the same time cycle, when the designed program has many branches, there will be obvious thread divergence: some threads execute the current branch, and other threads need to wait. When the program executes another branch, another part of the threads executes the branch, and other threads that do not belong to the branch need to wait.
[0003] For sequential, selective, and looping single-entry and single-exit structured programs, the static structure of the program is consistent with the dynamic execution process, so the related control under SIMT is also relatively easy. However, for sub-processes, function calls, recursion, and other non-structured programs with single entry and multiple exits, thread divergence may cause bypass, deadlock, and instructions in warps are executed multiple times on different divergent paths, resulting in lower execution efficiency. Therefore, how to handle divergence is a technical problem that technicians in this field need to solve. Summary of the invention
[0004] In view of the problems existing in the prior art, embodiments of the present invention provide a thread divergence processing method, device and equipment.
[0005] The present invention provides a thread divergence processing method, which is applied to a processor, wherein an ordered list is stored in the processor, wherein the ordered list includes: sub-item information corresponding to at least one instruction, wherein the sub-item information includes: instruction-related information and a thread execution mask, wherein the method includes:
[0006] Determine a next instruction of a currently executed instruction; if the currently executed instruction is a branch instruction, the next instruction includes at least two divergent instructions;
[0007] Determine the position to be inserted of the next instruction in the ordered list according to the value of the instruction related information corresponding to the next instruction, and determine the movement information of the sub-item information corresponding to each first instruction in the ordered list;
[0008] The sub-item information corresponding to the next instruction is inserted into the ordered list according to the to-be-inserted position corresponding to the next instruction and the movement information of the sub-item information corresponding to each of the first instructions.
[0009] According to a thread divergence processing method provided by the present invention, the determining of movement information of sub-item information corresponding to each first instruction in the ordered list includes:
[0010] According to the numerical values of the instruction-related information corresponding to each first instruction and the numerical values of the instruction-related information corresponding to the next instruction, the movement information of the sub-item information corresponding to each first instruction is determined; the movement information includes at least one of the following: move one position to the left, move one position to the right, do not move, and delete.
[0011] According to a thread divergence processing method provided by the present invention, the moving information of the sub-item information corresponding to each first instruction is determined according to the numerical value of the instruction related information corresponding to each first instruction and the numerical value of the instruction related information corresponding to the next instruction, including:
[0012] For each sub-item information corresponding to the first instruction, when the value of the instruction-related information corresponding to the first instruction is greater than the values of the instruction-related information corresponding to the two divergent instructions, the movement information includes a left shift of one position;
[0013] In the case where the value of the instruction-related information corresponding to the first instruction is less than the value of the instruction-related information corresponding to the divergent instruction, or, there is a second instruction in the ordered list, the second instruction is a forced waiting instruction, and all target threads are currently waiting, and the value of the instruction-related information corresponding to the first instruction is greater than the value of the instruction-related information corresponding to the second instruction, the movement information includes a right shift of one position;
[0014] In the case where the value of the instruction-related information corresponding to the first instruction is greater than the value of the instruction-related information corresponding to the divergence instruction, and there is no mandatory waiting instruction before the first instruction, the movement information includes: no movement;
[0015] When the first instruction is a forced waiting instruction and all target threads have been waited for, the moving information includes: deletion.
[0016] According to a thread divergence processing method provided by the present invention, before inserting the sub-item information corresponding to the next instruction into the ordered list, the method further includes:
[0017] The sub-item information corresponding to each of the first instructions is moved according to the moving information of the sub-item information corresponding to each of the first instructions.
[0018] According to a thread divergence processing method provided by the present invention, the instruction related information includes at least one of the following: instruction address, whether forced to wait, whether valid, and priority information;
[0019] The value of the instruction-related information is obtained by concatenating the sum of the values of at least one of the instruction address, whether it is forced to wait, whether it is valid, and the priority information.
[0020] According to a thread divergence processing method provided by the present invention, the sub-item information further includes: a forced waiting target thread mask;
[0021] The instruction includes an inter-thread synchronization instruction; the forced waiting target thread mask is caused by the inter-thread synchronization instruction.
[0022] The present invention also provides a thread divergence processing device, which is applied to a processor, wherein an ordered list is stored in the processor, wherein the ordered list includes: sub-item information corresponding to at least one instruction, wherein the sub-item information includes: instruction-related information and a thread execution mask, wherein the device includes:
[0023] A determination module, configured to determine a next instruction of a currently executed instruction; if the currently executed instruction is a branch instruction, the next instruction includes at least two divergent instructions;
[0024] The determination module is further configured to determine the position to be inserted of the next instruction in the ordered list according to the value of the instruction-related information corresponding to the next instruction, and to determine the movement information of the sub-item information corresponding to each first instruction in the ordered list;
[0025] The processing module is used to insert the sub-item information corresponding to the next instruction into the ordered list according to the to-be-inserted position corresponding to the next instruction and the movement information of the sub-item information corresponding to each of the first instructions.
[0026] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, any of the above-mentioned thread divergence processing methods is implemented.
[0027] The present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the thread divergence processing method described in any one of the above is implemented.
[0028] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements any of the above-mentioned thread divergence processing methods.
[0029] The thread divergence processing method, device and equipment provided by the present invention store sub-item information corresponding to instructions through an ordered list, and the sub-item information includes: instruction-related information and thread execution mask, which can record divergent instruction information. First, the next instruction of the currently executed instruction is determined; if the currently executed instruction is a branch instruction, the next instruction includes at least two divergent instructions; further, according to the numerical value of the instruction-related information corresponding to the next instruction, the position to be inserted of the next instruction in the ordered list is determined, and the movement information of the sub-item information corresponding to each first instruction in the ordered list is determined; according to the position to be inserted corresponding to the next instruction and the movement information of the sub-item information corresponding to each first instruction, the sub-item information corresponding to the next instruction is inserted into the ordered list, the ordered list is updated in real time, and the execution is performed based on the order of arrangement in the ordered list during execution, thereby realizing automatic convergence of threads and improving thread execution efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0031] Figure 1 This is one of the flow charts of the thread divergence processing method provided by the present invention.
[0032] Figure 2 It is a schematic diagram of the principle of the thread divergence processing method provided by the present invention.
[0033] Figure 3 This is one of the schematic diagrams of the sub-item movement principle of the thread divergence processing method provided by the present invention.
[0034] Figure 4 This is the second schematic diagram of the principle of sub-item movement of the thread divergence processing method provided by the present invention.
[0035] Figure 5 This is the third schematic diagram of the principle of sub-item movement of the thread divergence processing method provided by the present invention.
[0036] Figure 6 This is the fourth schematic diagram of the principle of sub-item movement of the thread divergence processing method provided by the present invention.
[0037] Figure 7 This is the fifth schematic diagram of the principle of sub-item movement of the thread divergence processing method provided by the present invention.
[0038] Figure 8This is the sixth schematic diagram of the sub-item movement principle of the thread divergence processing method provided by the present invention.
[0039] Fig. 9 This is the seventh schematic diagram of the principle of sub-item movement of the thread divergence processing method provided by the present invention.
[0040] Fig.10 It is a structural schematic diagram of the thread divergence processing device provided by the present invention.
[0041] Fig.11 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0042] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0043] The traditional SIMT stack (PDOM mechanism) adopts a "unified" mechanism after the thread bundles are differentiated, so that all differentiated thread bundles "uniformly" converge at the "immediate post-dominator" of the conditional jump instruction (i.e., IPDOM). The SIMT Stack "unified" mechanism (i.e., PDOM mechanism) only designs a general mechanism to solve the execution of differentiated thread bundles on the SIMD pipeline from the perspective of the static structure of the program, which only ensures the correctness of program execution; but ignores the dynamic execution characteristics of the program, reduces the performance of the program, and is prone to deadlock problems.
[0044] In the related prior art, in order to realize thread convergence, it is generally necessary to calculate the convergence point, which cannot be automatically converged and is inefficient.
[0045] Combine the following Figure 1-Figure 11 The technical solution of the embodiment of the present invention is described in detail with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments.
[0046] Figure 1 FIG. 1 is a flow chart of the thread divergence processing method provided by the present invention. Figure 1As shown, the method provided in this embodiment is applied to a processor, wherein an ordered list is stored in the processor, wherein the ordered list includes: sub-item information corresponding to at least one instruction, wherein the sub-item information includes: instruction-related information and a thread execution mask, and the method includes:
[0047] Step 101, determine the next instruction of the currently executed instruction; if the currently executed instruction is a branch instruction, the next instruction includes at least two divergent instructions.
[0048] Specifically, in the embodiment of the present invention, the divergent instruction information is stored and maintained through an ordered list, the ordered list includes: sub-item information corresponding to at least one instruction, each sub-item information includes: instruction-related information and thread execution mask, instruction-related information such as instruction address, priority information, etc., the thread execution mask indicates the thread enable that actually works when the instruction is executed. For example, assuming there are 4 threads, the thread execution mask 0001 indicates that thread 1 executes the corresponding instruction, 1100 indicates that thread 3 and thread 4 execute the corresponding instruction, and the left side of the thread execution mask indicates the high bit.
[0049] The ordered list is arranged according to the numerical value of the instruction related information (such as represented by pc_modify), and the pc of the instruction executed each time is fixed to pc_0.
[0050] Figure 2 In the example, pc_0 represents the currently executed instruction, and the next instruction of the currently executed instruction is determined. If the currently executed instruction is a branch instruction, the next instruction includes at least two divergent instructions; if the currently executed instruction is a non-branch instruction, the next instruction includes one instruction.
[0051] For example, in the following code segment, the next instruction nextpc corresponding to pc=1 is pc=2 and 4 respectively.
[0052] 1 if (a)
[0053] 2 xxx
[0054] 3 xxx
[0055] 4 xxx
[0056] Step 102: determine the position in the ordered list where the next instruction is to be inserted according to the numerical value of the instruction-related information corresponding to the next instruction, and determine the movement information of the sub-item information corresponding to each first instruction in the ordered list.
[0057] Specifically, according to the value of the instruction related information pc_modify corresponding to the next instruction, the position to be inserted into the ordered list of the next instruction is determined, and the moving information of the sub-item information corresponding to other instructions in the ordered list is determined.
[0058] For example, Figure 3 As shown, it is assumed that instructions 6.5 (6.5 represents the numerical size of instruction-related information) and 2.5 are instructions that need to be inserted. Since 6.5 is greater than 6 and less than 7, the position to be inserted is between instructions 6 and 7. Instruction 2.5 is greater than 2 and less than 3, and the position to be inserted is between instructions 2 and 3. 2.5 and 6.5 are only for illustration. Figure 3 The upper list is the list before insertion, the lower list is the list after insertion, and the number of sub-item information in the list is the number of threads in the thread warp.
[0059] Step 103: insert the sub-item information corresponding to the next instruction into the ordered list according to the position to be inserted corresponding to the next instruction and the movement information of the sub-item information corresponding to each of the first instructions.
[0060] Specifically, in step 102, the position to be inserted corresponding to the next instruction and the movement information of the sub-item information corresponding to each original first instruction in the ordered list are determined, and based on the above information, the sub-item information corresponding to the next instruction is inserted into the ordered list.
[0061] like Figure 3 As shown, since 6.5 is greater than 6 and less than 7, the position to be inserted is between instructions 6 and 7. The original sub-item is moved and 6.5 is inserted between instructions 6 and 7. Instruction 2.5 is greater than 2 and less than 3, so it is inserted between instructions 2 and 3.
[0062] The method of this embodiment stores sub-item information corresponding to instructions through an ordered list, and the sub-item information includes: instruction-related information and thread execution mask, and can record divergent instruction information. First, the next instruction of the currently executed instruction is determined; if the currently executed instruction is a branch instruction, the next instruction includes at least two divergent instructions; further, according to the numerical value of the instruction-related information corresponding to the next instruction, the position to be inserted into the ordered list of the next instruction is determined, and the movement information of the sub-item information corresponding to each first instruction in the ordered list is determined; according to the position to be inserted corresponding to the next instruction and the movement information of the sub-item information corresponding to each first instruction, the sub-item information corresponding to the next instruction is inserted into the ordered list, and the ordered list is updated in real time. During execution, the execution is performed based on the order of arrangement in the ordered list, thereby realizing automatic convergence of threads and improving thread execution efficiency.
[0063] Optionally, the instruction-related information includes at least one of the following: instruction address, whether forced to wait, whether valid, and priority information.
[0064] The value of the instruction-related information is obtained by splicing at least one of the instruction address, whether it is forced to wait, whether it is valid, and priority information.
[0065] Specifically, the ordered list can be stored in the processor through registers, the number of register groups is equal to the number of threads in a warp, and the maximum number of divergences that exist is equal to the number of threads.
[0066] The instruction related information (for example, represented by pc_modify) is the instruction address (for example, represented by the pc pointer) with some information attached, including the following information: whether the instruction is forced to wait, whether the instruction is valid, priority information, and instruction address.
[0067] Whether the instruction is forced to wait: When the processor issues an inter-thread synchronization instruction syncthread, when the forced waiting target thread mask is inconsistent with the thread execution mask corresponding to the current instruction, the bit in the forced waiting target thread mask is set to be consistent with the thread execution mask, for example, the bit in the forced waiting target thread mask is set high.
[0068] Is the instruction valid: Initialize the bit of all sub-items in the ordered list to be invalid. Each time an instruction is added to the ordered list, the bit of the corresponding entry is valid, for example, the bit is set high.
[0069] Priority information can be used to participate in divergent instruction selection. For example, when calling a function, it is always expected that the function with the deepest calling depth will be executed first. In this case, the function calling depth can be used as priority information.
[0070] In the above implementation, there is no stack structure, and an ordered list is used, which has high execution efficiency and supports any priority information to participate in the divergent instruction selection.
[0071] Optionally, the instruction includes an inter-thread synchronization instruction; the sub-item information also includes: a forced waiting target thread mask.
[0072] Specifically, the forced waiting target thread mask is caused by an inter-thread synchronization instruction, such as a syncthread instruction. When an instruction is a syncthread instruction, the mask corresponding to the waiting target thread in the forced waiting target thread mask is updated, such as set high.
[0073] In the above implementation, inter-thread synchronization instructions are supported to further optimize program execution efficiency.
[0074] Optionally, determining the next instruction of the currently executed instruction may be performed, for example, by Figure 2 The divergence instruction generation module in is implemented.
[0075] This module is used to generate the next instruction pc and possible divergent instructions. For example, in the following code segment, the next instruction nextpc generated by pc=1 is pc=2, 4 respectively;
[0076] 1 if (a)
[0077] 2 xxx
[0078] 3 xxx
[0079] 4 xxx
[0080] When there are loop, select, jump and other instructions, nextpc is the result of the interaction of these instructions, and the specific implementation logic is optional. It generates next_pc_modify0 / next_pc_modify01 together with priority information. In this example, an instruction will only generate 2 divergences at most.
[0081] Optionally, determining the movement information of the sub-item information corresponding to each first instruction in the ordered list may be implemented in the following manner:
[0082] According to the numerical values of the instruction-related information corresponding to each first instruction and the numerical values of the instruction-related information corresponding to the next instruction, the movement information of the sub-item information corresponding to each first instruction is determined; the movement information includes at least one of the following: move one position to the left, move one position to the right, do not move, and delete.
[0083] Specifically, based on the relationship between the numerical value of the instruction-related information corresponding to the next instruction and the numerical value of the instruction-related information corresponding to each first instruction in the ordered list, the movement information of each original sub-item information in the ordered list, such as the moving direction, whether to move or delete, is determined.
[0084] Optionally, the movement information includes at least one of the following: move one position to the left, move one position to the right, do not move, and delete.
[0085] Optionally, for each sub-item information corresponding to the first instruction, when a value of the instruction-related information corresponding to the first instruction is greater than values of the instruction-related information corresponding to the two divergent instructions, the movement information includes a left shift of one position;
[0086] In the case where the value of the instruction-related information corresponding to the first instruction is less than the value of the instruction-related information corresponding to the divergent instruction, or, there is a second instruction in the ordered list, the second instruction is a forced waiting instruction, and all target threads are currently waiting, and the value of the instruction-related information corresponding to the first instruction is greater than the value of the instruction-related information corresponding to the second instruction, the movement information includes a right shift of one position;
[0087] When the value of the instruction-related information corresponding to the first instruction is greater than the value of the instruction-related information corresponding to the divergence instruction, and there is no mandatory waiting instruction before the first instruction, the movement information includes: no movement, that is, the sub-item information corresponding to the first instruction is not moved;
[0088] When the first instruction is a forced waiting instruction and all target threads have been waited for, the moving information includes: deleting, that is, deleting the sub-item information corresponding to the first instruction from the ordered list.
[0089] Specifically, assuming that the divergence instructions include next_pc_modify0 and next_pc_modify1, the movement information of each sub-item entry in the ordered list is determined according to the relationship between the divergence instructions next_pc_modify0, the divergence instructions next_pc_modify1 and the pc_modify in each sub-item entry in the ordered list. There are four possibilities: move one position to the left (one grid in the list), move one position to the right (one grid in the list), do not move, and delete. The four logic descriptions are as follows:
[0090] 1. Move left one grid. The specific implementation principle is as follows:
[0091] 1) Shift left by 2 and right by 1:
[0092] Shift left by 2: There are two divergent instructions, the pc_modify of the current sub-item entry is greater than 2 next_pc_modify0 / next_pc_modify1, and next_pc_modify0 and next_pc_modify1 are not equal to the original instructions in the ordered list (that is, no merging occurs).
[0093] Shift right by 1: pc_0 is taken away and executed.
[0094] like Figure 3 Instructions 7 and 8 are shown when inserted into 6.5.
[0095] The above-mentioned shifting left by 2 and then right by 1 is just to illustrate the principle. In the actual execution process, directly shifting left by one grid does not exist. The situation of shifting left by 2 and then right by 1 does not exist, and the execution efficiency is higher.
[0096] 2. Move right one grid. There are two situations. The specific implementation principles are as follows:
[0097] 1) Shift right by 1:
[0098] No movement: no insertion ahead, no deletion.
[0099] Shift right by 1: pc_0 is taken away and executed.
[0100] like Figure 4 Instructions 2 and 1 are shown when inserted into 2.5.
[0101] 2) Shift right by 2 and left by 1:
[0102] Shift right by 1: There is a deletion in front of the current sub-item entry (the front refers to the sub-item entry before the current entry in the ordered table (that is, pc_modify is less than the pc_modify of the current sub-item entry), that is, the pc_modify of the instruction pc is less than the pc_modify of the current entry). Deletion means forcing the waiting instruction to wait for all target threads.
[0103] Shift left by 1: Deletion must be accompanied by an insertion and does not hit other sub-item entries (hit refers to the merge with other sub-item entries due to equal pc).
[0104] Shift right by 1: pc_0 is taken away and executed.
[0105] like Figure 5 Instructions 9, 8, 7, 6, and 5 are inserted into 6.5 and 2.5.
[0106] The above shift right by 2 and left by 1 is just to illustrate the principle. In the actual execution process, directly shifting right by one grid will have higher execution efficiency.
[0107] 3. Do not move. The specific implementation principle is as follows:
[0108] 1) Shift left by 1, shift right by 1:
[0109] Shift left by 1: the pc_modify of the current sub-item entry is greater than the pc_modify of 1 divergent instruction, and the divergent instruction does not hit other sub-item entries, and there is no deletion entry in front (there is an insertion in front).
[0110] Shift right by 1: pc0 is taken away and executed.
[0111] like Figure 6 Instruction 3 deletes instruction 4 and instruction 2.5.
[0112] 4. Delete. The specific implementation principle is as follows:
[0113] When the current sub-item entry has waited for all target threads, the sub-item information corresponding to the instruction is deleted from the ordered list. The deletion must be accompanied by an insertion and does not hit other sub-item entries.
[0114] Optionally, the sub-item information corresponding to each of the first instructions is moved according to the movement information of the sub-item information corresponding to each of the first instructions.
[0115] Specifically, Figure 2 As shown, this step can be implemented by the update control module, which maintains the information of each sub-item entry in the ordered list. There are 5 sources of information for each entry. Assuming that the current entry = tab[i], the sources for updating the entry at the next moment are:
[0116] old_tab[i], old_tab[i-1], old_tab[i+1], next_pc_modify0, next_pc_modify1.
[0117] (The original entry is recorded as old_tab[i])
[0118] 1) If Figure 3 As shown, the starting value of i is 0. From right to left, i=8 or 9, old tab[i-1] is shifted left, and new_tab[i]= old_tab[i-1].
[0119] 2) If Figure 4 As shown, i = 0 or 1, old tab[i+1] is shifted right, and new_tab[i] = old tab[i+1].
[0120] 3) If Figure 7 As shown, i=4, 5, 6 or 7, old_tab[i] no move, new_tab[i]=old_tab[i].
[0121] 4) If Figure 8 As shown, i=7, old_tab[i] = the tab to the left of new_tab[i], old_tab[i-1] != the tab to the left of new_tab[i-1], new_tab[i] = max(next_pc_modify0, next_pc_modify1), that is, instruction 6.5 is inserted at position i=7.
[0122] 5) If Fig. 9 As shown, i=2, old_tab[i] = the tab to the right of new_tab[i] (that is, instruction 2 in the figure moves one space to the right), old_tab[i+1] != the tab to the right of new_tab[i+1], new_tab[i] = min(next_pc_modify0, next_pc_modify1), that is, instruction 2.5 is inserted at position i=2.
[0123] For example, assume that a warp has 4 threads, the PC address width is 16, with 2-bit priority information, and it is expected that instructions with a deep function call depth will be executed first. Execute the following program, starting with PC=1: The expected instruction execution order is:
[0124] 1(4'b1111)->2(4'b1111)->3(4'b1100)->7(4'b1000)->8(4'b1000)->4(4'b1100)->5(4'b1111).
[0125] The program code is as follows:
[0126] 1: a=a+b
[0127] 2: branch to pc=5 / / condition=thread id<2
[0128] 3: branch to function call(A) / / condition=thread id==3
[0129] 4: c=c+d
[0130] 5: a=a b
[0131] 6: function(A)
[0132] 7: a=a+1
[0133] 8: return
[0134] The changes in the ordered list under each instruction are as follows:
[0135] 1) Initial state, as shown in Table 1 below, where pc_modify indicates instruction related information, mask indicates thread execution mask, and sync_targ indicates forced waiting target thread mask. The first bit on the left of Table 1 indicates whether forced waiting is performed, the second bit indicates whether it is valid, two bits indicate priority information, and 16 bits indicate instruction address.
[0136] Table 1
[0137]
[0138] 2) pc = 0, as shown in Table 2 below:
[0139] Table 2
[0140]
[0141] In Table 2, the first sub-item on the right includes information about the next instruction 1, and the thread execution mask is 1111.
[0142] 3) pc=1, as shown in Table 3 below:
[0143] Table 3
[0144]
[0145] In Table 3, the first sub-item on the right includes the information of the next instruction 2, that is, the instruction branch to pc=5 / / condition=thread id<2, and the thread execution mask is 1111.
[0146] 4) pc=2, as shown in Table 4 below:
[0147] Table 4
[0148]
[0149] In Table 4, the first sub-item on the right includes information about the next instruction 3, and the thread execution mask is 1100, indicating that the third and fourth threads execute the instruction. The second sub-item includes information about the next instruction 5, and the thread execution mask is 0011, indicating that the first and second threads execute the instruction.
[0150] 5) pc=3, as shown in Table 5 below:
[0151] Table 5
[0152]
[0153] In Table 5, the first sub-item on the right includes the information of the next instruction 7, and the thread execution mask is 1000, indicating that the fourth thread executes the instruction. The second sub-item includes the information of the next instruction 4, and the thread execution mask is 0100, indicating that the third thread executes the instruction. The third sub-item includes the information of the next instruction 5, and the thread execution mask is 0011, indicating that the first and second threads execute the instruction.
[0154] 6) pc=7, as shown in Table 6 below:
[0155] Table 6
[0156]
[0157] In Table 6, the first sub-item on the right includes information about the next instruction 8, and the thread execution mask is 1000, indicating that the fourth thread executes the instruction. The second sub-item includes information about the next instruction 4, and the thread execution mask is 0100, indicating that the third thread executes the instruction. The third sub-item includes information about the next instruction 5, and the thread execution mask is 0011, indicating that the first and second threads execute the instruction.
[0158] 7) pc=8, as shown in Table 7 below:
[0159] Table 7
[0160]
[0161] In Table 7, the first sub-item on the right includes the information of the next instruction 4, and the thread execution mask is 1100, indicating that the third and fourth threads execute the instruction, and the third and fourth threads achieve automatic convergence. The second sub-item includes the information of the next instruction 5, and the thread execution mask is 0011, indicating that the first and second threads execute the instruction.
[0162] 8) pc=4, as shown in Table 8 below:
[0163] Table 8
[0164]
[0165] In Table 8, the first sub-item on the right includes information about the next instruction 5, and the thread execution mask is 1111, indicating that the first, second, third, and fourth threads execute the instruction, and the four threads achieve automatic convergence.
[0166] 9) pc=5, as shown in Table 9 below:
[0167] Table 9
[0168]
[0169] The thread divergence processing device provided by the present invention is described below. The thread divergence processing device described below and the thread divergence processing method described above can be referred to each other.
[0170] Fig.10 Schematic diagram of the structure of the thread divergence processing device provided by the present invention. Fig.10 As shown, the thread divergence processing device provided in this embodiment is applied to a processor, wherein the processor stores an ordered list, wherein the ordered list includes: sub-item information corresponding to at least one instruction, wherein the sub-item information includes: instruction-related information and a thread execution mask, wherein the device includes:
[0171] The determination module 1010 is used to determine the next instruction of the currently executed instruction; if the currently executed instruction is a branch instruction, the next instruction includes at least two divergent instructions;
[0172] The determination module 1010 is further configured to determine the position to be inserted of the next instruction in the ordered list according to the value of the instruction related information corresponding to the next instruction, and to determine the movement information of the sub-item information corresponding to each first instruction in the ordered list;
[0173] The processing module 1020 is used to insert the sub-item information corresponding to the next instruction into the ordered list according to the to-be-inserted position corresponding to the next instruction and the movement information of the sub-item information corresponding to each of the first instructions.
[0174] Optionally, the determining module 1010 is specifically configured to:
[0175] According to the numerical values of the instruction-related information corresponding to each first instruction and the numerical values of the instruction-related information corresponding to the next instruction, the movement information of the sub-item information corresponding to each first instruction is determined; the movement information includes at least one of the following: move one position to the left, move one position to the right, do not move, and delete.
[0176] Optionally, the determining module 1010 is specifically configured to:
[0177] For each sub-item information corresponding to the first instruction, when the value of the instruction-related information corresponding to the first instruction is greater than the values of the instruction-related information corresponding to the two divergent instructions, the movement information includes a left shift of one position;
[0178] In the case where the value of the instruction-related information corresponding to the first instruction is less than the value of the instruction-related information corresponding to the divergent instruction, or, there is a second instruction in the ordered list, the second instruction is a forced waiting instruction, and all target threads are currently waiting, and the value of the instruction-related information corresponding to the first instruction is greater than the value of the instruction-related information corresponding to the second instruction, the movement information includes a right shift of one position;
[0179] In the case where the value of the instruction-related information corresponding to the first instruction is greater than the value of the instruction-related information corresponding to the divergence instruction, and there is no mandatory waiting instruction before the first instruction, the movement information includes: no movement;
[0180] When the first instruction is a forced waiting instruction and all target threads have been waited for, the moving information includes: deletion.
[0181] Optionally, the processing module 1010 is further configured to:
[0182] The sub-item information corresponding to each of the first instructions is moved according to the moving information of the sub-item information corresponding to each of the first instructions.
[0183] Optionally, the instruction-related information includes at least one of the following: instruction address, whether forced to wait, whether valid, and priority information;
[0184] The value of the instruction-related information is obtained by splicing at least one of the instruction address, whether it is forced to wait, whether it is valid, and priority information.
[0185] Optionally, the sub-item information further includes: a forced waiting target thread mask;
[0186] The instruction includes an inter-thread synchronization instruction; the forced waiting target thread mask is caused by the inter-thread synchronization instruction.
[0187] The device of the embodiment of the present invention is used to execute the method in any of the aforementioned method embodiments. Its implementation principle and technical effects are similar and will not be repeated here.
[0188] Fig.11 An example of a physical structure diagram of an electronic device is shown in FIG. Fig.11 As shown, the electronic device may include: a processor 1110, a communication interface 1120, a memory 1130 and a communication bus 1140, wherein the processor 1110, the communication interface 1120 and the memory 1130 communicate with each other through the communication bus 1140. The processor 1110 may call the logic instructions in the memory 1130 to execute the thread divergence processing method, wherein the processor stores an ordered list, wherein the ordered list includes: sub-item information corresponding to at least one instruction, wherein the sub-item information includes: instruction related information and thread execution mask, wherein the method includes:
[0189] Determine a next instruction of a currently executed instruction; if the currently executed instruction is a branch instruction, the next instruction includes at least two divergent instructions;
[0190] Determine the position to be inserted of the next instruction in the ordered list according to the value of the instruction related information corresponding to the next instruction, and determine the movement information of the sub-item information corresponding to each first instruction in the ordered list;
[0191] The sub-item information corresponding to the next instruction is inserted into the ordered list according to the to-be-inserted position corresponding to the next instruction and the movement information of the sub-item information corresponding to each of the first instructions.
[0192] In addition, the logic instructions in the above-mentioned memory 1130 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on such an understanding, the technical solution of the present invention can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0193] On the other hand, the present invention further provides a computer program product, the computer program product includes a computer program, the computer program can be stored on a non-transitory computer-readable storage medium, when the computer program is executed by a processor, the computer can execute the thread divergence processing method provided by the above methods, the method is applied to a processor, the processor stores an ordered list, the ordered list includes: sub-item information corresponding to at least one instruction, the sub-item information includes: instruction-related information and a thread execution mask, the method includes:
[0194] Determine a next instruction of a currently executed instruction; if the currently executed instruction is a branch instruction, the next instruction includes at least two divergent instructions;
[0195] Determine the position to be inserted of the next instruction in the ordered list according to the value of the instruction related information corresponding to the next instruction, and determine the movement information of the sub-item information corresponding to each first instruction in the ordered list;
[0196] The sub-item information corresponding to the next instruction is inserted into the ordered list according to the to-be-inserted position corresponding to the next instruction and the movement information of the sub-item information corresponding to each of the first instructions.
[0197] In another aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the method for handling thread divergence provided by the above methods is implemented. The method is applied to a processor, wherein an ordered list is stored in the processor, wherein the ordered list includes: sub-item information corresponding to at least one instruction, wherein the sub-item information includes: instruction-related information and a thread execution mask. The method includes:
[0198] Determine a next instruction of a currently executed instruction; if the currently executed instruction is a branch instruction, the next instruction includes at least two divergent instructions;
[0199] Determine the position to be inserted of the next instruction in the ordered list according to the value of the instruction related information corresponding to the next instruction, and determine the movement information of the sub-item information corresponding to each first instruction in the ordered list;
[0200] The sub-item information corresponding to the next instruction is inserted into the ordered list according to the to-be-inserted position corresponding to the next instruction and the movement information of the sub-item information corresponding to each of the first instructions.
[0201] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0202] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0203] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A thread divergence processing method, characterized in that: Applied to a processor, the processor stores an ordered list, the ordered list includes: sub-item information corresponding to at least one instruction, the sub-item information includes: instruction related information and a thread execution mask, the method includes: Determine a next instruction of a currently executed instruction; if the currently executed instruction is a branch instruction, the next instruction includes at least two divergent instructions; Determining a position in the ordered list where the next instruction is to be inserted according to a numerical value of the instruction related information corresponding to the next instruction; For the sub-item information corresponding to each first instruction in the ordered list: when the value of the instruction-related information corresponding to the first instruction is greater than the values of the instruction-related information corresponding to the two divergent instructions, the movement information of the sub-item information corresponding to the first instruction includes: shifting left by one position; when the value of the instruction-related information corresponding to the first instruction is less than the value of the instruction-related information corresponding to the divergent instruction, or, there is a second instruction in the ordered list, the second instruction is a forced waiting instruction, and all target threads have been waited for, and the value of the instruction-related information corresponding to the first instruction is greater than the value of the instruction-related information corresponding to the second instruction, the movement information of the sub-item information corresponding to the first instruction includes: shifting right by one position; when the value of the instruction-related information corresponding to the first instruction is greater than the value of the instruction-related information corresponding to the divergent instruction, and there is no forced waiting instruction before the first instruction, the movement information of the sub-item information corresponding to the first instruction includes: not moving; when the first instruction is a forced waiting instruction, and all target threads have been waited for, the movement information of the sub-item information corresponding to the first instruction includes: deleting; The sub-item information corresponding to the next instruction is inserted into the ordered list according to the to-be-inserted position corresponding to the next instruction and the movement information of the sub-item information corresponding to each of the first instructions.
2. The thread divergence processing method according to claim 1, characterized in that: Before inserting the sub-item information corresponding to the next instruction into the ordered list, the method further includes: The sub-item information corresponding to each of the first instructions is moved according to the moving information of the sub-item information corresponding to each of the first instructions.
3. The thread divergence processing method according to claim 1, characterized in that: The instruction related information includes at least one of the following: instruction address, whether it is forced to wait, whether it is valid, and priority information; The value of the instruction-related information is obtained by splicing at least one of the instruction address, whether it is forced to wait, whether it is valid, and priority information.
4. The thread divergence processing method according to claim 3, characterized in that: The sub-item information also includes: a forced waiting target thread mask; The instruction includes an inter-thread synchronization instruction; the forced waiting target thread mask is caused by the inter-thread synchronization instruction.
5. A thread divergence processing device, characterized in that: Applied to a processor, the processor storing an ordered list, the ordered list comprising: sub-item information corresponding to at least one instruction, the sub-item information comprising: instruction-related information and a thread execution mask, the device comprising: A determination module, used to determine the next instruction of the currently executed instruction; if the currently executed instruction is a branch instruction, the next instruction includes at least two divergent instructions; The determination module is further used to determine the position to be inserted of the next instruction in the ordered list according to the numerical value of the instruction related information corresponding to the next instruction; for the sub-item information corresponding to each first instruction in the ordered list: when the numerical value of the instruction related information corresponding to the first instruction is greater than the numerical values of the instruction related information corresponding to the two divergent instructions, the movement information of the sub-item information corresponding to the first instruction includes: shifting left by one position; when the numerical value of the instruction related information corresponding to the first instruction is less than the numerical value of the instruction related information corresponding to the divergent instruction, or when there is a second instruction in the ordered list, the second instruction is a forced waiting instruction, and all target threads are currently waiting, and the numerical value of the instruction related information corresponding to the first instruction is greater than the numerical value of the instruction related information corresponding to the second instruction, the movement information of the sub-item information corresponding to the first instruction includes: shifting right by one position; when the numerical value of the instruction related information corresponding to the first instruction is greater than the numerical value of the instruction related information corresponding to the divergent instruction, and there is no forced waiting instruction before the first instruction, the movement information of the sub-item information corresponding to the first instruction includes: not moving; when the first instruction is a forced waiting instruction, and all target threads are currently waiting, the movement information of the sub-item information corresponding to the first instruction includes: deleting; The processing module is used to insert the sub-item information corresponding to the next instruction into the ordered list according to the to-be-inserted position corresponding to the next instruction and the movement information of the sub-item information corresponding to each of the first instructions.
6. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the thread divergence processing method according to any one of claims 1 to 4 is implemented.
7. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the thread divergence processing method according to any one of claims 1 to 4 is implemented.
8. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the thread divergence processing method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Compiler-controlled region scheduling for simd execution of threads
CN103870246A
Determination of branch convergence in a sequence of program instructions
CN106257412A
