A data processing method, device and processor
Patent Information
- Application Number
- CN202211634334.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-15
- Publication Date
- 2026-10-27
- Estimated Expiration
- 2042-12-15
AI Technical Summary
[0003]有鉴于此,本公开提供一种数据处理方法、装置及处理器,以解决现有技术中pooling层计算过程速度慢的问题
[0003]有鉴于此,本公开提供一种数据处理方法、装置及处理器,以解决现有技术中pooling层计算过程速度慢的问题。
Smart Images

Figure CN115809091B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and in particular to a data processing method, apparatus and processor. Background Technology
[0002] In recent years, computer technology has developed rapidly, and computing devices have become increasingly powerful, with performance (especially computing power) becoming increasingly superior. For computing devices, constantly processing large amounts of data would be extremely time-consuming. It is necessary to gradually reduce the amount of data processed while preserving the main characteristics of the data. For this purpose, pooling algorithms have emerged. Currently, almost all deep learning and artificial intelligence technologies incorporate pooling layers and utilize pooling algorithms. This algorithm reduces the amount of data by downsampling it. Summary of the Invention
[0003] In view of this, the present disclosure provides a data processing method, apparatus and processor to solve the problem of slow calculation speed in the pooling layer in the prior art.
[0004] In a first aspect, this disclosure provides a data processing method, the method comprising:
[0005] Read hardware instructions to read single data features;
[0006] Decode the hardware instructions for calculating the single data feature read;
[0007] Execute hardware instructions to calculate the features of a single decoded data point, in order to complete the entire process of feature calculation for at least three data points.
[0008] Furthermore, before reading the hardware instructions to compute a single data feature, the method further includes:
[0009] Identify code segments consisting of two or more statements used to perform data feature calculations;
[0010] The identified code segment is translated into hardware instructions for computing the single data feature.
[0011] Furthermore, the hardware instructions for executing the decoded single data feature calculation include:
[0012] Different vector general-purpose registers are used to store the various data and calculation results involved in the data feature calculation.
[0013] Furthermore, the feature calculation can be any of the following: finding the maximum value, finding the minimum value, finding the mean value, or finding the median value.
[0014] Furthermore, the feature calculation is a pooling calculation; the data involved in the feature calculation is the feature data of the pooling window coverage area.
[0015] Furthermore, the pooling window can be 2x2 or 3x3.
[0016] Secondly, this disclosure also provides a data processing apparatus, the apparatus comprising:
[0017] The hardware instruction reading unit is used to read hardware instructions for calculating single data features;
[0018] The hardware instruction decoding unit is used to decode the hardware instructions for calculating the read single data features;
[0019] The hardware instruction execution unit is used to execute hardware instructions for calculating the features of a single decoded data, so as to complete the entire process of feature calculation for at least three data points.
[0020] Furthermore, the device also includes a hardware instruction generation unit, used before the hardware instruction reading unit reads a single data feature to calculate hardware instructions:
[0021] Identify code segments consisting of two or more statements used to perform data feature calculations;
[0022] Furthermore, the hardware instruction execution unit is used to execute hardware instructions for calculating the decoded single data feature, including:
[0023] Different vector general-purpose registers are used to store the various data and calculation results involved in the data feature calculation.
[0024] Furthermore, the feature calculation can be any of the following: finding the maximum value, finding the minimum value, finding the mean value, or finding the median value.
[0025] Furthermore, the feature calculation is a pooling calculation; the data involved in the feature calculation is the feature data of the pooling window coverage area.
[0026] Furthermore, the pooling window can be 2x2 or 3x3.
[0027] Thirdly, this disclosure also provides a processor, the processor including the data processing apparatus described in the second aspect above. Attached Figure Description
[0028] To more clearly illustrate the technical solutions in the embodiments of this disclosure or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0029] Figure 1 This is a schematic diagram illustrating how a pooling layer uses a 2x2 pooling window to retrieve the maximum value in some implementation methods.
[0030] Figure 2 A schematic diagram illustrating the averaging of a pooling layer using a 2x2 pooling window for some implementation methods;
[0031] Figure 3 This is a schematic diagram illustrating the instruction implementation for retrieving the maximum value when using a 2x2 pooling window in a pooling layer, as provided for some implementation methods.
[0032] Figure 4 This is a schematic diagram illustrating the instruction implementation for averaging when using a 2x2 pooling window in a pooling layer, as provided for some implementation methods.
[0033] Figure 5 A flowchart of a data processing method provided in an embodiment of this disclosure;
[0034] Figure 6 This is a schematic diagram of the structure of a data processing device provided in an embodiment of the present disclosure. Detailed Implementation
[0035] The embodiments of this disclosure will now be described in detail with reference to the accompanying drawings.
[0036] It should be understood that the described embodiments are merely some, not all, of the embodiments disclosed herein. All other embodiments obtained by those skilled in the art based on the embodiments of this disclosure without inventive effort are within the scope of protection of this disclosure.
[0037] In deep learning and artificial intelligence technologies, pooling layers primarily employ two computational methods to preserve the main features of the data: 1. Maximum value: This involves selecting the maximum value of a sub-block of the feature map and using it as the pooled value for that sub-block; 2. Average value: This involves calculating the average value of a sub-block of the feature map and using it as the pooled value for that sub-block. A sub-block is typically the area covered by an n*n pooling window, and multiple different sub-blocks are obtained by moving the pooling window according to a set stride. Figure 1 and Figure 2These are schematics illustrating the maximum and average values when using a 2x2 pooling window in the pooling layer. Based on this, current computing devices, such as CPUs (central processing units) or GPUs (graphics processing units), require at least three instructions to implement the maximum value method in the pooling layer, such as... Figure 3 As shown, the instructions are a = Max(a,b), c = Max(c,d), and a = Max(a,c). However, implementing the averaging method of the pooling layer requires executing at least four instructions, such as... Figure 4 As shown, the instructions are a = Add(a,b), c = Add(c,d), a = Add(a,c), and a = Div(a,4). Clearly, the computing device relies on multiple instructions to obtain the results for both calculation methods in the pooling layer, resulting in slow processing speed.
[0038] To address the aforementioned problems, this disclosure provides a method for calculating data features, applicable to computing devices. The computing device can be various electronic devices with a processor (such as a CPU or GPU) and an operating system, including but not limited to:
[0039] (1) Mobile communication devices: These devices are characterized by having mobile communication functions and are primarily designed to provide voice and data communication. These terminals include: smartphones (such as iPhones), multimedia phones, feature phones, and low-end phones, etc.
[0040] (2) Ultra-mobile personal computer devices: These fall under the category of personal computers, have computing and processing functions, and generally also have mobile Internet access capabilities. Such terminals include: PDA, MID and UMPC devices, such as iPad;
[0041] (3) Portable entertainment devices: These devices can display and play multimedia content, including audio and video players (such as iPods), handheld game consoles, e-books, as well as smart toys and portable car navigation devices;
[0042] (4) Server: A device that provides computing services. The components of a server include a processor, hard disk, memory, system bus, etc. Servers are similar to general computer architectures, but because they need to provide highly reliable services, they have higher requirements in terms of processing power, stability, reliability, security, scalability, and manageability.
[0043] (5) Other electronic devices with data processing functions.
[0044] The data processing method in this embodiment can be executed by a processor on a computing device, see [link to relevant documentation]. Figure 5 The method includes the following steps 501-503.
[0045] Step 501: Read the hardware instructions for calculating single data features.
[0046] In step 501, the single data feature calculation hardware instruction can be included in the executable program of the computing device. The operating system of the computing device preloads the executable program into memory, and then the processor accesses memory to retrieve and execute the instructions in the executable program. An executable program refers to an executable program that can float in the operating system's storage space and can be used to implement some or all of the functions of an application software product or service. Among the implemented functions is the data feature calculation function. Accordingly, the executable program contains a single data feature calculation hardware instruction, which is a specially added new processor instruction that can be directly recognized and executed by the processor.
[0047] The generation of hardware instructions for single data feature calculation can be achieved in two ways. In the first implementation, a code segment consisting of two or more statements used to implement data feature calculation is identified; the identified code segment is then translated into the single data feature calculation hardware instructions. In this method, the executable program containing the single data feature calculation hardware instructions is obtained by converting source code written in a high-level programming language. The specific generation process includes:
[0048] (1) The compiler uses the processor through the operating system to perform the following operations ① and ②:
[0049] ① Obtain the source code written in a high-level programming language, wherein the source code includes a code segment consisting of two or more statements used to perform data feature calculations;
[0050] ② The obtained source program is translated into the target program, wherein the code segment used to implement data feature calculation is translated into a single data feature calculation hardware instruction;
[0051] (2) The linker uses the processor through the operating system to perform the following operations: link the target program with library functions to generate the executable program.
[0052] In the above method, both the compiler and linker run on the operating system of the computing device. Unlike existing compilers, this disclosure adds a function to the compiler to identify whether the source program contains a code segment consisting of two or more statements used to implement data feature calculation. If so, the code segment will be translated into a newly added processor instruction: a data feature calculation hardware instruction, instead of simply translating the code in the code segment into multiple corresponding assembly codes as in existing technologies. The code segment identification operation is related to the writing conventions of the high-level programming language used in the source program; different writing conventions may result in different code segment identification operations.
[0053] Of course, those skilled in the art should understand that the executable program can also be obtained by compiling and linking the source program by the operating system of the computing device itself or other tools running on the operating system, and then the processor reads the executable program to execute it. This disclosure does not specifically limit this.
[0054] As a second implementation method, the hardware instructions for calculating the single data feature are generated directly without compilation. In this method, the executable program containing the hardware instructions for calculating the single data feature is obtained by converting a target program written in a machine-oriented low-level programming language (such as assembly language). The specific generation process includes:
[0055] The linker uses the processor through the operating system to perform the following operations:
[0056] Obtain the target program written in assembly language, wherein the target program includes hardware instructions for calculating single data features;
[0057] The target program is linked with the library functions to generate the executable program.
[0058] Similarly, those skilled in the art should understand that the executable program can also be obtained by linking the source program with the operating system of the computing device itself or other tools running on the operating system, and then the processor reads the executable program to execute it. This disclosure does not specifically limit this.
[0059] Step 502: Decode the hardware instructions for calculating the read single data feature.
[0060] In step 502, the hardware instruction for calculating a single data feature can be directly recognized by the processor as a newly added instruction in the processor's instruction set. The process of the processor decoding this instruction is existing technology and will not be described in detail here.
[0061] Step 503: Execute the hardware instruction for calculating the feature of the decoded single data to complete the feature calculation process for at least three data points.
[0062] Specifically, the data feature calculation can be performed on multiple data points of at least three, calculating any of the following features: maximum value, minimum value, mean, or median. Typically, the data feature calculation is a pooling calculation, and the data involved in the calculation are the feature data within the pooling window's coverage area. In the pooling calculation, the pooling window is preferably 2x2 or 3x3, and the data feature calculation specifically involves finding the maximum, minimum, mean, or median of four or nine feature data points within the pooling window's coverage area.
[0063] In this step, when the processor executes the hardware instruction for calculating a single data feature, it can first store the data involved in the data feature calculation in a vector general-purpose register before processing. Provided the instruction length remains within the maximum length limit, different vector general-purpose registers can be used to store the various data involved in the data feature calculation and the calculation results. The vector general-purpose register is a private register of the smallest processing unit in the processor. Of course, during the entire data feature calculation process, the source vector general-purpose register previously used to store one piece of data involved in the calculation can later be used as the destination vector general-purpose register to store the calculation result. Currently, a computing device can have a maximum of 256 vector general-purpose registers, and using 8-bit encoding to represent these registers allows for the representation of a maximum of 256 vector general-purpose registers. Assuming that four data points are involved in a single data feature calculation, the corresponding hardware instruction for single data feature calculation will have five operands, occupying either four vector general-purpose registers (one for each of the four data points and one for the result) or five vector general-purpose registers (one for each of the four data points and one for the result). The operand length in this instruction is at most 32 bits or 40 bits. In contrast, in the prior art, an instruction for calculating two data points has an operand length of 64 bits. Since the opcode lengths are the same, the length of the hardware instruction added in this embodiment will not increase.
[0064] The advantages of this embodiment are illustrated by the following examples.
[0065] (1) Data feature calculation is to find the maximum value of the four data points.
[0066] A code segment in the source program that calculates the maximum value of four data points is translated into a single data feature calculation hardware instruction, v_max4_f32, after being converted into an executable program. This instruction is designed as follows: v_max4_f32dst,src0,src1,src2,src3. The processor only needs to read this single instruction, decode it, and then execute the entire data feature calculation process: taking the four data points, calculating the maximum value, and obtaining the result. The calculation process could be, for example, dst = max(max(src0,src1),max(src2,src3)). In existing technology, see [link to previous documentation]. Figure 3 The processor needs to read and execute three instructions to complete the entire process of calculating the data features.
[0067] (2) Data feature calculation involves finding the average of the four data points.
[0068] A code segment in the source program that calculates the average of four data points is translated into a single hardware instruction for data feature calculation after being converted into an executable program: the v_avg4_f32 instruction. This instruction is designed as follows: v_avg4_f32 dst,src0,src1,src2,src3. The subsequent processor only needs to read this single instruction, decode it, and then execute the entire data feature calculation process: taking the four data points, calculating the average, and obtaining the result. For example, the calculation process could be: dst = (src0 + src1 + src2 + src3) / 4. In existing technologies, see [link to relevant documentation]. Figure 4 The processor needs to read and execute four instructions to complete the entire process of calculating the data features.
[0069] Since the time it takes for the processor to access memory to obtain instructions is much longer than the time it takes to execute instructions, the solution in this embodiment can simplify the task that was originally completed by multiple instructions into one instruction. Therefore, it can effectively shorten the instruction fetch time and improve the speed of data feature calculation.
[0070] It should be noted that this disclosure can pre-add various types of single data feature calculation hardware instructions. Different types of single data feature calculation hardware instructions correspond to different data feature calculation methods (finding the maximum value, minimum value, average value, and median value, respectively). Furthermore, each single data feature calculation hardware instruction can correspond to multiple single data feature calculation hardware instructions. These instructions have the same opcode but different operands. The executable program can also contain a total of multiple single data feature calculation hardware instructions, depending on the software product or service function it implements. Different single data feature calculation hardware instructions correspond to different data feature calculations, and these differences may lie in the calculation method or the calculation data. The data feature calculation process described in this embodiment refers to the operation implementation process of completing a specific data feature calculation. For example, the following are four different data feature calculation processes: finding the maximum value of the following four numbers: 2, 13, 6, 10; finding the maximum value of the following four numbers: 11, 7, 19, 8; finding the maximum value of the following nine numbers: 23, 21, 15, 25, 14, 19, 20, 14, 16; and finding the average value of the following four numbers: 2, 13, 6, 10.
[0071] This embodiment also provides a data processing device, see [link to documentation]. Figure 6 The device includes:
[0072] The hardware instruction reading unit 601 is used to read hardware instructions for calculating single data features.
[0073] The hardware instruction decoding unit 602 is used to decode the hardware instruction for calculating the read single data feature;
[0074] The hardware instruction execution unit 603 is used to execute hardware instructions for calculating the feature of a single decoded data, so as to complete the entire process of feature calculation for at least three data points.
[0075] Optionally, the data processing apparatus provided in this embodiment further includes a hardware instruction generation unit 600, used before the hardware instruction reading unit reads a single data feature to calculate hardware instructions:
[0076] Identify code segments consisting of two or more statements used to perform data feature calculations;
[0077] The identified code segment is translated into hardware instructions for computing the single data feature.
[0078] For example, the hardware instruction execution unit 603 is used to execute hardware instructions for calculating the decoded single data feature, including:
[0079] Different vector general-purpose registers are used to store the various data and calculation results involved in the data feature calculation.
[0080] Furthermore, in this embodiment, the feature calculation can be any of the following: finding the maximum value, finding the minimum value, finding the mean value, or finding the median value.
[0081] As a typical application scenario, the feature calculation is a pooling calculation; the data participating in the feature calculation is the feature data of the pooling window coverage area.
[0082] The pooling window can be 2*2 or 3*3.
[0083] The data processing device provided in this embodiment and the data processing method in the aforementioned method embodiment belong to the same technical concept. Technical details not described in this embodiment can be found in the relevant descriptions in the aforementioned method embodiment, and will not be repeated here.
[0084] In summary, the technical solution provided in this disclosure allows the executable program code for feature calculation of more than three data points to correspond to only one newly added hardware instruction. Only this one instruction needs to be read to execute the complete calculation process, instead of having to read multiple instructions sequentially as in the prior art. This can improve the calculation speed, especially for scenarios where pooling layers in deep learning and artificial intelligence technologies implement pooling algorithms. These algorithms involve a large number of data feature calculations (such as finding the maximum, minimum, mean, or median) when reducing the amount of data. Using the solution in this disclosure can greatly improve the operation speed of the pooling layer.
[0085] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0086] In this disclosure, the term "and / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. The character " / " generally indicates that the preceding and following related objects have an "or" relationship.
[0087] The various embodiments in this specification are described in a related manner. The same or similar parts between the various embodiments can be referred to each other. Each embodiment focuses on describing the differences from other embodiments.
[0088] In particular, the device embodiment is basically similar to the method embodiment, so the description is relatively simple. For relevant details, please refer to the description of the method embodiment.
[0089] For ease of description, the above apparatus is described by dividing it into various functional units / modules. Of course, in implementing this disclosure, the functions of each unit / module can be implemented in one or more software and / or hardware.
[0090] The above description is merely a specific embodiment of this disclosure, but the scope of protection of this disclosure is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this disclosure should be included within the scope of protection of this disclosure. Therefore, the scope of protection of this disclosure should be determined by the scope of the claims.
Claims
1. A data processing method, characterized in that, The method includes: Read single data feature calculation hardware instructions; the single data feature calculation hardware instructions are translated from a code segment consisting of two or more statements used to implement data feature calculation, and are specially added new processor instructions that are directly recognized by the processor. The compiler will not directly translate the code segment into the corresponding multiple assembly codes. Decode the hardware instructions for calculating the single data feature read; The decoded single data feature calculation hardware instruction is executed to complete the entire process of feature calculation for at least three data points. When executing the single data feature calculation hardware instruction, different vector general-purpose registers are used to store each data point involved in the data feature calculation and the calculation result. In a single data feature calculation, the source vector general-purpose register that previously stored the data involved in the calculation can be used as the destination vector general-purpose register to store the calculation result. The vector general-purpose register is a private register of the smallest processing unit in the processor.
2. The method according to claim 1, characterized in that, Before reading a single data feature to compute hardware instructions, the method further includes: Identify code segments consisting of two or more statements used to perform data feature calculations; The identified code segment is translated into hardware instructions for computing the single data feature.
3. The method according to claim 1, characterized in that, The feature calculation can be any of the following: finding the maximum value, finding the minimum value, finding the mean value, or finding the median value.
4. The method according to claim 3, characterized in that, The feature calculation is a pooling calculation; the data involved in the feature calculation is the feature data of the pooling window coverage area.
5. The method according to claim 4, characterized in that, The pooling window is 2*2 or 3*3.
6. A data processing apparatus, characterized in that, The device includes: The hardware instruction reading unit is used to read single data feature calculation hardware instructions; the single data feature calculation hardware instructions are translated from a code segment consisting of two or more statements used to implement data feature calculation, and are specially added new processor instructions that are directly recognized by the processor; wherein, the compiler will not directly translate the code segment into corresponding multiple assembly codes; The hardware instruction decoding unit is used to decode the hardware instructions for calculating the read single data features; The hardware instruction execution unit is used to execute the decoded single data feature calculation hardware instructions to complete the entire process of feature calculation for at least three data items. When executing the single data feature calculation hardware instructions, different vector general-purpose registers are used to store each data item participating in the data feature calculation and the calculation results. In a single data feature calculation, the source vector general-purpose register that previously stored the data participating in the calculation can be used as the destination vector general-purpose register to store the calculation results. The vector general-purpose register is a private register of the smallest processing unit in the processor.
7. The apparatus according to claim 6, characterized in that, The device further includes a hardware instruction generation unit, used before the hardware instruction reading unit reads a single data feature to calculate hardware instructions: Identify code segments consisting of two or more statements used to perform data feature calculations; The identified code segment is translated into hardware instructions for computing the single data feature.
8. The apparatus according to claim 7, characterized in that, The feature calculation can be any of the following: finding the maximum value, finding the minimum value, finding the mean value, or finding the median value.
9. The apparatus according to claim 8, characterized in that, The feature calculation is a pooling calculation; the data involved in the feature calculation is the feature data of the pooling window coverage area.
10. A processor, characterized in that, The processor is configured to perform the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Maximum pooling method and device, computer equipment and storage medium
CN110232665A
Operation processing method and device, device for operation processing and storage medium
CN112651489A