Cross compiler training method and device, computer equipment and storage medium

Through deep learning models, the source code and machine code are preprocessed and cross-compiler trained, the problem of poor adaptability when cross-compiler adapts to new MCU architectures in the existing technology is solved, and more efficient development and safer machine code translation are achieved.

CN119668618APending Publication Date: 2025-03-21PING AN TECH (SHENZHEN) CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411733870.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-27
Publication Date
2025-03-21

AI Technical Summary

Technical Problem

When facing the new MCU architecture, existing cross compilers have poor adaptability, which leads to developers requiring a lot of manpower and time to adapt and develop, reducing development efficiency and increasing costs.

Method used

Through a cross-compiler training method, the source code and machine code are preprocessed using deep learning models, source vectors and machine vectors are generated, and the deep learning model is trained through these vectors, and the model parameters are optimized to obtain the target cross-compiler, adapting to a variety of MCU architectures.

Benefits of technology

It improves the adaptability and accuracy of cross-compilers, reduces the adaptation cost to the new MCU architecture, improves development efficiency, and ensures the accuracy and security of translated machine code in financial payment terminals, financial transaction terminals and transaction equipment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119668618A_ABST
    Figure CN119668618A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of artificial intelligence, and discloses a cross compiler training method and device, computer equipment and a storage medium. A first source code is used as a training sample, and a first machine code corresponding to the first source code is confirmed according to an MCU architecture identifier, so that the first machine code is used for marking the first source code; taking a first source vector and a first machine vector corresponding to the first source code and the first machine code as samples to be input into a deep learning model; a first loss value is calculated based on the first source code and the first machine code, the first loss value is used for optimizing and adjusting model parameters of a deep learning model, source code translation modes in different MCU architectures are learned, and a target cross compiler is obtained so as to cope with the incompatibility condition of the cross compiler generated when a novel MCU architecture appears, and the compatibility of the cross compiler is improved. The suitability and the accuracy of the cross compiler are improved, so that the accuracy and the safety of translated machine codes in the financial field are ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a cross-compiler training method, device, computer equipment and storage medium. Background Art

[0002] MCU (Microcontroller Unit) is a monolithic integrated circuit that integrates a microprocessor core, memory, input / output interfaces and other peripherals. It is usually used as the main controller in embedded systems to control and execute various tasks. It is widely used in the Internet of Things, automotive, medical equipment, and financial fields.

[0003] Since the MCU needs to perform specific functions and tasks through instructions corresponding to machine code (low-level programming language), when a certain MCU needs to be operated, a compiler is required to translate the source code (high-level programming language) used by the programmer into an executable file consisting of machine code that can be directly executed by a computer, virtual machine or integrated circuit, so that the device can perform corresponding operations according to the instruction sequence in the machine code and realize the functions defined in the source code.

[0004] Especially in the financial field, the requirements for security and reliability are very high. Therefore, when developing and using MCU cross-compilers, it is necessary to strictly follow relevant safety standards and best practices to ensure the correctness and security of the software, and then apply it to financial payment terminals, financial transaction terminals and transaction equipment.

[0005] In the prior art, since there are multiple MCU architectures on the market, cross-compilers are usually used to facilitate the handling of multiple MCU architectures, so that developers can compile the code into multiple executable files suitable for the target architecture after writing it. At present, new MCU architectures emerge in an endless stream, and after the new MCU architecture appears, developers need to rewrite the cross-compiler for the MCU architecture to adapt to the complex development environment, thereby consuming a lot of manpower and time costs. Therefore, when targeting the new MCU architecture, the existing cross-compiler can only be adapted and developed again by the developers for the MCU architecture, thereby reducing development efficiency and increasing development costs. As can be seen from the above, when targeting the new MCU architecture, the existing cross-compiler has the problem of poor adaptability. Summary of the invention

[0006] The embodiments of the present invention provide a cross-compiler training method, apparatus, computer equipment and storage medium, which solve the problem of poor adaptability of existing cross-compilers when targeting a new MCU architecture.

[0007] An embodiment of the present invention provides a cross-compiler training method, comprising: Get raw text data and speaker identification; According to the original text data, obtaining an original text vector and an original phoneme vector; Performing text enhancement processing on the original text vector to obtain a target text vector; Performing pitch enhancement processing on the original phoneme vector to obtain a target pitch vector; Based on the speaker identifier, obtaining a target voiceprint vector corresponding to the speaker identifier; Concatenating the target text vector, the target tone vector, and the target voiceprint vector to obtain a target latent vector; A cross-compiler is trained according to the target latent vector to obtain a target cross-compiler corresponding to the speaker identifier.

[0008] The embodiment of the present invention also provides a source code cross-compilation method, comprising: Get the target source code; Based on the target cross compiler in the above method, the target source code is translated to obtain the target machine code.

