Code conversion method, device, electronic device and computer-readable medium

By parsing and converting GPU programming language code, the conversion problem caused by the inability to determine hardware manufacturers in heterogeneous computing environment is solved, and efficient GPU code conversion and operation is achieved through cache optimization.

CN117555542BActive Publication Date: 2025-07-01BEIJING QUALITY ENERGY CORE TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311517056.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-11-14
Publication Date
2025-07-01
Estimated Expiration
2043-11-14

AI Technical Summary

Technical Problem

In a heterogeneous computing environment, it is impossible to determine the hardware manufacturer currently used, resulting in the inability to convert the GPU programming language code, and thus the GPU of the current hardware manufacturer cannot be run. At the same time, there are many errors in the string replacement process and it is difficult to locate, resulting in too long conversion time.

Method used

By obtaining the set of code to be converted and parsing its conversion parameter information, parsing information is generated to determine the hardware information. Then, the code is converted and compiled based on the hardware information, and the converted code file is generated and stored in a cache to reduce future conversion time.

Benefits of technology

It realizes automatic identification of hardware manufacturers' GPUs in a heterogeneous computing environment, avoiding the situation where the current hardware manufacturers' GPUs cannot be run, and through cache optimization, reducing the time of GPU programming language code conversion.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117555542B_ABST
    Figure CN117555542B_ABST
Patent Text Reader

Abstract

Embodiments of the present disclosure disclose a code conversion method, apparatus, electronic device, and computer-readable medium. A specific implementation of the method includes: obtaining a set of code files to be converted, where the set of code files to be converted corresponds to conversion parameter information; performing parsing processing on the conversion parameter information corresponding to the set of code files to be converted to generate parsing information; in response to the parsing information indicating that the parameters are correct, determining hardware information corresponding to the set of code files to be converted according to the parsing information; performing conversion processing on the set of code files to be converted according to the hardware information to generate a set of converted code files; performing compilation processing on the set of converted code files according to the hardware information to generate a compilation result; and in response to the compilation result indicating successful compilation, storing the set of code files to be converted in a cache. This implementation avoids the situation where the current hardware manufacturer's GPU cannot be run.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present disclosure relate to the field of computer technologies, and in particular, to a code conversion method, apparatus, electronic device, and computer-readable medium. Background Art

[0002] In the scenario of heterogeneous computing, in order to adapt to GPUs (Graphics Processing Units) of different manufacturers, it is usually necessary to convert a GPU programming language code into another GPU programming language code (for example, convert CUDA (Compute Unified Device Architecture) code into MUSA (Moore Threads Unified System Architecture) code). How to convert GPU programming language codes has become an important research topic. Currently, when converting GPU programming language codes, the commonly adopted method is to use different code conversion tools (compilers) to convert GPU programming language codes according to different hardware manufacturers.

[0003] However, when converting GPU programming language codes in the above manner, the following technical problems often exist:

[0004] First, in a heterogeneous computing environment, it is necessary to convert programming language codes adapted to different hardware manufacturers multiple times. Since the current hardware manufacturer cannot be determined, the programming language codes cannot be converted, and thus the GPUs of the current hardware manufacturer cannot be run.

[0005] Second, when performing string replacement, after the code is replaced as a whole and then tested, it may be impossible to determine the source location of the error due to too many errors, resulting in a long time required to convert the GPU programming language code.

[0006] The above information disclosed in this background art section is only used to enhance the understanding of the background of the inventive concept, and thus, it may include information that does not form the prior art known to those of ordinary skill in the art in this country. Summary of the Invention

[0007] The content part of the present disclosure is used to introduce the concepts in a brief form, and these concepts will be described in detail in the following detailed implementation part. The content part of the present disclosure is not intended to identify the key features or essential features of the claimed technical solution, nor is it intended to be used to limit the scope of the claimed technical solution.

[0008] Some embodiments of the present disclosure provide a code conversion method, apparatus, electronic device, and computer-readable medium to solve one or more of the technical problems mentioned in the above background art section.

