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

CN119668618BActive Publication Date: 2026-10-30PING AN TECH (SHENZHEN) CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411733870.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-27
Publication Date
2026-10-30
Estimated Expiration
2044-11-27

AI Technical Summary

Technical Problem

[0006]本发明实施例提供一种交叉编译器训练方法、装置、计算机设备及存储介质,在针对新型MCU架构时,解决现有交叉编译器的适配性较差的问题

Benefits of technology

[0012]上述的交叉编译器训练方法、装置、计算机设备及存储介质,通过将第一源代码作为训练样本,根据MCU架构标识确认第一源代码对应的第一机器代码,从而将第一机器代码用于标注第一源代码;通过第一源代码和第一机器代码进行预处理后,将得到第一源向量和第一机器向量作为样本输入深度学习模型,以用于训练深度学习模型;最后,基于第一源代码进行转译,根据第一机器代码计算出第一损失值,将第一损失值用于对深度学习模型的模型参数进行优化调整,学习在不同MCU架构中的源代码转译方式,获得目标交叉编译器。通过目标交叉编译器应对新型MCU架构出现时,所产生交叉编译器的不兼容状况,提高交叉编译器的适配性和准确性,从而在金融支付终端、金融交易终端和交易设备中,确保使用目标交叉编译器转译后的机器代码的准确性和安全性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119668618B_ABST
    Figure CN119668618B_ABST
Patent Text Reader

Abstract

The application relates to the technical field of artificial intelligence, and discloses a cross-compiler training method and device, a computer device, and a storage medium. The first source code is taken as a training sample, the 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 labeling the first source code; the first source vector and the first machine vector corresponding to the first source code and the first machine code are taken as sample inputs of 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 the deep learning model, a source code translation mode in different MCU architectures is learned, a target cross-compiler is obtained, the incompatibility of the cross-compiler generated when a new MCU architecture appears is coped with, the adaptability and accuracy of the cross-compiler are improved, and therefore the accuracy and safety of the machine code after translation in the financial field are ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

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

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

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

[0004] In particular, the financial sector has very high requirements for security and reliability. Therefore, when developing and using MCU cross-compilers, it is necessary to strictly follow relevant security 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 existing technologies, due to the existence of various MCU architectures on the market, cross-compilers are typically used to facilitate compatibility with these architectures. This allows developers to compile their code into executables suitable for different target architectures. However, new MCU architectures are constantly emerging. With each new architecture, developers need to rewrite the cross-compiler to adapt to the complex development environment, consuming significant manpower and time. Therefore, existing cross-compilers require developers to further adapt and develop for new MCU architectures, reducing development efficiency and increasing costs. As can be seen, existing cross-compilers suffer from poor adaptability when dealing with new MCU architectures. Summary of the Invention

[0006] This invention provides a cross-compiler training method, apparatus, computer device, and storage medium, which solves the problem of poor adaptability of existing cross-compilers when targeting new MCU architectures.

[0007] This invention provides a cross-compiler training method, including: Obtain the raw text data and speaker identifiers; Based on the original text data, obtain the original text vector and the original phoneme vector; The original text vector is subjected to text enhancement processing to obtain the target text vector; The original phoneme vector is subjected to tone enhancement processing to obtain the target tone vector; Based on the speaker identifier, obtain the target voiceprint vector corresponding to the speaker identifier; The target text vector, the target tone vector, and the target voiceprint vector are concatenated to obtain the target latent vector; The cross-compiler is trained based on the target latent vector to obtain the target cross-compiler corresponding to the speaker identifier.

[0008] This invention also provides a method for cross-compiling source code, including: Obtain the target source code; Based on the target cross-compiler described in the above method, the target source code is translated to obtain the target machine code.

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

[0010] This invention also provides a computer device, 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, it implements the cross-compilation method described above, or when the processor executes the computer program, it implements the cross-compilation method of the source code described above.

[0011] This invention also provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it implements the above-described cross-compilation method for implementing a cross-compilation source code.

