A pipeline simulation method and device based on GEM5 and electronic equipment

By calling the processing functions of pipeline nodes and the simulation cycle advancement function on the GEM5 platform, the problem of low pipeline simulation efficiency is solved, and more efficient pipeline simulation is achieved.

CN122113772APending Publication Date: 2026-05-29HYGON INFORMATION TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HYGON INFORMATION TECH CO LTD
Filing Date
2026-01-21
Publication Date
2026-05-29

Smart Images

  • Figure CN122113772A_ABST
    Figure CN122113772A_ABST
Patent Text Reader

Abstract

Embodiments of the present application disclose a GEM5-based pipeline simulation method and device and electronic equipment, and relate to the technical field of integrated circuit simulation, and are invented to improve the pipeline simulation efficiency. The method comprises the following steps: calling a first processing function; determining, according to the serial number of a first node in a pipeline and a reference pointer of a current simulation period, a target array item corresponding to the first node and the current simulation period in a pipeline array; the first processing function performs corresponding operations according to an instruction context in the target array item, obtains an operation result corresponding to the first processing function, modifies the instruction context of the target array item according to the operation result, and obtains a new instruction context; calling a simulation period advancing function to make the reference pointer decrease by 1 to obtain a next simulation period reference pointer, and make the target array item correspond to a second processing function based on the next simulation period reference pointer; and calling the second processing function. The present application is suitable for simulating a pipeline.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of integrated circuit simulation technology, and in particular to a pipeline simulation method, apparatus, electronic device and readable storage medium based on GEM5. Background Technology

[0002] Pipelining in hardware circuits is a method that divides the execution process of a transaction request into multiple non-overlapping stages, each with its own specific task and hardware implementation, allowing these stages to execute concurrently to improve overall execution efficiency. To implement pipelining, pipelining registers are introduced to store the intermediate results of each stage. These registers transfer data between stages under the control of a clock signal. The operations of each stage occur within different clock cycles, enabling different transaction requests to be executed simultaneously in different stages, thereby improving the overall transaction request execution efficiency.

[0003] When using event-driven computer system simulators such as the GEM5 simulation platform (GEM5 is a merger of GEMS and M5; GEMS is the simulation framework from Wisconsin, and M5 is the simulation framework from Michigan; 5 represents the version number of the merged framework) to model pipelines, all programs are executed serially. If the pipeline is modeled according to the Register Transfer Level (RTL) design approach, each simulation cycle requires updating the pipeline registers in each node sequentially, i.e., an assignment operation is needed for each node in the pipeline. If the pipeline has a lot of node information or a long pipeline, such assignment operations are quite time-consuming, resulting in low simulation efficiency. Summary of the Invention

[0004] In view of this, embodiments of this application provide a pipeline simulation method, apparatus, electronic device, and readable storage medium based on GEM5, which facilitates the improvement of pipeline simulation efficiency.

[0005] In a first aspect, embodiments of this application provide a pipeline simulation method based on GEM5, comprising: calling a first processing function; wherein the first processing function is a processing function corresponding to a first node of the pipeline, and the first node is any node of the pipeline except the last stage node; determining a target array item corresponding to the first node in a preset pipeline array based on the stage number of the first node in the pipeline and the reference pointer of the current simulation cycle; wherein each array item of the pipeline array includes an instruction context; the instruction context is used to record information of the nodes of the pipeline related to its own array item; the first processing function determines the target array item based on the target array item. The instruction context is used to perform corresponding operations to obtain the operation result corresponding to the first processing function, and the instruction context of the target array item is modified according to the operation result to obtain a new instruction context; the simulation cycle advancement function is called to decrement the reference pointer by 1 to obtain the reference pointer of the next simulation cycle, and the target array item is made to correspond to the second processing function based on the reference pointer of the next simulation cycle; wherein, the second processing function is the processing function corresponding to the second node of the pipeline; the second node is adjacent to the first node on the pipeline and is located downstream of the first node; the second processing function is called to perform corresponding operations according to the new instruction context in the target array item.

[0006] According to a specific implementation of this application, the step of determining the target array item corresponding to the first node in the current simulation cycle in a preset pipeline array based on the stage number of the first node in the pipeline and the reference pointer of the current simulation cycle includes: determining a target index number based on the stage number of the first node in the pipeline, the reference pointer of the current simulation cycle, and a preset correspondence; and determining the target array item corresponding to the first node in the current simulation cycle in the preset pipeline array based on the target index number.

[0007] According to a specific implementation of an embodiment of this application, determining the target array item corresponding to the first node in the preset pipeline array based on the target index number includes: calling a retrieval function so that the retrieval function retrieves the target array item corresponding to the first node in the preset pipeline array based on the target index number.

[0008] According to a specific implementation of an embodiment of this application, each array item in the pipeline array further includes a status identifier; the first processing function performs corresponding operations based on the instruction context in the target array item, including: determining whether the status identifier in the target array item is a valid identifier; if it is a valid identifier, the first processing function performs corresponding operations based on the instruction context in the target array item.

