A heterogeneous compilation method, device and equipment of a power system simulation model

By writing simulation models and intermediate representations in domain-specific languages ​​and combining them with heterogeneous hardware platform information, the simulation models are automatically mapped to the target platform. This solves the problems of tight coupling between models and hardware and narrow adaptability in existing technologies, and realizes efficient cross-platform migration and resource utilization for power system simulation.

CN123137658APending Publication Date: 2026-11-20ELECTRIC POWER RES INST CHINA SOUTHERN POWER GRID CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611353386.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-02
Publication Date
2026-11-20

AI Technical Summary

Technical Problem

Existing power simulation platforms have models that are tightly coupled with hardware, requiring complete rewriting for cross-platform migration. They also have a narrow range of hardware compatibility, lack automated analysis capabilities, and are unable to meet the simulation needs of large-scale complex power grids.

Method used

The simulation model is written in a domain-specific language, an expanded syntax tree is generated, an intermediate representation is constructed, and task scheduling decisions are made through simulation computation graphs and heterogeneous hardware platform information. The model is automatically mapped to the target heterogeneous platform and heterogeneous executable code is generated.

Benefits of technology

It achieves complete decoupling between the model and the hardware, adapts to multiple hardware platforms, eliminates the need to rewrite code, improves the utilization of heterogeneous hardware resources, automates task scheduling, and meets the needs of large-scale complex power grid simulation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123137658A_ABST
    Figure CN123137658A_ABST
Patent Text Reader

Abstract

The application discloses a heterogeneous compiling method, device and equipment of a power system simulation model, and the method comprises the following steps: writing a simulation model according to a preset domain-specific language, and generating an expanded syntax tree in combination with semantic analysis; generating an intermediate representation which is extended from a high layer to a low layer inside a compiler according to the expanded syntax tree; performing simulation calculation relationship analysis according to the intermediate representation, and constructing a simulation calculation graph, wherein the simulation calculation graph comprises a dependency label and parallelism; based on heterogeneous hardware platform information, mapping a simulation task to a target heterogeneous platform in a task scheduling decision manner according to the simulation calculation graph and the intermediate representation, triggering a code generator and a to-be-optimized hardware to perform heterogeneous hardware automatic mapping compilation, and generating heterogeneous execution code. The application can solve the technical problems that the existing technology cannot be migrated due to the close coupling between a model and hardware, the hardware adaptation range is narrow, and the automatic analysis capability is insufficient, so the task scheduling is excessively dependent on manual work, and it is difficult to meet the simulation requirements of large-scale complex power grids.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of power system technology, and in particular to a heterogeneous compilation method, apparatus and equipment for power system simulation models. Background Technology

[0002] With the large-scale grid connection of new energy sources, the widespread integration of power electronic devices, and the increasing complexity of AC / DC hybrid power grid structures in new power systems, the demand for computing power in power system simulation is growing exponentially. Real-time and ultra-real-time simulation have become core technologies for power grid planning, design, and operation verification, directly supporting the safe and stable operation of new power systems. Meanwhile, the rapid development of heterogeneous computing hardware such as CPUs, GPUs, FPGAs, and ASICs provides diversified options for enhancing simulation computing power. How to efficiently tap the computing potential of heterogeneous hardware has become a core challenge in the field of power simulation.

[0003] Current mainstream power simulation platforms all adopt proprietary technology routes: the PSCAD platform uses Fortran to write simulation models, which are then compiled into CPU executable code; the RTDS platform uses the RSCAD proprietary scripting language, which is compiled to run on a self-developed dedicated processor; and the RT-LAB platform is based on MATLAB / Simulink modeling, compiling the models into FPGA hardware descriptions or embedded processor code. These platforms meet the simulation needs of specific scenarios through specialized design, but with the expansion of power grid scale and the iteration of hardware technology, their architectural limitations are becoming increasingly apparent.

[0004] Therefore, existing technologies still have some limitations. First, the model and hardware are tightly coupled, and each platform uses proprietary modeling languages ​​and compilation toolchains. Cross-platform migration of simulation models requires complete rewriting, resulting in a large amount of redundant development and waste of model assets. Second, the hardware compatibility is narrow, supporting only single or a few hardware to generate code, and cannot automatically match the optimal hardware according to the characteristics of the simulation task, resulting in low utilization of heterogeneous computing resources. Third, there is a lack of automated analysis capabilities, relying on manual task division and parallelism tuning. The execution performance of the generated code is significantly different from that of manual optimization, making it difficult to adapt to the simulation needs of large-scale complex power grids. Summary of the Invention

[0005] This application provides a heterogeneous compilation method, apparatus, and equipment for power system simulation models, which solves the technical problems of existing technology models being tightly coupled with hardware and unable to be migrated, having a narrow hardware adaptation range, and lacking automated analysis capabilities, thus relying excessively on manual task scheduling, making it difficult to meet the simulation needs of large-scale complex power grids.

[0006] In view of this, the first aspect of this application provides a heterogeneous compilation method for power system simulation models, including:

[0007] The simulation model is written in a specific language of the preset domain, and an expanded syntax tree is generated by combining semantic analysis. The simulation model describes the topology, component parameters, control strategies and simulation conditions of the power system.

[0008] Based on the expanded syntax tree, an intermediate representation is generated internally by the compiler, expanding from high to low levels;

[0009] Based on the intermediate representation, a simulation calculation relationship analysis is performed to construct a simulation calculation graph, which includes dependency labeling and parallelism.

[0010] Based on heterogeneous hardware platform information, the simulation task is mapped to the target heterogeneous platform in a task scheduling decision manner according to the simulation calculation graph and the intermediate representation, triggering the code generator and the hardware to be optimized to automatically compile heterogeneous hardware mapping and generate heterogeneous executable code.

[0011] Preferably, the step of writing a simulation model based on a specific language of a preset domain and generating an expanded syntax tree by combining semantic analysis includes:

[0012] A simulation model of the power system is written in a specific language of the preset domain, and a DSL simulation source file is generated.

[0013] The text of the DSL simulation source file is scanned using a preset lexical analyzer, and the text is filtered to generate a lexical tag sequence;

[0014] An abstract syntax tree is constructed by performing a preset parser to match and analyze the lexical tag sequence in a preset order.

[0015] Multiple semantic checks and domain primitive expansion operations are performed on the abstract syntax tree to generate an expanded syntax tree. The semantic checks and analyses include symbol resolution, type checking, and domain constraint checking.

[0016] Preferably, the step of performing simulation calculation relationship analysis based on the intermediate representation and constructing a simulation calculation graph includes:

[0017] Traverse the lower-level intermediate representations in the intermediate representations and establish data dependency edges based on instruction operation reference relationships to generate a dependency graph;

[0018] The dependency graph is subjected to simulation time cycle analysis, and the maximum number of tasks to be executed in parallel, computational intensity, composite dependencies, parallelism, critical path and data transfer volume are determined, generating an annotated simulation computation graph.

[0019] Preferably, the step of mapping simulation tasks to the target heterogeneous platform based on heterogeneous hardware platform information, according to the simulation computation graph and the intermediate representation, and triggering the code generator and the hardware to be optimized to perform automatic heterogeneous hardware mapping compilation to generate heterogeneous executable code includes:

[0020] Obtain information about the target hardware platform to obtain heterogeneous hardware platform information, which includes available hardware processing unit information, memory information, associated topology information, and communication parameters.

[0021] Based on the simulation calculation diagram and the heterogeneous hardware platform information, a task scheduling decision analysis is performed to determine the task scheduling scheme;

[0022] Based on the task scheduling scheme, the simulation task is mapped to the target heterogeneous platform for compilation according to the intermediate representation, generating a hardware instruction sequence.

[0023] Based on the code generator and the hardware to be optimized, hardware-specific optimization is performed according to the hardware instruction sequence to generate cross-hardware communication configuration and heterogeneous execution code.