[0009] In a first aspect, some embodiments of the present disclosure provide a code conversion method, which includes: obtaining a set of code files to be converted, where the set of code files to be converted corresponds to conversion parameter information; performing parsing processing on the conversion parameter information corresponding to the set of code files to be converted to generate parsing information; in response to the parsing information indicating that the parameters are correct, determining the hardware information corresponding to the set of code files to be converted according to the parsing information; performing conversion processing on the set of code files to be converted according to the hardware information to generate a set of converted code files; performing compilation processing on the set of converted code files according to the hardware information to generate a compilation result; and in response to the compilation result indicating successful compilation, storing the set of code files to be converted in the cache.

[0010] In a second aspect, some embodiments of the present disclosure provide a code conversion apparatus, which includes: an obtaining unit configured to obtain a set of code files to be converted, where the set of code files to be converted corresponds to conversion parameter information; a parsing unit configured to perform parsing processing on the conversion parameter information corresponding to the set of code files to be converted to generate parsing information; a determining unit configured to, in response to the parsing information indicating that the parameters are correct, determine the hardware information corresponding to the set of code files to be converted according to the parsing information; a conversion unit configured to perform conversion processing on the set of code files to be converted according to the hardware information to generate a set of converted code files; a compilation unit configured to perform compilation processing on the set of converted code files according to the hardware information to generate a compilation result; and a storage unit configured to, in response to the compilation result indicating successful compilation, store the set of code files to be converted in the cache.

[0011] In a third aspect, some embodiments of the present disclosure provide an electronic device, including: one or more processors; a storage device storing one or more programs thereon, and when the one or more programs are executed by the one or more processors, the one or more processors implement the method described in any implementation manner of the first aspect.

[0012] In a fourth aspect, some embodiments of the present disclosure provide a computer-readable medium storing a computer program thereon, where when the program is executed by a processor, the method described in any implementation manner of the first aspect is implemented.

[0013] The above-mentioned various embodiments of the present disclosure have the following beneficial effects: Through the code conversion method of some embodiments of the present disclosure, the situation of being unable to run the GPU of the current hardware manufacturer is avoided. Specifically, the reason for being unable to run the GPU of the current hardware manufacturer is that in a heterogeneous computing environment, it is necessary to convert the programming language code adapted to different hardware manufacturers multiple times, and it is impossible to determine the currently used hardware manufacturer, resulting in the inability to convert the programming language code, and thus the inability to run the GPU of the current hardware manufacturer. Based on this, in the code conversion method of some embodiments of the present disclosure, first, a set of code files to be converted is obtained. Thus, the code files that need to be converted can be determined. Secondly, the conversion parameter information corresponding to the set of code files to be converted is parsed to generate parsing information. Thus, it can be determined that the conversion parameters support code conversion. Then, in response to the parsing information indicating that the parameters are correct, according to the parsing information, the hardware information corresponding to the set of code files to be converted is determined. Thus, the GPU of the hardware manufacturer that needs to be converted can be automatically determined. After that, according to the hardware information, the set of code files to be converted is subjected to a conversion process to generate a set of converted code files. Thus, by automatically identifying the GPU of the hardware manufacturer to be converted, the code files that need to be converted can be converted. In a heterogeneous computing environment, there is no need to use different code conversion tools (compilers), thereby avoiding the situation of being unable to run the GPU of the current hardware manufacturer. Then, according to the hardware information, the set of converted code files is compiled to generate a compilation result. Thus, the converted programming language code can be compiled and run. Finally, in response to the compilation result indicating successful compilation, the set of code files to be converted is stored in the cache. Thus, the set of code files to be converted with successful compilation can be stored, and the code files can be quickly called from the cache when performing programming language code conversion next time, reducing the time for converting the code. The situation of being unable to run the GPU of the current hardware manufacturer is avoided. BRIEF DESCRIPTION OF THE DRAWINGS

[0014] In combination with the accompanying drawings and with reference to the following specific embodiments, the above and other features, advantages, and aspects of the various embodiments of the present disclosure will become more apparent. Throughout the drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic, and the elements and elements are not necessarily drawn to scale.

[0015] Figure 1 is a flowchart of some embodiments of the code conversion method according to the present disclosure;

[0016] Figure 2 is a schematic structural diagram of some embodiments of the code conversion device according to the present disclosure;

[0017] Figure 3It is a schematic structural diagram of an electronic device suitable for implementing some embodiments of the present disclosure. Detailed implementation manners

[0018] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although some embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. On the contrary, these embodiments are provided to more thoroughly and completely understand the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not used to limit the protection scope of the present disclosure.