[0009] The embodiment of the present invention also provides a cross-compiler training device, comprising: A first source code acquisition module, used to acquire a first source code and an MCU architecture identifier; A first machine code acquisition module, configured to acquire a first machine code corresponding to the first source code according to the MCU architecture identifier; a code preprocessing module, configured to preprocess the first source code and the first machine code to obtain a first source vector corresponding to the first source code and a first machine vector corresponding to the first machine code; A first loss value acquisition module, used for inputting the first source vector and the first machine vector into a deep learning model to acquire a first loss value; A target cross-compiler acquisition module is used to optimize and adjust the model parameters of the deep learning model according to the first loss value to obtain a target cross-compiler.

[0010] An embodiment of the present invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned cross-compiler training method when executing the computer program, or implements the above-mentioned source code cross-compilation method when executing the computer program.

[0011] An embodiment of the present invention also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the above-mentioned cross-compiler training method, or when the processor executes the computer program, it implements the above-mentioned source code cross-compilation method.

[0012] The above-mentioned cross-compiler training method, device, computer equipment and storage medium use the first source code as a training sample, confirm the first machine code corresponding to the first source code according to the MCU architecture identifier, and use the first machine code to annotate the first source code; after preprocessing the first source code and the first machine code, the first source vector and the first machine vector are obtained as samples to input into the deep learning model for training the deep learning model; finally, the first source code is translated based on the first source code, and the first loss value is calculated according to the first machine code, and the first loss value is used to optimize and adjust the model parameters of the deep learning model, learn the source code translation method in different MCU architectures, and obtain the target cross compiler. The target cross compiler is used to cope with the incompatibility of the cross compiler generated when the new MCU architecture appears, improve the adaptability and accuracy of the cross compiler, and ensure the accuracy and security of the machine code translated by the target cross compiler in financial payment terminals, financial transaction terminals and transaction equipment. BRIEF DESCRIPTION OF THE DRAWINGS

[0013] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.

[0014] Figure 1 is a schematic diagram of an application environment of a cross-compiler training method in one embodiment of the present invention; Figure 2 is a flow chart of a cross-compiler training method in one embodiment of the present invention; Figure 3 is a flowchart of step S202 of the cross-compiler training method in one embodiment of the present invention; Figure 4 is a flowchart of step S204 of the cross-compiler training method in one embodiment of the present invention; Figure 5 is a flowchart of step S205 of the cross-compiler training method in one embodiment of the present invention; Figure 6 is a flowchart of step S501 of the cross-compiler training method in one embodiment of the present invention; Figure 7is a flowchart of step S503 of the cross-compiler training method in one embodiment of the present invention; Figure 8 is a flow chart of a source code cross-compilation method in one embodiment of the present invention; Fig. 9 is a schematic diagram of a cross compiler training device in one embodiment of the present invention; Fig.10 is a schematic diagram of a computer device in one embodiment of the present invention. DETAILED DESCRIPTION

[0015] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0016] The cross compiler training method provided by the embodiment of the present invention can be applied in Figure 1 In the application environment shown. Figure 1 As shown, the client (computer device) communicates with the server through the network. The client, also known as the user end, refers to the program corresponding to the server that provides local services to the client. The client (computer device) includes but is not limited to various personal computers, laptops, smart phones, tablets, cameras and portable wearable devices. The server can be an independent server or a cloud server that provides 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, content delivery networks (CDN), and big data and artificial intelligence platforms.

[0017] The cross-compiler training method provided by the embodiment of the present invention can be applied as follows: Figure 1 Specifically, the cross-compiler training method is applied in a source code cross-compilation system, and the source code cross-compilation system includes: Figure 1 The client and server shown communicate with each other through a network to process source code to train a deep learning model, obtain a corresponding target cross-compiler, and improve the applicability and portability of source code cross-compilation.

[0018] In this example, in the financial field, cross-compilers are usually used in the following directions: financial payment terminals (such as POS terminals) are usually based on embedded systems and MCU architectures. Through cross-compilers, the software developed for payment terminals is translated into machine code suitable for specific MCU architectures; security modules in the financial field (such as encryption chips) are also usually based on MCU architectures to achieve security functions and data protection. Through cross-compilers, the software developed for security modules is compiled into machine code suitable for specific MCUs; financial transaction equipment (such as ATMs, transaction terminals, etc.) are based on embedded systems and MCU architectures. Through cross-compilers, the developed software is compiled into machine code suitable for specific MCU architectures.

[0019] In one embodiment, if Figure 2 As shown, a cross compiler training method is provided, which is applied in Figure 1 The server in the example is used as an example to illustrate the process, including the following steps: S201: Obtain a first source code and an MCU architecture identifier; S202: Acquire a first machine code corresponding to the first source code according to the MCU architecture identifier; S203: Preprocess the first source code and the first machine code to obtain a first source vector corresponding to the first source code and a first machine vector corresponding to the first machine code; S204: Inputting the first source vector and the first machine vector into the deep learning model to obtain a first loss value; S205: Optimize and adjust model parameters of the deep learning model according to the first loss value to obtain a target cross-compiler.