[0024] The cross-hardware communication configuration, the heterogeneous execution code, and the startup synchronization control code are integrated to generate a heterogeneous execution code package.

[0025] Preferably, the step of mapping simulation tasks to the target heterogeneous platform based on heterogeneous hardware platform information, according to the simulation computation graph and the intermediate representation, and triggering the code generator and the hardware to be optimized to perform automatic heterogeneous hardware mapping compilation to generate heterogeneous executable code, further includes:

[0026] The simulation computation graph and the intermediate representation are subjected to general optimization processing, which includes reuse of computation results, computation of constant representation values, dead code removal, matrix sparse representation, and matrix equation decomposition.

[0027] Preferably, the step of mapping simulation tasks to the target heterogeneous platform based on heterogeneous hardware platform information, according to the simulation computation graph and the intermediate representation, and triggering the code generator and the hardware to be optimized to perform automatic heterogeneous hardware mapping compilation to generate heterogeneous executable code further includes:

[0028] The code of the heterogeneous execution code package is deployed to the target heterogeneous platform for execution verification, and the code verification results are obtained.

[0029] The execution time and communication latency of each hardware processing unit in the target heterogeneous platform are collected by instrumenting code generated by the compiler.

[0030] The performance of the compiler's mapping and scheduling decisions is verified based on the execution time and the communication delay.

[0031] The second aspect of this application provides a heterogeneous compilation device for power system simulation models, comprising:

[0032] The semantic analysis unit is used to write simulation models according to a specific language of a preset domain, and generate an expanded syntax tree by combining semantic analysis. The simulation model describes the topology, component parameters, control strategies and simulation conditions of the power system.

[0033] The building unit is used to generate an intermediate representation that expands from the high level to the low level within the compiler based on the expanded syntax tree.

[0034] A relational analysis unit is used to perform simulation computation relational analysis based on the intermediate representation and construct a simulation computation graph, which includes dependency labeling and parallelism.

[0035] The heterogeneous compilation unit is used to map simulation tasks to the target heterogeneous platform based on heterogeneous hardware platform information, according to the simulation calculation graph and the intermediate representation, in a task scheduling decision manner, triggering the code generator and the hardware to be optimized to perform automatic heterogeneous hardware mapping compilation, and generating heterogeneous executable code.

[0036] Preferably, the semantic analysis unit is specifically used for:

[0037] A simulation model of the power system is written in a specific language of the preset domain, and a DSL simulation source file is generated.

[0038] The text of the DSL simulation source file is scanned using a preset lexical analyzer, and the text is filtered to generate a lexical tag sequence;

[0039] An abstract syntax tree is constructed by performing a preset parser to match and analyze the lexical tag sequence in a preset order.

[0040] Multiple semantic checks and domain primitive expansion operations are performed on the abstract syntax tree to generate an expanded syntax tree. The semantic checks and analyses include symbol resolution, type checking, and domain constraint checking.

[0041] Preferably, the relationship analysis unit is specifically used for:

[0042] Traverse the lower-level intermediate representations in the intermediate representations and establish data dependency edges based on instruction operation reference relationships to generate a dependency graph;

[0043] The dependency graph is subjected to simulation time cycle analysis, and the maximum number of tasks to be executed in parallel, computational intensity, composite dependencies, parallelism, critical path and data transfer volume are determined, generating an annotated simulation computation graph.

[0044] A third aspect of this application provides a heterogeneous compilation device for a power system simulation model, the device including a processor and a memory;

[0045] The memory is used to store program code and transmit the program code to the processor;

[0046] The processor is used to execute the heterogeneous compilation method of the power system simulation model described in the first aspect according to the instructions in the program code.

[0047] As can be seen from the above technical solutions, the embodiments of this application have the following advantages:

[0048] This application provides a heterogeneous compilation method for power system simulation models, comprising: writing a simulation model in a predefined domain-specific language; generating an expanded syntax tree by combining semantic analysis; the simulation model describing the power system's topology, component parameters, control strategies, and simulation conditions; generating an intermediate representation that expands from high to low levels within the compiler based on the expanded syntax tree; performing simulation computation relationship analysis based on the intermediate representation to construct a simulation computation graph, which includes dependency annotations and parallelism; and mapping simulation tasks to the target heterogeneous platform based on heterogeneous hardware platform information, according to the simulation computation graph and the intermediate representation, by using task scheduling decisions, triggering the code generator and the hardware to be optimized to perform automatic heterogeneous hardware mapping compilation, and generating heterogeneous executable code.

[0049] The heterogeneous compilation method for power system simulation models provided in this application uses a pre-defined domain-specific language to write the simulation model and generates an expanded syntax tree through semantic analysis. This constructs an intermediate representation that expands from high to low levels, achieving complete decoupling between model description and hardware execution. This allows a single model to be adapted to multiple different hardware platforms without requiring complete code rewriting for platform migration. Furthermore, by combining heterogeneous hardware platform information, simulation computation graphs, and intermediate representations, automatic mapping from simulation to hardware is achieved through task scheduling decisions. This automates the matching of task characteristics with hardware features, improving the utilization rate of heterogeneous hardware resources and overcoming the current problem of narrow hardware compatibility. In addition, by constructing a computation graph containing dependency annotations and parallelism information, the reliance on manual operation is overcome. Task scheduling and optimization can be automated based on the computational relationships in the simulation computation graph, and the parallel potential of the model can be explored, narrowing the performance gap with manual optimization. This method can meet the simulation needs of large-scale complex power grids. Therefore, this application solves the technical problems of existing technologies where models are tightly coupled with hardware, preventing migration; the hardware compatibility is narrow; and the lack of automated analysis capabilities leads to excessive reliance on manual task scheduling, making it difficult to meet the simulation needs of large-scale complex power grids. Attached Figure Description

[0050] Figure 1 A flowchart illustrating a heterogeneous compilation method for a power system simulation model provided in this application embodiment;

[0051] Figure 2 A schematic diagram of the structure of a heterogeneous compilation device for a power system simulation model provided in this application embodiment;

[0052] Figure 3 A flowchart illustrating the intermediate representation construction and simulation computation graph generation process provided in this application embodiment;

[0053] Figure 4 A flowchart illustrating the overall task scheduling decision and mapping compilation process provided in this application embodiment;

[0054] Figure 5 A schematic diagram of the overall structure of the simulation compiler system provided for the application example of this application. Detailed Implementation

[0055] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present application.

[0056] Terminology Explanation:

[0057] Domain-Specific Language (DSL): A programming language designed for a specific application domain. Unlike general-purpose programming languages, DSLs focus on the modeling needs of a particular professional domain, providing syntax and semantic expression capabilities that closely resemble domain concepts. This allows domain experts to define models in a near-natural descriptive manner without needing to understand the underlying programming details. In this invention, DSL specifically refers to a model description language for the field of power system simulation.

[0058] Heterogeneous hardware refers to a hardware environment that contains multiple processing units with different architectures within the same computing system. Typical examples include central processing units (CPUs), graphics processing units (GPUs), field-programmable gate arrays (FPGAs), and application-specific integrated circuits (ASICs). Different processing units have different computing characteristics and applicable scenarios. The core goal of heterogeneous computing is to rationally allocate computing tasks to the most suitable processing units to achieve optimal performance.

[0059] A computation graph is a data structure that represents a computation process using a directed graph structure. Nodes represent computational operations or data, and edges represent data dependencies. Analyzing a computation graph can identify dependencies between tasks, parallelism, and data flow, providing structured information for the compiler to perform task scheduling and parallelization optimizations. It is a key component of the compiler's intermediate representation.

[0060] Intermediate Representation (IR): An intermediate data structure used by the compiler to convert source code into target machine code. It is independent of the source language and target hardware, preserving the semantic information of the source program while facilitating various optimization transformations. The intermediate representation is the core bridge for decoupling the front-end language from the back-end hardware, enabling the same source code to generate executable code for different target platforms after unified optimization.