[0019] In addition, it should be noted that for the sake of convenience of description, only parts related to the relevant invention are shown in the drawings. Without conflict, the embodiments in the present disclosure and the features in the embodiments can be combined with each other.

[0020] It should be noted that the concepts such as "first" and "second" mentioned in the present disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or mutual dependence relationship of the functions performed by these devices, modules or units.

[0021] It should be noted that the modifications of "one" and "multiple" mentioned in the present disclosure are illustrative rather than restrictive. Those skilled in the art should understand that unless clearly indicated otherwise in the context, it should be understood as "one or more".

[0022] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only for illustrative purposes and are not used to limit the scope of these messages or information.

[0023] The present disclosure will be described in detail below with reference to the drawings and in combination with the embodiments.

[0024] Figure 1 Flow 100 of some embodiments of a code conversion method according to the present disclosure is shown. The code conversion method includes the following steps:

[0025] Step 101, obtain a set of code files to be converted.

[0026] In some embodiments, the execution entity (such as a server) of the code conversion method may obtain a set of code files to be converted. Among them, the above set of code files to be converted corresponds to conversion parameter information. The code files to be converted in the above set of code files to be converted may be code files that need to be code-converted. As an example, in response to the code to be converted being CUDA (Compute Unified Device Architecture) code, the above code files to be converted may be code files with a.cu suffix. The above conversion parameter information may be pre-set parameter information for code conversion. The above conversion parameter information includes at least one conversion parameter.

[0027] Step 102: Perform parsing processing on the conversion parameter information corresponding to the set of code files to be converted to generate parsing information.

[0028] In some embodiments, the above execution entity may perform parsing processing on the conversion parameter information corresponding to the set of code files to be converted to generate parsing information. In practice, the above execution entity may determine whether each conversion parameter included in the above conversion parameter information is within the preset parameter range corresponding to the above conversion parameter. In response to being within the preset parameter range, add the above conversion parameter to the parsing information.

[0029] Step 103: In response to the parsing information indicating that the parameters are correct, determine the hardware information corresponding to the set of code files to be converted according to the parsing information.

[0030] In some embodiments, the above execution entity may, in response to the parsing information indicating that the parameters are correct, determine the hardware information corresponding to the above set of code files to be converted according to the above parsing information. Here, the situation where the number of conversion parameters included in the parsing information is equal to the conversion parameters included in the above conversion parameter information may be determined as the parameters being correct. In practice, the information characterizing the hardware information may be selected from the parsing information to determine the hardware information corresponding to the above set of code files to be converted. Among them, the above hardware information may characterize the information of a GPU (Graphics Processing Unit) of a certain hardware manufacturer.

[0031] Step 104: Perform conversion processing on the set of code files to be converted according to the hardware information to generate a set of converted code files.

[0032] In some embodiments, the above execution entity may perform conversion processing on the set of code files to be converted according to the above hardware information to generate a set of converted code files.

[0033] In practice, the above execution entity may generate a set of converted code files through the following steps:

[0034] First step: According to the above hardware information, obtain a set of mapping information corresponding to the above hardware information. In practice, the set of mapping information corresponding to the above hardware information can be obtained from a database storing the set of mapping information. Among them, the mapping information in the above set of mapping information includes one of the following: header file mapping information, interface mapping information, and body mapping information. The above header file mapping information may include at least one replacement association relationship of header file strings. The above interface mapping information may include at least one replacement association relationship of interface strings. The above body mapping relationship may include at least one replacement association relationship of strings in the body.

[0035] Second step: Initialize a preset temporary file name sequence. Among them, the above preset temporary file name sequence is initially empty. The above preset temporary file name sequence is used to store the file names of temporary files.

[0036] Third step: Perform mirroring processing on each code file to be converted in the above code file set to be converted to generate a set of mirrored code files. The above mirroring processing can be copying processing.

[0037] Fourth step: Based on the set of mirrored code files and the preset temporary file name sequence, perform the following conversion steps:

[0038] First conversion step: According to the above set of mapping information, perform string replacement processing on the first mirrored code file in the set of mirrored code files to generate a code file after replacement. In practice, according to the replacement association relationships of each string included in the above set of mapping information, the strings of the above mirrored code file can be replaced.

[0039] In practice, the following sub-steps can be used to perform string replacement processing on the mirrored code file:

[0040] First sub-step: Split the above mirrored code file to generate a set of split code files. Here, the above splitting processing can be to split the mirrored code file by header file, interface, and file body.

[0041] Second sub-step: Initialize a preset task sequence. Among them, the above preset task sequence is initially empty.

[0042] Third sub-step: Based on the above set of split code files, perform the following replacement steps:

[0043] First replacement step: Select the mapping information corresponding to the first split code file in the above set of split code files from the above set of mapping information as the target mapping information.

[0044] The second replacement step is to replace the strings to be replaced in the first split code file according to the replacement association relationships of the respective representation strings included in the above target mapping information, so as to update the split code file and obtain an updated code file.

[0045] The third replacement step is to test the updated code file in response to the completion of the replacement to generate a test result.

[0046] The fourth replacement step is to add the at least one running error message to the above preset task sequence in response to the existence of at least one running error message in the above test result to generate an added task sequence. Among them, the running error message in the at least one running error message can represent that a certain line of code in the updated code file runs incorrectly.

[0047] The fifth replacement step is to perform an adaptation process on the added tasks in the added task sequence in response to the split code file set after removing the first split code file being empty. Among them, the above adaptation process can be the adaptation of the line of code corresponding to a certain running error message.

[0048] The fourth sub-step is to use the split code file set after removing the first split code file as the split code file set and the added task sequence as the preset task sequence, and execute the above replacement step again in response to the split code file set after removing the first split code file not being empty.

[0049] The relevant content in the above first sub-step to the fourth sub-step is an inventive point of the present disclosure, which solves the second technical problem mentioned in the background art, that is, "when performing string replacement, after the code is replaced as a whole and then tested, there may be too many errors to determine the source location of the error, resulting in a long time required to convert the GPU programming language code". The factors that cause a long time to convert the GPU programming language code are usually as follows: when performing string replacement, after the code is replaced as a whole and then tested, there may be too many errors to determine the source location of the error, resulting in a long time required to convert the GPU programming language code. If the above factors are solved, the effect of reducing the time for converting the GPU programming language code can be achieved. To achieve this effect, first, split the above mirror code file to generate a set of split code files. Thus, the mirror code file can be split into multiple sub-files. Second, initialize the preset task sequence. Thus, a sequence for storing error code information can be generated. Third, based on the above set of split code files, perform the following replacement steps: First, select the mapping information corresponding to the first split code file in the above set of split code files from the above mapping information set as the target mapping information. Thus, the mapping information to be replaced can be selected. Second, according to the replacement association relationships of each represented string included in the above target mapping information, replace the strings to be replaced in the above first split code file to update the above split code file to obtain an updated code file. Thus, the strings in the sub-files can be replaced with strings adapted to the hardware GPU. Then, in response to the completion of the replacement, test the above updated code file to generate a test result. Thus, it can be tested whether there is an error code in the replaced sub-file. After that, in response to the existence of at least one running error message in the above test result, add the above at least one running error message to the above preset task sequence to generate an added task sequence. Thus, the error code information can be recorded. Then, in response to the set of split code files after removing the first split code file being empty, perform an adaptation process on the added tasks in the above added task sequence. Thus, the error code can be quickly adapted. Thereby, the time for converting the GPU programming language code can be reduced. Fourth, in response to the set of split code files after removing the first split code file not being empty, use the set of split code files after removing the first split code file as the set of split code files and the added task sequence as the preset task sequence, and perform the above replacement steps again. The time for converting the GPU programming language code is reduced.

[0050] The second conversion step is to modify the file name of the above-mentioned replaced code file according to a preset name format to generate a modified file name. Among them, the above-mentioned preset name format can be a format preset for modifying the file name of the code file. For example, the above-mentioned preset name format can be the file name of the mirror code file + the hardware identifier of the hardware environment to be converted. As an example, the file name of the above-mentioned CUDA mirror code file can be "1", the above-mentioned hardware environment can be the MUSA coding environment, and the above-mentioned modified file name can be "1MUSA".

[0051] The third conversion step is to add the above-mentioned modified file name to a preset temporary file name sequence to generate an added preset temporary file name sequence as an added name sequence.

[0052] The fourth conversion step is to determine the generated replaced code file as the converted code file set in response to the mirror code file set after removing the first mirror code file being empty.

