CN112445316A - Compile-time low-power-consumption optimization method based on vector calculation - Google Patents
Compile-time low-power-consumption optimization method based on vector calculation Download PDFInfo
- Publication number
- CN112445316A CN112445316A CN201910794732.5A CN201910794732A CN112445316A CN 112445316 A CN112445316 A CN 112445316A CN 201910794732 A CN201910794732 A CN 201910794732A CN 112445316 A CN112445316 A CN 112445316A
- Authority
- CN
- China
- Prior art keywords
- vector
- calculation
- analysis
- library
- expression
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Withdrawn
Links
- 239000013598 vector Substances 0.000 title claims abstract description 128
- 238000004364 calculation method Methods 0.000 title claims abstract description 93
- 238000000034 method Methods 0.000 title claims abstract description 20
- 238000005457 optimization Methods 0.000 title claims abstract description 20
- 238000004458 analytical method Methods 0.000 claims abstract description 28
- 230000014509 gene expression Effects 0.000 claims abstract description 23
- 238000005206 flow analysis Methods 0.000 claims abstract description 20
- 230000003068 static effect Effects 0.000 claims abstract description 20
- 230000002159 abnormal effect Effects 0.000 claims description 4
- 238000001514 detection method Methods 0.000 claims description 4
- 238000005265 energy consumption Methods 0.000 abstract description 6
- 238000005065 mining Methods 0.000 abstract description 5
- 238000013433 optimization analysis Methods 0.000 description 4
- 238000010586 diagram Methods 0.000 description 2
- 230000000694 effects Effects 0.000 description 2
- 238000005516 engineering process Methods 0.000 description 2
- 238000003491 array Methods 0.000 description 1
- 238000006243 chemical reaction Methods 0.000 description 1
- 230000006870 function Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F1/00—Details not covered by groups G06F3/00 - G06F13/00 and G06F21/00
- G06F1/26—Power supply means, e.g. regulation thereof
- G06F1/32—Means for saving power
- G06F1/3203—Power management, i.e. event-based initiation of a power-saving mode
- G06F1/3234—Power saving characterised by the action undertaken
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Software Systems (AREA)
- Devices For Executing Special Programs (AREA)
Abstract
The invention discloses a compiling time low-power consumption optimization method based on vector calculation, which comprises the following steps: a compiler reads in a source program, and identifies and marks the condition that vector calculation parameters are constants through optimized analysis means of lexical analysis, syntactic analysis, semantic analysis, control flow analysis and data flow analysis; when analyzing that the parameters in the vector calculation expression are immediate vectors, the compiler calls a vector static pre-calculation library to calculate when performing expression matching, and then replaces the original expression with the calculated result; and when the compiler analyzes that the parameters in the vector calculation are initial value-assigned variables or constant variables, calling the vector static pre-calculation library for calculation, and then replacing the original expression with the calculated result. The method achieves the purpose of mining the precomputation capability of the vector data as much as possible during compiling, mines the precomputation capability of the vector data, reduces the vector access and calculation during running, improves the program performance, and reduces the energy consumption of a processor.
Description
Technical Field
The invention relates to a compiling time low-power consumption optimization method based on vector calculation, and belongs to the technical field of computers.
Background
To improve computational performance, many current mainstream processors support vector instructions. The AVX instruction set of Intel, for example, has currently supported 512b vector computations. Compared with the traditional scalar calculation, one vector instruction can simultaneously complete the functions of a plurality of scalar instructions, so that the execution of the program can be greatly accelerated, and on the other hand, the energy consumption caused by the program operation is reduced.
Efficient compilation optimization is indispensable to fully exploit the performance of the processor. However, the compiling optimization for vector calculation faces many difficulties, the specificity of vector instructions has unique requirements on the locality of programs, the correlation between data, the conversion between vectors and scalars, etc., and the mainstream compiler GCC generally simply compiles the vector instructions into vector instructions supported by processor hardware for execution for vector calculation, and cannot exert the optimizing capability of compiling to the maximum extent.
At present, the compiling optimization technology aiming at the vector (except the automatic vectorization of an Icc commercial compiler of an Intel processor) is rare, the effect is not ideal, the vector calculation cannot be optimized to the optimal effect in many cases, and even the mainstream compiler GCC is not exceptional. For example, for vector calculation with a parameter being a constant (e.g., an immediate vector, an initial value-assigned variable, or a constant variable), the GCC still passes the parameter to the back end, and finally generates a vector calculation instruction (e.g., vector addition, vector multiplication, etc.) for runtime calculation; and the values of the vector constant parameters are stored in corresponding data segments, loaded into a register through the access operation and then subjected to vector calculation. Thus, the calculation that can determine the result originally at the time of compiling needs to obtain the result through the access and calculation in multiple times of running, which actually reduces the calculation efficiency of the program and increases the power consumption in running.
Disclosure of Invention
The invention aims to provide a compiling-time low-power-consumption optimization method based on vector calculation, which realizes the purpose of mining the precomputation capability of vector data as much as possible during compiling, mines the precomputation capability of the vector data, reduces the vector access and calculation during running, improves the program performance and reduces the energy consumption of a processor.
In order to achieve the purpose, the invention adopts the technical scheme that: a compile-time low-power optimization method based on vector calculation comprises the following steps:
s1, constructing a vector static pre-calculation library, and specifically comprising the following steps:
s11, extracting each scalar component of the vector participating in calculation, and calling the original scalar calculation library of the GCC for each pair of corresponding scalar components to calculate to obtain a result;
s12, assembling the scalar results calculated in the S11 into a new result vector according to the sequence;
s13, performing type and range detection on the result vector obtained in S12, and confirming that the new result vector meets the requirement of the source operand vector data type and the value of the new result vector is within the maximum and minimum value range which can be expressed by the source operand vector data type;
s2, reading a source program by a compiler, sequentially performing lexical analysis, syntax analysis, semantic analysis, control flow analysis and data flow analysis, identifying the condition that vector calculation parameters are constants, and marking;
s3, on the basis of lexical analysis, syntactic analysis and semantic analysis, when parameters in a vector calculation expression are analyzed to be immediate vectors, and the expression is matched, calling a vector static pre-calculation library for calculation, and replacing the original expression with the calculated result;
and S4, on the basis of control flow analysis and data flow analysis, when parameters in the vector calculation expression are analyzed to be initial value-assigned variables or constant variables, calling a vector static pre-calculation library for calculation, and replacing the original expression with the calculated result.
The further improved scheme in the technical scheme is as follows:
1. in the scheme, in the operation process of the vector static precomputation library, corresponding boundary conditions and abnormal conditions are processed according to the actually calculated semantics.
Due to the application of the technical scheme, compared with the prior art, the invention has the following advantages:
the invention relates to a compiling-time low-power-consumption optimization method based on vector calculation, which identifies the condition that vector calculation parameters are constants by utilizing various optimization analysis of a compiler, completes compiling-time calculation aiming at constant vectors by compiling a static vector pre-calculation library and calling the vector pre-calculation library respectively during front-end and middle-end constant optimization, realizes the purpose of mining the pre-calculation capacity of vector data as much as possible during compiling, mines the pre-calculation capacity of the vector data, reduces the vector access and calculation during running, improves the program performance and reduces the energy consumption of a processor.
Drawings
FIG. 1 is a schematic diagram of the structural principle of the compiling time low-power consumption optimization method based on vector calculation;
FIG. 2 is a flow chart of a compile-time low-power optimization method based on vector calculation according to the present invention;
FIG. 3 is a schematic diagram of a general flow of a vector division static pre-calculation library in the optimization method of the present invention.
Detailed Description
Example (b): a compile-time low-power optimization method based on vector calculation comprises the following steps:
s1, constructing a vector static pre-calculation library, and specifically comprising the following steps:
s11, extracting each scalar component of the vector participating in calculation, and calling the original scalar calculation library of the GCC for each pair of corresponding scalar components to calculate to obtain a result;
s12, assembling the scalar results calculated in the S11 into a new result vector according to the sequence;
s13, performing type and range detection on the result vector obtained in S12, and confirming that the new result vector meets the requirement of the source operand vector data type and the value of the new result vector is within the maximum and minimum value range which can be expressed by the source operand vector data type;
s2, reading a source program by a compiler, sequentially performing lexical analysis, syntax analysis, semantic analysis, control flow analysis and data flow analysis, identifying the condition that vector calculation parameters are constants, and marking;
s3, on the basis of lexical analysis, syntactic analysis and semantic analysis, when parameters in a vector calculation expression are analyzed to be immediate vectors, and the expression is matched, calling a vector static pre-calculation library for calculation, and replacing the original expression with the calculated result;
and S4, on the basis of control flow analysis and data flow analysis, when parameters in the vector calculation expression are analyzed to be initial value-assigned variables or constant variables, calling a vector static pre-calculation library for calculation, and replacing the original expression with the calculated result.
And in the operation process of the vector static pre-calculation library, corresponding boundary conditions and abnormal conditions are processed according to the actually calculated semantics.
The examples are further explained below:
the compiler reads in a source program, identifies the condition that vector calculation parameters are constant through various optimization analysis means such as lexical analysis, syntactic analysis, semantic analysis, control flow analysis, data flow analysis and the like, and respectively calls a vector pre-calculation library during front-end and middle-end optimization to realize the pre-calculation capability of mining vector data during compilation and reduce the performance and power consumption pressure on the processor during running.
The invention is based on the existing GCC compiler, and the specific flow is briefly described as follows:
1) a compiler reads in a program, and identifies and marks the condition that vector calculation parameters are constants (immediate vectors, initial value-assigned variables or constant variables) through various optimization analysis means such as lexical analysis, syntax analysis, semantic analysis, control flow analysis, data flow analysis and the like;
2) after analyzing the condition that the parameters in the vector calculation expression are immediate vectors, the compiler calls a vector static precomputation library to calculate when the expressions are matched, and then replaces the original expression with the calculated result;
3) on the basis of control flow analysis and data flow analysis, the middle end of the compiler analyzes the condition that parameters in vector calculation are initial value variables or constant variables, calls a vector static pre-calculation library for calculation, and then replaces the original expression with the calculated result.
As a key technology of the invention, the vector static pre-calculation library is responsible for calculating the constant vectors meeting the conditions during compiling, obtaining a new result and returning the new result. The vector precomputation library needs to complete corresponding calculation aiming at different scalar data types and different arithmetic operations.
Taking vector division as an example, the general flow of vector pre-computation library is divided into the following steps:
1) for the divisor vector, extracting each scalar component of the divisor vector, judging each component, and if the scalar component is equal to 0, reporting a divisor 0 error and exiting;
2) extracting each scalar component of dividend and divisor vectors, and calling the original scalar division library of GCC for each pair of corresponding scalar components to calculate to obtain a result;
3) assembling the computed scalar results into a new result vector in order;
4) detecting the type and the range of the result vector;
vector precomputation libraries for other calculations (such as addition, subtraction, multiplication, square-heel solving, logic operation, shift and the like) are the same as or different from the vector precomputation libraries, only corresponding boundary conditions, abnormal condition processing and the like are needed to be carried out according to actual calculation semantics, essentially, the vectors are decomposed into a plurality of scalars, the original scalar calculation library of the GCC is called for calculation, then scalar calculation results are assembled to form result vectors, and finally, type and range detection is carried out on the results according to the corresponding semantics.
When the compiling-time low-power-consumption optimization method based on the vector calculation is adopted, the condition that the vector calculation parameters are constants is identified by various optimization analysis of a compiler, the compiling-time calculation of the constant vectors is completed by compiling the static vector pre-calculation library and calling the vector pre-calculation library respectively during the optimization of the front-end constants and the middle-end constants, the aim of mining the pre-calculation capacity of the vector data as much as possible during compiling is fulfilled, the pre-calculation capacity of the vector data is mined, the vector access and calculation during the operation are reduced, the program performance is improved, and the energy consumption of a processor is reduced.
To facilitate a better understanding of the invention, the terms used herein will be briefly explained as follows:
compiling: a process for generating an object program from a source program written in a source language using a compiler.
Vector quantity: one place to store data, like one-dimensional arrays and linked lists.
Low power consumption: memory access and calculation during running are reduced, program performance is improved, and energy consumption of a processor is reduced.
The above embodiments are merely illustrative of the technical ideas and features of the present invention, and the purpose thereof is to enable those skilled in the art to understand the contents of the present invention and implement the present invention, and not to limit the protection scope of the present invention. All equivalent changes and modifications made according to the spirit of the present invention should be covered within the protection scope of the present invention.
Claims (2)
1. A compile-time low-power consumption optimization method based on vector calculation is characterized in that: the method comprises the following steps:
s1, constructing a vector static pre-calculation library, and specifically comprising the following steps:
s11, extracting each scalar component of the vector participating in calculation, and calling the original scalar calculation library of the GCC for each pair of corresponding scalar components to calculate to obtain a result;
s12, assembling the scalar results calculated in the S11 into a new result vector according to the sequence;
s13, performing type and range detection on the result vector obtained in S12, and confirming that the new result vector meets the requirement of the source operand vector data type and the value of the new result vector is within the maximum and minimum value range which can be expressed by the source operand vector data type;
s2, reading a source program by a compiler, sequentially performing lexical analysis, syntax analysis, semantic analysis, control flow analysis and data flow analysis, identifying the condition that vector calculation parameters are constants, and marking;
s3, on the basis of lexical analysis, syntactic analysis and semantic analysis, when parameters in a vector calculation expression are analyzed to be immediate vectors, and the expression is matched, calling a vector static pre-calculation library for calculation, and replacing the original expression with the calculated result;
and S4, on the basis of control flow analysis and data flow analysis, when parameters in the vector calculation expression are analyzed to be initial value-assigned variables or constant variables, calling a vector static pre-calculation library for calculation, and replacing the original expression with the calculated result.
2. The method of vector computation-based compile-time low-power optimization of claim 1, wherein: and in the process of calling the vector static precomputation library to calculate, carrying out corresponding boundary condition and abnormal condition treatment according to the actually calculated semantics.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910794732.5A CN112445316A (en) | 2019-08-27 | 2019-08-27 | Compile-time low-power-consumption optimization method based on vector calculation |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910794732.5A CN112445316A (en) | 2019-08-27 | 2019-08-27 | Compile-time low-power-consumption optimization method based on vector calculation |
Publications (1)
Publication Number | Publication Date |
---|---|
CN112445316A true CN112445316A (en) | 2021-03-05 |
Family
ID=74741617
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201910794732.5A Withdrawn CN112445316A (en) | 2019-08-27 | 2019-08-27 | Compile-time low-power-consumption optimization method based on vector calculation |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN112445316A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN114237612A (en) * | 2021-12-03 | 2022-03-25 | 龙芯中科技术股份有限公司 | Program code compiling method, program code compiling device, electronic equipment and storage medium |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104424263A (en) * | 2013-08-29 | 2015-03-18 | 腾讯科技(深圳)有限公司 | Data recording method and data recording device |
CN109753306A (en) * | 2018-12-28 | 2019-05-14 | 北京东方国信科技股份有限公司 | A kind of big data processing method of because precompiled function caching engine |
-
2019
- 2019-08-27 CN CN201910794732.5A patent/CN112445316A/en not_active Withdrawn
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104424263A (en) * | 2013-08-29 | 2015-03-18 | 腾讯科技(深圳)有限公司 | Data recording method and data recording device |
CN109753306A (en) * | 2018-12-28 | 2019-05-14 | 北京东方国信科技股份有限公司 | A kind of big data processing method of because precompiled function caching engine |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN114237612A (en) * | 2021-12-03 | 2022-03-25 | 龙芯中科技术股份有限公司 | Program code compiling method, program code compiling device, electronic equipment and storage medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
Ho et al. | Exploiting half precision arithmetic in Nvidia GPUs | |
CN100388203C (en) | Optimize code automatic generation system | |
US6113650A (en) | Compiler for optimization in generating instruction sequence and compiling method | |
Laguna et al. | Gpumixer: Performance-driven floating-point tuning for gpu scientific applications | |
CN104536898B (en) | The detection method of c program parallel regions | |
CN103473168B (en) | A kind of statistical method of focus program | |
US20130067196A1 (en) | Vectorization of machine level scalar instructions in a computer program during execution of the computer program | |
US9720663B2 (en) | Methods, systems and apparatus to optimize sparse matrix applications | |
Feng et al. | Evaluation of compilers’ capability of automatic vectorization based on source code analysis | |
Albert et al. | SuperStack: Superoptimization of stack-bytecode via greedy, constraint-based, and SAT techniques | |
CN112445316A (en) | Compile-time low-power-consumption optimization method based on vector calculation | |
Fahringer et al. | A unified symbolic evaluation framework for parallelizing compilers | |
CN110673877B (en) | A Parallel Computing Method Based on Manual Vectorization | |
Yu et al. | Case study: optimization methods with TVM hybrid-op on RISC-V packed SIMD | |
Kumar et al. | An approach for compiler optimization to exploit instruction level parallelism | |
Huang et al. | Efficient multimedia coprocessor with enhanced SIMD engines for exploiting ILP and DLP | |
Chadha et al. | Performance Analysis of Accelerated Linear Algebra Compiler for TensorFlow | |
CN115113875B (en) | COStream-based data flow workload refined estimation method | |
CN119336334B (en) | Compiling optimization method for deep learning model with constant partial parameters | |
Kong et al. | Research on control flow conversion technique based on Domestic Sunway compiler | |
Pereira et al. | Beetle: A feature-based approach to reduce staleness in profile data | |
Sun et al. | Co-Utilizing SIMD and Scalar to Accelerate the Data Analytics Workloads | |
Sun et al. | Vectorizing programs with IF-statements for processors with SIMD extensions | |
Li et al. | LLVM Framework: Research and Applications | |
McFarlin et al. | Library function selection in compiling Octave |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
WW01 | Invention patent application withdrawn after publication | ||
WW01 | Invention patent application withdrawn after publication |
Application publication date: 20210305 |