[0020] As an example, in step S201, the server provides a sample set for the subsequent deep learning model based on the first source code preset by the developer and a certain MCU architecture identifier among multiple MCU architectures. In this example, the corresponding MCU architecture of its application is confirmed according to the different devices used, and used as the MCU architecture identifier. In another example, the corresponding MCU architecture identifier can also be selected according to the difference in specific businesses. For example, when a security module (such as an encryption chip) is applied in the financial field, the MCU architecture identifier corresponding to the business is selected, and the source code corresponding to the software developed in the security module is used as the first source code.

[0021] It is understandable that the machine code corresponding to the executable file after the source code is translated is different in different MCU architectures, that is, according to the MCU architecture identifier corresponding to the MCU architecture to be translated, the machine code corresponding to the source code in the MCU architecture is obtained. Among them, common MCU architectures include but are not limited to the following: ARM (Advanced RISC Machines) architecture, PIC (Peripheral Interface Controller) architecture, MSP430 (Mixed Signal Processor 430) architecture, 8051 architecture (Intel 8051) and x86_64 architecture.

[0022] In this example, the first source code is a high-level programming language used by developers. A high-level programming language is a developer-readable programming language used to write computer programs at a high level of abstraction. Compared with machine language or low-level language, a high-level programming language is closer to natural language and easier to understand and write. In this example, the demonstrated high-level programming language is python, among which common high-level programming languages ​​include but are not limited to python, C language, C++ and javascript.

[0023] It should be noted that the first source code is not limited to a section of code, but can also represent source code data, and in this example, the number of first source codes is not limited.

[0024] As an example, in step S202, after acquiring the first source code and the MCU architecture identifier, the server matches the first source code to the first machine code corresponding to the MCU architecture according to the MCU architecture identifier.

[0025] Preferably, for different MCU architecture identifiers, the machine codes corresponding to different MCU architectures are output using multi-tasking. By simultaneously predicting the machine codes of multiple MCU architectures, the model can learn the commonalities and differences between different MCU architectures, thereby improving the generalization and transfer learning capabilities of the model, and improving the adaptability of the model when facing unknown MCU architectures.

[0026] In this example, the python code as the first source code can be translated into the first machine code corresponding to the MCU architecture through an existing compiler, and then the corresponding first machine code can be annotated to the first source code; the corresponding source code and machine code can also be retrieved from the corresponding information library to match and annotate them with the first source code; the first source code can also be matched and annotated one by one with the corresponding first machine code manually. Among them, the examples corresponding to the matched first source code and the first machine code are as follows: when the MCU architecture is identified as the x86_64 architecture, according to the sub function in the python code of the first source code, the corresponding first machine code is matched to 0100100B1000001.

[0027] In this example, financial payment terminals, financial transaction terminals and transaction equipment in the financial field usually use ARM architecture, x86 architecture and MIPS architecture, etc. According to the MCU architecture identifier corresponding to the business, the machine code of the corresponding business under its corresponding architecture is generated as the first machine code.

[0028] As an example, in step S203, after obtaining the first source code and the first machine code corresponding to the first source code, the server will preprocess the first source code and the first machine code to obtain vectors for model recognition, which are encoded into a first source vector corresponding to the first source code and a first machine vector corresponding to the first machine code, respectively.

[0029] In this example, according to the deep learning model used, the input first source code and the first machine code can be encoded through the input layer of the deep learning model, and the encoding method used is selected according to specific needs, including but not limited to the following: tokenization, word embedding, and sequence encoding.

[0030] As an example, in step S204, the server uses the preprocessed first source vector and the first machine vector as sample data and inputs them into the constructed deep learning model, and outputs the first loss value obtained by the loss function through the deep learning processing of the first source vector and the first machine vector for use in deep learning model adjustment.

[0031] In this example, the deep learning model used is the transform model. The adaptability and relevance of the multi-head attention mechanism based on the transform model are conducive to better capturing the association between the input source code and the machine code corresponding to different MCU architectures. This embodiment provides the transform model as an example, and other deep learning models can also be selected, including but not limited to Long Short-Term Memory (LSTM), Convolutional Neural Networks (CNNs), Recurrent Neural Networks (RNNs) and Generative Adversarial Networks (GANs).

[0032] Preferably, the deep learning model used in this embodiment can be deployed on the corresponding server in the cloud or on the end side. In this example, by deploying the deep learning model on the end side, the end side has the following advantages: 1) The collected data can be processed in the first time without uploading it to the processing center on the cloud side through the network, which greatly speeds up the system response and reduces the system processing delay; 2) The end-side calculation can process valuable key data more efficiently, and the rest of the data is only temporary. Combining the capabilities of the deep learning model on the end side can not only process data more timely, but also reduce the limitations of network bandwidth and relieve the pressure on data storage at the center; 3) The deep learning model on the end side can efficiently process the user's source data, clean and protect some sensitive data, and the end-side device only reports the results processed by the deep learning model to the cloud.

[0033] As an example, in step S205, after obtaining the first loss value output by the deep learning model, the server optimizes and adjusts the model parameters of the deep learning model according to the first loss value, and after the loss value or the number of training iterations reaches a threshold, obtains the trained deep learning model as a target cross-compiler for subsequent source code translation.

