Code processing method and device, equipment, storage medium and program product
By using the error correction model to perform automated error detection and modification processing on hardware codes, and iteratively determining candidate codes, the problem of manual verification and error correction in the existing technology that is time-consuming and resource-consuming is solved, and efficient automatic code error correction is achieved.
Patent Information
- Application Number
- CN202411347652.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-26
- Publication Date
- 2025-01-24
AI Technical Summary
In the prior art, the verification and error correction process of hardware code mainly relies on manual labor, resulting in low degree of automation and time-consuming and resource-consuming.
By obtaining input data, including the first code, test platform files and design description files, the error correction model is used to detect and modify the code, and iteratively determine candidate codes with higher code quality until the second code after error correction is obtained .
It realizes the automation of the code verification and error correction process, saves development time and resources, accelerates the development process, and improves the code quality after error correction.
Smart Images

Figure CN119356679A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a code processing method, device, equipment, storage medium and program product, belonging to the technical field of automatic error correction of artificial intelligence computer programs. Background Art
[0002] During the hardware development process, it is usually necessary to develop hardware code according to the requirements of the target hardware to be designed as indicated by the design description file. The correctness of the developed hardware code is usually verified, and if there are code errors in the developed hardware code, error correction is performed to obtain code that meets the design requirements indicated by the design description file. The existing verification and error correction process for the code is usually handled manually, which makes the degree of automation of the code verification and error correction process low, which in turn leads to a large consumption of time and resources during the hardware development process. Summary of the invention
[0003] Purpose: In order to overcome the deficiencies in the prior art, the present invention provides a code processing method, device, equipment, storage medium and program product, which can realize the automation of the code verification and error correction process, save time and resources in the development process, and accelerate the development process.
[0004] Technical solution: To solve the above technical problems, the technical solution adopted by the present invention is:
[0005] On the one hand, an embodiment of the present application provides a code processing method, the method comprising:
[0006] Acquire input data; wherein the input data includes a first code, a test platform file, and a design description file, and the first code includes a register transfer level code generated based on the design description file;
[0007] Perform code error detection processing on the first code based on the test platform file to obtain an error detection report;
[0008] In a case where the error detection report indicates that no code error is detected, using the first code as a second code after error correction;
[0009] When the error detection report indicates that a code error is detected, performing code error correction processing on the first code based on the design description file and the error detection report by using an error correction model to obtain an intermediate code;
[0010] Determine a candidate code with higher code quality from the first code and the intermediate code;
[0011] The candidate code is used as a new first code, and the step of performing code error detection processing on the new first code is iteratively performed until a second code after error correction is obtained.
[0012] On the one hand, an embodiment of the present application provides a code processing device, the device comprising:
[0013] An acquisition unit, configured to acquire input data; wherein the input data includes a first code, a test platform file, and a design description file, and the first code includes a register transfer level code generated based on the design description file;
[0014] A processing unit, configured to perform code error detection processing on the first code based on the test platform file to obtain an error detection report;
[0015] The processing unit is further configured to use the first code as a second code after error correction if the error detection report indicates that no code error is detected;
[0016] The processing unit is further configured to, when the error detection report indicates that a code error is detected, perform code error correction processing on the first code based on the design description file and the error detection report through an error correction model to obtain an intermediate code;
[0017] The processing unit is further used to determine a candidate code with higher code quality from the first code and the intermediate code;
[0018] The processing unit is further configured to use the candidate code as a new first code and iteratively execute the step of performing code error detection processing on the new first code until an error-corrected second code is obtained.
[0019] In one aspect, an embodiment of the present application provides a computer device, the computer device including a communication interface, and the computer device further including:
[0020] A processor and a computer readable storage medium;
[0021] A computer-readable storage medium for storing a computer program;
[0022] The processor is used to run the computer program to implement the above code processing method.
[0023] On the one hand, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program, and the computer program is suitable for being loaded by a processor and executing the above-mentioned code processing method.
[0024] On the one hand, an embodiment of the present application provides a computer program product, which includes a computer program, and the computer program is suitable for being loaded by a processor and executing the above-mentioned code processing method.
[0025] Beneficial effect: In the embodiment of the present application, the first code to be corrected can be subjected to code error detection processing based on the test platform file to obtain an error detection report; when the error detection report indicates that no code error is detected, the first code is used as the second code after error correction; when the error detection report indicates that a code error is detected, the first code is subjected to code error modification processing based on the design description file and the error detection report through the error correction model to obtain an intermediate code; and then a candidate code with higher code quality can be determined from the first code and the intermediate code as a new first code, and the step of performing code error detection processing on the new first code is iteratively executed until the second code after error correction is obtained. Automatic iterative error correction of the code can be realized based on the code error detection processing and the code error modification processing, and the automation of the verification and error correction process of the code can be realized, saving time and resources in the development process and accelerating the development process. Moreover, the candidate code with higher code quality is determined from the first code and the intermediate code for iterative processing, which can improve the accuracy of the second code after error correction obtained by iterative error correction. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0027] Figure 1 It is a structural diagram of a code processing system provided in an embodiment of the present application;
[0028] Figure 2 It is a flowchart of a code processing method provided in an embodiment of the present application;
[0029] Figure 3 middle Figure 3 a is a schematic diagram of an error correction task prompt template provided in an embodiment of the present application;
[0030] Figure 3 middle Figure 3 b is a schematic diagram of a scoring task prompt template provided in an embodiment of the present application;
[0031] Figure 3 middle Figure 3 c is a schematic diagram of a code processing method executed based on a code processing device provided in an embodiment of the present application;
[0032] Figure 4 It is a flowchart of another code processing method provided in an embodiment of the present application;
[0033] Figure 5 middle Figure 5 a is a schematic diagram of another code processing method executed based on a code processing device provided in an embodiment of the present application;
[0034] Figure 5 middle Figure 5 b is a schematic diagram of determining a candidate code with higher code quality based on a data rollback mechanism provided by an embodiment of the present application;
[0035] Figure 6 is a structural diagram of a code processing device provided in an embodiment of the present application;
[0036] Figure 7 It is a structural diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0037] 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.
[0038] At the same time, in the description of the embodiments of the present application, the terms "first", "second", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance. Therefore, the features defined as "first" or "second" may explicitly or implicitly include one or more features.
[0039] Artificial Intelligence (AI) is a technology that studies and develops theories, methods, technologies and application systems for simulating, extending and expanding human intelligence. It attempts to understand the essence of intelligence and produce a new type of intelligent machine that can respond in a similar way to human intelligence. Artificial Intelligence technologies can include Computer Vision (CV), Speech Technology, Natural Language Processing (NLP) and Machine Learning. Learning, ML) / deep learning and other major directions; among them, machine learning technology is the core of artificial intelligence, and deep learning technology is a technology that uses deep neural network systems to perform machine learning. Machine learning technology and deep learning technology can include artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and teaching learning. The pre-training model (Pre-training model, PTM, also known as large model, basic model) developed based on deep learning technology is trained on massive unlabeled data. After fine-tuning, the pre-training model can be widely used in downstream tasks in various directions of artificial intelligence. Pre-training models can be divided into language models (such as GPT, BERT), visual models (such as V-MOE), speech models (such as VALL-E, ViT), multimodal models (such as ViBERT, Flamingo, Gato), etc. according to the data modality processed. Among them, multimodal models refer to models that establish feature representations of two or more data modalities. The fine-tuning technology of pre-training models can include supervised fine-tuning (Supervised Fine-Tuning, SFT), instruction fine-tuning (Instruction Tuning), parameter efficient fine-tuning (PEFT ) and other technologies.
[0040] The embodiment of the present application provides a code processing method based on artificial intelligence technology, which can realize automatic code error correction, save time and resource consumption in the verification and error correction process of the code, and accelerate the development process. The general principle of the code processing method is as follows: input data including a first code, a test platform file and a design description file can be obtained, and the first code is subjected to code error detection processing based on the test platform file to obtain an error detection report, wherein the first code includes a register transfer level code generated based on the design description file; when the error detection report indicates that no code error is detected, the first code is used as the second code after error correction; when the error detection report indicates that a code error is detected, the first code is subjected to code error modification processing based on the design description file and the error detection report through the error correction model to obtain an intermediate code, and a candidate code with higher code quality is determined from the first code and the intermediate code, and the candidate code is used as the new first code, and the steps of performing code error detection processing on the new first code are iteratively executed until the second code after error correction is obtained.
[0041] Among them, the first code may include any code to be corrected, for example, it may include hardware code or software code to be corrected; the design description file can be used to indicate the design requirements that the code needs to meet, for example, in the hardware or software development process, the design description file can be used to indicate the requirements of the target hardware or target software to be designed, and the first code can be generated based on the design description file, that is, the first code can be designed based on the requirements described in the design description file; optionally, the first code can be manually generated based on the requirements described in the design description file, or it can be automatically generated using a tool that can automatically generate code based on the requirements described in the design description file, and the embodiments of the present application are not limited; the test platform file may include a file that can be used to test the first code to detect whether there are errors in the code. The input of the first code and the expected output under the corresponding input can be defined in the test platform file, so that it is possible to determine whether there are errors in the first code by comparing whether the actual output of the first code under the corresponding input is the expected output. Further optionally, the first code may include a register transfer level code generated based on a design description file; wherein the register transfer level code is the RTL (Register Transfer Level) code in the hardware development process, the design description file is the Design specification, which can be used to indicate the design requirements that the RTL code needs to meet, for example, it can be used to indicate the functional requirements and performance requirements that the RTL code needs to meet, and the test platform file is the Testbench, which can include a file that can be used to simulate the RTL code to detect whether there are errors in the code, and specifically may include a golden reference for judging whether there are functional errors in the first code. For ease of explanation, the subsequent embodiments of this application are explained by taking the first code including the RTL code as an example. In a feasible implementation, the above-mentioned code processing method can be applied to a code error correction scenario, and the input data can be uploaded by a user with code error correction requirements.
[0042] In a feasible implementation, the above code processing method can be executed by a code processing device, which can be a terminal device or a server. Among them, the terminal device can include but is not limited to a mobile phone, a computer, a smart wearable device, a smart vehicle-mounted device, etc., which is not limited in the embodiments of this application; the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, big data and artificial intelligence platforms, etc., which is not limited in the embodiments of this application.
[0043] In another feasible implementation, the above code processing method can also be executed by any electronic device with computing power alone or in collaboration, and the present application embodiment does not limit this; for example, the above code processing method can also be executed by a code processing system including a terminal device and a server. Based on this, the present application embodiment also provides a code processing system, which can include a terminal device and a server; see Figure 1 , is a schematic diagram of the structure of a code processing system provided in an embodiment of the present application, Figure 1 In the code processing system shown, the terminal device may be indicated by 101, and the server may be indicated by 102; the terminal device 101 and the server 102 may be directly or indirectly connected to each other via wired or wireless communication, which is not limited in the present embodiment. Figure 1 When the code processing system shown is executed, the terminal device 101 can obtain input data; wherein the input data includes a first code, a test platform file and a design description file, and the first code includes a register transfer level code generated based on the design description file; code error detection processing is performed on the first code based on the test platform file to obtain an error detection report; when the error detection report indicates that no code error is detected, the first code is used as the second code after error correction; when the error detection report indicates that a code error is detected, the design description file, the error detection report and the first code are sent to the server 102 and the server 102 is requested to perform code error modification processing on the first code; the server 102 can perform code error modification processing on the first code based on the design description file and the error detection report through the error correction model to obtain an intermediate code, and return the intermediate code to the terminal device 101; the terminal device 101 can determine a candidate code with higher code quality from the first code and the intermediate code; the candidate code is used as a new first code, and the step of performing code error detection processing on the new first code is iteratively performed until the second code after error correction is obtained. Further, the terminal device 101 can output the second code after error correction to feedback to the user.
[0044] For example, the above code processing method is Figure 1When the code processing system shown is executed, the terminal device 101 can obtain input data, wherein the input data includes a first code, a test platform file, and a design description file, and the first code includes a register transfer level code generated based on the design description file; the terminal device 101 can send the input data to the server 102 and request the server 102 to perform code error correction on the first code in the input data. After receiving the input data, the server 102 can perform a process of performing code error detection processing on the first code based on the test platform file to obtain a corrected second code, and return the corrected second code to the terminal device 101. Further, after receiving the corrected second code, the terminal device 101 can output the corrected second code to feed back to the user.
[0045] Understandably, Figure 1 The servers or terminal devices in the illustrated code processing system do not constitute a limitation on the embodiments of the present application, that is, the number of servers, the types of servers, the number of terminal devices, the types of terminal devices, etc., do not affect the overall implementation of the technical solution in the embodiments of the present application, and can all be regarded as equivalent replacements or derivatives of the technical solution claimed for protection in the embodiments of the present application. For the sake of convenience, the subsequent embodiments of the present application take the code processing method executed by the code processing device as an example.
[0046] In the specific implementation of this application, user-related data (such as the first code, test platform files, etc.) is involved. When the embodiment of this application is used, the user's permission or consent is required, and the collection, use and processing of the relevant data must comply with local laws, regulations and standards.
[0047] Based on the above description, the following is an introduction to the relevant process of the code processing method provided in the embodiment of the present application; see Figure 2 , Figure 2 : is a flowchart of a code processing method provided in an embodiment of the present application. The code processing method can be executed by a code processing device. The code processing method can at least include the following steps S201 to S206:
[0048] S201, obtaining input data; wherein the input data includes a first code, a test platform file, and a design description file.
[0049] Among them, the first code may include any code to be corrected, for example, it may include hardware code or software code to be corrected; the design description file may be used to indicate the design requirements that the code needs to meet, for example, in the process of hardware or software development, the design description file may be used to indicate the requirements of the target hardware or target software to be designed, the first code may be generated based on the design description file, and the test platform file may include a file that can be used to test the first code to detect whether there is an error in the code; further optionally, the first code may include register transfer level code (i.e., RTL code, also known as Design under Test, referred to as DUT) generated based on the design description file, the design description file (i.e., Design specification) may be used to indicate the design requirements that the RTL code needs to meet, and the test platform file (i.e., Testbench) may include a file that can be used to simulate the RTL code to detect whether there is an error in the code. For the sake of convenience, the subsequent embodiments of this application are described by taking the first code including the RTL code as an example.
[0050] S202: Perform code error detection processing on the first code based on the test platform file to obtain an error detection report.
[0051] In a feasible implementation manner, the code processing device performs code error detection processing on the first code in order to use the first code as the second code after error correction when no code error is detected, and to perform code error correction on the first code after the code error is detected only when a code error is detected. Specifically, when the code processing device performs code error detection processing on the first code, it can detect whether the first code has syntax errors and functional errors, and determine that a code error is detected when the syntax error or functional error is detected in the first code, and determine that no code error is detected when the syntax error and functional error are not detected in the first code; wherein, syntax errors may include: errors that exist when the code does not conform to the writing specifications (including formal structures) of the programming language used by the code, for example, when the first code is written in Verilog language, when the first code does not conform to the writing specifications (including formal specifications) of the Verilog language, it is determined that the first code has syntax errors; functional errors may include: other errors that affect the code in addition to syntax errors, for example, semantic errors, logical errors, timing errors, etc., for example, when the actual output of the first code under a specified input is not the expected output that the first code should obtain under the specified input, it can be determined that the first code has a functional error.
[0052] Further optionally, syntax errors can be detected by code compilation, and functional errors can be detected by code simulation. Based on this, in a feasible implementation, the code processing device performs code error detection processing on the first code based on the test platform file, and in the process of obtaining the error detection report, the following steps can be specifically performed: through the compiler, the first code is compiled to detect syntax errors in the first code, and a compilation report is obtained; if the compilation report indicates that a syntax error is detected, the compilation report is used as an error detection report; if the compilation report indicates that no syntax error is detected, the first code is simulated by the simulator based on the test platform file to detect functional errors in the first code, and a simulation report is obtained; if the simulation report indicates that a functional error is detected, an error detection report is constructed based on the compilation report and the simulation report.
[0053] Optionally, the compiler and simulator can be selected according to specific needs, which is not limited in the embodiments of the present application. For example, the simulator can be a simulator, a waveform analysis tool, a timing analysis tool, etc.; the compilation report can indicate whether the compiled code has syntax errors, and the specific syntax errors when there are syntax errors (for example, it can indicate that a certain line of the compiled code does not meet the writing specifications); the simulation report can indicate whether the simulated code has functional errors, and the specific functional errors when there are functional errors (for example, it can indicate that the simulated code cannot obtain the expected output under a certain specified input). In a feasible implementation, when the compilation report indicates that no syntax errors are detected and the simulation report indicates that a functional error is detected, when the code processing device constructs an error detection report based on the compilation report and the simulation report, it can choose to use both the compilation report and the simulation report as the error detection report, or it can choose to use only the simulation report indicating the functional error as the error detection report. In a feasible implementation, when the compilation report indicates that no syntax errors are detected and the simulation report indicates that no functional errors are detected, the error detection report should indicate that no code errors are detected. Optionally, the code processing device can construct an error detection report containing information indicating that no code errors are detected, wherein the format of the information indicating that no code errors are detected can be set according to specific needs, for example, it can be a text format, an audio format, a video format, etc., which is not limited by the embodiments of the present application; optionally, the code processing device can also choose to use the compilation report and the simulation report together as an error detection report, indicating that no code errors are detected.
[0054] S203: When the error detection report indicates that no code error is detected, use the first code as the second code after error correction.
[0055] S204, when the error detection report indicates that a code error is detected, the first code is subjected to code error correction processing based on the design description file and the error detection report by using an error correction model to obtain an intermediate code.
[0056] Among them, since the error detection report can indicate errors existing in the first code (including one or more of syntactic errors or functional errors), when the code processing device performs code error modification processing on the first code, it can refer to the requirements indicated by the design description file and the errors indicated by the error detection report to make modifications, and modify the errors indicated by the error detection report in the first code so that the modified code still meets the requirements indicated by the design description file; in the code error modification processing process, in order to prevent the error correction model from changing the code on a large scale, resulting in the correct code being modified or even the code logic being changed, the code error modification processing process should minimize changes to the original code.
[0057] In a feasible implementation, the model type of the error correction model can be a large language model (LLM); based on this, the code processing device uses the error correction model to modify the first code based on the design description file and the error detection report. In the process of obtaining the intermediate code, the following steps can be performed: obtaining an error correction task prompt template; the error correction task prompt template includes an error correction task data filling field; the design description file, the error detection report and the first code are filled into the error correction task data filling field to obtain an error correction task prompt (i.e., Prompt); the error correction task prompt is input into the error correction model, and the error correction model uses the design description file and the error detection report in the error correction task prompt to modify the first code in the error correction task prompt to obtain the intermediate code. The error correction task prompt template can be used to prompt the error correction model to modify the provided code according to the provided design description file and error detection report. The error correction task prompt template can be designed according to specific needs, and the embodiments of the present application are not limited thereto; taking the error correction model supporting code error modification processing for codes written in the Verilog language in the field of integrated circuit (IC) design as an example, please refer to Figure 3a, is a schematic diagram of a correction task prompt template provided by an embodiment of the present application, wherein the correction task data filling field may include a design description file filling field (as shown by mark 301), an error detection report filling field (as shown by mark 303) and a code filling field (as shown by mark 302), and the code processing device may fill the design description file into the design description file filling field as shown by mark 301, fill the error detection report into the error detection report filling field as shown by mark 303, and fill the first code into the code filling field as shown by mark 302 to obtain the correction task prompt; it is worth noting that Figure 3 a is only an exemplary description of the error correction task prompt template and is not a limitation. In actual application, the error correction task prompt template can be designed according to specific needs, such as using other languages to describe the error correction task prompt template, or adjusting the text content of the error correction task prompt template.
[0058] In a feasible implementation, when the model type of the error correction model is a large language model, the error correction model can be obtained by fine-tuning the pre-trained large language model, and the fine-tuning strategy can be selected according to specific needs, for example, supervised fine-tuning (Supervised Fine-Tuning, SFT), instruction fine-tuning (Instruction Tuning), parameter efficient fine-tuning (PEFT), etc. can be selected; for example, in a hardware development scenario, the error correction model that needs to be fine-tuned can perform code error correction processing on the code written in the Verilog language, then the relevant standards of the Verilog language (such as the Verilog-2001 standard), RTL code examples (such as HDLBits, Verilog-G, RTL coding guidelines, etc.) and error knowledge (including grammatical error knowledge and functional error knowledge) can be used to fine-tune the pre-trained large language model (such as SFT). It can be known that the process of fine-tuning to obtain the error correction model can also be performed by other electronic devices, and the embodiments of the present application are not limited.
[0059] In a feasible implementation, the model type of the error correction model can also be selected from other neural network models, deep learning models, etc., which are not limited by the embodiments of the present application. In a feasible implementation, the error correction model can be obtained by the code processing device using training data to train the initial error correction model, and the training data may include a reference design description file, a reference test platform file, a reference first code, and a reference intermediate code, wherein the reference first code may be a code containing a code error generated according to the reference design description file, and the reference intermediate code may be a code that does not contain a code error generated according to the reference design description file (for example, a reference intermediate code that does not contain a code error can be generated according to the reference design description file, and a code error is inserted into the reference intermediate code to obtain a reference first code), and the reference test platform file can be used to indicate the error contained in the reference first code; the code processing device can input the reference design description file, the reference test platform file, and the reference first code into the initial error correction model, and the initial error correction model can perform code error modification processing on the reference first code based on the reference design description file and the reference error detection report to obtain a predicted intermediate code, and adjust the model parameters of the initial error correction model to reduce the difference between the predicted intermediate code and the reference intermediate code as the training target to train the error correction model. Optionally, the initial error correction model may also be a pre-trained model, and the above model training process is the fine-tuning process.
[0060] S205, determining a candidate code with higher code quality from the first code and the intermediate code.
[0061] In a feasible implementation, the purpose of determining a candidate code with higher code quality from the first code and the intermediate code is to select a candidate code with higher code quality for iterative processing, that is, to select a candidate code with higher code quality for iterative error correction to obtain a second code after error correction, which can avoid the problem of poor quality of the second code after error correction obtained by the final iterative error correction when subsequent iterative error correction is performed on the basis of a code with lower code quality. That is, it can effectively deal with abnormal situations such as iterative processing still being performed when the error correction model performs code error modification processing resulting in lower code quality. That is, selecting a candidate code with higher code quality for iterative error correction can improve the accuracy of the second code after error correction obtained by the iterative error correction.
[0062] In a feasible implementation manner, when the code processing device determines a candidate code with higher code quality from the first code and the intermediate code, it can: perform quality scoring processing on the intermediate code based on the design description file and the first code through a scoring model to obtain a scoring value; wherein the scoring value is positively correlated with the code quality of the intermediate code relative to the first code; if the scoring value is greater than or equal to a scoring threshold, the intermediate code is used as a candidate code with higher code quality; otherwise, the first code is used as a candidate code with higher code quality. The scoring value is positively correlated with the code quality of the intermediate code relative to the first code. In other words, the scoring model can refer to the requirements indicated by the design description file, compare the first code and the intermediate code, and obtain a scoring value that can be used to indicate the code quality of the intermediate code relative to the first code. The higher the code quality of the intermediate code relative to the first code, the higher the scoring value, and the lower the code quality of the intermediate code relative to the first code, the lower the scoring value. Based on this, the code processing device can use the intermediate code as a candidate code with higher code quality when the scoring value is greater than or equal to the scoring threshold; otherwise, use the first code as a candidate code with higher code quality. The scoring range of the scoring model can be set according to specific requirements, and the corresponding scoring value obtained based on the scoring model should be within the scoring range of the scoring model. For example, the scoring range of the scoring model can be set to 0 to 100, or to 0 to 10, and so on. The corresponding scoring threshold can be set based on the scoring range of the scoring model. For example, when the scoring range of the scoring model is set to 0 to 100, the scoring threshold can be set to 50. For example, when the scoring range of the scoring model is set to 0 to 100, the scoring threshold can be set to 6.
[0063] In a feasible implementation, the model type of the scoring model can be a large language model; based on this, the code processing device performs quality scoring processing on the intermediate code based on the design description file and the first code through the scoring model. In the process of obtaining the scoring value, the following steps can be performed: obtaining a scoring task prompt template; the scoring task prompt template includes a scoring task data filling field; filling the design description file, the first code and the intermediate code into the scoring task data filling field to obtain a scoring task prompt (i.e., Prompt); inputting the scoring task prompt into the scoring model, and performing quality scoring processing on the intermediate code in the scoring task prompt based on the design description file and the first code in the scoring task prompt through the scoring model to obtain a scoring value. The scoring task prompt template can be used to prompt the requirements indicated by the scoring model reference design description file, compare the first code and the intermediate code, and obtain a score value that can be used to indicate the code quality of the intermediate code relative to the first code within the scoring range of the scoring model. The scoring task prompt template can be designed according to specific needs, and the embodiments of the present application are not limited thereto; taking the scoring model supporting the quality scoring of codes written in the Verilog language in the field of integrated circuit (IC) design as an example, for example, see Figure 3 b, is a schematic diagram of a scoring task prompt template provided by an embodiment of the present application, wherein the scoring task data filling field may include a design description file filling field (as indicated by the mark 311), a first code filling field (as indicated by the mark 312) and an intermediate code filling field (as indicated by the mark 313), and the code processing device may fill the design description file into the design description file filling field as indicated by the mark 311, fill the first code into the first code filling field as indicated by the mark 312, and fill the intermediate code into the intermediate code filling field as indicated by the mark 313, to obtain a scoring task prompt; it is worth noting that Figure 3 b is only an exemplary description of the scoring task prompt template and is not a limitation. In actual application, the scoring task prompt template can be designed according to specific needs, such as using other languages to describe the scoring task prompt template, or adjusting the text content of the scoring task prompt template, etc. In the case where the model type of the scoring model is a large language model, the scoring model can be obtained by fine-tuning the pre-trained large language model, and the fine-tuning strategy can be selected according to specific needs, for example, supervised fine-tuning (Supervised Fine-Tuning, SFT), instruction fine-tuning (Instruction Tuning), parameter efficient fine-tuning (PEFT), etc. It can be known that the process of fine-tuning to obtain the scoring model can also be performed by other electronic devices, and the embodiments of the present application are not limited.
[0064] In a feasible implementation, the model type of the scoring model may also be selected from other neural network models, deep learning models, etc., which are not limited by the embodiments of the present application. In a feasible implementation, the scoring model may be obtained by the code processing device using training data to train the initial scoring model, and the training data may include a sample design description file, a sample first code, a sample intermediate code, and a sample scoring value, wherein the sample first code and the sample intermediate code may be different codes generated according to the sample design description file, and the sample scoring value may be used to indicate the code quality of the sample intermediate code relative to the sample first code; the code processing device may input the sample design description file, the sample first code, and the sample intermediate code into the initial scoring model, and the initial scoring model may perform quality scoring processing on the sample intermediate code based on the sample design description file and the sample first code to obtain a predicted scoring value, and adjust the model parameters of the initial scoring model to reduce the difference between the predicted scoring value and the sample scoring value as the training goal, so as to train and obtain the scoring model. Optionally, the initial scoring model may also be a pre-trained model, and the above-mentioned model training process is a fine-tuning process. Optionally, the sample design description file, sample first code and sample intermediate code used in the scoring model training process may be consistent with the reference design description file, reference first code and reference intermediate code used in the error correction model training process, or may be inconsistent, and the embodiments of the present application are not limited thereto.
[0065] In another feasible implementation, when the code processing device determines a candidate code with higher code quality from the first code and the intermediate code, it can also: perform quality scoring on the first code based on the design description file to obtain a first scoring value, and perform quality scoring on the intermediate code based on the design description file to obtain a second scoring value; if the difference between the second scoring value and the first scoring value is greater than or equal to a difference threshold, the intermediate code is used as a candidate code with higher code quality; otherwise, the first code is used as a candidate code with higher code quality. Optionally, the first scoring value and the second scoring value should be within a specified scoring range, and the specified scoring range can be set according to specific needs, for example, the specified scoring range can be set to 0 to 100, or to 0 to 10, etc.; Optionally, the difference between the second scoring value and the first scoring value can be represented by the difference between the second scoring value and the first scoring value, or by the ratio between the second scoring value and the first scoring value, etc., which is not limited in the embodiments of the present application; Optionally, the difference threshold can be set according to specific needs, which is not limited in the embodiments of the present application, for example, when the specified scoring range is set to 0 to 100, and the difference between the second scoring value and the first scoring value is represented by the difference between the second scoring value and the first scoring value, the difference threshold can be set to a score between 0 and 100 according to specific needs, for example, the difference threshold can be set to 1, 10, 20, etc. Optionally, when the code processing device performs quality scoring on the first code based on the design description file to obtain a first score value, and performs quality scoring on the intermediate code based on the design description file to obtain a second score value, a tool or model with corresponding functions can be used for implementation. The model used can be one trained according to the requirements or an existing model, and the embodiment of the present application does not limit this.
[0066] In another feasible implementation, when the code processing device determines a candidate code with higher code quality from the first code and the intermediate code, it can also: input the design description file, the first code and the intermediate code into the quality assessment model, and use the quality assessment model to perform quality assessment on the first code and the intermediate code based on the design description file to obtain a candidate code with higher code quality. Optionally, the quality assessment model can use a large language model; based on this, the quality assessment task prompt (i.e., Prompt) used by the large language model when performing model reasoning can be obtained by filling the design description file, the first code and the intermediate code into the quality assessment task prompt template; wherein the quality assessment task prompt template can be used to prompt the large language model (i.e., the quality assessment model) to refer to the requirements indicated by the design description file, compare the first code and the intermediate code, and select a candidate code with higher code quality. The scoring task prompt template can be designed according to specific requirements, and the embodiment of the present application is not limited.
[0067] S206, taking the candidate code as a new first code, and iteratively executing the step of performing code error detection processing on the new first code until a second code after error correction is obtained.
[0068] In a feasible implementation manner, the code processing method proposed in the embodiment of the present application may be executed by a code processing device deployed in a code processing device, and the code processing device may be a computer program; see Figure 3 c, is a schematic diagram of a code processing method executed by a code processing device provided in an embodiment of the application, Figure 3 The code processing device shown in c may include an error detection module, an error correction module, a code selection module and a condition determination module. The error detection module may be used to perform error detection processing on the code, the error correction module may be used to perform code error correction processing on the code, the code selection module may be used to determine a code with higher code quality from two codes, and the condition determination module may be used to determine whether the iteration is terminated. The code processing device is based on Figure 3 When the code processing device shown in c executes the code processing method, the input data of the code processing device includes the first code, the test platform file and the design description file; the code processing device can obtain input data, and the input data includes the first code, the test platform file and the design description file; the first code and the test platform file are sent to the error detection module, the error detection module can perform code error detection processing on the first code based on the test platform file to obtain an error detection report, and the conditional judgment module can use the first code as the second code after error correction and output it when it is determined that the error detection report indicates that no code error is detected, and the conditional judgment module can use the error detection report to indicate that a code error is detected, and the design description file, the error detection report and the first code are sent to the error correction module; the error correction module can perform code error modification processing on the first code based on the design description file and the error detection report through the error correction model to obtain an intermediate code, and the first code and the intermediate code are sent to the code selection module; the code selection module can determine a candidate code with higher code quality from the first code and the intermediate code; the candidate code is sent to the error detection module as a new first code, and the step of performing code error detection processing on the new first code is iteratively executed until the second code after error correction is obtained.
[0069] In the embodiment of the present application, the first code to be corrected can be subjected to code error detection processing based on the test platform file to obtain an error detection report; when the error detection report indicates that no code error is detected, the first code is used as the second code after error correction; when the error detection report indicates that a code error is detected, the first code is subjected to code error modification processing based on the design description file and the error detection report through the error correction model to obtain an intermediate code; and then a candidate code with higher code quality can be determined from the first code and the intermediate code as a new first code, and the step of performing code error detection processing on the new first code is iteratively executed until the second code after error correction is obtained. Automatic iterative error correction of the code can be realized based on the code error detection processing and the code error modification processing, and the automation of the verification and error correction process of the code can be realized, saving time and resources in the development process and accelerating the development process. Moreover, the candidate code with higher code quality is determined from the first code and the intermediate code for iterative processing, which can improve the accuracy of the second code after error correction obtained by iterative error correction.
[0070] Based on the above description, this application embodiment provides another code processing method; see Figure 4 , Figure 4 4 is a flowchart of another code processing method provided in an embodiment of the present application. The code processing method can be executed by a code processing device. The code processing method can at least include the following steps S401 to S408:
[0071] S401, obtaining input data; wherein the input data includes a first code, a test platform file, and a design description file; wherein the first code includes a register transfer level code generated based on the design description file. S402, performing code error detection processing on the first code based on the test platform file to obtain an error detection report. S403, when the error detection report indicates that no code error is detected, using the first code as the second code after error correction. S404, when the error detection report indicates that a code error is detected, obtaining the number of iterations. S405, when the number of iterations reaches a number threshold, using the first code as the second code after error correction. S406, when the number of iterations does not reach the number threshold, triggering the execution of a step of performing code error correction processing on the first code based on the design description file and the error detection report through an error correction model to obtain an intermediate code. S407, determining a candidate code with higher code quality from the first code and the intermediate code. S408, using the candidate code as a new first code, and iteratively executing the step of performing code error detection processing on the new first code until the second code after error correction is obtained.
[0072] Among them, steps S401 to S408 are similar to the steps in the above-mentioned steps S201 to S206, and are not repeated here; in the case of detecting a code error, further determining whether the iteration is terminated based on the number of iterations can prevent the iteration process from being unable to exit when multiple rounds of iterations cannot correct all errors in the code; further optionally, after obtaining the second code after error correction under the iteration stop condition based on the detection of a code error but the number of iterations reaching the number threshold, when outputting the second code after error correction, a modification prompt can be output to prompt the user to check the second code after error correction, and optionally, the specific content and specific format of the modification prompt can be set according to specific needs, for example, the specific format of the modification prompt can be set to text format, audio format, video format, etc., and the specific content of the modification prompt in text format can be, for example, "This modification has been made with the greatest effort, please check whether the modification is correct"; further optionally, the code processing device can also output an error detection report to prompt the user that the second code after error correction still has errors, for example, the corresponding modification prompt can be "This modification has been made with the greatest effort but some errors still exist, please check in conjunction with the error detection report".
[0073] In a feasible implementation, the following method is used as an example in which the code processing device determines a candidate code with higher code quality from the first code and the intermediate code: the intermediate code is scored based on the design description file and the first code through a scoring model to obtain a scoring value. If the scoring value is greater than or equal to a scoring threshold, the intermediate code is used as a candidate code with higher code quality; otherwise, the first code is used as a candidate code with higher code quality. This embodiment of the application proposes another code processing device. Please refer to Figure 5 a, a schematic diagram of another code processing method executed based on a code processing device provided in an embodiment of the application; Figure 5 The code processing device (also called processing framework Framework) shown in a may include an error detection module (also called toolchain Toolchain), an error correction module (also called DebugAgent), a code selection module and a conditional judgment module, wherein the error detection module may be used to perform error detection processing on the code, the error correction module may be used to perform code error correction processing on the code, the code selection module may be used to determine a code with higher code quality from two codes, and the conditional judgment module may be used to determine whether the iteration is terminated; further, the code selection module may include a scoring module (also called Scorer Agent) and a storage module (also called Code Repo), the scoring module may be used to perform quality scoring processing on the code, and the storage module may be used to store the code in the iteration process and the score value corresponding to the code.
[0074] Take the error correction model and scoring model as the model type, and select SFT as the fine-tuning strategy as an example; the code processing device is based on Figure 5 When the code processing device shown in a executes the code processing method, the input data of the code processing device includes the first code, the test platform file and the design description file. The code processing device can obtain input data, and the input data includes the first code, the test platform file and the design description file (i.e. Figure 5 a). The first code and the test platform file are input into the error detection module, and the error detection module can perform code error detection processing on the first code based on the test platform file to obtain an error detection report. When the conditional judgment module determines that the error detection report indicates that no code error is detected, the first code can be used as the second code after error correction and output. When the conditional judgment module determines that the error detection report indicates that a code error is detected, the design description file, the error detection report, and the first code are input into the error correction module (i.e. Figure 5 a). The error correction module can use the error correction model to perform code error correction processing on the first code based on the design description file and the error detection report to obtain an intermediate code. The first code and the intermediate code are input into the scoring module (i.e. Figure 5 a). The scoring module can use the scoring model to perform quality scoring on the intermediate code based on the design description file and the first code to obtain a scoring value, and the intermediate code and the scoring value of the intermediate code can be sent to the storage module for storage (i.e. Figure 5 a). The storage module may use the intermediate code as a candidate code with higher code quality if the score value of the intermediate code is greater than or equal to the score threshold, otherwise use the first code as a candidate code with higher code quality, and input the candidate code as a new first code into the error detection module, so that the step of performing code error detection processing on the new first code can be iteratively executed until the error-corrected second code (i.e. Figure 5 Step 5 in a); Optionally, the first code can be stored in a storage module after being acquired.
[0075] In a feasible implementation, before the code processing device determines the candidate code with higher code quality from the first code and the intermediate code, it can also detect whether the intermediate code is complete. If the intermediate code is incomplete, the first code is used as the candidate code with higher code quality. If the intermediate code is complete, it triggers the execution of the step of determining the candidate code with higher code quality from the first code and the intermediate code. Optionally, the mechanism of using the code before and after the code error correction processing by the error correction model as the candidate code with higher code quality can be called a data rollback mechanism. Based on Figure 5 a, see Figure 5b, a schematic diagram of a method for determining a candidate code with higher code quality based on a data rollback mechanism provided in an embodiment of the present application; the input of the code selection module is the code (such as an intermediate code) obtained by the error correction module, and the output of the code selection module is a candidate code with higher code quality. Specifically, taking the nth iteration process as an example, the code selection module can obtain the code obtained by the error correction module (i.e., the intermediate code generated by the nth iteration), and detect whether the intermediate code generated by the nth iteration is complete; if it is incomplete, a data rollback mechanism trigger instruction is sent to the storage module, so that the storage module can trigger the data rollback mechanism to use the first code required for the nth iteration (i.e., the candidate code (with higher code quality) generated by the n-1th iteration) as the candidate code (with higher code quality) generated by the nth iteration; if it is incomplete, the candidate code (with higher code quality) generated by the n-1th iteration (i.e., the first code required for the nth iteration) and the intermediate code generated by the nth iteration are input into the scoring module (corresponding to Figure 5 b) Step 1). The scoring module can use the scoring model to perform quality scoring on the intermediate code generated by the nth iteration based on the design description file and the candidate code (with higher code quality) generated by the n-1th iteration (i.e., the first code required to be used in the nth iteration) to obtain a scoring value. The intermediate code and its scoring value can be sent to the storage module for storage (corresponding to Figure 5 b) Step 2). The storage module can determine the candidate code with higher code quality (generated in the nth iteration) based on the score value of the intermediate code.
[0076] In an embodiment of the present application, code error detection processing can be performed on the first code to be corrected based on the test platform file to obtain an error detection report; when the error detection report indicates that no code error is detected, the first code is used as the second code after error correction; when the error detection report indicates that a code error is detected, code error modification processing is performed on the first code based on the design description file and the error detection report through the error correction model to obtain an intermediate code; and then a candidate code with higher code quality can be determined from the first code and the intermediate code as a new first code, and the step of performing code error detection processing on the new first code is iteratively executed until the second code after error correction is obtained. Automatic iterative error correction of the code can be achieved based on code error detection processing and code error modification processing, and the automation of the code verification and error correction process can be realized, which saves time and resources in the development process and accelerates the development process; the adoption of an iterative processing mechanism can effectively deal with the situation where a single code error correction is unsuccessful and improve the accuracy of code error correction, and based on the data rollback mechanism, candidate codes with higher code quality are determined from the first code and the intermediate code for iterative processing, which can improve the accuracy of the second code after error correction obtained by iterative error correction; in other words, the embodiment of the present application proposes that the code repair rate can be improved through an iterative algorithm, and by setting the iteration threshold and exception handling of the iterative algorithm, etc., the model modification code is improved in reducing the error rate and improving the design quality.
[0077] In an optional implementation, taking the first code as the RTL design code, the error correction model using the large language model, and the scoring model using the large language model as an example, the optional implementation process of the code processing method of the present invention is described:
[0078] The present invention realizes automatic error correction of hardware design through an iterative method. Each iteration is divided into four pipeline stages, namely step 1 to step 4, and step 0 is an initialization stage. The iteration will terminate and return the last modification result when there is no error or the threshold of the maximum number of iterations is reached.
[0079] Step 0: Get user input files (i.e. the above input data). Input files include: design description files, RTL design codes and test platform files.
[0080] Step 1: The RTL design code of the input file and the test platform file will be processed in the compiler and simulator respectively, wherein the RTL design code is compiled by the compiler, and the compiler will detect whether there are syntax errors therein and obtain a compilation report; if the compilation report indicates that a syntax error is detected, the compilation report is used as an error detection report; if the compilation report indicates that no syntax error is detected, the RTL design code is simulated based on the test platform file through the simulator to detect functional errors in the RTL design code and obtain a simulation report; if the simulation report indicates that a functional error is detected, an error detection report is constructed based on the compilation report and the simulation report.
[0081] If no error is detected, the entire process stops and exits, and the code is directly output as the result. If an error is detected, the code, error detection report, and design description file are sent to the error correction language model.
[0082] Step 2: The error correction large language model will correct the errors and return the modified RTL code based on the provided error detection report, design description file and RTL design code.
[0083] Step 3: Scoring The large language model analyzes and evaluates the modified code and scores it based on the code quality.
[0084] Step 4: Save the modified code and the score in the repository to start the rollback mechanism, which is mainly to prevent LLM errors in the returned RTL code, such as omitting code content. The repository will select the RTL code with the highest score for the next iteration, and continue until the termination condition of the architecture is met.
[0085] When using a large language model, exceptions may occur. For example, a large language model may return incomplete code. If subsequent iterations are based on these defective outputs, the quality of the results may be affected. In addition, in addition to modifying the wrong part of the code, the large language model may inadvertently modify the correct part of the code, resulting in subsequent iterations being used to solve new errors introduced by the large language model itself. To handle these exceptions, a scoring large language model and a data rollback mechanism are introduced into the architecture to jointly handle exceptions.
[0086] The structure for handling exceptions includes a large language model for scoring, a code repository, and a data rollback mechanism.
[0087] Scoring large language models are used to detect anomalies. During the error correction process, in order to prevent the large language model from making large-scale changes to the code, resulting in the modification of the correct code or even changes in the code logic, the error correction process should minimize changes to the original code. After the error correction large language model makes correction suggestions, the modified code will be compared with the version in the previous iteration. The scoring large language model will then evaluate the code based on its completeness and overall quality.
[0088] The code repository is used to save the code and reports generated during the iteration process. Each generated code is marked with an iteration version. If the evaluation score of the scoring large language model is lower than the preset threshold, the data rollback mechanism will be triggered to restore the design code to the previous iteration version.
[0089] The data rollback mechanism is an effective solution for abnormal situations. It is triggered by the score provided by the scoring language model to analyze the integrity of the code. When the score of the code in the scorer agent is lower than the predetermined threshold, a rollback will occur. After the trigger, the code with the highest score in the previous iteration will be used for the next iteration instead of the code generated this time. Further, the code modification process includes the following steps:
[0090] Obtain an error correction task prompt template; the error correction task prompt template includes an error correction task data filling field; fill the design description file, the error detection report and the RTL design code into the error correction task data filling field to obtain an error correction task prompt (i.e., Prompt); input the error correction task prompt into the error correction large language model, and perform code error modification processing on the RTL design code in the error correction task prompt based on the design description file and the error detection report in the error correction task prompt through the error correction large language model to obtain a modified RTL design code.
[0091] Loop iteration. The modified RTL design code will be recompiled and simulated to check whether there are syntax errors and functional errors. If there are any, the modified RTL design code will be used as the RTL design code provided in the code modification and will be modified again. The erroneous RTL design code will be corrected by iterating the above pipeline stage multiple times. Finally, if there are no errors, it will terminate and return the last modification result.
[0092] In addition, in order to prevent loop iterations from entering an infinite loop, an iteration threshold and an exception handling mechanism are set. The iteration threshold refers to the maximum number of times the loop iteration process can be performed; the exception handling mechanism is used to solve the "hallucination" problem that is easy to occur when modifying the code of a large language model. In actual use, the specific manifestations include: large-scale code changes in a large language model cause the correct code to be modified or even the code logic to change, and the code content returned by the large language model is empty, which will eventually lead to an infinite loop.
[0093] Furthermore, the abnormal situation handling mechanism includes the following steps:
[0094] Code evaluation. The scoring large language model (scorer agent) will return the code for analysis and evaluation, and determine the candidate code with higher code quality from the RTL design code and the modified RTL design code according to the code quality and design description file requirements. The scoring large language model performs quality scoring on the modified RTL design code and the RTL design code based on the design description file to obtain a scoreboard; if the scoreboard is greater than or equal to the score threshold, the modified RTL design code is used as a candidate code with higher code quality; otherwise, the RTL design code is used as a candidate code with higher code quality. Among them, the scoreboard is positively correlated with the code quality of the modified RTL design code relative to the RTL design code. In other words, the scoring large language model can refer to the requirements indicated by the design description file, compare the RTL design code and the modified RTL design code, and obtain a scoreboard that can be used to indicate the code quality of the modified RTL design code relative to the RTL design code. The higher the code quality of the modified RTL design code relative to the RTL design code, the higher the scoreboard, and the lower the code quality of the modified RTL design code relative to the RTL design code, the lower the scoreboard.
[0095] Based on the code evaluation results, the code repository (RTL code Repo.) can use the modified RTL design code as the RTL design code used in the next round of iteration if the score value is greater than or equal to the score threshold; otherwise, the data rollback mechanism will be triggered. Among them, the scoring range of the scoring large language model can be set according to specific needs, and the corresponding score value obtained based on the scoring large language model should be within the scoring range of the scoring large language model. For example, when the scoring range of the scoring large language model is set to 0 to 100, the scoring threshold can be set to 50. For example, when the scoring range of the scoring large language model is set to 0 to 10, the scoring threshold can be set to 6.
[0096] Data rollback mechanism. Triggered by the score value provided by the scoring large language model analysis code. When the score value in the scoring large language model is lower than the score threshold, the data rollback mechanism will be triggered. After the trigger, the modified RTL design code is not used for the next loop iteration, but the current RTL design code is reused for the next loop iteration, that is, the modification of this loop iteration does not meet expectations, and the current RTL design code will be modified again in the next loop iteration.
[0097] The embodiment of the present application proposes an automated hardware design error correction architecture based on a large language model, which can automatically modify the correct design code by providing a design description file, RTL design code and a test platform file; the embodiment of the present application also clearly proposes a method for handling abnormal situations using a scoring large language model, a code repository and a data rollback mechanism, wherein the scoring large language model can detect abnormal situations by comparing the code before and after modification, based on the integrity and overall quality assessment of the code, the code repository can be used to save the code and reports generated during the iteration process, the data rollback mechanism can ensure that the abnormal situation can be effectively resolved after it is discovered, and the iteration mechanism is introduced in the error correction process of the large language model, thereby improving the accuracy of code error correction.
[0098] In a feasible implementation manner, the first code takes the accumulator (accu) of the RTL design code as an example to illustrate the specific process of the code processing method of the present invention:
[0099]
[0100]
[0101]
[0102]
[0103]
[0104]
[0105] in," " ) should be ( ), this error is a syntax error.
[0106] Get user input. The RTL code is the error code shown above, and the design description file is an accumulator, which is a data structure or variable used to store and accumulate values. Its function is to add up the results of each calculation in different calculation processes to get the final sum or cumulative result.
[0107] Compile and simulate. The error code will first enter the compiler for compilation. Since this is a syntax error, a syntax error report (i.e., compilation report) will be generated during the compilation process. Since there is no functional error in the error code, the code will not pass the simulator at this time and will directly enter the next step.
[0108] Code modification: First, get the prompt word template, then fill in the previous information into the corresponding part to get the prompt word (prompt) for communicating with the debug agent.
[0109] The error correction language model will be modified according to the prompt words and return the modified RTL design code.
[0110] Code evaluation. The modified RTL design code is provided together with the previous RTL design code to the scoring language model (scorer agent) to obtain the scoreboard. First, the corresponding prompt word template is obtained, and then the corresponding code is filled into the corresponding position to obtain the prompt word (prompt) for communicating with the scoring language model.
[0111] Exemplarily, the results provided by the scoring large language model are as follows:
[0112] Score: 90
[0113] Reason:
[0114] 1.The modified code is almost complete and addresses the issues in the original code. The missing part is the initialization of the 'data_out'signal in the first always block.
[0115] 2.It should be initialized to @ when "rst_n' is low. Other than that, the modifications have corrected the functionality and structure of the original code.
[0116] The score is 90. If it is not lower than the score threshold, the data rollback mechanism will not be triggered. At this time, the modified RTL design code will be recompiled and simulated as the RTL design code input in the next round of iteration. If there are errors, this cycle will be repeated until the code is correct or the iteration number threshold is reached.
[0117] Of course, if the error correction result is other than the above, there may be a situation where the score is low and the data rollback mechanism is triggered. For example, the result provided by the scoring large language model is as follows:
[0118] Score:60
[0119] Reason:
[0120] 1.The code is missing the implementation of the ‘pass_request’ inputin the state machine logic. This input should be considered in the statetransitions and conditions。
[0121] 2.The 'clock" output is incorrectly assigned to "cnt’ instead ofbeing driven by the clock signal. The "clock’ output should be derived fromthe clock signal directly。
[0122] 3.The code has multiple always blocks sensitive to the same clock andreset signals, which can lead to potential issues. It is recommended tocombine these blocks into a single always。
[0123] 4.The code lacks comments to explain the functionality of each blockand signal, which is essential for understanding the design。
[0124] 5.The code has redundant assignments in the last always block, where the values of "red~, "yellow~, and "green~ are assigned to their previousvalues. This block can be simplified or Overall, the code needs improvements in terms of functionality, clarity, and best practices in Verilog coding.
[0125] The score value this time is 60. If it is not higher than the score threshold, the design file will be marked as err_design, triggering the data rollback mechanism, and the code will roll back to the input file of this iteration (it can also be understood that this modification is invalid and needs to be modified again).
[0126] At the same time, there may be cases where the code is empty. This situation is very easy to detect and does not need to be submitted to the scoring language model for evaluation. Therefore, the data rollback mechanism will be triggered directly before the code evaluation.
[0127] Based on the above description, the embodiment of the present application further discloses a code processing device; the code processing device may be a computer program running in a computer device, the computer device may be the above code processing device, and the code processing device may execute Figure 2 and Figure 4 The steps in the method flow are shown. Figure 6 , is a schematic diagram of the structure of a code processing device provided in an embodiment of the present application, the code processing device may include an acquisition unit 601 and a processing unit 602, wherein:
[0128] An acquisition unit 601 is used to acquire input data; wherein the input data includes a first code, a test platform file, and a design description file, and the first code includes a register transfer level code generated based on the design description file;
[0129] A processing unit 602 is used to perform code error detection processing on the first code based on the test platform file to obtain an error detection report;
[0130] The processing unit 602 is further configured to use the first code as a second code after error correction when the error detection report indicates that no code error is detected;
[0131] The processing unit 602 is further configured to, when the error detection report indicates that a code error is detected, perform code error correction processing on the first code based on the design description file and the error detection report by using an error correction model to obtain an intermediate code;
[0132] The processing unit 602 is further configured to determine a candidate code with higher code quality from the first code and the intermediate code;
[0133] The processing unit 602 is further configured to use the candidate code as a new first code, and iteratively execute the step of performing code error detection processing on the new first code until an error-corrected second code is obtained.
[0134] In one implementation, when the processing unit 602 is used to determine a candidate code with higher code quality from the first code and the intermediate code, it can be used to:
[0135] Performing a quality scoring process on the intermediate code based on the design description file and the first code by using a scoring model to obtain a scoring value; wherein the scoring value is positively correlated with the code quality of the intermediate code relative to the first code;
[0136] If the score value is greater than or equal to the score threshold, the intermediate code is used as a candidate code with higher code quality;
[0137] Otherwise, the first code is taken as a candidate code with higher code quality.
[0138] In one implementation, when the processing unit 602 is used to perform quality scoring processing on the intermediate code based on the design description file and the first code through a scoring model to obtain a scoring value, it can be used to:
[0139] Obtaining a scoring task prompt template; the scoring task prompt template includes a scoring task data filling field;
[0140] Fill the design description file, the first code and the intermediate code into the scoring task data filling field to obtain a scoring task prompt;
[0141] The scoring task prompt is input into the scoring model, and the intermediate code in the scoring task prompt is subjected to quality scoring processing by the scoring model based on the design description file and the first code in the scoring task prompt to obtain the scoring value.
[0142] In one implementation, when the processing unit 602 is used to perform code error detection processing on the first code based on the test platform file to obtain an error detection report, it can be used to:
[0143] Compiling the first code by a compiler to detect syntax errors in the first code and obtain a compilation report;
[0144] If the compilation report indicates that a syntax error is detected, using the compilation report as an error detection report;
[0145] If the compilation report indicates that no syntax errors are detected, then, by means of a simulator, code simulation processing is performed on the first code based on the test platform file to detect functional errors in the first code, and a simulation report is obtained;
[0146] If the simulation report indicates that a functional error is detected, an error detection report is constructed based on the compilation report and the simulation report.
[0147] In one implementation, when the processing unit 602 is used to perform code error correction processing on the first code based on the design description file and the error detection report through the error correction model to obtain the intermediate code, it can be used to:
[0148] Obtaining an error correction task prompt template; the error correction task prompt template includes an error correction task data filling field;
[0149] Fill the design description file, the error detection report and the first code into the error correction task data filling field to obtain an error correction task prompt;
[0150] The error correction task prompt is input into the error correction model, and the error correction model performs code error modification processing on the first code in the error correction task prompt based on the design description file and error detection report in the error correction task prompt to obtain the intermediate code.
[0151] In one implementation, when the error detection report indicates that a code error is detected, the processing unit 602 is used to perform code error correction processing on the first code based on the design description file and the error detection report through an error correction model to obtain an intermediate code, and can be used to:
[0152] In a case where the error detection report indicates that a code error is detected, obtaining the number of iterations;
[0153] When the number of iterations does not reach the number threshold, triggering the step of performing code error correction processing on the first code based on the design description file and the error detection report through the error correction model to obtain an intermediate code;
[0154] The method further comprises:
[0155] When the number of iterations reaches the number threshold, the first code is used as the second code after error correction.
[0156] According to another embodiment of the present application, Figure 6 The various units in the code processing device shown can be individually or completely combined into one or several other units to form a unit, or one (some) of the units can be further divided into multiple functionally smaller units to form a unit, which can achieve the same operation without affecting the realization of the technical effects of the embodiments of the present application.
[0157] In the embodiment of the present application, the first code to be corrected can be subjected to code error detection processing based on the test platform file to obtain an error detection report; when the error detection report indicates that no code error is detected, the first code is used as the second code after error correction; when the error detection report indicates that a code error is detected, the first code is subjected to code error modification processing based on the design description file and the error detection report through the error correction model to obtain an intermediate code; and then a candidate code with higher code quality can be determined from the first code and the intermediate code as a new first code, and the step of performing code error detection processing on the new first code is iteratively executed until the second code after error correction is obtained. Automatic iterative error correction of the code can be realized based on the code error detection processing and the code error modification processing, and the automation of the verification and error correction process of the code can be realized, saving time and resources in the development process and accelerating the development process. Moreover, the candidate code with higher code quality is determined from the first code and the intermediate code for iterative processing, which can improve the accuracy of the second code after error correction obtained by iterative error correction.
[0158] Based on the description of the above method embodiment and the device embodiment, the present application embodiment further provides a computer device, which can be the above code processing device. Figure 7 , is a structural diagram of a computer device provided in an embodiment of the present application. The computer device in the embodiment of the present application includes a processor 701, a computer-readable storage medium 702, and a communication interface 703. The processor 701, the computer-readable storage medium 702, and the communication interface 703 can exchange data, and the processor 701 implements the code processing method proposed in the embodiment of the present application.
[0159] The embodiment of the present application also provides a computer-readable storage medium (Memory), which is a memory device in a computer device for storing computer programs and data, and the stored computer programs are suitable for being loaded by a processor and executing the code processing method proposed in the embodiment of the present application. The computer-readable storage medium 702 may include one or more of a volatile memory or a non-volatile memory. For example, the volatile memory may include a random-access memory (RAM), and the non-volatile memory may include a flash memory, a solid-state drive (SSD), and the like.
[0160] The processor 701 may be a central processing unit (CPU); the processor 701 may also be a combination of a CPU and a graphics processing unit (GPU).
[0161] The communication interface 703 may be used to implement data input and output, and may include, for example, a display screen, a microphone or a speaker.
[0162] In one embodiment, a computer program stored in a computer-readable storage medium may be loaded and executed by a processor to implement the above-mentioned Figure 2 or Figure 4 Corresponding steps in the method embodiment shown; in a specific implementation, the computer program in the computer-readable storage medium can be loaded by the processor and execute the following steps:
[0163] Acquire input data; wherein the input data includes a first code, a test platform file, and a design description file, and the first code includes a register transfer level code generated based on the design description file;
[0164] Perform code error detection processing on the first code based on the test platform file to obtain an error detection report;
[0165] In a case where the error detection report indicates that no code error is detected, using the first code as a second code after error correction;
[0166] When the error detection report indicates that a code error is detected, performing code error correction processing on the first code based on the design description file and the error detection report by using an error correction model to obtain an intermediate code;
[0167] Determine a candidate code with higher code quality from the first code and the intermediate code;
[0168] The candidate code is used as a new first code, and the step of performing code error detection processing on the new first code is iteratively performed until a second code after error correction is obtained.
[0169] The present application provides a computer program product, which includes a computer program stored in a computer-readable storage medium; a processor of a computer device reads the computer program from the computer-readable storage medium, and the processor executes the computer program, so that the computer device performs the above Figure 2 or Figure 4 The method embodiment shown.
[0170] A person of ordinary skill in the art may understand that to implement all or part of the processes in the above-mentioned embodiment method, the process may be completed by a computer program to instruct the relevant hardware, and the program may be stored in a computer-readable storage medium. When the program is executed, it may include the processes of the above-mentioned method embodiments.
[0171] What is disclosed above is only part of the embodiments of the present application, which certainly cannot be used to limit the scope of rights of the present application. Ordinary technicians in this field can understand that all or part of the processes of implementing the above embodiments and equivalent changes made according to the claims of this application are still within the scope of the present invention.
Claims
1. A code error correction method, characterized in that: include: Acquire input data; wherein the input data includes a first code, a test platform file, and a design description file, and the first code includes a register transfer level code generated based on the design description file; Perform code error detection processing on the first code based on the test platform file to obtain an error detection report; In a case where the error detection report indicates that no code error is detected, using the first code as a second code after error correction; When the error detection report indicates that a code error is detected, performing code error correction processing on the first code based on the design description file and the error detection report by using an error correction model to obtain an intermediate code; Determine a candidate code with higher code quality from the first code and the intermediate code; The candidate code is used as a new first code, and the step of performing code error detection processing on the new first code is iteratively performed until a second code after error correction is obtained.
2. The method according to claim 1, characterized in that The step of determining a candidate code with higher code quality from the first code and the intermediate code includes: Performing a quality scoring process on the intermediate code based on the design description file and the first code by using a scoring model to obtain a scoring value; wherein the scoring value is positively correlated with the code quality of the intermediate code relative to the first code; If the score value is greater than or equal to the score threshold, the intermediate code is used as a candidate code with higher code quality; Otherwise, the first code is taken as a candidate code with higher code quality.
3. The method according to claim 2, characterized in that The step of performing a quality scoring process on the intermediate code based on the design description file and the first code by using a scoring model to obtain a scoring value includes: Obtaining a scoring task prompt template; the scoring task prompt template includes a scoring task data filling field; Fill the design description file, the first code and the intermediate code into the scoring task data filling field to obtain a scoring task prompt; The scoring task prompt is input into the scoring model, and the intermediate code in the scoring task prompt is subjected to quality scoring processing by the scoring model based on the design description file and the first code in the scoring task prompt to obtain the scoring value.
4. The method according to claim 1, characterized in that The performing code error detection processing on the first code based on the test platform file to obtain an error detection report includes: Compiling the first code to detect syntax errors in the first code and obtaining a compilation report; If the compilation report indicates that a syntax error is detected, using the compilation report as an error detection report; If the compilation report indicates that no syntax errors are detected, then, by means of a simulator, code simulation processing is performed on the first code based on the test platform file to detect functional errors in the first code, and a simulation report is obtained; If the simulation report indicates that a functional error is detected, an error detection report is constructed based on the compilation report and the simulation report.
5. The method according to claim 1, characterized in that The step of performing code error correction processing on the first code based on the design description file and the error detection report by using the error correction model to obtain an intermediate code includes: Obtaining an error correction task prompt template; the error correction task prompt template includes an error correction task data filling field; Fill the design description file, the error detection report and the first code into the error correction task data filling field to obtain an error correction task prompt; The error correction task prompt is input into the error correction model, and the error correction model performs code error modification processing on the first code in the error correction task prompt based on the design description file and error detection report in the error correction task prompt to obtain the intermediate code.
6. The method according to claim 1, characterized in that When the error detection report indicates that a code error is detected, performing code error correction processing on the first code based on the design description file and the error detection report by using an error correction model to obtain an intermediate code includes: In a case where the error detection report indicates that a code error is detected, obtaining the number of iterations; When the number of iterations does not reach the number threshold, triggering the step of performing code error correction processing on the first code based on the design description file and the error detection report through the error correction model to obtain an intermediate code; The method further comprises: When the number of iterations reaches the number threshold, the first code is used as the second code after error correction.
7. A code processing device, characterized in that: include: An acquisition unit, configured to acquire input data; wherein the input data includes a first code, a test platform file, and a design description file, and the first code includes a register transfer level code generated based on the design description file; A processing unit, configured to perform code error detection processing on the first code based on the test platform file to obtain an error detection report; The processing unit is further configured to use the first code as a second code after error correction if the error detection report indicates that no code error is detected; The processing unit is further configured to, when the error detection report indicates that a code error is detected, perform code error correction processing on the first code based on the design description file and the error detection report through an error correction model to obtain an intermediate code; The processing unit is further used to determine a candidate code with higher code quality from the first code and the intermediate code; The processing unit is further configured to use the candidate code as a new first code and iteratively execute the step of performing code error detection processing on the new first code until an error-corrected second code is obtained.
8. A computer device comprising a communication interface, characterized in that: Also includes: A processor and a computer readable storage medium; The computer readable storage medium is used to store a computer program; The processor is used to run the computer program to implement the code processing method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and the computer program is suitable for being loaded by a processor and executing the code processing method according to any one of claims 1 to 6.
10. A computer program product, characterized in that The computer program product comprises a computer program, and the computer program is suitable for being loaded by a processor and executing the code processing method according to any one of claims 1 to 6.
Citation Information
Cited By
Experimental platform and method for applying multi-modal large model digital circuit and medium
CN120509357A