[0061] Automatic mapping refers to the process by which the compiler automatically transforms an abstract computational description into a specific hardware execution scheme based on the characteristics of the computational task and the capabilities of the target hardware. This includes task partitioning, resource allocation, data layout, and communication scheduling. The goal is to generate executable code that is close to the level of manual optimization without the need for manual intervention from the user.

[0062] For easier understanding, please refer to Figure 1 An embodiment of a heterogeneous compilation method for a power system simulation model provided in this application includes:

[0063] Step 101: Write a simulation model according to the specific language of the preset domain, and generate an expanded syntax tree by combining semantic analysis. The simulation model describes the topology, component parameters, control strategy and simulation conditions of the power system.

[0064] It should be noted that, based on the specific domain of power systems, a domain-specific semantic language (DSL) can be designed for power system simulation. This DSL provides syntax and semantic expressions that meet the modeling needs of power networks and control logic, thus enabling the development of simulation models. The simulation model describes information such as the power system's topology, component parameters, control strategies, and simulation conditions; it is in the form of a source file.

[0065] The parsing process of a domain-specific language follows the compiler front-end flow; semantic analysis is the process of performing lexical analysis, syntax analysis, and semantic checks on the source files of the received simulation model; this process can organize and optimize the source files, converting them into a semantically related expanded syntax tree, which facilitates the subsequent construction of intermediate representations.

[0066] Further, step 101 includes:

[0067] A simulation model of the power system is written in a specific language of the preset domain, and a DSL simulation source file is generated.

[0068] A preset lexical analyzer is used to scan the text of the DSL simulation source file, and the text is filtered to generate a lexical tag sequence;

[0069] An abstract syntax tree is constructed by matching and analyzing lexical token sequences in a preset order using a preset parser.

[0070] Multiple semantic checks and analyses, as well as domain primitive expansion operations, are performed on the abstract syntax tree to generate an expanded syntax tree. The semantic checks and analyses include symbol resolution, type checking, and domain constraint checking.

[0071] Simulation models of power systems can be written using a pre-configured domain-specific language. The source files corresponding to the generated simulation models are called DSL simulation source files. DSL simulation source files record the node and branch structure of the power network, defining the voltage levels of each node and the types and parameters of components connected to each branch. Furthermore, component parameters are configured using parametric templates provided by the domain-specific language; configuration only requires determining the component type and specific parameter values, thus completing component modeling. For custom components not included in the standard component library, their electrical characteristics can be described using mathematical equations. The control logic section of the DSL simulation source file is defined using signal flow description syntax, allowing specification of measurement signal acquisition, control algorithm operation, and control signal output locations; while the simulation conditions section defines simulation time parameters, fault time series, and output observation variables, etc.

[0072] The preset lexical analyzer can scan the text of the DSL simulation source file character by character according to the DSL lexical rules, extracting different types of lexical units such as keyword tags, identifier tags, numerical constant tags, algorithm tags, and delimiter tags, forming an ordered sequence of lexical tags. At the same time, it can also filter out comment text and whitespace characters, and perform preliminary sorting and optimization of the lexical tag sequence.

[0073] The pre-defined parser can perform matching analysis on the optimized lexical tag sequence according to the DSL grammar rules in a pre-defined order, including top-down and bottom-up; gradually forming an abstract syntax tree. The internal nodes of the abstract syntax tree represent the production rules of the grammar rules, and the leaf nodes represent lexical tags; moreover, the parsing process will also record detected grammar errors and trigger reports to prompt the user.

[0074] Semantic analysis involves traversing the generated abstract syntax tree (DSL) to perform multiple semantic checks, followed by domain primitive expansion. Semantic checks include, but are not limited to, symbol resolution, type checking, and domain constraint checking. Symbol resolution establishes global and local symbol tables, associating each identifier's reference with its definition location, ensuring all referenced components, signal kernel parameters, and other parameters are correctly defined, and establishing a complete symbol table. Type checking verifies the compatibility of operand types in various operational expressions, ensuring consistency of physical dimensions, such as ensuring that voltage and current signals are not directly added without physical meaning. Domain constraint checking verifies the connectivity of the power network topology, checks the physical rationality of electrical parameters, and confirms signal matching relationships in control loops, such as checking for dangling nodes and whether circuits have reference ground nodes. After semantic checks are completed, domain primitive expansion can be performed; essentially, this replaces the high-level component models used in the DSL with their corresponding mathematical calculation expressions; for example, expanding the synchronous generator model into a discretized form of the Park equation, expanding the transmission line model into the equivalent circuit equations of the Bergeron model, and expanding the controller model into a numerical calculation expression in the form of difference equations. The expanded abstract syntax tree no longer contains domain-specific high-level primitives; all modeling content has been transformed into standard mathematical expressions, and it can be called an expanded syntax tree.

[0075] Specifically, the core syntax keywords of DSL are divided into four categories: component type keywords, control logic keywords, simulation control keywords, and data type keywords. Domain primitive expansion employs a recursive expansion strategy based on template matching. First, it traverses all instantiated nodes of the abstract syntax tree, retrieving matching template entries from the built-in model template library based on the component type keyword. If no template is found, it checks if the component is user-defined and switches to the direct equation parsing path. Then, it replaces the formal parameters of the template's parameterized mathematical equations with user-specified actual parameter values, generating an instantiated equation set. Next, it selects the appropriate discretization method based on the simulation type; for example, electromagnetic transient simulation uses the trapezoidal integral method to convert differential equations into difference equations, while electromechanical transient simulation uses the implicit Euler method for discretization. Subsequently, it assembles the discretized equations of each component into a global node equation Y·V=I according to the network topology, where Y is the node admittance matrix, V is the node voltage vector, and I is the injected current vector. Finally, for user-defined components, it parses the user-written equation set and expands it according to the same discretization rules, mapping the port variables of the user-defined equations to the corresponding positions in the global node equations.

[0076] Step 102: Generate an intermediate representation that expands from the high level to the low level within the compiler based on the expanded syntax tree.

[0077] It's important to note that this process involves converting the expanded syntax tree obtained through semantic analysis into a unified internal representation format for the compiler, namely, an intermediate representation. The conversion follows a layered strategy: first, a high-level intermediate representation is generated, where nodes correspond to subsystems or functional calculation modules of the power system, and edges between nodes represent data exchange relationships between subsystems, preserving higher-level domain semantic information. Then, the high-level intermediate representation is progressively downgraded, decomposing domain-level operations into standard mathematical calculation operations to generate a low-level intermediate representation. In other words, the mathematical operations within each calculation block are decomposed into a sequence of basic operations to obtain the low-level intermediate representation. Nodes in the low-level intermediate representation correspond to basic computational operations such as matrix operations, vector operations, and scalar operations, while edges represent data flow relationships between operations. Furthermore, the low-level intermediate representation uses a static single-assignment format, with each instruction containing the operation type, operand references, and result identifier.

[0078] In other words, the intermediate representation is designed using a static single-assignment method, where each variable is assigned a value only once, facilitating subsequent analysis and optimization. The intermediate representation also includes metadata annotation information, such as the estimated computational load of the operation, the data scale involved in the operation, and the data access pattern. This metadata provides important references for subsequent mapping and scheduling decisions. Furthermore, the intermediate representation includes high-level intermediate representation and low-level intermediate representation.