[0034] In this example, the Transformer is trained. The training formula is as follows: in, represents the best parameters, that is, the optimized model parameters; L represents the loss function; Represents the first prediction result of the model output, where represents the first source vector of the input; represents the real first machine vector corresponding to the first source vector; argmin represents the loss function taken during the iteration process The minimum loss value, that is, the minimum loss function .

[0035] Therefore, by minimizing the loss function , you can adjust the parameters of the Transformer model , so that it is the first source vector given the input and the corresponding first machine vector to achieve better prediction performance.

[0036] In this example, the first source code is used as a training sample, and the first machine code corresponding to the first source code is confirmed according to the MCU architecture identifier, so that the first machine code is used to annotate the first source code; after preprocessing the first source code and the first machine code, the first source vector and the first machine vector are obtained as samples to input into the deep learning model for training the deep learning model; finally, the first source code is translated, and the first loss value is calculated according to the first machine code, and the first loss value is used to optimize and adjust the model parameters of the deep learning model, learn the source code translation method in different MCU architectures, and obtain the target cross compiler. The target cross compiler is used to cope with the incompatibility of the cross compiler generated when the new MCU architecture appears, improve the adaptability and accuracy of the cross compiler, and ensure the accuracy and security of the machine code translated by the target cross compiler in financial payment terminals, financial transaction terminals and transaction equipment.

[0037] In one embodiment, if Figure 3 As shown, in step S202, according to the MCU architecture identifier, a first machine code corresponding to the first source code is obtained, including: S301, normalize the first source code to obtain a first standard code; S302: According to the MCU architecture identifier, a first standard code is matched to obtain a first machine code corresponding to the first standard code.

[0038] As an example, in step S301, after obtaining the first source code, the server normalizes the first source code to obtain a first normalized code corresponding to the normalization.

[0039] Among them, the normalization process usually includes segmenting and combing the first source code, thereby controlling the computational complexity of subsequent deep learning model learning, reducing the computational load of model training and inference, and making the model easier to train and deploy. At the same time, it can also improve the generalization ability of the model, prevent a large amount of redundant or irrelevant information from appearing in subsequent training data, and make the model more focused on key contextual information.

[0040] In this example, the input first source code, that is, the input python code, is combed and segmented to obtain the corresponding first standard code. The combing includes but is not limited to removing comments and standardizing indentation, and segmenting the python code by segmenting it into functions. The number of lines and character length of the python code can also be limited by presetting the corresponding character length and number of lines of code, for example, the number of lines of code is preset to be between 1 and 50 lines, and the character length of each line of code does not exceed 128 bytes.

[0041] As an example, in step S302, after normalizing the first source code, the server confirms the corresponding MCU architecture that needs to be translated according to the MCU architecture identifier, and obtains the first machine code of the first standard code by matching the first machine code corresponding to the MCU architecture. The first machine code and the first source code can be composed of a sample pair as a training sample for model training, or the first machine code can be used as a label corresponding to the first source code as a training sample for model training. The specific selection can be made according to different training methods, and is not limited again.

[0042] In this example, the first source code is normalized to control the computational complexity of subsequent deep learning model learning, thereby improving the generalization ability of the model; then, based on the normalized first standard code and the MCU architecture identifier, the actual first machine code under the corresponding MCU architecture is matched to complete the supervised training of the deep learning model.

[0043] In one embodiment, if Figure 4 As shown, in step S204, the first source vector and the first machine vector are input into the deep learning model to obtain a first loss value, including: S401, inputting the first source vector into an encoder of a deep learning model to obtain a first hidden representation; S402, inputting the first hidden representation into a decoder of a deep learning model to obtain a first prediction result; S403. Obtain a first loss value according to the first prediction result and the first machine vector.

[0044] It can be understood that the transformer model used in this embodiment generally has the following structure: input layer, encoder, decoder and output layer. The encoder and decoder are based on the self-attention mechanism. In this example, the encoder and decoder each have 6 layers, where the multi-head attention includes 16 attention heads, and the number of hidden layer units of each attention is 256.

[0045] As an example, in step S401, the server inputs the preprocessed first source vector into the encoder in the deep learning model, and based on the multi-head self-attention mechanism (Multi-Head Self-Attention) in the multi-layer encoder, performs self-attention calculation on the position of each vector in the input first source vector with other positions, captures the dependency within the input sequence, and outputs the encoded multi-dimensional vector as the first hidden representation.

[0046] As an example, in step S402, the server inputs the encoded first hidden representation into the decoder of the deep learning model, and performs attention calculation on the first hidden representation output by the encoder based on the multi-head self-attention mechanism (Multi-Head Self-Attention) in the multi-layer decoder. The decoder combines the output layer to map the calculated first hidden representation to the vocabulary space and obtains the predicted machine code, which is the first prediction result.