[0009] According to a specific implementation of an embodiment of this application, after calling the simulation cycle advancement function and before calling the second processing function, the method further includes: determining whether the status identifier in the array item pointed to by the next simulation cycle reference pointer is a valid identifier; if so, setting the status identifier in the array item pointed to by the next simulation cycle reference pointer to an invalid identifier.

[0010] According to a specific implementation of this application, after the first processing function performs the corresponding operation according to the instruction context in the target array item, and before calling the simulation cycle advancement function, the method further includes: calling a third processing function in reverse order of the node numbers of the pipeline; the third processing function is the processing function corresponding to the node in the pipeline that is adjacent to the first node and upstream of the first node.

[0011] According to a specific implementation of this application, the third processing function is the processing function corresponding to the starting node of the pipeline; after calling the third processing function in reverse order of the node numbers of the pipeline and before calling the simulation cycle advancement function, the method further includes: querying the status identifier of each array item in the pipeline array; and determining whether to execute the step of calling the simulation cycle advancement function based on the status identifier of each array item.

[0012] According to a specific implementation of an embodiment of this application, before calling the first processing function, the method further includes: instantiating a preset pipeline template according to the number of pipeline stages and the type of the pipeline instruction context to obtain the pipeline array.

[0013] Secondly, embodiments of this application provide a pipeline simulation device based on GEM5, comprising: a first calling module, configured to call a first processing function; wherein the first processing function is a processing function corresponding to a first node of the pipeline, and the first node is any node of the pipeline except the last stage node; a first determining module, configured to determine a target array item corresponding to the first node in a preset pipeline array based on the stage number of the first node in the pipeline and the reference pointer of the current simulation cycle; wherein each array item of the pipeline array includes an instruction context; the instruction context is used to record information of the nodes of the pipeline related to its own array item; and a modification module, configured to modify the first processing function according to the target... The instruction context in the array item performs the corresponding operation to obtain the operation result corresponding to the first processing function, and modifies the instruction context of the target array item according to the operation result to obtain a new instruction context; the second calling module is used to call the simulation cycle advancement function to decrement the reference pointer by 1 to obtain the reference pointer of the next simulation cycle, and make the target array item correspond to the second processing function based on the reference pointer of the next simulation cycle; wherein, the second processing function is the processing function corresponding to the second node of the pipeline; the second node is adjacent to the first node on the pipeline and is located downstream of the first node; the third calling module is used to call the second processing function to make the second processing function perform the corresponding operation according to the new instruction context in the target array item.

[0014] According to a specific implementation of an embodiment of this application, the first determining module includes: a first determining submodule, configured to determine a target index number based on the stage in the pipeline where the first node is located, the reference pointer of the current simulation cycle, and a preset correspondence; and a second determining submodule, configured to determine the target array item corresponding to the first node in the current simulation cycle in a preset pipeline array based on the target index number.

[0015] According to a specific implementation of an embodiment of this application, the second determining submodule is specifically used to: call an acquisition function so that the acquisition function obtains the target array item corresponding to the first node in the current simulation cycle from a preset pipeline array based on the target index number.

[0016] According to a specific implementation of an embodiment of this application, each array item in the pipeline array further includes a status identifier; the modification module is specifically used to: determine whether the status identifier in the target array item is a valid identifier; if it is a valid identifier, the first processing function performs a corresponding operation according to the instruction context in the target array item.

[0017] According to a specific implementation of an embodiment of this application, the device further includes: a judgment module, configured to determine whether the status identifier in the array item pointed to by the next simulation cycle reference pointer is a valid identifier after the second calling module calls the simulation cycle advancement function and before the third calling module calls the second processing function; and a setting module, configured to set the status identifier in the array item pointed to by the next simulation cycle reference pointer to an invalid identifier if the status identifier is valid.

[0018] According to a specific implementation of an embodiment of this application, the device further includes: a fourth calling module, used to call a third processing function in reverse order of the node numbers of the pipeline after the modification module performs the corresponding operation according to the instruction context in the target array item through the first processing function and before the second calling module calls the simulation cycle advancement function; the third processing function is the processing function corresponding to the node in the pipeline that is adjacent to the first node and is upstream of the first node.

[0019] According to a specific implementation of this application, the third processing function is the processing function corresponding to the starting node of the pipeline; the device further includes: a query module, used to query the status identifier of each array item in the pipeline array after the fourth calling module calls the third processing function in reverse order of the node numbers of the pipeline and before the second calling module calls the simulation cycle advancement function; and a second determining module, used to determine whether to execute the step of calling the simulation cycle advancement function based on the status identifier of each array item.

[0020] According to a specific implementation of an embodiment of this application, the apparatus further includes: an instantiation module, used to instantiate a preset pipeline template according to the number of pipeline stages and the type of the pipeline instruction context before the first calling module calls the first processing function, so as to obtain the pipeline array.

[0021] Thirdly, embodiments of this application provide an electronic device, the electronic device comprising: a processor and a memory, wherein the memory is used to store executable program code; the processor runs a program corresponding to the executable program code by reading the executable program code stored in the memory, for executing the pipeline simulation method based on GEM5 described in any of the foregoing embodiments.