[0012] The aforementioned cross-compiler training method, apparatus, computer equipment, and storage medium, by using the first source code as training samples and identifying the corresponding first machine code based on the MCU architecture identifier, thereby annotating the first source code with the first machine code; after preprocessing the first source code and the first machine code, the resulting first source vector and first machine vector are used as samples input into a deep learning model for training; finally, based on the first source code, a translation is performed, and a first loss value is calculated based on the first machine code. This first loss value is then used to optimize and adjust the model parameters of the deep learning model, learning the source code translation methods in different MCU architectures to obtain a target cross-compiler. The target cross-compiler addresses the incompatibility issues arising from the emergence of new MCU architectures, improving the adaptability and accuracy of the cross-compiler, thereby ensuring the accuracy and security of the machine code translated using the target cross-compiler in financial payment terminals, financial trading terminals, and trading devices. Attached Figure Description

[0013] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

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

[0015] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0016] The cross-compiler training method provided in this embodiment of the invention can be applied to, for example... Figure 1 The application environment shown. For example... Figure 1 As shown, the client (computer device) communicates with the server via a network. The client, also known as the user terminal, refers to the program that provides local services to the client, corresponding to the server. Client (computer device) includes, but is not limited to, various personal computers, laptops, smartphones, tablets, cameras, and portable wearable devices. The server can be a standalone server or 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, content delivery networks (CDNs), and big data and artificial intelligence platforms.

[0017] The cross-compiler training method provided in this embodiment of the invention can be applied to, for example... Figure 1 The application environment shown. Specifically, this cross-compiler training method is applied in a source code cross-compilation system, which includes, for example, […]. Figure 1 The client and server shown communicate with each other over a network to process source code, train deep learning models, obtain the 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 typically used in the following areas: financial payment terminals (such as POS terminals) are usually based on embedded systems and MCU architectures. Through a cross compiler, the software developed for the payment terminal is translated into machine code suitable for a specific MCU architecture. Security modules in the financial field (such as encryption chips) are also usually based on MCU architectures to implement security functions and data protection. Through a cross compiler, the software developed for the security module is compiled into machine code suitable for a specific MCU. Financial transaction devices (such as ATMs, transaction terminals, etc.) are based on embedded systems and MCU architectures. Through a cross compiler, the developed software is compiled into machine code suitable for a specific MCU architecture.

[0019] In one embodiment, such as Figure 2 As shown, a cross-compiler training method is provided, which is then applied to... Figure 1 Taking the server in the example, the following steps are included: S201: Obtain the first source code and MCU architecture identifier; S202: Based on the MCU architecture identifier, obtain the first machine code corresponding to the first source code; S203: Preprocess the first source code and the first machine code to obtain the first source vector corresponding to the first source code and the first machine vector corresponding to the first machine code; S204: Input the first source vector and the first machine vector into the deep learning model to obtain the first loss value; S205: Based on the first loss value, optimize and adjust the model parameters of the deep learning model to obtain the target cross-compiler.

[0020] As an example, in step S201, the server provides a sample set for subsequent deep learning models based on the first source code preset by the developers and a specific MCU architecture identifier from a variety of MCU architectures. In this example, the corresponding MCU architecture for the application is determined based on the different devices used, and this is used as the MCU architecture identifier. In another example, the corresponding MCU architecture identifier can also be selected based on the specific business requirements. For example, when applying a security module (such as an encryption chip) in the financial field, the MCU architecture identifier corresponding to that business is selected, and the source code corresponding to the software developed in that security module is used as the first source code.

[0021] Understandably, the machine code corresponding to the translated executable file is different in different MCU architectures. That is, the machine code corresponding to the source code in that MCU architecture is obtained based on the MCU architecture identifier of the MCU architecture to be translated. Common MCU architectures include, but are not limited to, the following: ARM (Advanced RISC Machines), PIC (Peripheral Interface Controller), MSP430 (Mixed Signal Processor 430), 8051 (Intel 8051), and x86_64 architecture.

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

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

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

[0025] Preferably, for different MCU architecture identifiers, the machine code corresponding to different MCU architectures is output using multi-task output. By simultaneously predicting the machine code of multiple MCU architectures, the model can learn the commonalities and differences between different MCU architectures, thereby improving the model's generalization ability and transfer learning ability, and enhancing the model's adaptability when facing unknown MCU architectures.