[0047] As an example, in step S403, after decoding and outputting the first hidden representation, the server obtains a first prediction result, and uses a corresponding loss function to calculate the loss between the first prediction result and the true first machine vector to obtain a calculated first loss value. Common loss functions include cross entropy loss, mean square error, etc.

[0048] In this example, by using the formula Calculate the first loss value, where L represents the loss function; Represents the first prediction result of the model output, where represents the first source vector of the input; Represents the actual first machine vector corresponding to the first source vector, and the loss value output by the formula is the first loss value.

[0049] In this example, the encoder of the deep learning model composed of multiple layers of encoders and decoders encodes and decodes the first source vector based on the attention mechanism, and outputs it to complete the first prediction result predicted according to the first source vector. The loss value between the first prediction result and the first source vector compiled in the MCU architecture is calculated for the subsequent optimization of the deep learning model.

[0050] In one embodiment, if Figure 5 As shown, in step S205, according to the first loss value, the model parameters of the deep learning model are optimized and adjusted to obtain a target cross compiler, including: S501. According to the first loss value, adjust the initial model parameters corresponding to the deep learning model to obtain a first cross-compiler; S502, preprocessing the second source code to obtain a second source vector corresponding to the second source code; S503: Based on the second source vector, optimize and train the first cross compiler to obtain a target cross compiler.

[0051] For the transformer model used in the example, the training parameters of the model are defined according to the business details during construction. In this example, the Adam optimizer is selected and the learning rate is set to 0.001. The optimizer is used to adjust the model parameters to minimize the loss function. According to the hardware settings of the training device, the batch size is set to 64, and the number of training iterations (epochs) is set, for example, 100.

[0052] As an example, in step S501, after obtaining the first loss value, the server adjusts the initial model parameters corresponding to the deep learning model according to the first loss value, and uses the adjusted deep learning model as the first cross-compiler.

[0053] In this another example, if the preset several first source codes, that is, using an existing high-level programming language, such as Python, as the first source code, the machine language (executable file) corresponding to the existing multiple MCU architectures is trained according to the preset training parameters to obtain the first cross-compiler, then the first cross-compiler is used as the target cross-compiler.

[0054] As an example, in step S502, after obtaining the first cross-compiler, if the second source code exists, the server preprocesses the second source code and obtains a second source vector corresponding to the second source code. The second source code is a high-level programming language used by a new MCU architecture, that is, when a new MCU architecture appears, the second source code is used to optimize and adjust the trained first cross-compiler.

[0055] In this example, the preprocessing of the second source code is the same as that of the first source code. The second source code is normalized and then encoded, that is, the second source code is processed through the input layer of the deep learning model.

[0056] As an example, in step S503, the server performs optimization training on the first cross-compiler according to the preprocessed second source vector to update the model parameters of the first cross-compiler, and uses the updated first cross-compiler as the target cross-compiler.

[0057] In this example, after the first cross-compiler is obtained based on the first source code and the first machine code training, if a new MCU architecture appears later, it is only necessary to input the second source code under the new MCU architecture without matching the machine code, thereby performing unsupervised or self-supervised training on the first cross-compiler. In this example, according to the first loss value obtained by the first prediction result and the first source vector, the initial model parameters corresponding to the deep learning model are adjusted through the corresponding training parameters, so as to obtain a first cross-compiler that can be used for source code translation; after obtaining the second source code corresponding to the new MCU architecture, the second source code is preprocessed and used to perform optimization training on the first cross-compiler to obtain the final target cross-compiler, so as to cope with the accurate translation of the source code when adapting to multiple MCU architectures.

[0058] In one embodiment, if Figure 6 As shown, in step S501, according to the first loss value, the initial model parameters corresponding to the deep learning model are adjusted to obtain a first cross compiler, including: S601. Update initial model parameters of the deep learning model according to the first loss value and the optimizer of the deep learning model to obtain a first iterative model; S602: If the first iteration model reaches a preset target condition, the first iteration model is used as a first cross-compiler.

[0059] As an example, in step S601, after obtaining the first loss value according to the first mechanical vector and the first prediction result, the server adjusts the initial model parameters of the deep learning model according to the optimizer preset in the training parameters to obtain the first iterative model after this adjustment. According to the value of the first loss value, the existing minimum loss value is compared to determine whether to use it to update the initial model parameters.

[0060] In this embodiment, according to the input of multiple or multiple first source codes, the processing is performed based on the first source code, and according to the processed first loss value, the deep learning model is iterated to complete the acquisition of the optimal model parameters, and the first iterative model is continuously updated according to the training parameter update. Among them, the first iterative model is the deep learning model after the initial adjustment. If the optimal model parameters are obtained after the subsequent acquisition, the first iterative model is updated, that is, the updated iterative model can be called the second iterative model, and can also continue to be called the first iterative model. The first and second are not a limitation.

[0061] Furthermore, by using the formula , to update the initial model parameters, where represents the best parameters, that is, the optimized model parameters; L represents the loss function; Represents the first prediction result of the model output, where represents the first source vector of the input; represents the real first machine vector corresponding to the first source vector; argmin represents the loss function taken during the iteration process The minimum loss value, that is, the minimum loss function .

