Branch instruction processing method, processor, chip, board, device and medium

By introducing a branch instruction processing unit and stack into the SIMT processor to determine and update address parameters, the problem of low efficiency in branch instruction processing of the SIMT processor is solved, and efficient multi-thread branch control is achieved.

CN114911528BActive Publication Date: 2024-09-13SHANGHAI POWERTENSORS INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210613728.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-31
Publication Date
2024-09-13
Estimated Expiration
2042-05-31

AI Technical Summary

Technical Problem

When a SIMT processor encounters a branch instruction, the execution path is different due to different data between threads, resulting in low efficiency and the inability to effectively handle the branch instruction method in the pipeline processor.

Method used

A branch instruction processing method is designed, which uses the branch instruction processing unit and stack to determine the address parameters of the convergence instruction and the first instruction address parameters of different branches, and push them into the stack to save key information, thereby achieving multi-thread branch control, and Update address parameters when executing branch instructions to ensure orderly processing.

Benefits of technology

It improves the efficiency of SIMT processors in processing branch instructions, reduces stack space requirements, enables efficient processing of instructions of different branches, and solves the efficiency problem of SIMT processors in processing branch instructions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114911528B
    Figure CN114911528B
Patent Text Reader

Abstract

The disclosed embodiments provide a branch instruction processing method, a SIMT processor, a chip, a board, a device and a storage medium. The SIMT processor includes a branch instruction processing unit and a stack; the branch instruction processing unit is used to: in the case of at least two different branches for executing branch instructions in multiple threads, determine the first address parameter of the convergence instruction and the second address parameter of the first instruction of the subsequent execution branch; push the entry including the first address parameter and the second address parameter into the top of the stack; in the process of executing the branch instruction or the instruction in the first execution branch, when the third address parameter of the next instruction to be executed is consistent with the first address parameter in the top of the stack, update the third address parameter to the second address parameter in the top of the stack. This implementation realizes efficient processing of branch instructions.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of data processing technology, and in particular to a branch instruction processing method, a SIMT processor, a chip, a board, a device and a storage medium. Background Art

[0002] Single Instruction Multi Thread (SIMT) uses a single instruction to control the execution of multiple threads, that is, multiple threads execute the same instruction at the same time. SIMT technology is applied to processor design, which can save instruction fetch logic resources, use more transistors for calculations, and improve the computing power of the processor; in graphics calculations, a large number of vertices and pixels need to perform the same operation, which has extremely high data parallelism, and SIMT has good adaptability.

[0003] In a SIMT processor, when all threads in a thread cluster have the same execution path, the SIMT processor can obtain full efficiency and performance; if there are conditional branches in the threads in the thread cluster, the execution paths will be different due to the different data of each thread. For example, when encountering a branch instruction, the execution results of some threads in the thread cluster meet the conditions indicated by the branch instruction, while the execution results of other threads do not meet the conditions. The threads that meet the conditions need to branch and transfer, while the others do not. In this case, the SIMT processor has the problem of low execution efficiency. However, unlike pipeline processors, SIMT processors do not need to predict branch instructions, and the branch instruction processing method in pipeline processors cannot be applied to SIMT processors.

[0004] Therefore, it is necessary to propose a more efficient branch instruction processing mechanism for SIMT processors. Summary of the invention

[0005] The present disclosure provides a branch instruction processing method, a SIMT processor, a chip, a board, a device and a storage medium.

[0006] According to a first aspect of an embodiment of the present disclosure, a SIMT processor is provided, comprising a branch instruction processing unit and a stack; multiple threads in the SIMT processor can synchronously execute instructions in the same instruction sequence, wherein the instruction sequence includes at least a branch instruction and a convergence instruction, wherein the branch instruction indicates multiple executable branches, and the multiple branches are aggregated at the convergence instruction;

[0007] The branch instruction processing unit is used for:

[0008] In case at least two of the plurality of threads are used to execute different branches of the branch instruction, determining a first address parameter of a convergence instruction and a second address parameter of a first instruction of a later executed branch in the different branches;

[0009] Pushing an entry including the first address parameter and the second address parameter onto the top of the stack;

[0010] In the process of executing the branch instruction or the instructions in the previously executed branch, when the third address parameter of the next instruction to be executed is consistent with the first address parameter at the top of the stack, the third address parameter is updated to the second address parameter at the top of the stack, so that the first instruction of the subsequently executed branch is determined as the next instruction.

[0011] Optionally, the branch instruction processing unit is also used to: during the execution of an instruction that executes a branch later, when the third address parameter of the next instruction is consistent with the first address parameter at the top of the stack, pop out an entry including the first address parameter and the second address parameter from the top of the stack.

[0012] Optionally, the multiple branches include transfer branches and sequential execution branches; the first instruction on the sequential execution branch is the instruction immediately following the branch instruction in the instruction sequence, and the transfer branch is other branches among the multiple branches except the sequential execution branch; the address parameter of the first instruction on the sequential execution branch is obtained by incrementing the address parameter of the branch instruction; the address parameter of the first instruction on the transfer branch is specified by the branch instruction and is discontinuous with the address parameter of the branch instruction.

[0013] Optionally, the branch instruction processing unit is also used to: obtain the first flag bit corresponding to the branch instruction of each thread according to the judgment result of each thread on the judgment condition of the branch instruction, and the first flag bit corresponding to the branch instruction of a thread is used to indicate the next branch executed by the thread after executing the branch instruction.

[0014] Optionally, the multiple branches include transfer branches and sequential execution branches; the first instruction on the sequential execution branch is the instruction immediately following the branch instruction in the instruction sequence, and the transfer branch is the other branch among the multiple branches except the sequential execution branch; the first flag bit of a thread corresponding to the transfer branch is the same as the first flag bit corresponding to the branch instruction, and the first flag bit of a thread corresponding to the sequential transfer branch is obtained by inverting the first flag bit of the thread corresponding to the branch instruction.

[0015] Optionally, the entry further includes a first flag bit of each thread corresponding to the subsequently executed branch.

[0016] Optionally, each thread also corresponds to a second flag bit, which is used to indicate whether the thread is running; the entry also includes the first flag bit and the second flag bit of each thread corresponding to the later executed branch; or the entry also includes the second flag bit of each thread; wherein, the first flag bit of a thread corresponding to the later executed branch is determined based on the second flag bit of the thread and the first flag bit of the thread corresponding to the earlier executed branch.

[0017] Optionally, the number of branch instruction processing units and the number of stacks are both greater than 1, each branch instruction processing unit corresponds to a thread cluster in the SIMT processor, and each stack corresponds to a thread cluster in the SIMT processor; wherein multiple threads in the same thread cluster can synchronously execute each instruction in the same instruction sequence.

[0018] Optionally, the SIMT processor further includes one or more shared memories, each shared memory corresponds to at least two thread clusters, and different shared memories correspond to different thread clusters;

[0019] The branch instruction processing unit is also used to: when the stack overflows, transfer the specified entry in the stack to the shared memory corresponding to the thread cluster; wherein the specified entry is determined according to the write pointer of the stack, and the push time of the specified entry is earlier than the push time of other entries that have not been transferred.

[0020] Optionally, the branch instruction processing unit is further used to: return to the stack; wherein the storage position of the target entry in the stack is adjacent to or differs from the original storage position of the specified entry in the stack by a preset number of storage units, and each storage unit is used to store one entry.

[0021] Optionally, the multiple branches include transfer branches and sequential execution branches; the first instruction on the sequential execution branch is the instruction immediately following the branch instruction in the instruction sequence, and the transfer branch is the other branch among the multiple branches except the sequential execution branch; the branch instruction processing unit is also used to: when the multiple threads are all used to execute the sequential execution branch indicated by the branch instruction, increment the address parameter of the branch instruction to obtain the address parameter of the next instruction to be executed; when the multiple threads are all used to execute the transfer branch indicated by the branch instruction, use the address parameter of the first instruction on the transfer branch as the address parameter of the next instruction to be executed.

[0022] Optionally, the branch instruction processing unit is also used to: in the process of executing an instruction in a previously executed branch or the subsequently executed branch, when the current instruction is a branch instruction and there are at least two threads for executing different branches of the branch instruction, execute the steps of determining a first address parameter and a second address parameter and pushing them into a stack to process the branch instruction nested in the previously executed branch or the subsequently executed branch.

[0023] Optionally, the later-executed branch among the different branches is determined according to a preset branch execution sequence.

