Obtaining method of target thread index, electronic equipment and medium
By obtaining the three-dimensional modulus of the target thread and dividing it into groups, and combining the coordinate values with the clock cycle, the problem of quickly and accurately obtaining the target thread index is solved, and efficient index information acquisition is achieved.
Patent Information
- Application Number
- CN202511525597.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-24
- Publication Date
- 2025-11-21
- Estimated Expiration
- 2045-10-24
AI Technical Summary
How to quickly and accurately obtain the index information of the target thread in the process, especially when the execution unit of the chip is executing the thread in the instruction.
By obtaining the modulus of the target thread in the process across three dimensions, dividing it into multiple groups, and calculating the coordinate values of the target thread in each group sequentially according to the clock cycle, and setting the periodic delay between dimensions, fast and accurate index retrieval can be achieved.
It can quickly and accurately obtain the index information of the target thread in the process, improving processing efficiency and accuracy.
Smart Images

Figure CN120994255A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of chip technology, and in particular to a method, electronic device, and medium for obtaining a target thread index. Background Technology
[0002] A program is a static set of instructions (waves), a process is a dynamic execution instance of a program, instructions are the basic unit of process execution, and threads are smaller units within a process that can be executed concurrently. They cooperate to implement complex software functions in a computer system. A process can include multiple instructions, and an instruction can include multiple threads. A process requires indices in multiple dimensions to determine the specific location of a thread. When the chip's execution unit (Accelerated Processor, or AP) executes a thread from an instruction, it needs to obtain the thread's position information in each dimension of the process. Therefore, how to quickly and accurately obtain the index information of a target thread within a process is a pressing technical problem that needs to be solved. Summary of the Invention
[0003] The purpose of this invention is to provide a method, electronic device, and medium for obtaining the index of a target thread, which can quickly and accurately obtain the index information of the target thread in the process.
[0004] According to a first aspect of the present invention, a method for obtaining a target thread index is provided, comprising: Step S1: Obtain the three-dimensional modulus (Z, Y, X) of the target thread in the process, where X is the first-dimensional modulus of the target thread in the process, Y is the second-dimensional modulus of the target thread in the process, and Z is the third-dimensional modulus of the target thread in the process. Step S2: Obtain the total number of target threads P=X×Y×Z, and the number of threads that can be executed in one clock cycle A=N / B, P≤M×N, where M is the maximum number of instructions contained in the process, N is the maximum number of threads contained in the instruction, and B is the number of clock cycles required to execute one instruction. Step S3: Divide the P target threads into Q groups {C0, C1, ..., C...} q ,...,C Q-1}, C q For the q-th target thread, the value of q ranges from 0 to Q-1, Q = roundup(P / A), where roundup() represents the round-up function. q ={t0 q ,t1 q ,...,t i q ,...,t f(q) q}, t iq C q The i-th target thread in the context, where i ranges from 0 to f(q), and f(q) is a function of C. q The number of target threads included, t i q The target line program number is u i q u i q =q×A+i, if P / A is an integer, then all f(q) are equal to A-1; if P / A is not an integer, then when q=Q-1, f(q) is the remainder of P / A; when q≠Q-1, f(q)=A-1. Step S4: Set v to take values from 0 to Q+1 sequentially. In the v-th clock cycle: when v=0, execute process 1; when v=1, execute process 1 and process 2; when 3≤v≤Q-1, execute process 1, process 2, process 3 and process 4; when v=Q, execute process 2, process 3 and process 4; when v=Q+1, execute process 3 and process 4. Process 1: Based on u i v And X determines t i v The corresponding first-dimensional coordinate x i v and t i v The corresponding second-dimensional carry value r i v ; Process 2: r determined based on the (v-1)th clock cycle i v-1 And Y determine t i v-1 The corresponding second-dimensional coordinate y i v-1 and t i v-1 The corresponding third-dimensional carry value s i v-1 ; Step 3: Based on s determined in the (v-2)th clock cycle i v-2 And Z determine t i v-2 The corresponding third-dimensional coordinate z i v-2 ; Process 4: Output t i v-2 Corresponding index information (z) i v-2 y i v-2 x iv-2 ).
[0005] According to a second aspect of the present invention, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being configured to perform the method described in the first aspect of the present invention.
[0006] According to a third aspect of the present invention, a computer-readable storage medium is provided, storing computer-executable instructions for performing the method described in the first aspect of the present invention.
[0007] Compared with existing technologies, this invention has significant advantages and beneficial effects. Through the above technical solution, the method, electronic device, and medium for obtaining a target thread index provided by this invention achieve considerable technological advancement and practicality, and have broad industrial application value. It has at least the following beneficial effects: This invention first obtains the modulus of the target thread in the process in three dimensions and the total number of target threads. Then, the target threads are divided into multiple groups. Then, the coordinate value of each dimension in each group of target threads is calculated sequentially according to the clock cycle. A delay of one cycle is set between the three dimensions, so as to quickly and accurately obtain the index information of the target thread in the process. Attached Figure Description
[0008] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0009] Figure 1 A flowchart illustrating the method for obtaining the target thread index provided in this embodiment of the invention. Detailed Implementation
[0010] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0011] This invention provides a method for obtaining a target thread index, such as... Figure 1 As shown, it includes: Step S1: Obtain the three-dimensional modulus (Z, Y, X) of the target thread in the process, where X is the first-dimensional modulus of the target thread in the process, Y is the second-dimensional modulus of the target thread in the process, and Z is the third-dimensional modulus of the target thread in the process.
[0012] It should be noted that an origin and coordinate axes of the first, second, and third dimensions are established in the process. The target thread is located in a cube in the process with (Z, Y, X) and the origin as vertices, together with the three coordinate axes. The magnitude of each dimension is the maximum length value of the target thread in the corresponding dimension.
[0013] Step S2: Obtain the total number of target threads P=X×Y×Z, and the number of threads that can be executed in one clock cycle A=N / B, P≤M×N, where M is the maximum number of instructions contained in the process, N is the maximum number of threads contained in the instruction, and B is the number of clock cycles required to execute one instruction.
[0014] Where M×N is the maximum number of threads that the process can accommodate, and P=X×Y×Z is the target total number of threads. Therefore, P≤M×N. For example, if the process contains a maximum of 16 instructions, and each instruction contains a maximum of 64 threads, then M=16, N=64, and M×N=1024. B is a known value, and the setting of the value of B needs to meet the timing requirements.
[0015] Step S3: Divide the P target threads into Q groups {C0, C1, ..., C...} q ,...,C Q-1}, C q For the q-th target thread, the value of q ranges from 0 to Q-1, Q = roundup(P / A), where roundup() represents the round-up function. q ={t0 q ,t1 q ,...,t i q ,...,t f(q) q}, t i q C q The i-th target thread in the context, where i ranges from 0 to f(q), and f(q) is a function of C. q The number of target threads included, t i q The target line program number is u i q u i q=q×A+i, if P / A is an integer, then all f(q) are equal to A-1. If P / A is not an integer, then when q=Q-1, f(q) is the remainder of P / A, and when q≠Q-1, f(q)=A-1.
[0016] Here, "roundup(P / A)" means rounding up the result of P / A. It should be noted that the P target threads are divided into Q groups to facilitate the subsequent calculation of the coordinate information of the target threads in each group according to the clock cycle. Moreover, the coordinates of the target threads that can be executed are calculated as much as possible in each clock cycle, so as to improve processing efficiency while ensuring accuracy.
[0017] Step S4: Set v to take values from 0 to Q+1 sequentially. In the v-th clock cycle: when v=0, execute process 1; when v=1, execute process 1 and process 2; when 3≤v≤Q-1, execute process 1, process 2, process 3 and process 4; when v=Q, execute process 2, process 3 and process 4; when v=Q+1, execute process 3 and process 4.
[0018] Process 1: Based on u i v And X determines t i v The corresponding first-dimensional coordinate x i v and t i v The corresponding second-dimensional carry value r i v .
[0019] Understandable, u i v Let t be one of the target line program numbers. i v This is a target thread for the vth target thread group.
[0020] Process 2: r determined based on the (v-1)th clock cycle i v-1 And Y determine t i v-1 The corresponding second-dimensional coordinate y i v-1 and t i v-1 The corresponding third-dimensional carry value s i v-1 .
[0021] Understandably, t i v-1 This is a target thread for the (v-1)th target thread group.
[0022] Step 3: Based on s determined in the (v-2)th clock cycle i v-2 And Z determine t i v-2 The corresponding third-dimensional coordinate z i v-2 .
[0023] Understandably, t i v-2 This is a target thread for the v-2 group of target threads.
[0024] Process 4: Output t i v-2 Corresponding index information (z) i v-2 y i v-2 x i v-2 ).
[0025] Understandably, through the above steps, each t can ultimately be obtained. i q Corresponding index information (z) i q y i q x i q ).
[0026] It should be noted that, in addition to obtaining the index information corresponding to each target thread, the correspondence between each target thread and the target instruction can also be obtained. As one embodiment, step S3 includes: Step S31: Divide the P target threads into F target instructions {W0, W1, ..., W...} f ,...,W F-1},W f Let f be the f-th target instruction, where f ranges from 0 to F-1, and F = roundup(P / N).
[0027] Here, roundup(P / N) represents rounding up the result of P / N. This can be understood as W0 to W... F-1 Each part is divided into N threads, W F The number of threads in the pool is less than or equal to N, depending on whether the result of P / N is an integer. If it is an integer, then W... F The number of threads in W is N; otherwise, W F The number of threads is the remainder of P / N.
[0028] Step S32: If 0, B, 2×B, ..., f×B, ..., (F-2)×B, then C k To Ck+B-1 The target instructions in the middle are divided into the corresponding W. f In the middle, if k = (F-1) × B, then C k To C Q-1 The target instructions in the middle are divided into the corresponding W. F middle.
[0029] It should be noted that through steps S31-S32, a mapping relationship between each target instruction and its corresponding target instruction can be established.
[0030] As one embodiment, in step S4, process 1, i.e., the process based on u i v And X determines t i v The corresponding first-dimensional coordinate x i v and t i v The corresponding second-dimensional carry value r i v ,include: Step S41, if u i v If the result is greater than or equal to X, then proceed to step S42; otherwise, proceed to step S43.
[0031] Step S42, obtain u i v The quotient divided by X and u i v The remainder when divided by X, u i v The remainder when divided by X is determined as t. i v The corresponding first-dimensional coordinate x i v , will u i v The quotient divided by X is determined as t. i v The corresponding second-dimensional carry value r i v .
[0032] Step S43, place u i v Determined as t i v The corresponding first-dimensional coordinate x i v , will t i v The corresponding second-dimensional carry value r i v The value is determined to be 0.
[0033] It should be noted that if X is a power of 2, the calculation can be performed based on the logic of steps S41-S43. To improve processing efficiency, if the value of X is not a power of 2, such as X being 3, 5, 6, 7, etc., a corresponding lookup table can be pre-set based on the value of X. The lookup table sets the correspondence between the input value and the corresponding output quotient and remainder, and the lookup table is used to obtain the quotient and remainder corresponding to the input value.
[0034] As one embodiment, in step S4, process 2, namely the step of determining r based on the (v-1)th clock cycle, is... i v-1 And Y determine t i v-1 The corresponding second-dimensional coordinate y i v-1 and t i v-1 The corresponding third-dimensional carry value s i v-1 ,include: Step C41, if r i v-1 If the result is ≥Y, then proceed to step C42; otherwise, proceed to step C43.
[0035] Step C42, obtain r i v-1 The quotient divided by Y and r i v-1 The remainder when divided by Y, r i v-1 The remainder when divided by Y is determined as t. i v-1 The corresponding second-dimensional coordinate y i v-1 , will r i v-1 The quotient divided by Y is determined as t. i v-1 The corresponding third-dimensional carry value s i v-1 .
[0036] Step C43, r i v-1 Determined as t i v-1 The corresponding second-dimensional coordinate y i v-1 , will t i v-1 The corresponding third-dimensional carry value s i v-1 The value is determined to be 0.
[0037] It should be noted that, as shown in process 2, the calculation of the second-dimensional coordinates for each target thread is based on the carry-in value of the corresponding first-dimensional coordinates, thus delaying the calculation by one clock cycle. Furthermore, if the Y value is a power of 2, it can be calculated based on the logic of steps C41-C43. To improve processing efficiency, if the Y value is not a power of 2, for example, if the Y value is 3, 5, 6, 7, etc., a corresponding lookup table can be pre-set based on the Y value. This lookup table establishes the correspondence between the input value and the corresponding output quotient and remainder, allowing the lookup table to retrieve the quotient and remainder corresponding to the input value.
[0038] As one embodiment, in step S4, process 3, i.e., s determined based on the (v-2)th clock cycle, i v-2 And Z determine t i v-2 The corresponding third-dimensional coordinate z i v-2 ,include: Step D41, if s i v-2 If the value is greater than or equal to Z, then proceed to step D42; otherwise, proceed to step D43.
[0039] Step D42, Obtain s i v-2 The remainder when divided by Z, s i v-2 The remainder when divided by Z is determined as t. i v-2 The corresponding third-dimensional coordinate z i v-2 .
[0040] Step D43, s i v-2 Determined as t i v-2 The corresponding third-dimensional coordinate z i v-2 .
[0041] It should be noted that, as shown in process 3, the calculation of the third-dimensional coordinates of each target thread is based on the carry-in value of the corresponding second-dimensional coordinates, thus delaying the calculation of the second-dimensional coordinates by one clock cycle. Furthermore, if the Z value is a power of 2, it can be calculated based on the logic of steps D41-D43. To improve processing efficiency, if the Z value is not a power of 2, for example, if the Z value is 3, 5, 6, 7, etc., a corresponding lookup table can be pre-set based on the Z value. The lookup table establishes the correspondence between the input value and the corresponding output remainder, and the remainder corresponding to the input value is obtained through the lookup table. If any two values of X, Y, and Z are the same, the same lookup table can be reused.
[0042] As one embodiment, in step S4, process 4, i.e., the output t i v-2 Corresponding index information (z) i v-2 y i v-2 x i v-2 ),include: Step E41: Obtain each t in the target thread of the v-2 group. i v-2 The corresponding first-dimensional coordinate x i v-2 Second-dimensional coordinate y i v-2 and the third-dimensional coordinate z i v-2 .
[0043] Step E42, based on each t i v-2 Corresponding x i v-2 y i v-2 z i v-2 Generate each t i v-2 Corresponding index information (z) i v -2 y i v-2 x i v-2 ).
[0044] Step E43: Output each t in the target thread of group v-2. i v-2 Corresponding (z) i v-2 y i v-2 x i v-2 ).
[0045] As one embodiment, step S4 is followed by step S5: generating a target thread index lookup table based on the target thread's index information and target instructions; the target thread index lookup table includes F×(B+1) rows and A columns, wherein the row and column numbers of the target thread index lookup table both start from 0; W f The identifier is stored in row f×(B+1) of the target thread index lookup table. i q Corresponding index information (z)i q y i q x i q The target thread index lookup table contains data stored in the q+roundup[(q+1) / B)]th row and i-th column. Step S5 includes: Step S51, in the target thread index lookup table, the non-W... f Fill all spaces in the row that do not contain index information with an invalid identifier; specifically, you can set the invalid identifier directly to 0.
[0046] Taking X=16, Y=5, Z=3 as an example, using the method described in this invention, four target instructions, wave0, wave1, wave2, and wave3, and 240 target threads are obtained. The generated target thread index lookup table is shown in Table 1. Table 1
[0047] After obtaining the index information of each target thread and the corresponding target instruction identifier, the chip's execution unit can either obtain the index information of all target threads corresponding to the target instruction to execute the target instruction, or obtain the index information of a single target thread to execute the target instruction.
[0048] It should be noted that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although the flowcharts describe the steps as sequential processes, many of these steps can be performed in parallel, concurrently, or simultaneously. Furthermore, the order of the steps can be rearranged. A process can be terminated when its operation is complete, but it may also have additional steps not included in the figures. A process can correspond to a method, function, procedure, subroutine, subroutine, etc.
[0049] This invention also provides an electronic device, including: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being configured to perform the method described in this invention.
[0050] This invention also provides a computer-readable storage medium storing computer-executable instructions for performing the methods described in this invention.
[0051] In this embodiment of the invention, the three dimensions of the target thread in the process and the total number of target threads are first obtained. Then, the target threads are divided into multiple groups. Then, the coordinate value of each dimension in each group of target threads is calculated sequentially according to the clock cycle. A delay of one cycle is set between the three dimensions, so as to quickly and accurately obtain the index information of the target thread in the process.
[0052] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention in any way. Although the present invention has been disclosed above with reference to preferred embodiments, it is not intended to limit the present invention. Any person skilled in the art can make some modifications or alterations to the above-disclosed technical content to create equivalent embodiments without departing from the scope of the present invention. Any simple modifications, equivalent changes, and alterations made to the above embodiments based on the technical essence of the present invention without departing from the scope of the present invention shall still fall within the scope of the present invention.
Claims
1. A method for obtaining a target thread index, characterized in that, include: Step S1: Obtain the three-dimensional modulus (Z, Y, X) of the target thread in the process, where X is the first-dimensional modulus of the target thread in the process, Y is the second-dimensional modulus of the target thread in the process, and Z is the third-dimensional modulus of the target thread in the process. Step S2: Obtain the total number of target threads P=X×Y×Z, and the number of threads that can be executed in one clock cycle A=N / B, P≤M×N, where M is the maximum number of instructions contained in the process, N is the maximum number of threads contained in the instruction, and B is the number of clock cycles required to execute one instruction. Step S3: Divide the P target threads into Q groups {C0, C1, ..., C...} q ,...,C Q-1 }, C q For the q-th target thread, the value of q ranges from 0 to Q-1, Q = roundup(P / A), where roundup() represents the round-up function. q ={t0 q ,t1 q ,...,t i q ,...,t f(q) q }, t i q C q The i-th target thread in the context, where i ranges from 0 to f(q), and f(q) is a function of C. q The number of target threads included, t i q The target line program number is u i q u i q =q×A+i, if P / A is an integer, then all f(q) are equal to A-1; if P / A is not an integer, then when q=Q-1, f(q) is the remainder of P / A; when q≠Q-1, f(q)=A-1. Step S4: Set v to take values from 0 to Q+1 sequentially. In the v-th clock cycle: when v=0, execute process 1; when v=1, execute process 1 and process 2; when 3≤v≤Q-1, execute process 1, process 2, process 3 and process 4; when v=Q, execute process 2, process 3 and process 4; when v=Q+1, execute process 3 and process 4. Process 1: Based on u i v And X determines t i v The corresponding first-dimensional coordinate x i v and t i v The corresponding second-dimensional carry value r i v ; Process 2: r determined based on the (v-1)th clock cycle i v-1 And Y determine t i v-1 The corresponding second-dimensional coordinate y i v-1 and t i v-1 The corresponding third-dimensional carry value s i v-1 ; Step 3: Based on s determined in the (v-2)th clock cycle i v-2 And Z determine t i v-2 The corresponding third-dimensional coordinate z i v-2 ; Process 4: Output t i v-2 Corresponding index information (z) i v-2 y i v-2 x i v-2 ).
2. The method according to claim 1, characterized in that, Step S3 includes: Step S31: Divide the P target threads into F target instructions {W0, W1, ..., W...} f ,...,W F-1 },W f Let f be the f-th target instruction, where f ranges from 0 to F-1, and F = roundup(P / N). Step S32: If 0, B, 2×B, ..., f×B, ..., (F-2)×B, then C k To C k+B-1 The target instructions in the middle are divided into the corresponding W. f In the middle, if k = (F-1) × B, then C k To C Q-1 The target instructions in the middle are divided into the corresponding W. F middle.
3. The method according to claim 1, characterized in that, In step S4, process 1 includes: Step S41, if u i v If the value is greater than or equal to X, then proceed to step S42; otherwise, proceed to step S43. Step S42, obtain u i v The quotient divided by X and u i v The remainder when divided by X, u i v The remainder when divided by X is determined as t. i v The corresponding first-dimensional coordinate x i v , will u i v The quotient divided by X is determined as t. i v The corresponding second-dimensional carry value r i v ; Step S43, place u i v Determined as t i v The corresponding first-dimensional coordinate x i v , will t i v The corresponding second-dimensional carry value r i v The value is determined to be 0.
4. The method according to claim 1, characterized in that, In step S4, process 2 includes: Step C41, if r i v-1 If the value is ≥Y, then proceed to step C42; otherwise, proceed to step C43. Step C42, obtain r i v-1 The quotient divided by Y and r i v-1 The remainder when divided by Y, r i v-1 The remainder when divided by Y is determined as t. i v-1 The corresponding second-dimensional coordinate y i v-1 , will r i v-1 The quotient divided by Y is determined as t. i v-1 The corresponding third-dimensional carry value s i v-1 ; Step C43, r i v-1 Determined as t i v-1 The corresponding second-dimensional coordinate y i v-1 , will t i v-1 The corresponding third-dimensional carry value s i v-1 The value is determined to be 0.
5. The method according to claim 1, characterized in that, In step S4, process 3 includes: Step D41, if s i v-2 If Z ≥ Z, then proceed to step D42; otherwise, proceed to step D43. Step D42, Obtain s i v-2 The remainder when divided by Z, s i v-2 The remainder when divided by Z is determined as t. i v-2 The corresponding third-dimensional coordinate z i v-2 ; Step D43, s i v-2 Determined as t i v-2 The corresponding third-dimensional coordinate z i v-2 .
6. The method according to claim 1, characterized in that, In step S4, process 4 includes: Step E41: Obtain each t in the target thread of the v-2 group. i v-2 The corresponding first-dimensional coordinate x i v-2 Second-dimensional coordinate y i v-2 and the third-dimensional coordinate z i v-2 ; Step E42, based on each t i v-2 Corresponding x i v-2 y i v-2 z i v-2 Generate each t i v-2 Corresponding index information (z) i v-2 y i v -2 x i v-2 ); Step E43: Output each t in the target thread of group v-2. i v-2 Corresponding (z) i v-2 y i v-2 x i v-2 ).
7. The method according to claim 2, characterized in that, Step S4 is followed by step S5: generating a target thread index lookup table based on the target thread's index information and target instructions; The target thread index lookup table includes F×(B+1) rows and A columns, wherein the row numbers and column numbers of the target thread index lookup table are both numbered starting from 0; W f The identifier is stored in the f×(B+1)th row of the target thread index lookup table; t i q Corresponding index information (z) i q y i q x i q The i-th column of row q+roundup[(q+1) / B] of the target thread index lookup table is stored.
8. The method according to claim 7, characterized in that, Step S5 includes: Step S51: Look up the target thread index in the table, not W. f All spaces in the row that do not contain index information are filled with an invalid identifier.
9. An electronic device, characterized in that, include: At least one processor; And, a memory communicatively connected to the at least one processor; The memory stores instructions that are executed by the at least one processor, the instructions being configured to perform the method of any one of claims 1-8.
10. A computer-readable storage medium, characterized in that, The device stores computer-executable instructions for performing the method of any one of claims 1-8.
Citation Information
Patent Citations
GPGPU (General Purpose Graphics Processing Unit) thread block synchronization method and equipment based on thread lock and medium
CN119557115A
Thread coordinate determination method and device, equipment, storage medium and program product
CN120276838A
Method and equipment for determining thread bundle index
CN120407141A
Apparatus and method for handling logical and numerical uncertainty utilizing novel underlying precepts
US20020019975A1
System, method and article of manufacture for a debugger capable of operating across multiple threads and lock domains
US20020199173A1