Instruction execution method and device, computer equipment, storage medium and computer program product
By alternately using different general registers between even and odd thread bundles for source operand reading and writing, the problem of register read and write in thread bundle is solved, reducing the insertion of NOP instructions and improving execution efficiency and support for instruction complexity.
Patent Information
- Application Number
- CN202411163866.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-22
- Publication Date
- 2024-12-03
AI Technical Summary
In a general-purpose graphics processor, the two instructions in the same thread bundle often have general-purpose register read and write conflict problems, resulting in the need to insert multiple NOP instructions to resolve the conflict, thereby reducing execution efficiency.
By receiving instructions transmitted by the thread beam control module at each even clock cycle, and obtaining the source operand from the first general register when the even thread beam, and obtaining the source operand from the second general register when the odd thread beam, storing the purpose operation The numbers are in the corresponding registers respectively to reduce the number of insertions of NOP instructions.
This method reduces the number of NOP instructions, expands the clock cycle between instruction execution, thereby improving execution efficiency, supporting instructions with multiple source operands, and improving read and write conflict problems in general registers.
Smart Images

Figure CN119067831A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of general-purpose graphics processors, and in particular to an instruction execution method, apparatus, computer equipment, storage medium, and computer program product. Background Art
[0002] In a general-purpose graphics processor, the computing unit is the core module of the entire processor, and the thread control module is the key to reasonably scheduling and controlling the computing unit to work effectively. On mainstream drawing platforms such as D3D, OpenGL, and Vulkan, various programmable shaders are the most important and time-consuming links in graphics rendering. These shaders include vertex shaders (VS), pixel shaders (PS), hull shaders (HS), and domain shaders (DS). Among these shaders, in addition to texture sampling instructions and memory read and write instructions, the largest proportion is computing instructions, so the execution efficiency of computing instructions is particularly important in general-purpose graphics processors.
[0003] In general-purpose processors, the two instructions before and after the same thread warp often have a general register read / write conflict. To solve this problem, the compiler needs to insert a NOP instruction between the two instructions. Since the WVC (WaveController, thread warp control module) sends an instruction to each SET in each even clock cycle, and each SET reads and writes the same set of CRF (common register file, general registers), the delay between the two instructions of the same thread warp is only two clock cycles, which will result in the need to insert more NOP instructions to solve the register read / write conflict problem, resulting in reduced execution efficiency. Summary of the invention
[0004] Based on this, it is necessary to provide an instruction execution method, apparatus, computer device, computer-readable storage medium and computer program product that can improve execution efficiency in response to the above technical problems.
[0005] In a first aspect, the present application provides an instruction execution method, applied to an arithmetic logic unit, the method comprising:
[0006] In each even-numbered clock cycle, receiving an instruction issued by a thread warp control module, wherein two instructions received in consecutive even-numbered clock cycles belong to an even-numbered thread warp and an odd-numbered thread warp respectively;
[0007] When the instruction belongs to an even warp, obtaining a source operand from a first general register, and when the instruction belongs to an odd warp, obtaining a source operand from a second general register;
[0008] The instruction is executed based on the source operand.
[0009] In one embodiment, after executing the instruction based on the source operand, the method further comprises:
[0010] Perform instruction operation based on the source operand to obtain a destination operand;
[0011] When the instruction belongs to an even warp, storing the destination operand in a first general register,
[0012] When the instruction belongs to an odd warp, the destination operand is stored in a second general register.
[0013] In one embodiment, the number of warps is a power of two.
[0014] In a second aspect, the present application further provides an instruction execution method, which is applied to a thread warp control module, and the method includes:
[0015] In each even clock cycle, an instruction is issued to the arithmetic logic unit of each instruction execution module group, and the two instructions issued to the same instruction execution module group in consecutive even clock cycles belong to the even thread warp and the odd thread warp respectively; when the instruction belongs to the even thread warp, the source operand is stored in the first general register of the instruction execution module group, and when the instruction belongs to the odd thread warp, the source operand is stored in the second general register of the instruction execution module group.
[0016] In one embodiment, before sending an instruction to the arithmetic logic unit of each instruction execution module group in each even clock cycle, the method includes:
[0017] Instructions are cyclically obtained from the instruction cache module based on the number of the instruction execution module groups, and one instruction is obtained in each clock cycle. The instructions obtained from the instruction cache module in adjacent clock cycles belong to different instruction execution module groups.
[0018] In a third aspect, the present application further provides an instruction execution device, the device comprising:
[0019] A thread warp control module, for issuing instructions to the arithmetic logic unit in every even clock cycle;
[0020] A first general register, used to store source operands of instructions corresponding to even-numbered warps;
[0021] A second general register, used to store source operands of instructions corresponding to odd-numbered warps;
[0022] An arithmetic logic unit is used to execute the above instruction execution method to execute the instructions issued by the thread warp control module.
[0023] In one embodiment, the device further comprises:
[0024] An instruction cache module, used to store instructions;
[0025] The thread warp control module is also used to cyclically obtain instructions from the instruction cache module based on the number of instruction execution module groups corresponding to the arithmetic logic unit, and obtain one instruction per clock cycle, and the instructions obtained from the instruction cache module in adjacent clock cycles belong to different instruction execution module groups.
[0026] In a fourth aspect, the present application further provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the above method when executing the computer program.
[0027] In a sixth aspect, the present application also provides a computer program product, including a computer program, which implements the steps of the above method when executed by a processor.
[0028] The above-mentioned instruction execution method, device, computer equipment, storage medium and computer program product receive instructions sent by the thread bundle control module in each even clock cycle, and the two instructions received in consecutive even clock cycles belong to the even thread bundle and the odd thread bundle respectively, and when the instruction belongs to the even thread bundle, the source operand is obtained from the first general register, and when the instruction belongs to the odd thread bundle, the source operand is obtained from the second general register, so that the source operands are stored in different general registers respectively, and the two instructions received in consecutive even clock cycles belong to the even thread bundle and the odd thread bundle respectively, so that there is an execution of the instruction of the odd thread bundle between the execution of the instructions of the two even thread bundles, which can extend the clock cycle between the execution of the instructions of the two even thread bundles, thereby reducing the number of inserted NOP instructions. Similarly, for the odd thread bundle, the number of inserted NOP instructions can also be reduced, thereby improving the execution efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the drawings required for use in the embodiments or the related technical descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0030] FIG1 is a working block diagram of a conventional thread warp control module;
[0031] FIG2 is a block diagram of an instruction execution device in one embodiment;
[0032] FIG3 is a clock diagram of an instruction execution process in one embodiment;
[0033] FIG4 is a schematic diagram of a flow chart of an instruction execution method in one embodiment;
[0034] FIG5 is a schematic flow chart of an instruction execution method in another embodiment;
[0035] FIG6 is a clock diagram of thread warp instruction execution in conventional technology;
[0036] FIG7 is a clock diagram of alternate execution of even and odd warp instructions in one embodiment;
[0037] FIG8 is a schematic diagram of a general register read-write conflict in one embodiment;
[0038] FIG9 is a schematic diagram of a general register read-write conflict in another embodiment;
[0039] FIG10 is a clock diagram of the execution of instructions with dependencies in the conventional technology;
[0040] FIG11 is a schematic diagram of a general register read-write conflict in yet another embodiment;
[0041] FIG12 is a clock diagram of the execution of instructions with dependencies in one embodiment;
[0042] FIG. 13 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0043] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0044] The working block diagram of the traditional wave controller (WVC) is shown in Figure 1. Each WVC corresponds to two arithmetic logic units (ALUs), and each ALU corresponds to a set of common register files (CRFs). In addition, an instruction cache (IC) is configured for the wave controller. The WVC sends the address of the instruction to be executed by the wave to the IC. The IC takes the instruction from the buffer or memory according to the instruction address and sends it to the WVC.
[0045] The existing thread warp instruction issuance method has the following two shortcomings:
[0046] Since only one CRF is configured for each ALU, when the ALU and CRF operate at the same frequency, the ALU can only read one source operand from the CRF in each clock cycle, which will cause the instruction to not support multiple source operands.
[0047] In general-purpose processors, the two instructions before and after the same thread warp often have general register read and write conflicts. To solve this problem, the compiler needs to insert NOP instructions between the two instructions. Since WVC sends an instruction to each SET in each even clock cycle, and each SET reads and writes the same set of CRFs, the delay between the two instructions in the same thread warp is only two clock cycles, which will result in the need to insert more NOP instructions to solve the register read and write conflicts.
[0048] The instruction execution method provided in the embodiment of the present application can be applied in the application environment shown in Figure 2. It mainly involves a thread warp control module, an instruction cache module, a general register module and an arithmetic logic unit.
[0049] The instruction cache module (IC) is responsible for storing a certain number of instructions. When the instruction cache module receives an instruction fetch request from the thread bundle control module, the instruction cache module first queries from the internal cache. If the instruction requested by the thread bundle control module is found, it returns immediately. Otherwise, the instruction requested by the thread bundle control module is read from the external memory, stored in the internal cache, and sent to the thread bundle control module.
[0050] The Wave Controller (WVC) is responsible for the instruction scheduling and execution of a certain number of thread bundles. The number of thread bundles is generally a power of 2, and 32 is used as an example in this application. The thread bundle control module is mainly responsible for fetching instructions from the instruction cache module and sending instructions to the arithmetic logic unit.
[0051] The arithmetic logic unit (ALU) is responsible for receiving instructions sent by the thread warp control module, reading source operands from the general register module, executing instructions, and finally writing the instruction execution results to the general register module.
[0052] Common Register File (CRF): responsible for storing the source and destination operands of instructions.
[0053] Among them, in this application, two groups of general registers are set for each arithmetic logic unit, namely the first general register CRF0 and the second general register CRF1. The two groups of general registers and the arithmetic logic unit constitute an instruction execution module group SET. Each thread bundle control module is responsible for managing 32 thread bundles, and each thread bundle has a corresponding index number, which is 0~31. Thread bundle instructions with index numbers 0~15 are sent to the first instruction execution module group SET0 for execution; thread bundles with index numbers 16~31 are sent to the second instruction execution module group SET1 for execution. Here, only 32 thread bundles are used as an example to illustrate the content of this application, which is not limited to 32, and is generally a power of 2. At the same time, the number of instruction execution module groups SET is not fixed, and can be 2, 4 or 8, etc. This application takes 2 as an example.
[0054] For each instruction execution module group SET, when the arithmetic logic unit receives an instruction for a thread bundle with an even index number, the arithmetic logic unit reads the source operand from the first general register CRF0 and writes the instruction execution result into the first general register CRF0; similarly, when the arithmetic logic unit receives an instruction for a thread bundle with an odd index number, the arithmetic logic unit reads the source operand from the second general register CRF1 and writes the instruction execution result into the second general register CRF1.
[0055] For ease of understanding, FIG3 is a clock diagram of an instruction execution process in an embodiment. In this embodiment, the thread warp control module sends an instruction to the arithmetic logic unit, and the arithmetic logic unit will execute it twice in a loop, but the source operands read in these two times are different, and the positions of the general registers written to the instruction execution results are also different; in this embodiment, these two executions are called low and high, and each group of general registers is divided into low bank and high bank. Therefore, as shown in FIG3, the thread warp control module will only send instructions at even clocks, and the execution of each instruction requires 9 clock cycles, namely, fetching instructions (FTH), decoding (DEC), reading the first source operand (RD0), reading the second source operand (RD1), reading the third source operand (RD2), calculating the first part (EX0), calculating the second part (EX1), calculating the third part (EX2), and writing the destination operand (WB).
[0056] In an exemplary embodiment, as shown in FIG4 , an instruction execution method is provided, and the method is applied to the arithmetic logic unit in FIG2 as an example for description, including the following steps 402 to 406. Among them:
[0057] S402: In each even-numbered clock cycle, an instruction issued by a warp control module is received, and two instructions received in consecutive even-numbered clock cycles belong to an even-numbered warp and an odd-numbered warp respectively.
[0058] The clock cycle is the working cycle of the thread bundle control module, and each clock cycle triggers the thread bundle to perform the corresponding work. In this application, each clock cycle is numbered, starting with the 0th clock cycle and increasing backward in chronological order, so that the clock cycle can be divided into an even clock cycle and an odd clock cycle. Optionally, in this application, the instructions emitted by the thread bundle control module are received in each even clock cycle. It should be noted that the even clock cycle is because it starts with the 0th clock cycle. If it starts with the 1st clock cycle, the instructions emitted by the thread bundle control module can also be received in each odd clock cycle. In other embodiments, it may also be unrelated to the number of the starting clock cycle, and no specific limitation is made here. Those skilled in the art will know that the even clock cycle here does not limit this application, but is only for illustrating that the instructions emitted by the thread bundle control module are received every two cycles.
[0059] The thread warp is scheduled and executed by the thread warp control module. The thread warp of the present application is described by taking 32 thread warps as an example. In other embodiments, the number of thread warps can be other. However, optionally, the number of thread warps is a power of two.
[0060] In addition, the instruction execution module group in the present application optionally includes an arithmetic logic unit, a first general register, and a second general register. The present application does not impose specific restrictions on the number of instruction execution module groups, which may be 2, 4, or 8, etc. The present application takes 2 as an example for illustration. In each clock cycle, the thread bundle control module requests an instruction from the instruction cache module, and the two instructions requested in two consecutive clock cycles must belong to wave0~15 and wave16~31 respectively. Wave0~15 represents the 0th to 15th thread bundles, and wave16~31 represents the 16th to 31st thread bundles. The instructions of wave0~15 must be emitted to the first instruction execution module group SET0, and the instructions of wave16~31 must be emitted to the second instruction execution module group SET1. In other embodiments, if the number of instruction execution module groups is 4, wave0~7 instructions must be issued to the first instruction execution module group SET0, wave8~15 instructions must be issued to the second instruction execution module group SET1, wave16~23 instructions must be issued to the third instruction execution module group SET2, and wave24~31 instructions must be issued to the fourth instruction execution module group SET3.
[0061] For ease of understanding, as shown in FIG3, in each even clock cycle, the warp control module simultaneously sends an instruction to the first instruction execution module group SET0 and the second instruction execution module group SET1. The two instructions sent by the warp control module to the same instruction execution module group SET in two consecutive even clock cycles must belong to an even warp and an odd warp. An even warp indicates that the index number of the warp is an even number, and an odd warp indicates that the index number of the warp is an odd number. As shown in Figure 3, in the first even clock cycle cycle0, instr0 of the even thread bundle wave0 is emitted, in the second even clock cycle cycle2, instr0 of the odd thread bundle wave1 is emitted, in the third even clock cycle cycle4, instr1 of the even thread bundle wave0 (it can also be instructions of even thread bundles such as wave2, wave4, wave6), and instr1 of the odd thread bundle wave1 (it can also be instructions of odd thread bundles such as wave3, wave5, wave7), etc. is emitted in the fourth even clock cycle cycle6, and so on. The thread bundle control module alternately emits instructions of even and odd thread bundles to the instruction execution module group SET.
[0062] S404: When the instruction belongs to an even warp, obtain the source operand from the first general register; when the instruction belongs to an odd warp, obtain the source operand from the second general register.
[0063] In this embodiment, the arithmetic logic unit receives the thread warp instruction issued by the thread warp control module, and issues a read source operand request to the corresponding general register according to the thread warp index number. When the index number is an even number, the read request is issued to the first general register CRF0; when the index number is an odd number, the read request is issued to the second general register CRF1.
[0064] S406: Execute the instruction based on the source operand.
[0065] The arithmetic logic unit receives the source operand returned by the general register module and then performs the corresponding operation according to the instruction opcode.
[0066] In one of the optional embodiments, after executing the instruction based on the source operand, it includes: performing instruction operation based on the source operand to obtain a destination operand; when the instruction belongs to an even thread warp, storing the destination operand in a first general register, and when the instruction belongs to an odd thread warp, storing the destination operand in a second general register.
[0067] The arithmetic logic unit receives the source operand returned by the general register module CRF, then performs the corresponding operation according to the instruction opcode, and writes the operation result to the corresponding general register module CRF. Similarly, for the read request of the general register module CRF, the write request issued by the arithmetic logic unit is also sent to the corresponding general register module CRF according to the index number of the thread warp; the write request of the even thread warp is sent to the first general register CRF0, and the write request of the odd thread warp is sent to the second general register CRF1.
[0068] The above instruction execution method receives instructions issued by the thread bundle control module in each even clock cycle, and the two instructions received in consecutive even clock cycles belong to the even thread bundle and the odd thread bundle respectively, and when the instruction belongs to the even thread bundle, the source operand is obtained from the first general register, and when the instruction belongs to the odd thread bundle, the source operand is obtained from the second general register, so that the source operands are stored in different general registers respectively, and the two instructions received in consecutive even clock cycles belong to the even thread bundle and the odd thread bundle respectively, so that for the execution of the instructions of the odd thread bundle between the execution of the instructions of the two even thread bundles, the clock cycle between the execution of the instructions of the two even thread bundles can be extended, thereby reducing the number of inserted NOP instructions. Similarly, for the odd thread bundle, the number of inserted NOP instructions can also be reduced, thereby improving the execution efficiency.
[0069] In an exemplary embodiment, as shown in FIG5 , an instruction execution method is provided, and the method is applied to the thread warp control module in FIG2 as an example for description, and includes the following steps 502 . Among them:
[0070] S502: In each even clock cycle, an instruction is issued to the arithmetic logic unit of each instruction execution module group, and the two instructions issued to the same instruction execution module group in consecutive even clock cycles belong to the even thread bundle and the odd thread bundle respectively; when the instruction belongs to the even thread bundle, the source operand is stored in the first general register of the instruction execution module group, and when the instruction belongs to the odd thread bundle, the source operand is stored in the second general register of the instruction execution module group.
[0071] The clock cycle is the working cycle of the thread bundle control module, and each clock cycle triggers the thread bundle to perform the corresponding work. In this application, each clock cycle is numbered, starting with the 0th clock cycle and increasing backward in chronological order, so that the clock cycle can be divided into an even clock cycle and an odd clock cycle. Optionally, in this application, the instructions emitted by the thread bundle control module are received in each even clock cycle. It should be noted that the even clock cycle is because it starts with the 0th clock cycle. If it starts with the 1st clock cycle, the instructions emitted by the thread bundle control module can also be received in each odd clock cycle. In other embodiments, it may also be unrelated to the number of the starting clock cycle, and no specific limitation is made here. Those skilled in the art will know that the even clock cycle here does not limit this application, but is only for illustrating that the instructions emitted by the thread bundle control module are received every two cycles.
[0072] The thread warp is scheduled and executed by the thread warp control module. The thread warp of the present application is described by taking 32 thread warps as an example. In other embodiments, the number of thread warps can be other. However, optionally, the number of thread warps is a power of two.
[0073] In addition, the instruction execution module group in the present application optionally includes an arithmetic logic unit, a first general register, and a second general register. The present application does not impose specific restrictions on the number of instruction execution module groups, which may be 2, 4, or 8, etc. The present application takes 2 as an example for illustration. In each clock cycle, the thread bundle control module requests an instruction from the instruction cache module, and the two instructions requested in two consecutive clock cycles must belong to wave0~15 and wave16~31 respectively. Wave0~15 represents the 0th to 15th thread bundles, and wave16~31 represents the 16th to 31st thread bundles. The instructions of wave0~15 must be emitted to the first instruction execution module group SET0, and the instructions of wave16~31 must be emitted to the second instruction execution module group SET1. In other embodiments, if the number of instruction execution module groups is 4, the instructions of wave0~7 must be issued to the first instruction execution module group SET0, the instructions of wave8~15 must be issued to the second instruction execution module group SET1, the instructions of wave16~23 must be issued to the third instruction execution module group SET2, and the instructions of wave24~31 must be issued to the fourth instruction execution module group SET3.
[0074] For ease of understanding, as shown in FIG3, in each even clock cycle, the warp control module simultaneously sends an instruction to the first instruction execution module group SET0 and the second instruction execution module group SET1. The warp control module sends two instructions to the same combination SET in two consecutive even clock cycles, one of which must belong to an even warp and the other to an odd warp. An even warp indicates that the index number of the warp is an even number, and an odd warp indicates that the index number of the warp is an odd number. As shown in Figure 3, in the first even clock cycle cycle0, instr0 of the even thread bundle wave0 is emitted, in the second even clock cycle cycle2, instr0 of the odd thread bundle wave1 is emitted, in the third even clock cycle cycle4, instr1 of the even thread bundle wave0 (it can also be instructions of even thread bundles such as wave2, wave4, wave6), and instr1 of the odd thread bundle wave1 (it can also be instructions of odd thread bundles such as wave3, wave5, wave7), etc. is emitted in the fourth even clock cycle cycle6, and so on. The thread bundle control module alternately emits instructions of even and odd thread bundles to the instruction execution module group SET.
[0075] In this embodiment, the arithmetic logic unit receives the thread warp instruction issued by the thread warp control module, and issues a read source operand request to the corresponding general register according to the thread warp index number. When the index number is an even number, the read request is issued to the first general register CRF0; when the index number is an odd number, the read request is issued to the second general register CRF1.
[0076] The above instruction execution method receives instructions issued by the thread bundle control module in each even clock cycle, and the two instructions received in consecutive even clock cycles belong to the even thread bundle and the odd thread bundle respectively, and when the instruction belongs to the even thread bundle, the source operand is obtained from the first general register, and when the instruction belongs to the odd thread bundle, the source operand is obtained from the second general register, so that the source operands are stored in different general registers respectively, and the two instructions received in consecutive even clock cycles belong to the even thread bundle and the odd thread bundle respectively, so that for the execution of the instructions of the odd thread bundle between the execution of the instructions of the two even thread bundles, the clock cycle between the execution of the instructions of the two even thread bundles can be extended, thereby reducing the number of inserted NOP instructions. Similarly, for the odd thread bundle, the number of inserted NOP instructions can also be reduced, thereby improving the execution efficiency.
[0077] In one of the optional embodiments, before sending an instruction to the arithmetic logic unit of each instruction execution module group in each even clock cycle, it includes: cyclically obtaining instructions from the instruction cache module based on the number of instruction execution module groups, and obtaining one instruction in each clock cycle, and the instructions obtained from the instruction cache module in adjacent clock cycles belong to different instruction execution module groups.
[0078] Optionally, the instruction execution module group in the present application includes an arithmetic logic unit, a first general register, and a second general register. The present application does not specifically limit the number of instruction execution module groups, which may be 2, 4, or 8, etc. The present application takes 2 as an example for illustration. In this embodiment, the thread warp control module requests an instruction from the instruction cache module in each clock cycle, and the two instructions requested in two consecutive clock cycles must belong to wave0~15 and wave16~31 respectively.
[0079] In other embodiments, if the number of instruction execution module groups is 4, the warp control module requests an instruction from the instruction cache module in each clock cycle, and the four instructions requested in four consecutive clock cycles belong to wave0-7, wave8-15, wave16-23 and wave24-31 respectively.
[0080] Therefore, in the present application, the number of instruction execution module groups can be determined first to control the loop, and then the instructions corresponding to each instruction execution module group can be obtained from the instruction cache module in sequence, with one instruction being obtained in each clock cycle.
[0081] In the above embodiment, the alternating execution of even and odd warp instructions can not only support instructions with multiple operands, but also improve the read-write conflict problem of general registers.
[0082] Specifically, as shown in Figure 6, Figure 6 is a clock diagram of thread bundle instruction execution in traditional technology. The thread bundle control module sends an instruction to each instruction execution module group SET every two clock cycles. Since there is no alternating transmission of odd and even thread bundles, and each instruction execution module group SET has only one set of general registers CRF, all instructions sent to the same instruction execution module group SET access the same set of general registers CRF.
[0083] Taking the instruction in Figure 6 as an example, instr0 has three source operands. The arithmetic logic unit reads the first source operand R0 and the second source operand R1 of instr0 in cycle2 and cycle3, and the arithmetic logic unit reads the first source operand R4 and the second source operand R5 of instr1 in cycle4 and cycle5. The third source operand R2 of instr0 needs to be read in cycle4, which will conflict with the reading of the first source operand R4 of instr1, so the existing thread bundle instruction issuance method cannot support instructions with three or more source operands.
[0084] As shown in FIG. 7 , FIG. 7 is a clock diagram of alternate execution of even and odd thread bundle instructions in one embodiment. In this embodiment, the thread bundle control module transmits an instruction of an even thread bundle to each instruction execution module group SET every 4 clock cycles. Similarly, an instruction of an odd thread bundle is transmitted to each instruction execution module group SET every 4 clock cycles. Two instructions transmitted in consecutive even clock cycles (such as cycle0 and cycle2) must belong to one even thread bundle and one odd thread bundle. Since even and odd thread bundles access the first general register CRF0 and the second general register CRF1 respectively, there is no general register CRF read conflict between even and odd thread bundles.
[0085] Taking the emission method of even-numbered thread bundle instructions as an example, the arithmetic logic unit reads the first, second and third source operands of wave0 instr0 from the first general register CRF0 in cycle2, cycle3 and cycle4, and reads the first, second and third source operands of wave0 instr1 from the first general register CRF0 in cycle6, cycle7 and cycle8. There is no conflict in reading operands between wave0 instr0 and wave0 instr1.
[0086] Similarly, taking the emission method of odd-numbered thread bundle instructions as an example, the arithmetic logic unit reads the first, second and third source operands of wave1 instr0 from the second general register CRF1 in cycle4, cycle5 and cycle6, and reads the first, second and third source operands of wave1 instr1 from the second general register CRF1 in cycle8, cycle9 and cycle10. It can be seen that there is no conflict in reading operands between wave1 instr0 and wave1 instr1.
[0087] Therefore, the method of alternating execution of even and odd warps can support instructions with 3 or even 4 source operands.
[0088] In general-purpose processors, there will always be a read-write conflict problem of the general register CRF. Taking the instruction in Figure 8 as an example, assuming that the source operand R2 of the instr1 MUL instruction comes from the destination operand of the instr0 ADD instruction, then instr1 must wait for the result of instr0 to be written into R2 before it can read R2.
[0089] As shown in Figure 8, since there is no dependency relationship between instr2 / 3 and instr0 / 1, the compiler can adjust the order of instructions and put the two RCP instructions between the ADD and MUL instructions, thereby solving the R2 read-write conflict problem of the ADD and MUL instructions.
[0090] However, in actual situations, as shown in Figure 9, there is usually a dependency relationship between the previous and next instructions. It is difficult for the compiler to insert instructions without a dependency relationship into the middle of instructions with a dependency relationship by adjusting the instruction order. Therefore, in general, the compiler solves the read-write conflict problem of the general register CRF by inserting NOP instructions.
[0091] As shown in Figure 10, the ALU writes the result of instr0 into R2 in cycle7. Therefore, the ALU must read R2 after cycle7, otherwise the data stored in R2 is the old data before the ADD update, resulting in a read-write conflict. In order to ensure that the ALU reads R2 after cycle7, the thread bundle control module must send instr1 to the ALU in cycle6, and cannot send it in cycle2 or cycle4. Therefore, the compiler needs to insert two NOP instructions between instr0 and instr1, consuming 4 cycles (cycle2~cycle5) to solve the R2 read-write conflict problem. NOP instructions do not perform any operations, but only consume cycles and introduce delays. Therefore, the more NOP instructions are inserted, the worse the performance.
[0092] Taking the same instruction as an example (see Figure 11), in the present application, as shown in Figure 12, taking the emission clock of the even-numbered thread bundle wave0 as an example, the thread bundle control module can read the destination operand R2 of the wave0 instr0 instruction when it emits the wave0 instr1 instruction in cycle8. Although there are 6 cycles between wave0 instr0 and wave1 instr1, the wave0 instruction can only be emitted in cycle4; in cycle2 and cycle6, which are the emission clocks of the odd-numbered thread bundle instructions, the emission of the odd and even thread bundle instructions does not affect each other. Therefore, as long as the thread bundle control module does not emit wave0 instr1 in cycle4, the read-write conflict problem of wave0 R2 can be guaranteed.
[0093] Therefore, only one NOP instruction needs to be inserted between wave0 instr0 and wave0 instr1. The thread bundle control module emits the wave0 NOP instruction in cycle4, causing a delay of 2 cycles (cycle4 and cycle5), ensuring that wave0instr1 is emitted in cycle8, thereby solving the read-write conflict problem of wave0 R2.
[0094] Similarly, we can find from the emission clock of the odd-numbered bundle wave1 that wave1 instr0 writes the result into R2 in cycle10, and the bundle control module can read the R2 result of wave1 instr0 as long as it emits wave1 instr1 in cycle10. Therefore, we only need to insert a NOP instruction between wave1 instr0 and instr1 to ensure that wave1instr1 is emitted in cycle10, thereby avoiding the read-write conflict of wave1 R2.
[0095] Compared with the traditional instruction issuance method, the method of alternating execution of even and odd thread warp instructions can reduce the number of NOPs from 2 to 1, thereby improving the execution performance of the arithmetic logic unit.
[0096] In the above embodiment, the thread warp control module, instruction cache module, general register module and arithmetic logic unit can support instructions with 3 or more operands when working at the same frequency. In a general processor, in order to solve the read and write conflict problem of the general register, a certain number of NOP instructions are introduced, but the present application can reduce the number of NOP instructions, thereby improving the efficiency of instruction execution.
[0097] It should be understood that, although the steps in the flowcharts involved in the above embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0098] Based on the same inventive concept, the embodiment of the present application also provides an instruction execution device for implementing the instruction execution method involved above. The implementation solution provided by the device to solve the problem is similar to the implementation solution recorded in the above method, so the specific limitations in one or more instruction execution device embodiments provided below can refer to the limitations on the instruction execution method above, and will not be repeated here.
[0099] In an exemplary embodiment, in conjunction with FIG. 2 , an instruction execution device is provided, including:
[0100] A thread warp control module, for issuing instructions to the arithmetic logic unit in every even clock cycle;
[0101] A first general register, used to store source operands of instructions corresponding to even-numbered warps;
[0102] A second general register, used to store source operands of instructions corresponding to odd-numbered warps;
[0103] An arithmetic logic unit is used to execute the instruction execution method described in any one of the above embodiments to execute the instructions issued by the thread warp control module.
[0104] In one of the optional embodiments, the device further comprises:
[0105] An instruction cache module, used to store instructions;
[0106] The thread warp control module is also used to cyclically obtain instructions from the instruction cache module based on the number of instruction execution module groups corresponding to the arithmetic logic unit, and obtain one instruction per clock cycle, and the instructions obtained from the instruction cache module in adjacent clock cycles belong to different instruction execution module groups.
[0107] Each module in the above instruction execution device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module above.
[0108] In an exemplary embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be shown in FIG13. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit, and an input device. The processor, the memory, and the input / output interface are connected via a system bus, and the communication interface, the display unit, and the input device are connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner may be implemented through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, an instruction execution method is implemented. The display unit of the computer device is used to form a visually visible picture, which may be a display screen, a projection device, or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the computer device shell, or an external keyboard, touchpad or mouse.
[0109] Those skilled in the art will understand that the structure shown in FIG. 13 is merely a block diagram of a partial structure related to the scheme of the present application, and does not constitute a limitation on the computer device to which the scheme of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.
[0110] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0111] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0112] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0113] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0114] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0115] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A method for executing an instruction, characterized in that: Applied to an arithmetic logic unit, the method comprises: In each even-numbered clock cycle, receiving an instruction issued by a thread warp control module, wherein two instructions received in consecutive even-numbered clock cycles belong to an even-numbered thread warp and an odd-numbered thread warp respectively; When the instruction belongs to an even warp, obtaining a source operand from a first general register, and when the instruction belongs to an odd warp, obtaining a source operand from a second general register; The instruction is executed based on the source operand.
2. The method according to claim 1, characterized in that After executing the instruction based on the source operand, the method further comprises: Perform instruction operation based on the source operand to obtain a destination operand; When the instruction belongs to an even warp, storing the destination operand in a first general register, When the instruction belongs to an odd warp, the destination operand is stored in a second general register.
3. The method according to claim 1 or 2, characterized in that: The number of warps is a power of two.
4. A method for executing an instruction, characterized in that: Applied to a thread warp control module, the method comprises: In each even clock cycle, an instruction is issued to the arithmetic logic unit of each instruction execution module group, and the two instructions issued to the same instruction execution module group in consecutive even clock cycles belong to the even thread warp and the odd thread warp respectively; when the instruction belongs to the even thread warp, the source operand is stored in the first general register of the instruction execution module group, and when the instruction belongs to the odd thread warp, the source operand is stored in the second general register of the instruction execution module group.
5. The method according to claim 4, characterized in that The method includes, before sending an instruction to the arithmetic logic unit of each instruction execution module group in each even clock cycle: Instructions are cyclically obtained from the instruction cache module based on the number of the instruction execution module groups, and one instruction is obtained in each clock cycle. The instructions obtained from the instruction cache module in adjacent clock cycles belong to different instruction execution module groups.
6. An instruction execution device, characterized in that: The device comprises: A thread warp control module, for issuing instructions to the arithmetic logic unit in every even clock cycle; A first general register, used to store source operands of instructions corresponding to even-numbered warps; A second general register, used to store source operands of instructions corresponding to odd-numbered warps; An arithmetic logic unit, configured to execute the instruction execution method according to any one of claims 1 to 3 to execute the instructions issued by the thread warp control module.
7. The device according to claim 6, characterized in that The device also includes: An instruction cache module, used to store instructions; The thread warp control module is also used to cyclically obtain instructions from the instruction cache module based on the number of instruction execution module groups corresponding to the arithmetic logic unit, and obtain one instruction per clock cycle, and the instructions obtained from the instruction cache module in adjacent clock cycles belong to different instruction execution module groups.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 5 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
Citation Information
Cited By
Instruction scheduling device and method, processor, electronic equipment and storage medium
CN120125419A