[0024] According to a second aspect of an embodiment of the present disclosure, a branch instruction processing method is provided, which is applied to a SIMT processor including a branch instruction processing unit and a stack, wherein multiple threads in the SIMT processor can synchronously execute instructions in the same instruction sequence, wherein the instruction sequence includes at least a branch instruction and a convergence instruction, wherein the branch instruction indicates multiple executable branches, and the multiple branches are aggregated at the convergence instruction; the method comprises:

[0025] In case at least two of the plurality of threads are used to execute different branches of the branch instruction, determining a first address parameter of a convergence instruction and a second address parameter of a first instruction of a later executed branch in the different branches;

[0026] Pushing an entry including the first address parameter and the second address parameter onto the top of the stack;

[0027] In the process of executing the branch instruction or the instructions in the previously executed branch, when the third address parameter of the next instruction to be executed is consistent with the first address parameter at the top of the stack, the third address parameter is updated to the second address parameter at the top of the stack, so that the first instruction of the subsequently executed branch is determined as the next instruction.

[0028] According to a third aspect of an embodiment of the present disclosure, a chip is provided, comprising a SIMT processor as described in any one of the first aspects.

[0029] According to a fourth aspect of an embodiment of the present disclosure, a board is provided, comprising the chip as described in the third aspect.

[0030] According to a fifth aspect of an embodiment of the present disclosure, an electronic device is provided, comprising the SIMT processor described in any one of the first aspect, or the chip described in the third aspect, or the board described in the fourth aspect.

[0031] According to a sixth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided, on which computer instructions are stored. When the computer instructions are executed, the method mentioned in the second aspect is implemented.

[0032] In the embodiment of the present disclosure, it should be understood that the embodiment of the present disclosure proposes a processing mechanism for efficiently processing branch instructions for a SIMT processor, and in the SIMT processor, a corresponding stack and a branch instruction processing unit are set for multiple threads that can synchronously execute the same instruction sequence. In the case of at least two different branches of the multiple threads for executing branch instructions, the branch instruction processing unit can determine the first address parameter of the convergence instruction and the second address parameter of the first instruction of the later executed branch in the different branches, and push the entry including the first address parameter and the second address parameter into the top of the stack, so as to save the key information of the later executed branch through the stack, and for a branch instruction, only the first address parameter and the second address parameter need to be pushed, and no other address parameters need to be pushed, so that the branch control of multiple threads can be completed with less stack space. Moreover, in the process of executing the branch instruction or the instruction in the previously executed branch, when the third address parameter of the next instruction to be executed is consistent with the first address parameter at the top of the stack, the third address parameter is updated to the second address parameter at the top of the stack, so as to realize the execution of the later-executed branch after the branch instruction (when there is no previously executed branch) or the previously executed branch is completed, thereby realizing orderly and efficient processing of different branches of the branch instruction.

[0033] The foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present disclosure and are used to illustrate the technical solutions of the present disclosure together with the specification.

[0035] Figure 1 It is a flowchart of an instruction sequence execution shown in an embodiment of the present disclosure.

[0036] Figure 2 It is a structural diagram of a SIMT processor shown in an embodiment of the present disclosure.

[0037] Figure 3 It is a structural diagram of a second SIMT processor shown in an embodiment of the present disclosure.

[0038] Figure 4 It is a structural diagram of a third SIMT processor shown in an embodiment of the present disclosure.

[0039] Figure 5 It is a structural diagram of a fourth SIMT processor shown in an embodiment of the present disclosure.

[0040] Figure 6It is a structural diagram of the fifth SIMT processor shown in an embodiment of the present disclosure.

[0041] Figure 7 It is a schematic diagram showing the moving of entries in a stack to a shared memory according to an embodiment of the present disclosure.

[0042] Figure 8 is a schematic diagram showing writing entries from a shared memory back to a stack according to an embodiment of the present disclosure.

[0043] Fig. 9 It is a flowchart of a branch instruction processing method shown in an embodiment of the present disclosure.

[0044] Fig.10 It is a flowchart of the second branch instruction processing method shown in an embodiment of the present disclosure.

[0045] Fig.11 It is a schematic diagram of the structure of a board card shown in an embodiment of the present disclosure. DETAILED DESCRIPTION

[0046] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.

[0047] The terms used in this disclosure are only for the purpose of describing specific embodiments and are not intended to limit the disclosure. The singular forms of "a", "said" and "the" used in this disclosure and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items. In addition, the term "at least one" herein means any combination of at least two of any one or more of a plurality of.

[0048] It should be understood that although the terms first, second, third, etc. may be used in the present disclosure to describe various information, such information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present disclosure, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".

[0049] In order to enable those skilled in the art to better understand the technical solutions in the embodiments of the present disclosure and to make the above-mentioned purposes, features and advantages of the embodiments of the present disclosure more obvious and understandable, the technical solutions in the embodiments of the present disclosure are further described in detail below in conjunction with the accompanying drawings.

[0050] Single Instruction Multi Thread (SIMT) uses a single instruction to control the execution of multiple threads, that is, multiple threads execute the same instruction at the same time. SIMT technology is applied to processor design, which can save instruction fetch logic resources, use more transistors for calculations, and provide processor computing power; in graphics computing, a large number of vertices and pixels need to perform the same operation, with extremely high data parallelism, SIMT has good adaptability. However, in non-graphic computing, the execution paths of different threads will be different (branch instructions make the execution paths of different threads used to execute the same instruction different), and SIMT has the problem of low efficiency.

[0051] Branch instructions are instructions that appear frequently in programs. In C language, there is one branch instruction for every nine instructions on average. Branch instructions bring about the diversity of program behavior. Branch instructions include if instructions, if-else instructions, while instructions, or for-loop instructions in programs. Branch instructions usually correspond to a specified condition. If the thread determines that the specified condition is true (i.e., the condition is met), the thread needs to branch; if the thread determines that the specified condition is false (i.e., the condition is not met), there is no need to branch but to execute the instructions that follow sequentially.

[0052] For an example, see Figure 1 , for a sequence of instructions such as:

[0053] PC1:if(PC0:condition){

[0054] PC5: instruction a1;

[0055] PC6: instruction a2;

[0056] PC7: instruction a3;}

[0057] else{

[0058] PC2: instruction b1;

[0059] PC3: instruction b2;

[0060] PC4: instruction b3 (jump instruction);}

[0061] PC8: instruction c1;

[0062] PC9: Instruction c2.

[0063] Among them, PC (program counter) is the abbreviation of "program counter". The PC value of an instruction can indicate the storage address of the instruction. For example, in the above instruction sequence, PC0 indicates the storage address of "condition"; PC1 indicates the storage address of the branch instruction (if-else instruction), and PC2 indicates the storage address of "instruction b1"; the PC value of an instruction can be determined during the execution of the previous instruction; for example, when executing instruction b1, the PC value of the next instruction b2 to be executed can be obtained by incrementing the PC value of instruction b1, so that instruction b2 can be obtained and executed based on the PC value of the next instruction b2.

[0064] See also Figure 2 The SIMT processor includes an instruction fetch unit 10, multiple threads 20 capable of synchronously executing the same instruction sequence, and a memory 30, where n is an integer greater than 1. The above instruction sequence can be stored in the memory 30, and the instruction fetch unit 10 can read instructions from the memory 30 based on the storage address indicated by the PC value so that the instructions can be synchronously executed by the multiple threads 20.

[0065] In the case of sequential execution, the SIMT processor can increment the PC value of the instruction to be executed, obtain the PC value of the next instruction to be executed, and prepare for fetching the next instruction to be executed; if the above-mentioned instructions a1, a2 and a3 are instructions to be executed sequentially, when executing instruction a1, PC6 can be obtained by incrementing PC5, and the instruction fetch unit can read instruction a2 from the memory based on the storage address indicated by PC6.

[0066] When a branch instruction is encountered and a branch transfer is required, the storage address (PC value) of the next instruction is specified by the branch instruction rather than being obtained by sequentially incrementing the PC value; for example, when executing the above-mentioned branch instruction, in a SIMT processor, assuming that there are 4 threads, two of which judge the condition as true, a branch transfer is required, and the branch instruction specifies the address of the next instruction after the branch transfer, i.e., PC5; while the other two threads judge the condition as false, and no branch transfer is required, and the next instruction to be executed, PC2, can be obtained by sequentially incrementing PC1, and the instruction b1 indicated by PC2 is the instruction immediately following the branch instruction in the instruction sequence.

