Method for generating hardware description language code, electronic equipment and storage medium
Through the optimization system of large language model, EDA tools and prompt generators, the hardware description language code is iteratively optimized, which solves the problem of low accuracy of large language model generation code and improves the quality and accuracy of hardware description language code.
Patent Information
- Application Number
- CN202410597031.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-14
- Publication Date
- 2024-11-12
AI Technical Summary
Large language models cannot take into account quality optimization design when generating hardware description language code, and there are a lot of syntax and semantic problems in the generated code, and the accuracy is low.
The optimization system consisting of a large language model, EDA tools and prompt generator is used to input the feedback information generated by the EDA tools during the iteration process to generate intermediate prompt information to indicate the hardware description language intermediate generated by the large language model. Code, generate optimized hardware description language object code.
It significantly improves the accuracy of the hardware description language object code and optimizes the quality of generated code, reduces syntax and semantic errors, and improves the efficiency of chip design.
Smart Images

Figure CN118940714A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of EDA, and in particular to a method for generating hardware description language code, an electronic device and a storage medium. Background Art
[0002] Chip (IC) design often starts with design specifications expressed in natural language, where natural language can be Chinese, English or other types of languages. These design specifications are then translated into hardware description languages (HDLs), especially Verilog, by IC designers. However, the process of IC designers designing hardware description languages based on design specifications is cumbersome and time-consuming, resulting in a long chip design and chip verification cycle.
[0003] With the rapid development of large language models, large language models have now demonstrated the ability to generate code in multiple software programming languages from natural language descriptions or code frameworks, for example, the software programming languages are Python, JavaScript, and C++.
[0004] However, applying the big prediction model to hardware description language has the following technical defects:
[0005] First, chip design and verification through hardware description language is not just code design, but also includes quality optimization design of chip design. Currently, large language models cannot generate hardware description language code that takes quality optimization design into account.
[0006] Second, the hardware description language code generated by the large language model has a large number of grammatical and semantic problems and low accuracy. Summary of the invention
[0007] In view of the above technical problem, the technical solution adopted by the present invention is: a method for generating a hardware description language code, the method comprising the following steps:
[0008] S100, obtaining the hardware description language intermediate code media_code.
[0009] S200, inputting media_code into an optimization system for at least one iteration to obtain an optimized hardware description language target code; wherein the optimization system includes a large language model, an EDA tool, and a prompt generator, wherein the steps of the i-th iteration include:
[0010] S210, obtaining the hardware description language intermediate code media_code generated by the large language model in the i-1th iteration i-1 .
[0011] S220, media_code i-1The EDA tool is input to obtain at least one feedback information fb generated by the EDA tool.
[0012] S230, input fb into a prompt generator, the prompt generator adds context information to fb, and obtains at least one intermediate prompt information prompt based on natural language; wherein prompt is used to prompt the large language model to perform media_code based on fb. i-1 Make optimizations.
[0013] S240, inputting prompt into the large language model, and the large language model performs media_code according to prompt. i-1 Perform the i-th iteration to generate the hardware description language intermediate code media_code i .
[0014] In addition, the present invention also provides a non-transitory computer-readable storage medium, in which at least one instruction or at least one program is stored, and the at least one instruction or the at least one program is loaded and executed by a processor to implement the above method.
[0015] In addition, the present invention also provides an electronic device, including a processor and the above-mentioned non-transitory computer-readable storage medium.
[0016] The present invention has at least the following beneficial effects:
[0017] The present invention provides a method for generating hardware description language code, an electronic device and a storage medium. The method iterates the hardware description code generated by the large language model through an optimization system composed of a large language model, an EDA tool and a prompt generator. During the iteration process, feedback information generated by the EDA tool is input into the prompt generator, and the prompt generator generates intermediate prompt information, which further instructs the large language model to optimize the hardware description language intermediate code generated last time to obtain the hardware description language target code, which can greatly improve the accuracy of the generated hardware description language target code and the quality of the optimized generated code. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0019] Figure 1 A flow chart of a method for generating hardware description language code provided by an embodiment of the present invention;
[0020] Figure 2 A schematic diagram of the structure of the optimization system provided by the present invention. DETAILED DESCRIPTION
[0021] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0022] See also Figure 1 , which shows a flow chart of a method for generating a hardware description language code, the method comprising the following steps:
[0023] S100, obtaining the hardware description language intermediate code media_code.
[0024] Optionally, the step of obtaining media_code includes: obtaining initial information, inputting the initial information into the large language model to obtain media_code; wherein the initial information includes initial text information and initial prompt information, and the initial prompt information is used to prompt the large language model to generate a hardware description language code according to the initial text information. It should be noted that the initial information is the natural language input into the large language model before the optimization system iteration, and is used to generate the initial hardware description language intermediate code.
[0025] Optionally, the initial text information is a hardware description language initial code or a chip design specification described in a natural language. The hardware description language initial code may be a hardware description language code framework or an incomplete hardware description language code. Other types of initial text information for constraining chip design also fall within the protection scope of the present invention.
[0026] Optionally, the natural language is Chinese or English. Other types of languages also fall within the protection scope of the present invention.
[0027] Optionally, the initial prompt information is preset prompt instruction information, or prompt instruction information input by the user. Initial prompt information generated by other methods for prompting the large language model to generate hardware description language code according to the initial text information falls within the protection scope of the present invention.
[0028] Optionally, the hardware description language is Verilog, SystemVerilog or VHDL. Other types of hardware description languages also fall within the protection scope of the present invention.
[0029] Preferably, the hardware description language is Verilog RTL (Register Transfer Level) code.
[0030] Among them, the hardware description language intermediate code media_code is the code generated by the large language model. Whether the code meets the requirements of chip design and the syntax and semantics of the hardware description language needs to be compiled or simulated by EDA tools to check the reliability of the code. It is not the final target code.
[0031] Among them, Large Language Models (LLM) refers to a type of large-scale and highly complex natural language processing model. Its core is to perform a variety of natural language processing tasks through deep learning technology, especially neural networks based on the Transformer architecture.
[0032] Optionally, the large language model is ChatGPT, Gemini or Copilot. Other large language models also fall within the protection scope of the present invention.
[0033] S200, inputting media_code into an optimization system for at least one iteration to obtain optimized hardware description language target code; wherein the optimization system includes a large language model, an EDA tool, and a prompt generator.
[0034] See also Figure 2 , which shows the optimization system of the present invention, in Figure 2 In the present invention, the EDA tool and the prompt generator are used as enhancement tools to enhance the large language model, so that the large language model optimizes the hardware description language intermediate code generated last time, and finally generates the hardware description language target code. The hardware description language target code is the code that does not appear or appears less error or warning information and / or has better quality when the EDA tool is compiled or simulated.
[0035] Optionally, the EDA tool is an RTL synthesis tool, an RTL simulation tool or an RTL static checking tool. Other EDA tools also fall within the protection scope of the present invention.
[0036] Optionally, the RTL synthesis tool is Synopsys Fusion Compiler, Cadence Genus or UniVista uvsyn. Other RTL synthesis tools also fall within the protection scope of the present invention.
[0037] Optionally, the RTL simulation tool is Synopsys VCS, Cadence Xcelium or UniVista UV. The RTL simulation tool also falls within the protection scope of the present invention.
[0038] The prompt generator is used to add context information to each feedback information generated by the EDA tool to generate intermediate prompt information; the intermediate prompt information serves as an instruction to indicate the optimization direction of the large language model.
[0039] Wherein, the optimization system includes at least one EDA tool.
[0040] When there is only one type of EDA tool in the optimization system, at least one iteration step is executed after media_code is input into the optimization system. If the code that meets the requirements can be obtained by executing one iteration step, the iteration step is stopped, and the code obtained by the last iteration step is used as the hardware description language target code. If the requirements cannot be met after one iteration, multiple iterations are performed until the hardware description language target code that meets the requirements is obtained.
[0041] When there are N different types of EDA tools in the optimization system, it can be that in one iteration, the result output by the large language model is input into one type of EDA tool, and the feedback information output by the EDA tool is input into the prompt generator, and the prompt generator generates intermediate prompt information, thereby instructing the large language model to iterate. It can also be that in one iteration, the result output by the large language model is simultaneously input into N different types of EDA tools, so that the feedback information output by the N different types of EDA tools is input into the prompt generator together, and the prompt generator generates intermediate prompt information, thereby instructing the large language model to iterate. Other ways of enhancing the large language model with EDA tools and prompt generators in the optimization system fall within the protection scope of the present invention.
[0042] Furthermore, the steps of the i-th iteration include:
[0043] S210, obtaining the hardware description language intermediate code media_code generated by the large language model in the i-1th iteration i-1 Wherein, i is greater than or equal to 1, and the hardware description language intermediate code generated in the 0th iteration is the hardware description language intermediate code generated after the initial information is input into the large language model before entering the optimization system for iteration.
[0044] S220, media_code i-1 The EDA tool is input to obtain at least one feedback information fb generated by the EDA tool.
[0045] Optionally, fb is an error message, a warning message, or a quality-related message in a quality report (Quality of Results, QOR) obtained by the EDA tool after compiling or simulating media_code. Other types of information fb also fall within the protection scope of the present invention.
[0046] Among them, the error or warning information is related to the syntax and semantics of the hardware description language code input into the EDA tool. Among them, the quality-related information is information related to timing, area and power consumption. For example, the timing-related information is the longest timing path in terms of the number of combinatorial logic unit levels. The area-related information is the number of combinatorial logic units and sequential logic units. The power consumption-related information is the number of flip-flops driven by non-gated clocks.
[0047] S230, input fb into a prompt generator, the prompt generator adds context information to fb, and obtains at least one intermediate prompt information prompt based on natural language; wherein prompt is used to prompt the large language model to perform media_code based on fb. i-1 Make optimizations.
[0048] The context information is a preset instruction.
[0049] Among them, prompt is the intermediate prompt information that combines context information and fb.
[0050] As an example, fb reports a syntax error: a semicolon is missing on line 137. Then prompt includes the preset instruction information and fb's natural language instructions. prompt can be: the media_code generated last time i-1 Very good, but please base on media_code i-1 Modify the following errors, and keep the rest of the code unchanged: Add a semicolon to the end of line 137. Alternatively, when fb is quality-related information, for example, reporting the number of flip-flops driven by no gated clock, the prompt can be: the media_code generated last time i-1 Very good, but please base on media_code i-1 Make the following modifications and keep other codes unchanged: Add gated clocks to triggers A, B, and C that are not driven by gated clocks.
[0051] Optionally, S230 may also be to input all feedback information generated by EDA into the prompt generator one by one to generate intermediate prompt information, or to input all feedback information generated by EDA into the prompt generator in batches to generate intermediate prompt information, or to input all feedback information generated by EDA into the prompt generator. Among them, when all feedback information generated by EDA is large, inputting the prompt generator in batches can reduce the pressure on the prompt generator, reduce jamming, and improve generation efficiency.
[0052] As a preferred embodiment, fb in S220 is bound to a fault code.
[0053] Optionally, when the fault code is in the error message, the fault code is an identifier of a sub-error type in the error type, which is used to accurately indicate the specific error type that occurred. The fault code is used to uniquely identify a known error or error type. However, there may be multiple identical errors in the same hardware description language code, and the same error code is the same.
[0054] Optionally, when the fault code is in the warning information, the fault code is an identifier of a sub-warning type subdivided within the warning type, and is used to accurately indicate the specific warning type that has occurred.
[0055] Similarly, the quality-related information in the quality report (Quality of Results, QOR) also has corresponding fault codes to identify the subdivided sub-fault types.
[0056] Further, the prompt generator presets natural language-based context information for all fault codes. Preferably, multiple different fault codes preset the same natural language-based context information. After fb is input into the prompt generator, S230 also includes:
[0057] S231, the prompt generator matches preset context information respectively according to the fault code bound to fb, and obtains target context information that successfully matches fb.
[0058] S232, adding the target context information to fb to obtain prompt.
[0059] Since the number of fault codes is limited and they are data information preset by the EDA tool, the prompt generator synchronously presets the context information of the corresponding fault code. When the feedback information is input into the prompt generator, the prompt generator matches the preset context information by the fault code in the feedback information to obtain the context information of the feedback information. This method not only generates context information efficiently, but also makes the context information of the same fault code the same, thus preventing errors.
[0060] Methods in which the prompt generator generates context information in other ways also fall within the protection scope of the present invention.
[0061] As a preferred embodiment, in S230, when a plurality of feedback information is input into the prompt generator, it also includes:
[0062] S231 also includes: the prompt generator matches preset context information according to the fault code bound to each feedback information, to obtain the context information matched by each feedback information.
[0063] S232 also includes: when the contexts matched by the multiple feedback information are the same, adding a common target context information to the multiple feedback information to generate an intermediate prompt information.
[0064] Among them, when the fault codes are different, the corresponding fault types are different, but the context information of different fault types may be the same. Therefore, when the feedback information bound to different fault types matches the same context information, the feedback information bound to the fault types with the same context information is translated into natural language instructions, and a common context information is added to generate an intermediate prompt information, which improves the generation efficiency and saves memory space.
[0065] As an example, fault code 167 indicates a missing semicolon, and fault code 182 indicates a vector width error. Although fault codes 167 and 182 are two different fault types, the context information for both is "the last generated media_code i-1 Very good, but please base on media_code i-1 Modify the following errors, and keep other codes unchanged: ". At this time, you can add the context information before the feedback information of fault codes 167 and 182 to generate a prompt, for example: "The media_code generated last time i-1 Very good, but please base on media_code i-1 Modify the following errors, and keep other codes unchanged: 1. Add a semicolon at the end of line r, 2. Change the vector width to "t". r is the line number, and t is the parameter representing the vector width.
[0066] The prompt generator adopts other methods to match context information and it also falls within the protection scope of the present invention.
[0067] As a preferred embodiment, S230 also includes: when fb is a preset feedback information of a to-be-translated type, the prompt generator translates fb into a natural language instruction, and adds context information to the target natural language instruction to obtain prompt. It should be noted that there is some information in the feedback information that is difficult to understand. The user can use the feedback information that is difficult to understand as feedback information of the to-be-translated type, and complete the translation of the preset feedback information of the to-be-translated type by querying the relevant mapping table through the prompt generator. Among them, the mapping table records the physical meanings based on natural language of various fault information included in the feedback information.
[0068] S240, inputting prompt into the large language model, and the large language model performs media_code according to prompt. i-1 Perform the i-th iteration to generate the hardware description language intermediate code media_code i .
[0069] As a preferred embodiment, when the optimization system includes N different types of EDA tools, each EDA tool participates in at least one iteration step; when the jth EDA tool participates in the i-th iteration step, the value range of j is 1 to N, and the step S220 is: media_code i-1 Input the jth type of EDA tool to obtain at least one piece of feedback information generated by the EDA tool. Iterate according to each type of EDA tool in turn through the iterative step until the iteration result meets the requirements of all types of EDA tools in the system, and then end the iterative process. In this way, optimization is performed in turn according to the feedback information generated by different types of EDA tools to obtain a hardware description language target code that finally meets the requirements.
[0070] As a preferred embodiment, when the optimization system includes N different types of EDA tools, all types of EDA tools participate in the iteration step at the same time; when the i-th iteration, step S220 is: media_code i-1 Input into all types of EDA tools in the optimization system respectively, and obtain feedback information generated by all EDA tools. This method can be used to optimize based on the feedback information generated by different types of EDA tools at one time. Compared with the method of optimizing one by one, it can avoid the situation where a large language model is modified according to one EDA tool and then fails to meet the requirements of another EDA tool.
[0071] Other methods for enhancing large language models to generate optimized codes according to different EDA tools all fall within the protection scope of the present invention.
[0072] When the feedback information is an error or warning information, the prompt generator can guide the large language model to correct the grammatical or semantic errors identified by the EDA tool by converting the error or warning information into intermediate prompt information to improve accuracy. When the feedback information is timing information, such as the timing path with the longest combinational logic level, that is, the path with the largest delay; the prompt generator guides the large language model to remap from a smaller combinational logic unit to a larger combinational logic unit by converting the timing information into intermediate prompt information to reduce the number of combinational logic levels and improve chip performance. When the feedback information is area information, such as the total number of combinational logic units and sequential logic units; the prompt generator guides the large language model to remap from a smaller combinational logic unit to a larger combinational logic unit by converting the area information into intermediate prompt information to reduce the number of combinational and sequential units, reduce the generated area, and improve performance. When the feedback information is power consumption information, such as a trigger without a gated clock; the prompt generator can guide the large language model to increase the number of gated clocks by converting the power consumption information into intermediate prompt information to reduce the dynamic power consumption of the chip design.
[0073] In summary, the present invention provides a method for generating hardware description language code, which iterates the hardware description code generated by the large language model through an optimization system composed of a large language model, an EDA tool, and a prompt generator. During the iteration, the hardware description language intermediate code generated by the last iteration of the large language model is input into the EDA tool, and the feedback information generated by the EDA tool is input into the prompt generator. The prompt generator generates intermediate prompt information, and the intermediate prompt information is used to instruct the large language model to optimize the hardware description language intermediate code generated last time according to the feedback information to obtain the optimized hardware description language target code. The method enhances the large language model based on the EDA tool and the prompt generator, and can greatly improve the accuracy of the generated hardware description language target code and optimize the quality of the generated code.
[0074] An embodiment of the present invention also provides a non-transitory computer-readable storage medium, which can be set in an electronic device to store at least one instruction or at least one program related to implementing a method in a method embodiment. The at least one instruction or the at least one program is loaded and executed by the processor to implement the method provided in the above embodiment.
[0075] An embodiment of the present invention further provides an electronic device, comprising a processor and the aforementioned non-transitory computer-readable storage medium.
[0076] An embodiment of the present invention further provides a computer program product, which includes program code. When the program product is run on an electronic device, the program code is used to enable the electronic device to execute the steps of the method according to various exemplary embodiments of the present invention described above in this specification.
[0077] Although some specific embodiments of the present invention have been described in detail by way of example, it should be understood by those skilled in the art that the above examples are for illustration only and are not intended to limit the scope of the present invention. It should also be understood by those skilled in the art that various modifications may be made to the embodiments without departing from the scope and spirit of the present invention. The scope of the present invention is defined by the appended claims.
Claims
1. A method for generating hardware description language code, It is characterized in that The method comprises the following steps: S100, obtaining a hardware description language intermediate code media_code; S200, inputting media_code into an optimization system for at least one iteration to obtain an optimized hardware description language target code; wherein the optimization system includes a large language model, an EDA tool, and a prompt generator, wherein the steps of the i-th iteration include: S210, obtaining the hardware description language intermediate code media_code generated by the large language model in the i-1th iteration i-1 ; S220, media_code i-1 Input the EDA tool to obtain at least one feedback information fb generated by the EDA tool; S230, input fb into a prompt generator, the prompt generator adds context information to fb, and obtains at least one intermediate prompt information prompt based on natural language; wherein prompt is used to prompt the large language model to perform media_code based on fb. i-1 Optimize S240, inputting prompt into the large language model, and the large language model generates media_code according to prompt. i-1 Perform the i-th iteration to generate the hardware description language intermediate code media_code i .
2. The method according to claim 1, It is characterized in that The fb in S220 is bound to a fault code; The prompt generator presets natural language-based context information for all fault codes. After fb is input into the prompt generator, S230 further includes: S231, the prompt generator matches the preset context information according to the fault code bound to fb, and obtains the target context information that successfully matches fb; S232, adding the target context information to fb to obtain prompt.
3. The method according to claim 2, It is characterized in that The prompt generator presets the same natural language-based context information for a plurality of different fault codes.
4. The method according to claim 2 or 3, It is characterized in that In S230, when a plurality of feedback information is input into the prompt generator, the method further includes: S231 also includes: the prompt generator matches preset context information according to the fault code bound to each feedback information, to obtain context information matched by each feedback information; S232 also includes: when the contexts matched by the multiple feedback information are the same, adding a common target context information to the multiple feedback information to generate an intermediate prompt information.
5. The method according to claim 1, It is characterized in that S230 further includes: when fb is feedback information of a preset type to be translated, the prompt generator translates fb into a natural language instruction, and adds context information to the target natural language instruction to obtain prompt.
6. The method according to claim 1, It is characterized in that When the optimization system includes N different types of EDA tools, each EDA tool participates in at least one iteration step; when the jth EDA tool participates in the i-th iteration step, the value range of j is 1 to N, and the step S220 is: media_code i-1 A j-th EDA tool is input to obtain at least one piece of feedback information generated by the EDA tool.
7. The method according to claim 1, It is characterized in that When the optimization system includes N different types of EDA tools, all types of EDA tools participate in the iteration step at the same time; when it is the i-th iteration, the step S220 is: media_code i-1 The information is input into all types of EDA tools in the optimization system respectively to obtain feedback information generated by all EDA tools.
8. The method according to claim 1, It is characterized in that In S220, fb is an error message, a warning message, or a quality-related information in a quality report obtained by the EDA tool after compiling or simulating media_code.
9. A non-transitory computer-readable storage medium, wherein at least one instruction or at least one program is stored in the storage medium. It is characterized in that The at least one instruction or the at least one program is loaded and executed by the processor to implement the method according to any one of claims 1 to 8.
10. An electronic device, It is characterized in that The invention comprises a processor and the non-transitory computer-readable storage medium as claimed in claim 9.
Citation Information
Cited By
Hardware description generation method, equipment and medium
CN121212035A
Code generation method and device, electronic equipment, storage medium and program product
CN121541855A
Training data generation method and device, electronic equipment and storage medium
CN121580010A