[0053] The fifth step is to, in response to the mirror code file set after removing the first mirror code file not being empty, use the above-mentioned added name sequence as the preset temporary file name sequence, use the mirror code file set after removing the first mirror code file as the mirror code file set, and execute the above-mentioned conversion steps again.

[0054] Optionally, before step 105, optimize each converted code file in the above-mentioned converted code file set according to the above-mentioned hardware information.

[0055] In some embodiments, the above-mentioned execution entity can optimize each converted code file in the above-mentioned converted code file set according to the above-mentioned hardware information.

[0056] Step 105: Compile the converted code file set according to the hardware information to generate a compilation result.

[0057] In some embodiments, the above-mentioned execution entity can compile the above-mentioned converted code file set according to the above-mentioned hardware information to generate a compilation result.

[0058] In practice, the above-mentioned execution entity can compile the above-mentioned converted code file set through the following steps:

[0059] The first step is to determine a target compiler corresponding to the above-mentioned hardware information according to the above-mentioned hardware information. In practice, the target compiler corresponding to the hardware information can be determined. For example, in response to the hardware information indicating a Moore Threads GPU, the above-mentioned target compiler can be the MCC (Moore Threads C Compiler) compiler.

[0060] In the second step, input the name-added sequence and the above set of converted code files into the above target compiler to obtain a compilation result.

[0061] In practice, the above execution entity can input the name-added sequence and the above set of converted code files into the above target compiler through the following sub-steps to obtain a compilation result:

[0062] In the first sub-step, determine whether compilation parameter information sent by the target terminal is received. Among them, the above compilation parameter information can be pre-set parameter information for compiling code files.

[0063] In the second sub-step, in response to receiving the compilation parameter information sent by the above target terminal, input the above compilation parameter information, the above name-added sequence, and the above set of converted code files into the above target compiler to obtain a compilation result.

[0064] In the third sub-step, in response to not receiving the compilation parameter information sent by the above target terminal, obtain a preset compilation parameter information set corresponding to the above hardware information. Among them, the preset compilation parameter information in the above preset compilation parameter information set can be pre-set compilation parameter system information (default parameters).

[0065] In the fourth sub-step, perform a merging process on the above preset compilation parameter information set according to the above set of converted code information to generate merged compilation information. In practice, first, the environmental information required by the above target encoder can be determined. Among them, the above environmental information can be information about the environment in which the converted code information can run stably. Secondly, according to the above environmental information, each preset compilation parameter information that meets the preset conditions can be selected from the preset compilation parameter information set for merging to generate merged compilation information. Among them, the above preset conditions can be the optimal preset compilation parameter information that meets the above environmental information.

[0066] As an example, in response to the above target compiler being an MCC compiler, the above environmental information may include optimization parameter information, link operation information, and link database information. The above optimization parameter information corresponds to -O2 and -O3 optimization parameters. Therefore, select the -O3 optimization parameter that meets the preset conditions as the optimization parameter.

[0067] In the fifth sub-step, input the above merged compilation information, the above name-added sequence, and the above set of converted code files into the above target compiler to obtain a compilation result.

[0068] In the third step, delete the above set of converted code files according to the above compilation result. In practice, in response to the compilation result indicating successful compilation, delete the above set of converted code files.

[0069] Step 106, in response to the compilation result indicating successful compilation, store the set of code files to be converted in the cache.

[0070] In some embodiments, the above execution entity may, in response to the compilation result indicating successful compilation, store the set of code files to be converted in the cache. Here, the set of code files to be converted may also be stored in an associated hard disk.