[0067] The branch instruction indicates that there are at most two executable branches. In the embodiment of the present disclosure, for the convenience of distinction, the execution path that does not require branch transfer is called a sequential execution branch (i.e. Figure 1① in: PC2→PC3→PC4), the execution path that needs to be branched is called the transfer branch (i.e. Figure 1 ② in it: PC5→PC6→PC7), the first instruction on the sequential execution branch is the instruction immediately following the branch instruction in the instruction sequence, the transfer branch is the other branches in the multiple branches except the sequential execution branch, and finally the sequential execution branch and the transfer branch are gathered at the convergence instruction c1; wherein, the PC value corresponding to the convergence instruction c1 is also specified by the branch instruction, and the convergence instruction refers to the instruction at the convergence point of the two branches. That is to say, when processing the branch instruction, the PC value of the first instruction on the transfer branch and the PC value of the convergence instruction can be determined, and since the PC value of the first instruction on the transfer branch is not obtained by sequential increment, if relevant measures are not taken, the PC value of the first instruction on the transfer branch will not be found in the subsequent instruction execution process, which may cause the transfer branch not to be executed and the instruction execution error.

[0068] The disclosed embodiment proposes a processing mechanism for efficiently processing branch instructions for a SIMT processor, and in the SIMT processor, a corresponding stack and a branch instruction processing unit are set for multiple threads that can synchronously execute the same instruction sequence. In the case of at least two different branches of the multiple threads for executing branch instructions, the branch instruction processing unit can determine the first address parameter of the convergence instruction and the second address parameter of the first instruction of the later executed branch in the different branches, and push the entry including the first address parameter and the second address parameter into the top of the stack, so as to save the key information of the later executed branch through the stack, and for a branch instruction, only the first address parameter and the second address parameter need to be pushed, and no other address parameters need to be pushed, so that the branch control of multiple threads can be completed with less stack space. Moreover, in the process of executing the branch instruction or the instruction in the previously executed branch, when the third address parameter of the next instruction to be executed is consistent with the first address parameter at the top of the stack, the third address parameter is updated to the second address parameter at the top of the stack, so as to realize the execution of the later-executed branch after the branch instruction (when there is no previously executed branch) or the previously executed branch is completed, thereby realizing orderly and efficient processing of different branches of the branch instruction.

[0069] In some embodiments, see Figure 3 The SIMT processor includes a branch instruction processing unit 40 and a stack 50; multiple threads in the SIMT processor can synchronously execute each instruction in the same instruction sequence (such as Figure 1), wherein the instruction sequence includes at least a branch instruction and a convergence instruction, wherein the branch instruction indicates a plurality of executable branches, and the plurality of executable branches are gathered at the convergence instruction.

[0070] The branch instruction processing unit 40 is used for:

[0071] In case at least two of the plurality of threads are used to execute different branches of the branch instruction, determining a first address parameter of a convergence instruction and a second address parameter of a first instruction of a later executed branch in the different branches;

[0072] Pushing an entry including the first address parameter and the second address parameter onto the top of the stack 50;

[0073] In the process of executing the branch instruction or the instructions in the previously executed branch, when the third address parameter of the next instruction to be executed is consistent with the first address parameter at the top of the stack, the third address parameter is updated to the second address parameter at the top of the stack, so that the first instruction of the subsequently executed branch is determined as the next instruction.

[0074] In this embodiment, when at least two of the multiple threads are used to execute different branches of the branch instruction, the stack 50 is used to save key information of the later executed branch. After the branch instruction (when there is no previously executed branch) or the previously executed branch is executed, the information saved in the stack 50 can be used to execute the later executed branch, thereby achieving orderly and efficient processing of different branches of the branch instruction.

[0075] In some embodiments, see Figure 4 The SIMT processor also includes a value fetching unit 10 and a memory 30. The above instruction sequence can be stored in the memory 30. The instruction fetching unit 10 can read instructions from the memory 30 based on the storage address indicated by the address parameter (such as the PC value). The branch instruction processing unit 40 is connected to the instruction fetching unit 10 in the SIMT processor and is used to perform branch instruction judgment on the instructions obtained by the instruction fetching unit 10; the branch instruction processing unit 40 is also connected to the stack 50 and is used to perform related stack push processing operations when at least two different branches in multiple threads are used to execute branch instructions.

[0076] In some embodiments, the address parameter of an instruction indicates the storage address of the instruction. Exemplarily, the address parameter of an instruction includes a PC value (or a program counter value). In some embodiments, the branch instruction processing unit 40 obtains the instruction to be executed from the instruction fetch unit 10, first determines whether the instruction to be executed is a branch instruction, and if the instruction to be executed is a branch instruction, it is necessary to determine whether the multiple threads need to branch for the branch instruction, and the branch instruction indicates that there are multiple branches, and the multiple executable branches include transfer branches (such as Figure 1 ② in: PC5→PC6→PC7) and sequential execution branches (such as Figure 1 ① in it: PC2→PC3→PC4); wherein, the first instruction on the sequential execution branch is the instruction immediately following the branch instruction in the instruction sequence, and the transfer branch is the other branches among the multiple branches except the sequential execution branch; the address parameter of the first instruction on the sequential execution branch is obtained by incrementing the address parameter of the branch instruction, and the address parameter of the first instruction on the transfer branch is specified by the branch instruction and is discontinuous with the address parameter of the branch instruction.

[0077] It should be noted that, since the branch instruction processing unit 40 does not know whether each instruction to be executed is a branch instruction when it obtains it from the instruction fetch unit 10, for each instruction to be executed obtained from the instruction fetch unit, the branch instruction processing unit 40 needs to execute the step of determining whether the instruction to be executed is a branch instruction.

[0078] If the instruction to be executed is a branch instruction, there are three possible situations:

[0079] In the first case, the multiple threads are used to execute the sequential execution branches indicated by the branch instruction, then the address parameter of the branch instruction is incremented to obtain the address parameter of the next instruction to be executed; for example, Figure 1 In the embodiment, if the judgment results of the judgment conditions of multiple threads used to synchronously execute the instruction sequence are all false, the sequential execution branch ① is executed, and the address parameter (PC2) of the first instruction on the sequential execution branch is the result of the increment of PC1.

[0080] In the second case, the multiple threads are all used to execute the branch instruction indicating the transfer branch, and the address parameter of the first instruction on the transfer branch is used as the address parameter of the next instruction to be executed; for example, Figure 1In the embodiment, if the judgment results of the judgment conditions for multiple threads used to synchronously execute the instruction sequence are all true, the transfer branch ② is executed, and the address parameter (PC5) of the first instruction on the transfer branch is specified by the branch instruction; exemplarily, the address parameter of the first instruction on the transfer branch can be determined according to the address code field of the branch instruction.

[0081] In the third case, at least two of the multiple threads are used to execute different branches of the branch instruction, that is, some threads execute sequential execution branches while other threads execute transfer branches. At this time, the above-mentioned stack push operation and its subsequent address parameter update operation can be performed.

[0082] In some embodiments, the branch instruction processing unit 40 can obtain the first flag bit corresponding to the branch instruction of each thread according to the judgment result of the judgment condition of the branch instruction of each thread, and the first flag bit corresponding to the branch instruction of a thread is used to indicate the next branch executed by the thread after executing the branch instruction. Exemplarily, when the flag bit is a first preset value, it indicates that the thread does not execute the transfer branch (i.e., executes the sequential execution branch); when the flag bit is a second preset value, it indicates that the thread executes the transfer branch; the first preset value and the second preset value are different. In one example, one of the first preset value and the second preset value is 1, and the other is 0.

[0083] Corresponding to the above three situations, the first flag bits corresponding to the branch instructions of all threads are the first preset value, indicating that the multiple threads are used to execute the sequential execution branches indicated by the branch instruction; the first flag bits corresponding to the branch instructions of all threads are the second preset value, indicating that the multiple threads are used to execute the transfer branches indicated by the branch instruction; there are at least two threads with different first flag bits corresponding to the branch instructions, indicating that at least two of the multiple threads are used to execute different branches of the branch instruction.

[0084] In one example, assuming that the first flag bit is "1" to indicate that the thread executes the transfer branch, and the first flag bit is "0" to indicate that the thread executes the sequential execution branch. Figure 1 In the illustrated embodiment, it is assumed that there are four threads (assumed to be A, B, C, and D). After determining the condition indicated by PC0, thread A, thread B, and thread C are determined to be true, and their first flag bits are all "1". Thread D is determined to be false, and its first flag bit is "0". There are at least two threads whose first flag bits corresponding to the branch instruction are different, and it can be seen from all the first flag bits "1110" that thread A, thread B, and thread C execute transfer branches, and thread D executes sequential branches.