[0022] Fourthly, embodiments of this application provide a computer-readable storage medium storing one or more programs, which can be executed by one or more processors to implement the pipeline simulation method based on GEM5 as described in any of the foregoing implementations.

[0023] This embodiment of the pipeline simulation method, apparatus, electronic device, and readable storage medium based on GEM5 calls the first processing function corresponding to the first node of the pipeline. Based on the stage number of the first node in the pipeline and the reference pointer of the current simulation cycle, it determines the target array item corresponding to the first node in the current simulation cycle from a preset pipeline array. The first processing function performs corresponding operations according to the instruction context in the target array item, obtains the operation result corresponding to the first processing function, and modifies the instruction context of the target array item according to the operation result, thereby obtaining a new instruction context. Then, it calls the simulation cycle advancement function to decrement the reference pointer by 1, obtaining the reference pointer for the next simulation cycle, and based on the reference pointer of the next simulation cycle, it... The target array item corresponds to the second processing function. Finally, the second processing function is called so that it performs the corresponding operation according to the new instruction context in the target array item. The second processing function is the processing function corresponding to the second node of the pipeline. The second node is adjacent to the first node in the pipeline and is downstream of the first node. In this way, by calling the simulation cycle advance function to advance the simulation to the next simulation cycle and decrementing the base pointer by 1, the processing functions of the two adjacent nodes in the pipeline can be respectively matched with the target array items and perform the corresponding operations. In this process, it is not necessary to update the pipeline registers in each node sequentially, saving pipeline simulation time and improving pipeline simulation efficiency. Attached Figure Description

[0024] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0025] Figure 1 A flowchart illustrating a pipeline simulation method based on GEM5 provided in an embodiment of this application; Figure 2 A schematic diagram illustrating the correspondence between array items of a pipeline array and pipeline nodes through a base index, provided in a specific embodiment of this application; Figure 3 A schematic diagram of the structure of a pipeline simulation device based on GEM5 provided in an embodiment of this application; Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0026] The embodiments of this application will now be described in detail with reference to the accompanying drawings. It should be understood that the described embodiments are merely some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.

[0027] To enable those skilled in the art to better understand the technical concept, implementation scheme and beneficial effects of the embodiments of this application, detailed descriptions are provided below through specific embodiments.

[0028] Figure 1 A flowchart illustrating a pipeline simulation method based on GEM5 provided in an embodiment of this application is shown below. Figure 1 As shown, this embodiment presents a pipeline simulation method based on GEM5.

[0029] GEM5 is an event-driven computer system simulator. GEM5 is widely used in computer architecture research, processor design, memory design, and operating systems. All programs running on GEM5 are executed serially.

[0030] The pipeline simulation method based on GEM5 in this embodiment may include: S101, Call the first processing function.

[0031] The first processing function is the processing function corresponding to the first node of the pipeline.

[0032] The first node is any node in the pipeline except for the last stage node. The processing functions of a node can perform the specific functions of the pipeline node.

[0033] Taking a five-stage pipeline as an example, the functions of each node, starting from the start node, sequentially complete instruction fetch, decode, execute, memory access, and write-back. The first processing function can be one of the corresponding processing functions from instruction fetch, decode, execute, and memory access.

[0034] S102. Based on the stage number of the first node in the pipeline and the reference pointer of the current simulation cycle, determine the target array item corresponding to the first node in the preset pipeline array for the current simulation cycle.

[0035] The reference pointer is used to point the starting node of the pipeline to an array item in the pipeline array.

[0036] The reference pointer can be represented by head. The reference pointer is the index number of the array item in the pipeline array that the pipeline starts at.

[0037] The total number of array items in the pipeline array pipeStages is equal to the number of nodes in the pipeline. For example, if the number of nodes in the pipeline is q (i.e., q-stage pipeline), then the number of array items in the pipeline array is also q, where q is an integer greater than or equal to 1.

[0038] Each array item in the pipeline array includes an instruction context, which is used to record information about the nodes of the pipeline associated with the array item to which it belongs.

[0039] The instruction context can include multiple fields. These fields contain all the information the pipeline needs to transmit.

[0040] The type of instruction context is the data type used to pass information between pipeline nodes. Different types of instruction contexts have different structures. The fields included in different types of instruction contexts may be different or the same.

[0041] The initial value of the instruction context can be a default value or empty. As the pipeline's processing functions run, the default value can be modified or updated based on the results, or a specific value can be added to an empty position.

[0042] S103. The first processing function performs the corresponding operation according to the instruction context in the target array item, obtains the operation result corresponding to the first processing function, and modifies the instruction context of the target array item according to the operation result to obtain a new instruction context.

[0043] The instruction context in the target array item includes the information required by the first processing function.

[0044] The instruction context includes fields corresponding to the operation result of the first processing function. After obtaining the operation result, these fields can be modified to obtain a new instruction context.

