Code conversion tools, code compilation methods and related products
By using a code conversion tool and the TVM framework, the automatic conversion from high-level code to low-level intermediate representation is achieved, solving the code conversion problem between different operator development methods and reducing programming difficulty.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-21
- Publication Date
- 2026-04-03
AI Technical Summary
In existing technologies, programming frameworks provide users with a variety of flexible operator development methods, which makes code conversion between high-level and low-level operator development methods difficult and results in an imbalance in programming difficulty.
This invention provides a code conversion tool that converts the source code of high-level operator development methods into low-level intermediate representations through an automated code compilation process. It utilizes the TVM framework to realize the mapping relationship between different code expression forms, thereby reducing the complexity of writing low-level target code for users.
It enables the automatic conversion of high-level code into low-level intermediate representations, reducing the programming difficulty for users and simplifying the programming process.
Smart Images

Figure CN116301872B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, specifically to a code conversion tool, a code compilation method, and related products. Background Technology
[0002] With the widespread application of deep learning technology, the demand for rapid deployment of network models on dedicated hardware platforms is increasing. To achieve efficient operator development and network construction, a programming framework can be provided for this dedicated hardware platform, offering a convenient software interface.
[0003] One implementation of the programming framework is based on the TVM (Tensor Virtual Machine) framework. TVM, as an open-source deep learning compilation stack, connects deep learning models and backend hardware platforms through a unified intermediate representation, thus making operator development adaptable to the backend hardware platform. In existing technologies, programming frameworks can provide users with various flexible operator development methods. Users can freely choose different operator development methods based on their understanding of the hardware platform, and then utilize the optimization and code generation capabilities of the programming framework to generate executable files for that hardware platform. The lower the level of the operator development method, the higher its programming difficulty; conversely, the higher the level of the operator development method, the lower its programming difficulty.
[0004] In this context, how to achieve code conversion between different operator development methods becomes a question worth exploring. Summary of the Invention
[0005] This application provides a code conversion tool, a code compilation method, and related products. The code conversion tool can convert code obtained through high-level operator development into low-level code through an automatic code compilation and conversion process, thereby reducing the programming difficulty for users.
[0006] In a first aspect, embodiments of this application provide a code conversion tool, wherein the code conversion tool is used for:
[0007] Obtain the source code, wherein the source code is implemented using a specific operator development method;
[0008] Determine the mapping relationship between the source code and the target intermediate representation;
[0009] Based on the mapping relationship between the source code and the target intermediate representation, the source code is converted into the target intermediate representation.
[0010] Secondly, embodiments of this application provide a code compilation method, wherein the method includes:
[0011] Obtain the source code, wherein the source code is implemented using a specific operator development method;
[0012] Determine the mapping relationship between the source code and the target intermediate representation;
[0013] Based on the mapping relationship between the source code and the target intermediate representation, the source code is converted into the target intermediate representation.
[0014] Thirdly, embodiments of this application provide an electronic device, including: a processor connected to a memory, the memory being used to store a computer program for implementing the above-mentioned code conversion tool, and the processor being used to execute the computer program stored in the memory to implement the conversion function of the code conversion tool.
[0015] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program that causes a computer to perform the method described in the second aspect.
[0016] Fifthly, embodiments of this application provide a computer program product, the computer program product including a non-transitory computer-readable storage medium storing a computer program, the computer being operable to perform the method as described in the second aspect.
[0017] Implementing the embodiments of this application has the following beneficial effects:
[0018] This code conversion tool can automatically convert high-level source code implemented by users using specific operator development methods into low-level intermediate representations, so that users do not need to understand the complex writing rules of low-level target code, thereby reducing programming difficulty. Attached Figure Description
[0019] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 A schematic diagram of a programming framework provided for an embodiment of this application;
[0021] Figure 2 A schematic diagram of another programming framework provided for an embodiment of this application;
[0022] Figure 3 A flowchart illustrating a code compilation method provided in an embodiment of this application;
[0023] Figure 4 This is a schematic diagram of the structure of a circuit board provided in an embodiment of this application;
[0024] Figure 5 This is a schematic diagram of the structure of a chip provided in an embodiment of this application. Detailed Implementation
[0025] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0026] The terms "first," "second," "third," and "fourth," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish different objects, not to describe a specific order. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or apparatuses.
[0027] In this document, the term "embodiment" means that a particular feature, result, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0028] With the widespread application of deep learning technology, the demand for rapid deployment of network models on dedicated hardware platforms is increasing. To achieve efficient operator development and network construction, a programming framework can be provided for this dedicated hardware platform, offering a convenient software interface.
[0029] One implementation of the programming framework is based on the TVM (Tensor Virtual Machine) framework. TVM, as an open-source deep learning compilation stack, connects deep learning models and backend hardware platforms through a unified intermediate representation, making operator development adaptable to the backend hardware platform. In existing technologies, programming frameworks offer users a variety of flexible operator development methods. Users can freely choose different operator development methods based on their understanding of the hardware platform, and then utilize the optimization and code generation capabilities of the programming framework to generate executable files for that hardware platform. The lower the level of the operator development method, the higher its programming difficulty; conversely, the higher the level, the lower the programming difficulty. When users use high-level operator development methods, a code compilation and conversion tool is needed to convert high-level code into target code.
[0030] In one embodiment of this disclosure, the programming framework may be implemented based on the TVM framework. Figure 1 A schematic diagram of the code hierarchy of the TVM programming framework is shown. The neural network model built by the user based on a deep learning framework (e.g., TensorFlow, PyTorch, Caffe, MXNet, PaddlePaddle, etc.) can be converted into a graph-level intermediate representation (e.g., GraphIR or Relay IR). Further, this graph-level intermediate representation can be compiled into a tensor-level intermediate representation (TIR, Tensor IR). Even further, this tensor-level intermediate representation can be compiled into target code adapted to the hardware platform. In one possible implementation, this target code can be C-like language code (e.g., CUDAC), which can be further compiled into binary instructions executable by the hardware platform. Optionally, to maximize the performance of the hardware platform, the programming rules of the target code can be determined based on the hardware platform's instruction set.
[0031] To fully utilize the resources of the hardware platform and maximize its performance, the programming framework can provide a series of application programming interfaces (APIs) to enable the development of custom operators. In this embodiment, to facilitate convenient operator development for users, the programming framework can provide a Python module. This Python module offers users a series of programming interfaces for developing operators using the Python language, allowing users to develop custom operators based on these interfaces.
[0032] The Python modules can be further categorized based on their ease of understanding of the hardware platform, including high-level Python operator development methods and low-level Python operator development methods. Operator implementation code developed using low-level Python operator development methods can be converted into tensor-level intermediate representations and further transformed to generate target code. Operator implementation code developed using high-level Python operator development methods can directly call operator implementation code obtained using low-level Python operator development methods, thus achieving the process of converting high-level Python operator implementation code into target code.
[0033] Because the code representation of this low-level Python operator development method differs from that of the intermediate representation at the tensor level, the aforementioned conversion process can be achieved through a code conversion tool or compiler. This disclosure provides a code conversion tool, which can be a piece of program code running on a general-purpose processor (such as a CPU). It can be used as a standalone plugin or embedded in a compiler; no specific limitations are made here.
[0034] like Figure 2 As shown, the code conversion tool disclosed herein can be used to obtain source code, determine the mapping relationship between the source code and the target intermediate representation, and convert the source code into the target intermediate representation according to the mapping relationship between the source code and the target intermediate representation. This code conversion tool can automatically convert high-level source code implemented by a user using a specific operator development method into a low-level intermediate representation, eliminating the need for the user to understand the complex writing rules of the low-level target code, thereby reducing programming difficulty.
[0035] The source code described herein is code implemented using a specific operator development method. In this embodiment, the source code may be operator code implemented using a low-level Python operator development method. For example, the source code may be operator code implemented using tensor computation primitives in the Python language, such as TCP (Tensor Computer Primitive) or TIK (TensorIterator Kernel), etc., without specific limitations. Furthermore, the source code implemented using a specific operator development method may include at least one operator for implementing different functions. This operator includes, but is not limited to, convolution operators, fully connected operators, activation operators, addition operators, conditional operators, and loop operators, etc. Even further, the source code implemented using a specific operator development method may be in the form of an executable module, etc., without specific limitations.
[0036] Optionally, the target intermediate representation can be a tensor-level intermediate representation (TIR) provided by the TVM framework. Since the source code obtained using low-level Python operators differs from the code representation of the target intermediate representation, the code conversion tool can establish a mapping relationship between different code representations to achieve code conversion based on this mapping. Optionally, the code conversion tool can establish a mapping relationship between each operator and different code representations separately to determine the mapping relationship between the entire source code and the target intermediate representation. Furthermore, the code conversion tool can automatically compile and convert the source code into the target intermediate representation based on the source code, the target intermediate representation, and the mapping relationship between them.
[0037] In one feasible embodiment, the code conversion tool is specifically used to parse the source code to obtain at least one function contained in the source code; for each function, the mapping relationship between the function and the target intermediate representation is determined to establish the mapping relationship between the source code and the target intermediate representation. Operators with different functionalities can be presented in the source code as functions. The source code can include at least one function, and each function can correspond to an implementation of an operator. Each function can include at least one parameter describing its implementation, such as the size and address of the input / output data, the data type (e.g., floating-point or integer), and the data arrangement. In this embodiment, by mapping each function in the source code to the target intermediate representation, the conversion between the source code and the target intermediate representation can be achieved.
[0038] For ease of explanation, this disclosure designates the way a function is expressed in the source code as the first representation, and correspondingly, the way the function is expressed in the target intermediate representation as the second representation. As mentioned above, there is a difference between the first and second representations. Based on this, the code conversion tool can be used to obtain, for each function, the first representation of the function in the source code and the second representation of the function in the target intermediate representation; and process the first representation according to the second representation to determine the mapping relationship between the first and second representations. Optionally, the processing of the first representation by the code conversion tool includes at least one of the following processing operations: direct mapping, splitting or merging the first parameter, determining the data address after splitting or merging, converting the data type of the first parameter, converting the data arrangement of the first parameter, etc.
[0039] Optionally, the second representation includes a scalar representation, which is used to express scalar data. A code conversion tool can be used to directly map the scalar data of the function in the first representation to the scalar representation.
[0040] Optionally, the second representation method further includes a tensor representation method for expressing tensor data. The code conversion tool is also used to determine the segmentation parameters of the tensor data of the function in the first representation method based on the tensor representation method of the target intermediate representation, so as to determine the mapping relationship between the first and second representation methods based on the segmentation parameters; wherein the segmentation parameters include the number of tensor data segments, the size of each sub-data obtained by segmentation, and the address information of each sub-data.
[0041] Specifically, the code conversion tool can segment the tensor data defined in the first representation method based on parameters involved in the tensor representation, which can be used to characterize the sub-tensors of the tensor data and the size and address information of each sub-tensor. Further, the code conversion tool can map the segmented sub-data to each sub-tensor defined in the tensor representation method. Even further, the code conversion tool can also convert the data type, data arrangement, and other characteristics of the tensor data defined in the first representation method.
[0042] For example, the source code below involves tensor data tcp.buffer:
[0043] def build_if(A:ty.handle,num_boxes:ty.int32)->None
[0044] A_1=tcp.buffer(A,
[64] ,dtype="float32",name="A").
[0045] The tensor representation of the target intermediate representation includes the size of the sub-tensors contained within the tensor data and the offset of each sub-tensor. When processing the source code, the code conversion tool can segment the tensor data `tcp.buffer` to obtain at least one sub-data, and calculate the size of each sub-data and its offset from the starting address. Then, the code conversion tool can map each sub-data in the source code to the corresponding sub-tensor in the target intermediate representation, and map the offset of each sub-data in the source code to the offset of the corresponding sub-tensor in the target intermediate representation, thereby establishing a mapping relationship between the source code and the target code, and completing the code conversion based on this mapping relationship.
[0046] Optionally, the aforementioned code conversion tool is also used to determine the type of the function; and based on the type of the function, to determine a second representation of the function in the target intermediate representation. As mentioned above, each function can correspond to an operator, wherein the operator includes, but is not limited to, convolution operators, fully connected operators, activation operators, addition operators, conditional operators, etc. Accordingly, the type of the function can be determined according to the function of the operator, which can include convolution functions, fully connected functions, activation functions, addition functions, conditional functions (such as if functions), and loop functions (such as for functions), without specific limitations here.
[0047] The target intermediate representation includes a function template library containing various code representations of different functions within the target intermediate representation. The code conversion tool can query the function template library to obtain a second representation of the function in the target intermediate representation based on its type. Optionally, the function template library can be a series of application programming interfaces (APIs) provided by a programming framework, where each function can correspond to one API. The code conversion tool can determine the second representation of each function in the target intermediate representation based on parameters such as its data type and data arrangement.
[0048] Based on the above description, the code conversion tool can automatically convert between two different code representations through the mapping relationship between source code and the target intermediate representation. Furthermore, the tool can also be used to convert the target intermediate representation into target code, which can be code written in a C-like language (e.g., CUDA C). That is, the tool can also be used to compile the tensor-level target intermediate representation (TIR) into target code.
[0049] like Figure 3 As shown, in one embodiment of this disclosure, a code compilation method is also provided, wherein the method includes:
[0050] S310. Obtain the source code, wherein the source code is code implemented using a specific operator development method. In this embodiment of the disclosure, the source code may be operator code implemented using a low-level Python operator development method. For example, the source code may be operator code implemented using tensor computation primitives in the Python language, such as TCP (Tensor Computer Primitive) or TIK (Tensor Iterator Kernel), etc., without specific limitations here.
[0051] Furthermore, the source code implemented using a specific operator development method may include multiple operators for implementing different functions. These operators include, but are not limited to, convolution operators, fully connected operators, activation operators, addition operators, conditional operators, and loop operators, etc.
[0052] S320. Determine the mapping relationship between the source code and the target intermediate representation.
[0053] Specifically, the target intermediate representation can be a tensor-level intermediate representation (TIR) provided by the TVM framework. Since the source code obtained using low-level Python operators differs from the code representation of the target intermediate representation, the code conversion tool can establish a mapping relationship between different code representations to achieve code conversion. Optionally, the code conversion tool can establish a mapping relationship between each operator and different code representations separately to determine the mapping relationship between the source code and the target intermediate representation.
[0054] S330. Based on the mapping relationship between the source code and the target intermediate representation, the source code is converted into the target intermediate representation. Specifically, the code conversion tool can automatically compile and convert the source code into the target intermediate representation based on the source code, the target intermediate representation, and the mapping relationship between the two.
[0055] This code conversion tool can automatically convert high-level source code implemented by users using specific operator development methods into low-level intermediate representations, so that users do not need to understand the complex writing rules of low-level target code, thereby reducing programming difficulty.
[0056] Optionally, determining the mapping relationship between the source code and the target code includes:
[0057] Parse the source code to obtain at least one function contained in the source code; wherein, operators with different functions can be presented in the source code in the form of functions, the source code can include at least one function, each function can correspond to the implementation of an operator, and each function can include at least one parameter for describing its function implementation, such as the size and address of input / output data, data type (such as floating point or integer, etc.) and data arrangement method, etc.
[0058] For each function, determine the mapping relationship between the source code and the target intermediate representation.
[0059] For ease of explanation, this disclosure designates the way a function is expressed in the source code as the first representation, and correspondingly, the way the function is expressed in the target intermediate representation as the second representation. As mentioned above, there is a difference between the first and second representations. Specifically, determining the mapping relationship between the source code and the target intermediate representation for each function further includes:
[0060] For each function, obtain the first representation of the function in the source code and the second representation of the function in the target intermediate representation;
[0061] The first representation is processed according to the second representation to determine the mapping relationship between the first and second representations. Optionally, the code conversion tool processes the relevant first parameters in the first representation, including at least one of the following operations: direct mapping, splitting or merging the first parameters, determining the data address after splitting or merging, converting the data type of the first parameters, converting the data layout of the first parameters, etc.
[0062] Optionally, the second representation includes a scalar representation, which is used to express scalar data. The processing of the first representation according to the second representation includes:
[0063] A scalar representation that directly maps scalar data in the function to the intermediate representation of the target.
[0064] Optionally, the second representation further includes a tensor representation for expressing tensor data. The processing of the first representation according to the second representation further includes:
[0065] Based on the tensor representation of the target intermediate representation, the segmentation parameters of the tensor data in the function are determined, so as to determine the mapping relationship between the first representation and the second representation based on the segmentation parameters; wherein the segmentation parameters include the number of tensor data segments, the size of each sub-data obtained by segmentation, and the address information of each sub-data.
[0066] For example, the source code below involves tensor data tcp.buffer:
[0067] def build_if(A:ty.handle,num_boxes:ty.int32)->None
[0068] A_1=tcp.buffer(A,
[64] ,dtype="float32",name="A").
[0069] The tensor representation of the target intermediate representation includes the size of the sub-tensors contained within the tensor data and the offset of each sub-tensor. When processing the source code, the code conversion tool can segment the tensor data `tcp.buffer` to obtain at least one sub-data, and calculate the size of each sub-data and its offset from the starting address. Then, the code conversion tool can map each sub-data in the source code to the corresponding sub-tensor in the target intermediate representation, and map the offset of each sub-data in the source code to the offset of the corresponding sub-tensor in the target intermediate representation, thereby establishing a mapping relationship between the source code and the target code, and completing the code conversion based on this mapping relationship.
[0070] Optionally, the above method further includes:
[0071] Determine the type of the function;
[0072] Based on the function's type, a second representation of the function in the target intermediate representation is determined. This target intermediate representation has a function template library, which includes various code representations of different functions within the target intermediate representation. The code conversion tool can query the function template library to obtain the second representation of the function in the target intermediate representation based on its type. Optionally, the function template library can be a series of programming interfaces (APIs) provided by a programming framework, where each function can correspond to one API. The code conversion tool can determine the second representation of each function in the target intermediate representation based on parameters such as the function's data type and data arrangement.
[0073] Furthermore, the method also includes:
[0074] The target intermediate representation is compiled into target code; wherein, the target code can be code formed in a C-like language (e.g., CUDA C). That is, the code conversion tool can also be used to compile the tensor-level target intermediate representation (TIR) into target code.
[0075] Furthermore, the method also includes:
[0076] The target code is compiled into an executable file, which may be binary instructions that the hardware platform can execute. Specifically, the executable file can be delivered to the hardware platform, which then performs corresponding computations or storage operations based on the executable file.
[0077] Optionally, the hardware platform can be a board or a chip. For example... Figure 4As shown, the board 400 includes a chip 402 and other supporting components, including but not limited to: a storage device 404, an interface device 406, and a controller 408.
[0078] The storage device is connected to the chip within the chip package structure via a bus and is used to store data. The storage device may include multiple sets of storage cells 410. Each set of storage cells is connected to the chip via a bus. It can be understood that each set of storage cells may be DDR SDRAM (Double Data Rate SDRAM).
[0079] The interface device is electrically connected to the chip within the chip package structure. The interface device is used to realize data transmission between the chip and an external device 412 (e.g., a server or computer). For example, in one embodiment, the interface device can be a standard PCIe interface. For instance, data to be processed is transferred from the server to the chip via a standard PCIe interface, realizing data transfer. In another embodiment, the interface device can also be other interfaces; this disclosure does not limit the specific form of the other interfaces mentioned above, as long as the interface unit can realize the switching function. Furthermore, the calculation results of the chip are still transmitted back to the external device (e.g., the server) by the interface device.
[0080] The controller is electrically connected to the chip. The controller monitors the state of the chip. Specifically, the chip and the controller can be electrically connected via an SPI interface. The controller may include a microcontroller (MCU). The chip may include multiple processing chips, multiple processing cores, or multiple processing circuits, capable of driving multiple loads. Therefore, the chip can operate in different states, such as high load and low load. The controller can regulate the operating states of multiple processing chips, multiple processing cores, and / or multiple processing circuits within the chip.
[0081] Figure 5 A schematic diagram of a chip architecture is shown. This chip could be an image processing chip or an artificial intelligence processing chip. Figure 5 As shown, Figure 4 The chip 402 may include an external storage controller 501, a peripheral communication module 502, an on-chip interconnect module 503, a synchronization module 504, and multiple clusters 505.
[0082] There can be multiple external storage controllers 501; two are shown exemplarily in the figure. These controllers respond to access requests from the processor core and access external storage devices. The peripheral communication module 502 receives control signals from the processing controller via the interface device 406, initiating the chip 402 to execute tasks. The on-chip interconnect module 503 connects the external storage controllers 501, the peripheral communication module 502, and multiple clusters 505, enabling data and control signal transmission between the modules. The synchronization module 504 is a global barrier controller (GBC) used to coordinate the working progress of each cluster and ensure information synchronization. The multiple clusters 505 are the computing core of the chip; four are shown exemplarily in the figure. With hardware development, the chip 401 of this invention can also include eight, sixteen, sixty-four, or even more clusters. The clusters 505 can be used to efficiently execute deep learning algorithms.
[0083] This application provides an electronic device, including: a processor connected to a memory, the memory storing a computer program for implementing the aforementioned code conversion tool, and the processor executing the computer program stored in the memory to implement the conversion function of the code conversion tool. The specific conversion function of the code conversion tool can be found in the description of the code conversion tool above, and will not be repeated here. Optionally, the processor may be a general-purpose processor such as a CPU, and the code conversion tool may run on this processor.
[0084] This application also provides a computer-readable storage medium storing a computer program that is executed by a processor to implement some or all of the steps of any of the methods described in the above method embodiments. Specifically, the implementation steps of the computer program are substantially the same as the implementation steps of the above methods, as detailed in the above description, and will not be repeated here.
[0085] This application also provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program. The computer program is operable to cause a computer to perform some or all of the steps of any of the methods described in the above method embodiments. Specifically, the implementation steps of the computer program are substantially the same as the implementation steps of the above methods, and can be found in the description above, which will not be repeated here.
[0086] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily essential to this application.
[0087] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0088] In the several embodiments provided in this application, it should be understood that the disclosed apparatus can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical or other forms.
[0089] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0090] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software program module.
[0091] If the integrated unit is implemented as a software program module and sold or used as an independent product, it can be stored in a computer-readable storage device (CMD). Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned memory includes various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0092] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, which may include: flash drive, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0093] The embodiments of this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The description of the above embodiments is only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A code conversion tool, wherein, The code conversion tool is used for: Obtain the source code, wherein the source code is a custom operator implemented using a specific operator development method; Determine the mapping relationship between the source code and the target intermediate representation; wherein the target intermediate representation is a tensor-level intermediate representation; Based on the mapping relationship between the source code and the target intermediate representation, the source code is converted into the target intermediate representation; The step of determining the mapping relationship between the source code and the target code includes: Parse the source code to obtain at least one function contained in the source code; For each function, the mapping relationship between the function and the target intermediate representation is determined to establish the mapping relationship between the source code and the target intermediate representation.
2. The code conversion tool according to claim 1, wherein, The code conversion tool is used for: For each function, obtain the first representation of the function in the source code and the second representation of the function in the target intermediate representation; The first representation is processed according to the second representation to determine the mapping relationship between the first representation and the second representation.
3. The code conversion tool according to claim 2, wherein, The second representation method includes scalar representation; The code conversion tool is used to directly map the scalar data of the function in the first representation to the scalar representation.
4. The code conversion tool according to claim 2 or 3, wherein, The second representation method also includes tensor representation; the code conversion tool is further used for: Based on the tensor representation of the target intermediate representation, determine the segmentation parameters of the tensor data of the function in the first representation; wherein, the segmentation parameters include the number of tensor data segments, the size of each sub-data obtained from the segmentation, and the address information of each sub-data. The mapping relationship between the first representation and the tensor representation is determined based on the segmentation parameters.
5. The code conversion tool according to claim 4, wherein, The code conversion tool is also used for: Determine the type of the function; Based on the type of the function, determine the second representation of the function in the target code.
6. The code conversion tool according to any one of claims 1-5, wherein, The code conversion tool is also used for: The target intermediate representation is compiled into target code.
7. A code compilation method, wherein, The method includes: Obtain the source code, wherein the source code is a custom operator implemented using a specific operator development method; Determine the mapping relationship between the source code and the target intermediate representation; wherein the target intermediate representation is a tensor-level intermediate representation; Based on the mapping relationship between the source code and the target intermediate representation, the source code is converted into the target intermediate representation; The step of determining the mapping relationship between the source code and the target code includes: Parse the source code to obtain at least one function contained in the source code; For each function, the mapping relationship between the function and the target intermediate representation is determined to establish the mapping relationship between the source code and the target intermediate representation.
8. The method according to claim 7, wherein, The method further includes: Compile the target intermediate representation into target code; Further, the target code is compiled into an executable file.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that is executed by a processor to implement the method as described in claim 7 or 8.
Citation Information
Patent Citations
Compilation method, device, and equipment based on heterogeneous system, and storage medium
CN113553054A