[0085] In some embodiments, the first flag bit of each thread is used to distinguish the different branches executed by each thread when at least two of the multiple threads are used to execute different branches of the branch instruction, and then control each thread to execute the instructions in the corresponding branch. When multiple threads are used to execute the same branch in the branch instruction, it is not necessary to use the first flag bit to distinguish the branches executed by each thread.

[0086] In some embodiments, when the multiple threads are used to execute different branches of branch instructions (i.e., at least one of the multiple threads is used to execute a transfer branch, and the other threads are used to execute a sequential execution branch), the branch instruction processing unit 40 obtains the address parameter of the convergence instruction and the second address parameter of the first instruction of the later executed branch in the different branches. Figure 1 In the embodiment, for example, if the later executed branch is a transfer branch, PC5 of the first instruction in the transfer branch and the convergence instruction PC8 are obtained.

[0087] Furthermore, the branch instruction processing unit 40 can determine the first flags of each thread corresponding to the transfer branch and the sequential branch respectively according to the first flags of each thread corresponding to the branch instruction. The first flag of a thread corresponding to the transfer branch is the same as the first flag corresponding to the branch instruction, and the first flag of a thread corresponding to the sequential transfer branch is obtained by inverting the first flag of the thread corresponding to the branch instruction.

[0088] In one example, still taking the first flag bit of each thread corresponding to the branch instruction as "1110" as an example, the first flag bits of multiple threads corresponding to the transfer branch are also "1110". Figure 1 Taking the branch shown in the figure as an example, "1110" indicates that thread A, thread B and thread C execute instructions a1, a2 and a3 on the branch; and the first flag bit of the plurality of threads corresponding to the sequential branch is "0001", for example Figure 1 Taking the sequential execution branch in the embodiment as an example, "0001" indicates that thread D points to instructions b1, b2 and b3 on the sequential branch.

[0089] In some embodiments, for the case where at least two of the multiple threads are used to execute different branches of the branch instruction, the order of branch execution can be pre-set, so that the first execution branch and the later execution branch in the different branches can be clearly defined. The address parameter of the first instruction in the first execution branch can be used to obtain the next instruction to be executed, and the second address parameter of the first instruction in the later execution branch and the first address parameter of the convergence instruction are pushed into the top of the stack 50 to save the key information in the later execution branch, and for a branch instruction, only the first address parameter and the second address parameter need to be pushed, and no other address parameters need to be pushed, so that the branch control of multiple threads can be completed with less stack 50 space. Exemplarily, the second address parameter of the first instruction in the later execution branch and the first address parameter of the convergence instruction can be pushed into the top of the stack 50 in the form of forming an entry.

[0090] In some exemplary embodiments, the preset branch execution sequence includes a first sequence and a second sequence; the first sequence indicates that the instructions on the sequential execution branch are executed first, and then the instructions on the transfer branch are executed; the second sequence indicates that the instructions on the transfer branch are executed first, and then the instructions on the sequential execution branch are executed. Any of the above sequences can be selected according to the actual application scenario, and this embodiment does not impose any restrictions on this. For example, in Figure 1 In the embodiment described, PC2 in the sequentially executed branch, PC5 in the transfer branch and the convergence instruction PC8 are obtained. Assuming that the preset branch execution order is the first order, the entry at the top of the stack 50 that needs to be pushed is {PC5, PC8}.

[0091] In one example, for a sequence of instructions such as:

[0092] PC1:if(PC0:condition){

[0093] PC3: instruction a1;

[0094] PC4: instruction a2;

[0095] PC5: instruction a3;}

[0096] PC2: instruction c1.

[0097] It can be seen that the first instruction on the sequential execution branch is instruction c1, and the convergence instruction is also instruction c1, that is, there is a situation where the first instruction on the sequential execution branch is the convergence instruction. Assuming that it is executed in the first order, in the process of executing the branch instruction, the third address parameter of the next instruction to be executed (that is, the address parameter of the first instruction on the sequential execution branch) is compared with the first address parameter of the convergence instruction at the top of the stack. If the two are consistent, the third address parameter is updated to the second address parameter at the top of the stack, so that the first instruction of the later execution branch is determined to be the next instruction.

[0098] In some embodiments, after the address parameter of the first instruction in the previously executed branch is used to obtain the next instruction to be executed, the relevant threads can be controlled to execute the instructions in the previously executed branch according to the first flag bit of each thread corresponding to the previously executed branch. The first flag bit of each thread corresponding to the previously executed branch can be determined based on the first flag bit of each thread corresponding to the branch instruction and the preset branch execution sequence. For example, if the preset branch execution sequence is the above-mentioned first sequence, the first flag bit of each thread corresponding to the previously executed branch (sequential branch) can be determined by inverting the first flag bit of the thread corresponding to the branch instruction.

[0099] In some embodiments, in addition to storing the above two address parameters (first address parameter and second address parameter) in the stack 50, considering that the first flag bit of each thread corresponding to the subsequent execution branch indicates the thread that needs to execute the instruction in the subsequent execution branch, therefore, the first flag bit of each thread corresponding to the subsequent execution branch also needs to be saved. Exemplarily, the entry also includes the first flag bit of each thread corresponding to the subsequent execution branch, so that the thread that needs to execute the instruction in the subsequent execution branch can be clearly identified based on the first flag bit of the stack 50. The first flag bit of each thread corresponding to the subsequent execution branch can be determined based on the first flag bit of each thread corresponding to the branch instruction and the preset branch execution order. For example, if the preset branch execution order is the first order mentioned above, it can be determined that the first flag bit of each thread corresponding to the subsequent execution branch (transfer branch) is the same as the first flag bit corresponding to the branch instruction.

[0100] In some embodiments, when at least two of the multiple threads are used to execute different branches of the branch instruction, the instructions in the first executed branch are pre-executed according to a preset branch execution order, wherein the address parameters of the instructions in the first executed branch are determined by the branch instruction processing unit 40 when processing the previous instruction, for example, the address parameters of the first instruction in the first executed branch are determined during the execution of the branch instruction, and the address parameters of the second instruction in the first executed branch are determined during the execution of the first instruction.

[0101] During the process of executing the branch instruction or the instruction that previously executed the branch, the branch instruction processing unit 40 can pre-fetch the third address parameter of the next instruction to be executed based on the currently executed instruction; generally, the branch instruction processing unit 40 can increment the address parameter of the currently executed instruction to obtain the third address parameter; in addition, when the currently executed instruction is a jump (jmp) instruction, the branch instruction processing unit 40 can determine the third address parameter based on the jump instruction.

[0102] After preliminarily determining the third address parameter of the next instruction to be executed, in order to determine whether the branch instruction is followed by a convergence instruction or whether the previously executed branch has been completed, the branch instruction processing unit 40 may compare the third address parameter with the first address parameter of the convergence instruction located at the top of the stack 50. The purpose of the comparison is to determine whether the branch instruction is followed by a convergence instruction or whether the previously executed branch has been completed. If the comparison is consistent, it indicates that the branch instruction is followed by a convergence instruction or the instruction on the previously executed branch has been executed, and it is necessary to execute the instruction in the later executed branch. The branch instruction processing unit 40 may update the third address parameter to the second address parameter read from the top of the stack 50, so that the first instruction of the later executed branch is determined as the next instruction, and the later executed branch is executed. If the comparison is inconsistent, it indicates that there is a previously executed branch after the branch instruction or the instruction on the previously executed branch has not been executed, then the third address parameter determined above remains unchanged, and is used to continue to obtain the next instruction on the previously executed branch.

[0103] In one example, Figure 1Taking the illustrated embodiment as an example, assuming that the order in which the branches are executed is the first order, that is, the previously executed branch is a sequentially executed branch, the entry pushed into the top of the stack 50 includes at least {PC5, PC8}, assuming that the currently executed instruction is instruction b3 indicated by PC4, b3 is a jump (jmp) instruction, and the third address parameter of the next instruction to be executed determined according to the jump instruction is PC8, and the third address parameter is consistent with the first address parameter at the top of the stack 50, both are PC8, indicating that the instruction on the previously executed branch has been executed, and the branch instruction processing unit 40 updates the third address parameter from PC8 to PC5 at the top of the stack 50, so as to execute the subsequently executed branch after the instruction in the previously executed branch has been executed.