[0062] As an example, in step S602, the server trains the first iterative model according to the preset target conditions in the preset training parameters. When the first iterative model reaches the preset target conditions, the first iterative model is used as the first cross-compiler.

[0063] In this example, 100 epochs is used as the preset target condition, and the preset target condition can also be a loss value threshold, which is not limited here. According to the preset training parameters, based on the first loss value and the optimizer, the back propagation algorithm is used to update the model parameters of the first iterative model until the number of iterations specified by the preset target condition is completed.

[0064] In another example, if the first source code and the first machine code under several existing MCU architectures are trained to a certain extent (when no new MCU architecture appears), the trained first cross-compiler is used as the target cross-compiler for converting the source code into machine code.

[0065] In this example, through the first loss value and the optimizer of the deep learning model, after confirming the first loss value, the initial model parameters of the deep learning model are updated to obtain a first iterative model trained by the first source vector; according to the preset target conditions of the training parameters, the first iterative model is iterated multiple times. When the preset target conditions are reached, the first iterative model of this iteration is used as the first cross-compiler, thereby optimizing the deep learning model based on the supervised training of the first source code to obtain a first cross-compiler with high accuracy.

[0066] In one embodiment, if Figure 7 As shown, in step S503, based on the second source vector, the first cross compiler is optimized and trained to obtain a target cross compiler, including: S701, inputting the second source vector into the first cross compiler to obtain a second prediction result; S702, performing loss calculation on the second source vector and the second prediction result to obtain a second loss value; S703: Adjust the first cross-compiler according to the second loss value to obtain a target cross-compiler.

[0067] As an example, in step S701, after preprocessing the second source code, the server inputs the preprocessed second source vector into the first cross compiler, and after being processed by the decoder and encoder of the first cross encoder, a second prediction result predicted by the first cross encoder is obtained.

[0068] As an example, in step S702, the server calculates a loss based on the second prediction result generated by the first cross encoder and the input second source code, and obtains a second loss value for adjusting the model parameters of the first cross compiler, that is, performing unsupervised or self-supervised learning based on the second source code, thereby optimizing the first cross compiler.

[0069] In this example, when unsupervised learning is performed on the first cross compiler based on the second source code, the second source code can be input into the trained Transformer model to generate a second prediction result of the machine code, and the reconstruction loss is calculated based on the consistency between the generated second prediction result and the second source code, and the model parameters are updated through back propagation and optimization algorithms.

[0070] In another example, when self-supervising learning is performed on the first cross compiler based on the second source code, some intrinsic structure or characteristics in the second source code can be used to generate auxiliary tasks, such as transforming the second source code by masking, partial occlusion, position prediction, etc., and then using the consistency between the transformed source code and the second source code as a training signal. The transformed source code is input into the trained Transformer model to generate a second prediction result of the machine code, which is compared with the second source code to calculate the loss. The model parameters are updated through back propagation and optimization algorithms so that the model can learn useful features of the source code.

[0071] As an example, in step S703, after obtaining the second loss value, the server adjusts the first cross-compiler according to the second loss value and the preset training parameters to obtain the final target cross-compiler, and completes the optimization adjustment of the first cross-compiler after the new MCU architecture appears.

[0072] In this example, when a new MCU architecture appears, the second source vector corresponding to the new MCU architecture is input into the first cross-compiler to obtain a second prediction result, and the loss calculation is performed on the second source vector and the second prediction result to perform unsupervised or self-supervised training on the first cross-compiler, and the first cross-compiler is optimized and adjusted according to the second loss value corresponding to the loss calculation to obtain the final target cross-compiler. Among them, the target cross-compiler has better adaptability and can translate source code for various MCU architectures. At the same time, the second source code corresponding to the new MCU architecture is used for unsupervised or self-supervised learning, which also reduces development costs and improves development efficiency.

[0073] In another embodiment, if Figure 8 As shown, a source code cross-compilation method is provided, which is applied in Figure 1 The server in the example is used as an example to illustrate the process, including the following steps: S801, obtaining target source code; S802: Based on the target cross compiler in the above method, the target source code is translated to obtain the target machine code.

[0074] As an example, in step S801, the server receives the target source code input by the user, and the target source code is a high-level programming language, including but not limited to Python, C language and JavaScript in this example.

[0075] In this example, the user can enter the target MCU architecture identifier for subsequent generation of an executable file (machine code) representing the corresponding MCU architecture, and can also select from the executable files corresponding to the generated multiple MCU architectures. In another example, the user can also confirm the corresponding target MCU architecture based on the input of a preset business, for example, the preset business is the translation of the target source code corresponding to the software developed for financial transaction equipment (such as ATMs, transaction terminals, etc.), and the target MCU architecture identifier is confirmed based on the preset business for subsequent translation of the target source code corresponding to the developed software into the target machine code.

[0076] As an example, in step S802, the server translates the target source code according to the received target source code based on the trained target cross compiler, thereby obtaining the target machine code corresponding to each MCU architecture for user confirmation.

