Thread coordinate determination method and device, equipment, storage medium and program product
By converting the thread index into an arrangement number on the graphics processor and using a lookup table to determine the three-dimensional coordinates, the problem of low division operation efficiency in the prior art is solved, and more efficient thread coordinate determination is achieved.
Patent Information
- Application Number
- CN202510321077.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-17
- Publication Date
- 2025-07-08
AI Technical Summary
In the prior art, when performing thread indexing to three-dimensional coordinate conversion on a graphics processor, there is a problem of low division operation efficiency.
By converting the thread index into the arrangement number in the current round, and using the preset lookup table to determine the conversion result between the arrangement number and the coordinate conversion value, the calculation complexity is reduced and the search efficiency is improved.
It improves the speed of thread coordinate determination, saves time, and is highly adaptable, and can support computing blocks of different dimensions.
Smart Images

Figure CN120276838A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to, but is not limited to, the field of computer technology, and in particular, to a method, apparatus, device, storage medium, and program product for determining thread coordinates. Background Art
[0002] When performing parallel computing on a Graphics Processing Unit (GPU), multiple threads are grouped into a three-dimensional computing block for processing. In this process, it involves converting the index of each thread into its three-dimensional coordinates in the three-dimensional computing block.
[0003] In the related art, the index of a thread is converted into three-dimensional coordinates by division and remainder. However, this method involves division operations and has the problem of low conversion efficiency. Summary of the Invention
[0004] In view of this, embodiments of the present disclosure at least provide a method, apparatus, device, storage medium, and program product for determining thread coordinates.
[0005] The technical solution of the embodiments of the present disclosure is implemented as follows:
[0006] On the one hand, an embodiment of the present disclosure provides a method for determining thread coordinates. The method for determining thread coordinates includes: determining the three-dimensional size of the thread workgroup to which the first thread belongs, the sequence number of the first thread in the current round, and the target number of threads that can be processed in each round; determining, based on the three-dimensional size and the target number, a coordinate conversion value constrained within the target number; determining, from a preset lookup table, a target conversion result between the sequence number and the coordinate conversion value; the lookup table includes conversion results between all values of the sequence number and all values of the coordinate conversion value; determining, based on the target conversion result, the first three-dimensional coordinates of the first thread.
[0007] On the other hand, an embodiment of the present disclosure provides a device for determining thread coordinates. The device for determining thread coordinates includes: a determination module, configured to determine the three-dimensional size of the thread workgroup to which the first thread belongs, the sequence number of the first thread in the current round, and the target number of threads that can be processed in each round; the determination module is further configured to determine, based on the three-dimensional size and the target number, a coordinate conversion value constrained within the target number; a lookup module, configured to determine, from a preset lookup table, a target conversion result between the sequence number and the coordinate conversion value; the lookup table includes conversion results between all values of the sequence number and all values of the coordinate conversion value; the determination module is further configured to determine, based on the target conversion result, the first three-dimensional coordinates of the first thread.
[0008] In another aspect, embodiments of the present disclosure provide a computer device, including a memory and a processor. The memory stores a computer program that can run on the processor. When the processor executes the program, it implements some or all of the steps in the above method.
[0009] In yet another aspect, embodiments of the present disclosure provide a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it implements some or all of the steps in the above method.
[0010] In yet another aspect, embodiments of the present disclosure provide a computer program, including computer-readable code. When the computer-readable code runs in a computer device, the processor in the computer device executes to implement some or all of the steps in the above method.
[0011] In yet another aspect, embodiments of the present disclosure provide a computer program product. The computer program product includes a non-transitory computer-readable storage medium storing a computer program. When the computer program is read and executed by a computer, it implements some or all of the steps in the above method.
[0012] In the embodiments of the present disclosure, converting the index of a thread into the arrangement serial number of the thread within the current round can reduce the complexity of calculation operations, and can also reduce the scale of the lookup table and improve the lookup efficiency. Determining the three-dimensional coordinates of a thread through a table lookup method, compared with determining the three-dimensional coordinates of a thread through division and remainder, maximally improves the determination rate of thread coordinates and saves time.
[0013] It should be understood that the above general description and the following detailed description are only exemplary and explanatory, and do not limit the technical solution of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] The drawings here are incorporated into the specification and constitute a part of this specification. These drawings show embodiments conforming to the present disclosure and are used together with the specification to illustrate the technical solutions of the present disclosure.
[0015] Figure 1 It is a schematic structural diagram of a method for determining thread coordinates provided by an embodiment of the present disclosure;
[0016] Figure 2 It is a schematic implementation flow diagram of a method for determining thread coordinates provided by an embodiment of the present disclosure Figure 1 ;
[0017] Figure 3 It is a schematic implementation flow diagram of a method for determining thread coordinates provided by an embodiment of the present disclosure Figure 2 ;
[0018] Figure 4Schematic diagram of state machine jump in a thread coordinate determination method provided by an embodiment of the present disclosure;
[0019] Figure 5 Schematic diagram of the structure of division calculation in a thread coordinate determination method provided by an embodiment of the present disclosure;
[0020] Figure 6 Schematic diagram of the composition structure of a thread coordinate determination device provided by an embodiment of the present disclosure;
[0021] Figure 7 Schematic diagram of the hardware entity of a computer device provided by an embodiment of the present disclosure. Detailed implementation manners
[0022] In order to make the objectives, technical solutions, and advantages of the present disclosure clearer, the technical solutions of the present disclosure will be further elaborated in detail below with reference to the accompanying drawings and embodiments. The described embodiments should not be construed as limitations on the present disclosure. All other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the scope of protection of the present disclosure.
[0023] In the following description, reference is made to "some embodiments", which describe a subset of all possible embodiments. However, it can be understood that "some embodiments" can be the same subset or different subsets of all possible embodiments, and can be combined with each other without conflict.
[0024] The terms "first / second / third" involved are only used to distinguish similar objects and do not represent a specific order for the objects. It can be understood that "first / second / third" can be interchanged with a specific order or sequence when allowed, so that the embodiments of the present disclosure described herein can be implemented in an order other than that illustrated or described herein.
[0025] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those of ordinary skill in the technical field to which the present disclosure belongs. The terms used herein are only for the purpose of describing the present disclosure and are not intended to limit the present disclosure.
[0026] An embodiment of the present disclosure provides a thread coordinate determination method. As Figure 1 shown, the method may include a plurality of converters. Specifically, the three-dimensional size of a thread workgroup is input into a target number of converters; a target number of converters are used to determine the three-dimensional coordinates of a target number of threads according to the three-dimensional size and the target number in each round. The target number refers to the number of threads that can be processed in each round, that is, the number of threads that can be processed per unit time. The target number can be represented as N. The target number can be set according to the hardware overhead during converter deployment, the three-dimensional size of the thread workgroup, and the throughput requirement.
[0027] Among them, as Figure 2 shown, the specific implementation method for any converter to determine the three-dimensional coordinates of any thread (the first thread) according to the three-dimensional size and the target number may include the following steps 201 to 204:
[0028] Step 201: Determine the three-dimensional size of the thread workgroup to which the first thread belongs, the serial number of the arrangement of the first thread in the current round, and the target number of threads that can be processed in each round.
[0029] A thread workgroup refers to a set of threads that work together, and can also be called a thread block. The three-dimensional size of the thread workgroup consists of three dimensions, which are the x dimension, the y dimension, and the z dimension respectively. Among them, the value on the x dimension is used to represent the size of the thread workgroup in the x dimension, and the value on the x dimension can be expressed as wg_size.x. The value on the y dimension is used to represent the size of the thread workgroup in the y dimension, and the value on the y dimension can be expressed as wg_size.y. The value on the z dimension is used to represent the size of the thread workgroup in the z dimension, and the value on the z dimension can be expressed as wg_size.z.
[0030] The first thread is any thread in the thread workgroup.
[0031] The serial numbers of the arrangements of the multiple threads to be processed in each round correspond to the identifiers of the converters. In some embodiments, the target number of converters can be encoded according to the arrangement order of the converters to determine the identifier of each converter.
[0032] In some embodiments, according to the target number of threads that can be processed in each round, the current round, and the serial number of the arrangement of the first thread in the current round, the index of the first thread can be determined. The index of the thread can represent the position of the thread in the thread workgroup. For example, the determination formula for the index of the first thread can be: (current round - 1) * target number + serial number of the arrangement of the first thread in the current round. If the serial number of the arrangement of the first thread in the second round is 9 and the target number of threads that can be processed in each round is 4, then the index of the first thread is (2 - 1) * 9 + 4 = 13.
[0033] The reason for converting the index of the thread to the serial number of the arrangement of the thread in the current round in the embodiments of the present disclosure is that: compared with the index of the thread, the serial number of the arrangement in the current round has a smaller value, the calculation operation is more convenient, and the scale of the lookup table can also be reduced, improving the lookup efficiency.
[0034] Step 202: Based on the three-dimensional size and the target number, determine the coordinate conversion value restricted within the target number.
[0035] In some embodiments, the specific implementation of step 202 may be: determining a coordinate conversion value based on the three-dimensional size; constraining the coordinate conversion value according to the target quantity so that the coordinate conversion value is constrained within N.
[0036] Assuming that the coordinate conversion value is not constrained, then the coordinate conversion value can be an arbitrarily large value, which will increase the computational complexity. By constraining the coordinate conversion value within N (the target quantity), the conversion operation of the thread index can be constrained within N, which can reduce the computational complexity of the thread coordinates and also reduce the scale of the lookup table, improving the lookup efficiency.
[0037] Step 203: Determine a target conversion result between the permutation serial number and the coordinate conversion value from a preset lookup table.
[0038] Wherein, the lookup table includes conversion results between all values of the permutation serial number and all values of the coordinate conversion value.
[0039] All values of the permutation serial number are all values of the converter identifier. For example, if the converter identifier calculator_id takes values between [0, N - 1], then all values of the permutation serial number are also between [0, N - 1]. The target conversion result is used to reflect the conversion result between all values of the permutation serial number and all values of the coordinate conversion value, that is, to reflect the conversion result between all identifier values of the converter and all values of the coordinate conversion value.
[0040] In some embodiments, all values of the permutation serial number (all identifier values of the converter) and all values of the coordinate conversion value can be determined in advance; calculate the conversion result between each value of the permutation serial number and each value of the coordinate conversion value; establish a mapping relationship between the conversion results between each value of the permutation serial number and each value of the coordinate conversion value; store this mapping relationship in the form of a table to obtain the lookup table.
[0041] In some embodiments, the permutation serial number and the coordinate conversion value can be used as matching bases to determine a target conversion result that matches both the permutation serial number and the coordinate conversion value from the lookup table.
[0042] Step 204: Determine the first three-dimensional coordinate of the first thread based on the target conversion result.
[0043] The first three-dimensional coordinate is the three-dimensional coordinate of the first thread finally output by the converter.
[0044] In some embodiments, when the first thread is a thread in the first round, directly determine the first three-dimensional coordinate of the first thread according to the target conversion result.
[0045] In some embodiments, when the first thread is the thread for the i-th round of processing, the first three-dimensional coordinates of the first thread are determined according to the three-dimensional coordinates of the second thread and the target conversion result determined in the (i - 1)-th round.
[0046] It should be noted that the embodiments of the present disclosure can add converters at any time according to business requirements to increase the number of threads that can be processed in each round and the system throughput. The expansion is convenient and does not require changing the method for determining thread coordinates.
[0047] In the embodiments of the present disclosure, converting the index of a thread to the arrangement serial number of the thread in the current round can reduce the complexity of calculation operations, reduce the scale of the lookup table, and improve the lookup efficiency. Determining the three-dimensional coordinates of a thread by the table lookup method maximally improves the determination rate of thread coordinates and saves time compared with determining the three-dimensional coordinates of a thread by division and remainder.
[0048] The embodiments of the present disclosure provide a method for determining thread coordinates, which can be executed by a converter of a computer device. As Figure 3 shown, the method includes the following steps 301 to 305:
[0049] Step 301: Determine the three-dimensional size of the thread workgroup to which the first thread belongs, the arrangement serial number of the first thread in the current round, and the target number of threads that can be processed in each round.
[0050] Here, the above step 301 corresponds to the foregoing step 201, and the specific implementation can refer to the specific implementation of the foregoing step 201 when implemented.
[0051] Among them, the three-dimensional size includes the first number of threads of the thread workgroup in the first dimension and the second number of threads in the second dimension.
[0052] The first dimension refers to the X dimension, and the second dimension refers to the Y dimension. The first number refers to the number of threads of the thread workgroup in the X dimension, and the second number refers to the number of threads of the thread workgroup in the Y dimension.
[0053] Step 302: Determine the first coordinate conversion value constrained within the target number based on the first number, the second number, and the target number.
[0054] In some embodiments, the specific implementation manner of step 302 can be: based on the first number and the second number, determine the number of threads of the thread workgroup in the plane formed by the first dimension and the second dimension; based on the number of threads of the thread workgroup in the plane formed by the first dimension and the second dimension and the target number, determine the first coordinate conversion value.
[0055] In some embodiments, the specific implementation of "determining the number of threads that a thread workgroup has on a plane formed by a first dimension and a second dimension based on a first quantity and a second quantity" may be: determining the product between the first quantity and the second quantity. For example, the calculation formula for the number of threads that a thread workgroup has on a plane formed by a first dimension and a second dimension can be expressed as: wg_size.x * wg_size.y.
[0056] In some embodiments, the specific implementation of "determining a first coordinate conversion value based on the number of threads that a thread workgroup has on a plane formed by a first dimension and a second dimension and a target quantity" may be: when the product is greater than the target quantity, using the target quantity as the first coordinate conversion value; when the product is less than or equal to the target quantity, using the product as the first coordinate conversion value.
[0057] For example, the calculation formula for the first coordinate conversion value can be expressed as: xy_mul = min(N, wg_size.x * wg_size.y), where xy_mul represents the first coordinate conversion value, N is the target quantity, wg_size.x is the number of threads of the thread workgroup on the x-axis, and wg_size.y represents the number of threads of the workgroup on the y-axis.
[0058] Step 303: Determine a second coordinate conversion value that is constrained within the target quantity based on the first quantity and the target quantity.
[0059] Wherein, the coordinate conversion value includes the first coordinate conversion value and the second coordinate conversion value.
[0060] Here, the above steps 302 to 303 correspond to the aforementioned step 202, and the specific implementation can refer to the specific implementation of the aforementioned step 202 when implemented.
[0061] In some embodiments, the specific implementation of step 303 may be: when the first quantity is greater than the target quantity, using the target quantity as the second coordinate conversion value; when the first quantity is less than or equal to the target quantity, using the first quantity as the second coordinate conversion value.
[0062] For example, the calculation formula for the second coordinate conversion value X_clamp can be expressed as: X_clamp = min(N, wg_size.x).
[0063] It can be understood that the first coordinate conversion value is determined by taking the minimum value of the product of the x - dimension size and the y - dimension size and N; the second coordinate conversion value is determined by taking the minimum value of the x - dimension size and N. In this way, limiting the coordinate conversion values within N can reduce the complexity of calculation operations and also reduce the scale of the lookup table, improving the lookup efficiency.
[0064] Step 304: Determine the target conversion result between the permutation serial number and the coordinate conversion value from a preset lookup table.
[0065] Among them, the lookup table includes the conversion results between all values of the permutation serial number and all values of the coordinate conversion value.
[0066] In some embodiments, when the first thread is the thread for the first - round processing, the specific implementation of step 303 can be: determine the first remainder and the first quotient value that match both the permutation serial number and the first coordinate conversion value from the lookup table; determine the second quotient value that matches both the first remainder and the second coordinate conversion value from the lookup table; the target conversion result includes the first remainder, the first quotient value, and the second quotient value.
[0067] The first remainder refers to the remainder that matches both the permutation serial number and the first coordinate conversion value, the first quotient value refers to the first quotient value that matches both the permutation serial number and the first coordinate conversion value. The second quotient value refers to the quotient value that matches both the first remainder and the second coordinate conversion value.
[0068] In a feasible implementation, the remainder and quotient value that match both the permutation serial number and the first coordinate conversion value can be determined from the lookup table based on the permutation serial number and the first coordinate conversion value as the matching basis, obtaining the first remainder and the first quotient value. Similarly, the quotient value that matches both the first remainder and the second coordinate conversion value can be determined from the lookup table based on the first remainder and the second coordinate conversion value as the matching basis, obtaining the second quotient value. In addition, the remainder that matches both the first remainder and the second coordinate conversion value can be determined from the lookup table based on the first remainder and the second coordinate conversion value as the matching basis.
[0069] For example, at this time, the calculation formula for the target conversion result can be expressed as:
[0070] remainder_0,division_0=look_up_table(calculator_id,xy_mul);
[0071] remainder_1,division_1=look_up_table(remainder_0,x_clamp);
[0072] Among them, remainder_0 represents the first remainder, division_0 represents the first quotient value, remainder_1 represents the remainder that matches both the first remainder and the second coordinate conversion value, and division_1 represents the second quotient value.
[0073] In some embodiments, when the first thread is the thread for the i-th round of processing, the specific implementation of step 303 may be: determine, from the lookup table, a second remainder and an increment that both match the target quantity and the first coordinate conversion value; i is a positive integer greater than 1; the determination of the three-dimensional coordinates of the first thread is based on the three-dimensional coordinates of the thread with the same arrangement serial number as the first thread within the first round; determine, from the lookup table, a third remainder and a third quotient value that both match the second remainder and the second coordinate conversion value; the target conversion result includes the increment, the third remainder, and the third quotient value.
[0074] The second remainder refers to the remainder that both matches the target quantity and the first coordinate conversion value. The increment refers to the increment in the z dimension, which may be the quotient value that both matches the target quantity and the first coordinate conversion value. The third remainder refers to the remainder that both matches the second remainder and the second coordinate conversion value, and the third quotient value refers to the quotient value that both matches the second remainder and the second coordinate conversion value.
[0075] In a feasible implementation, the second remainder and the increment that both match the target quantity and the first coordinate conversion value may be determined from the lookup table based on the target quantity and the first coordinate conversion value as the matching criteria. Similarly, the fourth remainder and the fourth quotient value that both match the third remainder and the second coordinate conversion value may be determined from the lookup table based on the third remainder and the second coordinate conversion value as the matching criteria.
[0076] Example, at this time, the calculation formula of the target conversion result can be expressed as:
[0077] z_remainer,z_increment=look_up_table(N,xy_mul);
[0078] remainder,division=look_up_table(z_remainer,x_clamp);
[0079] Among them, z_remainer represents the second remainder, z_increment represents the increment, remainder represents the third remainder, and division represents the third quotient value.
[0080] It should be noted that since both the permutation serial number and the first coordinate conversion value are constrained within N, the first remainder and the first quotient value between the permutation serial number and the first coordinate conversion value are also within N. Similarly, since the first remainder and the second coordinate conversion value are constrained within N, the second remainder and the second quotient value between the first remainder and the second coordinate conversion value are also within N. Similarly, since both the target quantity and the first coordinate conversion value are constrained within N, the third remainder and the third quotient value between the target quantity and the first coordinate conversion value are also within N. Similarly, since both the third remainder and the second coordinate conversion value are constrained within N, the fourth remainder and the fourth quotient value between the third remainder and the second coordinate conversion value are also within N. Thus, all division and remainder operations during the thread coordinate conversion can directly obtain the conversion results through the same lookup table, greatly improving the conversion rate of the thread coordinates.
[0081] Step 305: Based on the target conversion result, determine the first three-dimensional coordinates of the first thread.
[0082] In some embodiments, step 305 can be implemented through the following steps 3051 to 3053:
[0083] Step 3051: Based on the target conversion result, determine the second three-dimensional coordinates of the first thread.
[0084] In some embodiments, when the first thread is a thread processed in the first round, the specific implementation manner of step 3051 can be: taking the first quotient value as the coordinate value of the first thread in the first dimension, taking the second quotient value as the coordinate value of the first thread in the second dimension, and taking the first remainder as the coordinate value of the first thread in the third dimension to obtain the second three-dimensional coordinates.
[0085] Example, index.x = division_0, index.y = division_1, index.z = remainder_0, and at this time the second three-dimensional coordinates are (division_0, division_1, remainder_0).
[0086] In some embodiments, when the first thread is a thread processed in the i-th round, the specific implementation manner of step 3051 can be: determining the three-dimensional coordinates of the second thread determined in the (i - 1)-th round; the difference between the permutation serial number and the index of the second thread is the target quantity; based on the three-dimensional coordinates of the second thread, the third remainder, the third quotient value, and the increment, determine the second three-dimensional coordinates.
[0087] Among them, the three-dimensional coordinates of the second thread include a first coordinate value of the second thread in the first dimension, a second coordinate value of the second thread in the second dimension, and a third coordinate value of the second thread in the third dimension.
[0088] The first coordinate value refers to the coordinate value of the second thread on the x-axis, the second coordinate value refers to the coordinate value of the second thread on the y-axis, and the third coordinate value refers to the coordinate value of the second thread on the z-axis. The difference in the indices of the threads processed by any converter in two adjacent rounds is the target quantity. The second thread refers to the thread processed by the converter currently processing the first thread in the (i - 1)-th round.
[0089] In a feasible implementation manner, the specific implementation manner of "determining the second three-dimensional coordinate based on the three-dimensional coordinates of the second thread, the third remainder, the third quotient value, and the increment" may be: determining a fourth coordinate value of the first thread in the first dimension based on the first coordinate value and the third remainder; determining a fifth coordinate value of the first thread in the second dimension based on the second coordinate value and the third quotient value; determining a sixth coordinate value of the first thread in the third dimension based on the third coordinate value and the increment; and determining the second three-dimensional coordinate based on the fourth coordinate value, the fifth coordinate value, and the sixth coordinate value.
[0090] The fourth coordinate value refers to the coordinate value of the first thread on the x-axis, the fifth coordinate value refers to the coordinate value of the first thread on the y-axis, and the sixth coordinate value refers to the coordinate value of the first thread on the z-axis.
[0091] For example, if the three-dimensional coordinates of the second thread are (index.x’, index.y’, index.z’), then the fourth coordinate value index.x = index.x’ + remainder, the fifth coordinate value index.y = index.y’ + division, and index.z = index.z’ + z_increment. At this time, the second three-dimensional coordinate is (index.x’ + remainder, index.y’ + division, index.z’ + z_increment).
[0092] Step 3052: Determine the out-of-bounds situation of the second three-dimensional coordinate based on the three-dimensional size.
[0093] The out-of-bounds situation may refer to whether the index or coordinate accessed by the thread exceeds the legal range. In a multi-threaded environment, if the index or coordinate accessed by the thread exceeds the legal range, it may cause problems such as errors during program execution.
[0094] In some embodiments, step 3052 can be implemented through the following steps 3052a to 3052c:
[0095] Step 3052a, based on the magnitude relationship between the fourth coordinate value and the first quantity, determine the out-of-bounds situation of the fourth coordinate value.
[0096] In some embodiments, the specific implementation of step 3052a can be: when the fourth coordinate value is greater than or equal to the first quantity, determine that the coordinate value of the first thread in the first dimension is out of bounds; when the fourth coordinate value is less than the first quantity, determine that the fourth coordinate value is not out of bounds.
[0097] Example, if the fourth coordinate value is index.x and the first quantity is wg_size.x, the mathematical expression for determining whether the fourth coordinate value is out of bounds can be: oob_x = index.x >= wg_size.x, which means: determine whether index.x is greater than or equal to wg_size.x; if it is greater than or equal to, oob_x is assigned the value true; if it is less than, oob_x is assigned the value false.
[0098] Step 3052b, based on the magnitude relationship between the fifth coordinate value and the second quantity, determine the out-of-bounds situation of the fifth coordinate value.
[0099] In some embodiments, the specific implementation of step 3052b can be: based on the magnitude relationship between the fifth coordinate value and the second quantity, determine whether the fifth coordinate value is out of bounds; or, when the fourth coordinate value is out of bounds, update the fifth coordinate value based on a target threshold to obtain a first target fifth coordinate value; based on the magnitude relationship between the first target fifth coordinate value and the second quantity, determine whether the fifth coordinate value is out of bounds.
[0100] The first target fifth coordinate value refers to the fifth coordinate value updated based on the target threshold. In some embodiments, the target threshold can be 1. At this time, updating the fifth coordinate value based on the target threshold means adding one to the fifth coordinate value.
[0101] In a feasible implementation, the specific implementation of "based on the magnitude relationship between the fifth coordinate value and the second quantity, determine whether the fifth coordinate value is out of bounds" can be: when the fifth coordinate value is greater than or equal to the second quantity, determine that the fifth coordinate value is out of bounds; when the fifth coordinate value is less than the second quantity, determine that the fifth coordinate value is not out of bounds.
[0102] In a feasible implementation manner, the specific implementation manner of "determining whether the fifth coordinate value is out of bounds based on the magnitude relationship between the first target fifth coordinate value and the second quantity" may be: when the first target fifth coordinate value is greater than or equal to the second quantity, it is determined that the fifth coordinate value is out of bounds; when the first target fifth coordinate value is less than the second quantity, it is determined that the fifth coordinate value is not out of bounds.
[0103] For example, if the fifth coordinate value is index.y and the second quantity is wg_size.y, the mathematical expression for determining whether the fifth coordinate value is out of bounds can be: oob_y = (index.y >= wg_size.y) || ((oob_x == true) && (index.y + 1) >= wg_size.y); its meaning is as follows: The first part: index.y >= wg_size.y, which determines whether index.y is greater than or equal to wg_size.y. If so, then y is out of bounds and oob_y is true. The second part: oob_x == true is a prerequisite condition. Only when the thread is out of bounds on the x-axis will this condition be checked. The condition (index.y + 1) >= wg_size.y determines whether the thread will be out of bounds when advancing one position on the y-axis (i.e., index.y + 1). If the first part or the second part is true, then oob_y is assigned the value true, indicating that the thread is out of bounds on the y-axis. If both conditions are not met, then oob_y is assigned the value false, indicating that the thread is not out of bounds on the y-axis.
[0104] Step 3052c, determine whether the sixth coordinate value is out of bounds based on the magnitude relationship between the sixth coordinate value and the third quantity.
[0105] In some implementation manners, the specific implementation manner of step 3052c may be: determine whether the sixth coordinate value is out of bounds based on the magnitude relationship between the sixth coordinate value and the third quantity; or, when the fifth coordinate value is out of bounds, update the sixth coordinate value based on a target threshold to obtain a target sixth coordinate value; determine whether the sixth coordinate value is out of bounds based on the magnitude relationship between the target sixth coordinate value and the third quantity.
[0106] The target sixth coordinate value refers to the sixth coordinate value updated based on the target threshold. In some implementation manners, the target threshold may be 1. At this time, updating the sixth coordinate value based on the target threshold means adding one to the sixth coordinate value.
[0107] In a feasible implementation manner, the specific implementation manner of "determining whether the sixth coordinate value is out of bounds based on the magnitude relationship between the sixth coordinate value and the third quantity" may be: when the sixth coordinate value is greater than or equal to the third quantity, it is determined that the sixth coordinate value is out of bounds; when the sixth coordinate value is less than the third quantity, it is determined that the sixth coordinate value is not out of bounds.
[0108] In a feasible implementation manner, the specific implementation manner of "when the fifth coordinate value is out of bounds, determining whether the sixth coordinate value is out of bounds based on the magnitude relationship between the target sixth coordinate value and the third quantity" may be: when the target sixth coordinate value is greater than or equal to the third quantity, it is determined that the sixth coordinate value is out of bounds; when the target sixth coordinate value is less than the third quantity, it is determined that the sixth coordinate value is not out of bounds.
[0109] Example, if the sixth coordinate value is index.z and the third quantity is wg_size.z, the mathematical expression for determining whether the sixth coordinate value is out of bounds can be: oob_z = (index.z >= wg_size.z) || ((oob_y == true) && (index.z + 1) >= wg_size.z); its meaning is that the first part: index.z >= wg_size.z, determines whether index.z is greater than or equal to wg_size.z. If so, the thread is out of bounds on the z-axis and oob_z will be true. The second part: oob_y == true is a prerequisite condition, and this condition will only be checked when the thread is already out of bounds on the y-axis. (index.z + 1) >= wg_size.z determines whether the thread will be out of bounds when advancing one position on the z-axis (i.e., index.z + 1). If the condition of the first part or the second part is true, oob_z will be assigned true, indicating that the thread is out of bounds on the z-axis. If both conditions are not met, oob_z will be assigned false, indicating that the thread is not out of bounds on the z-axis.
[0110] Step 3053, update the second three-dimensional coordinate based on the out-of-bounds situation to obtain the first three-dimensional coordinate.
[0111] As shown in Table 1 below, there are the following situations for updating the second three-dimensional coordinate based on the out-of-bounds situation:
[0112] First, do not update the coordinate; when the fourth coordinate value, the fifth coordinate value, and the sixth coordinate value in the second three-dimensional coordinate are all out of bounds, output the second three-dimensional coordinate as the first three-dimensional coordinate.
[0113] Second, update the coordinate;
[0114] (1) When the fourth coordinate value has exceeded the boundary, but the fifth coordinate value and the sixth coordinate value have not exceeded the boundary, update the fourth coordinate value based on the first quantity to obtain a target fourth coordinate value; determine the first three-dimensional coordinate based on the target fourth coordinate value, the first target fifth coordinate value (the fifth coordinate value after incrementing by one), and the sixth coordinate value.
[0115] The target fourth coordinate value refers to the fourth coordinate value updated based on the first quantity.
[0116] Example, when oob_x = 1, oob_y = 0, oob_z = 0, Index.x” = index.x – wg_size.x, Index.y” = index.y + 1; where Index.x” represents the updated fourth coordinate value, Index.y” represents the first target fifth coordinate value, and the first three-dimensional coordinate at this time is (index.x – wg_size.x, index.y + 1, index.z).
[0117] (2) When the fifth coordinate value has exceeded the boundary, but the fourth coordinate value and the sixth coordinate value have not exceeded the boundary, update the fifth coordinate value based on the second quantity to obtain a second target fifth coordinate value; determine the first three-dimensional coordinate based on the fourth coordinate value, the updated fifth coordinate value, and the sixth coordinate value after incrementing by one.
[0118] The second target fifth coordinate value refers to the fifth coordinate value updated based on the second quantity.
[0119] Example, when oob_x = 0, oob_y = 1, oob_z = 0, Index.y” = Index.y - index.y, Index.z” = index.z + 1; where Index.z” represents the updated sixth coordinate value, and the first three-dimensional coordinate at this time is (index.x, Index.y - index.y, index.z + 1).
[0120] (3) When both the fourth coordinate value and the fifth coordinate value have exceeded the boundary, but the sixth coordinate value has not exceeded the boundary, update the fourth coordinate value based on the first quantity to obtain a target fourth coordinate value; update the fifth coordinate value based on the target threshold and the second quantity to obtain a third target fifth coordinate value; update the sixth coordinate value based on the target threshold to obtain a target sixth coordinate value; determine the first three-dimensional coordinate based on the target fourth coordinate value, the third target fifth coordinate value, and the target sixth coordinate value.
[0121] Among them, the third target fifth coordinate value refers to the fifth coordinate value updated based on the target threshold and the second quantity.
[0122] For example, when oob_x = 1, oob_y = 1, oob_z = 0, the target fourth coordinate value Index.x" = index.x - wg_size.x, the third target fifth coordinate value Index.y" = Index.y + 1 - wg_size.y, and the target sixth coordinate value Index.z" = index.z + 1; the first three-dimensional coordinate at this time is (index.x - wg_size.x, Index.y + 1 - wg_size.y, index.z + 1).
[0123] The third case is not to output when out of bounds; in the case where the sixth coordinate value is out of bounds, no output is made. The sixth coordinate value being out of bounds includes at least one of the following: (1) the sixth coordinate value is out of bounds, but neither the fourth coordinate value nor the fifth coordinate value is out of bounds; (2) both the sixth coordinate value and the fourth coordinate value are out of bounds, but the fifth coordinate value is not out of bounds; (3) both the sixth coordinate value and the fifth coordinate value are out of bounds, but the fourth coordinate value is not out of bounds; (4) the sixth coordinate value, the fifth coordinate value, and the fourth coordinate value are all out of bounds.
[0124] For example, when oob_x = 0, oob_y = 0, oob_z = 1, or oob_x = 1, oob_y = 0, oob_z = 1, or oob_x = 0, oob_y = 1, oob_z = 1, or oob_x = 1, oob_y = 1, oob_z = 1, the three-dimensional coordinates are not output, and the process ends directly.
[0125]
[0126] Table 1
[0127] Based on the foregoing embodiments, the thread coordinate determination method provided by the embodiments of the present disclosure may further include the following steps 306 to 308:
[0128] Step 306, when obtaining the three-dimensional size, switch the state machine corresponding to the first thread from the idle state to the initial state.
[0129] The idle state can be represented as IDLE, and the initial state can be represented as INITIAL. When the state machine is in the idle state, it means that the conversion of thread coordinates is not currently being performed; when the state machine is in the initial state, it means that the initial coordinates (the three-dimensional coordinates determined in the first round) are currently being calculated and whether the initial coordinates are out of bounds is being judged.
[0130] Step 307: When the first thread is a thread in the first round and the three-dimensional coordinates of the first thread are not output, switch the state machine from the initial state to the waiting state.
[0131] Example: If the initial coordinates are out of bounds, the initial coordinates are not output, and at the same time, the state machine is switched from INITIAL to IDLE.
[0132] Step 308: When the first three-dimensional coordinates are output, switch the state machine from the initial state to the running state to determine the three-dimensional coordinates of the next-round thread, and switch the state machine according to the out-of-bounds situation of the three-dimensional coordinates of the next-round thread.
[0133] Example: As Figure 4 shown, if the initial coordinates are not out of bounds, the initial coordinates are output, and the state machine is switched to RUNNING. After the state machine is switched to RUNNING, after increasing the corresponding step size (the target number N), the determination and out-of-bounds judgment of the coordinates of the next-round thread are performed. If it is out of bounds, the state machine is switched from RUNNING to IDLE; if it is not out of bounds, the coordinates are output, and the corresponding step size is continuously increased to perform the conversion and out-of-bounds judgment of the coordinates of the next-round thread until the coordinates of all threads in the thread working group are determined.
[0134] In the embodiments of the present disclosure, the division calculation is converted into a look-up table method, which shortens the time delay required for the division calculation. By setting the target number N to determine the number of converters to be instantiated, the number of threads that can be processed in each round is increased, the throughput rate is improved, and the hardware can be expanded at any time according to the service requirements. When expanding, it is not necessary to change the execution logic inside the converter, and only the converter needs to be added. The embodiments of the present disclosure can support calculation blocks with the same size in three dimensions, and can also support calculation blocks with different sizes in three dimensions, with strong adaptability.
[0135] Next, the application of the thread coordinate determination method provided by the embodiments of the present disclosure in an actual scenario is described.
[0136] The embodiments of the present disclosure aim to realize the conversion from thread index to three-dimensional coordinates with limited area overhead through the look-up table method. At the same time, the circuit module can increase multiple calculation instances to realize the coordinate conversion of multiple threads processed per unit time, and improve the calculation throughput rate.
[0137] As Figure 1 shown, according to the throughput rate requirements of the chip where the GPU is located, several converters can be selected for instantiation, and each converter has an identifier (unique id); the identifier of the converter takes values within [0, N - 1].
[0138] 1. As Figure 4As shown, when receiving the three - dimensional size of a new thread workgroup, N converter control state machines switch from IDLE to INITIAL, calculate the initial coordinates of each converter, and simultaneously determine whether the initial coordinates are out - of - bounds;
[0139] a) If out - of - bounds, do not output the current coordinates, and switch the state machine from INITIAL to IDLE;
[0140] b) If not out - of - bounds, output the current coordinates, and switch the state machine to RUNNING.
[0141] 2. After the state machine switches to RUNNING, it is necessary to increase the corresponding step size (the number of targets N) to determine and judge the out - of - bounds of the thread coordinates in the next round;
[0142] a) If out - of - bounds, switch the state machine from RUNNING to IDLE;
[0143] b) If not out - of - bounds, output the coordinates, and repeat step 2.
[0144] The converter needs to complete the calculation of the initial coordinates, the calculation of the coordinate increment, and the judgment of the coordinate out - of - bounds. To save chip area and shorten the latency required for calculation, the embodiments of the present disclosure use a table - lookup method and a bypass processing method to implement the division calculation in the process of thread coordinate conversion. Specifically, as Figure 5 shown, for the division operation in the thread coordinate determination method, when the divisor is 0, directly output (0, 0); when the divisor is not 0, determine the three - dimensional coordinates of the thread through the table - lookup method.
[0145] Assume that the throughput requirement of the chip where the GPU is located is to output the three - dimensional coordinates of N threads per beat (per round). Then, N converters need to be instantiated in the chip, where N must be a power of 2.
[0146] The calculation steps inside the converter are as follows:
[0147] 1. Calculate the product of the x - dimension size and the y - dimension size, and limit the product result within N, that is, take the minimum value of the product and N;
[0148] a) xy_mul = min(N, wg_size.x * wg_size.y); wg_size.x and wg_size.y respectively represent the number of threads of the workgroup on the x - axis and y - axis.
[0149] 2. Take the minimum value of the x - dimension size and N;
[0150] a) X_clamp = min(N, wg_size.x);
[0151] 3. Calculate the initial coordinates of each converter. The formula for the initial coordinates is as follows:
[0152] a) Index.x = calculator_id / xy_mul;
[0153] b) Index.y = (calculator_id % xy_mul) / x_clamp; % is the remainder operator, also known as the modulo operator
[0154] c) Index.z = calculator_id % x_clamp;
[0155] Where calculator_id is the converter identifier, xy_mul and x_clamp have been calculated in steps 1 and 2 to be values less than or equal to N, and calculator_id takes values in the range [0, N - 1]; therefore, the above division calculation can be converted into a look-up table operation of choosing 1 from N;
[0156] That is:
[0157] remainder_0, division_0 = look_up_table(calculator_id, xy_mul);
[0158] remainder_1, division_1 = look_up_table(remainder_0, x_clamp);
[0159] index.x = division_0;
[0160] index.y = division_1;
[0161] index.z = remainder_0;
[0162] 4. Determine whether the coordinates are out of bounds and perform coordinate value update and state machine jump;
[0163] a) oob_x = index.x >= wg_size.x;
[0164] b) oob_y = (index.y >= wg_size.y) || ((oob_x == true) && (index.y + 1) >= wg_size.y);
[0165] c) oob_z = (index.z >= wg_size.z) || ((oob_y == true) && (index.z + 1) >= wg_size.z);
[0166] The coordinate values need to be updated and the state machine needs to jump according to the out-of-bounds situation of the coordinates shown in Table 1 above.
[0167] 5. Calculate the coordinate increment;
[0168] After one cycle of calculation, the next cycle will skip N threads to calculate the new three-dimensional coordinates, that is, the increment for each converter is N;
[0169] Index.x = (N % xy_mul) % x_clamp;
[0170] Index.y = (N % xy_mul) / x_clamp;
[0171] Index.z = N / xy_mul;
[0172] Among them, xy_mul and x_clamp have obtained values less than or equal to N through steps 1 and 2; therefore, the above division calculation can be converted into a look-up table operation of choosing 1 from N;
[0173] That is:
[0174] a) z_remainer, z_increment = look_up_table(N, xy_mul);
[0175] b) remainder, division = look_up_table(z_remainer, x_clamp);
[0176] c) index.z = index.z + z_increment;
[0177] d) index.y = index.y + division;
[0178] e) index.x = index.x + remainder.
[0179] 6. Jump to step 4 to perform out-of-bounds judgment on the incremental coordinates.
[0180] 7. End the calculation.
[0181] Taking the target quantity N as 16 as an example, the entries in the corresponding look-up table are shown in Table 2 below:
[0182]
[0183]
[0184] The innovation point of the embodiments of the present disclosure lies in: a converter for determining the three-dimensional coordinates of threads, which can calculate the three-dimensional coordinates of threads in a thread workgroup of any size through at most two operations of the N-to-1 look-up table method. The target number N can be set as needed to instantiate multiple converters and improve the calculation throughput rate.
[0185] Based on the foregoing embodiments, the embodiments of the present disclosure provide a thread coordinate determination device, which includes each unit included and each module included in each unit, and can be implemented by a processor in a computer device; of course, it can also be implemented by specific logic circuits; in the implementation process, the processor can be a central processing unit (CPU), a microprocessor unit (MPU), a digital signal processor (DSP), or a field programmable gate array (FPGA), etc.
[0186] Figure 6 It is a schematic structural diagram of the composition of a thread coordinate determination device provided by the embodiments of the present disclosure. As Figure 6 shown, the thread coordinate determination device 600 includes: a determination module 610 and a search module 620, where:
[0187] The determination module 610 is configured to determine the three-dimensional size of the thread workgroup to which the first thread belongs, the arrangement serial number of the first thread in the current round, and the target number of threads that can be processed in each round;
[0188] The determination module 610 is further configured to determine a coordinate conversion value constrained within the target number based on the three-dimensional size and the target number;
[0189] The search module 620 is configured to determine a target conversion result between the arrangement serial number and the coordinate conversion value from a preset look-up table; the look-up table includes conversion results between all values of the arrangement serial number and all values of the coordinate conversion value;
[0190] The determination module 610 is further configured to determine the first three-dimensional coordinates of the first thread based on the target conversion result.
[0191] In some embodiments, the three-dimensional size includes a first number of threads of the thread workgroup in a first dimension and a second number of threads in a second dimension; the determining module 610 is further configured to determine a first coordinate conversion value constrained within the target number based on the first number, the second number, and the target number; determine a second coordinate conversion value constrained within the target number based on the first number and the target number; the coordinate conversion value includes the first coordinate conversion value and the second coordinate conversion value.
[0192] In some embodiments, the determining module 610 is further configured to determine a product between the first number and the second number; in a case where the product is greater than the target number, use the target number as the first coordinate conversion value; in a case where the product is less than or equal to the target number, use the product as the first coordinate conversion value.
[0193] In some embodiments, the determining module 610 is further configured to, in a case where the first number is greater than the target number, use the target number as the second coordinate conversion value; in a case where the first number is less than or equal to the target number, use the first number as the second coordinate conversion value.
[0194] In some embodiments, the coordinate conversion value includes a first coordinate conversion value and a second coordinate conversion value; the lookup module 620 is further configured to, in a case where the first thread is a thread for the first-round processing, determine, from the lookup table, a first remainder and a first quotient value that both match the permutation serial number and the first coordinate conversion value; determine, from the lookup table, a second quotient value that matches both the first remainder and the second coordinate conversion value; the target conversion result includes the first remainder, the first quotient value, and the second quotient value.
[0195] In some embodiments, the coordinate conversion value includes a first coordinate conversion value and a second coordinate conversion value; the determining module 610 is further configured to, in a case where the first thread is a thread for the i-th round of processing, determine, from the lookup table, a second remainder and an increment that both match the target number and the first coordinate conversion value; i is a positive integer greater than 1; the determination of the three-dimensional coordinates of the first thread is performed based on the three-dimensional coordinates of the thread with the same permutation serial number as the first thread within the first round; determine, from the lookup table, a third remainder and a third quotient value that both match the second remainder and the second coordinate conversion value; the target conversion result includes the increment, the third remainder, and the third quotient value.
[0196] In some embodiments, the determining module 610 is further configured to determine a second three-dimensional coordinate of the first thread based on the target conversion result; determine an out-of-bounds condition of the second three-dimensional coordinate based on the three-dimensional size; and update the second three-dimensional coordinate based on the out-of-bounds condition to obtain the first three-dimensional coordinate.
[0197] In some embodiments, when the first thread is a thread processed in the first round, the determining module 610 is further configured to use the first quotient as the coordinate value of the first thread in the first dimension, use the second quotient as the coordinate value of the first thread in the second dimension, and use the first remainder as the coordinate value of the first thread in the third dimension to obtain the second three-dimensional coordinate.
[0198] In some embodiments, when the first thread is a thread processed in the i-th round, the determining module 610 is further configured to determine the three-dimensional coordinate of a second thread determined in the (i - 1)-th round; the difference between the index of the first thread and the index of the second thread is the target quantity; and determine the second three-dimensional coordinate based on the three-dimensional coordinate of the second thread, the third remainder, the third quotient, and the increment.
[0199] In some embodiments, the three-dimensional coordinate of the second thread includes a first coordinate value of the second thread in the first dimension, a second coordinate value of the second thread in the second dimension, and a third coordinate value of the second thread in the third dimension; the determining module 610 is further configured to determine a fourth coordinate value of the first thread in the first dimension based on the first coordinate value and the third remainder; determine a fifth coordinate value of the first thread in the second dimension based on the second coordinate value and the third quotient; determine a sixth coordinate value of the first thread in the third dimension based on the third coordinate value and the increment; and determine the second three-dimensional coordinate based on the fourth coordinate value, the fifth coordinate value, and the sixth coordinate value.
[0200] In some embodiments, the three-dimensional size includes a first quantity of threads of the thread workgroup in the first dimension, a second quantity of threads of the thread workgroup in the second dimension, and a third quantity of threads of the thread workgroup in the third dimension; the second three-dimensional coordinate includes a fourth coordinate value of the first thread in the first dimension, a fifth coordinate value of the first thread in the second dimension, and a sixth coordinate value of the first thread in the third dimension; the determining module 610 is further configured to determine an out-of-bounds condition of the fourth coordinate value based on the magnitude relationship between the fourth coordinate value and the first quantity; determine an out-of-bounds condition of the fifth coordinate value based on the magnitude relationship between the fifth coordinate value and the second quantity; and determine an out-of-bounds condition of the sixth coordinate value based on the magnitude relationship between the sixth coordinate value and the third quantity.
[0201] In some embodiments, the determining module 610 is further configured to, when the fourth coordinate value is greater than or equal to the first quantity, determine that the coordinate value of the first thread in the first dimension has exceeded the boundary; when the fourth coordinate value is less than the first quantity, determine that the fourth coordinate value has not exceeded the boundary.
[0202] In some embodiments, the determining module 610 is further configured to determine whether the fifth coordinate value exceeds the boundary based on the magnitude relationship between the fifth coordinate value and the second quantity; or, when the fourth coordinate value has exceeded the boundary, update the fifth coordinate value based on a target threshold to obtain a first target fifth coordinate value; and determine whether the fifth coordinate value exceeds the boundary based on the magnitude relationship between the first target fifth coordinate value and the second quantity.
[0203] In some embodiments, the second three-dimensional coordinate includes a fourth coordinate value of the first thread in the first dimension, a fifth coordinate value in the second dimension, and a sixth coordinate value in the third dimension; the determining module 610 is further configured to, when the fourth coordinate value has exceeded the boundary but both the fifth coordinate value and the sixth coordinate value have not exceeded the boundary, update the fourth coordinate value based on the first quantity to obtain a target fourth coordinate value; update the fifth coordinate value based on a target threshold to obtain a first target fifth coordinate value; and determine the first three-dimensional coordinate based on the target fourth coordinate value, the first target fifth coordinate value, and the sixth coordinate value.
[0204] In some embodiments, the second three-dimensional coordinate includes a fourth coordinate value of the first thread in the first dimension, a fifth coordinate value in the second dimension, and a sixth coordinate value in the third dimension; the determining module 610 is further configured to, when the fifth coordinate value has exceeded the boundary but both the fourth coordinate value and the sixth coordinate value have not exceeded the boundary, update the fifth coordinate value based on the second quantity to obtain a second target fifth coordinate value; update the sixth coordinate value based on a target threshold to obtain a target sixth coordinate value; and determine the first three-dimensional coordinate based on the fourth coordinate value, the second target fifth coordinate value, and the target sixth coordinate value.
[0205] In some embodiments, the second three-dimensional coordinates include a fourth coordinate value of the first thread in a first dimension, a fifth coordinate value in a second dimension, and a sixth coordinate value in a third dimension; the determining module 610 is further configured to, when both the fourth coordinate value and the fifth coordinate value have exceeded the boundary but the sixth coordinate value has not exceeded the boundary, update the fourth coordinate value based on the first quantity to obtain a target fourth coordinate value; update the fifth coordinate value based on a target threshold and the second quantity to obtain a third target fifth coordinate value; update the sixth coordinate value based on the target threshold to obtain a target sixth coordinate value; and determine the first three-dimensional coordinates based on the target fourth coordinate value, the third target fifth coordinate value, and the target sixth coordinate value.
[0206] In some embodiments, the determining module 610 is further configured to, when obtaining the three-dimensional size, switch the state machine corresponding to the first thread from an idle state to an initial state; when the first thread is a thread in the first round and the three-dimensional coordinates of the first thread are not output, switch the state machine from the initial state to a waiting state; and when outputting the first three-dimensional coordinates, switch the state machine from the initial state to a running state to determine the three-dimensional coordinates of the thread in the next round and perform state machine switching according to the out-of-bounds situation of the three-dimensional coordinates of the thread in the next round.
[0207] The description of the above device embodiments is similar to the description of the above method embodiments and has similar beneficial effects to those of the method embodiments. In some embodiments, the functions or modules included in the device provided in the embodiments of the present disclosure can be used to execute the methods described in the above method embodiments. For the technical details not disclosed in the device embodiments of the present disclosure, please refer to the description of the method embodiments of the present disclosure for understanding.
[0208] It should be noted that in the embodiments of the present disclosure, if the above thread coordinate determination method is implemented in the form of a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the embodiments of the present disclosure, in essence or the part that contributes to the related art, can be embodied in the form of a software product. The software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in the embodiments of the present disclosure. The foregoing storage medium includes: various media such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a magnetic disk, or an optical disc that can store program codes. In this way, the embodiments of the present disclosure are not limited to any specific hardware, software, or firmware, or any arbitrary combination of hardware, software, and firmware.
[0209] An embodiment of the present disclosure provides a computer device, including a memory and a processor. The memory stores a computer program that can run on the processor, and when the processor executes the program, some or all of the steps in the above method are implemented.
[0210] An embodiment of the present disclosure provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, some or all of the steps in the above method are implemented. The computer-readable storage medium can be transient or non-transient.
[0211] An embodiment of the present disclosure provides a computer program, including computer-readable code. When the computer-readable code runs in a computer device, the processor in the computer device executes to implement some or all of the steps in the above method.
[0212] An embodiment of the present disclosure provides a computer program product. The computer program product includes a non-transient computer-readable storage medium storing a computer program. When the computer program is read and executed by a computer, some or all of the steps in the above method are implemented. The computer program product can be specifically implemented by means of hardware, software, or a combination thereof. In some embodiments, the computer program product is specifically embodied as a computer storage medium. In other embodiments, the computer program product is specifically embodied as a software product, such as a Software Development Kit (SDK), etc.
[0213] It should be noted here that: the descriptions of the above embodiments tend to emphasize the differences between the embodiments, and their similarities or similarities can be referred to each other. The descriptions of the above device, storage medium, computer program, and computer program product embodiments are similar to the descriptions of the above method embodiments and have beneficial effects similar to those of the method embodiments. For the technical details not disclosed in the embodiments of the device, storage medium, computer program, and computer program product of the present disclosure, please refer to the descriptions of the method embodiments of the present disclosure for understanding.
[0214] It should be noted that Figure 7 is a schematic diagram of a hardware entity of the computer device in the embodiment of the present disclosure. As Figure 7 shown, the hardware entity of the computer device 700 includes: a processor 701, a communication interface 702, and a memory 703, where:
[0215] The processor 701 generally controls the overall operation of the computer device 700.
[0216] The communication interface 702 can enable the computer device to communicate with other terminals or servers through a network.
[0217] The memory 703 is configured to store instructions and applications executable by the processor 701, and can also cache data to be processed or already processed by the processor 701 and each module in the computer device 700 (such as, image data, audio data, voice communication data, and video communication data), and can be implemented by flash memory (FLASH) or random access memory (RAM). Data transmission can be performed between the processor 701, the communication interface 702, and the memory 703 through the bus 704.
[0218] It should be understood that the "one embodiment" or "an embodiment" mentioned throughout the specification means that the specific features, structures, or characteristics related to the embodiment are included in at least one embodiment of the present disclosure. Therefore, the appearances of "in one embodiment" or "in an embodiment" throughout the specification do not necessarily refer to the same embodiment. In addition, these specific features, structures, or characteristics can be combined in one or more embodiments in any suitable manner. It should be understood that in various embodiments of the present disclosure, the magnitudes of the serial numbers of the above steps / processes do not mean the order of execution is prior or subsequent. The order of execution of each step / process should be determined by its function and internal logic, and should not constitute any limitation to the implementation process of the embodiments of the present disclosure. The serial numbers of the embodiments of the present disclosure above are only for description and do not represent the superiority or inferiority of the embodiments.
[0219] It should be noted that in this article, the term "comprising", "including" or any other variant thereof is intended to cover a non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed, or further includes elements inherent to such process, method, article or device. Without further limitation, the element defined by the statement "including a..." does not exclude the existence of additional identical elements in the process, method, article or device including the element.
[0220] In several embodiments provided by the present disclosure, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only illustrative. For example, the division of the units is only a logical function division, and there can be other division methods in actual implementation. For example, multiple units or components can be combined, or can be integrated into another system, or some features can be ignored, or not executed. In addition, the couplings between the components shown or discussed, or direct couplings, or communication connections can be through some interfaces. The indirect couplings or communication connections of devices or units can be electrical, mechanical or other forms.
[0221] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units; they may be located in one place or distributed across multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0222] In addition, each functional unit in the embodiments of the present disclosure may be all integrated in a processing unit, or each unit may be separately regarded as a unit, or two or more units may be integrated in one unit; the above-mentioned integrated unit may be implemented in the form of hardware or in the form of a hardware plus software functional unit.
[0223] Those of ordinary skill in the art can understand that all or part of the steps to implement the above method embodiments can be completed by hardware related to program instructions. The foregoing program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps including the above method embodiments; and the foregoing storage medium includes: removable storage devices, read-only memory (ROM), magnetic disks, or optical discs and other various media that can store program codes.
[0224] Alternatively, if the above-mentioned integrated unit of the present disclosure is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present disclosure essentially or the part that contributes to the related technology can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in the embodiments of the present disclosure. And the foregoing storage medium includes: removable storage devices, ROM, magnetic disks, or optical discs and other various media that can store program codes.
[0225] The above is only the implementation manner of the present disclosure, but the protection scope of the present disclosure is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present disclosure, and all of them should be covered by the protection scope of the present disclosure.
Claims
1. A method for determining thread coordinates, characterized in that The thread coordinate determination method includes: Determine the three-dimensional size of the thread workgroup to which the first thread belongs, the arrangement serial number of the first thread in the current round, and the target number of threads that can be processed in each round; Based on the three-dimensional size and the target number, determine the coordinate conversion value constrained within the target number; From a preset lookup table, determine the target conversion result between the arrangement serial number and the coordinate conversion value; the lookup table includes the conversion results between all values of the arrangement serial number and all values of the coordinate conversion value; Based on the target conversion result, determine the first three-dimensional coordinates of the first thread.
2. The method for determining thread coordinates according to claim 1, wherein The three-dimensional size includes the first number of threads of the thread workgroup in the first dimension and the second number of threads in the second dimension; The determining the coordinate conversion value constrained within the target number based on the three-dimensional size and the target number includes: Based on the first number, the second number, and the target number, determine the first coordinate conversion value constrained within the target number; Based on the first number and the target number, determine the second coordinate conversion value constrained within the target number; the coordinate conversion value includes the first coordinate conversion value and the second coordinate conversion value.
3. The method for determining thread coordinates according to claim 2, characterized in that, The determining the first coordinate conversion value constrained within the target number based on the first number, the second number, and the target number includes: Determine the product between the first number and the second number; When the product is greater than the target number, use the target number as the first coordinate conversion value; When the product is less than or equal to the target number, use the product as the first coordinate conversion value.
4. The thread coordinate determination method according to claim 2, characterized in that, The determining the second coordinate conversion value constrained within the target number based on the first number and the target number includes: When the first number is greater than the target number, use the target number as the second coordinate conversion value; When the first number is less than or equal to the target number, use the first number as the second coordinate conversion value.
5. The method for determining thread coordinates according to any one of claims 1 to 4, characterized in that, The coordinate conversion value includes the first coordinate conversion value and the second coordinate conversion value; The determining the target conversion result between the arrangement serial number and the coordinate conversion value from a preset lookup table includes: When the first thread is a thread processed in the first round, from the lookup table, determine the first remainder and the first quotient value that match both the arrangement serial number and the first coordinate conversion value; From the lookup table, determine the second quotient value that matches both the first remainder and the second coordinate conversion value; the target conversion result includes the first remainder, the first quotient value, and the second quotient value.
6. The thread coordinate determination method according to any one of claims 1 to 4, characterized in that The coordinate conversion value includes the first coordinate conversion value and the second coordinate conversion value; The determining the target conversion result between the arrangement serial number and the coordinate conversion value from a preset lookup table includes: When the first thread is the thread for the i-th round of processing, determine, from the lookup table, a second remainder and an increment that both match the target quantity and the first coordinate conversion value; i is a positive integer greater than 1; the determination of the three-dimensional coordinates of the first thread is based on the three-dimensional coordinates of the thread with the same arrangement serial number as the first thread within the first round; Determine, from the lookup table, a third remainder and a third quotient value that both match the second remainder and the second coordinate conversion value; the target conversion result includes the increment, the third remainder, and the third quotient value.
7. The thread coordinate determination method according to any one of claims 1 to 4, characterized in that The determining of the first three-dimensional coordinates of the first thread based on the target conversion result includes: Determine the second three-dimensional coordinates of the first thread based on the target conversion result; Determine the out-of-bounds situation of the second three-dimensional coordinates based on the three-dimensional size; Update the second three-dimensional coordinates based on the out-of-bounds situation to obtain the first three-dimensional coordinates.
8. The thread coordinate determination method according to claim 5, characterized in that, The determining of the second three-dimensional coordinates of the first thread based on the target conversion result includes: When the first thread is the thread for the first round of processing, use the first quotient value as the coordinate value of the first thread in the first dimension, use the second quotient value as the coordinate value of the first thread in the second dimension, and use the first remainder as the coordinate value of the first thread in the third dimension to obtain the second three-dimensional coordinates.
9. The thread coordinate determination method according to claim 6, characterized in that, The determining of the second three-dimensional coordinates of the first thread based on the target conversion result includes: When the first thread is the thread for the i-th round of processing, determine the three-dimensional coordinates of the second thread determined within the (i - 1)-th round; the difference between the index of the first thread and the index of the second thread is the target quantity; Determine the second three-dimensional coordinates based on the three-dimensional coordinates of the second thread, the third remainder, the third quotient value, and the increment.
10. The method for determining thread coordinates according to claim 9, wherein The three-dimensional coordinates of the second thread include a first coordinate value of the second thread in the first dimension, a second coordinate value of the second thread in the second dimension, and a third coordinate value of the second thread in the third dimension; The determining of the second three-dimensional coordinates based on the three-dimensional coordinates of the second thread, the third remainder, the third quotient value, and the increment includes: Determine a fourth coordinate value of the first thread in the first dimension based on the first coordinate value and the third remainder; Determine a fifth coordinate value of the first thread in the second dimension based on the second coordinate value and the third quotient value; Determine a sixth coordinate value of the first thread in the third dimension based on the third coordinate value and the increment; Determine the second three-dimensional coordinates based on the fourth coordinate value, the fifth coordinate value, and the sixth coordinate value.
11. The method for determining thread coordinates according to claim 7, characterized in that, The three-dimensional size includes a first number of threads of the thread workgroup in a first dimension, a second number of threads of the thread workgroup in a second dimension, and a third number of threads of the thread workgroup in a third dimension; the second three-dimensional coordinates include a fourth coordinate value of the first thread in the first dimension, a fifth coordinate value in the second dimension, and a sixth coordinate value in the third dimension; Determining an out-of-bounds situation of the second three-dimensional coordinates based on the three-dimensional size includes: Determining an out-of-bounds situation of the fourth coordinate value based on a magnitude relationship between the fourth coordinate value and the first number; Determining an out-of-bounds situation of the fifth coordinate value based on a magnitude relationship between the fifth coordinate value and the second number; Determining an out-of-bounds situation of the sixth coordinate value based on a magnitude relationship between the sixth coordinate value and the third number.
12. The thread coordinate determination method according to claim 11, characterized in that, Determining an out-of-bounds situation of the fourth coordinate value based on a magnitude relationship between the fourth coordinate value and the first number includes: Determining that the coordinate value of the first thread in the first dimension is out of bounds when the fourth coordinate value is greater than or equal to the first number; Determining that the fourth coordinate value is not out of bounds when the fourth coordinate value is less than the first number.
13. The thread coordinate determination method according to claim 11, characterized in that, Determining an out-of-bounds situation of the fifth coordinate value based on a magnitude relationship between the fifth coordinate value and the second number includes: Determining whether the fifth coordinate value is out of bounds based on a magnitude relationship between the fifth coordinate value and the second number; or, When the fourth coordinate value is out of bounds, updating the fifth coordinate value based on a target threshold to obtain a first target fifth coordinate value; determining whether the fifth coordinate value is out of bounds based on a magnitude relationship between the first target fifth coordinate value and the second number.
14. The thread coordinate determination method according to claim 7, characterized in that, The second three-dimensional coordinates include a fourth coordinate value of the first thread in the first dimension, a fifth coordinate value in the second dimension, and a sixth coordinate value in the third dimension; Updating the second three-dimensional coordinates based on the out-of-bounds situation to obtain the first three-dimensional coordinates includes: When the fourth coordinate value is out of bounds but the fifth and sixth coordinate values are not out of bounds, updating the fourth coordinate value based on the first number to obtain a target fourth coordinate value; Updating the fifth coordinate value based on a target threshold to obtain a first target fifth coordinate value; Determining the first three-dimensional coordinates based on the target fourth coordinate value, the first target fifth coordinate value, and the sixth coordinate value.
15. The method for determining thread coordinates according to claim 7, characterized in that, The second three-dimensional coordinates include a fourth coordinate value of the first thread in the first dimension, a fifth coordinate value in the second dimension, and a sixth coordinate value in the third dimension; Updating the second three-dimensional coordinates based on the out-of-bounds situation to obtain the first three-dimensional coordinates includes: When the fifth coordinate value is out of bounds but the fourth and sixth coordinate values are not out of bounds, updating the fifth coordinate value based on the second number to obtain a second target fifth coordinate value; Updating the sixth coordinate value based on a target threshold to obtain a target sixth coordinate value; Determine the first three-dimensional coordinate based on the fourth coordinate value, the second target fifth coordinate value, and the target sixth coordinate value.
16. The thread coordinate determination method according to any one of claims 7 to 13, characterized in that The second three-dimensional coordinate includes the fourth coordinate value of the first thread in the first dimension, the fifth coordinate value in the second dimension, and the sixth coordinate value in the third dimension; The updating the second three-dimensional coordinate based on the out-of-bounds situation and determining the first three-dimensional coordinate includes: In the case where both the fourth coordinate value and the fifth coordinate value are out of bounds, but the sixth coordinate value is not out of bounds, update the fourth coordinate value based on the first quantity to obtain a target fourth coordinate value; Update the fifth coordinate value based on a target threshold and the second quantity to obtain a third target fifth coordinate value; Update the sixth coordinate value based on a target threshold to obtain a target sixth coordinate value; Determine the first three-dimensional coordinate based on the target fourth coordinate value, the third target fifth coordinate value, and the target sixth coordinate value.
17. The thread coordinate determination method according to any one of claims 1 to 4, or 8 to 16, characterized in that The thread coordinate determination method further includes: When obtaining the three-dimensional size, switch the state machine corresponding to the first thread from the idle state to the initial state; When the first thread is a thread in the first round and does not output the three-dimensional coordinate of the first thread, switch the state machine from the initial state to the waiting state; When outputting the first three-dimensional coordinate, switch the state machine from the initial state to the running state to determine the three-dimensional coordinate of the thread in the next round, and perform the switching of the state machine according to the out-of-bounds situation of the three-dimensional coordinate of the thread in the next round.
18. A thread coordinate determination device, characterized in that, The thread coordinate determination device includes: A determination module, configured to determine the three-dimensional size of the thread workgroup to which the first thread belongs, the arrangement serial number of the first thread in the current round, and the target number of threads that can be processed in each round; The determination module is further configured to determine a coordinate conversion value constrained within the target number based on the three-dimensional size and the target number; A lookup module, configured to determine a target conversion result between the arrangement serial number and the coordinate conversion value from a preset lookup table; the lookup table includes conversion results between all values of the arrangement serial number and all values of the coordinate conversion value; The determination module is further configured to determine the first three-dimensional coordinate of the first thread based on the target conversion result.
19. A computer device, comprising a memory and a processor, the memory storing a computer program that can run on the processor, characterized in that, When the processor executes the program, it implements the steps of the method according to any one of claims 1 to 17.
20. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the method according to any one of claims 1 to 17.
21. A computer program product, the computer program product includes a non-transitory computer-readable storage medium storing a computer program, and when the computer program is read and executed by a computer, it implements the steps of the method according to any one of claims 1 to 17.
Citation Information
Cited By
Thread bundle construction device and method and processor
CN120973501A
Obtaining method of target thread index, electronic equipment and medium
CN120994255A