[0104] In some embodiments, after the third address parameter of the next instruction to be executed is updated to the second address parameter read from the top of the stack 50, the thread in the SIMT processor starts to execute the subsequent execution branch. In addition, as mentioned above, in addition to pushing the above two address parameters to the top of the stack 50, the first flag bit of each thread corresponding to the subsequent execution branch is also pushed. When the thread in the SIMT processor starts to execute the subsequent execution branch, it is also necessary to read the first flag bit of each thread corresponding to the subsequent execution branch from the top of the stack 50 to determine the thread that needs to execute the subsequent execution branch.

[0105] In one example, Figure 1 Taking the embodiment shown as an example, it is assumed that the execution order of the branches is the first order, that is, the later executed branch is a transfer branch. Based on the above example, it can be seen that the first flag bit of each thread corresponding to the later executed branch is also "1110", indicating that in the process of executing the instructions of the later executed branch, thread A, thread B and thread C need to execute the instructions on the transfer branch, while thread D does not need to.

[0106] During the process of executing an instruction that executes a branch later, the branch instruction processing unit 40 can determine the third address parameter of the next instruction to be executed based on the currently executed instruction; generally, the branch instruction processing unit 40 can increment the address parameter of the currently executed instruction to obtain the third address parameter of the next instruction to be executed; in addition, when the currently executed instruction is a jump (jmp) instruction, the branch instruction processing unit 40 can determine the third address parameter of the next instruction to be executed based on the jump instruction.

[0107] After preliminarily determining the third address parameter of the next instruction to be executed, in order to determine whether the subsequent execution branch has been completed, the branch instruction processing unit 40 may compare the third address parameter of the next instruction to be executed with the first address parameter of the convergence instruction located at the top of the stack 50. If the comparison is consistent, it indicates that the instruction on the subsequent execution branch has also been executed, and the branch instruction processing unit 40 can pop out an entry including at least the first address parameter and the second address parameter from the top of the stack 50; illustratively, the entry also includes the first flag bit of each thread corresponding to the subsequent execution branch. If the comparison is inconsistent, it indicates that the instruction on the subsequent execution branch has not been executed, and the third address parameter of the next instruction to be executed determined above remains unchanged, and is used to continue to obtain the next instruction to be executed on the subsequent execution branch.

[0108] In one example, Figure 1 Taking the embodiment shown as an example, assuming that the order of execution of the branches is the first order, that is, the later executed branch is a transfer branch, the entries pushed into the top of the stack 50 include at least {PC5, PC8}, assuming that the currently executed instruction is instruction a3 indicated by PC7, and the third address parameter of the next instruction to be obtained by incrementing the address parameter of instruction a3 is PC8. The third address parameter of the next instruction is consistent with the first address parameter of the convergence instruction at the top of the stack 50, both are PC8, indicating that the instruction on the later executed branch has also been executed, and the branch instruction processing unit 40 pops out the entry at the top of the stack 50, indicating that the two branches corresponding to the branch instruction have been executed.

[0109] In some embodiments, during the execution of an instruction in the previously executed branch or the subsequently executed branch, if the instruction is a branch instruction and there are at least two threads for executing different branches of the branch instruction, the steps of determining the first address parameter and the second address parameter and pushing them into the stack 50 can be performed in the same manner as the processing method of the branch instruction in the same situation mentioned above, so as to process the branch instruction nested in the previously executed branch or the subsequently executed branch. Moreover, due to the first-in-last-out data storage format of the stack 50, the branch instruction nested in the previously executed branch or the subsequently executed branch can be processed first, and then the outer branch instruction (i.e., the original branch instruction indicating the previously executed branch and the subsequently executed branch) can be further processed, so as to efficiently handle the branch nesting situation.

[0110] In one example, for a sequence of instructions such as:

[0111] PC1:if(PC0:condition){

[0112] PC8: instruction a1;

[0113] PC9: instruction a2;

[0114] PC10: instruction a3;}

[0115] else{

[0116] PC2: instruction b1;

[0117] PC4:if(PC3:condition){

[0118] PC6: instruction d1;

[0119] PC7: instruction d2 (jump instruction);

[0120] }

[0121] PC5: instruction b3 (jump instruction);}

[0122] PC11: instruction c1;

[0123] PC12: instruction c2.

[0124] When it is determined that the instruction indicated by PC1 is a branch instruction, and at least two of the multiple threads are used to execute different branches of the branch instruction, the first address parameter PC8 of the convergence instruction and the second address parameter PC11 of the first instruction of the later executed branch (assuming it is a transfer branch) among the different branches are determined, and {PC8, PC11} are pushed to the top of the stack 50. In the process of executing the instruction in the previously executed branch (sequential branch), assuming that the currently executed instruction is the instruction indicated by PC4, when it is determined that the instruction indicated by PC4 is a branch instruction, and at least two of the multiple threads are used to execute different branches of the branch instruction, the first address parameter PC5 of the convergence instruction and the second address parameter PC6 of the first instruction of the later executed branch (assuming it is a transfer branch) among the different branches are determined, and {PC5, PC6} are pushed to the top of the stack 50. At this time, the entry at the top of the stack is {PC5, PC6}. Due to the first-in-last-out data storage format of the stack 50, the different branches of the branch instruction indicated by PC4 can be processed first, and then PC4 is incremented to obtain the third address parameter PC5 of the next instruction to be executed. The third address parameter is the same as the first-in-last-out data storage format of the stack 50. The first address parameter at the top of the stack is the same, which is PC5. The third address parameter is updated to PC6 at the top of the stack. The branch instruction processing unit 40 obtains the instruction indicated by PC6 for processing, increments PC6 to obtain the third address parameter PC7 of the next instruction to be executed, and the third address parameter is different from the first address parameter at the top of the stack. The instruction indicated by PC7 is obtained for processing, and the third address parameter PC5 of the next instruction is obtained according to the jump instruction indicated by PC7. The third address parameter is the same as the first address parameter at the top of the stack, indicating that after the subsequent execution branch is executed, {PC5, PC6} at the top of the stack is popped out. At this time, the entry at the top of the stack is {PC8, PC11}, and the different branch situations of the branch instruction indicated by PC1 are further processed to achieve efficient processing of nested branches.

[0125] In some embodiments, each thread further corresponds to a second flag bit, and the second flag bit is used to indicate whether the thread is running. Exemplarily, when the flag bit is a first preset value, it indicates that the thread does not run the instruction sequence; when the flag bit is a second preset value, it indicates that the thread runs the instruction sequence; the first preset value and the second preset value are different. In one example, one of the first preset value and the second preset value is 1, and the other is 0.

[0126] After executing the previously executed branch and the subsequently executed branch, multiple threads gather at the convergence instruction, and then synchronously execute the convergence instruction and its subsequent instructions. At this time, the second flag bit is needed to indicate the running thread to determine the thread that needs to execute the convergence instruction and its subsequent instructions. Therefore, it is also necessary to push the second flag bit into the top of the stack 50. In the case of determining that at least two of the multiple threads are used to execute different branches of the branch instruction, the entry including the first address parameter, the second address parameter, the first flag bit of each thread corresponding to the subsequently executed branch, and the second flag bit can be pushed into the top of the stack 50. The second flag bit is used to indicate the thread that needs to execute the convergence instruction and its subsequent instructions after the subsequent execution branch is executed. In other embodiments, considering that the first flag bit of each thread corresponding to the subsequently executed branch can be determined based on the second flag bit of the thread and the first flag bit of the thread corresponding to the previously executed branch. The second flag bit is used to indicate whether the thread is running. The first flag bit of a thread corresponding to the previously executed branch indicates whether the thread executes the branch. Then, threads that are not running and threads that have executed the previously executed branch can be excluded from multiple threads. The remaining threads are threads that need to execute the later executed branch, that is, the first flag bit of the thread corresponding to the later executed branch is determined. Therefore, in order to save the storage space of the stack 50, the first flag bit of each thread corresponding to the later executed branch may not be stored, that is, an entry pushed into the top of the stack 50 includes {the first address parameter, the second address parameter, and the second flag bit corresponding to each thread}. Subsequently, when the third address parameter of the next instruction is updated to the second address parameter in the top of the stack so that the first instruction of the subsequently executed branch is determined to be the next instruction, the first flag bit of each thread corresponding to the subsequently executed branch can be determined based on the second flag bit of the thread in the top of the stack and the first flag bit of the thread corresponding to the previously executed branch; wherein, since the branch instruction processing unit 40 is currently still executing instructions in the previously executed branch, the first flag bit of the thread corresponding to the previously executed branch is also known to the branch instruction processing unit 40.