[0077] In this example, it is also possible to directly translate into the corresponding target machine code according to the target MCU architecture. For example, according to the MCU architecture corresponding to the financial transaction equipment (such as ATMs, transaction terminals, etc.), the translated target machine code is obtained to meet the high standards for security and reliability in the financial field, and the translated target machine code is burned into the corresponding financial transaction equipment for execution.

[0078] In this example, the Transformer-based cross-compiler that can be used for different MCU architectures is different from the previous professionals who wrote translators for adapted MCU architectures. It only needs to input the target source code, such as Python code, into the Transformer-based target cross-compiler to generate the corresponding target machine code. The present invention is used on the edge side, and the target cross-compiler for different MCU architectures can solve the problem of cumbersome operation and cross adaptability of existing cross-compilers when the source code is compiled into MCUs of different architectures in terminal devices.

[0079] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.

[0080] In one embodiment, a cross-compiler training device is provided, and the cross-compiler training device corresponds one-to-one to the cross-compiler training method in the above embodiment. Fig. 9 As shown, the cross-compiler training device includes a first source code acquisition module 901, a first machine code acquisition module 902, a code preprocessing module 903, a first loss value acquisition module 904 and a target cross-compiler acquisition module 905. The functional modules are described in detail as follows: A first source code acquisition module 901, used to acquire a first source code and an MCU architecture identifier; A first machine code acquisition module 902 is used to acquire a first machine code corresponding to the first source code according to the MCU architecture identifier; A code preprocessing module 903, configured to preprocess the first source code and the first machine code to obtain a first source vector corresponding to the first source code and a first machine vector corresponding to the first machine code; A first loss value acquisition module 904, used to input the first source vector and the first machine vector into the deep learning model to obtain a first loss value; The target cross-compiler acquisition module 905 is used to optimize and adjust the model parameters of the deep learning model according to the first loss value to acquire the target cross-compiler.

[0081] In one embodiment, the first machine code acquisition module 902 includes: A first standard code acquisition unit, used for performing standardization processing on the first source code to acquire a first standard code; The first machine code acquisition unit is used to match the first standard code according to the MCU architecture identifier to acquire the first machine code corresponding to the first standard code.

[0082] In one embodiment, the first loss value obtaining module 904 includes: A first hidden representation acquisition unit, configured to input the first source vector into an encoder of the deep learning model to acquire a first hidden representation; A first prediction result obtaining unit, configured to input the first hidden representation into a decoder of the deep learning model to obtain a first prediction result; The first loss value acquisition unit is used to acquire a first loss value according to the first prediction result and the first machine vector.

[0083] In one embodiment, the target cross-compiler acquisition module 905 includes: A first cross-compiler acquisition unit, configured to adjust initial model parameters corresponding to the deep learning model according to the first loss value, and acquire a first cross-compiler; A second source vector obtaining unit, configured to preprocess the second source code to obtain a second source vector corresponding to the second source code; The target cross-compiler acquisition unit is used to perform optimization training on the first cross-compiler based on the second source vector to acquire the target cross-compiler.

[0084] In one embodiment, the first cross-compiler acquisition unit includes: A first iterative model acquisition subunit, used to update initial model parameters of the deep learning model according to the first loss value and the optimizer of the deep learning model, and acquire a first iterative model; The first cross-compiler acquisition subunit is used to use the first iterative model as the first cross-compiler if the first iterative model meets the preset target condition.

[0085] In one embodiment, the target cross compiler acquisition unit includes: A second prediction result acquisition subunit, used for inputting the second source vector into the first cross compiler to acquire a second prediction result; A second loss value obtaining subunit, used to perform loss calculation on the second source vector and the second prediction result to obtain a second loss value; The target cross-compiler acquisition subunit is used to adjust the first cross-compiler according to the second loss value to acquire the target cross-compiler.

[0086] In another embodiment, a speech synthesis device is provided, which corresponds one-to-one to the cross-compiler training method in the above embodiment, including: A target source code acquisition module is used to acquire the target source code; The target machine code acquisition module is used to translate the target source code based on the target cross compiler in the above method to obtain the target machine code.

[0087] The specific definition of the cross-compiler training device can be found in the definition of the cross-compiler training method above, which will not be repeated here. Each module in the above-mentioned cross-compiler training device can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.

[0088] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Fig.10 As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to execute the data used or generated during the cross-compiler training method. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a cross-compiler training method is implemented.

[0089] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the cross-compiler training method in the above embodiment is implemented, for example Figure 2 S201-S207 as shown, or Figures 3 to 7 As shown in , a computer program that can also be run on a processor, when the processor executes the computer program, the cross-compilation method of the source code is implemented when the computer program in the above embodiment is executed, for example Figure 8 S801-S802 are shown, and will not be described here to avoid repetition. Alternatively, when the processor executes the computer program, the functions of each module / unit in this embodiment of the cross-compiler training device are realized, for example Fig. 9 The cross-compiler training device shown includes the functions of a first source code acquisition module 901, a first machine code acquisition module 902, a code preprocessing module 903, a first loss value acquisition module 904 and a target cross-compiler acquisition module 905, which will not be described again here to avoid repetition.