[0026] In this example, the Python code serving as the first source code can be translated into the first machine code corresponding to the MCU architecture using an existing compiler, and then the corresponding first machine code can be annotated to the first source code. Alternatively, the first source code can be matched and annotated by searching a database of corresponding source and machine code information. Another method is to manually match and annotate the first source code with the corresponding first machine code one by one. For example, when the MCU architecture is identified as x86_64, the first machine code matched to the `sub` function in the Python code serving as the first source code is 0100100B1000001.

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

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

[0029] In this example, depending on the deep learning model used, the input first source code and first machine code can be encoded through the input layer of the deep learning model. The encoding method used can be 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 first machine vector as sample data, inputs them into the constructed deep learning model, and outputs the first loss value obtained by the deep learning model through the loss function after processing the first source vector and first machine vector, for use in adjusting the deep learning model.

[0031] In this example, the deep learning model used is the Transform model. The adaptability and correlation advantages of the Transform model's multi-head attention mechanism are beneficial for better capturing the correlation between the input source code and the machine code corresponding to different MCU architectures. This embodiment provides the Transform model as an example; 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 a corresponding server in the cloud or on the edge. In this example, deploying the deep learning model on the edge offers the following advantages: 1) It allows for immediate processing of collected data without uploading it to a cloud processing center, significantly accelerating system response and reducing processing latency; 2) Edge computing can process valuable, critical data more efficiently, while other data is only temporary. Combining the capabilities of the deep learning model on the edge not only allows for more timely data processing but also alleviates network bandwidth limitations and reduces pressure on data storage at the central location; 3) The edge-based deep learning model can efficiently process the user's source data, cleaning and protecting sensitive data. The edge device only reports the processed results 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 based on 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 optimal parameters, i.e., the optimized model parameters; L represents the loss function; This represents the first prediction result output by the model, where This represents the first source vector of the input; This represents the true 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, minimizing the loss function. .

[0035] Therefore, by minimizing the loss function You can adjust the parameters of the Transformer model. So that it is in the first source vector of the given 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. The corresponding first machine code is identified based on the MCU architecture identifier, and this first machine code is used to annotate the first source code. After preprocessing the first source code and the first machine code, the resulting first source vector and first machine vector are input as samples into the deep learning model for training. Finally, the first source code is transpiled, and a first loss value is calculated based on the first machine code. This first loss value is used to optimize and adjust the model parameters of the deep learning model, learning the source code transpilation methods in different MCU architectures to obtain the target cross-compiler. The target cross-compiler addresses the incompatibility issues that arise when new MCU architectures emerge, improving the cross-compiler's adaptability and accuracy. This ensures the accuracy and security of the machine code transpiled using the target cross-compiler in financial payment terminals, financial trading terminals, and trading devices.

[0037] In one embodiment, such as Figure 3 As shown, in step S202, based on the MCU architecture identifier, the first machine code corresponding to the first source code is obtained, including: S301. Standardize the first source code to obtain the first standardized code; S302. Based on the MCU architecture identifier, perform matching processing on the first specification code to obtain the first machine code corresponding to the first specification code.

[0038] As an example, in step S301, after obtaining the first source code, the server performs normalization processing on the first source code to obtain the corresponding normalized first standard code.

[0039] Normalization typically involves segmenting and organizing the initial source code to control the computational complexity of subsequent deep learning model training, reducing the computational load on model training and inference, and making the model easier to train and deploy. It also improves the model's generalization ability, preventing the inclusion of excessive redundant or irrelevant information in subsequent training data, allowing the model to focus more on key contextual information.

[0040] In this example, the input source code, i.e., the input Python code, is processed and segmented to obtain the corresponding standard code. This processing includes, but is not limited to, removing comments and standardizing indentation, and segmenting the Python code into functions. Furthermore, the number of lines and character lengths of the Python code can be limited by preset character limits, such as a preset number of lines between 1 and 50, with each line not exceeding 128 bytes.

