Search

CN-121979517-A - Simulink model code generation method and system based on redundancy elimination

CN121979517ACN 121979517 ACN121979517 ACN 121979517ACN-121979517-A

Abstract

The invention provides a Simulink model code generation method and system based on redundancy elimination, wherein the method comprises the steps of analyzing a Simulink model to construct a data flow diagram and acquiring an input/output mapping relation of each component; the method comprises the steps of determining an accurate output range of a target component in a data flow graph by analyzing data use requirements of a subsequent component, reversely deducing the accurate input range of the target component based on an input/output mapping relation, identifying the component as an optimizable component if the range is reduced, reorganizing memory layout of effective data of the optimizable component, reconstructing the input/output mapping relation, and generating a simplified code for executing only necessary calculation based on the input/output mapping relation. According to the invention, through global data flow analysis, CPU load and memory occupation when the generated code is executed on the embedded system can be obviously reduced, and the execution efficiency and memory utilization rate of the generated code are improved.

Inventors

  • YU ZEHONG
  • SU ZHUO
  • Pu Jinxiao
  • SHI DALONG
  • JIANG YU

Assignees

  • 清华大学
  • 中航国际金网(北京)科技有限公司

Dates

Publication Date
20260505
Application Date
20251226

Claims (10)

  1. 1. A Simulink model code generation method based on redundancy elimination is characterized by comprising the following steps: Analyzing a Simulink model, constructing a data flow graph representing the data flow direction in the Simulink model based on the analyzed attribute of each component in the Simulink model and the connection relation among the components, and acquiring the input/output mapping relation of each component in the data flow graph; determining the accurate output range of a target component in the data flow diagram by analyzing the data use requirements of one or more subsequent components of the target component; determining an accurate input range of the target component based on the accurate output range and an input/output mapping relation of the target component; determining whether the exact input range or the exact output range of the target component is a proper subset of its corresponding original range, identifying the target component as an optimizable component; For the optimizable component, reorganizing the memory layout of the input and output data according to the precise input range and the precise output range of the optimizable component, and rebuilding the input/output mapping relation of the optimizable component based on the new memory layout; Based on the reconstructed input/output mapping relationship, the precise input range and the precise output range, generating simplified codes for the optimizable component, wherein the simplified codes only execute necessary calculation.
  2. 2. The method for generating a Simulink model code based on redundancy elimination according to claim 1, wherein the determining the accurate output range of the target component by analyzing the data usage requirement of one or more subsequent components thereof specifically comprises: determining that one or more subsequent components exist in the target component, recursively acquiring the precise input range of each subsequent component, and taking the union of the corresponding precise input ranges of all the subsequent components as the precise output range of the target component, or And determining that the target component does not have a subsequent component, and taking the original output range as the accurate output range.
  3. 3. The method for generating a Simulink model code based on redundancy elimination according to claim 1 or 2, wherein the determining the precise input range of the target component based on the precise output range and the input/output mapping relation of the target component specifically includes: traversing each output element within the precise output range; For each output element, reversely searching one or more input elements required by calculating the output element according to the input/output mapping relation; and determining the set of all the searched required input elements as the accurate input range of the target component.
  4. 4. The method for generating a Simulink model code based on redundancy elimination according to claim 1, wherein the reorganizing the memory layout of the input and output data thereof specifically comprises: Allocating contiguous memory space only for valid data elements within the precision input range and the precision output range, and calculating a new index in the contiguous memory space for each valid data element.
  5. 5. The method for generating Simulink model code based on redundancy elimination according to claim 4, wherein the reconstructing the input/output mapping relation based on the new memory layout specifically includes: And updating the original input/output mapping relation of the target component by using the new index of the effective data element so as to reflect the new position of the data in the continuous storage space.
  6. 6. The method for generating a Simulink model code based on redundancy elimination according to claim 4 or 5, wherein the generating a reduced code for the optimizable component that performs only necessary computation based on the reconstructed input/output mapping relation, the precise input range, and the precise output range includes: selecting a code template matched with the function of the optimizable component from a pre-constructed code library; substituting the reconstructed input/output mapping relation, the precise input range and the precise output range into the code template as parameters to generate a final code statement.
  7. 7. A Simulink model code generation method based on redundancy elimination according to claim 1or2, wherein the data usage requirements of the successor component are defined by a data intercept class component in the Simulink model, the data intercept class component being configured to select a portion of data from its input data stream for subsequent computation.
  8. 8. A Simulink model code generation system based on redundancy elimination, comprising: the analysis module is used for analyzing the Simulink model, constructing a data flow graph representing the data flow direction in the Simulink model based on the analyzed attribute of each component in the Simulink model and the connection relation among the components, and acquiring the input/output mapping relation of each component in the data flow graph; the accurate output determining module is used for determining the accurate output range of the target component in the data flow diagram by analyzing the data use requirement of one or more subsequent components of the target component; The accurate input determining module is used for determining the accurate input range of the target component based on the accurate output range and the input/output mapping relation of the target component; An optimizable component determination module for identifying the target component as an optimizable component if the exact input range or the exact output range of the target component is a proper subset of its corresponding original range; The memory layout reconstruction module is used for reorganizing the memory layout of the input and output data of the optimizable component according to the precise input range and the precise output range of the optimizable component, and reconstructing the input/output mapping relation of the optimizable component based on the new memory layout; and the redundancy elimination module is used for generating a reduced code for executing only necessary calculation for the optimizable component based on the reconstructed input/output mapping relation, the precise input range and the precise output range.
  9. 9. An electronic device comprising a memory, a processor and a computer program stored on the memory and running on the processor, wherein the processor implements the redundancy elimination-based Simulink model code generation method of any one of claims 1 to 7 when the computer program is executed by the processor.
  10. 10. A non-transitory computer readable storage medium having stored thereon a computer program, wherein the computer program when executed by a processor implements the Simulink model code generation method based on redundancy elimination according to any one of claims 1 to 7.

