Branch prediction method, device, equipment and program product
Through the online branch prediction method and weight update technology based on CNN, the problem of low accuracy in actual applications of existing branch prediction models is solved, especially the prediction of complex branches, and higher prediction accuracy and adaptability are achieved.
Patent Information
- Application Number
- CN202411293103.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Priority Date
- 2023-10-20
- Filing Date
- 2024-09-13
- Publication Date
- 2024-12-03
AI Technical Summary
The existing branch prediction model has low prediction accuracy in practical applications, especially the prediction accuracy of complex branches, and offline trained models are difficult to adapt to the real-time changes of the instruction pipeline.
A branch prediction method based on convolutional neural network (CNN) is proposed. Through online branch prediction model training and weight update, the prediction result statistical data is used to optimize the weight of the branch prediction training model, and adapt to the state of the instruction pipeline in real time, thereby improving branch prediction accuracy.
It improves the instruction prediction accuracy of the branch prediction model, can better adapt to the real-time changes of the instruction pipeline, and enhances the prediction ability of complex branches.
Smart Images

Figure CN119065721A_ABST
Abstract
Description
[0001] This application claims the priority of the Chinese patent application filed with the China Patent Office on October 20, 2023, with application number 202311367042.4 and invention name “A CNN-based intelligent online branch prediction method”, the entire contents of which are incorporated by reference in this application. Technical Field
[0002] The present application relates to the field of computer technology, and in particular to a branch prediction method, device, equipment and program product. Background Art
[0003] Branch prediction technology means that when the processor processes a branch instruction, it does not wait for the branch instruction to be executed, but directly predicts the current branch jump direction and jump target. Using branch prediction technology can achieve an uninterrupted instruction flow. Branch prediction technology can effectively improve the speed of instruction execution, but it also brings certain hidden dangers. If the predicted direction is wrong, the processor extracts the wrong next instruction. In order to correct this error, the pipeline will discharge all instructions after this instruction and re-read the correct instruction, which will greatly reduce the performance of the processor.
[0004] Performing branch prediction through a branch prediction model is a branch prediction solution with broad application prospects. However, the branch prediction accuracy of the current branch prediction model is not high, and it is difficult to meet the accurate pipeline branch prediction requirements. Summary of the invention
[0005] Based on the above technical problems, the present application proposes a branch prediction method, device, equipment and program product, which can improve the instruction prediction accuracy of the branch prediction model.
[0006] The first aspect of the present application provides a branch prediction method, comprising:
[0007] In the process of performing online branch prediction using a branch prediction model, a prediction result obtained by predicting a branch instruction in an instruction pipeline using the branch prediction model is obtained, and based on the prediction result and actual instruction jump conditions, prediction result statistical data is generated;
[0008] Performing branch prediction training on a branch prediction training model using the prediction result statistical data to obtain a trained branch prediction training model; wherein, before performing branch prediction training on the branch prediction training model, a weight of the branch prediction training model is the same as a weight of the branch prediction model;
[0009] In the case where it is determined that the branch prediction result of the trained branch prediction training model is better than the branch prediction result of the branch prediction model, the weight of the branch prediction model is updated using the weight of the trained branch prediction training model.
[0010] A second aspect of the present application provides a branch prediction device, comprising:
[0011] A data acquisition unit is used to acquire a prediction result obtained by predicting a branch instruction in an instruction pipeline using the branch prediction model during online branch prediction, and generate prediction result statistics based on the prediction result and actual instruction jump conditions;
[0012] A model training unit, used to perform online branch prediction training on a branch prediction training model using the prediction result statistical data to obtain a trained branch prediction training model; wherein, before performing online branch prediction training on the branch prediction training model, a weight of the branch prediction training model is the same as a weight of the branch prediction model;
[0013] A model updating unit is used to update the weight of the branch prediction model using the weight of the trained branch prediction training model when it is determined that the branch prediction result of the trained branch prediction training model is better than the branch prediction result of the branch prediction model.
[0014] A third aspect of the present application provides a branch prediction device, comprising:
[0015] Memory and processor;
[0016] The memory is connected to the processor and is used to store programs;
[0017] The processor is used to implement the above-mentioned branch prediction method by running the program in the memory.
[0018] A fourth aspect of the present application provides a computer program product, comprising computer program instructions, which, when executed by a processor, enable the processor to execute the above-mentioned branch prediction method.
[0019] The branch prediction method proposed in the present application obtains the prediction result obtained by the branch prediction model for the branch instruction in the instruction pipeline during the process of online branch prediction using the branch prediction model, and generates the prediction result statistical data based on the prediction result and the actual instruction jump situation; then the branch prediction training model is trained for branch prediction based on the prediction result statistical data to obtain the trained branch prediction training model; when it is determined that the branch prediction result of the trained branch prediction training model is better than the branch prediction result of the branch prediction model, the weight of the branch prediction model is updated using the weight of the trained branch prediction training model. The above scheme can update the weight of the branch prediction model based on the instruction jump situation in the instruction pipeline in real time during the application of the branch prediction model, so that the weight of the branch prediction model is adapted to the real-time state of the instruction pipeline and can be kept updated in real time, thereby improving the instruction prediction accuracy of the branch prediction model. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0021] Figure 1 A schematic diagram of the structure of a branch prediction model proposed in an embodiment of the present application.
[0022] Figure 2 A schematic diagram of the structure of another branch prediction model provided in an embodiment of the present application.
[0023] Figure 3 A schematic diagram of the structure of the SE module provided in an embodiment of the present application.
[0024] Figure 4 A schematic diagram of the historical information encoding results provided in an embodiment of the present application.
[0025] Figure 5 A schematic diagram of historical information encoding and historical information encoding splicing provided in an embodiment of the present application.
[0026] Figure 6 A schematic flow chart of a branch prediction method provided in an embodiment of the present application.
[0027] Figure 7 A schematic diagram of the structure of a branch prediction system provided in an embodiment of the present application.
[0028] Figure 8A schematic diagram of the structure of a branch classifier provided in an embodiment of the present application.
[0029] Fig. 9 A schematic diagram of querying branch classification status from a saturation counter group provided in an embodiment of the present application.
[0030] Fig.10 A schematic diagram of the structure of a branch prediction device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0031] In modern high-performance microprocessors, branch prediction is to predict the branch direction and address before executing the branch instruction, and obtain the program jump address instruction in advance. Correct branch prediction can effectively avoid the performance loss caused by pipeline pauses, while incorrect branch prediction will cause the CPU instruction pipeline to pause. Complex branch prediction is the main bottleneck for CPU performance improvement.
[0032] Current research usually defines difficult-to-predict branches as complex branches. Branch prediction schemes can be divided into two directions: static branch prediction and dynamic branch prediction. The static scheme relies on static strategies to predict branches, setting branch instructions as jumps or non-jumps. Dynamic branch prediction is the current mainstream prediction scheme, which dynamically updates the prediction results based on the historical execution information of branch instructions.
[0033] Traditional TAGE-based branch prediction technology has been able to achieve accurate prediction of most simple branches, but when faced with complex branches with noise, existing branch predictors still have the problem of low efficiency and are difficult to expand.
[0034] Traditional branch predictors such as TAGE and Perceptron are designed to be updated at runtime. Therefore, their update algorithms must be simple, low-overhead, and fast to adapt to the behavior of the program at different stages of execution. Simplicity and adaptability are necessary to predict most branches at runtime, but limitations in training time and processing power make it difficult for online branch predictors to learn complex correlations in branch histories. In order to learn these correlations in branch histories, it is necessary to design more complex prediction mechanisms.
[0035] With the rapid development of neural networks, machine learning has also been used more in branch prediction. Its essence is to predict the jump of the current branch instruction by learning the characteristics of the branch history. Researchers designed a convolutional neural network (CNN) as a branch prediction model, and compared the model with the deep belief network (DBN), ResNet-50 and TAGE-based branch prediction algorithm. The prediction accuracy is higher than other algorithms. Other researchers have proposed a branch prediction model based on the BranchNet convolutional neural network model, which improves the prediction accuracy by inputting enough branch history features into the model.
[0036] At present, the research on combining traditional branch prediction technology with machine learning has achieved good results, but there are still some problems to be solved. The branch prediction accuracy based on machine learning is very high, but there are still mispredictions. The main source of these mispredictions is a few complex branches that are systematically difficult to predict (Hard-To-Predict, H2P). The existing technology has a low prediction accuracy for complex branches.
[0037] The applicant of this case found through research that the current branch prediction models are deployed in microprocessors after offline training. However, due to the difference between offline data and actual operation data of microprocessors, the branch prediction models completed through offline training may not fully adapt to the actual program instruction characteristics and instruction changes in the instruction pipeline, resulting in the branch prediction model having good performance in offline training but low prediction accuracy in actual applications.
[0038] In response to the above technical problems, the present application proposes a new branch prediction solution, which can improve the prediction accuracy of the branch prediction model in practical applications.
[0039] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0040] The branch prediction method proposed in the application embodiment is suitable for an application scenario in which the jump direction of a predicted branch instruction is predicted based on the historical information of the predicted branch instruction. Specifically, it can be applied to an execution environment in which branch jump direction prediction is performed, such as by a computer that performs branch prediction tasks, or by a processor when performing branch prediction. For example, when a processor using an instruction pipeline mode performs branch prediction, it can be implemented by executing the branch prediction method proposed in the application embodiment. The application embodiment does not limit the specific execution environment and application scenario of the branch prediction method proposed in the application. In subsequent embodiments, the specific processing process of the branch prediction method will be mainly introduced.
[0041] The embodiment of the present application first proposes a branch prediction model, which is constructed based on a convolutional neural network (CNN).
[0042] See also Figure 1 As shown, the branch prediction model proposed in the embodiment of the present application includes multiple convolutional neural network slices, each convolutional neural network slice is a convolutional neural network structure, and the structures of each convolutional neural network slice are the same, and the parameters of each convolutional neural network slice can be the same or different. For example, each convolutional neural network slice can use the same network parameters, or some convolutional neural network slices can use the same network parameters while other convolutional neural network slices use different network parameters, or each convolutional neural network slice can use different network parameters.
[0043] Each convolutional neural network slice is used to predict the jump direction of a branch instruction. That is to say, each convolutional neural network slice can input the historical information of the predicted branch instruction, and based on the historical information of the predicted branch instruction, predict the jump direction of the predicted branch instruction to obtain a jump direction prediction result.
[0044] The final jump direction predicted for the predicted branch instruction is determined by the jump direction prediction results output by each convolutional neural network slice. For example, the jump direction prediction result with the highest frequency of occurrence can be selected from the jump direction prediction results output by each convolutional neural network slice as the final jump direction, or the jump direction prediction result with the highest confidence can be selected from the jump direction prediction results output by each convolutional neural network slice as the final jump direction, and so on.
[0045] In some embodiments, see Figure 2As shown, the above-mentioned convolutional neural network slices include, from front to back, the first convolutional layer, the first average pooling layer, the first fully connected layer, the second convolutional layer, the second average pooling layer and the output layer. The output layers of the multiple convolutional neural network slices are respectively connected to the second fully connected layer, and the second fully connected layer summarizes the outputs of each convolutional neural network slice and outputs the final jump direction prediction result. For example, the output of each convolutional neural network slice includes 2 neurons, corresponding to the two situations of jump and no jump. The second fully connected layer is used to determine which slice's output result has a higher confidence, and then select the slice output result with the highest confidence to obtain the final branch prediction result.
[0046] Among them, the number of input channels of the first convolution layer is 1, the number of output channels is 16, the convolution kernel size is 3×3, and the step size is 1; the pooling kernel size of the first average pooling layer is 2×2, and the step size is 1; the number of input channels of the second convolution layer is 16, the number of output channels is 4, the convolution kernel size is 3×3, and the step size is 1; the pooling kernel size of the second average pooling layer is 2×2, and the step size is 1.
[0047] In addition, if Figure 2 As shown, the embodiment of the present application also sets an attention mechanism module in the first convolution layer of each convolutional neural network slice. The attention mechanism module assigns different weights to the data of each channel output by the first convolution layer, so that the model is able to judge which channel represents more important features, and there is no need to make major changes to the original convolution layer.
[0048] The attention mechanism module can be implemented by any module that can implement the attention mechanism (Attention Mechanism), and the embodiment of the present application does not limit the specific structure of the above-mentioned attention mechanism module. Squeeze-and-Excitation (SE) is a channel attention model that enhances the attention to important channels by adjusting the weights of each channel, thereby improving the expressiveness of the model. Experiments show that SE can achieve better performance in tasks such as image classification, object detection, and segmentation. Therefore, the attention mechanism module added in each convolutional neural network slice in the embodiment of the present application is implemented in the manner of the above-mentioned SE module.
[0049] like Figure 3As shown in the figure, after the input data X is input to the first convolutional layer for processing, the first convolutional layer outputs 16 channels of 1×99 data. After entering the attention mechanism module, the data is first globally pooled, and the 799 values on each channel are added to obtain the weight of the current channel. Then it enters a fully connected layer. At this time, the division by r is to reduce the amount of calculation of the fully connected layer. In the actual design, r is taken as 4 to balance the results of accuracy and calculation. Then after being processed by the ReLU activation function, it is input to the second fully connected layer. At this time, the weights of the 16 channels are restored, and then normalized by the Sigmoid function, so that 16 weights between 0 and 1 are obtained. Finally, the values of these 16 weights are multiplied by the 799 values of the 16 corresponding channels to obtain the final output X′ of the first convolutional layer.
[0050] In other embodiments, the branch prediction model includes 5 convolutional neural network slices, and the 5 convolutional neural network slices are configured to process history information of different lengths, that is, the 5 convolutional neural network slices are respectively used to receive history information of different lengths of the predicted branch instructions, for example, the 5 convolutional neural network slices respectively receive history information of 10, 20, 30, 50, and 200 lengths from the predicted branch instructions. Through the above configuration, when the 5 convolutional neural network slices perform branch prediction at the same time, the jump direction of the predicted branch can be predicted by different convolutional neural network slices with the help of history information of different lengths, and finally the output results of each convolutional neural network slice are integrated, so that in the process of branch prediction, the branch information appearing at a farther position can be considered while taking into account the intervals where the branch information at a closer position appears frequently, so that useful information can be more comprehensively mined from the data of different intervals to improve the accuracy of branch prediction.
[0051] After the branch prediction model is constructed through the above-mentioned embodiment, the embodiment of the present application predicts the branch prediction model through the following processing methods of steps A1-A4:
[0052] A1. Extract the global history information of each branch path from the running process record of the test program in the setting database.
[0053] Specifically, the embodiment of the present application uses SPEC CPU2006 as a database, obtains the running process record trace of each test program in the database through the PinTool tool, and uses a script to extract the global history information of each branch path in the running process record of the test program. Among them, the global history information includes two data types, namely PC and history. PC represents the address of the branch instruction, that is, the historical address where the current branch address appears in the global history, and history represents all the historical information of the program, saves all the branch instruction information of the currently executed program, and records the address of each branch instruction and the corresponding jump direction.
[0054] Furthermore, in an embodiment of the present application, the trace of each test program is also used to perform branch prediction using a branch predictor to obtain the prediction accuracy of each branch instruction, and then branches with a prediction accuracy of less than 95% are defined as complex branches. These complex branches are usually branches that contain a large amount of historical information, or branches whose jump directions can only be accurately predicted by processing a large amount of historical information. Since the branch predictor has a low prediction accuracy for these branches, the embodiment of the present application uses the historical information of these branches to train the branch prediction model, so that the trained branch prediction model can achieve accurate prediction of these types of branches. Therefore, in this embodiment, the global historical information of each branch path is extracted from the running process record of the test program in the set database, specifically the global historical information of each complex branch is extracted.
[0055] A2. Perform encoding processing on each historical information pair in the global historical information to obtain historical information codes corresponding to each historical information pair.
[0056] Specifically, the embodiment of the present application represents the global history information of the branch path in the form of a history information pair (PC, direction), wherein PC represents the history address of the branch path, and direction represents the jump direction corresponding to PC.
[0057] Since PC can take many different values in a computer, in order to enable the PC in each historical information pair to be processed by the branch prediction model, the embodiment of the present application encodes each historical information pair to obtain the historical information encoding corresponding to each historical information pair.
[0058] Exemplarily, the embodiment of the present application performs one-bit binary quantization on the jump direction direction in the historical information pair, that is, a binary number is used to represent the jump direction, such as 0 for no jump and 1 for jump, to obtain the jump direction code. At the same time, the historical address PC in the historical information pair is binary quantized, that is, the address code is represented in binary to obtain the historical address code.
[0059] Then, the historical address code is shifted left by one position, and the jump direction code is used to fill the shifted empty position. That is, the historical address code is shifted left by one position as a whole, and a vacancy appears at the last position, and then the jump direction code is filled in the vacancy.
[0060] Finally, the value corresponding to the last N bits of the padded historical address code is obtained as the historical information code of the historical information pair, where N is a positive integer.
[0061] In this embodiment, the decimal value corresponding to the last 8 bits of the padded historical address code is extracted as the historical information code of the historical information pair.
[0062] Exemplarily, the encoding of historical information pairs can be achieved by the following formula:
[0063] (PC<<1+dir)&(2 k -1)
[0064] Among them, PC represents the binary encoding of the last 8 bits of the historical address in the historical information pair, PC<<1 means shifting the binary encoding of the last 8 bits of the historical address one bit to the left, dir represents the encoding of the jump direction in the historical information pair, k is 8, (PC<<1+dir)&(2 k -1) can convert the binary code of (PC<<1+dir) into a decimal value.
[0065] like Figure 4 As shown in , according to the encoding method of the above embodiment of the present application, for the branch path recorded in the program counter, the historical information encoding corresponding to each historical information pair can be calculated respectively. For example, 40062a represents the historical address, and its corresponding jump direction is "jump". The historical information encoding of the historical information pair obtained by the above embodiment is 85, and the corresponding binary encoding is 01010101.
[0066] A3. Concatenate multiple historical information codes corresponding to the same branch path to obtain a historical information code matrix.
[0067] Specifically, since a branch path includes multiple historical addresses, and the prediction of branch instructions also requires information of multiple historical addresses, the embodiment of the present application will splice multiple historical information codes corresponding to the same branch path to obtain a historical information code matrix.
[0068] like Figure 5 As shown, the historical position indicates the position where the current branch occurs, 200 represents the branch instruction on the current branch, in the jump direction, T represents jump, NT represents no jump, and the numerical value represents the historical information encoding obtained after encoding according to the above embodiment. Figure 5 The matrix on the right in the middle shows the historical information encoding matrix obtained after splicing.
[0069] A4. Input the historical information encoding matrix into a pre-built branch prediction model, and perform jump direction prediction training on the branch prediction model.
[0070] Specifically, for each convolutional neural network slice in the branch prediction model, historical information of a specific length is extracted from the running process record of the test program to obtain corresponding historical information pairs, and the historical information pairs are processed by performing the above steps A1-A3 to obtain a historical information encoding matrix. The historical information encoding matrix is input into each convolutional neural network slice of the branch prediction model, so that each convolutional neural network slice is trained for jump direction prediction.
[0071] During the training process, the second fully connected layer of the branch prediction model assigns higher weights to the output results of the convolutional neural network slices with high confidence and lower weights to the output results of the convolutional neural network slices with low confidence based on the output of each convolutional neural network slice. Then, based on the weights of the output results of each convolutional neural network, the output results of each convolutional neural network are fused to determine the final jump direction prediction result.
[0072] The loss function between the prediction result and the jump direction label is used to optimize the parameters of each convolutional neural network slice of the branch prediction model, making the prediction result of the branch prediction model more and more accurate.
[0073] The branch prediction model trained as above can be used to predict the jump direction of any predicted branch instruction, and is particularly suitable for predicting the jump direction of branch instructions with complex historical information.
[0074] The branch prediction model constructed and trained based on the above embodiment can be deployed in the branch prediction scenario of the instruction pipeline. In the instruction pipeline, when a predicted branch instruction is obtained, the predicted branch instruction is input into the branch prediction model so that the branch prediction model predicts the jump direction of the predicted branch instruction.
[0075] The historical information of the predicted branch instruction includes the historical address of the branch path where the predicted branch instruction is located and the corresponding jump direction, that is, the PC of the branch path where the predicted branch instruction is located and the corresponding direction.
[0076] In some embodiments, since the branch prediction model includes multiple convolutional neural network branches, the historical information of the predicted branch instructions is grouped and the inputs corresponding to each convolutional neural network branch are generated respectively.
[0077] Specifically, based on the history information of the predicted branch instruction, multiple history information sets are generated; wherein the number of the history information sets is equal to the number of the convolutional neural network slices, and the history information sets include history information of a specific length of the predicted branch instruction. That is, the length of the history information in the history information set corresponding to each convolutional neural network slice is equal to the processable length of the history information set for the convolutional neural network slice.
[0078] Then, each historical information set can be input one-to-one into each convolutional neural network slice of the pre-trained branch prediction model, so that each convolutional neural network slice can perform the jump direction prediction task.
[0079] In some embodiments, it is specifically disclosed that the branch prediction model includes 5 convolutional neural network slices, and the processable historical information lengths are set to 10, 20, 30, 50, and 200 respectively.
[0080] Based on the above configuration, when multiple historical information sets are generated based on the historical information of the predicted branch instruction, it specifically includes:
[0081] Based on the history information of the predicted branch instruction, generating a first history information set, a second history information set, a third history information set, a fourth history information set and a fifth history information set;
[0082] The first history information set includes 10 consecutive history addresses extracted from the address of the predicted branch instruction and along the branch path where the predicted branch instruction is located, and the corresponding jump directions;
[0083] The second history information set includes 20 consecutive history addresses extracted from the address of the predicted branch instruction and forward along the branch path where the predicted branch instruction is located, and the corresponding jump directions;
[0084] The third history information set includes 30 consecutive history addresses extracted from the address of the predicted branch instruction and forward along the branch path where the predicted branch instruction is located, and the corresponding jump directions;
[0085] The fourth history information set includes 50 consecutive history addresses extracted from the address of the predicted branch instruction and forward along the branch path where the predicted branch instruction is located, and the corresponding jump directions;
[0086] The fifth history information set includes 200 consecutive history addresses extracted from the address of the predicted branch instruction and forward along the branch path where the predicted branch instruction is located, and the corresponding jump directions.
[0087] That is, through the above processing, among the first 200 historical addresses of the predicted branch instructions, starting from the address of the predicted branch instruction, 10, 20, 30, 50, and 200 historical addresses and their corresponding jump direction information are extracted forward respectively, and 5 historical information sets are obtained. These 5 historical information sets can be used to input 5 convolutional neural network slices for jump direction prediction respectively.
[0088] It is also disclosed in another embodiment that, in order to facilitate the branch prediction model to process the historical information of the predicted branch instruction, the historical information of the predicted branch instruction is encoded according to the encoding method introduced in the above embodiment, and the encoding matrix of each historical address of the branch path where the predicted branch instruction is located and the corresponding jump direction is obtained, and the encoding matrix is input into the branch prediction model.
[0089] That is to say, in the above embodiment, the historical information of the predicted branch instructions input to each convolutional neural network slice of the branch prediction model is specifically in the form of a coding matrix of each historical address of the branch path where the predicted branch instruction is located and the corresponding jump direction.
[0090] The above encoding matrix is obtained in the same manner as the encoding and concatenation manner described in the above embodiment. The final encoding matrix is as follows: Figure 5 The matrix form shown on the right.
[0091] Exemplarily, when encoding the historical information of the predicted branch instruction, firstly, binary code each historical address and corresponding jump direction of the branch path where the predicted branch instruction is located to obtain the code corresponding to each historical address. Then, concatenate the codes corresponding to each historical address of the branch path where the predicted branch instruction is located to obtain a coding matrix as the historical information of the predicted branch instruction.
[0092] Specifically, according to the processing method shown in steps A2 and A3 in the above embodiment, each historical address of the branch path where the predicted branch instruction is located and the corresponding jump direction (historical information pair) are encoded, and the obtained encoding results (including the encoding of the historical address and jump direction) are spliced to obtain the encoding matrix of the historical information of the predicted branch instruction.
[0093] The branch prediction method proposed in the embodiment of the present application processes the historical information of the predicted branch instruction through a pre-trained branch prediction model to predict the jump direction of the branch instruction. The branch prediction model includes multiple convolutional neural network slices, each of which is used to predict the jump direction of the branch instruction, and the jump direction of the predicted branch instruction is determined based on the jump direction predicted by each of the convolutional neural network slices. Since the convolutional neural network has good processing performance in complex information processing, the above-mentioned branch prediction model can better mine the useful information scattered in the complex historical information of the predicted branch instruction through the convolutional neural network, thereby realizing accurate jump direction prediction. In addition, the multiple convolutional neural network slices of the above-mentioned branch prediction model can more comprehensively and effectively extract the branch features hidden in the historical information of the predicted branch instruction, and then predict the jump direction based on these branch features, which can further improve the accuracy of the jump direction prediction.
[0094] However, the branch prediction accuracy of the above-mentioned branch prediction model constructed simply with the help of offline training in the actual instruction pipeline is not high enough. Therefore, based on the branch prediction model described in the above-mentioned embodiment and the branch prediction scheme based on the branch prediction model proposed in the above-mentioned embodiment, the embodiment of the present application proposes a new branch prediction method.
[0095] See also Figure 6 As shown, the method includes:
[0096] S101. In the process of performing online branch prediction using a branch prediction model, a prediction result obtained by the branch prediction model for predicting branch instructions in an instruction pipeline is obtained, and prediction result statistics are generated based on the prediction result and actual instruction jump conditions.
[0097] Specifically, during the operation of a processor in an instruction pipeline mode, an online branch prediction is performed using a branch prediction model, specifically, the branch instruction in the instruction pipeline is input into the above-mentioned branch prediction model, and the branch prediction model is used to predict the jump direction of the branch instruction to obtain a prediction result. The embodiment of the present application also stores and records the prediction result obtained by the branch prediction model predicting the branch instruction in the instruction pipeline.
[0098] At the same time, the actual instruction jump status of the branch instruction in the instruction pipeline is also stored and recorded.
[0099] Based on the above data records, the embodiment of the present application generates prediction result statistics based on the prediction results of branch instructions in the instruction pipeline and the actual instruction jump conditions.
[0100] The above-mentioned prediction result statistics include the address of the branch instruction, the historical information of the branch instruction, the prediction result of the branch instruction, the actual jump situation of the branch execution, whether the branch instruction is a complex branch, the prediction accuracy of the branch prediction model for the branch instruction, etc.
[0101] Exemplarily, for each branch instruction address in the instruction pipeline, corresponding prediction result statistics can be generated.
[0102] It can be understood that the above-mentioned prediction result statistics are the result statistics of predicting the branch instructions in the instruction pipeline during the actual operation of the instruction pipeline, as well as the actual jump situation statistics of the branch instructions. The prediction result statistics are data that can reflect the actual operation process of the instruction pipeline.
[0103] S102: Perform branch prediction training on a branch prediction training model using the prediction result statistical data to obtain a trained branch prediction training model.
[0104] Specifically, in the embodiment of the present application, in addition to setting the above-mentioned branch prediction model in the processor architecture to perform branch prediction tasks, a branch prediction training model with the same weight as the above-mentioned branch prediction model is also set. The structure and parameter weights of the branch prediction training model are the same as those of the above-mentioned branch prediction model.
[0105] The weight of the branch prediction model or the branch prediction training model refers to the parameters used to calculate and estimate the relationship between input and output within the neural network of the model, that is, the parameters between neurons of the neural network. The weight of the model determines the learning ability and prediction accuracy of the model and is an important parameter in the model.
[0106] In the process of applying the above branch prediction model to the branch instruction prediction of the instruction pipeline, after obtaining the above prediction result statistical data, the branch prediction training model is trained using the above prediction result statistical data. That is, the branch prediction training model is trained using the prediction result statistical data obtained in the online branch prediction process of the branch prediction model, the weight of the branch training model is optimized and adjusted, and the trained branch prediction training model is obtained.
[0107] Among them, the branch prediction training process of the branch prediction training model is the same as the process of offline training of the branch prediction model introduced in the above embodiment. The training process is to use the branch prediction training model to predict the jump direction of the branch instructions in the prediction result statistical data, and then use the loss function between the prediction result and the actual jump situation to optimize the parameter weight of the branch prediction training model, so that the loss between the prediction result of the branch prediction training model and the actual jump situation is smaller, that is, the branch prediction accuracy of the branch prediction training model is higher.
[0108] Exemplarily, when executing the technical solution of the embodiment of the present application, a branch prediction training execution cycle can be set for the branch prediction training model, that is, a set cycle is set at each interval, and the prediction results of the branch instructions within the cycle and the actual instruction jump situation are used to generate prediction result statistics, and the prediction result statistics are used to perform branch prediction training on the branch prediction training model.
[0109] S103: When it is determined that the branch prediction result of the trained branch prediction training model is better than the branch prediction result of the branch prediction model, update the weight of the branch prediction model using the weight of the trained branch prediction training model.
[0110] Specifically, after completing the branch prediction training of the branch prediction training model, the branch prediction results of the trained branch prediction training model are compared with those of the branch prediction model to determine whether the branch prediction results of the trained branch prediction training model are better than the branch prediction results of the branch prediction model, that is, to determine whether the branch prediction accuracy of the trained branch prediction training model is better than the branch prediction accuracy of the branch prediction model.
[0111] Exemplarily, in the process of training the branch prediction training model using the above-mentioned prediction result statistical data, the prediction accuracy of the branch prediction training model for each branch instruction in the prediction result statistical data is recorded in real time. After the training of the branch prediction training model is completed, the branch prediction accuracy of the branch prediction training model after training is compared with the branch prediction accuracy of the branch prediction model recorded in the above-mentioned prediction result statistical data to determine whether the branch prediction accuracy of the branch prediction training model after training is better than the branch prediction accuracy of the branch prediction model.
[0112] When it is determined that the branch prediction result of the trained branch prediction training model is better than the branch prediction result of the branch prediction model, the weight of the branch prediction model is updated using the weight of the trained branch prediction training model, that is, all the weights of the trained branch prediction training model are assigned to the branch prediction model. At this time, the weights of the branch prediction training model and the branch prediction model are consistent, and the branch prediction model after the updated weight has a higher branch prediction accuracy than the original branch prediction model, that is, online training and optimization of the branch prediction model are realized.
[0113] From the above introduction, it can be seen that the branch prediction method proposed in the embodiment of the present application obtains the prediction result obtained by the branch prediction model for predicting the branch instructions in the instruction pipeline through the branch prediction model, and generates the prediction result statistical data based on the prediction result and the actual instruction jump situation; then, the branch prediction training model is trained for branch prediction based on the prediction result statistical data to obtain the trained branch prediction training model; when it is determined that the branch prediction result of the trained branch prediction training model is better than the branch prediction result of the branch prediction model, the weight of the branch prediction model is updated using the weight of the trained branch prediction training model. The above scheme can update the weight of the branch prediction model based on the instruction jump situation in the instruction pipeline in real time during the application of the branch prediction model, so that the weight of the branch prediction model is adapted to the real-time state of the instruction pipeline, and can be kept updated in real time, thereby improving the instruction prediction accuracy of the branch prediction model.
[0114] In other embodiments, it is proposed that Figure 7 The branch prediction system shown is used to implement the branch prediction method proposed in the above embodiments of the present application.
[0115] See also Figure 7 As shown, the branch prediction system includes:
[0116] Branch classifier, branch predictor, branch prediction model, prediction result statistics unit, branch prediction training model.
[0117] The program counter counts the branch instructions in the instruction pipeline and determines the address of the branch instruction. Whenever a branch instruction is counted, the address of the branch instruction is input into the branch classifier to start the branch prediction process.
[0118] The branch classifier is used to classify the predicted branch instruction output by the program counter to determine whether it is a simple branch or a complex branch.
[0119] When the predicted branch instruction is determined to be a complex branch, the predicted branch instruction is input into the branch prediction model so that the branch prediction model predicts the predicted branch instruction to obtain a prediction result. The structure of the branch prediction model and the prediction process of the branch prediction model for the predicted branch instruction can be referred to the above embodiment.
[0120] When the predicted branch instruction is determined to be a simple branch, the predicted branch instruction is input into a branch predictor so that the branch predictor predicts the predicted branch instruction to obtain a prediction result. In the embodiment of the present application, the branch predictor is a TAGE_SC_L branch predictor.
[0121] The prediction result statistics unit is used to record and count the branch prediction results output by the branch prediction model and the branch predictor, including the address of the branch instruction, the historical information of the branch instruction, whether the branch instruction jumps, etc. In addition, the prediction result statistics unit can also generate prediction result statistics based on the statistical results of the branch prediction results output by the branch prediction model and the branch predictor. The prediction result statistics include the address of the branch instruction, the historical information of the branch instruction, whether the branch instruction is a complex branch, whether the branch instruction predicted by the branch predictor and / or the branch prediction model jumps, the actual jump of the branch instruction, the branch prediction accuracy of the branch predictor and / or the branch prediction model, etc. The prediction result statistics are used to train the branch prediction training model. The specific training process can be referred to the introduction of the above embodiment.
[0122] After the branch prediction training model is trained using the above-mentioned prediction result statistical data, the prediction accuracy of the trained branch prediction training model is compared with that of the branch prediction model. If the prediction accuracy of the trained branch prediction training model is higher than that of the branch prediction model, all the weights of the branch prediction training model are assigned to the branch prediction model.
[0123] Exemplarily, in an embodiment of the present application, an update signal sig is set to identify whether to update the weight of the branch prediction model. When it is determined that the prediction accuracy of the trained branch prediction training model is higher than the prediction accuracy of the branch prediction model, the value of the update signal is set to 1. When the system detects that the update signal is 1, all the weights of the branch prediction training model are assigned to the branch prediction model. When it is determined that the prediction accuracy of the trained branch prediction training model is not higher than the prediction accuracy of the branch prediction model, the value of the update signal is set to 0. When the system detects that the update signal is 0, the weight of the branch prediction model remains unchanged.
[0124] Based on the above-mentioned branch prediction system, in the process of branch prediction for the instruction pipeline, the weight of the branch prediction model can be updated online, so that the branch prediction model can adjust the weight in real time as the processed branch instructions change. In this way, the branch prediction model will not have unstable performance due to frequent changes in branch instructions during the branch instruction prediction process, thereby improving the prediction accuracy of the branch prediction model.
[0125] On the other hand, the above-mentioned branch prediction system includes both a branch predictor and a branch prediction model, which can be used to predict simple branches and complex branches respectively, so that both simple branches and complex branches in the instruction pipeline are predicted in the optimal way, thereby improving the instruction prediction efficiency and accuracy.
[0126] In some embodiments, see Figure 8 As shown, the above branch classifier includes:
[0127] Program counter, saturation counter group, and update module;
[0128] The above-mentioned saturation counter group is used to store the classification status of the branch instruction. The above-mentioned classification status is used to indicate whether the branch instruction is a complex branch or a simple branch. In an embodiment of the present application, four classification states are set, namely a strong complex branch state, a strong simple branch state, a complex branch state and a weak simple branch state. In addition, the embodiment of the present application identifies the above-mentioned different classification states by a 2-bit binary number, for example, 11 is used to represent a strong complex branch state, 00 is used to represent a strong simple branch state, 10 is used to represent a weak complex branch state, and 01 is used to represent a weak simple branch state.
[0129] In the above saturation counter group, the address of the branch instruction and the 2-bit identifier of the classification state of the branch instruction are stored correspondingly. Through the address of the branch instruction, the corresponding instruction classification state can be queried from the saturation counter group.
[0130] The program counter is used to count branch instructions in the instruction pipeline and determine the address of the branch instruction.
[0131] The update module is used to update the classification status in the saturation counter group.
[0132] Based on the above-mentioned parts, when the branch classifier classifies the predicted branch instruction, the program counter queries the classification status of the predicted branch instruction from the saturated counter group based on the address of the predicted branch instruction, and sends the query classification result to the update module.
[0133] In the embodiment of the present application, the address of the predicted branch instruction is the last k bits of the predicted branch instruction, where k is a positive integer. In the present embodiment, k=4, that is, the program counter queries the classification status of the predicted branch instruction from the saturated counter group based on the last 4 bits of the predicted branch instruction.
[0134] In the embodiment of the present application, the last k bits of the branch instruction are used for addressing, and then 2 k +1 list to store the address of the branch instruction, so that only 2 k+1 The storage space for storing the classification table. Using the last k bits of the address for addressing requires the maintenance of 2 k A saturation counter is provided, and each saturation counter represents the classification state of the branch instruction through a 2-bit binary number, thereby fully hashing the branch address without causing a large number of table entry replacements.
[0135] like Fig. 9 As shown, the program counter determines that the last 4 bits of the address of the currently entered predicted branch instruction are 1110. By addressing in the saturated counter group, it is found that the classification state corresponding to the address 1110 is 11, indicating that the predicted branch instruction is in a strong complex branch state. At this time, the predicted branch instruction can be predicted to be a complex branch.
[0136] After the program counter queries and determines the classification status of the predicted branch instruction, the query result is sent to the update module.
[0137] The update module obtains the classification status queried from the saturated counter group and the actual classification result of the predicted branch instruction, and updates the classification status corresponding to the predicted branch instruction stored in the saturated counter group using the queried classification status and the actual classification result.
[0138] Among them, the actual classification results of the predicted branch intelligence can be obtained from Figure 7 The prediction result statistics unit shown in is obtained.
[0139] The update module compares the classification status of the predicted branch instruction queried by the program counter from the saturation counter group with the actual classification result of the predicted branch instruction, and updates the classification status corresponding to the predicted branch instruction stored in the saturation counter group based on the comparison result.
[0140] Specifically, if the classification status of the predicted branch instruction in the saturated counter group is a strong complex branch state 11, and the actual classification result of the predicted branch instruction is also a complex branch, then the classification status of the predicted branch instruction in the saturated counter group is maintained as a strong complex branch state 11; if the classification status of the predicted branch instruction in the saturated counter group is a strong complex branch state 11, but the actual classification result of the predicted branch instruction is a simple branch, then the classification status of the predicted branch instruction in the saturated counter group is updated to a complex branch state 10.
[0141] During the update process, if a branch instruction is found to have no record in the saturation counter group, then according to the FIFO principle, the earliest instruction record that enters the saturation counter group is popped out, and then the unrecorded instruction is stored in the saturation counter group, and its classification state is set to a strong state, such as a strong complex branch state 11 or a strong simple branch state 00. The branch newly added to the saturation counter group is assigned a strong state, that is, the classification state of the first appearance of the branch is selected. The scheme of assigning values using this rule can better reduce the interference between branches with the same addressing address.
[0142] Through the above scheme, the classification status of the sub-instructions recorded in the saturation counter group is continuously updated, so that the branch classifier can gradually have the branch classification capability and the branch classification accuracy can be gradually improved.
[0143] Corresponding to the above branch prediction method, an embodiment of the present application further provides a branch prediction device, the device comprising:
[0144] A data acquisition unit is used to acquire a prediction result obtained by predicting a branch instruction in an instruction pipeline using the branch prediction model during online branch prediction, and generate prediction result statistics based on the prediction result and actual instruction jump conditions;
[0145] A model training unit, used to perform online branch prediction training on a branch prediction training model using the prediction result statistical data to obtain a trained branch prediction training model; wherein, before performing online branch prediction training on the branch prediction training model, a weight of the branch prediction training model is the same as a weight of the branch prediction model;
[0146] A model updating unit is used to update the weight of the branch prediction model using the weight of the trained branch prediction training model when it is determined that the branch prediction result of the trained branch prediction training model is better than the branch prediction result of the branch prediction model.
[0147] In some implementations, the data acquisition unit is further configured to:
[0148] When the predicted branch instruction is obtained, classifying the predicted branch instruction;
[0149] In the case where it is determined that the predicted branch instruction is a complex branch, the predicted branch instruction is input into the branch prediction model, so that the branch prediction model predicts the predicted branch instruction to obtain a prediction result.
[0150] In some implementations, the data acquisition unit is further configured to:
[0151] In the case where it is determined that the predicted branch instruction is a simple branch, the predicted branch instruction is input into a branch predictor so that the branch predictor predicts the predicted branch instruction to obtain a prediction result;
[0152] The prediction result output by the branch predictor is used to generate the prediction result statistics.
[0153] In some implementations, when the data acquisition unit acquires the predicted branch instruction, classifying the predicted branch instruction includes:
[0154] When a predicted branch instruction is obtained, the predicted branch instruction is input into a branch classifier so that the branch classifier classifies the predicted branch instruction.
[0155] In some implementations, the branch classifier includes a program counter, a saturation counter group, and an update module;
[0156] The branch classifier classifies the predicted branch instruction, including:
[0157] The program counter queries the classification status of the predicted branch instruction from the saturation counter group based on the address of the predicted branch instruction, and sends the queried classification status to the update module;
[0158] The update module obtains the classification status queried from the saturated counter group and the actual classification result of the predicted branch instruction, and updates the classification status corresponding to the predicted branch instruction stored in the saturated counter group using the queried classification status and the actual classification result.
[0159] In some implementations, the address of the predicted branch instruction includes the last k bits of the address of the predicted branch instruction, where k is a positive integer;
[0160] The saturation calculator group includes 2 kA saturation counter is provided, in which the classification of the branch instruction is represented by a 2-bit binary number.
[0161] In some implementations, the data acquisition unit is further configured to:
[0162] Inputting the historical information of the predicted branch instruction into the branch prediction model so that the branch prediction model predicts the jump direction of the predicted branch instruction;
[0163] Among them, the historical information of the predicted branch instruction includes the historical address of the branch path where the predicted branch instruction is located and the corresponding jump direction; the branch prediction model includes multiple convolutional neural network slices, each of the convolutional neural network slices is used to predict the jump direction of the branch instruction, and the jump direction of the predicted branch instruction is determined based on the jump direction predicted by each of the convolutional neural network slices.
[0164] In some implementations, the data acquisition unit inputs historical information of predicted branch instructions into a pre-trained branch prediction model, including:
[0165] Based on the historical information of the predicted branch instruction, generate a plurality of historical information sets; wherein the number of the historical information sets is equal to the number of the convolutional neural network slices, and the historical information sets include historical information of a specific length of the predicted branch instruction;
[0166] Each historical information set is input one-to-one into each convolutional neural network slice of the pre-trained branch prediction model.
[0167] In some implementations, the branch prediction model includes five convolutional neural network slices; based on the historical information of the predicted branch instruction, multiple historical information sets are generated, including:
[0168] Based on the history information of the predicted branch instruction, generating a first history information set, a second history information set, a third history information set, a fourth history information set and a fifth history information set;
[0169] The first history information set includes 10 consecutive history addresses extracted from the address of the predicted branch instruction and along the branch path where the predicted branch instruction is located, and the corresponding jump directions;
[0170] The second history information set includes 20 consecutive history addresses extracted from the address of the predicted branch instruction and forward along the branch path where the predicted branch instruction is located, and the corresponding jump directions;
[0171] The third history information set includes 30 consecutive history addresses extracted from the address of the predicted branch instruction and forward along the branch path where the predicted branch instruction is located, and the corresponding jump directions;
[0172] The fourth history information set includes 50 consecutive history addresses extracted from the address of the predicted branch instruction and forward along the branch path where the predicted branch instruction is located, and the corresponding jump directions;
[0173] The fifth history information set includes 200 consecutive history addresses extracted from the address of the predicted branch instruction and forward along the branch path where the predicted branch instruction is located, and the corresponding jump directions.
[0174] In some implementations, the historical information of the predicted branch instruction includes the encoding matrix of the historical addresses of the branch path where the predicted branch instruction is located and the corresponding jump directions, and the encoding matrix includes the encoding of the historical addresses of the branch path where the predicted branch instruction is located and the corresponding jump directions.
[0175] In some implementations, the data acquisition unit is further configured to:
[0176] Binary encode each historical address of the branch path where the predicted branch instruction is located and the corresponding jump direction to obtain the code corresponding to each historical address;
[0177] The codes corresponding to the respective historical addresses of the branch path where the predicted branch instruction is located are concatenated to obtain the historical information of the predicted branch instruction.
[0178] In some implementations, the convolutional neural network slice includes a first convolutional layer, a first average pooling layer, a first fully connected layer, a second convolutional layer, a second average pooling layer, and an output layer, wherein the first convolutional layer includes an attention mechanism module;
[0179] The output layers of the multiple convolutional neural network slices are respectively connected to the second fully connected layer.
[0180] In some implementations, the number of input channels of the first convolution layer is 1, the number of output channels is 16, the convolution kernel size is 3×3, and the step size is 1; the pooling kernel size of the first average pooling layer is 2×2, and the step size is 1; the number of input channels of the second convolution layer is 16, the number of output channels is 4, the convolution kernel size is 3×3, and the step size is 1; the pooling kernel size of the second average pooling layer is 2×2, and the step size is 1.
[0181] In some implementations, the attention mechanism module includes an SE channel attention module.
[0182] In some implementations, the model training unit is further used to: train and obtain the branch prediction model based on the running process record of the test program in the setting database;
[0183] The training process of the branch prediction model includes:
[0184] Extracting global history information of each branch path from the running process record of the test program in the setting database, wherein the global history information includes each historical address of the branch path and the jump direction corresponding to each historical address;
[0185] Performing encoding processing on each historical information pair in the global historical information to obtain historical information encodings corresponding to each historical information pair; wherein the historical information pair includes a historical address and a jump direction corresponding to the historical address;
[0186] Multiple historical information codes corresponding to the same branch path are concatenated to obtain a historical information code matrix;
[0187] The historical information encoding matrix is input into a pre-built branch prediction model, and jump direction prediction training is performed on the branch prediction model.
[0188] In some implementations, encoding the historical information pair includes:
[0189] Performing one-bit binary quantization on the jump direction in the historical information pair to obtain a jump direction code, and performing binary quantization on the historical address in the historical information pair to obtain a historical address code;
[0190] Shift the historical address code left by one position, and use the jump direction code to fill the empty position after the shift;
[0191] The numerical value corresponding to the last N bits of the padded historical address code is obtained as the historical information code of the historical information pair, where N is a positive integer.
[0192] The branch prediction device provided in this embodiment belongs to the same application concept as the branch prediction method provided in the above embodiments of this application, and can execute the branch prediction method provided in any of the above embodiments of this application, and has the corresponding functional modules and beneficial effects of the execution method. For technical details not fully described in this embodiment, please refer to the specific processing content of the branch prediction method provided in the above embodiments of this application, and will not be repeated here.
[0193] The functions implemented by the above data acquisition unit, model training unit and model updating unit can be implemented by the same or different processors respectively, and the embodiments of the present application are not limited thereto.
[0194] It should be understood that the units in the above devices can be implemented in the form of a processor calling software. For example, the device includes a processor, the processor is connected to a memory, and instructions are stored in the memory. The processor calls the instructions stored in the memory to implement any of the above methods or realize the functions of each unit of the device, wherein the processor can be a general-purpose processor, such as a CPU or a microprocessor, etc., and the memory can be a memory in the device or a memory outside the device. Alternatively, the units in the device can be implemented in the form of hardware circuits, and the functions of some or all units can be realized by designing the hardware circuits. The hardware circuit can be understood as one or more processors; for example, in one implementation, the hardware circuit is an ASIC, and the functions of some or all of the above units are realized by designing the logical relationship of the components in the circuit; for another example, in another implementation, the hardware circuit can be implemented by PLD, taking FPGA as an example, which can include a large number of logic gate circuits, and the connection relationship between the logic gate circuits is configured by the configuration file, so as to realize the functions of some or all of the above units. All units of the above devices can be implemented in the form of a processor calling software, or in the form of hardware circuits, or in part by a processor calling software, and the remaining part is implemented in the form of hardware circuits.
[0195] In an embodiment of the present application, a processor is a circuit with the ability to process signals. In one implementation, the processor may be a circuit with the ability to read and run instructions, such as a CPU, a microprocessor, a GPU, or a DSP; in another implementation, the processor may implement certain functions through the logical relationship of a hardware circuit, and the logical relationship of the hardware circuit is fixed or reconfigurable, such as a hardware circuit implemented by an ASIC or PLD, such as an FPGA. In a reconfigurable hardware circuit, the process of the processor loading a configuration document to implement the hardware circuit configuration can be understood as the process of the processor loading instructions to implement the functions of some or all of the above units. In addition, it can also be a hardware circuit designed for artificial intelligence, which can be understood as an ASIC, such as an NPU, TPU, DPU, etc.
[0196] It can be seen that each unit in the above device can be one or more processors (or processing circuits) configured to implement the above method, such as: CPU, GPU, NPU, TPU, DPU, microprocessor, DSP, ASIC, FPGA, or a combination of at least two of these processor forms.
[0197] In addition, all or part of the units in the above device can be integrated together, or can be implemented independently. In one implementation, these units are integrated together and implemented in the form of a SOC. The SOC may include at least one processor for implementing any of the above methods or implementing the functions of each unit of the device. The type of the at least one processor may be different, for example, including a CPU and an FPGA, a CPU and an artificial intelligence processor, a CPU and a GPU, etc.
[0198] Another embodiment of the present application further provides a branch prediction device, see Fig.10 As shown, the device includes:
[0199] Memory 200 and processor 210;
[0200] The memory 200 is connected to the processor 210 and is used to store programs;
[0201] The processor 210 is used to implement the branch prediction method disclosed in any of the above embodiments by running the program stored in the memory 200.
[0202] Specifically, the branch prediction device may further include: a bus, a communication interface 220 , an input device 230 and an output device 240 .
[0203] The processor 210, the memory 200, the communication interface 220, the input device 230 and the output device 240 are connected to each other via a bus.
[0204] A bus may include a pathway that transfers information between components of a computer system.
[0205] The processor 210 may be a general-purpose processor, such as a general-purpose central processing unit (CPU), a microprocessor, etc., or an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the program of the scheme of the present invention. It may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0206] The processor 210 may include a main processor, and may also include a baseband chip, a modem, and the like.
[0207] The memory 200 stores a program for executing the technical solution of the present invention, and may also store an operating system and other key services. Specifically, the program may include a program code, and the program code includes a computer operation instruction. More specifically, the memory 200 may include a read-only memory (ROM), other types of static storage devices that can store static information and instructions, a random access memory (RAM), other types of dynamic storage devices that can store information and instructions, a disk storage, a flash, and the like.
[0208] The input device 230 may include a device for receiving data and information input by a user, such as a keyboard, a mouse, a camera, a scanner, a light pen, a voice input device, a touch screen, a pedometer, or a gravity sensor.
[0209] Output device 240 may include devices that allow information to be output to a user, such as a display screen, printer, speaker, etc.
[0210] The communication interface 220 may include any transceiver or the like to communicate with other devices or communication networks, such as Ethernet, Radio Access Network (RAN), Wireless Local Area Network (WLAN), etc.
[0211] The processor 210 executes the program stored in the memory 200 and calls other devices, which can be used to implement each step of any branch prediction method provided in the above embodiments of the present application.
[0212] In addition to the above methods and devices, an embodiment of the present application may also be a computer program product, which includes computer program instructions, which, when executed by a processor, enable the processor to execute the steps of the branch prediction method described in any of the above embodiments of this specification.
[0213] The computer program product may be written in any combination of one or more programming languages to write program codes for performing the operations of the embodiments of the present application, including object-oriented programming languages, such as Java, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as an independent software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0214] In addition, an embodiment of the present application may also be a storage medium on which a computer program is stored, and the computer program is executed by a processor to execute the steps of the branch prediction method described in any of the above embodiments of this specification.
[0215] For the aforementioned method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the order of the actions described, because according to the present application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
[0216] It should be noted that each embodiment in this specification is described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same or similar parts between the embodiments can be referred to each other. For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0217] The steps in the methods of each embodiment of the present application can be adjusted in order, combined and deleted according to actual needs, and the technical features recorded in each embodiment can be replaced or combined.
[0218] The modules and sub-modules in the devices and terminals of the various embodiments of the present application can be combined, divided and deleted according to actual needs.
[0219] In the several embodiments provided in the present application, it should be understood that the disclosed terminals, devices and methods can be implemented in other ways. For example, the terminal embodiments described above are only schematic, for example, the division of modules or submodules is only a logical function division, and there may be other division methods in actual implementation, for example, multiple submodules or modules can be combined or integrated into another module, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms.
[0220] The modules or submodules described as separate components may or may not be physically separated, and the components of the modules or submodules may or may not be physical modules or submodules, that is, they may be located in one place, or they may be distributed on multiple network modules or submodules. Some or all of the modules or submodules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0221] In addition, each functional module or submodule in each embodiment of the present application may be integrated into one processing module, or each module or submodule may exist physically separately, or two or more modules or submodules may be integrated into one module. The above-mentioned integrated modules or submodules may be implemented in the form of hardware or in the form of software functional modules or submodules.
[0222] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0223] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly by hardware, software units executed by a processor, or a combination of the two. The software units may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0224] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0225] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A branch prediction method, characterized in that: include: In the process of performing online branch prediction using a branch prediction model, a prediction result obtained by predicting a branch instruction in an instruction pipeline using the branch prediction model is obtained, and based on the prediction result and actual instruction jump conditions, prediction result statistical data is generated; Performing branch prediction training on a branch prediction training model using the prediction result statistical data to obtain a trained branch prediction training model; wherein, before performing branch prediction training on the branch prediction training model, a weight of the branch prediction training model is the same as a weight of the branch prediction model; In the case where it is determined that the branch prediction result of the trained branch prediction training model is better than the branch prediction result of the branch prediction model, the weight of the branch prediction model is updated using the weight of the trained branch prediction training model.
2. The method according to claim 1, characterized in that The method further comprises: When the predicted branch instruction is obtained, classifying the predicted branch instruction; In the case where it is determined that the predicted branch instruction is a complex branch, the predicted branch instruction is input into the branch prediction model, so that the branch prediction model predicts the predicted branch instruction to obtain a prediction result.
3. The method according to claim 2, characterized in that The method further comprises: In the case where it is determined that the predicted branch instruction is a simple branch, the predicted branch instruction is input into a branch predictor so that the branch predictor predicts the predicted branch instruction to obtain a prediction result; The prediction result output by the branch predictor is used to generate the prediction result statistics.
4. The method according to claim 2, characterized in that: When a predicted branch instruction is obtained, the predicted branch instruction is classified, including: When a predicted branch instruction is obtained, the predicted branch instruction is input into a branch classifier so that the branch classifier classifies the predicted branch instruction.
5. The method according to claim 4, characterized in that The branch classifier includes a program counter, a saturation counter group, and an update module; The branch classifier classifies the predicted branch instruction, including: The program counter queries the classification status of the predicted branch instruction from the saturation counter group based on the address of the predicted branch instruction, and sends the queried classification status to the update module; The update module obtains the classification status queried from the saturated counter group and the actual classification result of the predicted branch instruction, and updates the classification status corresponding to the predicted branch instruction stored in the saturated counter group using the queried classification status and the actual classification result.
6. The method according to claim 5, characterized in that The address of the predicted branch instruction, including the last k bits of the address of the predicted branch instruction; The saturation calculator group includes 2 k A saturation counter is provided, in which the classification of the branch instruction is represented by a 2-bit binary number, and k is a positive integer.
7. The method according to any one of claims 1 to 6, characterized in that: The method further comprises: Inputting the historical information of the predicted branch instruction into the branch prediction model so that the branch prediction model predicts the jump direction of the predicted branch instruction; Among them, the historical information of the predicted branch instruction includes the historical address of the branch path where the predicted branch instruction is located and the corresponding jump direction; the branch prediction model includes multiple convolutional neural network slices, each of the convolutional neural network slices is used to predict the jump direction of the branch instruction, and the jump direction of the predicted branch instruction is determined based on the jump direction predicted by each of the convolutional neural network slices.
8. The method according to claim 7, characterized in that The historical information of the predicted branch instructions is input into the pre-trained branch prediction model, including: Based on the historical information of the predicted branch instruction, generate a plurality of historical information sets; wherein the number of the historical information sets is equal to the number of the convolutional neural network slices, and the historical information sets include historical information of a specific length of the predicted branch instruction; Each historical information set is input one-to-one into each convolutional neural network slice of the pre-trained branch prediction model.
9. The method according to claim 8, characterized in that The branch prediction model includes 5 convolutional neural network slices; Based on the historical information of the predicted branch instruction, multiple historical information sets are generated, including: Based on the history information of the predicted branch instruction, generating a first history information set, a second history information set, a third history information set, a fourth history information set and a fifth history information set; The first history information set includes 10 consecutive history addresses extracted from the address of the predicted branch instruction and along the branch path where the predicted branch instruction is located, and the corresponding jump directions; The second history information set includes 20 consecutive history addresses extracted from the address of the predicted branch instruction and along the branch path where the predicted branch instruction is located, and the corresponding jump directions; The third history information set includes 30 consecutive history addresses extracted from the address of the predicted branch instruction and forward along the branch path where the predicted branch instruction is located, and the corresponding jump directions; The fourth history information set includes 50 consecutive history addresses extracted from the address of the predicted branch instruction and forward along the branch path where the predicted branch instruction is located, and the corresponding jump directions; The fifth history information set includes 200 consecutive history addresses extracted from the address of the predicted branch instruction and forward along the branch path where the predicted branch instruction is located, and the corresponding jump directions.
10. The method according to claim 7, characterized in that The historical information of the predicted branch instruction includes the encoding matrix of each historical address of the branch path where the predicted branch instruction is located and the corresponding jump direction, and the encoding matrix includes the encoding of each historical address of the branch path where the predicted branch instruction is located and the corresponding jump direction.
11. The method according to claim 7, characterized in that The convolutional neural network slice includes a first convolutional layer, a first average pooling layer, a first fully connected layer, a second convolutional layer, a second average pooling layer and an output layer, wherein the first convolutional layer includes an attention mechanism module; The output layers of the multiple convolutional neural network slices are respectively connected to the second fully connected layer.
12. The method according to claim 11, characterized in that The number of input channels of the first convolution layer is 1, the number of output channels is 16, the convolution kernel size is 3×3, and the step size is 1; the pooling kernel size of the first average pooling layer is 2×2, and the step size is 1; the number of input channels of the second convolution layer is 16, the number of output channels is 4, the convolution kernel size is 3×3, and the step size is 1; the pooling kernel size of the second average pooling layer is 2×2, and the step size is 1.
13. The method according to any one of claims 1 to 6, characterized in that: The method further comprises: training the branch prediction model based on the running process record of the test program in the setting database; The training process of the branch prediction model includes: Extracting global history information of each branch path from the running process record of the test program in the setting database, wherein the global history information includes each historical address of the branch path and the jump direction corresponding to each historical address; Performing encoding processing on each historical information pair in the global historical information to obtain historical information encodings corresponding to each historical information pair; wherein the historical information pair includes a historical address and a jump direction corresponding to the historical address; Multiple historical information codes corresponding to the same branch path are concatenated to obtain a historical information code matrix; The historical information encoding matrix is input into a pre-built branch prediction model, and jump direction prediction training is performed on the branch prediction model.
14. A branch prediction device, characterized in that: include: A data acquisition unit is used to acquire a prediction result obtained by predicting a branch instruction in an instruction pipeline using the branch prediction model during online branch prediction, and generate prediction result statistics based on the prediction result and actual instruction jump conditions; A model training unit, used to perform online branch prediction training on a branch prediction training model using the prediction result statistical data to obtain a trained branch prediction training model; wherein, before performing online branch prediction training on the branch prediction training model, a weight of the branch prediction training model is the same as a weight of the branch prediction model; A model updating unit is used to update the weight of the branch prediction model using the weight of the trained branch prediction training model when it is determined that the branch prediction result of the trained branch prediction training model is better than the branch prediction result of the branch prediction model.
15. A branch prediction device, characterized in that: include: Memory and processor; The memory is connected to the processor and is used to store programs; The processor is used to implement the branch prediction method according to any one of claims 1 to 13 by running the program in the memory.
16. A computer program product, characterized in that The method comprises computer program instructions, which, when executed by a processor, cause the processor to perform the branch prediction method according to any one of claims 1 to 13.