[0127] In a possible implementation, the first flag bit of the thread corresponding to the later executed branch is obtained by inverting the first flag bit of the thread corresponding to the earlier executed branch, and then ANDing the inverted result with the second flag bit corresponding to the thread.

[0128] In one example, in the second flag bit, assuming that the flag bit is "1" to indicate that the thread executes the instruction sequence, and the flag bit is "0" to indicate that the thread does not execute the instruction sequence. Assuming that there are 4 threads (A, B, C, D), and all 4 threads are running, the second thread enable bit is "1111". In the first thread enable bit, assuming that the flag bit is "1" to indicate that the thread executes the transfer branch, and the flag bit is "0" to indicate that the thread executes the sequential execution branch. At this time, after judging the condition indicated by PC0, thread A, thread B and thread C are judged to be true, and the first flag bits corresponding to the branch instruction are all "1", and thread D is judged to be false, and the first flag bit corresponding to the branch instruction is "0", then the first flag bits of multiple threads corresponding to the branch instruction are "1110", assuming that the preset branch execution order is the first order, the later executed branch is a transfer branch, and the first flag bits of multiple threads corresponding to the later executed branch are "1110", which can be obtained based on bitwise inversion of the first flag bits "0001" corresponding to the first executed branch of multiple threads to obtain "1110", and then ANDed with the second flag bits "1111" corresponding to the multiple threads.

[0129] It should be noted that the “multiple threads” mentioned above can synchronously execute each instruction in the same instruction sequence.

[0130] In one embodiment, in order to expand the functionality of a SIMT processor, such as Figure 5 As shown, the number of the branch instruction processing units 40 and the number of the stacks 50 are both greater than 1, the SIMT processor may include one or more thread clusters, n is an integer greater than 0, each thread cluster includes multiple threads, and multiple threads in the same thread cluster can synchronously execute each instruction in the same instruction sequence. Each branch instruction processing unit 40 corresponds to a thread cluster in the SIMT processor, and each stack 50 corresponds to a thread cluster in the SIMT processor; the branch instruction processing unit 40 can perform the above-mentioned processing when there is disagreement in the execution of branch instructions by multiple threads in the corresponding thread cluster.

[0131] For example, see Figure 5 The SIMT processor also includes an instruction execution unit 60, which can be called by the thread to execute related instructions, and then store the execution results of the instructions in the memory 30; in an example, the instruction execution unit 60 includes an adder, a subtractor, a multiplier, a divider, an integral operation circuit or a logarithmic operation circuit, etc. The specific operation circuit and its number can be specifically set according to the actual application scenario, and this embodiment does not impose any limitation on this.

[0132] Exemplarily, in order to better execute the instruction sequence corresponding to each thread cluster, the SIMT processor also includes an instruction fetch unit corresponding to each thread cluster, and the instruction fetch unit is used to obtain instructions in the instruction sequence corresponding to the thread cluster from the instruction fetch component and send it to the branch instruction processing unit 40.

[0133] In some embodiments, considering that the stack 50 may overflow when branch instructions are nested in multiple layers, one or more shared memories 70 are set in the SIMT processor to deal with the overflow. Figure 6 In the figure, one shared memory 70 corresponds to n thread clusters, each of the shared memories 70 corresponds to at least two thread clusters, and different shared memories 70 correspond to different thread clusters. In one example, for example, multiple thread clusters can be divided into two groups, each group corresponding to a shared memory 70.

[0134] The stack 50 corresponds to a stack 50 pointer, and the stack 50 instruction includes a read pointer and a write pointer, the read pointer points to the top of the stack 50, and the write pointer = read pointer + 1. In the case of the stack 50 overflow, the branch instruction processing unit 40 can transfer at least one specified entry in the stack 50 to the shared memory 70 corresponding to the thread cluster, the specified entry is determined according to the write pointer, and the push time of the at least one specified entry is earlier than the push time of other entries that have not been transferred.

[0135] For an example, see Figure 7 , Figure 7 A stack 50 with 8 layers (8 storage units) is shown, each layer (each storage unit) is used to store an entry, reg0~reg7 indicates the storage address of each layer, at this time, there are 8 entries stored in the stack 50, the read pointer = 7, pointing to the top of the stack 50 (i.e., reg7), the write pointer = 8, pointing to reg0, it can be determined that the stack 50 is overflowing at this time, and the next entry cannot be pushed in. If the next entry is pushed in, the entry 1 stored in reg0 will be overwritten. Therefore, in order to save the entry 1 and ensure that the stack 50 can continue to push the next entry, at least one entry that needs to be transferred can be determined according to the write pointer, that is, the entry 1 stored in reg0, and the entry 1 stored in reg0 is stored in the shared memory 70. Of course, in order to avoid multiple transfer operations, at least two entries can be transferred at one time, for example, the four entries stored in reg0~reg3 can be transferred to the shared RAM at one time, thereby reducing the high-frequency multiple reads and writes to the shared memory 70, which is conducive to improving processing efficiency. It can be seen that the push time of the four entries stored in reg0 to reg3 is earlier than the push time of the other entries that have not been transferred.

[0136] In some embodiments, after the target entry is popped out of the stack 50, the at least one designated entry transferred to the shared memory 70 is written back to the stack 50; wherein, considering the deployment differences of different SIMT processors, the clock cycles required to read the at least one designated entry from the shared memory 70 are different. In one case, the at least one designated entry may be written back to the stack 50 in the next clock cycle after a read request is initiated to the shared memory 70. In another case, after a read request is initiated to the shared memory 70, it may be necessary to wait for at least one more clock cycle to complete the operation of writing the at least one designated entry back to the stack 50. In order to avoid the situation where all entries in the stack 50 are popped out but at least one designated entry stored in the shared memory 70 has not been written back, causing the branch instruction processing unit 40 to read the stack 50 empty, the storage location of the target entry in the stack 50 may be set to be adjacent to or different from the original storage location of the designated entry in the stack 50 by a preset number of storage units according to the actual application scenario. The specific value of the preset number is determined according to the clock cycle required to wait for writing back the at least one designated entry, so as to ensure efficient execution of the instruction sequence. In one example, please refer to Figure 8 , for example, the timing requirement in the SIMT processor is that the at least one specified entry transferred to the shared memory 70 will be moved to the read data bus only in the next clock cycle after a read request is initiated to the shared memory 70, and can be accurately written back to the stack 50 in the next clock cycle. After initiating a read request to the shared memory 70, it is necessary to wait for another clock cycle to complete the operation of writing the at least one specified entry back to the stack 50. The preset number is 1, for example, Figure 7 In the embodiment, the entries transferred to the shared memory 70 are entries 1 to 4, and their original storage addresses in the stack 50 are reg1 to reg4. After entry 6 is popped out of the stack 50, the storage position of entry 6 differs from the original storage position of entry 4 in the stack 50 by 1 storage unit. At this time, entries 1 to 4 transferred to the shared memory 70 can be moved back and written back to the stack 50, thereby avoiding the situation in which the branch instruction processing component needs to wait to read the stack 50 after entry 5 in the stack 50 is popped out, thereby improving the processing efficiency of the instruction sequence.

[0137] It is not difficult to understand that the solutions described in the above embodiments can be combined when there is no conflict, and they are not listed one by one in the embodiments of the present disclosure.

[0138] Accordingly, see Fig. 9The embodiment of the present disclosure also provides a branch instruction processing method, which is applied to a SIMT processor including a branch instruction processing unit and a stack, wherein multiple threads in the SIMT processor can synchronously execute instructions in the same instruction sequence, wherein the instruction sequence includes at least a branch instruction and a convergence instruction, wherein the branch instruction indicates multiple executable branches, and the multiple branches are aggregated at the convergence instruction. The method is executed by the branch instruction processing unit, and the method includes:

[0139] In step S101, when at least two of the multiple threads are used to execute different branches of the branch instruction, a first address parameter of a convergence instruction and a second address parameter of a first instruction of a later executed branch among the different branches are determined.

[0140] In step S102, an entry including the first address parameter and the second address parameter is pushed onto the top of the stack.