[0041] As an example, in step S302, after the server normalizes the first source code, it identifies the corresponding MCU architecture to be translated based on the MCU architecture identifier. Then, it obtains the actual first machine code of the first normalized code by matching the first machine code corresponding to that MCU architecture. The first machine code and the first source code can be paired to form a sample pair for model training, or the first machine code can be used as a label corresponding to the first source code for model training. The choice depends on the specific training method and is not further limited.

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

[0043] In one embodiment, such as 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 the first loss value, including: S401. Input the first source vector into the encoder of the deep learning model to obtain the first hidden representation; S402. Input the first hidden representation into the decoder of the deep learning model to obtain the first prediction result; S403. Obtain the first loss value based on the first prediction result and the first machine vector.

[0044] Understandably, the transformer model used in this embodiment typically has the following structure: input layer, encoder (… The encoder, decoder, and output layer are based on a self-attention mechanism. In this example, both the encoder and decoder have 6 layers, with the multi-head attention mechanism containing 16 attention heads, and each attention layer having 256 hidden units.

[0045] As an example, in step S401, the server inputs the preprocessed first source vector into the encoder of the deep learning model. Based on the multi-head self-attention mechanism in the multi-layer encoder, the server performs self-attention calculation on the position of each vector in the input first source vector and other positions to capture the dependencies 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. Based on the multi-head self-attention mechanism in the multi-layer decoder, attention is calculated on the first hidden representation output by the encoder. The decoder combines the output layer to map the calculated first hidden representation to the vocabulary space and obtain the prediction 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 the first prediction result, uses a corresponding loss function to calculate the loss between the first prediction result and the true first machine vector, and obtains the calculated first loss value. Common loss functions include cross-entropy loss and mean squared error.

[0048] In this example, by using the formula Calculate the first loss value, where L represents the loss function; This represents the first prediction result output by the model, where This represents the first source vector of the input; Let represent the true first machine vector corresponding to the first source vector. Then, the loss value calculated using this formula is the first loss value.

[0049] In this example, the encoder of a deep learning model consisting of multiple encoders and decoders encodes and decodes the first source vector based on an attention mechanism, and outputs the first prediction result based on the first source vector. The loss value between the first prediction result and the first machine vector compiled from the first source vector on the MCU architecture is calculated and used for subsequent optimization of the deep learning model.

[0050] In one embodiment, such as Figure 5 As shown, in step S205, the model parameters of the deep learning model are optimized and adjusted according to the first loss value to obtain the target cross-compiler, including: S501. Based on the first loss value, adjust the initial model parameters corresponding to the deep learning model to obtain the first cross-compiler; S502. Preprocess the second source code to obtain the 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 the target cross-compiler.

[0051] In this example, the transformer model used is built by defining the training parameters based on the business details. 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. Based on 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 parameters based on the first loss value, and uses the adjusted deep learning model as the first cross-compiler.

[0053] In this other example, if the preset first source code is a certain existing high-level programming language, such as Python, as the first source code, and the machine language (executable file) corresponding to the existing multiple MCU architectures is trained according to the preset training parameters, 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 a second source code exists, the server preprocesses the second source code to obtain the second source vector corresponding to the second source code. The second source code is the high-level programming language used by the new MCU architecture; that is, when a new MCU architecture emerges, 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 optimizes the training of the first cross-compiler based on 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 training the first cross-compiler based on the first source code and the first machine code, if a new MCU architecture emerges, it only needs to input the second source code under the new MCU architecture, without needing to perform machine code matching, thus enabling unsupervised or self-supervised training of the first cross-compiler. In this example, based on the first prediction result and the first loss value obtained from the first source vector, the initial model parameters corresponding to the deep learning model are adjusted using the corresponding training parameters 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 optimize and train the first cross-compiler to obtain the final target cross-compiler, which can accurately translate the source code when adapting to multiple MCU architectures.

[0058] In one embodiment, such as Figure 6 As shown, in step S501, the initial model parameters corresponding to the deep learning model are adjusted according to the first loss value to obtain the first cross-compiler, including: S601. Based on the first loss value and the optimizer of the deep learning model, update the initial model parameters of the deep learning model to obtain the first iteration model. S602. If the first iterative model meets the preset target conditions, then the first iterative model will be used as the first cross-compiler.

[0059] As an example, in step S601, after obtaining the first loss value based on the first machine 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. Specifically, the value of the first loss value is compared with the existing minimum loss value to determine whether it should be used to update the initial model parameters.

[0060] In this embodiment, based on multiple inputs of the first source code, processing is performed on the first source code, and the deep learning model is iterated based on the processed first loss value to obtain the optimal model parameters. The first iterative model is continuously updated based on the training parameters. The first iterative model is the initially adjusted deep learning model. If the optimal model parameters are subsequently obtained, the first iterative model is updated. That is, the updated iterative model can be called the second iterative model, or it can continue to be called the first iterative model; "first" and "second" are not limiting terms.

[0061] Furthermore, by using the formula To update the initial model parameters, where, represents the optimal parameters, i.e., the optimized model parameters; L represents the loss function; This represents the first prediction result output by the model, where This represents the first source vector of the input; This represents the true 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, minimizing the 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 iterations are set as the preset target condition. The preset target condition could also be a loss threshold; this is not limited here. Based on the preset training parameters, and using the first loss value and the optimizer, the model parameters of the first iteration model are updated using the backpropagation algorithm until the number of iterations specified by the preset target condition is completed.

[0064] In another example, if the first source code and 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 the conversion of source code into machine code.

[0065] In this example, after confirming 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 the first iterative model trained with 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. Thus, based on the supervised training of the first source code, the deep learning model is optimized to obtain the first cross-compiler with high accuracy.

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

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

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

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

[0070] In another example, during self-supervised learning of the first cross-compiler based on the second source code, an auxiliary task can be generated using some inherent structure or feature of the second source code. This could involve transforming the second source code through methods such as masking, partial occlusion, or position prediction. The consistency between the transformed and second source codes is then used as a training signal. The transformed source code is input into a pre-trained Transformer model to generate a second prediction result in machine code, which is then compared with the second source code to calculate the loss. Backpropagation and optimization algorithms are used to update the model parameters, enabling the model to learn useful features from the source code.

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

[0072] In this example, when a new MCU architecture emerges, the second source vector corresponding to the new MCU architecture is input into the first cross-compiler to obtain a second prediction result. 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. Based on the loss calculation, a second loss value is calculated to optimize and adjust the first cross-compiler, resulting in the final target cross-compiler. The target cross-compiler has better adaptability, capable of translating source code for various MCU architectures. Furthermore, using unsupervised or self-supervised learning on the second source code corresponding to the new MCU architecture reduces development costs and improves development efficiency.

[0073] In another embodiment, such as Figure 8 As shown, a source code cross-compilation method is provided, which is then applied to... Figure 1 Taking the server in the example, the following steps are included: S801, Obtain the 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, which is in a high-level programming language. In this example, this includes, but is not limited to, Python, C, and JavaScript.

[0075] In this example, the user can input a target MCU architecture identifier for subsequent generation of an executable file (machine code) representing the corresponding MCU architecture. The user can also select from multiple generated executable files corresponding to different MCU architectures. In another example, the user can also confirm the corresponding target MCU architecture by inputting a preset service. For example, the preset service might be the translation of the target source code for software developed for financial trading devices (such as ATMs, trading terminals, etc.). The user can confirm the target MCU architecture identifier based on the preset service to subsequently translate the target source code of the developed software into target machine code.

[0076] As an example, in step S802, the server, based on the received target source code and the trained target cross-compiler, performs translation processing on the target source code to obtain the target machine code corresponding to each MCU architecture for user confirmation.

[0077] In this example, the target MCU architecture can also be directly translated into the corresponding target machine code. For example, the translated target machine code can be obtained based on the MCU architecture of the financial trading device (such as ATM, trading terminal, etc.) to meet the high standards of security and reliability in the financial field, and the translated target machine code can be burned into the corresponding financial trading device for execution.

[0078] In this example, a Transformer-based cross-compiler applicable to different MCU architectures is presented. Unlike previous methods where professionals had to write adapters for specific MCU architectures, this invention simply requires inputting the target source code, such as Python code, into the Transformer-based target cross-compiler to generate the corresponding target machine code. This invention, used on the edge, addresses the cumbersome process and incompatibility issues of existing cross-compilers when compiling source code onto MCUs of different architectures on terminal devices.

[0079] It should be understood that the sequence number of each step in the above embodiments does not imply 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 embodiments of the present invention.

[0080] In one embodiment, a cross-compiler training apparatus is provided, which corresponds one-to-one with the cross-compiler training methods described in the above embodiments. For example... Figure 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. Detailed descriptions of each functional module are as follows: The first source code acquisition module 901 is used to acquire the first source code and the MCU architecture identifier; The first machine code acquisition module 902 is used to acquire the first machine code corresponding to the first source code based on the MCU architecture identifier; The code preprocessing module 903 is used to preprocess the first source code and the first machine code to obtain the first source vector corresponding to the first source code and the first machine vector corresponding to the first machine code; The first loss value acquisition module 904 is used to input the first source vector and the first machine vector into the deep learning model to obtain the first loss value; The target cross-compiler acquisition module 905 is used to optimize and adjust the model parameters of the deep learning model based on the first loss value, and to acquire the target cross-compiler.

[0081] In one embodiment, the first machine code acquisition module 902 includes: The first standardized code acquisition unit is used to standardize the first source code and acquire the first standardized code. The first machine code acquisition unit is used to match the first specification code according to the MCU architecture identifier and obtain the first machine code corresponding to the first specification code.

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

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

[0084] In one embodiment, the first cross-compiler acquisition unit includes: The first iteration model obtains a sub-unit, which is used to update the initial model parameters of the deep learning model based on the first loss value and the optimizer of the deep learning model, and obtains the first iteration model. The first cross-compiler acquires a sub-unit, which is used to use the first iterative model as the first cross-compiler if the first iterative model meets the preset target conditions.

[0085] In one embodiment, the target cross-compiler acquisition unit includes: The second prediction result acquisition subunit is used to input the second source vector into the first cross compiler to obtain the second prediction result; The second loss value acquisition subunit is used to calculate the loss between the second source vector and the second prediction result and obtain the second loss value. The target cross-compiler obtains sub-units, which are used to adjust the first cross-compiler based on the second loss value, and obtain the target cross-compiler.

[0086] In another embodiment, a speech synthesis device is provided, which corresponds one-to-one with the cross-compiler training method in the above embodiments, including: The 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] Specific limitations regarding the cross-compiler training device can be found in the limitations of the cross-compiler training method described above, and will not be repeated here. Each module in the aforementioned cross-compiler training device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in the computer device in hardware form, or stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to each module.