[0071] The above various embodiments of the present disclosure have the following beneficial effects: Through the code conversion method of some embodiments of the present disclosure, the situation of being unable to run the GPU of the current hardware manufacturer is avoided. Specifically, the reason for being unable to run the GPU of the current hardware manufacturer is that in a heterogeneous computing environment, it is necessary to convert the programming language code adapted to different hardware manufacturers multiple times, and it is impossible to determine the currently used hardware manufacturer, resulting in the inability to convert the programming language code, and thus the inability to run the GPU of the current hardware manufacturer. Based on this, the code conversion method of some embodiments of the present disclosure first obtains a set of code files to be converted. Thus, the code files that need to be converted can be determined. Secondly, the conversion parameter information corresponding to the set of code files to be converted is parsed to generate parsing information. Thus, it can be determined that the conversion parameters support code conversion. Then, in response to the parsing information indicating that the parameters are correct, according to the parsing information, the hardware information corresponding to the set of code files to be converted is determined. Thus, the GPU of the hardware manufacturer that needs to be converted can be automatically determined. After that, according to the above hardware information, the set of code files to be converted is converted to generate a set of converted code files. Thus, by automatically identifying the GPU of the hardware manufacturer to be converted, the code files that need to be converted can be converted. In a heterogeneous computing environment, there is no need to use different code conversion tools (compilers), thus avoiding the situation of being unable to run the GPU of the current hardware manufacturer. Then, according to the above hardware information, the set of converted code files is compiled to generate a compilation result. Thus, the converted programming language code can be compiled and run. Finally, in response to the compilation result indicating successful compilation, the set of code files to be converted is stored in the cache. Thus, the set of code files to be converted with successful compilation can be stored, and the code files can be quickly called from the cache when converting programming language code next time, reducing the time for converting code. The situation of being unable to run the GPU of the current hardware manufacturer is avoided.

[0072] Further referring to Figure 2 As an implementation of the methods shown in the above figures, the present disclosure provides some embodiments of a code conversion device. These device embodiments correspond to Figure 1 the method embodiments shown, and the code conversion device can be specifically applied to various electronic devices.

[0073] As shown Figure 2 As shown in FIG. 200, the code conversion apparatus 200 according to some embodiments includes: an obtaining unit 201, a parsing unit 202, a determining unit 203, a converting unit 204, a compiling unit 205, and a storing unit 206. Among them, the obtaining unit 201 is configured to obtain a set of code files to be converted, where the set of code files to be converted corresponds to conversion parameter information; the parsing unit 202 is configured to perform parsing processing on the conversion parameter information corresponding to the set of code files to be converted to generate parsing information; the determining unit 203 is configured to, in response to the parsing information indicating that the parameters are correct, determine the hardware information corresponding to the set of code files to be converted according to the parsing information; the converting unit 204 is configured to perform conversion processing on the set of code files to be converted according to the hardware information to generate a set of converted code files; the compiling unit 205 is configured to perform compiling processing on the set of converted code files according to the hardware information to generate a compiling result; the storing unit 206 is configured to, in response to the compiling result indicating successful compilation, store the set of code files to be converted in the cache.

[0074] It can be understood that the units described in the code conversion apparatus 200 correspond to the respective steps in the method described with reference to Figure 1 Therefore, the operations, features, and beneficial effects described above for the method also apply to the code conversion apparatus 200 and the units included therein, and will not be described herein again.