[0045] In this embodiment, the instruction context for modifying the target array item based on the operation result can be either replacing the original initial value with the operation result or adding a specific value to the field.

[0046] S104. Call the simulation cycle advancement function to decrement the reference pointer by 1, obtain the reference pointer for the next simulation cycle, and make the target array items correspond to the second processing function based on the reference pointer for the next simulation cycle.

[0047] See Figure 2The simulation cycle advancement function can be implemented using the `advance` method, which is called when the simulation cycle needs to be advanced by one cycle. This method requires updating the reference pointer. Specifically, the reference pointer `head` is decremented by 1 each time the simulation cycle advances, i.e., `head(1) = (head(0) + n-1)%n` for the next simulation cycle. In other words, `head` cycles backward in the pipeline node array (`pipeStages`) as the simulation cycle progresses. Here, `head(1)` is the reference index for the next simulation cycle, `head(0)` is the reference index for the current simulation cycle, and `n` is the total number of array items in the pipeline array.

[0048] After the simulation progresses to the next cycle, the reference pointer for the next simulation cycle is reduced by 1 based on the previous simulation cycle. Thus, before calling the simulation cycle advance function, since the array item pointed to by the reference pointer is the array item corresponding to the start node of the pipeline, if the reference pointer points to the first array item in the current simulation cycle, after calling the simulation cycle advance function, the reference pointer is reduced by 1, and at this time, the reference pointer points to the second array item. The second array item is adjacent to the first array item in the pipeline array and is located before the first array item.

[0049] Based on the baseline pointer for the next simulation cycle, the target array item is assigned to the second processing function. That is, in the previous simulation cycle, the target array item corresponds to the first processing function, and in the next simulation cycle, the target array item corresponds to the second processing function. In this embodiment, the second processing function is the processing function corresponding to the second node of the pipeline. The second node is adjacent to the first node on the pipeline and is downstream of the first node.

[0050] Taking a five-stage pipeline as an example, if the first processing function is the function corresponding to decoding, then the second processing function is the function corresponding to execution.

[0051] S105. Call the second processing function so that the second processing function performs the corresponding operation according to the new instruction context in the target array item.

[0052] The new instruction context includes the result of the operation of the first processing function.

[0053] The second processing function can perform corresponding operations based on the operation result of the first processing function in the new instruction context.

[0054] In this embodiment, the first processing function corresponding to the first node of the pipeline is called. Based on the stage number of the first node in the pipeline and the reference pointer of the current simulation cycle, the target array item corresponding to the first node in the current simulation cycle is determined in the preset pipeline array. The first processing function performs corresponding operations according to the instruction context in the target array item, obtains the operation result corresponding to the first processing function, and modifies the instruction context of the target array item according to the operation result to obtain a new instruction context. Then, the simulation cycle advancement function is called to decrement the reference pointer by 1 to obtain the reference pointer of the next simulation cycle. Based on the reference pointer of the next simulation cycle, the target array item is made to correspond with the second processing function. Finally, the second processing function is called so that it performs the corresponding operation based on the new instruction context in the target array item. The second processing function is the processing function corresponding to the second node of the pipeline. The second node is adjacent to the first node in the pipeline and is downstream of the first node. In this way, by calling the simulation cycle advance function to advance the simulation to the next simulation cycle and decrementing the base pointer by 1, the processing functions of the two adjacent nodes in the pipeline can be respectively matched with the target array items and perform the corresponding operations. In this process, it is not necessary to update the pipeline registers in each node sequentially, saving pipeline simulation time and improving pipeline simulation efficiency.

[0055] In some examples, based on the stage number of the first node in the pipeline and the reference pointer of the current simulation cycle, the target array item corresponding to the first node in the current simulation cycle is determined in the preset pipeline array (S102), which may include: S102a. Determine the target index number based on the stage number of the first node in the pipeline, the reference pointer of the current simulation cycle, and the preset correspondence.

[0056] In this embodiment, the target index number is the index number of the target array item.

[0057] In this embodiment, the preset correspondence is that, starting from the array item of the pipeline array pointed to by the reference pointer, along the direction of increasing index number of each array item of the pipeline array, the level of each node of the pipeline corresponds one-to-one with each array item of the pipeline array.

[0058] S102b. Based on the target index number, determine the target array item corresponding to the first node in the preset pipeline array for the current simulation cycle.

[0059] Each array item in the pipeline array has an index number, so the target array item can be determined based on the target index number.

[0060] When retrieving a specific array item for the current simulation cycle, the state offset is performed based on the baseline index `head` of the current simulation cycle to obtain the information. For example, if the current simulation cycle needs to retrieve information about pipeline node P3, the relevant information in the array item `pipeStages[(head + 3)%n]` can be returned, where `(head + 3)%n` is the index of the array item, and `n` is the total number of array items. Clearly, this design fully utilizes the information values ​​in the array, rather than reassigning data. It simply updates the `head` value in each simulation cycle, reducing assignment operations and thus improving simulation efficiency.