[0088] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 10As shown, the computer device includes a processor, memory, network interface, and database connected via a system bus. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database is used to store data employed or generated during the execution of a cross-compiler training method. The network interface is used to communicate with external terminals via a network connection. The computer program is executed by the processor to implement a cross-compiler training method.

[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, it implements the cross-compiler training method described in the above embodiment, for example... Figure 2 As shown in S201-S207, or Figures 3 to 7 As shown, a computer program can also run on the processor. When the processor executes the computer program, it implements the cross-compilation method of the source code in the above embodiments, for example... Figure 8 S801-S802, as shown, will not be described again here to avoid repetition. Alternatively, when the processor executes a computer program, it implements the functions of each module / unit in this embodiment of the cross-compiler training device, for example... Figure 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. To avoid repetition, these functions will not be described in detail here.

[0090] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When executed by a processor, the computer program implements the cross-compiler training method described in the above embodiment, for example... Figure 2 As shown in S201-S207, or Figures 3 to 7 As shown, a computer program can also run on the processor. When the processor executes the computer program, it implements the cross-compilation method of the source code in the above embodiments, for example... Figure 8 S801-S802, as shown, will not be described again here to avoid repetition. Alternatively, when this computer program is executed by the processor, it implements the functions of each module / unit in this embodiment of the cross-compiler training apparatus, for example... Figure 9The 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. To avoid repetition, these functions will not be described in detail here.

[0091] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. This computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided by this invention can 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 a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAM bus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0092] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is used as an example. In practical applications, the above functions can be assigned to 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, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included within the protection scope of the present invention.

