Data vectorization processing method and device
By calculating the loop execution overhead and vectorization overhead, cyclic distribution is performed only when the loop execution overhead is greater than the vectorization overhead, which solves the problem of negative acceleration effect in traditional data vectorization methods, and realizes more efficient data vectorization processing, reducing Performance requirements for compiler.
Patent Information
- Application Number
- CN202411136809.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-19
- Publication Date
- 2024-12-06
AI Technical Summary
Traditional data vectorization methods may lead to negative acceleration effects in specific application scenarios, and bring additional performance overhead to the compiler, which cannot effectively improve execution efficiency.
By calculating the loop execution overhead and vectorization overhead, cyclic distribution is performed only when the loop execution overhead is greater than the vectorization overhead to realize the vectorization processing of data and avoid the occurrence of negative acceleration effects.
It effectively avoids the occurrence of negative acceleration effects, reduces the additional performance requirements for the compiler, and improves the execution efficiency of data vectorization.
Smart Images

Figure CN119088454A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer technology, and in particular relates to a data vectorization processing method and device. Background Art
[0002] Data vectorization mainly vectorizes the data that needs to be processed in the program. Because there are multiple data structures in one instruction scheduling process, this vectorization of the data to be processed can effectively reduce the number of instruction scheduling times, thereby improving code running efficiency and reducing the performance requirements for the compiler.
[0003] The traditional method of automatically vectorizing the data to be processed is generally the loop distribution optimization method, which divides the original loop into multiple sub-loops, eliminates the parts of the loop with dependencies, transforms the original loop into non-vectorizable loops and vectorizable loops, and improves the partial vectorization capability of the compiler, thereby improving the performance of the compiler. However, in specific application scenarios, after the data to be processed is vectorized, the execution efficiency after the transformation is not necessarily higher than that before the transformation. That is to say, the use of vector instructions can reduce instruction overhead, but vector transformation will bring additional overhead to the compiler, and this additional overhead may cover the acceleration effect brought by the vector instructions.
[0004] Therefore, how to vectorize the data to be processed and avoid the occurrence of negative acceleration effect is a technical problem to be solved by those skilled in the art. Summary of the invention
[0005] The purpose of the present invention is to solve the technical problem in the prior art that negative acceleration effect occurs when vectorizing data to be processed.
[0006] To achieve the above technical objectives, on the one hand, the present invention provides a data vectorization processing method, which is applied to cyclic distribution, and the method includes:
[0007] determining loop execution overhead according to loop information of data to be processed;
[0008] Determining vectorization overhead of the data to be processed;
[0009] When the loop execution overhead is greater than the vectorization overhead, the data to be processed are cyclically distributed so that the data to be processed are vectorized.
[0010] Furthermore, the loop execution overhead includes loop execution internal overhead and loop execution external overhead, and the loop execution overhead is specifically determined by the following formula:
[0011]
[0012] Wherein, distscalar cost is the loop execution cost, n is the number of partitions, distscalarinsidecostp is the internal loop execution cost of a single partition, and distscalar outside costp is the external loop execution cost of a single partition.
[0013] Furthermore, the internal overhead of the loop execution of the single partition is determined by the following formula:
[0014] distscalarinside costp=SIC*niters
[0015] Wherein, SIC is the sum of the overheads of all instructions in one iteration, and niters is the number of loop iterations in the loop information.
[0016] Furthermore, the external overhead of the loop execution of the single partition specifically includes a header overhead, a tail overhead and a version check overhead.
[0017] Furthermore, the vectorization overhead includes a first internal overhead and a first external overhead, and the vectorization overhead is specifically determined by the following formula:
[0018]
[0019] Wherein, distvectcost is the vectorization cost, n is the number of partitions, distvectinsidecostp is the first internal cost of a single partition, and distvectoutsidecostp is the first external cost of a single partition.
[0020] Furthermore, the first internal cost of the single partition is determined by the following formula:
[0021] distvectinside costp=VIC*(niters / VF)
[0022] Where VIC is the loop overhead within one iteration, niters is the number of iterations of the loop before vectorization, and VF is the vectorization factor.
[0023] Furthermore, the first external overhead specifically includes overhead caused by non-alignment and aliasing and SLP overhead.
[0024] On the other hand, the present invention also provides a data vectorization processing device, the device comprising:
[0025] A first determining module, configured to determine a loop execution overhead according to loop information of data to be processed;
[0026] A second determination module, used to determine the vectorization overhead of the data to be processed;
[0027] The execution module is used to perform cyclic distribution on the data to be processed when the loop execution overhead is greater than the vectorization overhead, so as to complete vectorization of the data to be processed.
[0028] The present invention provides a data vectorization processing method and device. Compared with the prior art, the method first determines the loop execution overhead according to the loop information of the data to be processed; then determines the vectorization overhead of the data to be processed; finally, when the loop execution overhead is greater than the vectorization overhead, the data to be processed is cyclically distributed so that the data to be processed is vectorized. This method can vectorize the data to be processed, avoid the occurrence of negative acceleration effects, and avoid placing additional performance requirements on the compiler. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] In order to more clearly illustrate the embodiments of this specification or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0030] Figure 1 The figure is a schematic diagram of the process flow of the data vectorization processing method provided in the embodiment of this specification;
[0031] Figure 2 The figure is a schematic diagram of the structure of the data vectorization processing device provided in the embodiment of this specification. DETAILED DESCRIPTION
[0032] In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of this application.
[0033] like Figure 1The flowchart of the data vectorization processing method provided by the embodiment of this specification is shown. Although this specification provides the method operation steps or device structures shown in the following embodiments or drawings, the method or device may include more or fewer operation steps or module units after partial merger based on routine or no creative labor. In the steps or structures where there is no necessary causal relationship logically, the execution order of these steps or the module structure of the device is not limited to the execution order or module structure shown in the embodiments or drawings of this specification. When the method or module structure is applied in actual devices, servers or terminal products, it can be executed sequentially or in parallel according to the method or module structure shown in the embodiments or drawings (for example, in the environment of parallel processors or multi-threaded processing, and even in the implementation environment of distributed processing and server clusters).
[0034] The data vectorization processing method provided in the embodiments of this specification can be applied to terminal devices such as clients and servers. Figure 1 As shown, the method specifically comprises the following steps:
[0035] Step S101 : determining loop execution overhead according to loop information of data to be processed.
[0036] Specifically, for loops that cannot be vectorized in loop distribution, the number of loop iterations is niters, and the loop overhead includes internal overhead and external overhead. The internal overhead is caused by instruction execution, including scalar memory access instructions and other scalar instructions. SIC represents the sum of the overhead caused by all instructions in one iteration, which is obtained by accumulating the overhead of each scalar instruction in the loop.
[0037] In addition, the solution also includes determining whether the loop partition can be vectorized, and if so, continuing to execute subsequent steps, and if not, terminating the operation without performing loop distribution.
[0038] In the embodiment of the present application, for loops that cannot be vectorized in loop distribution, the number of loop iterations is niters, and the loop execution overhead includes loop execution internal overhead and loop execution external overhead. The loop execution internal overhead is caused by instruction execution, including scalar memory access instructions and other scalar instructions. SIC represents the sum of the overhead caused by all instructions in one iteration, which is obtained by accumulating the overhead of each scalar instruction in the loop. The loop execution internal overhead of a single partition is determined by the following formula:
[0039] dist scalarinside costp=SIC*niters
[0040] Wherein, SIC is the sum of the overheads of all instructions in one iteration, and niters is the number of loop iterations in the loop information.
[0041] The external overhead of the loop execution of a single partition specifically includes the header overhead, the tail overhead and the version check overhead, and the accumulation of the header overhead, the tail overhead and the version check overhead is the external overhead of the loop execution of a single partition. In a specific application scenario, it can be illustrated by the following code:
[0042]
[0043] The loop execution overhead is specifically determined by the following formula:
[0044]
[0045] Wherein, distscalar cost is the loop execution cost, n is the number of partitions, distscalarinsidecostp is the internal loop execution cost of a single partition, and distscalar outside costp is the external loop execution cost of a single partition.
[0046] Step S102: Determine the vectorization overhead of the data to be processed.
[0047] In the embodiment of the present application, in the loop that meets the vectorization requirement, the loop overhead includes internal overhead and external overhead. In the internal overhead calculation, VIC represents the loop overhead within one iteration, which is obtained by accumulating the vector instruction overhead. For loops distributed differently, the vectorization width of the loop may be different. The number of loop iterations after vectorization is calculated by niters / VF. The vectorization overhead includes the first internal overhead and the first external overhead. The first internal overhead of a single partition is determined by the following formula:
[0048] distvectinside costp=VIC*(niters / VF)
[0049] Wherein, VIC is the loop overhead in one iteration, niters is the number of loop iterations in the loop information, and VF is the vectorization factor.
[0050] The first external overhead specifically includes the overhead caused by non-alignment and aliasing and the SLP overhead. In a specific application scenario, the first external overhead is defined as the external overhead of the vectorized statement (including the statement in the inner loop of the vectorized loop), which can be illustrated by the following code:
[0051] / / External overhead of vectorized statements (including statements in the inner loop of the vectorized loop)
[0052] vec_outside_cost+=cost.outside_of_loop(stmt_info);
[0053] vec_outside_cost+=cost.outside_of_loop(pattern_def_stmt_info);
[0054] / / SLP overhead
[0055] vec_outside_cost+=cost.outside_of_loop(instance);
[0056] if (loop peeling number unknown) {
[0057] vec_outside_cost+=(peel_iters_prologue*scalar_single_iter_cost)+(peel_iters_epilogue*scalar_single_iter_cost)+peel_guard_costs;
[0058] peel_guard_costs+=2*(vect_get_cost(cond_branch_taken)+vect_get_cost(cond_branch_not_taken));
[0059] }
[0060] The vectorization overhead is determined by the following formula:
[0061]
[0062] Wherein, distvectcost is the vectorization cost, n is the number of partitions, distvectinsidecostp is the first internal cost of a single partition, and distvectoutsidecostp is the first external cost of a single partition.
[0063] Step S103: When the loop execution overhead is greater than the vectorization overhead, the data to be processed is cyclically distributed to complete vectorization of the data to be processed.
[0064] Specifically, after the loop execution overhead and the vectorization overhead are determined, the loop execution overhead and the vectorization overhead are compared. In addition, the vectorization overhead will include a part of the scalar cost, that is, the loop processing execution overhead. When determining the total vectorization overhead, the first internal overhead and the first external overhead calculated by all partitions can be accumulated. These first internal overheads and the first external overheads include the above-mentioned part of the scalar cost. Finally, after the loop execution overhead is greater than the vectorization overhead, the data to be processed is cyclically distributed to complete the vectorization of the data to be processed.
[0065] In addition, the present application solution may also set a cost table in the compiler, in which descriptions of the costs of various instructions are stored. When determining loop execution overhead and vectorization overhead, the loop instruction overhead is obtained based on the cost table to complete the overhead calculation.
[0066] Based on the above-mentioned data vectorization processing method, one or more embodiments of this specification also provide a platform and terminal for data vectorization processing. The platform or terminal may include a device, software, module, plug-in, server, client, etc. that uses the method described in the embodiments of this specification and is combined with necessary implementation hardware. Based on the same innovative concept, the system in one or more embodiments provided in the embodiments of this specification is as described in the following embodiments. Since the implementation scheme and method for solving the problem of the system are similar, the implementation of the specific system in the embodiments of this specification can refer to the implementation of the aforementioned method, and the repetitions will not be repeated. The terms "unit" or "module" used below can be a combination of software and / or hardware that implements predetermined functions. Although the system described in the following embodiments is preferably implemented in software, hardware and a combination of software and hardware are also possible and conceived.
[0067] Specifically, Figure 2 is a schematic diagram of the module structure of an embodiment of the data vectorization processing device provided in this specification, such as Figure 2 As shown, the data vectorization processing device provided in this specification includes:
[0068] A first determining module 201, configured to determine a loop execution overhead according to loop information of data to be processed;
[0069] A second determination module 202, configured to determine the vectorization overhead of the data to be processed;
[0070] The execution module 203 is used to perform cyclic distribution on the data to be processed when the loop execution overhead is greater than the vectorization overhead, so as to complete vectorization of the data to be processed.
[0071] It should be noted that the above-mentioned system may also include other implementation modes according to the description of the corresponding method embodiment. The specific implementation modes may refer to the description of the above-mentioned corresponding method embodiment, which will not be described one by one here.
[0072] The present application also provides an electronic device, including:
[0073] processor;
[0074] a memory for storing instructions executable by the processor;
[0075] The processor is configured to execute the method provided in the above embodiment.
[0076] The electronic device provided by the embodiment of the present application stores the executable instructions of the processor in a memory. When the processor executes the executable instructions, it can first determine the loop execution overhead according to the loop information of the data to be processed; then determine the vectorization overhead of the data to be processed; finally, when the loop execution overhead is greater than the vectorization overhead, the data to be processed is cyclically distributed so that the data to be processed is vectorized. This can vectorize the data to be processed, avoid the occurrence of a negative acceleration effect, and also avoid placing additional performance requirements on the compiler.
[0077] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0078] The methods or devices described in the above embodiments provided in this specification can implement business logic through computer programs and record them on storage media, and the storage media can be read and executed by computers to achieve the effects of the solutions described in the embodiments of this specification, such as:
[0079] determining loop execution overhead according to loop information of data to be processed;
[0080] Determining vectorization overhead of the data to be processed;
[0081] When the loop execution overhead is greater than the vectorization overhead, the data to be processed are cyclically distributed so that the data to be processed are vectorized.
[0082] The storage medium may include a physical device for storing information, which is usually a medium that digitizes information and then stores it in an electrical, magnetic or optical manner. The storage medium may include: a device that stores information in an electrical energy manner, such as various memories, such as RAM, ROM, etc.; a device that stores information in a magnetic energy manner, such as a hard disk, a floppy disk, a magnetic tape, a magnetic core memory, a magnetic bubble memory, a USB flash drive; a device that stores information in an optical manner, such as a CD or a DVD. Of course, there are other readable storage media, such as quantum memory, graphene memory, etc.
[0083] The embodiments of this specification are not limited to complying with industry communication standards, standard computer resource data update and data storage rules, or the situations described in one or more embodiments of this specification. Certain industry standards or slightly modified implementation plans based on the implementation described in the custom method or embodiment can also achieve the same, equivalent or similar, or predictable implementation effects after deformation of the above-mentioned embodiments. The embodiments obtained by using these modified or deformed data acquisition, storage, judgment, processing methods, etc. can still fall within the scope of the optional implementation plans of the embodiments of this specification.
[0084] The device embodiments described above are merely illustrative. For example, the division of the units is merely a logical function division. There may be other divisions in actual implementation, such as multiple units or plug-ins may be combined or integrated into another system, or some features may be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed may be through some interface, indirect coupling or communication connection of the device or unit, which may be electrical, mechanical or other forms.
[0085] These computer program instructions may also be loaded onto a computer or other programmable resource data updating device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions executed on the computer or other programmable device for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0086] Each embodiment in this specification is described in a progressive manner, and the same and similar parts between the embodiments can be referenced to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can refer to the partial description of the method embodiment. In the description of this specification, the description of the reference terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of this specification. In this specification, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art can combine and combine the different embodiments or examples described in this specification and the features of different embodiments or examples without contradiction.
[0087] Those skilled in the art will appreciate that the embodiments described herein are intended to help readers understand the principles of the present invention, and should be understood that the protection scope of the present invention is not limited to such specific statements and embodiments. Those skilled in the art can make various other specific variations and combinations that do not deviate from the essence of the present invention based on the technical revelations disclosed by the present invention, and these variations and combinations are still within the protection scope of the present invention.
Claims
1. A data vectorization processing method, characterized in that: The method comprises: determining loop execution overhead according to loop information of data to be processed; Determining vectorization overhead of the data to be processed; When the loop execution overhead is greater than the vectorization overhead, the data to be processed are cyclically distributed so that the data to be processed are vectorized.
2. The data vectorization processing method according to claim 1, characterized in that: The loop execution overhead includes loop execution internal overhead and loop execution external overhead, and the loop execution overhead is specifically determined by the following formula: Wherein, dist scalar cost is the loop execution cost, n is the number of partitions, distscalarinsidecostp is the internal loop execution cost of a single partition, and dist scalar outside costp is the external loop execution cost of a single partition.
3. The data vectorization processing method according to claim 2, characterized in that: The internal overhead of the loop execution of a single partition is determined by the following formula: dist scalarinside costp=SIC*niters Wherein, SIC is the sum of the overheads of all instructions in one iteration, and niters is the number of loop iterations in the loop information.
4. The data vectorization processing method according to claim 2, characterized in that: The external overhead of the loop execution of the single partition specifically includes a header overhead, a tail overhead and a version check overhead.
5. The data vectorization processing method according to claim 1, characterized in that: The vectorization overhead includes a first internal overhead and a first external overhead, and the vectorization overhead is specifically determined by the following formula: In the formula, distvect cost is the vectorization cost, n is the number of partitions, distvect inside costp is the first internal cost of a single partition, and distvect outside costp is the first external cost of a single partition.
6. The data vectorization processing method according to claim 5, characterized in that: The first internal cost of the single partition is determined by the following formula: distvectinside costp=VIC*(niters / VF) Wherein, VIC is the loop overhead in one iteration, niters is the number of loop iterations in the loop information, and VF is the vectorization factor.
7. The data vectorization processing method according to claim 5, characterized in that: The first external overhead specifically includes overhead caused by non-alignment and aliasing and SLP overhead.
8. A data vectorization processing device, characterized in that: The device comprises: A first determining module, configured to determine a loop execution overhead according to loop information of data to be processed; A second determination module, used to determine the vectorization overhead of the data to be processed; The execution module is used to perform cyclic distribution on the data to be processed when the loop execution overhead is greater than the vectorization overhead, so as to complete vectorization of the data to be processed.