[0061] In a specific example, determining the target array item corresponding to the first node in the current simulation cycle (S102b) within a preset pipeline array based on the target index number may include: A1. Call the acquisition function so that the acquisition function can retrieve the target array item corresponding to the first node of the current simulation cycle from the preset pipeline array according to the target index number.

[0062] In this embodiment, the retrieval function is a pre-defined function that can be called by higher-level applications. In some specific examples, the retrieval function can be a `get` function or an overloaded `[]` method, which can retrieve information of a specified array item. Using the overloaded `[]` method facilitates programming. Both methods accept the index x of a pipeline node Px that needs to access information and return the array item `pipeStages[(head + x)%n]` corresponding to that index, specifically returning the instruction context of that array item.

[0063] To facilitate simulation of the actual working state of the pipeline, in some examples, each array item in the pipeline array may also include a status identifier; wherein, the first processing function performs the corresponding operation based on the instruction context in the target array item (S103), which may include: S103a. Determine whether the status flag in the target array item is a valid flag.

[0064] The status flag `valid` is used to indicate whether the instruction context in an array item is valid. Status flags include valid and invalid flags. `valid` is of type boolean; in one embodiment, 1 represents a valid flag and 0 represents an invalid flag; in another embodiment, 0 represents a valid flag and 1 represents an invalid flag. It is understood that `true` can also be used to represent a valid flag and `false` to represent an invalid flag.

[0065] S103b If it is a valid identifier, the first processing function performs the corresponding operation based on the instruction context in the target array item.

[0066] When the status flag is valid, meaning the instruction context is valid, the first processing function performs the corresponding operation based on the instruction context in the target array item.

[0067] In one embodiment, after calling the simulation cycle advancement function in step S104 and before calling the second processing function in step S105, the method of this embodiment may further include: S106. Determine whether the status flag in the array item pointed to by the reference pointer in the next simulation cycle is a valid flag.

[0068] S107. If so, set the status flag in the array item pointed to by the reference pointer in the next simulation cycle to an invalid flag.

[0069] Set the status flag in the array item pointed to by the reference pointer in the next simulation cycle from valid to invalid, i.e., pipeStages[head].valid = false, to simulate deleting nodes that should leave the pipeline in the next simulation cycle.

[0070] Specifically, the `reset` method can be called to set the status flag to invalid, simulating a scenario where node information is discarded and not passed down when certain conditions are not met. This method needs to receive the index x of the deleted pipeline node Px, and update `stageValidMask[x] = 0` and `pipeStages[(head + x)%n].valid = false` through this method.

[0071] Understandably, after setting the status flag in the array item pointed to by the reference pointer of the next simulation cycle to an invalid flag, if the pipeline needs to receive a new task request, it can continue to call the processing function of the starting node corresponding to that array item to process the new task request and set the status flag in that value item to a valid flag.

[0072] In non-blocking assignment circuit implementations, if the processing functions of each node are called directly according to the pipeline execution order, especially when multiple pipelines jointly affect the state machine, the calling order needs to be carefully designed to increase the necessary code to ensure functional correctness. This is not only inefficient, but also has high code coupling and poor portability. To solve this problem, in some examples, after the first processing function in step S103 performs the corresponding operation according to the instruction context in the target array item, and before calling the simulation cycle advancement function in step S104, the method of this embodiment may also include: S108. Call the third processing function in reverse order of the node numbers of the pipeline.

[0073] The third processing function is the processing function corresponding to the node in the pipeline that is adjacent to the first node and upstream of the first node.

[0074] Taking a five-stage pipeline as an example, if the first processing function is the function corresponding to decoding, then the third processing function is the processing function corresponding to instruction fetching.

[0075] By calling the processing functions of each node in the pipeline in reverse order of their node numbers, unnecessary code design in simulation modeling can be reduced.

[0076] For example, the nodes of the pipeline include P0, P1, P2, P3...Pn-2, Pn-1. In the same simulation cycle, the processing functions of each node are called in the order of Pn-1, Pn-2...P3, P2, P1, P0.

[0077] If the pipeline array includes array items with valid status flags, simulation needs to continue. In this case, the simulation cycle advance function needs to be called to update the correspondence between each array item in the pipeline array and the stage number of the pipeline node. To determine whether pipeline simulation needs to continue, in some examples, the third processing function is the processing function corresponding to the pipeline's starting node. After calling the third processing function in step S108 according to the reverse order of the pipeline node numbers, and before calling the simulation cycle advance function in step S104, the method of this embodiment may further include: S109. Query the status flags of each array item in the pipeline array.

[0078] After calling the processing functions of P0 (the starting node) in reverse order, you can query the status flag "valid" (a boolean value) in each array item of the pipeline array, or you can query the preset status flag sequence "stageValidMask". The status flag sequence helps to obtain the overall status of the pipeline array more quickly.

[0079] The status identifier sequence stageValidMask represents the status of each node in the pipeline during the current simulation cycle. It is used to mark the valid identifier of each pipeline node. The effective bit width of this sequence is n (the total number of pipeline nodes). Each bit represents the status of the pipeline node. For example, stageValidMask[2] corresponds to the status identifier of pipeline node P2. 1 can represent a valid identifier, and 0 can represent an invalid identifier.

