Data processing methods, apparatus, computer equipment, readable storage media and program products
By distributing tensor data to multiple computing units and dividing it into data blocks in the GPGPU architecture, and mapping it to the target memory for feature value calculation, the problem of wasted computing resources between computing units is solved, and efficient parallel computing is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-29
- Publication Date
- 2026-04-03
AI Technical Summary
In the GPGPU architecture, during cross-computation process, each computing unit needs to independently execute the same computation process, resulting in a large amount of address calculation overhead, consuming chip resources and reducing computing efficiency.
Tensor data is distributed to multiple computation units, and each computation unit is divided into data blocks corresponding to the number of computation units. Local feature values are mapped to storage blocks in the target memory through the index of the data blocks to form a global feature value table for feature value calculation.
It achieves conflict-free parallel computing, improves the utilization of computing resources, and enhances data processing efficiency.
Smart Images

Figure CN121210159B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a data processing method, apparatus, computer equipment, computer-readable storage medium, and computer program product. Background Technology
[0002] In the current field of computer image processing and high-performance computing, parallel computing based on the general-purpose computing on graphics processing units (GPGPU) architecture has become a key technology for improving the efficiency of various computing tasks.
[0003] When performing cross-computation unit calculations in the GPGPU architecture, the relevant technologies need to collect the individual calculation values of each computing unit before performing the overall calculation. Since the data in each computing unit needs to independently and repeatedly perform the same calculation process, a large amount of address calculation overhead is generated. These additional overheads not only consume the chip's computing resources, but also lead to a decrease in computing efficiency. Summary of the Invention
[0004] Therefore, it is necessary to provide a data processing method, apparatus, computer equipment, computer-readable storage medium, and computer program product to address the aforementioned technical problems, which can reduce the consumption of computing resources and improve computing efficiency in parallel computing.
[0005] In a first aspect, this application provides a data processing method, including:
[0006] Acquire the tensor data to be processed and distribute the tensor data to multiple computing units;
[0007] Based on the local tensor data assigned to the target computational unit, calculate the local eigenvalues corresponding to the target computational unit; wherein, the target computational unit is any one of multiple computational units;
[0008] The target computing unit is divided into data blocks corresponding to the number of multiple computing units;
[0009] Based on the sequence number of the data block, the local feature values recorded in each data block are mapped to the target storage block of the target memory until the local feature values in each computing unit are distributed to the corresponding storage blocks in the target memory, thus obtaining the global feature value table;
[0010] Based on the global feature value table, feature values are calculated to determine the target feature value.
[0011] In one embodiment, the step of distributing the local feature values in each computing unit to the corresponding storage blocks in the target memory to obtain a global feature value table includes:
[0012] The local feature values stored in the i-th data block in each computing unit are mapped to the i-th storage block in the corresponding target memory to obtain the global feature value table.
[0013] Where i is the sequence number of the data block and the storage block, the global feature value table is arranged horizontally and continuously according to the sequence number of the data block, and the local feature values from the corresponding data block of each computing unit are arranged in order.
[0014] In one embodiment, the local feature value includes a first local row maximum value, the target feature value includes a target row maximum value, and the step of calculating the feature value according to the global feature value table to determine the target feature value includes:
[0015] Based on the global feature value table, the maximum value of the first local row in each target storage block in the target memory is horizontally mapped to the storage location corresponding to the register cluster; wherein, the register cluster includes the target register corresponding to each computing unit, and each target register includes a corresponding number of storage blocks;
[0016] In the register cluster, the target row maximum value is obtained by using the target register corresponding to each computing unit and calculating the row maximum value sequence in each computing unit in parallel based on the first local row maximum value in the global feature value table.
[0017] In one embodiment, the local feature value includes the local row index and the step of calculating the local feature value corresponding to the target computing unit based on the local tensor data allocated to the target computing unit includes:
[0018] Calculate the maximum value of the second local row for each computational unit based on the local tensor data in each computational unit.
[0019] According to the preset calculation formula, the row index sum is calculated based on the maximum value of the second local row to obtain the local row index sum.
[0020] In one embodiment, the step of calculating feature values based on a global feature value table to determine the target feature value includes:
[0021] Based on the global feature value table, the local row index and horizontal mapping of each target memory block in the target memory are mapped to the corresponding storage location of the register cluster;
[0022] In the register cluster, the row index sum of the row index sum sequence in each computing unit is calculated in parallel based on the local row index sum in the global feature value table, using the target register corresponding to each computing unit, to obtain the first target row index sum.
[0023] In one embodiment, the local feature values include the local row maximum value and the local row exponent sum. After the step of calculating feature values according to the global feature value table to determine the target feature value, the data processing method further includes:
[0024] Calculate the correction factor based on the maximum value of the target row;
[0025] Based on the correction coefficient, the local row index sum in the global feature value table is corrected to obtain the corrected row index sum.
[0026] The corrected row index is summed with the local row index in the global feature value table to obtain the second target row index.
[0027] Secondly, this application also provides a data processing apparatus, comprising:
[0028] The acquisition module is used to acquire tensor data to be processed and distribute the tensor data to multiple computing units;
[0029] The first calculation module is used to calculate the local feature values corresponding to the target calculation unit based on the local tensor data allocated to the target calculation unit; wherein, the target calculation unit is any one of multiple calculation units;
[0030] The partitioning module is used to divide the target computing unit into data blocks corresponding to the number of multiple computing units;
[0031] The mapping module is used to map the local feature values recorded in each data block to the target storage block of the target memory according to the sequence number of the data block, until the local feature values in each computing unit are distributed to the corresponding storage blocks in the target memory, thus obtaining the global feature value table.
[0032] The second calculation module is used to calculate feature values based on the global feature value table in order to determine the target feature value.
[0033] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the data processing method described in the first aspect.
[0034] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the data processing method described in the first aspect.
[0035] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the data processing method described in the first aspect.
[0036] The aforementioned data processing method, apparatus, computer equipment, computer-readable storage medium, and computer program product, after acquiring the first matrix data, acquire tensor data to be processed and allocate the tensor data to multiple computing units; calculate the local eigenvalues corresponding to the target computing unit based on the local tensor data allocated to the target computing unit; wherein the target computing unit is any one of the multiple computing units; divide the target computing unit into data blocks corresponding to the number of multiple computing units; map the local eigenvalues recorded in each data block to the target storage block of the target memory according to the sequence number of the data block, until the local eigenvalues in each computing unit are distributed to the corresponding storage blocks in the target memory, thereby obtaining a global eigenvalue table; and perform eigenvalue calculation based on the global eigenvalue table to determine the target eigenvalues. Therefore, in this embodiment of the application, the local feature values of each computing unit are divided into data blocks corresponding to the number of computing units, and mapped to the corresponding storage blocks of the target memory according to the sequence number. This allows each computing unit to contain local feature values obtained from different computing units, and the target feature value is determined based on parallel computing of each computing unit. As a result, each computing unit can independently and in parallel process the computing tasks of different data block sequences, realizing conflict-free parallel computing, improving the utilization rate of computing resources, and enhancing the efficiency of data processing. Attached Figure Description
[0037] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0038] Figure 1 This is a flowchart illustrating a data processing method in one embodiment;
[0039] Figure 2 This is a detailed flowchart of step 15 of the data processing method in one embodiment;
[0040] Figure 3 This is a detailed flowchart of step 12 of the data processing method in one embodiment;
[0041] Figure 4A This is a schematic diagram illustrating a specific scenario for calculating the maximum value of a row in one embodiment.
[0042] Figure 4B This is a schematic diagram illustrating a specific scenario for calculating the sum of row indices in one embodiment.
[0043] Figure 4CThis is a schematic diagram illustrating a specific scenario of data loading across computing units in one embodiment.
[0044] Figure 5 This is a flowchart illustrating the data processing method in another embodiment;
[0045] Figure 6 This is a structural block diagram of a data processing device in one embodiment;
[0046] Figure 7 This is a schematic diagram of the internal structure of a computer device in one embodiment. Detailed Implementation
[0047] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0048] It should be noted that the terms "first," "second," etc., used in this application can be used to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish the first element from the second element. The terms "comprising" and "having," and any variations thereof, used in this application, are intended to cover non-exclusive inclusion. The term "multiple" used in this application refers to two or more. The term "and / or" used in this application refers to one of the embodiments, or any combination of multiple embodiments.
[0049] In one embodiment, such as Figure 1 As shown, a data processing method is provided. This embodiment illustrates the method applied to a terminal. It is understood that this data processing method can also be applied to a server, and further to a system including both a terminal and a server, and implemented through interaction between the terminal and the server. In this embodiment, the method includes steps 11 to 15. Wherein:
[0050] Step 11: Obtain the tensor data to be processed and distribute the tensor data to multiple computing units.
[0051] The tensor data to be processed can be a high-dimensional array of the original input during natural language processing. Specifically, this high-dimensional array can be text sequence data transformed from image, video, or text content in different specific application scenarios, or it can be a numerical representation of image, video, or text content from a specific application scenario to a virtual computing process.
[0052] For example, in the attention mechanism, the input can be tensor data with shape [batch size, sequence length, hidden layer dimension]. This tensor data can be the query (Q) matrix and key (K) matrix obtained after processing the input sentence or document and performing a linear projection transformation.
[0053] In the GPGPU architecture, efficient computational parallelism can be achieved by mapping computational tasks to hierarchical thread groups. Specifically, in the parallel computing architecture of the GPGPU architecture, a cluster can include multiple computing units in the row direction. Here, the computing unit can correspond to a thread group (TG), and each thread group consists of multiple warp threads.
[0054] After acquiring the complete tensor data, the data can be divided into multiple logical blocks and distributed to different computing units according to the resource distribution of the parallel computing architecture. That is, different data of the overall tensor are assigned to different thread groups for processing, and the thread bundles in each thread group acquire a partial data block from the local tensor data. In this way, multiple thread groups in the parallel architecture can perform parallel computation on their respective allocated local tensor data blocks, thereby fully utilizing the hardware's parallel computing capabilities.
[0055] It should be noted that after the tensor data to be processed is distributed to multiple computing units, the tensor data fragment held by each computing unit is called local tensor data. These local data are components of the tensor data to be processed. Based on the data distribution strategy of distributing tensor data to each computing unit, large-scale tensor data operations can be decomposed into multiple parallel subtasks, thereby improving the data processing efficiency of tensor data processing.
[0056] Step 12: Calculate the local eigenvalues corresponding to the target computing unit based on the local tensor data allocated to the target computing unit.
[0057] The target computation unit can be any one of multiple computation units.
[0058] The local feature value can be one or more local feature values calculated based on the local tensor data allocated in the target computing unit. The local feature value can represent the statistical characteristics of the corresponding local tensor data in the target computing unit.
[0059] Here, each computational unit can independently calculate its corresponding local eigenvalues based on the assigned local tensor data. The local eigenvalues determined by each computational unit can be used for coordination and integration in subsequent steps to determine global eigenvalues that can represent the global data tensor. Each computational unit can execute the same computational logic in parallel based on its corresponding local tensor data. However, since the local tensor data corresponding to each computational unit is different, the local eigenvalues calculated by each computational unit can be different.
[0060] It should be noted that the local feature value can mainly include the row maximum value and the row exponent sum. These two parameters are key intermediate parameters in the process of performing the softmax normalization operation.
[0061] The row maximum value can be the maximum value among all elements in each row of data within the local data block managed by the computation unit. In the Softmax calculation, the maximum value in the data needs to be determined first, and then the maximum value of the row is subtracted from all elements in that row to achieve data offset. This is done to ensure numerical stability and prevent overflow when calculating the exponential function later.
[0062] The row exponent sum is obtained by calculating the exponent function of all offset elements in a row after the above data offset is completed, and then summing the calculated exponent values. This row exponent sum is a calculation parameter in the normalization process. This embodiment simplifies the calculation process of the maximum row value and the row exponent sum, thereby simplifying the overall calculation process and improving calculation efficiency.
[0063] In the specific implementation of this application, after determining the local tensor data in the target computation unit, one or more of the following computation modes can be flexibly executed based on the local tensor data corresponding to the target computation unit, specifically including:
[0064] (1) Calculate the maximum row value in the local tensor data based on the local tensor data;
[0065] (2) Calculate the row indices in the local tensor data based on the local tensor data;
[0066] (3) Based on the local tensor data, simultaneously calculate the maximum row value and the row index in the local tensor data.
[0067] It should be further explained that after the target computing unit calculates its corresponding local feature value, the value in each data block in the target computing unit can be updated, so that after the target computing unit is processed, each data block of the target computing unit records the local feature value.
[0068] For example, the target computing unit can be a target thread group among multiple thread groups in a GPGPU architecture. The target thread group is any one of the multiple thread groups, and each thread group consists of multiple thread bundles. Therefore, after the target thread group calculates the corresponding local feature value based on the data in the multiple thread bundles, it can update the local feature value to each thread bundle in the target thread group to synchronize the local feature value in the target thread group and record the local feature value in each thread bundle.
[0069] Step 13: Divide the target computing unit into data blocks corresponding to the number of multiple computing units.
[0070] Here, dividing the target computing unit into data blocks corresponding to the number of multiple computing units provides a completely symmetrical data exchange basis for subsequent data permutation. In this way, each computing unit can receive local feature values provided by other computing units, and at the same time, it can also distribute the local feature values stored in its own computing unit to each computing unit.
[0071] It should be noted that after determining the local feature values in each computing unit, each computing unit can be further partitioned. Specifically, the storage area of each computing unit can be divided into multiple data blocks corresponding to the number of computing units in the GPGPU architecture. This allows the local feature values of each computing unit to be stored in corresponding data blocks within the target computing unit. Furthermore, the data of each computing unit can be transformed horizontally and vertically based on the partitioned data structure. That is, the local feature values of each computing unit can be stored in multiple data blocks of a target computing unit, and the multiple data blocks of a target computing unit include the local feature values corresponding to each computing unit.
[0072] For example, in the overall parallel computing architecture, there may be 4 thread groups. After calculating the corresponding local feature values based on the local tensor data in the 4 thread groups, the corresponding local feature values can be updated back to the corresponding thread group. Each of the 4 thread groups can also be divided into multiple data blocks corresponding to the number of thread groups, so that the local feature values in each thread group can be written to any one of the thread groups.
[0073] As a specific implementation method, when the maximum row value calculated by each thread group based on the corresponding local tensor data is stored in the four thread groups, the four thread groups can be divided into four data blocks. In this way, each thread group can store the maximum row value corresponding to each thread group based on the four divided data blocks.
[0074] As another specific implementation, when the four thread groups store the maximum row value and the sum of row exponents calculated by each thread group based on the corresponding local tensor data, the four thread groups can be divided into 2*4 data blocks. In this way, each thread group can store the maximum row value and the sum of row exponents corresponding to each thread group based on the divided 8 data blocks.
[0075] It should be noted that the above-mentioned division of computing units is usually a division of logical views, thereby realizing address planning and management, so that a contiguous physical storage space can be orderly divided into multiple virtual data blocks, thereby avoiding the overhead of actual data transfer while providing a clear data structure for upper-level operations.
[0076] Step 14: Based on the sequence number of the data block, map the local feature values recorded in each data block to the target storage block of the target memory, until the local feature values in each computing unit are distributed to the corresponding storage blocks in the target memory, thus obtaining the global feature value table.
[0077] The target memory can be shared memory within each computing unit. This target memory may include multiple storage blocks, which are contiguous storage areas reserved within the target memory for storing local feature values written by the local memory corresponding to the computing unit. The logical arrangement of these storage blocks in the target memory can correspond to each data block in the partitioned computing units.
[0078] After dividing the local feature values of each computing unit, the data blocks after the computing unit is divided can be numbered to determine the sequence number of each data block in multiple computing units.
[0079] Here, the global feature value table can be a data table determined by writing the local feature values of each data block in all computing units into each storage block in the target memory based on a preset permutation rule. The global feature value table includes the local feature values of each data block in all planning units. It is a distributed data structure that includes all local feature values after the data arrangement structure has been transformed.
[0080] In one specific implementation, the step of distributing the local feature values in each computing unit to the corresponding storage blocks in the target memory to obtain a global feature value table includes: mapping the local feature values stored in the i-th data block in each computing unit to the i-th storage block in the corresponding target memory to obtain a global feature value table; where i is the sequence number of the data block and the storage block, and the global feature value table arranges the local feature values from the corresponding sequence number data block of each computing unit horizontally and continuously according to the sequence number of the data block.
[0081] Here, each computing unit maps its internally divided i-th data block to the corresponding storage block numbered i in the target memory. Thus, there is a deterministic correspondence between multiple computing units and the target memory. Here, the sequence number i simultaneously defines the source attribute of the data block and the target location of the storage block.
[0082] Based on the correspondence between data blocks and storage blocks determined in the above steps, data blocks with the same sequence number in all computing units are stored consecutively in the corresponding sequence number storage block, forming a storage structure arranged horizontally according to data block sequence number. This ensures that the local memory of each computing unit carries a complete dimension of the global feature value, rather than scattered fragments of the original data.
[0083] For example, all computing units follow the same instruction to map the local feature value stored in the i-th data block in each computing unit to the i-th storage block in the corresponding target memory. That is, the 0-th data block in the computing unit is mapped to the 0-th storage block for storage; the 1-th data block in the computing unit is mapped to the 1-th storage block for storage; ... and so on; the i-th data block in the computing unit is mapped to the i-th storage block for storage.
[0084] Each computational unit executes the mapping instructions in parallel. Each unit can perform the step of mapping the local feature values stored in i data blocks to the lower i storage blocks in the target memory in parallel. After each computational unit completes the mapping instructions, each unit includes its own local feature values and local feature values from other different computational units. This constitutes multiple local feature values arranged "horizontally" for each computational unit. These multiple local feature values can be used to represent the region feature values corresponding to the local tensor data in each computational unit.
[0085] As a specific example, multiple computing units may include TG0, TG1, TG2, and TG3. Each computing unit calculates its own local feature value and updates each data block of that computing unit with that local feature value. The following is the data arrangement in multiple computing units:
[0086] TG0: [2, 2, 2, 2]
[0087] TG1: [7, 7, 7, 7]
[0088] TG2: [1, 1, 1, 1]
[0089] TG3: [5, 5, 5, 5]
[0090] After setting the target storage block in the target memory for the data in each data block of each computing unit TG0, TG1, TG2, and TG3, the following is the data arrangement in the target memory:
[0091] TG0: [2, 7, 1, 5]
[0092] TG1: [2, 7, 1, 5]
[0093] TG2: [2, 7, 1, 5]
[0094] TG3: [2, 7, 1, 5]
[0095] Thus, the global eigenvalue table is obtained.
[0096] Step 15: Calculate the feature values based on the global feature value table to determine the target feature values.
[0097] The target feature value can refer to the global feature value determined relative to the local feature values calculated by each computing unit.
[0098] Here, the global feature value table refers to the data arrangement of the local feature values corresponding to each computing unit in the corresponding storage block in the target memory. After determining the global feature value table, it can be shifted in the target memory to the data block corresponding to each computing unit, and the corresponding target feature value can be calculated based on the data in the global feature value table for each computing unit.
[0099] After determining the global feature value table, the local feature values arranged according to the new rules in the target memory can be shifted and loaded into the local thread register corresponding to each computing unit for feature value calculation. For example, the computing unit can shift and load the local feature values of each row in the shared memory into the local thread register of each computing unit for continuous storage, and based on the local thread register, perform maximum value calculation on the multiple local feature values stored continuously within each computing unit, and finally determine the target feature value.
[0100] Each computing unit only needs to calculate multiple feature values within itself. Each computing unit includes its own computing unit and all local feature values corresponding to other computing units. Therefore, each computing unit can determine the target feature value by performing a local feature value calculation based on the local register. This target feature value can be used to represent the feature of the global data.
[0101] In addition, each computing unit performed the above-mentioned eigenvalue calculation steps in parallel.
[0102] As an example, taking a four-thread group as multiple computational units, each thread group no longer stores the original, scattered local feature values. Instead, they each hold different dimensions of the global feature values. Specifically, thread group 0 stores the 0th data block of all computational units, thread group 1 stores the 1st data block of all computational units, and so on. This data distribution method allows each thread group to independently complete the key parts of the global computation. When all thread groups synchronously execute the maximum value calculation, thread group 0 is responsible for calculating the maximum value of the 0th block in the global data, and thread group 1 is responsible for calculating the maximum value of the 1st block.
[0103] For example, each thread group needs to perform eigenvalue calculations on the following storage blocks to determine the maximum value:
[0104] TG0: [2, 7, 1, 5]
[0105] TG1: [2, 7, 1, 5]
[0106] TG2: [2, 7, 1, 5]
[0107] TG3: [2, 7, 1, 5]
[0108] Each thread group can obtain the final target feature value of 7.
[0109] In the above data processing method, the embodiments of this application transform the serially dependent calculation process into a fully parallel execution mode through data reorganization. All calculation units independently complete the calculation task based on local data, which solves the serial bottleneck in traditional tree-structured calculation and improves memory access efficiency by performing calculations through local registers.
[0110] In an exemplary embodiment, the local feature value includes a first local row maximum value, and correspondingly, the target feature value includes a target row maximum value, such as... Figure 2 As shown, step 15 includes steps 151 and 152. Wherein:
[0111] Step 151: Based on the global feature value table, the first local row maximum value in each target memory block in the target memory is horizontally mapped to the storage location corresponding to the register cluster.
[0112] The register cluster includes a target register corresponding to each computing unit, and each target register includes a corresponding number of storage blocks.
[0113] In this embodiment, the maximum row value in the tensor data to be processed can be calculated. Correspondingly, the local row maximum value of each computing unit can be calculated based on the local tensor data allocated to multiple computing units. After dividing each computing unit and mapping the local row maximum values in each data block of the computing unit to the target storage block in the shared memory, a global feature value table including the row maximum values calculated by each computing unit can be determined.
[0114] After determining the global feature value table, the maximum value of the first local row temporarily stored in each target storage block in the target memory can be completely mapped to the corresponding storage location of the register cluster according to the horizontal arrangement rule. In this way, the reorganized global feature value table is transferred from shared memory to the local register of the computing unit.
[0115] The target memory can be the local memory corresponding to each computing unit, and the computing unit can perform direct operations on the linearly arranged data in the local memory based on the local memory.
[0116] Step 152: In the register cluster, the target row maximum value is obtained by parallel calculation of the row maximum value sequence in each computing unit based on the first local row maximum value in the global feature value table through the target register corresponding to each computing unit.
[0117] After mapping the first local row maximum value in each target memory block to the corresponding storage location of the register cluster, each computing unit can perform independent calculations based on the set of first local row maximum values stored in its target register.
[0118] Since the data layout has been optimized into a horizontal structure, each computing unit can perform calculations on the maximum value sequence of the row it is responsible for, that is, the data block with the same sequence number from all computing units. The local maximum value of the sequence can be quickly obtained through parallel comparison operations. In this way, the target row maximum value is determined based on the distributed computing determined by multiple computing units.
[0119] The implementation method of this application decomposes the calculation of the global maximum value into fully parallel subtasks through precise data mapping and parallel computing mechanisms, so that all computing units remain fully active during the calculation phase, breaking through the serial bottleneck of traditional tree-structured computing; in addition, memory access efficiency is improved and computing latency is reduced through register-level data processing.
[0120] In an exemplary embodiment, local feature values include local row indices and, correspondingly, local tensor data allocated to the target computational unit, such as... Figure 3 As shown, step 12 includes steps 131 to 132. Wherein:
[0121] Step 131: Calculate the maximum value of the second local row corresponding to each computational unit based on the local tensor data in each computational unit.
[0122] The second local row maximum value is a temporary local row maximum value calculated by the current computation unit based on its local tensor data, used to assist in the calculation of the row index.
[0123] Each computation unit can independently scan its assigned local tensor data to determine the maximum value of each row. By finding the local maximum value within each computation unit first, the corresponding computation unit can be started to calculate the row maximum value before calculating the corresponding row index sum based on the global row maximum value. Therefore, during the calculation of the corresponding local row index sum based on the local tensor data, the second local row maximum value corresponding to the local tensor data can be calculated simultaneously, ensuring the activity of the computation unit.
[0124] Please refer to Figure 4A , Figure 4A This diagram illustrates a specific scenario for calculating local row maximum values. Specifically, during the initial data preparation phase, four thread groups (TG0, TG1, TG2, and TG3) have obtained row maximum values from different data blocks obtained from different computational units through data exchange. TG0 holds the row maximum value fragment of the 0th data block of all thread groups (rowmaxLocal0), TG1 holds the row maximum value of the 1st data block of all thread groups (rowmaxLocal1), TG2 holds the row maximum value of the 2nd data block of all thread groups (rowmaxLocal2), and TG3 holds the row maximum value of the 3rd data block of all thread groups (rowmaxLocal3). This forms a horizontal data layout encompassing multiple thread groups. Furthermore, for this horizontally distributed data pattern, corresponding workgroups exist. For example, the data block composed of the four thread groups (TG0, TG1, TG2, and TG3) can be divided into Work Group 0 (WG0) and Work Group 1 (WG1), storing the row maximum value data from different thread groups respectively. Here, WG0 can be used to store the calculated local row maximum values.
[0125] Each thread group starts parallel computation mode. TG0 performs a calculation operation on the maximum value of all rows of the 0th data block it stores, and obtains the local maximum value rowmax_0 of the data block sequence; TG1 synchronously processes the maximum value of all rows of the 1st data block to obtain rowmax_1; TG2 and TG3 process the 2nd and 3rd data blocks in the same way to obtain the corresponding results.
[0126] Step 132: Calculate the row index sum based on the second local row maximum value according to the preset calculation formula, and obtain the local row index sum.
[0127] The local row index sum can be an uncorrected temporary row index sum calculated based on the local tensor data and the maximum value of the second local row.
[0128] After obtaining the second local row maximum value, each computational unit can normalize its local tensor data according to the second local row maximum value, perform exponentiation and summation operations, and obtain the local row exponent sum.
[0129] It should be noted that, according to the preset calculation formula, the row exponent sum is calculated based on the second local row maximum value. The local row exponent sum can be obtained by subtracting the local row maximum value of each element in the local tensor data, then calculating its exponent value, and finally summing these exponent values.
[0130] This application decomposes the complex row exponent and calculation into highly parallelizable subtasks, and parallelizes the time-consuming exponent calculation process with the maximum value calculation. Subsequent steps only need to make simple corrections to these pre-digested local sums to obtain the global result. By distributing the computational burden to all computing units and completing the heavy-load tasks in advance, computational latency is reduced and computational efficiency is improved.
[0131] Please refer to Figure 4B , Figure 4B This diagram illustrates a specific scenario for calculating local row index sums. Specifically, four thread groups, TG0, TG1, TG2, and TG3, have exchanged data and each holds the local row index sums for different data blocks. Specifically: TG0 holds the local row index sum of the 0th data block for all thread groups (rowsumLocal0); TG1 holds the local row index sum of the 1st data block (rowsumLocal1); TG2 holds the local row index sum of the 2nd data block (rowsumLocal2); and TG3 holds the local row index sum of the 3rd data block (rowsumLocal3). This forms a horizontally distributed data structure involving multiple thread groups. Furthermore, for this horizontally distributed data structure, there are corresponding workgroups. For example, the data block formed by the four thread groups TG0, TG1, TG2, and TG3 can be divided into Work Group 0 (WG0) and Work Group 1 (WG1), which can store the row index sums from different thread groups respectively. Here, WG1 can be used to store the calculated local row index sums.
[0132] Specifically, after determining the maximum row value, the row index sum is calculated based on the following formula:
[0133] rowSum=Σexp(element-rowMax).
[0134] Where element is each number in a row of the four thread groups TG0, TG1, TG2, and TG3, and rowMax is the maximum value of the second local row.
[0135] In one embodiment, when the local feature values include local row indices, the step of calculating feature values based on a global feature value table to determine the target feature value further includes:
[0136] (1) Based on the global feature value table, map the local row index and horizontally to the corresponding storage location of the register cluster in each target memory block;
[0137] (2) In the register cluster, the first target row index sum is obtained by using the target register corresponding to each computing unit and calculating the row index sum of the sequence in each computing unit in parallel according to the local row index sum in the global feature value table.
[0138] Among these, the local row index sum can refer to the set of index sums pre-calculated by each computing unit based on its own local data and the maximum value of the local row. A register cluster refers to a distributed storage system composed of the local registers of all computing units, while a target storage block is a data storage unit sequentially divided within the target memory.
[0139] The proposed solution maps the horizontally arranged local row indices in each target memory block to the corresponding storage location of the register cluster, and transfers the fully swapped and reorganized indexes and data from shared memory to the local registers of the computing unit.
[0140] In the register cluster where data mapping is complete, each computation unit performs calculations on the stored row indices and sequences, as well as the same index and data blocks from all computation units, through its target register. Since the data is arranged in a horizontal structure according to the global eigenvalue table, each computation unit can independently perform summation calculations on the data sequences it is responsible for. These distributed summation results together constitute the intermediate result of the first target row index sum.
[0141] Please refer to Figure 4C , Figure 4CThis diagram illustrates a specific scenario for data loading across computing units. Specifically, in the initial state, each thread group (TG0, TG1, TG2, TG3) independently stores its computed local feature values, forming a vertical data layout. The feature values of each thread group are logically organized according to data blocks and feature types. For example, in TG0, (1,1) represents the maximum local row value of its first data block, and (1,4) represents the sum of local row indices within the same data block. When determining local feature values and mapping them to shared memory, the i-th data block is mapped to the shared memory of the i-th thread group. Specifically, TG0 can map its (0,0) and (0,4) feature values to the corresponding (0,0) and (0,1) positions in its shared memory TG0 GSM via local mapping st.gsm. Simultaneously, TG1 can map its (0,0) and (0,4) feature values to the corresponding (1,0) and (1,1) positions in its shared memory GSM via cross-cell mapping st.async; TG2 can map its (0,0) and (0,4) feature values to the corresponding (2,0) and (2,1) positions in its shared memory GSM via cross-cell mapping st.async; and TG3 can map its (0,0) and (0,4) feature values to the corresponding (3,0) and (3,1) positions in its shared memory GSM via cross-cell mapping st.async. During this process, all thread groups TG0, TG1, TG2, and TG3 execute the same data mapping steps as T0 in parallel, ultimately forming a horizontally arranged global feature view in the shared memory of each thread group.
[0142] Thus, the smooth transition from thread-group-specific data to globally shared data lays the foundation for subsequent parallel computing. By optimizing access patterns through regularized memory layout, memory bandwidth utilization is significantly improved, enabling each thread group to independently process specific data block sequences, achieving complete parallelization of computing resources, completely eliminating the serial bottleneck in traditional tree-structured computing, maximizing memory access efficiency for exponential and sum calculations through register-level data processing, minimizing computational latency, and further improving the data processing efficiency of Softmax computing.
[0143] In an exemplary embodiment, local feature values include the local row maximum value and the local row exponent sum, such as... Figure 5 As shown, the data processing method further includes steps 16 to 18. Wherein:
[0144] Step 16: Calculate the correction factor based on the maximum value of the target row.
[0145] When the system needs to process both the maximum value of a local row and the sum of its local row exponents simultaneously, a correction coefficient can be calculated based on the determined maximum value of the target row. The formula for calculating this correction coefficient is as follows:
[0146] modifierX=exp((rmaxTgX-rmax_global).
[0147] Where modifierX is the correction coefficient, rmaxTgX can be the local row maximum value calculated in each thread group of TG0, TG1, TG2, and TG3, and rmax_global is the target row maximum value.
[0148] It should be noted that this correction factor is used to uniformly transform local intermediate results calculated based on different benchmarks to the same global benchmark, thereby enabling these local results to be correctly arithmetically combined.
[0149] Step 17: Based on the correction coefficient, correct the local row index sum in the global eigenvalue table to obtain the corrected row index sum.
[0150] After determining the correction coefficient, the local row index sums stored in the global feature value table can be scalar corrected according to the correction coefficient. By multiplying each local row index sum by its corresponding correction coefficient, the scattered results originally calculated based on different local maxima are transformed into comparable data under a unified benchmark, thereby preserving the efficiency of the previous parallel computing.
[0151] Step 18: The corrected row index is summed with the local row index in the global feature value table to obtain the second target row index.
[0152] Through a parallel accumulation mechanism, the corrected row index sums obtained by each computing unit are globally aggregated to form the second target row index sum. The distributed results are quickly integrated through multi-level computing operations, and the global row index sum that meets the requirements of Softmax computing is output.
[0153] This application's embodiments concentrate computational overhead at the lightweight scalar operation level, maximizing the performance advantages of parallel computing, establishing a scalable feature value processing framework, and providing an efficient computational foundation for complex machine learning operators, thereby maintaining overall computational accuracy.
[0154] It should be understood that although the steps in the flowcharts of the above embodiments are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the above embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages in other steps. It is understood that the steps in different embodiments can be freely combined as needed, and all non-contradictory solutions formed by such combinations are within the scope of protection of this application.
[0155] Based on the same inventive concept, this application also provides a data processing apparatus for implementing the data processing method described above. The solution provided by this apparatus is similar to the implementation scheme described in the above method; therefore, the specific limitations in one or more data processing apparatus embodiments provided below can be found in the limitations of the data processing method described above, and will not be repeated here.
[0156] In one exemplary embodiment, such as Figure 6 As shown, a data processing device is provided, comprising: an acquisition module, a first calculation module, a partitioning module, a mapping module, and a second calculation module, wherein:
[0157] The acquisition module is used to acquire tensor data to be processed and distribute the tensor data to multiple computing units;
[0158] The first calculation module is used to calculate the local feature values corresponding to the target calculation unit based on the local tensor data allocated to the target calculation unit; wherein, the target calculation unit is any one of multiple calculation units;
[0159] The partitioning module is used to divide the target computing unit into data blocks corresponding to the number of multiple computing units;
[0160] The mapping module is used to map the local feature values recorded in each data block to the target storage block of the target memory according to the sequence number of the data block, until the local feature values in each computing unit are distributed to the corresponding storage blocks in the target memory, thus obtaining the global feature value table.
[0161] The second calculation module is used to calculate feature values based on the global feature value table in order to determine the target feature value.
[0162] In one embodiment, the mapping module includes a corresponding mapping unit, wherein:
[0163] The corresponding mapping unit is used to map the local feature values stored in the i-th data block in each computing unit to the i-th storage block in the corresponding target memory to obtain the global feature value table;
[0164] Where i is the sequence number of the data block and the storage block, the global feature value table is arranged horizontally and continuously according to the sequence number of the data block, and the local feature values from the corresponding data block of each computing unit are arranged in order.
[0165] In one embodiment, the second computing module includes a horizontal mapping unit and a third computing unit, wherein:
[0166] The horizontal mapping unit is used to horizontally map the first local row maximum value in each target storage block in the target memory to the storage location corresponding to the register cluster according to the global feature value table; wherein, the register cluster includes the target register corresponding to each computing unit, and each target register includes a corresponding number of storage blocks.
[0167] The third computation unit is used to calculate the maximum row value of the row value sequence in each computation unit in parallel, based on the first local row maximum value in the global feature value table, through the target register corresponding to each computation unit in the register cluster, so as to obtain the target row maximum value.
[0168] In one embodiment, the first computing module includes a fourth computing unit and a fifth computing unit, wherein:
[0169] The fourth computational unit is used to calculate the maximum value of the second local row corresponding to each computational unit based on the local tensor data in each computational unit.
[0170] The fifth calculation unit is used to calculate the row index sum based on the second local row maximum value according to the preset calculation formula, and obtain the local row index sum.
[0171] In one embodiment, the data processing apparatus further includes a fifth calculation module, a correction module, and a sixth calculation module, wherein:
[0172] The fifth calculation module is used to calculate the correction coefficient based on the maximum value of the target row.
[0173] The correction module is used to correct the local row index sum in the global feature value table according to the correction coefficient, so as to obtain the corrected row index sum;
[0174] The sixth calculation module is used to sum the corrected row index with the local row index in the global feature value table to obtain the second target row index sum.
[0175] Each module in the aforementioned data processing device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can call and execute the operations corresponding to each module.
[0176] In one exemplary embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 7 As shown, this computer device includes a processor, memory, input / output interfaces (I / O), and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores matrix data. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communicating with external terminals via a network connection. When the computer program is executed by the processor, it implements a data processing method.
[0177] In one exemplary embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 7As shown, the computer device includes a processor, memory, input / output interfaces, a communication interface, a display unit, and an input device. The processor, memory, and input / output interfaces are connected via a system bus, and the communication interface and input device are also connected to the system bus via the input / output interfaces. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The input / output interfaces are used for exchanging information between the processor and external devices. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, Near Field Communication (NFC), or other technologies. When the computer program is executed by the processor, it implements a data processing method. The display unit is used to form a visually visible image and can be a display screen, a projection device, or a virtual reality imaging device. The display screen can be an LCD screen or an e-ink screen. The input device of the computer device can be a touch layer covering the display screen, or buttons, trackballs, or touchpads set on the casing of the computer device, or external keyboards, touchpads, or mice, etc.
[0178] Those skilled in the art will understand that Figure 7 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0179] In one exemplary embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:
[0180] The process involves acquiring tensor data to be processed and distributing it to multiple computational units. Based on the local tensor data distributed to the target computational unit, local feature values corresponding to that unit are calculated. The target computational unit can be any one of the multiple computational units. The target computational unit is then divided into data blocks corresponding to the number of computational units. Based on the data block number, the local feature values recorded in each data block are mapped to target storage blocks in the target memory, until the local feature values in each computational unit are distributed to the corresponding storage blocks in the target memory, resulting in a global feature value table. Finally, feature value calculations are performed based on the global feature value table to determine the target feature value.
[0181] In one embodiment, when the processor executes the computer device, it further performs the following steps:
[0182] The local feature values stored in the i-th data block in each computing unit are mapped to the i-th storage block in the corresponding target memory to obtain a global feature value table; where i is the index of the data block and the storage block. The global feature value table is arranged horizontally and continuously according to the index of the data block, containing the local feature values from the corresponding indexed data block of each computing unit.
[0183] In one embodiment, when the processor executes the computer device, it further performs the following steps:
[0184] According to the global feature value table, the first local row maximum value in each target storage block in the target memory is horizontally mapped to the storage location corresponding to the register cluster; wherein, the register cluster includes the target register corresponding to each computing unit, and each target register includes a corresponding number of storage blocks; in the register cluster, the row maximum value of the row maximum value sequence in each computing unit is calculated in parallel according to the first local row maximum value in the global feature value table through the target register corresponding to each computing unit, so as to obtain the target row maximum value.
[0185] In one embodiment, when the processor executes the computer device, it further performs the following steps:
[0186] Based on the local tensor data in each computational unit, calculate the second local row maximum value corresponding to each computational unit; according to the preset calculation formula, calculate the row index sum based on the second local row maximum value to obtain the local row index sum.
[0187] In one embodiment, when the processor executes the computer device, it further performs the following steps:
[0188] Based on the global feature value table, the local row index sums in each target memory block are horizontally mapped to the corresponding storage locations in the register cluster. In the register cluster, the row index sums of the row index sum sequences in each computing unit are calculated in parallel using the target registers corresponding to each computing unit, based on the local row index sums in the global feature value table, to obtain the first target row index sum.
[0189] In one embodiment, when the processor executes the computer device, it further performs the following steps:
[0190] Calculate the correction coefficient based on the maximum value of the target row; correct the local row index sum in the global feature value table based on the correction coefficient to obtain the corrected row index sum; sum the corrected row index with the local row index sum in the global feature value table to obtain the second target row index sum.
[0191] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon that, when executed by a processor, implements the steps in the above method embodiments.
[0192] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0193] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.
[0194] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0195] The above embodiments are merely illustrative of several implementation methods of this application, and their descriptions are relatively specific and detailed. However, they should not be construed as limiting the scope of this application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A data processing method, characterized in that, The method includes: Acquire the tensor data to be processed and distribute the tensor data to multiple computing units; Based on the local tensor data allocated to the target computing unit, calculate the local feature value corresponding to the target computing unit; wherein, the target computing unit is any one of the plurality of computing units; The storage area of the target computing unit is divided into data blocks corresponding to the number of the plurality of computing units; Based on the sequence number of the data block, the local feature values recorded in each data block of the target computing unit are mapped to the target storage block of the target memory, until the local feature values of multiple computing units are distributed to the corresponding storage blocks in the target memory, thus obtaining a global feature value table; wherein, the target memory is the shared memory of each computing unit, the target memory includes multiple storage blocks, and the storage blocks have a deterministic correspondence with the data blocks; Based on the global feature value table, feature values are calculated to determine the target feature value.
2. The method according to claim 1, characterized in that, The step of distributing local feature values from multiple computing units to corresponding storage blocks in the target memory to obtain a global feature value table includes: The local feature values stored in the i-th data block of each computing unit are mapped to the i-th storage block in the corresponding target memory to obtain the global feature value table; Where i is the sequence number of the data block and the storage block, and the global feature value table is arranged horizontally and continuously according to the sequence number of the data block, containing local feature values from the corresponding sequence number data block of each computing unit.
3. The method according to claim 1, characterized in that, The local feature value includes the maximum value of a first local row, the target feature value includes the maximum value of a target row, and the step of calculating the feature value according to the global feature value table to determine the target feature value includes: According to the global feature value table, the first local row maximum value in each target storage block in the target memory is horizontally mapped to the storage location corresponding to the register cluster; wherein, the register cluster includes a target register corresponding to each computing unit, and each target register includes a corresponding number of storage blocks; In the register cluster, the target row maximum value is obtained by using the target register corresponding to each computing unit and calculating the row maximum value sequence in each computing unit in parallel according to the first local row maximum value in the global feature value table.
4. The method according to claim 1, characterized in that, The local feature values include local row indices and sums. The step of calculating the local feature values corresponding to the target computing unit based on the local tensor data allocated to the target computing unit includes: Calculate the maximum value of the second local row corresponding to the target computing unit based on the local tensor data in the target computing unit; According to the preset calculation formula, the row index sum is calculated based on the second local row maximum value to obtain the local row index sum.
5. The method according to claim 4, characterized in that, The step of calculating feature values based on the global feature value table to determine the target feature value includes: Based on the global feature value table, the local row index and horizontal mapping of each target storage block in the target memory are mapped to the storage location corresponding to the register cluster; In the register cluster, the row index sum of the row index sum sequence in each computing unit is calculated in parallel using the target register corresponding to each computing unit, based on the local row index sum in the global feature value table, to obtain the first target row index sum.
6. The method according to any one of claims 1 to 5, characterized in that, The local feature values include the local row maximum value and the local row exponent sum, and the target feature value includes the target row maximum value and the second target row exponent sum. After the step of calculating the feature value according to the global feature value table to determine the target feature value, the data processing method further includes: Calculate the correction factor based on the maximum value of the target row; Based on the correction coefficient, the local row index sum in the global feature value table is corrected to obtain the corrected row index sum; The corrected row index sum is summed with the local row index sum in the global feature value table to obtain the second target row index sum.
7. A data processing apparatus, characterized in that, The data processing device includes: An acquisition module is used to acquire tensor data to be processed and distribute the tensor data to multiple computing units; The first calculation module is used to calculate the local feature value corresponding to the target calculation unit based on the local tensor data allocated to the target calculation unit; wherein, the target calculation unit is any one of the plurality of calculation units; A partitioning module is used to divide the storage area of the target computing unit into data blocks corresponding to the number of the plurality of computing units; A mapping module is used to map the local feature values recorded in each data block of the target computing unit to a target storage block of the target memory according to the sequence number of the data block, until the local feature values in multiple computing units are distributed to the corresponding storage blocks in the target memory to obtain a global feature value table; wherein, the target memory is the shared memory of each computing unit, the target memory includes multiple storage blocks, and the storage blocks have a deterministic correspondence with the data blocks; The second calculation module is used to calculate feature values based on the global feature value table in order to determine the target feature value.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Processing unit array based on nonvolatile memory calculation and calculation method thereof
CN111045727A
Data processing method and device, electronic equipment and storage medium
CN120508384A