[0090] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the cross-compiler training method in the above embodiment is implemented, for example Figure 2S201-S207 as shown, or Figures 3 to 7 As shown in , a computer program that can also be run on a processor, when the processor executes the computer program, the cross-compilation method of the source code is implemented when the computer program in the above embodiment is executed, for example Figure 8 S801-S802 are shown, and will not be described here to avoid repetition. Alternatively, when the computer program is executed by the processor, the functions of each module / unit in the embodiment of the cross-compiler training device are realized, for example Fig. 9 The cross-compiler training device shown includes the functions of a first source code acquisition module 901, a first machine code acquisition module 902, a code preprocessing module 903, a first loss value acquisition module 904 and a target cross-compiler acquisition module 905, which will not be described again here to avoid repetition.

[0091] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided by the present invention may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (RambuS) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0092] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.

[0093] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention.

Claims

1. A cross-compiler training method, characterized in that: include: Obtain the first source code and MCU architecture identifier; According to the MCU architecture identifier, obtaining a first machine code corresponding to the first source code; Preprocessing the first source code and the first machine code to obtain a first source vector corresponding to the first source code and a first machine vector corresponding to the first machine code; Inputting the first source vector and the first machine vector into a deep learning model to obtain a first loss value; According to the first loss value, the model parameters of the deep learning model are optimized and adjusted to obtain a target cross compiler.

2. The cross-compiler training method according to claim 1, characterized in that: The acquiring, according to the MCU architecture identifier, a first machine code corresponding to the first source code includes: Performing standardization processing on the first source code to obtain a first standard code; According to the MCU architecture identifier, the first standard code is matched to obtain a first machine code corresponding to the first standard code.

3. The cross-compiler training method according to claim 1, characterized in that: The step of inputting the first source vector and the first machine vector into a deep learning model to obtain a first loss value includes: Inputting the first source vector into an encoder of the deep learning model to obtain a first hidden representation; Inputting the first hidden representation into a decoder of the deep learning model to obtain a first prediction result; A first loss value is obtained according to the first prediction result and the first machine vector.

4. The cross-compiler training method according to claim 1, characterized in that: The step of optimizing and adjusting the model parameters of the deep learning model according to the first loss value to obtain a target cross compiler includes: According to the first loss value, adjusting the initial model parameters corresponding to the deep learning model to obtain a first cross-compiler; Preprocessing the second source code to obtain a second source vector corresponding to the second source code; Based on the second source vector, optimization training is performed on the first cross-compiler to obtain a target cross-compiler.

5. The cross-compiler training method as claimed in claim 4, characterized in that: The step of adjusting the initial model parameters corresponding to the deep learning model according to the first loss value to obtain a first cross compiler includes: According to the first loss value and the optimizer of the deep learning model, the initial model parameters of the deep learning model are updated to obtain a first iterative model; If the first iterative model meets the preset target condition, the first iterative model is used as a first cross-compiler.

6. The cross-compiler training method as claimed in claim 4, characterized in that: The step of performing optimization training on the first cross compiler based on the second source vector to obtain a target cross compiler includes: Inputting the second source vector into the first cross compiler to obtain a second prediction result; Performing loss calculation on the second source vector and the second prediction result to obtain a second loss value; The first cross-compiler is adjusted according to the second loss value to obtain a target cross-compiler.

7. A source code cross-compilation method, characterized in that: include: Get the target source code; Based on any one of the target cross compilers in claim 1 to claim 6, the target source code is translated to obtain the target machine code.

8. A cross compiler training device, characterized in that: include: A first source code acquisition module, used to acquire a first source code and an MCU architecture identifier; A first machine code acquisition module, configured to acquire a first machine code corresponding to the first source code according to the MCU architecture identifier; a code preprocessing module, configured to preprocess the first source code and the first machine code to obtain a first source vector corresponding to the first source code and a first machine vector corresponding to the first machine code; A first loss value acquisition module, used for inputting the first source vector and the first machine vector into a deep learning model to acquire a first loss value; A target cross-compiler acquisition module is used to optimize and adjust the model parameters of the deep learning model according to the first loss value to obtain a target cross-compiler.

9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the cross-compiler training method as described in any one of claims 1 to 6 is implemented, or when the processor executes the computer program, the source code cross-compilation method as described in claim 7 is implemented.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by the processor, the cross-compiler training method as described in any one of claims 1 to 6 is implemented, or when the processor executes the computer program, the source code cross-compilation method as described in claim 7 is implemented.

Citation Information

Patent Citations

  • Compiler based on machine learning (ML) model

    CN116541011A

  • Application cross compiling method and device, computing equipment and storage medium

    CN116991381A

  • Virtual compiler data enhancement-based assembly code search and performance optimization method

    CN118444891A

  • Optimized compilation using an auto-tuned compiler as a service

    US20170123773A1