[0075] Next, with reference to Figure 3 FIG. 300 shows a schematic structural diagram of an electronic device 300 suitable for implementing some embodiments of the present disclosure. The electronic device in some embodiments of the present disclosure may include, but is not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Tablet Computers), PMPs (Portable Multimedia Players), in-vehicle terminals (such as in-vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 3 The electronic device shown in FIG. 300 is only an example and should not impose any limitation on the functions and usage scope of the embodiments of the present disclosure.

[0076] As shown Figure 3As shown, the electronic device 300 may include a processing device 301 (such as a central processing unit, a graphics processing unit, etc.), which may perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 302 or a program loaded from a storage device 308 into a random access memory (RAM) 303. In the RAM 303, various programs and data required for the operation of the electronic device 300 are also stored. The processing device 301, the ROM 302, and the RAM 303 are connected to each other through a bus 304. An input / output (I / O) interface 305 is also connected to the bus 304.

[0077] Generally, the following devices may be connected to the I / O interface 305: an input device 306 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 307 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 308 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 309. The communication device 309 may allow the electronic device 300 to communicate with other devices wirelessly or wiredly to exchange data. Although Figure 3 the electronic device 300 with various devices is shown, it should be understood that it is not required to implement or have all the shown devices. More or fewer devices may be implemented or had alternatively. Figure 3 Each block shown in may represent a device or, as required, multiple devices.

[0078] In particular, according to some embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, some embodiments of the present disclosure include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes program codes for performing the methods shown in the flowcharts. In such some embodiments, the computer program may be downloaded and installed from a network through the communication device 309, or installed from the storage device 308, or installed from the ROM 302. When the computer program is executed by the processing device 301, the above functions defined in the methods of some embodiments of the present disclosure are executed.

[0079] It should be noted that the computer-readable media described in some embodiments of the present disclosure may be a computer-readable signal medium, a computer-readable storage medium, or any combination of the two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In some embodiments of the present disclosure, the computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In some embodiments of the present disclosure, the computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium may also be any computer-readable medium other than the computer-readable storage medium, which can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.

[0080] In some embodiments, the client and the server may communicate using any currently known or future-developed network protocol such as HTTP (HyperText Transfer Protocol), and may be interconnected with digital data communication in any form or medium (e.g., a communication network). Examples of communication networks include local area networks ("LANs"), wide area networks ("WANs"), the Internet (e.g., the Internet), and end-to-end networks (e.g., ad hoc end-to-end networks), as well as any currently known or future-developed network.

[0081] The above computer-readable medium may be included in the above electronic device; or it may exist independently without being assembled into the electronic device. The above computer-readable medium carries one or more programs, and when the one or more programs are executed by the electronic device, the electronic device is caused to: obtain a set of code files to be converted, wherein the set of code files to be converted corresponds to conversion parameter information. Parse and process the conversion parameter information corresponding to the set of code files to be converted to generate parsed information. In response to the parsed information indicating that the parameters are correct, determine the hardware information corresponding to the set of code files to be converted according to the parsed information. Convert the set of code files to be converted according to the hardware information to generate a set of converted code files. Compile the set of converted code files according to the hardware information to generate a compilation result. In response to the compilation result indicating successful compilation, store the set of code files to be converted in the cache.

[0082] Computer program code for performing the operations of some embodiments of the present disclosure may be written in one or more programming languages or combinations thereof. The programming languages include object-oriented programming languages such as Java, Smalltalk, C++, and also include conventional procedural programming languages such as the "C" language or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, executed as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., by connecting through the Internet using an Internet service provider).

[0083] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagram may represent a module, a program segment, or a part of code that contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than marked in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, and combinations of blocks in the block diagram and / or flowchart, may be implemented by a dedicated hardware-based system for performing the specified functions or operations, or may be implemented by a combination of dedicated hardware and computer instructions.

[0084] The units described in some embodiments of the present disclosure can be implemented in software or in hardware. The described units can also be provided in a processor. For example, it can be described as: a processor includes an acquisition unit, a parsing unit, a determination unit, a conversion unit, a compilation unit, and a storage unit. Among them, the names of these units do not constitute a limitation to the unit itself in some cases. For example, the acquisition unit can also be described as "the unit for acquiring the code file set to be converted".

[0085] The functions described above can be performed, at least in part, by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that can be used include: Field Programmable Gate Array (FPGA), Application Specific Integrated Circuit (ASIC), Application Specific Standard Product (ASSP), System on Chip (SOC), Complex Programmable Logic Device (CPLD), and so on.

[0086] The above description is only some preferred embodiments of the present disclosure and an explanation of the applied technical principles. Those skilled in the art should understand that the scope of the invention involved in the embodiments of the present disclosure is not limited to the technical solutions formed by the specific combination of the above technical features, and should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above inventive concept. For example, the technical solutions formed by mutually replacing the above features with the (but not limited to) technical features with similar functions disclosed in the embodiments of the present disclosure.

Claims

1. A code conversion method, comprising: Obtaining a set of code files to be converted, where the set of code files to be converted corresponds to conversion parameter information; Performing parsing processing on the conversion parameter information corresponding to the set of code files to be converted to generate parsing information; In response to the parsing information indicating that the parameters are correct, determining the hardware information corresponding to the set of code files to be converted according to the parsing information; Performing conversion processing on the set of code files to be converted according to the hardware information to generate a set of converted code files; Performing compilation processing on the set of converted code files according to the hardware information to generate a compilation result; In response to the compilation result indicating successful compilation, storing the set of code files to be converted in a cache; Wherein, the performing conversion processing on the set of code files to be converted according to the hardware information to generate a set of converted code files includes: Obtaining a set of mapping information corresponding to the hardware information according to the hardware information, where the mapping information in the set of mapping information includes one of the following: header file mapping information, interface mapping information, and body mapping information; Initializing a preset temporary file name sequence, where the preset temporary file name sequence is initially empty; Performing mirror processing on each code file to be converted in the set of code files to be converted to generate a set of mirror code files; Based on the set of mirror code files and the preset temporary file name sequence, performing the following conversion steps: Performing string replacement processing on the first mirror code file in the set of mirror code files according to the set of mapping information to generate a replaced code file; Modifying the file name of the replaced code file according to a preset name format to generate a modified file name; Adding the modified file name to the preset temporary file name sequence to generate an added preset temporary file name sequence as an added name sequence; In response to the set of mirror code files after removing the first mirror code file being empty, determining the generated replaced code file as the set of converted code files.