Claims

1. A training method for a cross-compiler, characterized in that, include: Obtaining the first source code and MCU architecture identifier includes: when applying a security module in the financial field, selecting the MCU architecture identifier corresponding to the business, and using the source code corresponding to the software developed in the security module as the first source code; The first source code is normalized to obtain normalized first standard code; the normalized first standard code is matched according to the MCU architecture identifier to obtain the first machine code under the MCU architecture corresponding to the first standard code; the normalization process includes segmenting and sorting the first source code; The first source code and the first machine code are preprocessed to obtain the first source vector corresponding to the first source code and the first machine vector corresponding to the first machine code. Input the first source vector and the first machine vector into the deep learning model to obtain the first loss value; Based on the first loss value, the initial model parameters corresponding to the deep learning model are adjusted to obtain the first cross-compiler; The second source code is preprocessed to obtain the second source vector corresponding to the second source code. Based on the second source vector, the first cross-compiler is optimized and trained to obtain the target cross-compiler.

2. The training method for the cross-compiler as described in claim 1, characterized in that, The step of inputting the first source vector and the first machine vector into the deep learning model to obtain the first loss value includes: The first source vector is input into the encoder of the deep learning model to obtain the first hidden representation; The first hidden representation is input into the decoder of the deep learning model to obtain a first prediction result; Based on the first prediction result and the first machine vector, obtain the first loss value.