[0079] It should be noted that in this embodiment, for state variables that are repeatedly updated at each time step in the simulation time-stepping loop, the compiler inserts a φ(phi) function instruction at the entry basic block of the loop body for each such variable. The semantic definition of the φ(phi) function is: select different versions of the variable based on the source of the control flow; if the control flow comes from outside the loop, the initial value version is selected; if the control flow comes from the end of the loop body, the updated value version at the end of the previous iteration is selected. Taking the inductor current i... L Taking iterative updates in a loop as an example, its SSA form is: Instruction i is generated at the loop entry point. L_k =φ(i L_init i L_prev_updated ), where i L_init This is the initial value of the inductor current at the start of the simulation, determined by the initial conditions set by the user in the DSL model or the initial operating point obtained through steady-state calculations. L_prev_updated This is the latest value of the inductor current after being updated by the difference equation at the end of the previous time step iteration, i.e., the update result generated by the assignment instruction at the end of the loop body. All calculation instructions within the loop body that reference this variable use i. L_k This unique version generates an updated version i at the end of the loop body using a new assignment instruction. L_k_updated =f(i L_kThe updated version serves as the input choice for the φ(phi) function in the next iteration. Through this mechanism, each variable name appears only once in the entire intermediate representation, strictly satisfying the static single assignment formal constraint, while fully preserving the computational semantics of iteratively updating state variables in the time-stepping loop. In the subsequent computation graph analysis phase, the compiler automatically extracts the loop-carried dependencies by identifying the φ(phi) function nodes, marking the back edges of the φ(phi) function as boundary data flows across time steps, thus seamlessly integrating with the aforementioned single-step directed acyclic computation graph construction strategy.

[0080] Step 103: Perform simulation calculation relationship analysis based on the intermediate representation, and construct a simulation calculation graph, which includes dependency annotations and parallelism.

[0081] This embodiment analyzes the computational relationships in the simulation process based on the intermediate representation, and constructs a simulation computation graph accordingly. The compiler can automatically extract the data dependencies between various computational tasks in the intermediate representation, identify groups of computational tasks that can be executed in parallel, evaluate the computational complexity and data communication requirements of each computational task, and form a computation graph with dependency annotations and parallelism information. Based on the simulation computation graph, the terminal optimizer can also perform a series of hardware-independent general optimization changes, such as computational redundancy elimination, common subexpression merging, and loop optimization, to improve the execution efficiency of the simulation computation graph.

[0082] Further, step 103 includes:

[0083] Traverse the lower-level intermediate representations in the intermediate representations and establish data dependency edges based on instruction operation reference relationships to generate a dependency graph;

[0084] Perform simulation time cycle analysis on the dependency graph, and determine the maximum number of tasks to be executed in parallel, computational intensity, composite dependencies, parallelism, critical path and data transfer volume, and generate an annotated simulation computation graph.

[0085] This embodiment, based on intermediate representations, constructs a simulation computation graph by utilizing low-level intermediate representations as input to generate a global computation dependency graph. This process includes: data dependency analysis, identifying which computational operations' outputs are inputs to other operations and establishing data dependency edges; control dependency analysis, identifying control dependencies introduced by conditional branches and loop structures; parallelism identification, finding the set of computational operations that can be executed simultaneously based on dependency analysis and determining the maximum available parallelism of the computation graph; critical path analysis, calculating the longest dependency path from input to output and determining the theoretical minimum execution time lower bound; and computational load assessment, labeling each node with the estimated number of arithmetic operations and memory accesses.

[0086] The simulation computation graph is used in subsequent operations in the form of an labeled computation graph. Each node in the computation graph is accompanied by a computational quantity metric, an optional hardware type label, and data locality information, while each edge is accompanied by data transmission quantity and transmission direction information.

[0087] During the construction of the simulation calculation graph, all instructions in the lower-level intermediate representations are traversed. Data dependency edges are established by analyzing the operation reference relationships of sub-parts. If instruction B uses the calculation result of instruction A, a data dependency edge is established from node A to node B in the calculation graph, thus generating the dependency graph.

[0088] Then, simulation time step loop analysis is performed, which analyzes the data dependencies across steps and identifies the dependencies carried by the loop. Based on the dependency graph, parallelism analysis can also be performed, which finds all instruction sets without mutual dependencies and determines the maximum number of tasks that can be executed in parallel at the same time in each time step. At the same time, critical path analysis can also be performed to find the longest dependency link from the start to the end of the simulation step. The length of this path determines the shortest theoretical execution time of a single simulation step.

[0089] Based on the above, various information such as the maximum number of tasks executed in parallel, computational intensity, complex dependencies, parallelism, critical path, and data transfer volume can be analyzed from the dependency graph. Therefore, computational intensity information can be labeled for each computing node, and data transfer information can be labeled for each dependency edge to generate an annotated simulation computation graph. For the process of constructing the intermediate representation and generating the simulation computation graph in this embodiment, please refer to [link to relevant documentation]. Figure 3 .

[0090] Step 104: Based on heterogeneous hardware platform information, the simulation task is mapped to the target heterogeneous platform by means of task scheduling decision according to the simulation calculation graph and intermediate representation, triggering the code generator and the hardware to be optimized to automatically compile the heterogeneous hardware mapping and generate heterogeneous executable code.

[0091] It should be noted that heterogeneous hardware platform information can be obtained directly from the target hardware platform or automatically detected by the runtime detector. Heterogeneous hardware platform information includes, but is not limited to, the type, quantity, peak computing power, and supported operation types of each processing unit, and may also include memory-related information. Therefore, any information required by the mapping compilation process can be obtained in advance to generate a convenient heterogeneous hardware platform information format. This is just an example and is not a limitation.

[0092] The simulation computation graph can be used for task partitioning, task allocation, and scheduling execution during task scheduling, while the intermediate representation can trigger hardware-specific optimization of the target heterogeneous platform during the process of mapping simulation tasks to heterogeneous hardware, and generate execution code based on the specialized code generator.

[0093] Specifically, based on heterogeneous hardware platform information, the intermediate representation of computing tasks can be mapped to the target heterogeneous platform. The backend includes specialized code generators for different hardware types, generating corresponding executable code or hardware descriptions for processor architectures such as CPU, GPU, FPGA, and ASIC. During the backend code generation process, the compiler performs hardware-related optimizations based on the architectural characteristics of the target hardware, including task-to-processing unit mapping, memory-level data layout optimization, and communication scheduling optimization, ensuring that the execution performance of the generated code on the target platform is close to that of manual optimization.

[0094] This embodiment completely decouples the simulation model from the computing hardware through an intermediate representation. The intermediate representation retains the complete semantic information of the simulation model and is independent of any specific hardware architecture. It is the key bridge connecting the front-end DSL and the back-end hardware. The same DSL model description generates a unified intermediate representation after being processed by the front end. This intermediate representation can be processed by different back-end code generators, thereby automatically adapting to any target platform, from a single CPU in a laptop to a large-scale heterogeneous hardware in a supercomputing cluster.

[0095] The simulation compiler in this embodiment follows the same layered architecture concept as a general-purpose compiler, but its implementation at each operational stage is deeply customized for the power system simulation domain. For example, the front-end DSL provides native modeling primitives for the power system domain; the mid-end computational graph analysis is specifically optimized for the computational characteristics of power system simulation, such as matrix operation decomposition in electromagnetic transient calculations and long-time step optimization in electromechanical transient calculations; and the back-end code generator is specially designed to handle the timing constraints and deterministic requirements of real-time simulation. This domain-specific layered compilation architecture gives the solution in this embodiment both the flexibility and scalability of a general-purpose compiler and the ability to generate high-quality executable code for the specific needs of the power system simulation domain.

[0096] Furthermore, the compiler in this embodiment can also provide a hardware capability description interface, allowing for a structured description of the target hardware's computing resources, storage hierarchy, interconnect topology, and communication bandwidth, among other characteristics. When performing hardware mapping, the compiler backend can comprehensively consider the task characteristics of the simulation computation graph and the capability characteristics of the target hardware, using an automatic mapping strategy to find the optimal allocation scheme between computing tasks and hardware resources, thereby achieving efficient utilization of heterogeneous hardware resources.

[0097] Further, step 104 includes:

[0098] Obtain information about the target hardware platform to obtain heterogeneous hardware platform information, which includes available hardware processing unit information, memory information, associated topology information, and communication parameters.

[0099] Based on the simulation calculation diagram and heterogeneous hardware platform information, a task scheduling decision analysis is performed to determine the task scheduling scheme;

[0100] Based on the task scheduling scheme, the simulation task is mapped to the target heterogeneous platform for compilation according to the intermediate representation, and a hardware instruction sequence is generated.

[0101] Based on the code generator and the hardware to be optimized, hardware-specific optimization is performed according to the hardware instruction sequence to generate cross-hardware communication configuration and heterogeneous execution code.

[0102] Integrate cross-hardware communication configuration, heterogeneous execution code, and startup synchronization control code to generate a heterogeneous execution code package.

[0103] It should be noted that the mapping compilation in this embodiment involves a joint analysis of the simulation computation graph and heterogeneous hardware platform information. From the heterogeneous hardware platform information, the available processing unit information, memory information, associated topology information, and communication parameters of the hardware platform can be determined. Specifically, processing unit information includes type, quantity, peak computing power, and supported operation types; memory information includes storage hierarchy, capacity at each level, and bandwidth; associated topology information refers to the interconnection topology between processing units; and communication parameters refer to communication latency parameters. For multi-node cluster environments, the topology and bandwidth information of the network between nodes will also be included. The heterogeneous hardware platform information is also known as hardware description information, which is provided to the mapping scheduling task in structured data form as hardware constraint input for mapping decisions.

[0104] The task scheduling decision phase requires three operations: task partitioning, task allocation, and execution scheduling. The task partitioning phase aggregates computing nodes into several task groups based on the structure and data flow of the simulation graph, maximizing data exchange between nodes within a group while minimizing data exchange between groups. The task allocation phase selects the most suitable processing unit type for each task group based on its computational characteristics: computationally intensive and regular matrix operation task groups are preferentially allocated to GPU-based processing units; control computation task groups with strict timing deterministic requirements are preferentially allocated to FPGA-based processing units; and logically complex but computationally moderate serial task groups are allocated to CPU-based processing units. The allocation process simultaneously considers load balancing and minimizing communication overhead across processing units. The execution scheduling phase determines the execution order of task groups on each processing unit, arranges overlapping execution of computation and communication operations while satisfying data dependency constraints, and inserts synchronization primitives at nodes requiring synchronization. After completing these three operations, a task scheduling scheme is generated for subsequent mapping and compilation.

[0105] Task partitioning is implemented based on a multi-level graph partitioning algorithm. The specific process is as follows: Multi-level coarsening is performed on the labeled computation graph. In each level of coarsening, a heavy-edge matching algorithm is used. That is, for all unmatched nodes in the computation graph, nodes connected by the edge with the largest weight are merged into a super node, ordered from largest to smallest by the weight of the connecting edge / data transfer volume. The computational cost of the super node is the sum of the computational costs of the two nodes before merging, and the edge weights between super nodes are the sum of the original edge weights. This process is repeated until the number of nodes in the coarsened graph is reduced to c times the target number of partitions k, where c is the coarsening coefficient, with a default value of 20. Then, a greedy binary recursive partitioning strategy is used on the coarsened graph, with the goal of minimizing the total weight of cross-partition edge cutting, EdgeCut = Σw(e), where w(e) is the data transfer volume of edge e, and the computational cost W of each partition is constrained. p Satisfying the equilibrium condition | W p -W_avg|≤ε·W_avg, where ε is the imbalance tolerance (default value is 0.1), and W_avg is the average computational cost of each partition. The coarsened graph is recursively bisected until k partitions are obtained. Finally, local optimization is performed through progressive refinement and KL (Kernighan-Lin) boundary node swaps. In each refinement level, the swaps of partition boundary node pairs are enumerated, and swaps that can reduce edge cutting weights are accepted until no swaps can further reduce edge cutting weights.

[0106] Task allocation is implemented using a greedy allocation mechanism based on matching score. The specific process is as follows: For each task group T i and each candidate processing unit P j Calculate the matching score S(T) i P j )=α·Cmat(T i P j )+β·Bload(P j )+γ·Ccom(T i P j ), where each sub-item is defined as: calculating the feature matching degree Cmat(T) i P j )=cos(F i H j )=(F i ·H j ) / (|F i |·|H j |), F i For task group T i The computational operation type distribution vector is as follows: scalar operation proportion, vector operation proportion, matrix operation proportion, and logic control operation proportion; H j For processing unit P jThe computing power characteristic distribution vector, where each component is the normalized peak throughput of the corresponding operation type; load balancing degree Bload(P) j )=1-L j / L j _max, where L j For processing unit P j The allocated cumulative computational load, L j _max is P j Maximum computational load within a single simulation step time limit; communication overhead Ccom(T) i P j )=-D ij / Dmax, where D ij For task group T i With P already assigned j The total data transfer volume between associated task groups on external processing units is represented by Dmax, which is the global maximum data transfer volume used for normalization. α, β, and γ are weighting coefficients, with default values ​​of α=0.5, β=0.3, and γ=0.2, which users can adjust according to their application scenarios. The allocation process sorts task groups from largest to smallest computational workload and assigns each task group to the processing unit with the highest matching score.