[0080] After setting the status flag in the array item pointed to by the reference pointer in the next simulation cycle to an invalid flag, the status flag sequence stageValidMask<<= 1 needs to be updated.

[0081] In a specific example, two query methods, isValid and anyValid, can be used to determine whether each pipeline node is valid. The isValid method takes an index Px of the pipeline node to be judged and returns stageValidMask[x]. The anyValid method is used to determine whether the pipeline has a valid transaction request. The upper layer is generally used to determine whether further pipeline simulation is needed. When this method returns stageValidMask != 0, that is, not all values ​​are 0, simulation needs to continue.

[0082] S110. Based on the status flags of each array item, determine whether to execute step S104, which involves calling the simulation cycle advancement function.

[0083] If at least one of the status flags of each array item is a valid flag, it means that the simulation needs to continue. Therefore, the simulation cycle advance function needs to be called to enter the next simulation cycle. If all the status flags of each array item are invalid flags, the simulation can end without calling the simulation cycle advance function.

[0084] To enhance the flexibility of pipeline simulation, in some examples, before calling the first processing function in step S101, the method of this embodiment may further include: S111. Instantiate a preset pipeline template based on the pipeline stage and the type of pipeline instruction context to obtain a pipeline array.

[0085] The preset pipeline template (PIPE template class structure) contains an array of pipeline nodes (pipeStages), a base index (head), and the status of each pipeline node (stageValidMask).

[0086] The array items in the pipeline node array must contain at least the status flag "valid" and the instruction context template type "payload". The payload is used to record information about the pipeline node, which can be direct information about the pipeline node or a pointer to information about the pipeline node.

[0087] In actual pipeline modeling, firstly, based on the specific pipeline, declare the pipeline stage number and the data type of pipeline node information transmission, i.e., the payload type. Then, instantiate a preset pipeline template based on the pipeline stage number n and the payload type to obtain the initial or default values ​​of the pipeline array, the base index, and the initial values ​​of the state (stageValidMask) of each pipeline node. Optionally, in the initial state, the base index points to the first array item pipeStages[0] of the pipeline array pipeStages.

[0088] In this embodiment, a template-based design is used, which can be directly instantiated and used, making the simulation method suitable for all pipeline designs and increasing the versatility of the simulation method.

[0089] In other embodiments, pipeline processing functions can also be written. When a new instruction context needs to be loaded in the current simulation cycle, the `put` method can be used; to delete pipeline nodes that meet the conditions, the `reset` method is used. The `put` method updates the information of a pipeline node in the array. This method requires two parameters: the index `x` of the pipeline node Px and the node's information payload. It needs to update `stageValidMask[x] = 1` and `pipeStages[(head + x)%n] = payload`. Here, `(head + x)%n` is the array index corresponding to node Px in the current simulation cycle.

[0090] In the above embodiments, the PIPE model structure is constructed using the concept of circular arrays, and the order of upper-level call logic is specified, which reduces the complexity of the pipeline model and improves the running efficiency of the model.

[0091] Figure 3 This is a schematic diagram of the structure of a pipeline simulation device based on GEM5 provided in an embodiment of this application, as shown below. Figure 3As shown, the pipeline simulation device based on GEM5 in this embodiment includes: a first calling module 11, used to call a first processing function; wherein the first processing function is the processing function corresponding to the first node of the pipeline, and the first node is any node of the pipeline except the last stage node; a first determining module 12, used to determine the target array item corresponding to the first node in the current simulation cycle in a preset pipeline array according to the stage number of the first node in the pipeline and the reference pointer of the current simulation cycle; wherein each array item of the pipeline array includes an instruction context; the instruction context is used to record the information of the nodes of the pipeline related to its own array item; and a modifying module 13, used by the first processing function to modify the target array item. The instruction context in the pipeline executes the corresponding operation to obtain the operation result corresponding to the first processing function, and modifies the instruction context of the target array item according to the operation result to obtain a new instruction context; the second calling module 14 is used to call the simulation cycle advancement function to decrement the reference pointer by 1 to obtain the next simulation cycle reference pointer, and make the target array item correspond to the second processing function based on the next simulation cycle reference pointer; wherein, the second processing function is the processing function corresponding to the second node of the pipeline; the second node is adjacent to the first node on the pipeline and is located downstream of the first node; the third calling module 15 is used to call the second processing function to make the second processing function execute the corresponding operation according to the new instruction context in the target array item.

[0092] The apparatus of this embodiment can be used to perform Figure 1 The technical solutions of the method embodiments shown are similar in principle and in effect, and will not be described again here.