Description

Simulink model code generation method and system based on redundancy elimination Technical Field The invention relates to the technical field of model drive design and embedded code generation, in particular to a Simulink model code generation method and system based on redundancy elimination. Background In the development of modern embedded systems for automotive electronics, aerospace, and the like, model-driven design (Model-DRIVEN DESIGN, MDD) has become the dominant paradigm. The Simulink is taken as a graphical modeling environment, and becomes a real core infrastructure in the field by virtue of the strong simulation, verification and code generation capability. The developer builds a system model through Simulink and directly converts the system model into deployable embedded C/C++ codes by utilizing an automatic code generation technology. The process greatly improves the development efficiency, reduces the manual coding errors, remarkably improves the development efficiency and ensures the software quality. To meet the stringent requirements of embedded systems for high performance and low resource usage, code generators often integrate a variety of optimization techniques. For example, the business tool Simulink Embedded Coder can implement optimization of expression folding and data buffer multiplexing, etc. Academic research has also proposed optimization methods for specific scenarios, such as accelerating complex branch logic or generating parallel instructions (SIMDs). These methods are highly effective in improving code quality. However, the prior art has a significantly shorter plate when dealing with increasingly popular data-intensive models. Such models are commonly used in the fields of digital signal processing, electric drive control and the like, and are characterized in that a large number of operations are performed based on arrays or matrices. The optimization granularity of current code generators is mostly limited to a single component or statement, lacking the capability of analyzing the model global data stream. This results in a ubiquitous and costly problem in that, after an upstream component has completed a calculation of the entire data array, its downstream component (e.g., the Selector) may use only a small portion of it. Existing methods cannot identify such cross-component data dependencies and thus still generate redundant code that computes a complete array. The inherent redundant calculation and memory occupation seriously waste the precious CPU period and memory resources of the embedded equipment, and directly influence the performance of the final software. Thus, existing code generation techniques do not provide an optimal solution for data intensive applications. Disclosure of Invention The invention provides a Simulink model code generation method and system based on redundancy elimination, which are used for solving the defects of a large amount of redundancy calculation and memory occupation of codes generated by a data-intensive model in the prior art and realizing accurate identification and elimination of cross-component redundancy calculation. The invention provides a Simulink model code generation method based on redundancy elimination, which comprises the following steps: Analyzing a Simulink model, constructing a data flow graph representing the data flow direction in the Simulink model based on the analyzed attribute of each component in the Simulink model and the connection relation among the components, and acquiring the input/output mapping relation of each component in the data flow graph; Determining, for a target component in the dataflow graph, an accurate output range of the target component by analyzing data usage requirements of one or more subsequent components thereof; determining an accurate input range of the target component based on the accurate output range and an input/output mapping relation of the target component; If the exact input range or exact output range of the target component is a proper subset of its corresponding original range, identifying the target component as an optimizable component; For the optimizable component, reorganizing the memory layout of the input and output data according to the precise input range and the precise output range of the optimizable component, and rebuilding the input/output mapping relation of the optimizable component based on the new memory layout; Based on the reconstructed input/output mapping relationship, the precise input range and the precise output range, generating simplified codes for the optimizable component, wherein the simplified codes only execute necessary calculation. According to the Simulink model code generation method based on redundancy elimination provided by the invention, the accurate output range of the target component is determined by analyzing the data use requirements of one or more subsequent components, and the method specifically comprises the following