[0107] The mapping and compilation stage involves triggering specialized code generators for corresponding hardware such as CPU, GPU, and FPGA based on the task scheduling scheme and the low-level intermediate representation to perform hardware-specific optimization, generate cross-hardware communication configurations and heterogeneous execution code, and then integrate the code and configuration to generate a complete executable code package.

[0108] Specifically, the corresponding code generator backend needs to be called according to the task scheduling scheme and the intermediate representation of the task groups assigned to different types of processing units. For example, the CPU code generator backend translates the intermediate representation instructions assigned to the CPU task groups into CPU instruction sequences, generates parallel code using a multi-threaded programming model, accelerates numerical calculations using the processor's vectorized instruction set, and optimizes cache-friendly data layout according to the data access mode.

[0109] The GPU code generator backend converts the task groups allocated to the GPU into parallel computing kernel functions, divides thread blocks according to the data parallelism characteristics of the task, makes reasonable use of the GPU's shared memory to reduce global memory access latency, and optimizes the register usage and occupancy of the kernel functions.

[0110] The FPGA code generator backend converts the task groups assigned to the FPGA into hardware description language code, maps the computation tasks into pipelined hardware processing units, utilizes the parallel hardware resources of the FPGA to achieve highly parallel computation, and ensures that the timing of the hardware circuit meets the simulation real-time requirements.

[0111] Each processor translates the intermediate representation according to its respective receiving task group, generating its corresponding hardware instruction sequence. Then, based on the hardware instruction sequence, it triggers the code generator to generate executable code, initiating specialized optimization of the hardware implementation to be optimized, resulting in cross-hardware communication configuration and heterogeneous executable code. The heterogeneous executable code generated by each backend, along with the cross-hardware communication configuration code between processing units and the startup synchronization control code, are packaged together into a complete deployable executable code package, i.e., the heterogeneous executable code package. For the overall task scheduling decision and mapping compilation process of this embodiment, please refer to [link to relevant documentation]. Figure 4 .

[0112] Furthermore, step 104, preceding the following, also includes:

[0113] The simulation computation graph and intermediate representation are subjected to general optimization processes, including reuse of computation results, computation of constant representation values, dead code removal, matrix sparse representation, and matrix equation decomposition.

[0114] It should be noted that general optimization processing refers to hardware-independent optimization transformations of the simulation computation graph and intermediate representation. Specifically, it involves eliminating redundant operations, removing invalid code, and simplifying some expressions to improve computational efficiency while ensuring semantic equivalence. General optimization processing includes, but is not limited to, reusing computation results, calculating constant representations, dead code removal, sparse matrix representation, and matrix equation decomposition. Other operations can also be set as needed; this is only an example and not a limitation.