[0141] In step S103, during the execution of the branch instruction or the instructions in the previously executed branch, when the third address parameter of the next instruction to be executed is consistent with the first address parameter at the top of the stack, the third address parameter is updated to the second address parameter at the top of the stack, so that the first instruction of the subsequently executed branch is determined as the next instruction.

[0142] In some embodiments, it also includes: during the execution of an instruction that executes a branch later, when the third address parameter of the next instruction is consistent with the first address parameter at the top of the stack, popping an entry including the first address parameter and the second address parameter from the top of the stack.

[0143] In some embodiments, the multiple branches include transfer branches and sequential execution branches; the first instruction on the sequential execution branch is the instruction immediately following the branch instruction in the instruction sequence, and the transfer branch is the other branch among the multiple branches except the sequential execution branch; the address parameter of the first instruction on the sequential execution branch is obtained by incrementing the address parameter of the branch instruction; the address parameter of the first instruction on the transfer branch is specified by the branch instruction and is discontinuous with the address parameter of the branch instruction.

[0144] In some embodiments, it also includes: according to the judgment result of each thread on the judgment condition of the branch instruction, obtaining the first flag bit of each thread corresponding to the branch instruction, and the first flag bit of a thread corresponding to the branch instruction is used to indicate the next branch executed by the thread after executing the branch instruction.

[0145] In some embodiments, the multiple branches include transfer branches and sequential execution branches; the first instruction on the sequential execution branch is the instruction immediately following the branch instruction in the instruction sequence, and the transfer branch is the other branch among the multiple branches except the sequential execution branch; the first flag bit of a thread corresponding to the transfer branch is the same as the first flag bit corresponding to the branch instruction, and the first flag bit of a thread corresponding to the sequential transfer branch is obtained by inverting the first flag bit of the thread corresponding to the branch instruction.

[0146] In some embodiments, the entry further includes a first flag bit of each thread corresponding to the later executed branch.

[0147] In some embodiments, each thread also corresponds to a second flag bit, which is used to indicate whether the thread is running; the entry also includes a first flag bit and a second flag bit corresponding to the later executed branch of each thread; or the entry also includes a second flag bit of each thread; wherein, a first flag bit of a thread corresponding to the later executed branch is determined based on the second flag bit of the thread and the first flag bit of the thread corresponding to the earlier executed branch.

[0148] In some embodiments, the number of the branch instruction processing units and the number of the stacks are both greater than 1, each branch instruction processing unit corresponds to a thread cluster in the SIMT processor, and each stack corresponds to a thread cluster in the SIMT processor; wherein, multiple threads in the same thread cluster can synchronously execute each instruction in the same instruction sequence.

[0149] In some embodiments, the SIMT processor also includes one or more shared memories, each shared memory corresponds to at least two thread clusters, and different shared memories correspond to different thread clusters; the method also includes: before pushing the entry including the first address parameter and the second address parameter to the top of the stack, in the event of an overflow of the stack, transferring the specified entry in the stack to the shared memory corresponding to the thread cluster; wherein the specified entry is determined according to the write pointer of the stack, and the push time of the specified entry is earlier than the push time of other entries that have not been transferred.

[0150] In some embodiments, the method further includes: after popping the target entry from the stack, writing the specified entry back to the stack; wherein the storage position of the target entry in the stack is adjacent to or differs from the original storage position of the specified entry in the stack by a preset number of storage units, and each storage unit is used to store one entry.

[0151] In some embodiments, the multiple branches include transfer branches and sequential execution branches; the first instruction on the sequential execution branch is the instruction immediately following the branch instruction in the instruction sequence, and the transfer branch is the other branch among the multiple branches except the sequential execution branch; the method also includes: when the multiple threads are all used to execute the sequential execution branch indicated by the branch instruction, incrementing the address parameter of the branch instruction to obtain the address parameter of the next instruction to be executed; when the multiple threads are all used to execute the transfer branch indicated by the branch instruction, using the address parameter of the first instruction on the transfer branch as the address parameter of the next instruction to be executed.

[0152] In some embodiments, the method also includes: in the process of executing an instruction in a previously executed branch or the subsequently executed branch, when the current instruction is a branch instruction and there are at least two threads for executing different branches of the branch instruction, executing the step of determining a first address parameter and a second address parameter and pushing them into a stack to process the branch instruction nested in the previously executed branch or the subsequently executed branch.

[0153] In some embodiments, the later executed branch among the different branches is determined according to a preset branch execution order.

[0154] In some exemplary embodiments, see Fig.10 , Fig.10 Another flow chart of a branch instruction processing method is shown. The method can be executed by the branch instruction processing unit in the above-mentioned SIMT processor.

[0155] In step S201, it is determined whether the currently executed instruction is a branch instruction; if not, step S202 is executed; if so, step S203 is executed;

[0156] In step S202, the PC value of the currently executed instruction is incremented to obtain the PC value of the next instruction to be executed; wherein, after obtaining the next instruction according to the PC value of the next instruction, step S201 is repeated, that is, each instruction obtained needs to be determined whether it is a branch instruction.

[0157] In step S203, the branch to be executed is determined according to the first flag bit of each thread corresponding to the branch instruction;

[0158] In step S204, if multiple threads are used to execute the sequential execution branch indicated by the branch instruction, the PC value of the branch instruction is incremented to obtain the PC value of the next instruction to be executed; the PC value of the subsequent instruction is obtained by incrementing the PC value of the previous instruction;

[0159] In step S205, if multiple threads are used to execute the branch instruction indicating the transfer branch, the PC value of the first instruction located on the transfer branch is obtained as the PC value of the next instruction to be executed; the PC value of the subsequent instruction is obtained by incrementing the PC value of the previous instruction;

[0160] In step S206, if at least two of the multiple threads are used to execute different branches of the branch instruction (i.e., the first flag bits of at least two threads are different), it is determined whether the stack overflows, if so, step S207 is executed, if not, step S208 is executed;

[0161] In step S207, at least one designated entry in the stack is transferred to the shared memory corresponding to the thread cluster; at this time, the stack frees up space for pushing new entries.

[0162] In step S208, determine the first PC value of the converged instruction, the second PC value of the first instruction of the later executed branch among the different branches, and the second flag bit corresponding to each thread; push the entry including the first PC value, the second PC value and the second flag bit corresponding to each thread into the top of the stack;

[0163] In step S209, during the execution of the branch instruction or the previously executed instruction in the branch, it is determined whether the third PC value of the next instruction to be executed is consistent with the first PC value at the top of the stack; if so, step S210 is executed; if not, the third PC value remains unchanged, the next instruction is obtained using the third PC value, and step S209 is repeated;

[0164] In step S210, the third PC value is updated to the second PC value at the top of the stack, and the first flag bit of each thread corresponding to the later executed branch is determined according to the first flag bit of each thread at the top of the stack and the first flag bit corresponding to the previously executed branch;

[0165] In step S211, during the execution of the instruction of the subsequent execution branch, it is determined whether the third PC value of the next instruction to be executed is consistent with the first PC value at the top of the stack; if so, step S212 is executed; if not, the third PC value remains unchanged, the next instruction is obtained using the third PC value, and step S211 is repeated;

[0166] In step S212, an entry including the first PC value, the second PC value and the second flag bit corresponding to each thread is popped from the top of the stack;

[0167] In step S213, the convergence instruction is executed, and all threads converge.

[0168] It is not difficult to understand that the solutions described in the above embodiments can be combined when there is no conflict, and they are not listed one by one in the embodiments of the present disclosure.

[0169] Correspondingly, an embodiment of the present disclosure further provides a chip, including the above-mentioned SIMT processor.

[0170] Correspondingly, an embodiment of the present disclosure further provides a board comprising the above-mentioned chip.

[0171] For example, see Fig.11 , which provides an exemplary board card, the board card includes a packaging structure encapsulating at least one of the above chips 100, and may also include other components, including but not limited to: a memory 102 and an interface device 104.

[0172] The memory 102 is connected to the chip in the chip package structure via a bus for storing data. The memory 102 may include multiple groups of storage units 106, such as DDR SDRAM (English: Double Data Rate SDRAM, double rate synchronous dynamic random access memory), etc. Each group of storage units 106 is connected to the chip 100 via a bus.

[0173] The interface device 104 is electrically connected to the chip in the chip packaging structure. The interface device 104 is used to realize data transmission between the chip and an external device 108 (for example, a terminal, a server, a camera, etc.). In one embodiment, the interface device 104 may include a PCIE interface, or a network interface, or other interfaces, which are not limited in the present disclosure.