[0093] In this embodiment, the apparatus calls a first processing function corresponding to the first node of the pipeline. Based on the stage number of the first node in the pipeline and the reference pointer of the current simulation cycle, it determines the target array item corresponding to the first node in the current simulation cycle from a preset pipeline array. The first processing function performs corresponding operations based on the instruction context in the target array item, obtains the operation result corresponding to the first processing function, and modifies the instruction context of the target array item according to the operation result to obtain a new instruction context. Then, it calls the simulation cycle advancement function to decrement the reference pointer by 1, obtains the reference pointer for the next simulation cycle, and, based on the reference pointer of the next simulation cycle, aligns the target array item with the second processing function. Finally, the second processing function is called so that it performs the corresponding operation based on the new instruction context in the target array item. The second processing function is the processing function corresponding to the second node of the pipeline. The second node is adjacent to the first node in the pipeline and is downstream of the first node. In this way, by calling the simulation cycle advance function to advance the simulation to the next simulation cycle and decrementing the base pointer by 1, the processing functions of the two adjacent nodes in the pipeline can be respectively matched with the target array items and perform the corresponding operations. In this process, it is not necessary to update the pipeline registers in each node sequentially, saving pipeline simulation time and improving pipeline simulation efficiency.

[0094] As an optional implementation, the first determining module includes: a first determining submodule, used to determine a target index number based on the stage in the pipeline where the first node is located, the reference pointer of the current simulation cycle, and a preset correspondence; and a second determining submodule, used to determine the target array item corresponding to the first node in the current simulation cycle in a preset pipeline array based on the target index number.

[0095] As an optional implementation, the second determining submodule is specifically used to: call an acquisition function so that the acquisition function can obtain the target array item corresponding to the first node in the current simulation cycle from the preset pipeline array according to the target index number.

[0096] As an optional implementation, each array item in the pipeline array further includes a status identifier; the modification module is specifically used to: determine whether the status identifier in the target array item is a valid identifier; if it is a valid identifier, the first processing function performs corresponding operations according to the instruction context in the target array item.

[0097] As an optional implementation, the device further includes: a judgment module, configured to determine whether the status identifier in the array item pointed to by the next simulation cycle reference pointer is a valid identifier after the second calling module calls the simulation cycle advancement function and before the third calling module calls the second processing function; and a setting module, configured to set the status identifier in the array item pointed to by the next simulation cycle reference pointer to an invalid identifier if the status identifier is valid.

[0098] As an optional implementation, the device further includes: a fourth calling module, used to call a third processing function in reverse order of the node numbers of the pipeline after the modification module performs the corresponding operation according to the instruction context in the target array item through the first processing function and before the second calling module calls the simulation cycle advancement function; the third processing function is the processing function corresponding to the node in the pipeline that is adjacent to the first node and is upstream of the first node.

[0099] As an optional implementation, the third processing function is the processing function corresponding to the starting node of the pipeline; the device further includes: a query module, used to query the status identifier of each array item in the pipeline array after the fourth calling module calls the third processing function in reverse order of the node numbers of the pipeline and before the second calling module calls the simulation cycle advancement function; and a second determining module, used to determine whether to execute the step of calling the simulation cycle advancement function based on the status identifier of each array item.

[0100] As an optional implementation, the apparatus further includes: an instantiation module, configured to instantiate a preset pipeline template according to the number of pipeline stages and the type of the pipeline instruction context before the first calling module calls the first processing function, so as to obtain the pipeline array.

[0101] The apparatus described in the above embodiments can be used to execute the technical solutions of the above method embodiments. The implementation principle and technical effects are similar, and will not be repeated here.

[0102] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application, as shown below. Figure 4 As shown, it may include a processor 61 and a memory 62, wherein the memory 62 is used to store executable program code; the processor 61 runs the program corresponding to the executable program code by reading the executable program code stored in the memory 62, which is used to execute any of the pipeline simulation methods based on GEM5 provided in the foregoing embodiments, and thus can also achieve the corresponding beneficial technical effects, which have been described in detail above and will not be repeated here.

[0103] The aforementioned electronic devices exist in various forms, including but not limited to: (1) Personal computer devices: These devices have computing and processing functions and generally also have mobile Internet access capabilities.

[0104] (2) Server: A device that provides computing services. The components of a server include a processor, hard disk, memory, system bus, etc. Servers are similar to general computer architectures, but because they need to provide highly reliable services, they have higher requirements in terms of processing power, stability, reliability, security, scalability, and manageability.

[0105] (3) Other electronic devices with data interaction functions.

[0106] Accordingly, embodiments of this application also provide a computer-readable storage medium storing one or more programs, which can be executed by one or more processors to implement any of the GEM5-based pipeline simulation methods provided in the foregoing embodiments, thus achieving the corresponding technical effects. This has been described in detail above and will not be repeated here.

[0107] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0108] The various embodiments in this specification are described in a related manner. The same or similar parts between the various embodiments can be referred to each other. Each embodiment focuses on describing the differences from other embodiments.

[0109] In particular, the device embodiment is basically similar to the method embodiment, so the description is relatively simple. For relevant details, please refer to the description of the method embodiment.

[0110] For ease of description, the above apparatus is described by dividing it into various functional units / modules. Of course, in implementing this application, the functions of each unit / module can be implemented in one or more software and / or hardware.

[0111] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program using hardware related to the instructions to be processed. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The storage medium can be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.