[0115] General optimizations can include eliminating instances where the same expression is repeatedly computed in multiple places in the computation graph through common subexpressions; replacing duplicate computations with references to the initial computation result, reducing the total computation load (result reuse); determining and computing constant expressions during compile time through constant propagation and folding optimizations, eliminating redundant runtime computations (constant representations); and eliminating or removing dead code, preventing invalid instructions from using the computation result.

[0116] There are also some special optimizations for power system simulation, including: taking advantage of the sparsity of the power network admittance matrix to replace dense matrix operations with sparse matrix operations, which greatly reduces the calculation of invalid zero elements, i.e., matrix sparse representation; and taking advantage of the partitioning characteristics of the network topology to decompose large-scale matrix equations into multiple smaller independent sub-equations, i.e., matrix equation decomposition.

[0117] Taking the sparse representation of the admittance matrix as an example, zero elements in the admittance matrix can be removed and matrix decomposition performed. Zero element removal is implemented based on sparse pattern analysis of symbols during compilation. During the compilation phase, the compiler statically determines the non-zero element position pattern of the node admittance matrix Y based on the power network topology: a matrix element Y(i,j) is non-zero if and only if there is a direct branch connection between node i and node j (either a non-diagonal element or a diagonal element of i=j) equal to the sum of the admittances of all branches connected to that node. Based on this, the compiler generates a compressed sparse row format storage index table, containing a row pointer array, a column index array, and a non-zero value array, storing and calculating only the operations corresponding to the non-zero element positions. For the core matrix-vector multiplication operation Y·V=I, where V represents the node voltage vector, its j-th component Vj... j Representing the voltage value of the j-th node in the power network, the compiler expands it into a sparse accumulation instruction sequence that only targets non-zero elements: for each node i, an accumulation instruction I is generated. i =Σ j ∈N(i)Y(i,j)·V j Where N(i) is the set of neighboring nodes directly connected to node i, including i itself, rather than traversing all n nodes; V j Let V represent the node voltage vector, and its j-th component V j Let represent the voltage value of the j-th node in the power network. This elimination rule reduces the computational complexity of matrix-vector multiplication from O(n²) to O(nnz), where nnz is the total number of non-zero elements, which is approximately 3n to 5n for a typical power network.

[0118] The decomposition of the admittance matrix can be achieved using a sparse LU decomposition method based on network topology. This involves four processes: node reordering, symbolic decomposition, numerical decomposition, and specific solutions for large-scale power networks with distinct partitioning structures. Node reordering involves renumbering the nodes of the power network graph using an approximate minimum degree sorting algorithm. This algorithm selects the node with the smallest degree at each elimination step to minimize the number of fill-in elements during LU decomposition, reducing the total number of non-zero elements in the L and U factors after decomposition. Symbolic decomposition, based on the reordered sparse pattern, pre-determines the positions of all non-zero elements in the L and U factor matrices during compile time using an elimination tree algorithm. This includes the original non-zero positions and fill-in positions, generating a fixed non-zero element index structure and a corresponding decomposition calculation instruction sequence. Numerical decomposition, performed at runtime, calculates the actual values ​​of each non-zero position according to the instruction sequence determined at compile time, completing the LU decomposition. Since the instruction sequence is fixed at compile time, there is no need to dynamically determine the sparse pattern at runtime, resulting in execution efficiency close to dense decomposition. The solution for large-scale power networks employs a block-parallel solution method based on Schur's complement for matrix solving. Specifically, the entire network is divided into several internal sub-regions and boundary node sets. The equations within each sub-region are solved independently and in parallel first, and then the Schur's complement formula S = Y_BB - Y_BI·Y_II is used. - ¹·Y_IB constructs the boundary coupling equation, where Y_BB is the admittance submatrix between boundary nodes, Y_BI and Y_IB are the boundary-interior coupling submatrix, and Y_II is the admittance submatrix of the interior nodes. After solving the boundary equation in a concentrated manner, the boundary-related variables of each subregion are solved back by substituting the solutions.

[0119] Furthermore, step 104 also includes:

[0120] Deploy the code of the heterogeneous execution code package to the target heterogeneous platform for execution verification and obtain the code verification results;

[0121] The execution time and communication latency of each hardware processing unit in the target heterogeneous platform are collected by instrumenting code generated by the compiler.

[0122] The performance of the compiler's mapping and scheduling decisions is verified based on execution time and communication latency.

[0123] It should be noted that deploying the executable code in the heterogeneous executable code package to the target heterogeneous platform involves loading the executable code of each processing unit into the corresponding hardware, configuring the communication channels between processing units, and initializing the simulation runtime environment. The effectiveness of the executable code can be verified based on the running results. If it does not meet the expected requirements, targeted optimization and adjustments can be made, which will not be elaborated here.

[0124] This embodiment can also use the compiler to generate instrumentation code, which is used to collect the actual execution time and communication latency of each hardware processing unit when the platform runs the code for the first time, and then verify whether the compiler's mapping and scheduling decisions have achieved the expected performance goals based on these data.

[0125] For ease of understanding, this application provides an example of a simulation compiler system application, which is used to implement the heterogeneous compilation method for the power system simulation model of this application. Please refer to [link to relevant documentation]. Figure 5 The system includes a DSL parsing module, a semantic analysis module, an intermediate representation construction module, a computation graph analysis module, a general optimization module, a hardware description module, a mapping and scheduling module, and a code generation module. The modules interact with each other through well-defined data interfaces to form a complete compilation and processing pipeline.

[0126] The DSL parsing module receives user-written domain-specific language source code, performs lexical and syntactic analysis, and transforms the textual model description into a structured abstract syntax tree. The DSL parsing module incorporates a built-in syntax rule library for power system simulation, supporting the parsing of modeling primitives such as power network topology descriptions, component parameter definitions, control logic expressions, and simulation condition settings. The lexical analyzer decomposes the DSL source code into a sequence of tokens, and the syntax analyzer organizes these token sequences into an abstract syntax tree structure according to domain syntax rules. When syntax errors exist in the source code, the parsing module can provide clear error location and error type information.

[0127] The semantic analysis module performs semantic-level checks and enhancements on the abstract syntax tree. This module verifies the rationality of the connection relationships of power components in the model, whether the parameter values ​​conform to physical constraints, and whether the input-output relationships of control signals match. It also performs operations such as type inference, symbol resolution, and domain rule checking. The semantic analysis module is also responsible for expanding domain-specific high-level modeling primitives into standardized mathematical computational expressions. The specific definitions of high-level and low-level intermediate representations in terms of partitioning dimensions, data structure formats, and hierarchical transformation rules are as follows:

[0128] In terms of the division dimensions, the high-level middle layer represents the division granularity based on the functional subsystems of the power system. Each node corresponds to a complete power component or control subsystem, such as a generator, a transmission line, or a control loop. The node encapsulates all the mathematical equations and state variables of the component. The low-level middle layer represents the division granularity based on a single mathematical operation instruction. Each node corresponds to a scalar operation, vector operation, or matrix operation.

[0129] In terms of data structure format, the high-level intermediate representation adopts a hierarchical component graph structure. Each component node contains three data fields: a list of port interfaces, a set of internal state variables, and a parameter table. Electrical quantities or control signals are transmitted between component nodes through port connection edges, which are accompanied by data type labels and physical dimension information. The low-level intermediate representation adopts a static single-assignment instruction sequence structure. Each instruction is represented in the form of a quadruple: opcode, source operand 1, source operand 2, and destination virtual register. Data flow edges are established between instructions through virtual register reference relationships. The supported opcodes cover basic operation categories such as scalar arithmetic operations, matrix multiplication, vector inner product, trigonometric functions, comparison jumps, etc.