2. The method according to claim 1, wherein The method further includes: In response to the set of mirror code files after removing the first mirror code file not being empty, using the added name sequence as the preset temporary file name sequence, using the set of mirror code files after removing the first mirror code file as the set of mirror code files, and performing the conversion steps again.

3. The method according to claim 1, wherein Before the performing compilation processing on the set of converted code files according to the hardware information to generate a compilation result, the method further includes: Optimizing each converted code file in the set of converted code files according to the hardware information.

4. The method according to claim 2, wherein, The performing compilation processing on the set of converted code files according to the hardware information to generate a compilation result includes: Determining a target compiler corresponding to the hardware information according to the hardware information; Inputting the added name sequence and the set of converted code files into the target compiler to obtain a compilation result; Deleting the set of converted code files according to the compilation result.

5. The method according to claim 4, wherein The inputting the added name sequence and the set of converted code files into the target compiler to obtain a compilation result includes: Determine whether the compilation parameter information sent by the target terminal is received; In response to receiving the compilation parameter information sent by the target terminal, input the compilation parameter information, the added name sequence, and the set of converted code files into the target compiler to obtain a compilation result.

6. The method according to claim 5, wherein, The step of inputting the added name sequence and the set of converted code files into the target compiler to obtain a compilation result further includes: In response to not receiving the compilation parameter information sent by the target terminal, obtain a preset compilation parameter information set corresponding to the hardware information; According to the set of converted code information, perform a merging process on the preset compilation parameter information set to generate merged compilation information; Input the merged compilation information, the added name sequence, and the set of converted code files into the above-mentioned target compiler to obtain a compilation result.

7. A code conversion device, comprising: An acquisition unit configured to acquire a set of code files to be converted, wherein the set of code files to be converted corresponds to conversion parameter information; An analysis unit configured to perform an analysis process on the conversion parameter information corresponding to the set of code files to be converted to generate analysis information; A determination unit configured to, in response to the analysis information indicating that the parameters are correct, determine the hardware information corresponding to the set of code files to be converted according to the analysis information; A conversion unit configured to perform a conversion process on the set of code files to be converted according to the hardware information to generate a set of converted code files; the conversion unit is further configured to: According to the hardware information, obtain a set of mapping information corresponding to the hardware information, wherein the mapping information in the set of mapping information includes one of the following: header file mapping information, interface mapping information, and body mapping information; Initialize a preset temporary file name sequence, wherein the preset temporary file name sequence is initially empty; Perform a mirroring process on each code file to be converted in the set of code files to be converted to generate a set of mirrored code files; Based on the set of mirrored code files and the preset temporary file name sequence, perform the following conversion steps: According to the set of mapping information, perform a string replacement process on the first mirrored code file in the set of mirrored code files to generate a replaced code file; Modify the file name of the replaced code file according to a preset name format to generate a modified file name; Add the modified file name to the preset temporary file name sequence to generate an added preset temporary file name sequence as the added name sequence; In response to the set of mirrored code files after removing the first mirrored code file being empty, determine the generated replaced code file as the set of converted code files; A compilation unit configured to perform a compilation process on the set of converted code files according to the hardware information to generate a compilation result; A storage unit configured to, in response to the compilation result indicating successful compilation, store the set of code files to be converted in the cache.

8. An electronic device, comprising: One or more processors; A storage device on which one or more programs are stored; When the one or more programs are executed by the one or more processors such that the one or more processors implement the method according to any one of claims 1 to 6.

9. A computer-readable medium having a computer program stored thereon, wherein, When the program is executed by a processor, it implements the method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • An allocation and issue stage for reordering a microinstruction sequence into an optimized microinstruction sequence to implement an instruction set agnostic runtime architecture

    CN106716362A

  • Code generation method and code generation device

    CN113268229A