Device used to exchange data between threads
By designing a data exchange device between threads and using index generation, storage and query units, the problem of data exchange between any threads in the existing technology is solved, the data exchange of any thread within the thread warp is realized, and the consumption of hardware resources is reduced And supports multiple application scenarios.
Patent Information
- Application Number
- CN202410760817.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-13
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2044-06-13
AI Technical Summary
Existing inter-thread data exchange modes, such as up, down, and butterfly modes, can only realize data exchange between specific threads, and it is difficult to realize data exchange between any threads.
A device is designed, which includes an index generation unit, an index storage unit, an index query unit and a data exchange unit. It generates index information through mask signals, stores and queries index information, and realizes data exchange between any threads.
It realizes data exchange between any threads in the thread warp, simplifies the data exchange process, reduces hardware resource consumption, and supports multiple application scenarios.
Smart Images

Figure CN118350981B
Abstract
Description
Technical Field
[0001] Embodiments of the present disclosure generally relate to the field of data exchange (shuffle) between threads, and more particularly to a device for performing data exchange between threads. Background Art
[0002] In GPGPU (general purpose graphics processing unit), in some scenarios, different threads need to access each other's data. Ways to achieve data access between different threads include data exchange (shuffle). Data exchange modes include up, down, and butterfly data exchange. These data exchange modes can only achieve data exchange between specific threads among a specific number of threads. There are many difficulties in achieving data exchange between any threads.
[0003] In summary, it is difficult to implement data exchange between arbitrary threads. Summary of the invention
[0004] In view of the above problems, the present disclosure provides a device for exchanging data between threads. The device can implement data exchange between any threads in a sub-warp for multiple threads.
[0005] According to one aspect of the present disclosure, a device for exchanging data between threads is provided. The device includes: an index generation unit, configured to generate index information corresponding to each thread in a sub-thread bundle according to a mask signal for defining a sub-thread bundle in a thread bundle; an index storage unit, configured to store the index information in a predetermined order; an index query unit, electrically connected to the index storage unit, configured to query the index storage unit according to the offset information corresponding to the data exchange instruction to obtain the corresponding index information; and a data exchange unit, electrically connected to the index query unit, configured to perform data exchange for the queried index information and the source thread and the target thread corresponding to the mask signal.
[0006] In some embodiments, the mask signal includes a mask field corresponding to each thread in the sub-thread warp respectively; the index generation unit is further configured to determine the first index information corresponding to the thread corresponding to the mask field according to the order of the mask field in the mask signal.
[0007] In some embodiments, the index generation unit is further configured to identify threads corresponding to the same mask field as threads in the same sub-warp, and generate corresponding second index information for each thread in the same sub-warp.
[0008] In some embodiments, the index generation unit is further configured to use the second index information as write address information, the first index information as write data information, and store the first index information in the index storage unit, where the first index information is global index information.
[0009] In some embodiments, the index query unit is further configured to read the corresponding first index information from the index storage unit using the offset information as read address information.
[0010] In some embodiments, the data exchange unit includes a data query unit, and the data query unit is configured to use the first index information as a query address to query data corresponding to the target thread.
[0011] In some embodiments, the data query unit includes a multiplexer, which includes: multiple data input terminals, configured to respectively receive data corresponding to the multiple threads; a selection control terminal, configured to receive the first index information; and a data output terminal, configured to output data corresponding to the target thread.
[0012] In some embodiments, the index generation unit includes: a first counting unit, configured to count the mask fields in the mask signal in sequence so as to use the first count value corresponding to the mask field as the first ordering of the mask field in the mask signal, and the first ordering as the first index information; and a second counting unit, configured to count the mask fields in the same sub-thread bundle in sequence so as to use the second count value corresponding to the mask field as the second ordering corresponding to the mask field in the sub-thread bundle, and the second ordering as the second index information.
[0013] In some embodiments, the data exchange unit is further configured to determine whether the source thread and the target thread belong to the same sub-thread warp, and in response to determining that the source thread and the target thread belong to the same sub-thread warp, perform data exchange on the source thread and the target thread, and in response to determining that the source thread and the target thread do not belong to the same sub-thread warp, not perform data exchange on the source thread and the target thread.
[0014] In some embodiments, the index generation unit is also configured to generate the index information in response to multiple mask signals used to define multiple sub-thread bundles in the thread bundle in sequence; there are multiple index storage units, and the multiple index storage units are configured to respectively store index information corresponding to the multiple sub-thread bundles; there are multiple index query units, and the multiple index query units are respectively electrically connected to the multiple index storage units, and the multiple index query units are configured to: query the corresponding index storage units according to the offset information corresponding to the multiple data exchange instructions corresponding to the multiple sub-thread bundles to obtain the corresponding index information; and there are multiple data exchange units, and the multiple data exchange units are respectively electrically connected to the multiple index query units, and the multiple data exchange units are configured to: exchange data for the source thread and the target thread corresponding to the queried index information and the mask signal.
[0015] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. In the accompanying drawings, the same or similar reference numerals represent the same or similar elements.
[0017] Figure 1 A block diagram of an apparatus for exchanging data between threads according to an embodiment of the present disclosure is shown.
[0018] Figure 2 A schematic diagram of an apparatus for exchanging data between threads according to an embodiment of the present disclosure is shown.
[0019] Figure 3 A schematic diagram of a data query unit according to an embodiment of the present disclosure is shown.
[0020] Figure 4 A schematic diagram of an apparatus for exchanging data between threads according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0021] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0022] As used herein, the term "including" and its variations mean open inclusion, i.e., "including but not limited to". Unless otherwise stated, the term "or" means "and / or". The term "based on" means "based at least in part on". The terms "an example embodiment" and "an embodiment" mean "at least one example embodiment". The term "another embodiment" means "at least one additional embodiment". The terms "first", "second", etc. may refer to different or the same objects. Other explicit and implicit definitions may also be included below.
[0023] As described above, the current modes for implementing data exchange between threads include up, down, and butterfly data exchange. Taking a sub-thread warp with 8 threads (e.g., corresponding numbers 0 to 7) as an example, using the up mode, the data of each thread can be exchanged with the thread with a higher number (e.g., the number increases by 1), for example, the data of thread n is provided to thread (n+1), where n∈[0,6], and for thread 7, its data is provided to thread 0. Similarly, using the down mode, the data of each thread can be exchanged with the thread with a lower number (e.g., the number decreases by 1), for example, the data of thread n is provided to thread (n-1), where n∈[1,7], and for thread 0, its data is provided to thread 7. In addition, the butterfly mode can also be used to implement data exchange between threads with symmetrical relationships, for example, data exchange between thread 0 and thread 7, data exchange between thread 1 and thread 6, etc., which will not be described in detail.
[0024] It can be seen that the up, down, and butterfly data exchange modes can only exchange data between specific threads, that is, they can only realize data exchange between threads with specific (or established) relationships. However, in actual applications, there is a demand for data exchange between unspecified threads (or arbitrary threads). However, there are many difficulties in exchanging data between arbitrary threads.
[0025] In order to at least partially solve one or more of the above problems and other potential problems, a device for exchanging data between threads is provided. The index generation unit generates index information according to a mask signal for limiting a sub-thread bundle in a thread bundle, and the index information can identify the corresponding thread in the sub-thread bundle. The index information corresponding to the thread is stored in an index storage unit in a predetermined order. The index query unit queries the index storage unit according to the offset information corresponding to the data exchange instruction to obtain the corresponding index information, and the corresponding index information can identify the target thread for data exchange. The data exchange unit performs data exchange for the queried index information and the source thread and the target thread corresponding to the mask signal. Therefore, the device for exchanging data between threads can realize data exchange between any threads in the sub-thread bundle in the thread bundle.
[0026] The method of the embodiment of the present disclosure is described in detail below. Figure 1 A block diagram of an apparatus 100 for exchanging data between threads according to an embodiment of the present disclosure is shown. Figure 2 A schematic diagram of an apparatus 100 for exchanging data between threads according to an embodiment of the present disclosure is shown. The apparatus 100 includes an index generating unit 102 , an index storing unit 104 , an index query unit 106 , and a data exchanging unit 108 .
[0027] Regarding the index generation unit 102, it generates index information corresponding to each thread in the sub-warp according to the mask signal used to define the sub-warp in the warp. That is, the index generation unit 102 determines at least one sub-warp among the multiple threads according to the mask information corresponding to the multiple threads in the warp, and the sub-warp includes at least one thread. In some embodiments, a sub-warp includes multiple threads. In some embodiments, a sub-warp includes one thread.
[0028] Taking a warp with 32 threads as an example, the mask information corresponding to the multiple threads in the warp is represented by a "sub-warp mask" (sub_warp_mask). The mask information includes multiple mask fields corresponding to the multiple threads. For example, sub_warp_mask has 32 bits, each of which corresponds to a thread in the warp, that is, each bit in sub_warp_mask is a mask field corresponding to a thread. For example, sub_warp_mask can be "0x0000_0006", that is, the values of the second and first bits of sub_warp_mask are "1", which indicates that threads 2 and thread 1 in the warp constitute a sub-warp. For example, sub_warp_mask is "0xe000_0000", that is, the values of the 31st, 30th and 29th bits of sub_warp_mask are "1", which indicates that threads 31, 30 and 29 in the warp constitute a sub-warp. That is, threads with the same mask field (ie, the values of the corresponding mask fields are the same) belong to the same sub-warp.
[0029] It should be understood that, in some embodiments, the number of bits contained in the mask information corresponding to the multiple threads in the warp may be a multiple of the number of threads contained in the warp. That is, each mask field may have multiple bits of data. For example, for a warp with 32 threads, sub_warp_mask has 32*n bits (n is an integer greater than or equal to 2), where each n bits of data is a mask field, and each mask field corresponds to a thread. The index generation unit 102 identifies threads corresponding to the same mask field as threads in the same sub-warp. A warp may be divided into multiple sub-warps, for example, based on the mask information corresponding to the multiple threads in the warp.
[0030] For example, the apparatus 100 performs data exchange between different threads in the same sub-warp, but does not perform data exchange between multiple threads belonging to different sub-warps.
[0031] The index generation unit 102 generates index information corresponding to each thread in the sub-thread warp according to the mask signal for defining the sub-thread warp in the thread warp. For example, the index generation unit 102 includes a first counting unit and a second counting unit. The first counting unit is configured to count the mask fields in the mask signal in sequence so as to use the first count value corresponding to the mask field as the first sorting of the mask field in the mask signal, and the first sorting is used as the first index information. That is, the first counting unit counts the mask fields in the mask information one by one so as to determine the first count value corresponding to the current mask field, and the count value can be used as the sorting (for example, sequence number) of the current mask field in the mask signal, and the sorting can be used as the global index information corresponding to the current mask field. It should be understood that the global index information corresponding to the current mask field is the global index information of the thread corresponding to the mask field. The global index information is used as the "first index information". Therefore, it should be understood that the first index information (global index information) corresponding to the thread can be the sorting information of the thread in the thread warp.
[0032] The second counting unit is configured to count the mask fields in the same sub-thread warp in sequence, so as to use the second count value corresponding to the mask field as the second sorting corresponding to the mask field in the sub-thread warp, and the second sorting is used as the second index information. That is, the second counting unit counts the same mask field of the mask information, and the obtained second count value about the current mask field can be used as the mask field to determine the relative index information corresponding to the current mask field. Therefore, it should be understood that the second index information (relative index information) corresponding to the thread can be the sorting information of the thread in the sub-thread warp to which the thread belongs.
[0033] Taking sub_warp_mask = 8'b1101_0110 as an example, it is the mask information for a warp with 8 threads, where each bit is a mask field corresponding to a thread, for example, the nth bit of sub_warp_mask corresponds to thread n, where n∈[0,7]. The mask field with a value of "0" in sub_warp_mask (it should be understood that each bit is a mask field) indicates that the thread corresponding to the mask field is "invalid". The mask field with a value of "1" in sub_warp_mask indicates that the threads corresponding to the mask field belong to the same sub-thread. That is, in this identification, for a thread with a mask field value of "0", it is regarded as an "invalid" thread, and is not regarded as belonging to a sub-thread. For a thread with a mask field value of "1", it is regarded as belonging to a sub-thread.
[0034] For ease of explanation, the multiple mask fields in the mask information are referred to as "mask field 0", "mask field 1", "mask field 2", ... "mask field 7" in order from low to high according to their corresponding positions. Among them, the mask field at the rightmost side of the mask information is the lowest mask field, and the mask field at the leftmost side of the mask information is the highest mask field. In some embodiments, the first counting unit counts the mask fields one by one from low to high starting from the lowest mask field (mask field 0) for sub_warp_mask. For example, for the lowest mask field (mask field 0) of sub_warp_mask, the first count value of the first counting unit is "0" ("0" is, for example, the initial value of the first counting unit), and the first count value "0" is used as the global index information of the thread corresponding to mask field 0, that is, the first ranking of the thread corresponding to mask field 0 in the thread warp is "0", that is, the thread corresponding to mask field 0 is thread 0. In addition, since the value of the lowest mask field (mask field 0) of sub_warp_mask is "0", thread 0 corresponding to mask field 0 does not belong to the sub-warp. Therefore, for thread 0, the second counting unit does not count, that is, thread 0 does not have a corresponding second counting value.
[0035] Next, for mask field 1, the first count value of the first counting unit is "1", and the first count value "1" is used as the global index information of the thread corresponding to mask field 1. That is, the thread corresponding to mask field 1 is thread 1. In addition, since the value of mask field 1 is "1", for mask field 1, the second counting unit uses its initial value "0" as the corresponding second count value and as the relative index information (second index information). That is, the relative index information corresponding to thread 1 is "0", or in other words, the ranking of thread 1 in the sub-thread warp is "0".
[0036] It should be understood that each thread in each thread bundle has the corresponding relative index information, and an "invalid" thread, or a thread that does not belong to the sub-thread bundle, does not have the relative index information about the thread bundle. It should be understood that the first counting unit counts each mask field in the mask information one by one. The second counting unit only counts the mask field corresponding to the thread in the sub-thread bundle, and the thread that does not belong to the sub-thread bundle does not have the relative index information corresponding to the sub-thread bundle. When there are multiple sub-thread bundles in a thread bundle, multiple second counting units can be configured, each counting unit corresponding to a sub-thread bundle, so as to count the thread bundle.
[0037] Next, the index generation unit 102 uses the relative index information corresponding to thread 1 as address information and the global index information corresponding to thread 1 as data information to store the global index information corresponding to thread 1 in the index storage unit 104. For example, the global index information "1" corresponding to thread 1 is stored as data information in the storage space at the address "0" in the index storage unit 104.
[0038] By analogy, for mask field 2, the first count value of the first counting unit is "2", and the first count value "2" serves as the global index information of the thread corresponding to mask field 2. That is, the thread corresponding to mask field 2 is thread 2. In addition, since the value of mask field 2 is "1", the second count value of the second counting unit is "1" for mask field 2, and serves as the relative index information of mask field 2. That is, the relative index information corresponding to thread 2 is "1", or in other words, the ranking of thread 2 in the sub-thread warp is "1". The index generation unit 102 uses the relative index information corresponding to thread 2 as the address information and the global index information corresponding to thread 2 as the data information, and stores the global index information corresponding to thread 2 in the index storage unit 104. For example, the global index information "2" corresponding to thread 2 is stored as data information in the storage space with the address "1" in the index storage unit 104.
[0039] For mask field 3, the first count value of the first count unit is "3", and the first count value "3" is used as the global index information of the thread corresponding to mask field 3. That is, the thread corresponding to mask field 3 is thread 3. There is no corresponding relative index information for thread 3. Therefore, the global index information of thread 3 will not be stored in the index storage unit 104.
[0040] For mask field 4, the first count value of the first count unit is "4", and the first count value "4" serves as the global index information of the thread corresponding to mask field 4. That is, the thread corresponding to mask field 4 is thread 4. For thread 4, the second count value of the second count unit is "2", and serves as the relative index information of thread 4. That is, the relative index information corresponding to thread 4 is "2". The index generation unit 102 uses the relative index information corresponding to thread 4 as address information and the global index information corresponding to thread 4 as data information, and stores the global index information corresponding to thread 4 in the index storage unit 104. For example, the global index information "4" corresponding to thread 4 is stored as data information in the storage space with address "2" in the index storage unit 104.
[0041] For mask field 5, the first count value of the first count unit is "5", and the first count value "5" is used as the global index information of the thread corresponding to mask field 5. That is, the thread corresponding to mask field 5 is thread 5. There is no corresponding relative index information for thread 5. Therefore, the global index information of thread 3 will not be stored in the index storage unit 104.
[0042] For mask field 6, the first count value of the first counting unit is "6", and the first count value "6" serves as the global index information of the thread corresponding to mask field 6. That is, the thread corresponding to mask field 6 is thread 6. For thread 6, the second count value of the second counting unit is "3", and serves as the relative index information of thread 6. That is, the relative index information corresponding to thread 6 is "3". The index generation unit 102 uses the relative index information corresponding to thread 6 as address information and the global index information corresponding to thread 6 as data information, and stores the global index information corresponding to thread 6 in the index storage unit 104. For example, the global index information "6" corresponding to thread 6 is stored as data information in the storage space with address "3" in the index storage unit 104.
[0043] For mask field 7, the first count value of the first counting unit is "7", and the first count value "7" serves as the global index information of the thread corresponding to mask field 7. That is, the thread corresponding to mask field 7 is thread 7. For thread 7, the second count value of the second counting unit is "4", and serves as the relative index information of thread 7. That is, the relative index information corresponding to thread 7 is "4". The index generation unit 102 uses the relative index information corresponding to thread 7 as address information and the global index information corresponding to thread 7 as data information, and stores the global index information corresponding to thread 7 in the index storage unit 104. For example, the global index information "7" corresponding to thread 7 is stored as data information in the storage space with address "4" in the index storage unit 104.
[0044] Therefore, for this thread warp, the storage space corresponding to address "0" of the index storage unit 104 stores global index information "1" corresponding to thread 1; the storage space corresponding to address "1" of the index storage unit 104 stores global index information "2" corresponding to thread 2; the storage space corresponding to address "2" of the index storage unit 104 stores global index information "4" corresponding to thread 4; the storage space corresponding to address "3" of the index storage unit 104 stores global index information "6" corresponding to thread 6; the storage space corresponding to address "4" of the index storage unit 104 stores global index information "7" corresponding to thread 7. The global index information is represented by "phy_thread_id", for example, and the register used for the global index information is represented by "global_dem_index", for example.
[0045] The above operations performed by the index generation unit 102 may be implemented with reference to the following pseudo code:
[0046] k=0;
[0047] for(i=0;i<8;i++) begin
[0048] if(sub_warp_mask[i] ==1) begin
[0049] global_dem_index[k] = i;
[0050] k=k+1;
[0051] end
[0052] end
[0053] for(j=0;j<8;j++) begin
[0054] phy_thread_id[j] = sub_warp_mask[j] ?
[0055] global_dem_index[lane_offset[j]] : j;
[0056] dst_data[j] = src_data[phy_thread_id[j]];
[0057] end
[0058] Referring to the pseudocode, for example, the first request for data exchange carries sub_warp_mask and src_data (source data of multiple threads). sub_warp_mask can, for example, reflect the validity of threads in a sub-warp bundle ("valid" is considered to belong to the defined sub-warp bundle). src_data is a set of data carried by each thread. The second request carries lane_offset (offset information), which represents the data corresponding to the valid thread in sub_warp_mask that the target thread needs to obtain (that is, the relative index information of the target thread with which the current thread wants to exchange data). Similarly, lane_offset is also a set of data, which can contain multiple offset fields corresponding to multiple threads in the warp bundle.
[0059] Referring to the pseudo code, the working process of the device 100 is as follows: first, sub_warp_mask is traversed (i.e., the mask fields in the mask information are counted one by one). During the traversal process, the relative index information rel_thread_id corresponding to each valid thread (i.e., the thread belonging to the sub-thread bundle) is calculated. Among them, k indicates that the next valid thread is the kth valid thread in the sub-thread bundle, and the initial value of k is 0. A group of global_dem_index registers are defined in the index storage unit, which are used to store the global index information corresponding to each relative index information rel_thread_id (i.e., the first order of the corresponding thread in the thread bundle). Using k as the address, the global index information phy_thread_id is stored in the corresponding global_dem_index register. When the first valid thread is found, k=0 at this time, then the global index information phy_thread_id (e.g., "i") corresponding to the current thread is written into the address "0" (i.e., global_dem_index[0]) of the global_dem_index register, and then k is added by 1 for the next valid thread to be traversed and retrieved, until all threads in the sub-thread bundle are traversed.
[0060] The second request transmits the offset information lane offset, then you only need to directly index (or "query") gobal_dem_index according to the laneoffset of each target thread, obtain the corresponding global index information phy_thread_id, and then use the global index information phy_thread_id to find the source data corresponding to the target thread. Finally, assemble the data found by each target thread to get the target data dst_data.
[0061] It is worth noting that the first counting unit counts each mask field in turn according to the arrangement order of the mask fields in sub_warp_mask. Therefore, the first count value obtained by the first counting unit for the current mask field is the global index information of the thread corresponding to the current mask field. The global index information can be the index number (or sorting number) corresponding to the thread corresponding to the current mask field based on the arrangement order of the mask fields. For example, thread 0 corresponds to the lowest mask field, and the first count value corresponding to the lowest mask field is "0". Therefore, the global index information (index number) of the thread corresponding to the lowest mask field (i.e., thread 0) is "0". Similarly, the global index information (index number) of thread n is "n", where n∈[0,7]. Therefore, for each thread in the thread warp, there is a unique corresponding global index information, which can be used as information to identify the thread.
[0062] It should be understood that the first count value corresponding to the mask field 0 is defined as "0" here, which is only an optional implementation. In some embodiments, the first count value corresponding to the mask field 0 can also be defined as "1", and the first count values corresponding to the subsequent mask fields are deduced in the same way, which will not be repeated.
[0063] Different from the global index information, the relative index information of the thread is obtained based on the second counting unit. The second counting unit only counts the corresponding sub-thread warp. For the thread that does not belong to the sub-thread warp, the second counting unit does not count, and the corresponding relative index information will not be configured for the thread. In other words, the thread that does not belong to the sub-thread warp does not have the relative index information corresponding to the sub-thread warp. Taking sub_warp_mask = 8'b1101_0110 as an example, thread 1, thread 2, thread 4, thread 6, and thread 7 have relative index information, which are "0", "1", "2", "3", and "4" respectively, while thread 0, thread 3, and thread 5 do not belong to the sub-thread warp, and therefore do not have relative index information. In other words, the relative index information of the threads in a sub-thread warp can be the index number (or sorting number) of the thread in the sub-thread warp based on the arrangement order of the mask field. For example, according to sub_warp_mask = 8'b1101_0110, thread 1, thread 2, thread 4, thread 6, and thread 7 constitute a sub-warp. The threads in the sub-warp are numbered (i.e., relative index signals) based on the order of the mask fields, and thread 1 is numbered "0", i.e., the relative index information is "0"; thread 2 is numbered "1", i.e., the relative index information is "1"; thread 4 is numbered "2", i.e., the relative index information is "2"; thread 6 is numbered "3", i.e., the relative index information is "3"; and thread 7 is numbered "4", i.e., the relative index information is "4".
[0064] It is worth noting that the index storage unit 104 can be implemented based on a register or a RAM (random access memory). After executing the above steps, the space at address "0" of the index storage unit 104 stores data "1", the space at address "1" stores data "2", the space at address "2" stores data "4", the space at address "3" stores data "6", and the space at address "4" stores data "7".
[0065] Regarding the index query unit 106, it is electrically connected to the index storage unit 104 and is configured to query the storage unit according to the offset information corresponding to the data exchange instruction in order to obtain the corresponding index information. The offset information is the relative index information of the target thread with which the current thread is to exchange data. The offset information, for example, includes multiple offset fields corresponding to multiple threads in the thread bundle, each offset field corresponding to a thread. The offset information is represented by "lane_offset", for example, assuming that lane_offset[7:0]={3,4,1,2,0,1,1,1}, where lane_offset[n] is the offset field corresponding to thread n, n∈[0,7]. The offset field represents the relative index information of the target thread with which the current thread corresponding to the offset field is to exchange data. The thread corresponding to the index information corresponding to (or possessed by) the offset field is the source thread. Taking lane_offset[7] as an example, the index information corresponding to the offset field is "7", the current thread (i.e., source thread) corresponding to the offset field is thread 7, and the value of lane_offset[7] is "3", indicating that the target thread for data exchange corresponding to source thread 7 is the thread with the relative index information "3". The specific thread that the target thread is can be determined by querying the index query unit 106. That is, the source thread can be determined based on the index information corresponding to the offset field in the offset information, and the target thread can be determined based on the index information represented by the value of the offset field in the offset information. The index information corresponding to the offset field is, for example, the order or number of the offset field in the offset information.
[0066] In some embodiments, the index query unit 106 uses the offset sub-segment in the offset information as the read address information, and reads the index information corresponding to the thread corresponding to the offset field from the index storage unit 104. For example, in the case where the value of lane_offset[7] is "3", the index query unit 106 uses "3" as the read address information, and reads the data stored at the address (address "3") from the index storage unit 104. As described above, the data stored in the space with address "3" of the index query unit 106 is "6". Therefore, for lane_offset[7], the index information queried by the index query unit 106 is "6". That is, the target thread for data exchange corresponding to the current thread 7 is thread 6.
[0067] Similarly, for the case where the value of lane_offset[6] is "4", the index information obtained by the index query unit 106 is "7". That is, the target thread for data exchange corresponding to the current thread 6 is thread 7. For the case where the value of lane_offset[5] is "1", the index information obtained by the index query unit 106 is "2". That is, the target thread for data exchange corresponding to the current thread 5 is thread 2. For the case where the value of lane_offset[4] is "2", the index information obtained by the index query unit 106 is "4". That is, the target thread for data exchange corresponding to the current thread 4 is thread 4. For the case where the value of lane_offset[3] is "0", the index information obtained by the index query unit 106 is "1". That is, the target thread for data exchange corresponding to the current thread 3 is thread 1. For the case where the value of lane_offset[2] is "1", the index information obtained by the index query unit 106 is "2". That is, the target thread for data exchange corresponding to the current thread 2 is thread 2. For the case where the value of lane_offset[1] is "1", the index information obtained by the index query unit 106 is "2". That is, the target thread for data exchange corresponding to the current thread 1 is thread 2. For the case where the value of lane_offset[0] is "1", the index information obtained by the index query unit 106 is "2". That is, the target thread for data exchange corresponding to the current thread 0 is thread 2.
[0068] It is worth noting that corresponding offset information (such as an offset field corresponding to the thread) is configured for each current thread. Therefore, based on the index query unit 106, for each current thread, the index information of the target thread corresponding to the current thread can be determined.
[0069] The index query unit 106 may be implemented based on a combinational logic circuit or a sequential logic circuit.
[0070] The data exchange unit 108 is electrically connected to the index query unit 106 and is configured to perform data exchange with respect to the source thread and the target thread corresponding to the queried index information and mask information.
[0071] In some embodiments, the data exchange unit 108 includes a data query unit 182 , which is configured to query source data corresponding to a corresponding target thread according to the index information queried by the index query unit 106 .
[0072] It should be understood that for each current thread, the data query unit 182 queries the source data corresponding to the target thread according to the corresponding index information (i.e., the global index information corresponding to the target thread). It should be understood that the source data corresponding to the multiple threads in the thread bundle are stored in a predetermined storage area, and the storage address of the data corresponds to the global index information of the thread, for example. Therefore, based on the global index information, the source data corresponding to the target thread can be queried from the predetermined storage area. The queried source data can be used as the object of data exchange.
[0073] Take the source data corresponding to the 8 threads in the thread bundle as src_data[7:0] = {7,6,5,4,3,2,1,0} as an example for explanation. Among them, src_data[n] represents the source data corresponding to thread n, n∈[0,7]. That is, the source data corresponding to thread 7 is "7", the source data corresponding to thread 6 is "6", the source data corresponding to thread 5 is "5", the source data corresponding to thread 4 is "4", the source data corresponding to thread 3 is "3", the source data corresponding to thread 2 is "2", the source data corresponding to thread 1 is "1", and the source data corresponding to thread 0 is "0".
[0074] Figure 3 A schematic diagram of a data query unit of an embodiment of the present disclosure is shown. The data query unit 182 includes a multiplexer 184. The multiplexer 184 includes a plurality of data input terminals, a strobe control terminal, and a data output terminal. The plurality of data input terminals are configured to receive data (e.g., referred to as "source data") corresponding to a plurality of threads, respectively. The strobe control terminal is configured to receive first index information. The data output terminal is configured to output data corresponding to the target thread.
[0075] It is worth noting that, in the data query unit 182, a corresponding multiplexer 184 is configured for each thread, for performing data selection for the thread. Taking thread n as an example, Figure 3The multiplexer 184 corresponding to thread n of an embodiment of the present disclosure is shown. Specifically, the offset information lane_offset[7] corresponding to thread 7 as the source thread is "3", so the global index information phy_thread_id[7] corresponding to thread 7 is global_dem_index[3], whose value is "6", so the value of the target data dst_data[7] for thread 7 selected through the multiplexer 184 is "src_data[6]", that is, thread 6 is the target thread for data exchange with thread 7, and the data "src_data[6]" of thread 6 is used as the target data dst_data[7] of thread 7. It should be understood that the global index information corresponding to thread 7 is the same data.
[0076] Similarly, the offset information lane_offset[6] corresponding to thread 6 is "4", so the global index information phy_thread_id[6] corresponding to thread 6 is global_dem_index[4], whose value is "7". Therefore, the value of the target data dst_data[6] for thread 6 selected by the multiplexer 184 corresponding to thread 6 is "src_data[7]", that is, thread 7 is the target thread for data exchange with thread 6, and the data "src_data[7]" of thread 7 is used as the target data dst_data[6] of thread 6.
[0077] The offset information lane_offset[5] corresponding to thread 5 is "1", therefore, the global index information phy_thread_id[5] corresponding to thread 5 is global_dem_index[1], whose value is "2", so the value of the target data dst_data[5] for thread 5 selected through the multiplexer 184 corresponding to thread 5 is "src_data[2]", that is, thread 2 is the target thread for data exchange with thread 5, and the data "src_data[2]" of thread 2 is used as the target data dst_data[5] of thread 5.
[0078] The offset information lane_offset[4] corresponding to thread 4 is "2", so the global index information phy_thread_id[4] corresponding to thread 4 is global_dem_index[2], whose value is "4". Therefore, the value of the target data dst_data[4] for thread 4 selected through the multiplexer 184 corresponding to thread 4 is "src_data[4]", that is, thread 4 is the target thread for thread 4 to exchange data, and the data "src_data[4]" of thread 4 is used as the target data dst_data[4] of thread 4.
[0079] The offset information lane_offset[3] corresponding to thread 3 is "0", so the global index information phy_thread_id[3] corresponding to thread 3 is global_dem_index[0], and its value is "1". Therefore, the value of the target data dst_data[3] for thread 3 selected through the multiplexer 184 corresponding to thread 3 is "src_data[1]", that is, thread 1 is the target thread for data exchange with thread 3, and the data "src_data[1]" of thread 1 is used as the target data dst_data[3] of thread 3.
[0080] The offset information lane_offset[2] corresponding to thread 2 is "1", so the global index information phy_thread_id[2] corresponding to thread 3 is global_dem_index[1], and its value is "2". Therefore, the value of the target data dst_data[2] for thread 2 selected through the multiplexer 184 corresponding to thread 2 is "src_data[2]", that is, thread 2 is the target thread for thread 2 to exchange data, and the data "src_data[2]" of thread 2 is used as the target data dst_data[2] of thread 2.
[0081] The offset information lane_offset[1] corresponding to thread 1 is "1", therefore, the global index information phy_thread_id[1] corresponding to thread 1 is global_dem_index[1], whose value is "2", so the value of the target data dst_data[1] for thread 1 selected through the multiplexer 184 corresponding to thread 1 is "src_data[2]", that is, thread 2 is the target thread for data exchange with thread 1, and the data "src_data[2]" of thread 2 is used as the target data dst_data[1] of thread 1.
[0082] The offset information lane_offset[0] corresponding to thread 0 is "1", therefore, the global index information phy_thread_id[0] corresponding to thread 0 is global_dem_index[1], whose value is "2", so the value of the target data dst_data[0] for thread 0 selected through the multiplexer 184 corresponding to thread 0 is "src_data[2]", that is, thread 2 is the target thread for data exchange with thread 0, and the data "src_data[2]" of thread 2 is used as the target data dst_data[0] of thread 0.
[0083] Next, the data exchange unit 108 further determines whether the source thread and the target thread belong to the same sub-thread warp, and performs data exchange on the source thread and the target thread in response to determining that the source thread and the target thread belong to the same sub-thread warp, and does not perform data exchange on the source thread and the target thread in response to determining that the source thread and the target thread do not belong to the same sub-thread warp.
[0084] For example, for thread 7, thread 6, thread 4, thread 2, and thread 1, the data exchange unit 108 can determine based on the mask information that they belong to the same sub-thread bundle. Therefore, the data exchange unit 108 uses the data "src_data[6]" (whose value is "6") of thread 6 as the target data dst_data[7] of thread 7 for data exchange; the data exchange unit 108 uses the data "src_data[7]" (whose value is "7") of thread 7 as the target data dst_data[6] of thread 6 for data exchange; data exchange Unit 108 uses thread 4's data "src_data[4]" (whose value is "4") as thread 4's target data dst_data[4] for data exchange; the data exchange unit 108 uses thread 2's data "src_data[2]" (whose value is "2") as thread 2's target data dst_data[2] for data exchange; the data exchange unit 108 uses thread 2's data "src_data[2]" (whose value is "2") as thread 1's target data dst_data[1] for data exchange.
[0085] It is worth noting that according to sub_warp_mask, thread 5 does not belong to the sub-warp, so the data exchange unit 108 will not exchange data for thread 5, so the data of thread 5 will be retained, that is, the target data dst_data[5] for thread 5 finally determined by the data exchange unit 108 is "src_data[5]", and its specific value is "5". According to sub_warp_mask, thread 3 does not belong to the sub-warp, so the data exchange unit 108 will not exchange data for thread 3, so the data of thread 3 will be retained, that is, the target data dst_data[3] for thread 3 finally determined by the data exchange unit 108 is "src_data[3]", and its specific value is "3". According to sub_warp_mask, thread 0 does not belong to the sub-warp, so the data exchange unit 108 will not exchange data for thread 0. Therefore, the data of thread 0 will be retained, that is, the target data dst_data[0] for thread 0 finally determined by the data exchange unit 108 is "src_data[0]", and its specific value is "0".
[0086] Therefore, for threads 7 to 0, the target data dst_data[7:0] for data exchange by the data exchange unit 108 is {6, 7, 5, 4, 3, 2, 2, 0}. The data exchange unit 108 performs data exchange operations according to the source data src_data[7:0] and the target data dst_data[7:0] corresponding to threads 7 to 0.
[0087] According to the device for data exchange between threads according to the embodiment of the present disclosure, data exchange between any threads can be realized for the threads in the sub-thread bundle. In addition, it can be seen from the implementation process that the number of traversals is small, and the mapping between the relative index information and the global index information is realized by the way when determining the relative index information (rel_thread_id), so that the implementation process is simplified. In addition, the hardware circuit resource consumption of the device of the present disclosure is small. For example, only one accumulator can be used to calculate the relative index information, and a large number of comparators for implementing the mapping between the relative index information and the global index information can be omitted, which greatly saves the hardware area. Further, the device of the present disclosure supports various application scenarios and can effectively reduce power consumption when a small number of threads exchange data. It is worth noting that the computing unit of the device of the present disclosure has good independence. When it is necessary to process multiple sub-thread bundles, only the corresponding computing unit needs to be expanded. It has good scalability and can better meet the computing needs of the application scenario.
[0088] Figure 4A schematic diagram of an apparatus 400 for exchanging data between threads according to an embodiment of the present disclosure is shown. The index generation unit 102 is further configured to sequentially respond to a plurality of mask signals for defining a plurality of sub-warps in a warp to generate the index information.
[0089] There are multiple index storage units 104 , and the multiple index storage units 104 are configured to store index information corresponding to multiple sub-threads respectively.
[0090] There are multiple index query units 106, which are electrically connected to the multiple index storage units 104 respectively, and are configured to query the corresponding index storage units respectively according to the offset information corresponding to the multiple data exchange instructions corresponding to the multiple sub-thread bundles to obtain the corresponding index information.
[0091] There are multiple data exchange units 108 , which are electrically connected to the multiple index query units 106 respectively, and are configured to perform data exchange with respect to the source thread and the target thread corresponding to the queried index information and the mask signal.
[0092] For example, a warp can be configured into multiple sub-warps according to multiple mask information. Still taking a warp with 8 threads as an example, in order to configure the warp into multiple different sub-warps so as to perform corresponding data processing (such as data exchange) for different sub-warps in different scenarios, multiple (for example, N) mask information can be configured for the warp, wherein each mask information sub_warp_mask has, for example, 8 mask fields corresponding to the 8 threads respectively. Corresponding to each mask information, multiple threads in the warp form a sub-warp corresponding to the mask information. It should be understood that these sub-warps are defined by corresponding mask information in the above-mentioned multiple mask information respectively. For example, corresponding to one of the multiple mask information, sub_warp_mask0=8'b1101_0110, the mask fields corresponding to threads 1, 2, 4, 6, and 7 in the thread warp are the same. Therefore, threads 1, 2, 4, 6, and 7 are defined by the mask information sub_warp_mask0 to form a sub-thread warp. Corresponding to another of the multiple mask information, sub_warp_mask1=8'b0101_1001, the mask fields corresponding to threads 0, 3, 4, and 6 in the thread warp are the same. Therefore, threads 0, 3, 4, and 6 are defined by the mask information sub_warp_mask1 to form a sub-thread warp. For other mask information in the N mask information, examples are not given one by one.
[0093] For the received multiple mask information, the index generation unit 102 is used in a time-division multiplexing manner. That is, in the apparatus 400, only one index generation unit 102 may be provided to time-division multiplex the multiple mask information. For example, in the first multiplexing cycle, the index generation unit 102 generates index information corresponding to each thread in the sub-warp defined by the mask information according to the mask information sub_warp_mask0.
[0094] Corresponding to each mask information, or in other words, corresponding to the sub-warp defined by each mask information, a corresponding index storage unit 104, index query unit 106 and data exchange unit 108 are respectively provided in the apparatus 400. That is, in the apparatus 400, the index generation unit 102 is time-division multiplexed, and multiple index storage units 104, index query units 106 and data exchange units 108 can realize parallel processing.
[0095] For example, the index information generated based on the mask information sub_warp_mask0 is stored in the index storage unit No. 0, the index information generated based on the mask information sub_warp_mask1 is stored in the index storage unit No. 1... the index information generated based on the mask information sub_warp_maskn is stored in the index storage unit No. n, where n∈[0,N].
[0096] Accordingly, the index query unit includes, for example, index query unit No. 0, index query unit No. 1, index query unit No. 2, ..., index query unit No. 7. Each index query unit queries the corresponding index storage unit according to the offset information corresponding to the data exchange instruction corresponding to the corresponding sub-thread warp to obtain the corresponding index information. For example, index query unit No. 0 queries index storage unit No. 0. Other index query units will not be described one by one.
[0097] Accordingly, the data exchange unit includes, for example, data exchange unit No. 0, data exchange unit No. 1, data exchange unit No. 2, ..., data exchange unit No. 7. Among them, data exchange unit No. 0 performs data exchange for the source thread and the target thread corresponding to the index information and the mask signal queried by index query unit No. 0. Other data exchange units will not be described one by one.
[0098] Therefore, for a scenario where a warp is limited to multiple sub-warps, the device 400 can satisfy the processing with multiple sub_warp_masks. Compared with a single processing circuit, it is necessary to carry multiple sub_warp_masks (0~N) in the first request and multiple lane offsets (0~N) in the second request. The index generation unit processes (N+1) sub_warp_masks in sequence to obtain the corresponding global_dem_index, which is then sent to processing units 0~N (each processing unit includes, for example, an index storage unit, an index query unit, and a data exchange unit).
[0099] The embodiments of the present disclosure have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or technical improvements in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
[0100] The above are only optional embodiments of the present disclosure and are not intended to limit the present disclosure. For those skilled in the art, the present disclosure may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A device for exchanging data between threads, comprising: An index generating unit configured to generate index information corresponding to each thread in the sub-warp according to a mask signal used to define the sub-warp in the warp; An index storage unit configured to store index information in a predetermined order; An index query unit, electrically connected to the index storage unit, configured to query the index storage unit according to the offset information corresponding to the data exchange instruction so as to obtain the corresponding index information; as well as A data exchange unit, electrically connected to the index query unit, and configured to perform data exchange with a source thread and a target thread corresponding to the queried index information and the mask signal; The mask signal includes a mask field corresponding to each thread in the sub-warp; The index generating unit is further configured to determine first index information corresponding to the thread corresponding to the mask field according to the order of the mask field in the mask signal; The index generation unit is further configured to identify threads corresponding to the same mask field as threads in the same sub-warp, and generate corresponding second index information for each thread in the same sub-warp.
2. The device according to claim 1, characterized in that The index generating unit is further configured to use the second index information as write address information, use the first index information as write data information, and store the first index information in an index storing unit.
3. The device according to claim 2, characterized in that The index query unit is further configured to read the corresponding first index information from the index storage unit using the offset information as read address information.
4. The device according to claim 3, characterized in that The data exchange unit includes a data query unit, and the data query unit is configured to use the first index information as a query address to query data corresponding to the target thread.
5. The device according to claim 4, characterized in that The data query unit includes a multiplexer, and the multiplexer includes: A plurality of data input terminals are configured to respectively receive data corresponding to the plurality of threads; a strobe control terminal configured to receive the first index information; and The data output terminal is configured to output the data corresponding to the target thread.
6. The device according to claim 1, characterized in that The index generation unit includes: a first counting unit configured to count the mask fields in the mask signal in sequence, so as to use a first count value corresponding to the mask field as a first sorting of the mask field in the mask signal, and the first sorting as the first index information; and The second counting unit is configured to count the mask fields in the same sub-thread warp in sequence, so as to use the second counting value corresponding to the mask field as the second sorting corresponding to the mask field in the same sub-thread warp, and the second sorting as the second index information.
7. The device according to claim 1, characterized in that The data exchange unit is further configured to determine whether the source thread and the target thread belong to the same sub-thread warp, and in response to determining that the source thread and the target thread belong to the same sub-thread warp, perform data exchange on the source thread and the target thread, and in response to determining that the source thread and the target thread do not belong to the same sub-thread warp, not perform data exchange on the source thread and the target thread.
8. The device according to claim 1, characterized in that The index generation unit is further configured to generate the index information in response to a plurality of mask signals used to define a plurality of sub-warps in the warp in sequence; There are multiple index storage units, and the multiple index storage units are configured to store index information corresponding to the multiple sub-warps respectively; There are multiple index query units, each of which is electrically connected to the multiple index storage units. The multiple index query units are configured to: query the corresponding index storage units respectively according to the offset information corresponding to the multiple data exchange instructions corresponding to the multiple sub-thread warps to obtain the corresponding index information; as well as There are multiple data exchange units, each of which is electrically connected to the multiple index query units. The multiple data exchange units are configured to perform data exchange on the source thread and the target thread corresponding to the queried index information and the mask signal.