[0130] Regarding the hierarchical transformation rules, the downgrading from high-level intermediate representation to low-level intermediate representation is performed in the following three steps: First, for each component node, its corresponding model expansion template is called, replacing the formal parameters in the component's parameterized mathematical equations with the actual user parameter values, and selecting the discretization method according to the simulation type. For example, the trapezoidal integral method is used for electromagnetic transient simulation, and the implicit Euler method is used for electromechanical transient simulation, converting the differential equations into a sequence of instructions in the form of difference equations. Second, the port connection relationships between components are converted into explicit data transfer instructions, and the voltage and current coupling relationships of electrical ports are converted into corresponding row and column element assignment instructions for the global node admittance matrix equation. Third, all expanded instruction sequences are globally numbered and statically assigned values, and multiple definitions of the same variable are eliminated by renaming variables, forming a unified low-level intermediate representation instruction flow primitive expansion into a standardized mathematical calculation expression. For example, the transformer model is expanded into the matrix equation representation corresponding to its equivalent circuit.

[0131] The intermediate representation construction module converts the semantically analyzed model information into a unified intermediate representation format used internally by the compiler. The intermediate representation adopts a layered design, comprising a high-level intermediate representation and a low-level intermediate representation. The high-level intermediate representation preserves domain semantic information, describing computational tasks at the granularity of power system components and subsystems; the low-level intermediate representation is closer to the computational operation level, describing the computational process at the granularity of basic mathematical operations and data access. The intermediate representation construction module first converts the semantically analyzed model information into a high-level intermediate representation, and then gradually downgrades it to a low-level intermediate representation during subsequent optimization and code generation processes.

[0132] The computational graph analysis module extracts the computational dependency graph of the simulation model based on the intermediate representation. This module traverses all computational tasks in the intermediate representation, analyzes the data and control dependencies between tasks, and constructs a directed acyclic computation graph. Regarding the transformation method from a time-stepping loop in power system simulation to a directed acyclic computation graph and the rules for handling circular dependencies, the compiler employs a single-step expansion and boundary variable isolation mechanism, specifically as follows: The compiler expands all computational operations within a single time step of the simulation time-stepping loop into a directed acyclic computation graph, while separating cross-time-step dependencies using the boundary variable mechanism. For state variables in the simulation loop, whose values ​​at the current time step t depend on the computation result of the previous time step t-1, the compiler marks these cross-step state variables as boundary input variables, introducing them as source nodes of known inputs in the current step's computation graph, rather than forming circular dependency edges, thus ensuring the acyclic nature of the single-step computation graph. The updated state variable values ​​in the current step's computation graph are marked as boundary output variables, cached at runtime, and used as boundary inputs for the next time step's computation graph. For loop dependencies, where the assignment of a variable within a loop depends on a previous assignment of the same variable in the same iteration, the compiler uses dependency chain analysis to break it down into a strict sequence of instructions and incorporates it into the critical path of the computation graph, ensuring correct execution order. For algebraic rings caused by implicit integration methods, such as when the trapezoidal rule depends on the current step's input, the compiler uses a predict-correct expansion strategy to decompose the algebraic ring into two-stage serial computation: the first stage uses the extrapolated value from the previous step as the prediction input, and the second stage uses the prediction result for corrective iterative computation, thereby eliminating the circular dependencies introduced by the algebraic ring and ensuring that the directed acyclic property of the computation graph is strictly maintained. Based on the computation graph, the module further analyzes the set of tasks that can be executed in parallel, evaluates the critical path length, calculates the computational and data transfer volumes of each task, and labels each task and edge with corresponding metric information, providing a quantitative basis for subsequent mapping and scheduling decisions.

[0133] The general optimization module performs a series of hardware-independent optimization transformations at the intermediate representation level. Key optimization strategies include: computational redundancy elimination (identifying and removing redundantly computed sub-expressions); constant propagation and folding (compiling determinable constant expressions at compile time); loop optimization (expanding and merging simulation time-stepping loops); and sparse matrix optimization (leveraging the sparsity of power network topology to reduce unnecessary zero-element operations). The output of the general optimization module remains in intermediate representation format, but computational efficiency has been significantly improved.

[0134] The hardware description module manages the capability information of the target hardware platform in a structured manner. This module maintains a description file for each supported hardware architecture, including parameters such as the number and computing power of processing units, memory hierarchy and capacity, interconnect topology and communication bandwidth, supported data types, and arithmetic instructions. The hardware description module allows users to define custom descriptions for new hardware platforms, enabling the compiler to adapt to newly introduced hardware types.

[0135] The mapping and scheduling module integrates computation graph analysis results and target hardware description information to automatically make mapping decisions on computational tasks to hardware resources. Based on the computational characteristics, data dependencies, and hardware resource constraints of the tasks, this module determines which processing unit each computational task should execute on, the execution order between tasks, and the communication method, and generates a mapping and scheduling scheme. During the decision-making process, the mapping and scheduling module aims to minimize the total execution time while simultaneously satisfying the timing constraints of real-time simulation.

[0136] The code generation module converts the intermediate representation into executable code for specific hardware based on the mapping scheduling scheme and the characteristics of the target hardware architecture. The code generation module includes multiple hardware-specific code generation backends, supporting CPU instruction code generation, GPU parallel computing kernel function generation, and FPGA hardware description language generation, respectively. Each backend performs hardware-related optimizations during the code generation process; for example, the CPU backend performs vector instruction utilization and cache optimization, the GPU backend performs thread block partitioning and shared memory optimization, and the FPGA backend performs pipeline insertion and resource mapping optimization.

[0137] The heterogeneous compilation method for power system simulation models provided in this application uses a pre-defined domain-specific language to write the simulation model and generates an expanded syntax tree through semantic analysis. This constructs an intermediate representation that expands from high to low levels, achieving complete decoupling between model description and hardware execution. This allows a single model to be adapted to multiple different hardware platforms without requiring complete code rewriting for platform migration. Furthermore, by combining heterogeneous hardware platform information, simulation computation graphs, and intermediate representations, automatic mapping from simulation to hardware can be achieved through task scheduling decisions. This automates the matching of task characteristics with hardware features, improving the utilization rate of heterogeneous hardware resources and overcoming the current problem of narrow hardware compatibility. In addition, by constructing a computation graph containing dependency annotations and parallelism information, the reliance on manual operation is overcome. Task scheduling and optimization can be automated based on the computational relationships in the simulation computation graph, and the parallel potential of the model can be explored, narrowing the performance gap with manual optimization. This method can meet the simulation needs of large-scale complex power grids. Therefore, this application can solve the technical problems of existing technologies where models are tightly coupled with hardware, preventing migration, resulting in narrow hardware compatibility, and lacking automated analysis capabilities, leading to excessive reliance on manual task scheduling and making it difficult to meet the simulation needs of large-scale complex power grids.

[0138] For easier understanding, please refer to Figure 2 This application provides an embodiment of a heterogeneous compilation device for a power system simulation model, comprising:

[0139] The semantic analysis unit 201 is used to write simulation models according to a predefined domain-specific language, and generate an expanded syntax tree by combining semantic analysis. The simulation model describes the topology, component parameters, control strategies and simulation conditions of the power system.

[0140] The construction unit 202 is used to generate intermediate representations that expand from high to low levels within the compiler based on the expanded syntax tree;

[0141] The relation analysis unit 203 is used to perform simulation calculation relation analysis based on the intermediate representation and construct a simulation calculation graph, which includes dependency labeling and parallelism.

[0142] The heterogeneous compilation unit 204 is used to map simulation tasks to the target heterogeneous platform based on heterogeneous hardware platform information, simulation calculation graph and intermediate representation in a task scheduling decision manner, trigger the code generator and the hardware to be optimized to perform heterogeneous hardware automatic mapping compilation, and generate heterogeneous executable code.

[0143] Furthermore, the semantic analysis unit 201 is specifically used for:

[0144] A simulation model of the power system is written in a specific language of the preset domain, and a DSL simulation source file is generated.

[0145] A preset lexical analyzer is used to scan the text of the DSL simulation source file, and the text is filtered to generate a lexical tag sequence;

[0146] An abstract syntax tree is constructed by matching and analyzing lexical token sequences in a preset order using a preset parser.

