Code compiling method and device, electronic equipment and storage medium
By supervising and enhancing learning of the initial code compilation model, the problem of low code compilation efficiency of different hardware platforms is solved, and an efficient and stable code compilation process on multiple platforms is realized.
Patent Information
- Application Number
- CN202510506997.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-22
- Publication Date
- 2025-08-01
AI Technical Summary
In the prior art, the code compilation method has limitations in cross-platform support due to the differences in hardware architecture and operating system interfaces of different hardware platforms, which reduces the efficiency of code compilation.
By obtaining hardware feature sample data, source code sample data and performance feedback sample data, supervised learning and enhanced learning of the pre-built initial code compilation model, obtaining the intermediate model of code compilation and the target code compilation model, reducing the participation of the compiler, and improving the code compilation efficiency and stability.
It realizes efficient and stable compilation of source code into object code on different hardware platforms, reducing the post-compilation debugging process and improving the efficiency and usability of code compilation.
Smart Images

Figure CN120406955A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computers, and is applicable to the fields of financial technology and medical technology. In particular, it relates to a code compilation method and device, an electronic device, and a storage medium. Background Art
[0002] Code compilation refers to the process of converting the source code written by a user into target code that can run on a hardware platform. For example, in the financial field, by compiling the source code of an automated teller machine written by a user, target code for controlling the operation of the automated teller machine can be obtained, thus ensuring the accurate operation of the automated teller machine. In the medical field, by compiling the source code of a medical device written by a user, target code for controlling the operation of the medical device can be obtained, thus ensuring the accurate operation of the medical device.
[0003] Currently, code compilation methods usually use compiler tools to compile source code data to generate target code suitable for a hardware platform. However, different hardware platforms have different hardware architectures, operating system interfaces, or instruction sets, resulting in limitations in cross-platform support when using compilers for code compilation, reducing the efficiency of code compilation. Therefore, how to improve the efficiency of code compilation has become a technical problem to be urgently solved. Summary of the Invention
[0004] The main purpose of the embodiments of this application is to propose a code compilation method and device, an electronic device, and a storage medium, aiming to improve the efficiency of code compilation.
[0005] To achieve the above object, a first aspect of the embodiments of this application proposes a code compilation method, and the method includes:
[0006] Obtain hardware characteristic sample data, source code sample data, target code sample data, and performance feedback sample data. Among them, there is a code data mapping relationship between the source code sample data and the target code sample data. The target code sample data represents code data that can be executed in the hardware environment indicated by the hardware characteristic sample data. The performance feedback sample data represents the hardware performance data generated when the target code sample data is executed in the hardware environment indicated by the hardware characteristic sample data;
[0007] Based on the hardware characteristic sample data, the source code sample data, the target code sample data, and the performance feedback sample data, perform supervised learning on a pre-constructed initial code compilation model to obtain a code compilation intermediate model;
[0008] Based on the hardware characteristic sample data, the target code sample data, and the performance feedback sample data, perform reinforcement learning on the code compilation intermediate model to obtain a target code compilation model;
[0009] Obtain the target hardware characteristic data of the target hardware, and obtain the target source code data of the target hardware;
[0010] Based on the target code compilation model and the target hardware characteristic data, compile the target source code data to obtain target compiled code, where the target compiled code represents code that can be executed on the target hardware.
[0011] In some embodiments, the supervised learning of the pre-constructed initial code compilation model based on the hardware characteristic sample data, the source code sample data, the target code sample data, and the performance feedback sample data to obtain a code compilation intermediate model includes:
[0012] Based on the initial code compilation model, compile the source code sample data to obtain predicted compiled code;
[0013] Based on the hardware characteristic sample data, execute the predicted compiled code to obtain predicted performance feedback data;
[0014] Based on the initial code compilation model, calculate the loss of the predicted compiled code and the target code sample data to obtain code loss data;
[0015] Based on the initial code compilation model, calculate the loss of the predicted performance feedback data and the performance feedback sample data to obtain performance loss data;
[0016] Based on the code loss data and the performance loss data, adjust the parameters of the initial code compilation model to obtain the code compilation intermediate model.
[0017] In some embodiments, the compiling the source code sample data based on the initial code compilation model to obtain predicted compiled code includes:
[0018] Based on the initial code compilation model, learn the mapping relationship between the source code sample data and the target code sample data to obtain a code mapping relationship;
[0019] Based on the initial code compilation model, parse the source code sample data to obtain an abstract syntax tree of the code;
[0020] Based on the initial code compilation model, perform format conversion on the abstract syntax tree of the code to obtain intermediate code;
[0021] Based on the initial code compilation model and the code mapping relationship, perform code mapping on the intermediate code to obtain the predicted compiled code.
[0022] In some embodiments, simulating the prediction compilation code based on the hardware characteristic sample data to obtain prediction performance feedback data includes:
[0023] Constructing a hardware simulation platform based on the hardware characteristic sample data;
[0024] Dynamically running the prediction compilation code based on the hardware simulation platform to obtain the prediction performance feedback data.
[0025] In some embodiments, adjusting the parameters of the initial code compilation model based on the code loss data and the performance loss data to obtain the intermediate code compilation model includes:
[0026] Merging the code loss data and the performance loss data based on a preset weight ratio of the loss data to obtain total model loss data;
[0027] Performing backpropagation on the initial code compilation model based on the total model loss data to obtain model convergence parameters;
[0028] Replacing the parameters of the initial code compilation model based on the model convergence parameters to obtain the intermediate code compilation model.
[0029] In some embodiments, performing reinforcement learning on the intermediate code compilation model based on the hardware characteristic sample data, the target code sample data, and the performance feedback sample data to obtain a target code compilation model includes:
[0030] Performing reward evaluation on the performance feedback sample data based on the intermediate code compilation model to obtain feedback data reward information;
[0031] Optimizing the target code sample data based on the intermediate code compilation model, the performance feedback sample data, the hardware characteristic sample data, and the feedback data reward information to obtain optimized code data;
[0032] Adjusting the parameters of the intermediate code compilation model based on the optimized code data to obtain the target code compilation model.
[0033] In some embodiments, obtaining target hardware characteristic data of the target hardware and obtaining target source code data of the target hardware includes:
[0034] Extracting information from a preset hardware configuration file to obtain hardware key information and code information;
[0035] Performing data standardization processing on the hardware key information to obtain the target hardware characteristic data;
[0036] Perform data cleaning on the said code information to obtain the target source code data.
[0037] To achieve the above object, a second aspect of the embodiments of the present application provides a code compilation device, which includes:
[0038] A sample data acquisition module, configured to acquire hardware characteristic sample data, source code sample data, target code sample data, and performance feedback sample data. Among them, there is a code data mapping relationship between the source code sample data and the target code sample data. The target code sample data represents code data that can be executed in the hardware environment indicated by the hardware characteristic sample data, and the performance feedback sample data represents the hardware performance data generated when the target code sample data is executed in the hardware environment indicated by the hardware characteristic sample data;
[0039] A model supervised learning module, configured to perform supervised learning on a pre-constructed initial code compilation model based on the hardware characteristic sample data, the source code sample data, the target code sample data, and the performance feedback sample data to obtain a code compilation intermediate model;
[0040] A model reinforcement learning module, configured to perform reinforcement learning on the code compilation intermediate model based on the hardware characteristic sample data, the target code sample data, and the performance feedback sample data to obtain a target code compilation model;
[0041] A target data acquisition module, configured to acquire target hardware characteristic data of the target hardware and acquire target source code data of the target hardware;
[0042] A model code compilation module, configured to perform code compilation on the target source code data based on the target code compilation model and the target hardware characteristic data to obtain target compilation code, where the target compilation code represents code that can be executed on the target hardware.
[0043] To achieve the above object, a third aspect of the embodiments of the present application provides an electronic device, which includes a memory and a processor. The memory stores a computer program, and when the processor executes the computer program, the method described in the first aspect above is implemented.
[0044] To achieve the above object, a fourth aspect of the embodiments of the present application provides a computer-readable storage medium, which stores a computer program, and when the computer program is executed by a processor, the method described in the first aspect above is implemented.
[0045] This application obtains hardware characteristic sample data, source code sample data, object code sample data, and performance feedback sample data, and performs supervised learning on a pre-constructed initial code compilation model based on the hardware characteristic sample data, source code sample data, object code sample data, and performance feedback sample data to obtain an intermediate code compilation model, enabling the intermediate code compilation model to achieve the mapping from source code to object code, thereby reducing the participation of the compiler in the code compilation process, solving the problem that source code data on different hardware platforms requires different compilers, and thus improving the code compilation efficiency. Secondly, based on the hardware characteristic sample data, object code sample data, and performance feedback sample data, reinforcement learning is performed on the intermediate code compilation model to obtain an object code compilation model, enabling the object code compilation model to compile source code data into code data that conforms to the characteristics of the hardware platform, reducing the post-compilation debugging process, and thus improving the stability and efficiency of code compilation. Finally, the target hardware characteristic data of the target hardware and the target source code data of the target hardware are obtained, and based on the object code compilation model and the target hardware characteristic data, the target source code data is compiled to obtain target compilation code, enabling the object code compilation model to be applied in practice and ensuring the usability of the object code compilation model. Description of the Drawings
[0046] Figure 1 is the flowchart of the code compilation method provided by the embodiment of the present application;
[0047] Figure 2 is Figure 1 the flowchart of step S102 in
[0048] Figure 3 is Figure 2 the flowchart of step S201 in
[0049] Figure 4 is Figure 2 the flowchart of step S202 in
[0050] Figure 5 is Figure 2 the flowchart of step S205 in
[0051] Figure 6 is Figure 1 the flowchart of step S103 in
[0052] Figure 7 is Figure 1 the flowchart of step S104 in
[0053] Figure 8 is the structural schematic diagram of the code compilation device provided by the embodiment of the present application;
[0054] Figure 9 It is a schematic diagram of the hardware structure of the electronic device provided by the embodiments of the present application. Detailed implementation manners
[0055] In order to make the objectives, technical solutions and advantages of the present application more clear and understandable, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0056] It should be noted that although functional module division is performed in the device schematic diagram and the logical sequence is shown in the flowchart, in some cases, the steps shown or described may be executed in a different module division in the device or a different sequence in the flowchart. Terms such as "first" and "second" in the specification, claims and the above-mentioned drawings are used to distinguish similar objects and do not necessarily need to describe a specific order or sequence.
[0057] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the technical field to which the present application belongs. The terms used herein are only for the purpose of describing the embodiments of the present application and are not intended to limit the present application.
[0058] First, several terms involved in the present application are analyzed:
[0059] Hardware platform: The hardware platform is the physical basis of a computer system and consists of key components such as the hardware architecture type, CPU / GPU / NPU specifications, hardware instruction set, memory / storage data, and input / output interfaces. These components together determine the performance, function, and compatibility of the computer, affecting the operating efficiency of software and the user experience. Different hardware platforms are suitable for different application scenarios, such as embedded systems, servers, mobile devices, etc.
[0060] Source code: The source code refers to the program code written by a programmer using a programming language. It is the original form of software and contains the logic and algorithms of the program. It is in a human-readable and editable form and is used to implement the functions and operations of the program. The source code needs to be converted into machine code or intermediate code through a compiler or interpreter before it can run on computer hardware. The source code is the basis of software development, and developers implement and optimize the functions of the program by writing, modifying, and maintaining the source code.
[0061] Large Language Model: A large language model is an artificial intelligence technology based on deep learning and is also one of the core research areas in natural language processing. Its core is to train the model using large-scale datasets so that it can generate natural language text or understand the meaning of language text. These models learn and simulate the complex rules of human language through a stacked neural network structure, achieving text generation capabilities close to the human level. Large language models adopt a similar Transformer architecture and pre-training objectives as small models. The main difference from small models lies in increasing the model size, training data, and computing resources. Compared with traditional natural language processing models, large language models can better understand and generate natural text and also exhibit certain logical thinking and reasoning abilities.
[0062] Code compilation refers to the process of converting the source code written by users into object code that can run on a hardware platform. For example, in the medical field, by compiling the source code of medical devices written by users, the object code for controlling the operation of medical devices can be obtained, thus ensuring the precise operation of medical devices.
[0063] Currently, the code compilation method usually uses a compiler tool to compile the source code data to generate object code suitable for the hardware platform. However, different hardware platforms have different hardware architectures, operating system interfaces, or instruction sets, resulting in limitations in cross-platform support when using a compiler for code compilation, reducing the efficiency of code compilation. Therefore, how to improve the efficiency of code compilation has become a technical problem to be solved urgently.
[0064] Based on this, the embodiments of this application provide a code compilation method, device, electronic device, and storage medium, aiming to improve the efficiency of code compilation.
[0065] The code compilation method, device, electronic device, and storage medium provided by the embodiments of this application are specifically described through the following embodiments. First, the code compilation method in the embodiments of this application is described.
[0066] The embodiments of this application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology, and application system that uses a digital computer or a machine controlled by a digital computer to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use knowledge to obtain the best results.
[0067] The basic technologies of artificial intelligence generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technologies, operation / interaction systems, and mechatronics. The software technologies of artificial intelligence mainly include several major directions such as computer vision technology, robotics, biometric technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0068] The code compilation method provided by the embodiments of the present application relates to the field of computer technology and is applicable to the fields of fintech and medical technology. The code compilation method provided by the embodiments of the present application can be applied to a terminal, can also be applied to a server side, or can also be software running on a terminal or a server side. In some embodiments, the terminal can be a smart phone, a tablet computer, a notebook computer, a desktop computer, etc.; the server side can be configured as an independent physical server, can also be configured as a server cluster or a distributed system composed of multiple physical servers, or can also be configured as a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application that implements the code compilation method, etc., but is not limited to the above forms.
[0069] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multi-processor systems, microprocessor-based systems, set-top boxes, programmable consumer electronic devices, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, and so on. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in a distributed computing environment, where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0070] Figure 1 It is an optional flowchart of the code compilation method provided by the embodiments of the present application. Figure 1 The method in [it] can include but is not limited to steps S101 to S107.
[0071] Step S101, obtain hardware characteristic sample data, source code sample data, target code sample data, and performance feedback sample data. Among them, there is a code data mapping relationship between the source code sample data and the target code sample data. The target code sample data represents code data that can be executed in the hardware environment shown by the hardware characteristic sample data, and the performance feedback sample data represents the hardware performance data generated when the target code sample data is executed in the hardware environment shown by the hardware characteristic sample data;
[0072] Step S102, based on the hardware characteristic sample data, source code sample data, target code sample data, and performance feedback sample data, perform supervised learning on a pre-constructed initial code compilation model to obtain a code compilation intermediate model;
[0073] Step S103, based on the hardware characteristic sample data, target code sample data, and performance feedback sample data, perform reinforcement learning on the code compilation intermediate model to obtain a target code compilation model;
[0074] Step S104, obtain the target hardware characteristic data of the target hardware, and obtain the target source code data of the target hardware;
[0075] Step S105, based on the target code compilation model and the target hardware characteristic data, perform code compilation on the target source code data to obtain target compilation code, where the target compilation code represents code that can be executed on the target hardware.
[0076] In the steps S101 to S105 shown in the embodiments of the present application, the present application obtains hardware characteristic sample data, source code sample data, target code sample data, and performance feedback sample data, and based on the hardware characteristic sample data, source code sample data, target code sample data, and performance feedback sample data, performs supervised learning on a pre-constructed initial code compilation model to obtain a code compilation intermediate model, enabling the code compilation intermediate model to realize the mapping from source code to target code, thereby reducing the participation of the compiler in the code compilation process and solving the problem that source code data on different hardware platforms requires different compilers, thus improving the code compilation efficiency. Secondly, based on the hardware characteristic sample data, target code sample data, and performance feedback sample data, perform reinforcement learning on the code compilation intermediate model to obtain a target code compilation model, enabling the target code compilation model to compile source code data into code data that conforms to the characteristics of the hardware platform, reducing the post-compilation debugging process, thereby improving the stability and efficiency of code compilation. Finally, obtain the target hardware characteristic data of the target hardware and the target source code data of the target hardware, and based on the target code compilation model and the target hardware characteristic data, perform code compilation on the target source code data to obtain target compilation code, enabling the target code compilation model to be applied in practice and ensuring the availability of the target code compilation model.
[0077] In step S101 of some embodiments, the hardware characteristic sample data refers to data such as the resources and performance of the hardware platform. For example, the hardware architecture type, CPU / GPU / NPU specifications, hardware instruction set, memory / storage data, input / output interfaces, etc. Among them, the hardware architecture types include ARM, x86, etc. For example, a portable medical device may adopt the ARM architecture. The CPU / GPU / NPU specifications can be the number of computing cores, main frequency, memory bandwidth, cache size, hardware acceleration ability, etc. The hardware instruction set can be a set of instructions that the hardware platform can understand and execute. For example, the NEON, AVX, etc. instruction sets of ARM. The memory / storage data refers to device memory, storage type, bandwidth, latency, etc. The input / output interfaces can be touch screens, voice inputs, sensor data, etc. The source code sample data refers to program code written in a programming language. For example, the control program of an electrocardiograph written in the C language, program code written in the C++ language, etc. The object code sample data refers to the machine language code or low-level language code generated after the source code sample data passes through a compiler. For example, assembly files, binary files, etc. It should be noted that there is a code mapping relationship between the object code sample data and the source code sample data. The performance feedback sample data refers to the performance data of the hardware platform when the object code sample data runs on the hardware platform. For example, running time, memory occupancy, power consumption, etc.
[0078] The embodiments of the present application can parse out data such as the resources and performance of the hardware platform by reading the configuration file of the hardware platform. Further, by integrating the data such as the resources and performance of the hardware platform, hardware characteristic data can be obtained. Secondly, the source code data of the hardware platform can be obtained on the code hosting platform, and then the source code data can be compiled into object code data by using a compiler, and the object code data can be run on the corresponding hardware platform to obtain the performance feedback data of the hardware platform. Finally, data preprocessing such as data cleaning and standardization is performed on the above-mentioned hardware characteristic data, source code data, object code data, and performance feedback data to obtain hardware characteristic sample data, source code sample data, object code sample data, and performance feedback sample data.
[0079] It should be noted that the types of the above-mentioned hardware characteristic data, source code data, target code data, and performance feedback data are inconsistent. Therefore, different data preprocessing needs to be performed on different data. For example, hardware characteristic sample data can be obtained by performing data standardization, data normalization, redundancy removal, and data format conversion on the hardware characteristic data; source code sample data can be obtained by performing code separation and code cleaning on the source code data; target code sample data can be obtained by performing code format standardization and data alignment on the target code; and performance feedback sample data can be obtained by performing performance benchmark testing and data standardization on the performance feedback data.
[0080] In step S102 of some embodiments, the initial code compilation model refers to a model that has the ability to compile code but has not been trained and cannot accurately compile code. For example, an untrained large language model. The code compilation intermediate model refers to a model that has learned the code mapping relationship from the source code sample data to the target code sample data.
[0081] In the embodiments of the present application, by inputting the hardware characteristic sample data, source code sample data, target code sample data, and performance feedback sample data into a pre-constructed initial code compilation model, the initial code compilation model is enabled to learn the code mapping relationship from the source code sample data to the target code sample data. Further, based on the learned code mapping relationship, the initial code compilation model performs compilation prediction on the source code sample data to obtain predicted compiled code and predicted performance feedback data. Secondly, based on the input target code sample data and performance feedback sample data, the current loss data of the initial code compilation model can be calculated. Finally, based on this loss data, the parameters of the initial code compilation model are adjusted to obtain a code compilation intermediate model.
[0082] Specifically, please refer to Figure 2 , in some embodiments, step S102 may include but is not limited to steps S201 to S205:
[0083] Step S201: Based on the initial code compilation model, compile the source code sample data to obtain predicted compiled code;
[0084] Step S202: Based on the hardware characteristic sample data, execute the predicted compiled code to obtain predicted performance feedback data;
[0085] Step S203: Based on the initial code compilation model, calculate the loss between the predicted compiled code and the target code sample data to obtain code loss data;
[0086] Step S204: Based on the initial code compilation model, calculate the loss for the prediction performance feedback data and the performance feedback sample data to obtain performance loss data.
[0087] Step S205: Based on the code loss data and the performance loss data, adjust the parameters of the initial code compilation model to obtain an intermediate code compilation model.
[0088] In step S201 of some embodiments, the predicted compiled code refers to the code data after compiling the source code sample data predicted by the initial code compilation model.
[0089] In the embodiments of the present application, the initial code compilation model can learn the code mapping relationship from the source code sample data to the target code sample data by learning the input source code sample data and target code sample data. Secondly, the initial code compilation model can perform operations such as code parsing and format conversion on the source code data to obtain the intermediate representation of the source code. Finally, the initial code compilation model can perform code mapping on the source code sample data according to the learned code mapping relationship from the source code sample data to the target code sample data to obtain the predicted compiled code.
[0090] Specifically, please refer to Figure 3 , in some embodiments, step S201 may include but is not limited to steps S301 to S304:
[0091] Step S301: Based on the initial code compilation model, learn the mapping relationship for the source code sample data and the target code sample data to obtain the code mapping relationship.
[0092] Step S302: Based on the initial code compilation model, perform code parsing on the source code sample data to obtain the code abstract syntax tree.
[0093] Step S303: Based on the initial code compilation model, perform format conversion on the code abstract syntax tree to obtain the intermediate code.
[0094] Step S304: Based on the initial code compilation model and the code mapping relationship, perform code mapping on the intermediate code to obtain the predicted compiled code.
[0095] In step S301 of some embodiments, the training target of the initial code compilation model can be set to learn the mapping relationship between the source code sample data and the target code sample data, so that the initial code compilation model actively learns the code mapping relationship from the source code sample data to the target code sample data.
[0096] In steps S302 and S303 of some embodiments, after the initial code compilation model changes the training objective to learning code compilation for source code sample data, the initial code compilation model can convert the source code sample data into an abstract syntax tree of the code by performing structured processing on the source code sample data. Further, for the convenience of code mapping processing, the abstract syntax tree of the code is converted into an intermediate representation of the source code, that is, intermediate code.
[0097] In step S304 of some embodiments, the initial code compilation model maps the above intermediate code to the compilation code space according to the learned code mapping relationship, thereby obtaining the predicted compilation code.
[0098] In steps S301 to S304 illustrated in this embodiment, the initial code compilation model maps the source code sample data to the predicted compilation code by learning the code mapping relationship from the source code sample data to the target code sample data, enabling the initial code compilation model to be applicable to the field of code compilation and improving the code compilation ability of the initial code compilation model.
[0099] In step S202 of some embodiments, the predicted performance feedback data refers to the performance feedback data of the hardware platform when the above predicted compilation code runs on the hardware platform.
[0100] In the embodiments of the present application, a corresponding hardware simulation platform can be constructed according to the input hardware characteristic sample data, and then the above predicted compilation code is executed on the hardware simulation platform to obtain the predicted performance feedback data.
[0101] Specifically, please refer to Figure 4 , in some embodiments, step S202 may include but is not limited to steps S401 to S402:
[0102] Step S401, constructing a hardware simulation platform based on the hardware characteristic sample data;
[0103] Step S402, dynamically running the predicted compilation code based on the hardware simulation platform to obtain the predicted performance feedback data.
[0104] In step S401 of some embodiments, the hardware simulation platform refers to a virtual hardware platform.
[0105] In the embodiments of the present application, the hardware characteristic sample data includes resource data, performance data, etc. of the hardware platform. Therefore, through the hardware characteristic sample data, a virtual platform can be constructed to run the above predicted compilation code, that is, the hardware simulation platform.
[0106] In step S402 of some embodiments, after the hardware simulation platform is constructed, the above-mentioned prediction compilation code is input into the corresponding hardware simulation platform. The hardware simulation platform dynamically runs the prediction compilation code and outputs the current hardware performance data, that is, the prediction performance feedback data.
[0107] In steps S401 to S402 illustrated in this embodiment, according to the hardware characteristic sample data, a hardware simulation platform is constructed, and then based on the hardware simulation platform, the prediction compilation code is dynamically run to obtain the prediction performance feedback data, which can realize the real-time test of the prediction compilation code output by the initial code compilation model, so as to understand the deficiencies of the prediction compilation code in real time.
[0108] In steps S203 and S204 of some embodiments, the code loss data is used to characterize the difference size between the prediction compilation code and the target code sample data. The performance loss data is used to characterize the difference size between the prediction performance feedback data and the performance feedback sample data.
[0109] In the embodiments of the present application, after the initial code compilation model obtains the prediction compilation code and the prediction performance feedback data, it calculates the difference between the input target code sample data and the prediction compilation code, that is, the code loss data, based on a pre-set code loss calculation function, and then calculates the difference between the input performance feedback sample data and the prediction performance feedback data, that is, the performance loss data, based on a pre-set performance loss calculation function.
[0110] In step S205 of some embodiments, by merging the above-mentioned code loss data and performance loss data, the total loss of the initial code compilation model, that is, the model total loss data, can be obtained. Then, based on the model total loss data, the parameters of the initial code compilation model are adjusted to obtain the code compilation intermediate model.
[0111] Specifically, please refer to Figure 5 In some embodiments, step S205 may include but is not limited to steps S501 to S503:
[0112] Step S501, based on the pre-set loss data weight ratio, data merge the code loss data and the performance loss data to obtain the model total loss data;
[0113] Step S502, based on the model total loss data, perform backpropagation on the initial code compilation model to obtain the model convergence parameters;
[0114] Step S503, based on the model convergence parameters, perform parameter substitution on the initial code compilation model to obtain the code compilation intermediate model.
[0115] In step S501 of some embodiments, the loss data weight ratio refers to the respective proportions of the code loss data and the performance loss data. The total model loss data is used to characterize the overall difference between the data predicted by the initial code compilation model and the actual data.
[0116] In the embodiments of the present application, according to the pre-set proportions of the code loss data and the performance loss data when calculating the model loss data, the above-mentioned code loss data and performance loss data are combined to obtain the loss data of the initial code compilation model, that is, the total model loss data.
[0117] In steps S502 and S503 of some embodiments, the model convergence parameter refers to the parameter value when the initial code compilation model reaches the convergence state when the total model loss data no longer changes significantly during the model training process.
[0118] In the embodiments of the present application, according to the calculated total model loss data, the gradients of each parameter in the initial code compilation model are calculated through the backpropagation algorithm, and the parameters of the initial code compilation model are updated using the optimization algorithm according to the calculated gradients, so as to obtain the model convergence parameter. Finally, when determining the model convergence parameter, the model convergence parameter at this time is saved as the final parameter of the initial code compilation model, thereby training the initial code compilation model into a code compilation intermediate model.
[0119] In steps S501 to S503 illustrated in this embodiment, according to the loss data weight ratio, the code loss data and the performance loss data are merged to obtain the total model loss data. Then, based on the total model loss data, backpropagation is performed on the initial code compilation model to obtain the model convergence parameter. Finally, according to the model convergence parameter, parameter substitution is performed on the initial code compilation model to obtain the code compilation intermediate model, so that the code compilation intermediate model can be applicable to the code compilation tasks of hardware platforms with different hardware characteristic data, thereby improving the efficiency of code compilation.
[0120] In steps S201 to S205 illustrated in this embodiment, using the pre-constructed initial code compilation model, the source code sample data is compiled to obtain the predicted compiled code. Then, according to the hardware characteristic sample data, the predicted compiled code is simulated to obtain the predicted performance feedback data. Further, according to the initial code compilation model, the loss between the predicted compiled code and the target code sample data is calculated to obtain the code loss data. According to the initial code compilation model, the loss between the predicted performance feedback data and the performance feedback sample data is calculated to obtain the performance loss data. Finally, according to the code loss data and the performance loss data, the parameters of the initial code compilation model are adjusted to obtain the code compilation intermediate model, so that the code compilation intermediate model can compile the source code into the target code, improving the accuracy of code compilation.
[0121] In step S103 of some embodiments, the target code compilation model refers to a model that can optimize the target code sample data according to the performance feedback sample data.
[0122] In the embodiments of the present application, by adding a reward mechanism to the code compilation model, when the code compilation intermediate model outputs prediction performance feedback data and solves the existing performance problems, it can obtain reward incentives, so that the code compilation intermediate model can output optimized compilation code, and then realize the transformation of the code compilation intermediate model into the target code compilation model.
[0123] Specifically, please refer to Figure 6 , in some embodiments, step S103 may include but is not limited to steps S601 to S603:
[0124] Step S601, based on the code compilation intermediate model, perform a reward evaluation on the performance feedback sample data to obtain feedback data reward information;
[0125] Step S602, based on the code compilation intermediate model, the performance feedback sample data, the hardware characteristic sample data, and the feedback data reward information, optimize the target code sample data to obtain optimized code data;
[0126] Step S603, based on the optimized code data, adjust the parameters of the code compilation intermediate model to obtain the target code compilation model.
[0127] In step S601 of some embodiments, the feedback data reward information refers to information used to guide the model to optimize the code performance.
[0128] In the embodiments of the present application, based on the existing parameters of the code compilation intermediate model, a reward function is added, and the performance feedback sample data is converted into a reward value according to the reward function, that is, the feedback data reward information.
[0129] In step S602 of some embodiments, the code optimization strategy of the code compilation intermediate model can be adjusted according to the feedback data reward information and the hardware characteristic sample data. For example, in the medical field, for a hardware platform sensitive to power consumption, the power consumption is optimized first, and for a memory-constrained platform, the memory occupancy is optimized first. Secondly, the code compilation intermediate model adjusts the previously output target code data according to the code optimization strategy, so as to obtain optimized code data.
[0130] In step S603 of some embodiments, during the process of outputting the optimized code data, the parameters in the code compilation intermediate model are continuously adjusted, so that the code compilation intermediate model can output more excellent optimized code data according to the source code data, thereby obtaining the target code compilation model.
[0131] In steps S601 to S603 illustrated in this embodiment, according to the intermediate model of code compilation, a reward evaluation is performed on the performance feedback sample data to obtain feedback data reward information. Secondly, according to the intermediate model of code compilation, the performance feedback sample data, the hardware characteristic sample data, and the feedback data reward information, code optimization is performed on the target code sample data to obtain optimized code data. Finally, according to the optimized code data, parameter adjustment is performed on the intermediate model of code compilation to obtain a target code compilation model, enabling the target code compilation model to directly compile source code data into optimized code data, thereby improving the stability of code compilation.
[0132] In step S104 of some embodiments, the target hardware refers to the hardware platform for which code compilation is required. The target hardware characteristic data refers to the hardware resource data, hardware performance data, etc. of the target hardware. The target source code data refers to the code data written in a programming language that needs to be compiled.
[0133] In the embodiments of the present application, the target hardware characteristic data and the target source code data of the target hardware can be obtained by querying the configuration file of the target hardware, the source code data repository, etc.
[0134] Specifically, please refer to Figure 7 In some embodiments, step S104 may include but is not limited to steps S701 to S703:
[0135] Step S701, information extraction is performed on a preset hardware configuration file to obtain hardware key information and code information;
[0136] Step S702, data standardization processing is performed on the hardware key information to obtain target hardware characteristic data;
[0137] Step S703, data cleaning is performed on the code information to obtain target source code data.
[0138] In step S701 of some embodiments, the hardware configuration file refers to the configuration file of the target hardware. The hardware key information refers to information such as the resources and performance of the target hardware. The code information refers to the source code data of the target hardware written in a programming language.
[0139] In the embodiments of the present application, by traversing the hardware configuration file of the target hardware, information such as the resources and performance of the target hardware can be read from the hardware configuration file, and by extracting the information such as the resources and performance, the hardware key information can be obtained. In addition, the source code data of the target hardware can also be read from the hardware configuration file, and by performing data extraction on the source code data, the code information of the target hardware can be obtained.
[0140] In steps S702 and S703 of some embodiments, operations such as data standardization, normalization, redundancy removal, and data format conversion are performed on the hardware key information to obtain target hardware characteristic data, and operations such as code separation and code cleaning are performed on the code information to obtain target source code data, which can improve the code compilation efficiency of the target code compilation model.
[0141] In steps S701 to S703 illustrated in this embodiment, by extracting information from the preset hardware configuration file, hardware key information and code information are obtained. Secondly, data standardization processing is performed on the hardware key information to obtain target hardware characteristic data. Finally, data cleaning is performed on the code information to obtain target source code data, enabling the target code compilation model to quickly understand the relevant information of the target hardware, thereby improving the code compilation efficiency of the target code compilation model.
[0142] In step S105 of some embodiments, the target compilation code refers to code data that can be understood by the target hardware and can be executed on the target hardware.
[0143] In the embodiments of the present application, after obtaining the target hardware characteristic data and the target source code data of the target hardware, the target hardware characteristic data and the target source code data are input into the above-mentioned trained target code compilation model. The target code compilation model can compile the target source code data into compilation code according to the learned code mapping relationship. Further, the target code compilation model adjusts the compilation code according to the input target hardware characteristic data to make the compilation code applicable to the target hardware, thereby obtaining the target compilation code.
[0144] This application obtains hardware characteristic sample data, source code sample data, object code sample data, and performance feedback sample data, and performs supervised learning on a pre-constructed initial code compilation model based on the hardware characteristic sample data, source code sample data, object code sample data, and performance feedback sample data to obtain a code compilation intermediate model, enabling the code compilation intermediate model to achieve the mapping from source code to object code, thereby reducing the participation of the compiler in the code compilation process and solving the problem that source code data on different hardware platforms requires different compilers, thus improving the code compilation efficiency. Secondly, based on the hardware characteristic sample data, object code sample data, and performance feedback sample data, reinforcement learning is performed on the code compilation intermediate model to obtain an object code compilation model, enabling the object code compilation model to compile source code data into code data that conforms to the characteristics of the hardware platform, reducing the post-compilation debugging process, thereby improving the stability and efficiency of code compilation. Finally, the target hardware characteristic data and target source code data of the target hardware are obtained, and based on the object code compilation model and the target hardware characteristic data, the target source code data is compiled to obtain target compilation code, enabling the object code compilation model to be applied in practice and ensuring the usability of the object code compilation model.
[0145] Please refer to Figure 8 , this embodiment of the application also provides a code compilation device that can implement the above code compilation method. The device includes:
[0146] A sample data acquisition module 801, configured to acquire hardware characteristic sample data, source code sample data, object code sample data, and performance feedback sample data. Among them, there is a code data mapping relationship between the source code sample data and the object code sample data. The object code sample data represents code data that can be executed in the hardware environment indicated by the hardware characteristic sample data, and the performance feedback sample data represents the hardware performance data generated when the object code sample data is executed in the hardware environment indicated by the hardware characteristic sample data;
[0147] A model supervised learning module 802, configured to perform supervised learning on a pre-constructed initial code compilation model based on the hardware characteristic sample data, source code sample data, object code sample data, and performance feedback sample data to obtain a code compilation intermediate model;
[0148] A model reinforcement learning module 803, configured to perform reinforcement learning on the code compilation intermediate model based on the hardware characteristic sample data, object code sample data, and performance feedback sample data to obtain an object code compilation model;
[0149] A target data acquisition module 804, configured to acquire the target hardware characteristic data of the target hardware and acquire the target source code data of the target hardware;
[0150] The model code compilation module 805 is configured to compile the target source code data based on the target code compilation model and the target hardware characteristic data to obtain the target compiled code, where the target compiled code represents the code that can be executed on the target hardware.
[0151] The specific implementation manner of this code compilation device is basically the same as that of the above-mentioned code compilation method, and will not be elaborated here.
[0152] An embodiment of this application also provides an electronic device, which includes a memory and a processor. The memory stores a computer program, and when the processor executes the computer program, it implements the above-mentioned code compilation method. This electronic device can be any intelligent terminal including a tablet computer, an in-vehicle computer, etc.
[0153] Please refer to Figure 9 , Figure 9 , which shows the hardware structure of the electronic device in another embodiment. The electronic device includes:
[0154] The processor 901 can be implemented by using a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, etc., and is configured to execute relevant programs to implement the technical solutions provided by the embodiments of this application;
[0155] The memory 902 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM), etc. The memory 902 can store an operating system and other application programs. When implementing the technical solutions provided by the embodiments of this specification through software or firmware, the relevant program codes are stored in the memory 902, and the processor 901 is called to execute the code compilation method of the embodiments of this application;
[0156] The input / output interface 903 is used to implement information input and output;
[0157] The communication interface 904 is used to implement communication interaction between this device and other devices, and can implement communication through a wired manner (such as USB, network cable, etc.) or through a wireless manner (such as mobile network, WIFI, Bluetooth, etc.);
[0158] The bus 905 transmits information between various components of the device (such as the processor 901, the memory 902, the input / output interface 903, and the communication interface 904);
[0159] Among them, the processor 901, the memory 902, the input / output interface 903, and the communication interface 904 are communicatively connected to each other inside the device through the bus 905.
[0160] An embodiment of the present application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the above-mentioned code compilation method is implemented.
[0161] As a non-transitory computer-readable storage medium, the memory can be used to store non-transitory software programs and non-transitory computer-executable programs. In addition, the memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one magnetic disk storage device, a flash memory device, or other non-transitory solid-state storage devices. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories can be connected to the processor through a network. Examples of the above-mentioned network include but are not limited to the Internet, an enterprise intranet, a local area network, a mobile communication network, and combinations thereof.
[0162] The code compilation method, code compilation device, electronic device, and storage medium provided by the embodiments of the present application obtain hardware characteristic sample data, source code sample data, target code sample data, and performance feedback sample data, and based on the hardware characteristic sample data, source code sample data, target code sample data, and performance feedback sample data, perform supervised learning on a pre-constructed initial code compilation model to obtain a code compilation intermediate model. Further, based on the hardware characteristic sample data, target code sample data, and performance feedback sample data, perform reinforcement learning on the code compilation intermediate model to obtain a target code compilation model. Finally, obtain target hardware characteristic data and target source code data of the target hardware, and perform code compilation on the target source code data according to the target code compilation model and the target hardware characteristic data to obtain target compilation code.
[0163] The embodiments described in the embodiments of the present application are for more clearly illustrating the technical solutions of the embodiments of the present application, and do not constitute a limitation on the technical solutions provided by the embodiments of the present application. Those skilled in the art can know that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by the embodiments of the present application are equally applicable to similar technical problems.
[0164] Those skilled in the art can understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than those shown in the figures, or combine certain steps, or different steps.
[0165] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0166] Those of ordinary skill in the art can understand that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices, can be implemented as software, firmware, hardware, and their appropriate combinations.
[0167] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of this application and the above-mentioned drawings are used to distinguish similar objects and do not necessarily describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances so that the embodiments of this application described here can be implemented in an order different from those illustrated or described here. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units does not necessarily limit to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products, or devices.
[0168] It should be understood that in this application, "at least one (item)" means one or more, and "multiple" means two or more. "And / or" is used to describe the association relationship of associated objects and indicates that three relationships can exist. For example, "A and / or B" can mean: only A exists, only B exists, and both A and B exist at the same time. Among them, A and B can be singular or plural. The character " / " generally means that the associated objects before and after are in an "or" relationship. "At least one (one) of the following" or a similar expression means any combination of these items, including any combination of single item (one) or plural items (ones). For example, at least one (one) of a, b, or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0169] In several embodiments provided by the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the above-mentioned units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. The displayed or discussed couplings or direct couplings or communication connections to each other can be through some interfaces. The indirect couplings or communication connections of devices or units can be in electrical, mechanical or other forms.
[0170] The units described above as separate components may or may not be physically separated. The components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0171] In addition, in each embodiment of the present application, the functional units can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above-mentioned integrated units can be implemented in the form of hardware or in the form of software functional units.
[0172] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or all or part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes multiple instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods in each embodiment of the present application. The foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical discs that can store programs.
[0173] The preferred embodiments of the embodiments of the present application have been described above with reference to the accompanying drawings, but this does not limit the scope of the rights of the embodiments of the present application. Any modifications, equivalent replacements, and improvements made by those skilled in the art without departing from the scope and essence of the embodiments of the present application shall be within the scope of the rights of the embodiments of the present application.
Claims
1. A code compilation method, characterized in that, The method includes: Obtaining hardware characteristic sample data, source code sample data, target code sample data, and performance feedback sample data, where there is a code data mapping relationship between the source code sample data and the target code sample data, the target code sample data represents code data that can be executed in the hardware environment indicated by the hardware characteristic sample data, and the performance feedback sample data represents the hardware performance data generated when the target code sample data is executed in the hardware environment indicated by the hardware characteristic sample data; Based on the hardware characteristic sample data, the source code sample data, the target code sample data, and the performance feedback sample data, performing supervised learning on a pre-constructed initial code compilation model to obtain an intermediate code compilation model; Based on the hardware characteristic sample data, the target code sample data, and the performance feedback sample data, performing reinforcement learning on the intermediate code compilation model to obtain a target code compilation model; Obtaining target hardware characteristic data of the target hardware and obtaining target source code data of the target hardware; Based on the target code compilation model and the target hardware characteristic data, performing code compilation on the target source code data to obtain target compiled code, where the target compiled code represents code that can be executed on the target hardware.
2. The method according to claim 1, wherein The performing supervised learning on a pre-constructed initial code compilation model based on the hardware characteristic sample data, the source code sample data, the target code sample data, and the performance feedback sample data to obtain an intermediate code compilation model includes: Based on the initial code compilation model, performing code compilation on the source code sample data to obtain predicted compiled code; Based on the hardware characteristic sample data, executing the predicted compiled code to obtain predicted performance feedback data; Based on the initial code compilation model, calculating a loss between the predicted compiled code and the target code sample data to obtain code loss data; Based on the initial code compilation model, calculating a loss between the predicted performance feedback data and the performance feedback sample data to obtain performance loss data; Based on the code loss data and the performance loss data, adjusting parameters of the initial code compilation model to obtain the intermediate code compilation model.
3. The method according to claim 2, characterized in that, The performing code compilation on the source code sample data based on the initial code compilation model to obtain predicted compiled code includes: Based on the initial code compilation model, learning a mapping relationship between the source code sample data and the target code sample data to obtain a code mapping relationship; Based on the initial code compilation model, parsing the source code sample data to obtain an abstract syntax tree of the code; Based on the initial code compilation model, performing format conversion on the abstract syntax tree of the code to obtain intermediate code; Based on the initial code compilation model and the code mapping relationship, performing code mapping on the intermediate code to obtain the predicted compiled code.
4. The method according to claim 2, characterized in that The performing simulation running on the predicted compiled code based on the hardware characteristic sample data to obtain predicted performance feedback data includes: Construct a hardware simulation platform based on the hardware characteristic sample data; Based on the hardware simulation platform, dynamically run the predictive compilation code to obtain the predictive performance feedback data.
5. The method according to claim 2, wherein The adjusting the parameters of the initial code compilation model based on the code loss data and the performance loss data to obtain the intermediate code compilation model includes: Based on a preset weight ratio of loss data, merge the code loss data and the performance loss data to obtain the total model loss data; Based on the total model loss data, perform backpropagation on the initial code compilation model to obtain model convergence parameters; Based on the model convergence parameters, perform parameter substitution on the initial code compilation model to obtain the intermediate code compilation model.
6. The method according to any one of claims 1-5, characterized in that, The enhancing the learning of the intermediate code compilation model based on the hardware characteristic sample data, the target code sample data, and the performance feedback sample data to obtain the target code compilation model includes: Based on the intermediate code compilation model, perform reward evaluation on the performance feedback sample data to obtain feedback data reward information; Based on the intermediate code compilation model, the performance feedback sample data, the hardware characteristic sample data, and the feedback data reward information, optimize the target code sample data to obtain optimized code data; Based on the optimized code data, adjust the parameters of the intermediate code compilation model to obtain the target code compilation model.
7. The method according to any one of claims 1-5, characterized in that, The obtaining the target hardware characteristic data of the target hardware and obtaining the target source code data of the target hardware includes: Extract information from a preset hardware configuration file to obtain hardware key information and code information; Perform data standardization processing on the hardware key information to obtain the target hardware characteristic data; Perform data cleaning on the code information to obtain the target source code data.
8. A code compilation device, characterized in that, The device includes: A sample data acquisition module, configured to acquire hardware characteristic sample data, source code sample data, target code sample data, and performance feedback sample data, wherein there is a code data mapping relationship between the source code sample data and the target code sample data, the target code sample data represents code data that can be executed in the hardware environment indicated by the hardware characteristic sample data, and the performance feedback sample data represents the hardware performance data generated when the target code sample data is executed in the hardware environment indicated by the hardware characteristic sample data; A model supervised learning module, configured to perform supervised learning on a pre-constructed initial code compilation model based on the hardware characteristic sample data, the source code sample data, the target code sample data, and the performance feedback sample data to obtain an intermediate code compilation model; A model reinforcement learning module, configured to perform reinforcement learning on the intermediate code compilation model based on the hardware characteristic sample data, the target code sample data, and the performance feedback sample data to obtain a target code compilation model; A target data acquisition module, configured to acquire the target hardware characteristic data of the target hardware and acquire the target source code data of the target hardware; A model code compilation module, which is used to compile the target source code data based on the target code compilation model and the target hardware characteristic data to obtain target compiled code, where the target compiled code represents code that can be executed on the target hardware.
9. An electronic device, characterized in that, The electronic device includes a memory and a processor. The memory stores a computer program, and when the processor executes the computer program, it implements the code compilation method according to any one of claims 1 to 7.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the code compilation method according to any one of claims 1 to 7.