Method and device for determining program memory allocation based on large model, equipment and medium
By building a memory allocation data set and adjusting it using a large language model, we generate target header files that record memory allocation, which solves the problem of deterministic memory allocation in real-time security-critical environments, and realizes the determination of program memory allocation during the compilation period, improving response speed and applicability.
Patent Information
- Application Number
- CN202411657807.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-19
- Publication Date
- 2025-03-11
AI Technical Summary
The prior art is difficult to achieve runtime deterministic memory allocation in real-time security-critical environments, and static analysis tools based on LLVM have problems with insufficient code intrusion and generalization capabilities.
By obtaining the program memory allocation data determined during the compilation period, building a memory allocation data set, and adjusting it using a large language model to generate a target header file that records memory allocation to determine the program's memory allocation during the compilation period.
It realizes that the machine automatically detects and analyzes the memory allocation in the program without running a computer program, improves the response speed, and meets the programming scenario requirements with high real-time and safety criticality requirements.
Smart Images

Figure CN119597296A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of memory allocation, and in particular to a method, device, electronic device and computer-readable storage medium for determining program memory allocation based on a large model. Background Art
[0002] In the related art, runtime deterministic memory allocation is an important aspect of any safety-critical real-time system. One of the simplest and widely adopted allocation mechanisms used in such systems is a memory pool with a fixed block size. However, the need to determine the exact size of the memory block makes any practical use of memory pools with C++ allocator-based methods problematic, as the true nature of user allocations is usually hidden. For example, STL node-based containers (such as "std::map") and other standard mechanisms (such as "std::promise" or "std::allocate_shared").
[0003] At the same time, maintaining compatibility with the standard allocator model and following common conventions familiar to every C++ developer are also important aspects to consider when studying runtime deterministic memory allocation. Therefore, a practical memory pool-based allocator suitable for modern C++ is essential.
[0004] Memory allocation in a real-time safety-critical environment needs to meet the following constraints: 1) The solution should be safe and certifiable; 2) The solution should comply with the AUTOSAR C++14 coding guidelines for memory allocation. In terms of the C++ programming language, memory allocation should comply with the AUTOSAR C++14 programming guidelines, which meet the ISO26262 standard requirements for functional safety of road vehicles. Specifically, memory allocation should comply with the two main principles of the guidelines, as follows:
[0005] 1.Rule A18-5-5(required,implementation,partially automated)
[0006] Memory management functions should ensure the following conditions are met:
[0007] a. Ensure deterministic behavior even in the presence of worst-case execution time;
[0008] b. Avoid memory fragmentation;
[0009] c. Avoid insufficient memory;
[0010] d. Avoid mismatch between allocation and release;
[0011] e. Does not rely on non-deterministic calls to the kernel;
[0012] c and d (i.e. avoiding insufficient memory and avoiding mismatch between allocation and release) cannot be ensured in the middleware, but the other three requirements (i.e. a, b, e) can be solved by the middleware.
[0013] 2.Rule A18-5-7 (required, implementation, non-automated)
[0014] If the project uses a non-real-time implementation of the dynamic memory management function, the memory can only be allocated and released in the non-real-time program stage. That is, the memory can be pre-allocated by calling the non-real-time interface in the initialization phase, but the memory cannot be allocated and released through the non-real-time interface during the running process.
[0015] Memory pools with fixed block sizes are a solution to these problems:
[0016] It provides constant time allocation (deallocation) in preallocated memory buffers;
[0017] It avoids memory fragmentation through precisely sized buckets;
[0018] It is easy to implement, understand, and reason about;
[0019] The specific implementation of the memory pool includes a memory pool, an allocator that allocates from the memory pool, and a method to generate memory bucket definitions based on actual allocations. However, the memory pool solution has a prerequisite, that is, the developer needs to know the size of all buckets in advance. More specifically, the maximum number of blocks depends on the runtime, but the block size should be known at compile time, such as Figure 1 However, C++ is all about high-level abstractions that hide the actual size of allocations, e.g.: std::map, std::list, std::promise, std::shared_ptr.
[0020] In order to solve the above problems, an allocation analyzer implementation is needed, that is, in order to collect the information injected by the allocator, the definition of memory buckets and memory pools needs to be generated, such as Figure 2 shown.
[0021] In terms of understanding the code of a program, LLM (Large Language Model) such as OpenAI's ChatGpt has shown extraordinary efficiency and is increasingly used in the field of program analysis. An advantageous feature of LLM is its adaptability to different tasks, thanks to rapid engineering techniques. These techniques include designing effective input prompts to elicit the desired output from the LLM.
[0022] like Figure 3As shown in the paper, Apex.AI proposes an approach that combines a code-instrumented memory allocator implementation with an external LLVM-based tool that extracts the instrumentation information and generates static memory pool definitions, allowing the allocator to switch from the heap to the memory pool without any further changes to the code, including:
[0023] 1. Design of memory bucket: Each memory bucket is a collection of memory blocks of the same size. The memory bucket is defined by the number of blocks and the block size. The size of the memory bucket is the product of the number of blocks and the block size.
[0024] 2. Design of memory pool: Each memory pool is a collection of one or more memory buckets (the sizes of memory buckets can be the same or different, that is, the number of blocks and block size of each memory bucket can be configured independently), and each memory pool has a unique identifier. Each memory pool should be bound to a unique allocation function instance so that the allocation function can only allocate from the bound memory pool; the size of the memory pool should be fixed at compile time, and the application can allocate, access and release memory blocks in a given memory bucket in the memory pool at runtime (for example, in the real-time program stage).
[0025] 3. Header file recording memory allocation: contains the definition of one or more memory pools (in order to prevent threads from being bound to each other, an independent memory pool can be bound to each thread) and the definition of one or more memory buckets, where each memory pool with a unique identifier contains a reference description of one or more memory buckets.
[0026] 4. Design of virtual call: It is called in the memory allocation function of the allocator to extract the memory pool identifier, the type of data to be allocated, and the size of the data to be allocated.
[0027] 5. Determine memory allocation during compilation: Through a static analysis method, scan the virtual calls in the program to generate a header file that records the memory allocation, and then compile the header file together with the source code, so that the memory allocation of the program can be determined during compilation.
[0028] However, the above method has the disadvantage of code intrusion, which requires injecting virtual call functions into the program. In addition, the LLVM-based static analysis tool relies on predefined rules and pattern matching, and its generalization ability is limited by the written rule set, resulting in weak generalization ability. In addition, this method also requires iteration and maintenance. The LLVM-based static analysis tool requires manual rule updates to adapt to new coding patterns or language features. Summary of the invention
[0029] To overcome the problems existing in the related art, the present disclosure provides a method, an apparatus, an electronic device and a computer-readable storage medium for determining program memory allocation based on a large model.
[0030] According to a first aspect of an embodiment of the present disclosure, a method for determining program memory allocation based on a large model is provided, comprising: obtaining data for determining program memory allocation at compile time, constructing a memory allocation data set, wherein the memory allocation data set comprises a code slice set and a header file recording memory allocation; adjusting a large language model using the memory allocation data set to obtain an adjusted target large language model; obtaining a target application code, reasoning the target application code using the target large language model, and generating a target header file recording memory allocation, for determining program memory allocation at compile time.
[0031] In some embodiments, the method of obtaining data for determining program memory allocation at compile time and constructing a memory allocation data set includes: obtaining existing application code for determining program memory allocation at compile time; using the LLVM static code analysis tool to scan the existing application code and generate a header file that records memory allocation; based on a code knowledge graph, extracting information from the existing application code and generating a code slice set; and constructing a memory allocation data set based on the header file and the code slice set.
[0032] In some embodiments, the large language model includes BERT and ChatGPT.
[0033] In some embodiments, the code knowledge graph includes the code's calling relationship, control flow, data flow, program flow, value range analysis, hot spot analysis, lexical analysis, semantic analysis, and type analysis.
[0034] In some embodiments, the use of the memory allocated dataset to adjust the large language model to obtain an adjusted target large language model includes: pre-training the large language model using multiple programming languages; inputting the memory allocated dataset into the pre-trained large language model for fine-tuning to generate a target large language model.
[0035] In some embodiments, the method of obtaining the target application code, using the target large language model to infer the target application code, and generating a target header file that records memory allocation includes: obtaining the target application code, performing feature extraction and pruning filtering on the target application code according to a code knowledge graph, and generating a target code slice set; sending the target code slice set to the target large language model, generating a target header file that records memory allocation, and determining the memory allocation of the program during compilation through the target header file; and compiling and building according to the target application code and the target header file to generate an executable program.
[0036] In some embodiments, it also includes: deploying, running and testing the executable program.
[0037] According to a second aspect of an embodiment of the present disclosure, there is provided an apparatus for determining program memory allocation based on a large model, comprising: a data set construction module, used to obtain data for determining program memory allocation at compile time, and to construct a memory allocation data set, wherein the memory allocation data set comprises a code slice set and a header file recording memory allocation; a large language model adjustment module, used to adjust the large language model using the data set to obtain an adjusted target large language model; and a memory allocation determination module, used to obtain a target application code, use the target large language model to infer the target application code, and generate a target header file recording memory allocation, so as to determine the program's memory allocation at compile time.
[0038] According to a third aspect of an embodiment of the present disclosure, an electronic device is provided, comprising: a processor; a memory for storing executable instructions of the processor; the processor is used to read the executable instructions from the memory and execute the instructions to implement the method for determining program memory allocation based on a large model provided in the first aspect of the present disclosure.
[0039] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided, on which computer program instructions are stored. When the program instructions are executed by a processor, the steps of the method for determining program memory allocation based on a large model provided in the first aspect of the present disclosure are implemented.
[0040] The technical solution provided by the embodiments of the present disclosure may include the following beneficial effects: by acquiring data on program memory allocation determined during compilation, a memory allocation data set is constructed, which includes a code slice set and a header file recording memory allocation; the memory allocation data set is used to adjust the large language model to obtain an adjusted target large language model to match the pattern and characteristics of program memory allocation so that it has stronger generalization ability; the target application code is acquired, the target large language model is used to infer the target application code, and a target header file recording memory allocation is generated to determine the program's memory allocation during compilation, thereby enabling the machine to automatically detect and analyze the memory allocation in the program without running the computer program, thereby improving the response speed and meeting the requirements of programming scenarios with high real-time and safety criticality requirements.
[0041] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0043] Figure 1Is a memory pool with fixed blocks of different sizes.
[0044] Figure 2 It is the relationship between memory bucket and memory pool.
[0045] Figure 3 The present invention is a flowchart of determining the memory allocation of a program at compile time according to the prior art.
[0046] Figure 4 The invention is a flowchart showing a method for determining program memory allocation based on a large model according to an exemplary embodiment.
[0047] Figure 5 The figure is a flowchart of a method for constructing a memory allocation data set according to an exemplary embodiment.
[0048] Figure 6 The figure is a flowchart of constructing a memory allocation data set according to an exemplary embodiment.
[0049] Figure 7 The figure is a flowchart of a large language model adjustment method according to an exemplary embodiment.
[0050] Figure 8 The figure is a flowchart of large language model training according to an exemplary embodiment.
[0051] Fig. 9 The figure is a flowchart of a method for generating an executable program according to an exemplary embodiment.
[0052] Fig.10 is a flowchart of reasoning of a target large language model according to an exemplary embodiment.
[0053] Fig.11 The invention is a block diagram showing a device for determining program memory allocation based on a large model according to an exemplary embodiment.
[0054] Fig.12 It is a block diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION
[0055] Exemplary embodiments will be described in detail below with reference to the accompanying drawings.
[0056] It should be pointed out that the relevant embodiments and drawings are only for describing exemplary embodiments provided by the present disclosure, rather than all embodiments of the present disclosure, and it should not be understood that the present disclosure is limited to the relevant exemplary embodiments.
[0057] It should be noted that the terms "first", "second", etc. used in the present disclosure are only used to distinguish different steps, devices or modules, etc. The related terms neither represent any specific technical meanings nor indicate the order or interdependence between them.
[0058] It should be noted that the modifications of the terms "one", "multiple", and "at least one" used in the present disclosure are illustrative rather than restrictive. Unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0059] It should be noted that the term "and / or" used in this disclosure is used to describe the association relationship between associated objects, and generally indicates that there are at least three association relationships. For example, A and / or B can at least indicate the existence of three association relationships: A exists alone, A and B exist at the same time, and B exists alone.
[0060] It should be noted that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. Unless otherwise specified, the scope of the present disclosure is not limited by the order of description of the steps in the relevant embodiments.
[0061] It should be noted that all actions of acquiring signals, information or data in the present disclosure are carried out in compliance with the relevant data protection laws and policies of the country where the device is located and with the authorization given by the owner of the corresponding device.
[0062] Exemplary Methods
[0063] Figure 4 is a flowchart of a method for determining program memory allocation based on a large model according to an exemplary embodiment. Figure 4 As shown, the method for determining program memory allocation based on a large model is used in program memory allocation, comprising the following steps:
[0064] In step S110, data for determining program memory allocation during compilation is obtained, and a memory allocation data set is constructed. The memory allocation data set includes a code slice set and a header file recording memory allocation.
[0065] In some embodiments, data on program memory allocation determined at compile time is obtained. Since each piece of data on program memory allocation determined at compile time is composed of two parts: a set of code slices extracted from the code knowledge graph where memory allocation exists, and a header file generated to record memory allocation, when constructing a memory allocation data set for determining program memory allocation at compile time, the obtained memory allocation data set also includes a set of code slices and a header file to record memory allocation.
[0066] In step S120, the large language model is adjusted using the memory allocation data set to obtain an adjusted target large language model.
[0067] Among them, large language models include BERT and ChatGPT.
[0068] In some embodiments, an open source large language model is selected, such as BERT, ChatGPT, etc. The large language model has learned the semantics of multiple programming languages such as C++ well, and the constructed memory allocation dataset is used to adjust the selected large language model to obtain an adjusted target large language model, so that the large language model can learn the patterns and characteristics of program memory allocation, so that it has stronger generalization ability.
[0069] In step S130, the target application code is obtained, and the target large language model is used to infer the target application code to generate a target header file recording memory allocation, which is used to determine the memory allocation of the program during compilation.
[0070] In some embodiments, the compiled target application code is obtained, the target application code is inferred using a fine-tuned target large language model, a target header file that records memory allocation is generated, and compilation and construction are performed based on the target application code and the target header file to generate an executable program. By deploying the executable program in the target application and performing a run test, the memory allocation of the program can be determined during compilation, so as to reduce the delay caused by memory allocation, improve the response speed, and meet real-time applications, such as motion control of vehicles or robots. It is suitable for memory allocation management involved in programming scenarios with high real-time and safety requirements.
[0071] The compile time refers to the behavior of the compiler when compiling the source code in program design, including syntax analysis, semantic analysis, type checking, template instantiation, code generation, etc. In other words, memory determination is performed without running the program to ensure memory allocation in real-time and safety-critical environments, and the memory allocation is safe and verifiable.
[0072] In one embodiment, after step S130, the method further includes: deploying, running and testing the executable program.
[0073] Specifically, in order to verify the effect of the obtained executable program, it is also necessary to deploy the obtained executable program into the corresponding application program, and determine the actual effect of the executable program by running and testing the executable program.
[0074] In the above embodiment, by acquiring data on program memory allocation determined at compile time, a memory allocation data set is constructed, which includes a code slice set and a header file recording memory allocation. The memory allocation data set is used to adjust the large language model to obtain an adjusted target large language model to match the pattern and characteristics of program memory allocation so that it has stronger generalization ability. The target application code is acquired, and the target large language model is used to infer the target application code to generate a target header file recording memory allocation for determining the program's memory allocation at compile time, thereby achieving automatic detection and analysis of memory allocation in the program by the machine without running the computer program, thereby improving the response speed and meeting the requirements of programming scenarios with high real-time and safety criticality requirements.
[0075] Figure 5 is a flowchart of a method for constructing a memory allocation data set according to an exemplary embodiment. Figure 5 As shown, the method for constructing the memory allocation data set is used in step S110, and includes the following steps:
[0076] In step S210, the existing application program code for determining program memory allocation during compilation is obtained.
[0077] Specifically, when compiling the source code, the application code related to program memory allocation is pre-compiled. In order to train the large language model, the existing application code containing program memory allocation is obtained, such as Figure 6 shown.
[0078] In step S220, the LLVM static code analysis tool is used to scan the existing application code and generate a header file that records memory allocation.
[0079] Specifically, the LLVM static code analysis tool is used to scan the application code containing memory allocation and generate a header file that records the memory allocation. The header file is used to describe the behavior of the memory allocator when allocating memory. LLVM is a compiler infrastructure that provides static code analysis tools, such as Clang Static Analyzer, which uses LLVM's intermediate representation (IR) to analyze source code.
[0080] In step S230, information is extracted from the existing application code based on the code knowledge graph to generate a code slice set.
[0081] Specifically, based on the code knowledge graph, information extraction is performed on the existing application code containing memory allocation. The information extraction includes function-level code segment extraction, file-level code segment extraction, and variable-level code segment extraction. The code is cut through the above-mentioned extraction methods and finally a code slice set is generated.
[0082] When extracting information, you can make the following settings: function-level code segment: function definition, parameter passing, declaration and use of local variables; file-level code segment: file introduction, function definition, class declaration, variable declaration; variable set code segment: variable declaration and use, variable type selection, initialization, assignment, and how to use it in the program.
[0083] Among them, the code knowledge graph includes call relationship, control flow, data flow, program flow, value range analysis, hotspot analysis, syntax analysis, lexical analysis, semantic analysis and type analysis.
[0084] Specifically, through the code knowledge graph, the existing application code is decomposed and refined to obtain multimodal structured information, such as call relationship information, control information, value range information, etc., and a set of code slices is generated to facilitate the training and adjustment of the large language model.
[0085] In step S240, a memory allocation data set is constructed based on the header file and the code slice set.
[0086] Specifically, a header file and a code slice set that record memory allocation are combined to form a piece of data in a data set for determining program memory allocation at compile time. Through multiple header files and code slice sets, a memory allocation data set for determining program memory allocation at compile time is constructed, which facilitates subsequent adjustment of the large language model.
[0087] In this embodiment, the existing application code that determines the program memory allocation during compilation is obtained, and the LLVM static code analysis tool is used to scan the existing application code to generate a header file that records the memory allocation. The information of the existing application code is extracted based on the code knowledge graph to generate a code slice set. Based on the header file and the code slice set, a memory allocation data set is constructed to facilitate the training and adjustment of a large language model based on the memory allocation data set.
[0088] Figure 7 is a flowchart of a large language model adjustment method according to an exemplary embodiment. Figure 7 As shown, the large language model adjustment method is used in step S120, including the following steps:
[0089] In step S310, a large language model is pre-trained using multiple programming languages.
[0090] Specifically, Figure 8 As shown, multiple programming languages (for example, C++, C, etc.) are used to pre-train open source large language models (including but not limited to BERT, ChatGPT, etc.) so that the large language model can realize multi-language recognition and improve the generalization ability of the large language model.
[0091] In step S320, the memory allocation data set is input into the pre-trained large language model for fine-tuning to generate a target large language model.
[0092] Specifically, the constructed memory allocation dataset is input into the pre-trained large language model, and the large language model is fine-tuned through the memory allocation dataset to generate a fine-tuned target large language model to generate a header file that records memory allocation. The combination of knowledge graph and large language model can better help the model understand and associate multimodal data in the code, thereby improving the large language model's ability to analyze and generate code.
[0093] In this embodiment, a large language model is pre-trained using multiple programming languages, and a memory allocation data set is input into the trained large language model for fine-tuning to generate a target large language model, thereby realizing recognition of multiple programming languages and improving the generalization ability of the model. Moreover, through fine-tuning of the memory allocation data set, the target large language model can generate a header file recording memory allocation, which combines the knowledge graph with the large language model and improves the code analysis and generation capability of the large language model, so as to facilitate the analysis of the code through the large language model, thereby realizing the determination of program memory allocation at compile time.
[0094] Fig. 9 is a flowchart of a method for generating an executable program according to an exemplary embodiment. Fig. 9 As shown, the executable program generation method is used in step S130, comprising the following steps:
[0095] In step S410, the target application code is obtained, and feature extraction and pruning filtering are performed on the target application code according to the code knowledge graph to generate a target code slice set.
[0096] Specifically, Fig.10 As shown, the target application code that needs to perform program memory allocation is obtained, and according to the code knowledge graph, feature extraction and pruning filtering are performed on the target application code containing memory allocation to generate a target code slice set for subsequent code classification, recognition and detection tasks.
[0097] In step S420, the target code slice set is sent to the target large language model, a target header file recording memory allocation is generated, and the memory allocation of the program is determined during compilation through the target header file.
[0098] Specifically, the obtained target code slice set is sent to the target large language model, and the memory allocation-related program code is automatically detected through the automatic code of the target large language model, and a target header file recording the memory allocation is generated. The memory allocation of the program is determined during compilation through the target header file, so as to facilitate the determination of program memory allocation during compilation.
[0099] In step S430, the target application code and the target header file are compiled and constructed to generate an executable program.
[0100] Specifically, the header file recording the memory allocation is compiled and built together with the application code containing the memory allocation to generate an executable program. By deploying, running and testing the executable program, the memory allocation of the program can be determined at compile time, which improves the program response speed and makes the memory allocation safe and verifiable, which can be applied to real-time and safety-critical environments.
[0101] In this embodiment, by obtaining the target application code, feature extraction and pruning and filtering are performed on the target application code according to the code knowledge graph, a target code slice set is generated, the target code slice set is sent to the target large language model, a target header file recording memory allocation is generated, the memory allocation of the program is determined during compilation through the target header file, and compilation and construction are performed according to the target application code and the target header file to generate an executable program. The program code can be automatically detected and analyzed without running the computer program, and a header file recording memory allocation is generated, thereby realizing the determination of the program's memory allocation during compilation, thereby improving the response speed.
[0102] Exemplary Devices
[0103] Fig.11 is a block diagram of a device for determining program memory allocation based on a large model according to an exemplary embodiment. Fig.11 The device 200 includes a data set construction module 210, a large language model adjustment module 220 and a memory allocation determination module 230.
[0104] The data set construction module 210 is used to obtain data for determining program memory allocation during compilation and to construct a memory allocation data set, wherein the memory allocation data set includes a code slice set and a header file for recording memory allocation;
[0105] A large language model adjustment module 220, configured to adjust the large language model using the data set to obtain an adjusted target large language model;
[0106] The memory allocation determination module 230 is used to obtain the target application code, use the target large language model to infer the target application code, and generate a target header file that records the memory allocation, which is used to determine the memory allocation of the program during compilation.
[0107] In one embodiment, the data set construction module 210 is specifically used to: obtain the existing application code that determines the program memory allocation at compile time; use the LLVM static code analysis tool to scan the existing application code and generate a header file that records the memory allocation; based on the code knowledge graph, extract information from the existing application code and generate a code slice set; based on the header file and the code slice set, construct a memory allocation data set.
[0108] In one embodiment, the large language model adjustment module 220 is specifically used to: pre-train the large language model using multiple programming languages; input the memory allocation data set into the pre-trained large language model for fine-tuning, and generate a target large language model.
[0109] In one embodiment, the memory allocation determination module 230 is specifically used to: obtain the target application code, perform feature extraction and pruning filtering on the target application code according to the code knowledge graph, and generate a target code slice set; send the target code slice set to the target large language model, generate a target header file that records the memory allocation, and determine the memory allocation of the program during compilation through the target header file; compile and build according to the target application code and the target header file to generate an executable program.
[0110] In the above embodiment, through the operation of the device, a method for determining program memory allocation based on a large model is implemented, ensuring that the device can implement all contents of a method for determining program memory allocation based on a large model.
[0111] Exemplary Electronic Devices
[0112] Fig.12 1 is a block diagram of an electronic device 900 according to an exemplary embodiment. The electronic device 900 may be a vehicle controller, a vehicle terminal, a vehicle computer or other types of electronic devices.
[0113] Reference Fig.12 , the electronic device 900 may include at least one processor 910 and a memory 920. The processor 910 may execute instructions stored in the memory 920. The processor 910 is communicatively connected to the memory 920 via a data bus. In addition to the memory 920, the processor 910 may also be communicatively connected to an input device 930, an output device 940, and a communication device 950 via a data bus.
[0114] The processor 910 may be any conventional processor, such as a commercially available CPU. The processor may also include a graphics processor (Graphic Process Unit, GPU), a field programmable gate array (Field Programmable Gate Array, FPGA), a system on chip (System on Chip, SOC), an application specific integrated circuit (Application Specific Integrated Circuit, ASIC) or a combination thereof.
[0115] The memory 920 may be implemented by any type of volatile or nonvolatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0116] In an embodiment of the present disclosure, executable instructions are stored in the memory 920, and the processor 910 can read the executable instructions from the memory 920 and execute the instructions to implement all or part of the steps of the method for determining program memory allocation based on a large model as described in any of the above exemplary embodiments.
[0117] Exemplary computer-readable storage media
[0118] In addition to the above methods and devices, the exemplary embodiments of the present disclosure may also be a computer program product or a computer-readable storage medium storing the computer program product. The computer product includes computer program instructions that can be executed by a processor to implement all or part of the steps described in any method in the above exemplary embodiments.
[0119] The computer program product may be written in any combination of one or more programming languages to write program codes for performing the operations of the embodiments of the present application, including object-oriented programming languages, such as Java, C++, etc., and also conventional procedural programming languages, such as "C" language or similar programming languages and scripting languages (e.g., Python). The program code may be executed entirely on the user computing device, partially on the user computing device, as an independent software package, partially on the user computing device and partially on the remote computing device, or entirely on the remote computing device or server.
[0120] The computer readable storage medium can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can include, for example, but is not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples of readable storage media include: a static random access memory (SRAM) with one or more wires electrically connected, an electrically erasable programmable read-only memory (EEPROM), an erasable programmable read-only memory (EPROM), a programmable read-only memory (PROM), a read-only memory (ROM), a magnetic storage, a flash memory, a magnetic disk or an optical disk, or any suitable combination of the above.
[0121] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the present disclosure. This application is intended to cover any variations, uses or adaptations of the present disclosure, which follow the general principles of the present disclosure and include common knowledge or customary technical means in the art that are not disclosed in the present disclosure. The specification and examples are to be considered as exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.
[0122] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A method for determining program memory allocation based on a large model, characterized in that: include: Acquire data for determining program memory allocation during compilation, and construct a memory allocation data set, wherein the memory allocation data set includes a code slice set and a header file recording memory allocation; Using the memory allocation data set to adjust the large language model to obtain an adjusted target large language model; The target application code is obtained, the target large language model is used to infer the target application code, and a target header file recording memory allocation is generated, which is used to determine the memory allocation of the program during compilation.
2. The method for determining program memory allocation based on a large model according to claim 1, characterized in that: The step of obtaining data for determining program memory allocation during compilation and constructing a memory allocation data set includes: Get existing application code that determines program memory allocation at compile time; Using the LLVM static code analysis tool to scan the existing application code and generate a header file recording memory allocation; According to the code knowledge graph, information is extracted from the existing application code to generate a code slice set; A memory allocation data set is constructed based on the header file and the code slice set.
3. The method for determining program memory allocation based on a large model according to claim 1, characterized in that: The large language models include BERT and ChatGPT.
4. The method for determining program memory allocation based on a large model according to claim 2, characterized in that: The code knowledge graph includes the code's calling relationship, control flow, data flow, program flow, value range analysis, hot spot analysis, lexical analysis, semantic analysis and type analysis.
5. The method for determining program memory allocation based on a large model according to claim 1, characterized in that: The step of adjusting the large language model by using the memory allocation data set to obtain an adjusted target large language model includes: Use multiple programming languages to pre-train large language models; The memory allocation data set is input into the pre-trained large language model for fine-tuning to generate a target large language model.
6. The method for determining program memory allocation based on a large model according to claim 1, characterized in that: The step of obtaining the target application code, using the target large language model to infer the target application code, and generating a target header file that records memory allocation includes: Obtain target application code, perform feature extraction and pruning filtering on the target application code according to the code knowledge graph, and generate a target code slice set; Sending the target code slice set to the target large language model, generating a target header file recording memory allocation, and determining the memory allocation of the program during compilation through the target header file; Compile and construct according to the target application code and the target header file to generate an executable program.
7. The method for determining program memory allocation based on a large model according to claim 1, characterized in that: Also includes: The executable program is deployed, run and tested.
8. A device for determining program memory allocation based on a large model, characterized in that: include: A data set construction module is used to obtain data for determining program memory allocation during compilation and to construct a memory allocation data set, wherein the memory allocation data set includes a code slice set and a header file for recording memory allocation; A large language model adjustment module, used to adjust the large language model using the data set to obtain an adjusted target large language model; The memory allocation determination module is used to obtain the target application code, use the target large language model to infer the target application code, and generate a target header file that records the memory allocation, which is used to determine the memory allocation of the program during compilation.
9. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is used to read the executable instructions from the memory and execute the instructions to implement the method for determining program memory allocation based on a large model as described in any one of claims 1-7.
10. A computer-readable storage medium having computer program instructions stored thereon, characterized in that: When the program instructions are executed by a processor, the steps of the method for determining program memory allocation based on a large model described in any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Code compiling method, electronic equipment and storage medium
CN120215957A
Code compiling method, electronic device and storage medium
CN120215957B