3. The training method for the cross-compiler as described in claim 1, characterized in that, The step of adjusting the initial model parameters corresponding to the deep learning model based on the first loss value to obtain the first cross-compiler includes: Based on 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 the first iterative model; If the first iterative model meets the preset target conditions, then the first iterative model will be used as the first cross-compiler.

4. The training method for the cross-compiler as described in claim 1, characterized in that, The step of optimizing and training the first cross-compiler based on the second source vector to obtain the target cross-compiler includes: Input the second source vector into the first cross-compiler to obtain the second prediction result; The loss is calculated between the second source vector and the second prediction result to obtain a second loss value; Based on the second loss value, the first cross-compiler is adjusted to obtain the target cross-compiler.

5. A method for cross-compiling source code, characterized in that, include: Obtain the target source code; Based on any one of the target cross-compilers described in claims 1 to 4, the target source code is translated to obtain the target machine code.

6. A cross-compiler training device, characterized in that, include: The first source code acquisition module is used to acquire the first source code and the MCU architecture identifier; The first machine code acquisition module is used to perform normalization processing on the first source code to obtain the normalized first normalized code; Based on the MCU architecture identifier, the standardized first standardized code is matched to obtain the first machine code under the MCU architecture corresponding to the first standardized code; the standardization process includes segmenting and sorting the first source code; The code preprocessing module is used to preprocess the first source code and the first machine code to obtain the first source vector corresponding to the first source code and the first machine vector corresponding to the first machine code. The first loss value acquisition module is used to input the first source vector and the first machine vector into the deep learning model to obtain the first loss value; The target cross-compiler acquisition module is used to adjust the initial model parameters corresponding to the deep learning model based on the first loss value, and acquire the first cross-compiler; The second source code is preprocessed to obtain the second source vector corresponding to the second source code. Based on the second source vector, the first cross-compiler is optimized and trained to obtain the target cross-compiler; The first source code acquisition module includes: when applying a security module in the financial field, selecting the MCU architecture identifier corresponding to the business, and using the source code corresponding to the software developed in the security module as the first source code.

7. 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, it implements the cross-compiler training method as described in any one of claims 1 to 4, or when the processor executes the computer program, it implements the cross-compilation method of the source code as described in claim 5.

8. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the cross-compiler training method as described in any one of claims 1 to 4, or when the processor executes the computer program, it implements the cross-compilation method of the source code as described in claim 5.

Citation Information

Patent Citations

  • Compiler based on machine learning (ML) model

    CN116541011A