[0174] Accordingly, the embodiment of the present disclosure further provides an electronic device, including the above-mentioned SIMT processor, or the above-mentioned chip, or the above-mentioned board. The specific functions of the SIMT processor, chip and board can refer to the description of the above embodiment, which will not be repeated here.

[0175] The present disclosure also provides a computer-readable storage medium on which computer instructions are stored. When the computer instructions are executed by a processor, the method described in any of the above embodiments is implemented.

[0176] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.

[0177] It can be known from the description of the above implementation methods that those skilled in the art can clearly understand that the embodiments of the present disclosure can be implemented by means of software plus a necessary general hardware platform. Based on such an understanding, the technical solution of the embodiments of the present disclosure is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which can be stored in a storage medium such as ROM / RAM, a disk, an optical disk, etc., including several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present disclosure or some parts of the embodiments.

[0178] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, a game console, a tablet computer, a wearable device or a combination of any of these devices.

[0179] Each embodiment in this specification is described in a progressive manner, and the same and similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment. The device embodiment described above is merely illustrative, wherein the modules described as separate components may or may not be physically separated, and the functions of each module can be implemented in the same one or more software and / or hardware when implementing the embodiment of the present disclosure. It is also possible to select some or all of the modules according to actual needs to achieve the purpose of the embodiment. A person of ordinary skill in the art can understand and implement it without paying creative labor.

[0180] The above is only a specific implementation of the embodiment of the present disclosure. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the embodiment of the present disclosure. These improvements and modifications should also be regarded as the protection scope of the embodiment of the present disclosure.

Claims

1. A SIMT processor, characterized in that: It includes a branch instruction processing unit and a stack; multiple threads in the SIMT processor can synchronously execute various instructions in the same instruction sequence, the instruction sequence includes at least a branch instruction and a convergence instruction, the branch instruction indicates multiple executable branches, and the multiple branches are gathered at the convergence instruction; The branch instruction processing unit is used for: In case at least two of the plurality of threads are used to execute different branches of the branch instruction, determining a first address parameter of a convergence instruction and a second address parameter of a first instruction of a later executed branch in the different branches; Pushing an entry including the first address parameter and the second address parameter onto the top of the stack; In the process of executing the branch instruction or the instructions in the previously executed branch, when the third address parameter of the next instruction to be executed is consistent with the first address parameter at the top of the stack, the third address parameter is updated to the second address parameter at the top of the stack, so that the first instruction of the subsequently executed branch is determined as the next instruction.

2. The SIMT processor according to claim 1, characterized in that: The branch instruction processing unit is also used for: During the execution of the instruction for executing a branch later, when the third address parameter of the next instruction is consistent with the first address parameter of the top of the stack, an entry including the first address parameter and the second address parameter is popped from the top of the stack.

3. The SIMT processor according to claim 1 or 2, characterized in that: The multiple branches include transfer branches and sequential execution branches; The first instruction on the sequential execution branch is the instruction immediately following the branch instruction in the instruction sequence, and the transfer branch is the other branch among the multiple branches except the sequential execution branch; The address parameter of the first instruction on the sequential execution branch is obtained by incrementing the address parameter of the branch instruction; The address parameter of the first instruction on the branch is specified by the branch instruction and is not continuous with the address parameter of the branch instruction.

4. The SIMT processor according to any one of claims 1 to 3, characterized in that: The branch instruction processing unit is also used for: According to the judgment result of each thread on the judgment condition of the branch instruction, the first flag bit of each thread corresponding to the branch instruction is obtained. The first flag bit of a thread corresponding to the branch instruction is used to indicate the next branch executed by the thread after executing the branch instruction.

5. The SIMT processor according to claim 4, characterized in that: The multiple branches include transfer branches and sequential execution branches; the first instruction on the sequential execution branch is the instruction immediately following the branch instruction in the instruction sequence, and the transfer branch is the other branch among the multiple branches except the sequential execution branch; The first flag bit of a thread corresponding to the transfer branch is the same as the first flag bit corresponding to the branch instruction, and the first flag bit of a thread corresponding to the sequential transfer branch is obtained by inverting the first flag bit of the thread corresponding to the branch instruction.

6. The SIMT processor according to claim 5, characterized in that: The entry also includes a first flag bit of each thread corresponding to the later executed branch.

7. The SIMT processor according to claim 5, characterized in that: Each thread also corresponds to a second flag bit, which is used to indicate whether the thread is running; The entry further includes a first flag bit and a second flag bit corresponding to the later-executed branch of each thread; or The entry also includes a second flag bit of each thread; wherein a first flag bit of a thread corresponding to the later-executed branch is determined based on the second flag bit of the thread and the first flag bit of the thread corresponding to the earlier-executed branch.

8. The SIMT processor according to any one of claims 1 to 7, characterized in that: The number of the branch instruction processing units and the number of the stacks are both greater than 1, each branch instruction processing unit corresponds to a thread cluster in the SIMT processor, and each stack corresponds to a thread cluster in the SIMT processor; Among them, multiple threads in the same thread cluster can synchronously execute each instruction in the same instruction sequence.

9. The SIMT processor according to claim 8, characterized in that: The SIMT processor further includes one or more shared memories, each shared memory corresponds to at least two thread clusters, and different shared memories correspond to different thread clusters; The branch instruction processing unit is also used for: In the event of stack overflow, a designated entry in the stack is transferred to a shared memory corresponding to the thread cluster; wherein the designated entry is determined according to a write pointer of the stack, and a push time of the designated entry is earlier than a push time of other entries that have not been transferred.

10. The SIMT processor according to claim 9, characterized in that: The branch instruction processing unit is also used for: After the target entry is popped out of the stack, the designated entry is written back to the stack; wherein the storage position of the target entry in the stack is adjacent to or differs from the original storage position of the designated entry in the stack by a preset number of storage units, and each storage unit is used to store one entry.

11. The SIMT processor according to any one of claims 1 to 10, characterized in that: The multiple branches include transfer branches and sequential execution branches; the first instruction on the sequential execution branch is the instruction immediately following the branch instruction in the instruction sequence, and the transfer branch is the other branch among the multiple branches except the sequential execution branch; The branch instruction processing unit is also used for: In a case where the plurality of threads are all used to execute the sequential execution branches indicated by the branch instruction, incrementing the address parameter of the branch instruction to obtain the address parameter of the next instruction to be executed; In the case that the multiple threads are all used to execute the branch indicated by the branch instruction, the address parameter of the first instruction on the branch is used as the address parameter of the next instruction to be executed.

12. The SIMT processor according to any one of claims 1 to 11, characterized in that: The branch instruction processing unit is also used for: In the process of executing an instruction in a previously executed branch or the subsequently executed branch, when the current instruction is a branch instruction and there are at least two threads for executing different branches of the branch instruction, the steps of determining a first address parameter and a second address parameter and pushing them into a stack are performed to process the branch instruction nested in the previously executed branch or the subsequently executed branch.

13. The SIMT processor according to any one of claims 1 to 12, characterized in that: The later executed branch among the different branches is determined according to a preset branch execution sequence.

14. A branch instruction processing method, characterized in that: Applied to a SIMT processor including a branch instruction processing unit and a stack, multiple threads in the SIMT processor can synchronously execute various instructions in the same instruction sequence, the instruction sequence at least including a branch instruction and a convergence instruction, the branch instruction indicates multiple executable branches, and the multiple branches are gathered at the convergence instruction; the method comprises: In case at least two of the plurality of threads are used to execute different branches of the branch instruction, determining a first address parameter of a convergence instruction and a second address parameter of a first instruction of a later executed branch in the different branches; Pushing an entry including the first address parameter and the second address parameter onto the top of the stack; In the process of executing the branch instruction or the instructions in the previously executed branch, when the third address parameter of the next instruction to be executed is consistent with the first address parameter at the top of the stack, the third address parameter is updated to the second address parameter at the top of the stack, so that the first instruction of the subsequently executed branch is determined as the next instruction.

15. A chip, characterized in that: Comprising a SIMT processor as claimed in any one of claims 1 to 13.

16. A board, characterized in that: A package structure comprising at least one chip as claimed in claim 15 is encapsulated.

17. An electronic device, characterized in that: It comprises the SIMT processor as claimed in any one of claims 1 to 13, or the chip as claimed in claim 15, or the board as claimed in claim 16.

18. A computer-readable storage medium having computer instructions stored thereon, characterized in that: When the computer instructions are executed by a processor, the steps of the method of claim 14 are implemented.