[0147] Multiple semantic checks and analyses, as well as domain primitive expansion operations, are performed on the abstract syntax tree to generate an expanded syntax tree. The semantic checks and analyses include symbol resolution, type checking, and domain constraint checking.

[0148] Furthermore, relational analysis unit 203 is specifically used for:

[0149] Traverse the lower-level intermediate representations in the intermediate representations and establish data dependency edges based on instruction operation reference relationships to generate a dependency graph;

[0150] Perform simulation time cycle analysis on the dependency graph, and determine the maximum number of tasks to be executed in parallel, computational intensity, composite dependencies, parallelism, critical path and data transfer volume, and generate an annotated simulation computation graph.

[0151] This application also provides a heterogeneous compilation device for power system simulation models, the device including a processor and a memory;

[0152] The memory is used to store program code and transfer the program code to the processor;

[0153] The processor is used to execute the heterogeneous compilation method of the power system simulation model in the above method embodiment according to the instructions in the program code.

[0154] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.

[0155] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0156] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0157] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for executing all or part of the steps of the methods described in the various embodiments of this application through a computer device (which may be a personal computer, server, or network device, etc.). The aforementioned storage medium includes: USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, optical disks, and other media capable of storing program code.

[0158] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.

Claims

1. A heterogeneous compilation method for a power system simulation model, characterized in that, include: The simulation model is written in a specific language of the preset domain, and an expanded syntax tree is generated by combining semantic analysis. The simulation model describes the topology, component parameters, control strategies and simulation conditions of the power system. Based on the expanded syntax tree, an intermediate representation is generated internally by the compiler, expanding from high to low levels; Based on the intermediate representation, a simulation calculation relationship analysis is performed to construct a simulation calculation graph, which includes dependency labeling and parallelism. Based on heterogeneous hardware platform information, the simulation task is mapped to the target heterogeneous platform in a task scheduling decision manner according to the simulation calculation graph and the intermediate representation, triggering the code generator and the hardware to be optimized to automatically compile heterogeneous hardware mapping and generate heterogeneous executable code.

2. The heterogeneous compilation method for power system simulation models according to claim 1, characterized in that, The step of writing a simulation model based on a specific language of a preset domain and generating an expanded syntax tree by combining semantic analysis includes: A simulation model of the power system is written in a specific language of the preset domain, and a DSL simulation source file is generated. The text of the DSL simulation source file is scanned using a preset lexical analyzer, and the text is filtered to generate a lexical tag sequence; An abstract syntax tree is constructed by performing a preset parser to match and analyze the lexical tag sequence in a preset order. Multiple semantic checks and domain primitive expansion operations are performed on the abstract syntax tree to generate an expanded syntax tree. The semantic checks and analyses include symbol resolution, type checking, and domain constraint checking.

3. The heterogeneous compilation method for power system simulation models according to claim 1, characterized in that, The step of performing simulation calculation relationship analysis based on the intermediate representation and constructing a simulation calculation graph includes: Traverse the lower-level intermediate representations in the intermediate representations and establish data dependency edges based on instruction operation reference relationships to generate a dependency graph; The dependency graph is subjected to simulation time cycle analysis, and the maximum number of tasks to be executed in parallel, computational intensity, composite dependencies, parallelism, critical path and data transfer volume are determined, generating an annotated simulation computation graph.

4. The heterogeneous compilation method for power system simulation models according to claim 1, characterized in that, Based on heterogeneous hardware platform information, the simulation task is mapped to the target heterogeneous platform using a task scheduling decision based on the simulation computation graph and the intermediate representation. This triggers the code generator and the hardware to be optimized to perform automatic heterogeneous hardware mapping compilation, generating heterogeneous executable code, including: Obtain information about the target hardware platform to obtain heterogeneous hardware platform information, which includes available hardware processing unit information, memory information, associated topology information, and communication parameters. Based on the simulation calculation diagram and the heterogeneous hardware platform information, a task scheduling decision analysis is performed to determine the task scheduling scheme; Based on the task scheduling scheme, the simulation task is mapped to the target heterogeneous platform for compilation according to the intermediate representation, generating a hardware instruction sequence. Based on the code generator and the hardware to be optimized, hardware-specific optimization is performed according to the hardware instruction sequence to generate cross-hardware communication configuration and heterogeneous execution code. The cross-hardware communication configuration, the heterogeneous execution code, and the startup synchronization control code are integrated to generate a heterogeneous execution code package.

5. The heterogeneous compilation method for power system simulation models according to claim 1, characterized in that, Based on heterogeneous hardware platform information, the simulation task is mapped to the target heterogeneous platform using task scheduling decisions according to the simulation computation graph and the intermediate representation. This triggers the code generator and the hardware to be optimized to perform automatic heterogeneous hardware mapping compilation, generating heterogeneous executable code. Prior to this, the process also includes: The simulation computation graph and the intermediate representation are subjected to general optimization processing, which includes reuse of computation results, computation of constant representation values, dead code removal, matrix sparse representation, and matrix equation decomposition.

6. The heterogeneous compilation method for power system simulation models according to claim 1, characterized in that, The process of mapping simulation tasks to target heterogeneous platforms based on heterogeneous hardware platform information, according to the simulation computation graph and the intermediate representation, and triggering the code generator and the hardware to be optimized to perform automatic heterogeneous hardware mapping compilation to generate heterogeneous executable code, further includes: The code of the heterogeneous execution code package is deployed to the target heterogeneous platform for execution verification, and the code verification results are obtained. The execution time and communication latency of each hardware processing unit in the target heterogeneous platform are collected by instrumenting code generated by the compiler. The performance of the compiler's mapping and scheduling decisions is verified based on the execution time and the communication delay.

7. A heterogeneous compilation device for power system simulation models, characterized in that, include: The semantic analysis unit is used to write simulation models according to a specific language of a preset domain, and generate an expanded syntax tree by combining semantic analysis. The simulation model describes the topology, component parameters, control strategies and simulation conditions of the power system. The building unit is used to generate an intermediate representation that expands from the high level to the low level within the compiler based on the expanded syntax tree. A relational analysis unit is used to perform simulation computation relational analysis based on the intermediate representation and construct a simulation computation graph, which includes dependency labeling and parallelism. The heterogeneous compilation unit is used to map simulation tasks to the target heterogeneous platform based on heterogeneous hardware platform information, according to the simulation calculation graph and the intermediate representation, in a task scheduling decision manner, triggering the code generator and the hardware to be optimized to perform automatic heterogeneous hardware mapping compilation, and generating heterogeneous executable code.

8. The heterogeneous compilation device for power system simulation models according to claim 7, characterized in that, The semantic analysis unit is specifically used for: A simulation model of the power system is written in a specific language of the preset domain, and a DSL simulation source file is generated. The text of the DSL simulation source file is scanned using a preset lexical analyzer, and the text is filtered to generate a lexical tag sequence; An abstract syntax tree is constructed by performing a preset parser to match and analyze the lexical tag sequence in a preset order. Multiple semantic checks and domain primitive expansion operations are performed on the abstract syntax tree to generate an expanded syntax tree. The semantic checks and analyses include symbol resolution, type checking, and domain constraint checking.

9. The heterogeneous compilation device for power system simulation models according to claim 7, characterized in that, The relation analysis unit is specifically used for: Traverse the lower-level intermediate representations in the intermediate representations and establish data dependency edges based on instruction operation reference relationships to generate a dependency graph; The dependency graph is subjected to simulation time cycle analysis, and the maximum number of tasks to be executed in parallel, computational intensity, composite dependencies, parallelism, critical path and data transfer volume are determined, generating an annotated simulation computation graph.

10. A heterogeneous compilation device for power system simulation models, characterized in that, The device includes a processor and a memory; The memory is used to store program code and transmit the program code to the processor; The processor is used to execute the heterogeneous compilation method of the power system simulation model according to any one of claims 1-6 according to the instructions in the program code.