[0112] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A pipeline simulation method based on GEM5, characterized in that, include: Call the first processing function; wherein the first processing function is the processing function corresponding to the first node of the pipeline, and the first node is any node of the pipeline except the last level node; Based on the stage number of the first node in the pipeline and the reference pointer of the current simulation cycle, the target array item corresponding to the first node in the current simulation cycle is determined in the preset pipeline array; wherein, each array item of the pipeline array includes an instruction context; the instruction context is used to record information about the nodes of the pipeline related to its own array item; The first processing function performs corresponding operations based on the instruction context in the target array item to obtain the operation result corresponding to the first processing function, and modifies the instruction context of the target array item based on the operation result to obtain a new instruction context; The simulation cycle advance function is called to decrement the reference pointer by 1 to obtain the reference pointer for the next simulation cycle. Based on the reference pointer for the next simulation cycle, the target array item is assigned to the second processing function. The second processing function is the processing function corresponding to the second node of the pipeline. The second node is adjacent to the first node and is downstream of the first node on the pipeline. The second processing function is invoked so that it performs the corresponding operation based on the new instruction context in the target array item.

2. The method according to claim 1, characterized in that, The step of determining the target array item corresponding to the first node in the current simulation cycle from a preset pipeline array based on the stage number of the first node in the pipeline and the reference pointer of the current simulation cycle includes: The target index number is determined based on the stage number of the first node in the pipeline, the reference pointer of the current simulation cycle, and the preset correspondence. Based on the target index number, determine the target array item corresponding to the first node in the preset pipeline array for the current simulation cycle.

3. The method according to claim 2, characterized in that, The step of determining the target array item corresponding to the first node in the preset pipeline array based on the target index number includes: Call the acquisition function so that the acquisition function can obtain the target array item corresponding to the first node in the current simulation cycle from the preset pipeline array according to the target index number.

4. The method according to claim 1, characterized in that, Each array item in the pipeline array also includes a status identifier; The first processing function performs corresponding operations based on the instruction context in the target array item, including: Determine whether the status identifier in the target array item is a valid identifier; If it is a valid identifier, the first processing function performs the corresponding operation based on the instruction context in the target array item.

5. The method according to claim 4, characterized in that, After calling the simulation cycle advancement function and before calling the second processing function, the method further includes: Determine whether the status flag in the array item pointed to by the reference pointer in the next simulation cycle is a valid flag; If so, the status flag in the array item pointed to by the reference pointer in the next simulation cycle will be set to invalid.

6. The method according to claim 4, characterized in that, After the first processing function performs the corresponding operation based on the instruction context in the target array item, and before calling the simulation cycle advancement function, the method further includes: The third processing function is called in reverse order of the node numbers of the pipeline; the third processing function is the processing function corresponding to the node in the pipeline that is adjacent to the first node and upstream of the first node.

7. The method according to claim 6, characterized in that, The third processing function is the processing function corresponding to the starting node of the pipeline; After calling the third processing function in reverse order of the node numbers of the pipeline, and before calling the simulation cycle advancement function, the method further includes: Query the status flag of each array item in the pipeline array; Based on the status flags of each array item, determine whether to execute the step of calling the simulation cycle advancement function.

8. The method according to claim 1, characterized in that, Before calling the first processing function, the method further includes: Based on the number of stages in the pipeline and the type of the instruction context of the pipeline, a preset pipeline template is instantiated to obtain the pipeline array.

9. A pipeline simulation device based on GEM5, characterized in that, include: The first calling module is used to call the first processing function; wherein the first processing function is the processing function corresponding to the first node of the pipeline, and the first node is any node of the pipeline except the last level node; The first determining module is used to determine the target array item corresponding to the first node in the current simulation cycle in a preset pipeline array based on the stage number of the first node in the pipeline and the reference pointer of the current simulation cycle; each array item of the pipeline array includes an instruction context; the instruction context is used to record information about the nodes of the pipeline related to its own array item; The modification module is used to perform corresponding operations based on the instruction context in the target array item through the first processing function, obtain the operation result corresponding to the first processing function, and modify the instruction context of the target array item according to the operation result to obtain a new instruction context; The second calling module is used to call the simulation cycle advancement function to decrement the reference pointer by 1 to obtain the reference pointer for the next simulation cycle, and based on the reference pointer for the next simulation cycle, to make the target array item correspond to the second processing function; wherein, the second processing function is the processing function corresponding to the second node of the pipeline; the second node is adjacent to the first node on the pipeline and is located downstream of the first node; The third calling module is used to call the second processing function so that the second processing function performs corresponding operations according to the new instruction context in the target array item.

10. An electronic device, characterized in that, The electronic device includes a processor and a memory, wherein the memory is used to store executable program code; the processor runs a program corresponding to the executable program code by reading the executable program code stored in the memory, for executing the pipeline simulation method based on GEM5 as described in any one of claims 1-8.

11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores one or more programs, which can be executed by one or more processors to implement the pipeline simulation method based on GEM5 as described in any one of claims 1-8.