Method and apparatus for automatically generating operator calling code, and medium and device

By analyzing the calculation diagram of the deep learning algorithm and generating the corresponding operator call code, the operator call code rewriting problem caused by the adaptation of the back-end hardware platform is solved, and efficient code generation and development efficiency are improved.

WO2025060180A1PCT designated stage expired Publication Date: 2025-03-27ZHEJIANG LAB

Patent Information

Application Number
PCT/CN2023/126815
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-09-18
Filing Date
2023-10-26
Publication Date
2025-03-27

AI Technical Summary

Technical Problem

In the deep learning framework, with the adaptation of the back-end hardware platform, the implementation method of back-end operators has changed, resulting in developers needing to rewrite operator call code, which is complicated and time-consuming, resulting in waste of human resources.

Method used

By obtaining the basic information of the operator library of the backend hardware platform and the calculation diagram of the target deep learning algorithm, analyzing the calculation diagram, determining the front-end operator, and generating the corresponding call code based on the mapping relationship between the front-end operator and the operator call template, automatically generating the call code of the back-end operator.

Benefits of technology

It improves the generation efficiency of operator call code, reduces the waste of human resources, simplifies the complex coding process, and greatly improves development efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2023126815_27032025_PF_FP_ABST
    Figure CN2023126815_27032025_PF_FP_ABST
Patent Text Reader

Abstract

Disclosed in the present disclosure are a method and apparatus for automatically generating an operator calling code, and a medium and a device. The method comprises: acquiring basic information of an operator library corresponding to a back-end hardware platform, and a computation graph of a target deep learning algorithm; generating a code head of an operator calling code on the basis of the basic information of the operator library; parsing the computation graph to determine each front-end operator in the computation graph; for each front-end operator, on the basis of a mapping relationship between the front-end operator and an operator calling template, determining a declaration statement of the operator calling template corresponding to the operator, and a calling statement of a template function; on the basis of the code head, the declaration statement, the calling statement, and configuration information corresponding to the operator, generating a complete calling code of a back-end operator; and calling each back-end operator on the basis of the calling code of each back-end operator, so as to execute a computation task by means of each back-end operator.
Need to check novelty before this filing date? Find Prior Art

Description

Method, device, medium and equipment for automatically generating operator call code Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a method, apparatus, medium, and device for automatically generating operator call code. Background Art

[0002] Operators are fundamental components of deep learning frameworks. Generally, AI (Artificial Intelligence) models consist of several computational modules, such as the fully connected Dense layer, the Convolutional Conv layer, and the Relu activation function. These computational modules are implemented by calling encapsulated backend operators. Because computational modules typically process data as tensors, and different backend hardware platforms differ in their storage, processing, and computational methods for tensors, different backend hardware platforms may have different implementation details for the same operator, resulting in different exposed operator call interfaces.

[0003] To call an operator on a specific backend hardware platform, you need to write operator call code according to its format requirements. In a typical framework, you need to write an operator call code for each operator based on all the information required for the operator call, and then complete the call to the underlying operator call interface.

[0004] However, in the process of adapting deep learning frameworks to new hardware platforms, due to changes in the implementation methods of back-end operators, developers are required to rewrite new operator call codes to implement the calls to back-end operators. The writing process is relatively complicated, which not only consumes a lot of time but also causes a serious waste of human resources.

[0005] Therefore, how to improve the efficiency of operator call code generation and reduce resource waste is an urgent problem to be solved.

[0006] Summary of the Invention

[0007] The present disclosure provides a method, apparatus, medium, and device for automatically generating operator call code to partially solve the above-mentioned problems existing in the prior art.

[0008] This disclosure adopts the following technical solutions:

[0009] The present disclosure provides a method for automatically generating operator call code, comprising:

[0010] Obtain basic information about the operator library corresponding to the backend hardware platform and the computational graph of the target deep learning algorithm;

[0011] Generate a code header of the operator call code according to the basic information of the operator library, wherein the code header is used to introduce the operator library and dependent libraries of the hardware platform;

[0012] Parsing the computation graph to determine each front-end operator in the computation graph;

[0013] For each front-end operator, determine the declaration statement of the operator call template and the calling statement of the template function corresponding to the operator based on the mapping relationship between the front-end operator and the operator call template;

[0014] Generate a backend operator's calling code based on the code header, the declaration statement, the calling statement, and the configuration information corresponding to the operator;

[0015] The backend operator of the backend hardware platform is called according to the calling code of the backend operator to execute the computing task through the backend operator.

[0016] Optionally, the basic information of the operator library includes: the path and name of the header file of the backend hardware platform operator library;

[0017] Generate the code header of the operator call code based on the basic information of the operator library, including:

[0018] Generate the import information of the dependent library and the import information of the operator library according to the path and name of the header file of the operator library;

[0019] The code header is generated according to the import information of the dependent library and the import information of the operator library.

[0020] Optionally, for each front-end operator, before determining a declaration statement of the operator call template and a call statement of the template function corresponding to the operator based on a mapping relationship between the front-end operator and the operator call template, the method further includes:

[0021] According to the configuration information corresponding to the front-end operator, a mapping relationship between the front-end operator and the operator call template is determined.

[0022] Optionally, for each front-end operator, according to the mapping relationship between the front-end operator and the operator call template, a declaration statement of the operator call template corresponding to the operator and a call statement for the template function are determined, including:

[0023] Get the target key-value pair with the name of the front-end operator as the key;

[0024] An operator call template corresponding to the value in the target key-value pair is determined, and the declaration statement and the call statement are generated, wherein for each operator call template, the operator call template corresponds to at least one front-end operator.

[0025] Optionally, the configuration information includes: the name of the operator call template, the number of input tensors, the number of output tensors, and the description object declaration of the backend operator corresponding to the operation, the operation declaration of the operation, and the memory release statement of the description object.

[0026] Optionally, a complete backend operator calling code is generated according to the code header, the declaration statement, the calling statement, and the configuration information corresponding to the operator, including:

[0027] Calling the complete function body of the template function corresponding to the operator calling template according to the declaration statement and the call statement;

[0028] Generate the calling code of the backend operator according to the template function, the code header and the configuration information.

[0029] Optionally, the template function corresponding to the operator call template contains module codes of various functional modules, and the module codes include: device management module code, memory application module code, tensor declaration module code, data handling module code, operation module code and memory release module code.

[0030] The present disclosure provides an automatic generation device for operator call code, comprising:

[0031] Get the module to obtain the basic information of the operator library corresponding to the backend hardware platform and the calculation graph of the target deep learning algorithm;

[0032] A first generation module generates a code header of an operator call code according to the basic information of the operator library, wherein the code header is used to introduce the operator library and dependent libraries of the hardware platform;

[0033] A parsing module, which parses the computation graph and determines each front-end operator in the computation graph;

[0034] The determination module determines, for each front-end operator, the declaration statement of the operator call template and the calling statement of the template function corresponding to the operator according to the mapping relationship between the front-end operator and the operator call template;

[0035] A second generation module generates a call code for a backend operator based on the code header, the declaration statement, the call statement, and configuration information corresponding to the operator;

[0036] The calling module calls the backend operator of the backend hardware platform according to the calling code of the backend operator to execute the computing task through the backend operator.

[0037] The present disclosure provides a computer-readable storage medium storing a computer program, which implements the above-mentioned method for automatically generating operator call codes when executed by a processor.

[0038] The present disclosure provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the method for automatically generating operator call codes is implemented.

[0039] At least one of the above technical solutions adopted in the present disclosure can achieve the following beneficial effects:

[0040] In the method for automatically generating operator call code provided by the present invention, basic information of the operator library corresponding to the backend hardware platform and the calculation graph of the target deep learning algorithm are obtained; a code header of the operator call code is generated according to the basic information of the operator library; the calculation graph is parsed to determine each front-end operator in the calculation graph; for each front-end operator, the declaration statement of the operator call template corresponding to the operator and the call statement of the template function are determined according to the mapping relationship between the front-end operator and the operator call template; the call code of the back-end operator is generated according to the code header, the declaration statement, the call statement and the configuration information corresponding to the operator; and each back-end operator is called according to the call code of each back-end operator to execute the computing task through each back-end operator.

[0041] It can be seen from the above method that this solution can parse the deep learning algorithm calculation graph, and then automatically generate the back-end operator calling code based on the mapping configuration information of the front-end operator and the operator library in the back-end hardware platform. Compared with the method of developers rewriting the operator calling code, this solution can automatically generate the calling code of the new operator, improve the generation efficiency of the operator calling code, and greatly save human resources and the complexity of operator calling. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] The drawings described herein are used to provide further understanding of the present disclosure and constitute a part of the present disclosure. The exemplary embodiments of the present disclosure and their descriptions are used to explain the present disclosure and do not constitute improper limitations on the present disclosure.

[0043] FIG1 is a flow chart of a method for automatically generating operator call code provided in the present disclosure;

[0044] FIG2 is a schematic diagram of a mapping relationship between a front-end operator and an operator call target provided in the present disclosure;

[0045] FIG3 is a schematic diagram of the structure of an operator call template provided in the present disclosure;

[0046] FIG4 is a schematic diagram of an automatic generation device for operator call code provided by the present disclosure;

[0047] FIG5 is a schematic diagram of an electronic device provided by the present disclosure corresponding to FIG1 . DETAILED DESCRIPTION

[0048] To make the objectives, technical solutions, and advantages of the present disclosure more clear, the technical solutions of the present disclosure will be clearly and completely described below in conjunction with the specific embodiments of the present disclosure and the corresponding drawings. The described embodiments are only part of the embodiments of the present disclosure, not all of the embodiments. Based on the embodiments of the present disclosure, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present disclosure.

[0049] The technical solutions provided by various embodiments of the present disclosure are described in detail below with reference to the accompanying drawings.

[0050] FIG1 is a flow chart of a method for automatically generating operator call code provided in the present disclosure, which includes the following steps S101 - S106 .

[0051] S101: Obtain basic information of the operator library corresponding to the backend hardware platform and the computational graph of the target deep learning algorithm.

[0052] S102: Generate a code header of the operator call code according to the basic information of the operator library, where the code header is used to introduce the operator library and dependent libraries of the hardware platform.

[0053] The key to the implementation of artificial intelligence (AI) applications lies in the efficient training of AI models (deep learning models). In practical applications, deep learning frameworks implement the computational tasks involved in deep learning algorithm training by calling operators on the backend hardware platform.

[0054] Among them, the back-end hardware platform can include AI accelerators of different types and architectures, such as graphics processing units (GPUs), data processing units (DPUs), image processing units (IPUs), and tensor processing units (TPUs).

[0055] In addition, in the present disclosure, the execution entity for implementing a method for automatically generating operator call code can be a device such as a server deployed with a deep learning framework. For the sake of convenience of description, the present disclosure only takes the server as the execution entity as an example to illustrate a method for automatically generating operator call code provided in the present disclosure.

[0056] The server can obtain the basic information of the operator library corresponding to the backend hardware platform and the calculation graph of the target deep learning algorithm. The calculation graph can be obtained after compiling the deep learning algorithm.

[0057] The operator library is a collection of operators supported by the hardware platform. For example, there are multiple operator libraries available for GPU, including oneDNN, cuDNN, etc. Each operator library contains multiple GPU operators, such as convolution operators, pooling operators, activation function operators, etc. The dependency library can refer to the C++ standard library used in the code body, such as<stdio.h> 、 <iostream> 、 <memory>The specific configuration of the operator library and the dependent library can be obtained according to actual conditions, and this disclosure does not impose any restrictions on this.

[0058] The basic information of an operator library includes the path and name of the header file of the operator library in the local memory of the backend hardware platform. Based on the path and name of the operator library header file, the server can generate the import information of the operator's dependent library and the operator library, and then generate the code header based on the import information of the dependent library and the operator library. In this way, the dependent library and the operator library are imported through this code header during the backend operator call process.

[0059] S103: Analyze the computation graph to determine each front-end operator in the computation graph.

[0060] S104: For each front-end operator, determine the declaration statement of the operator call template and the calling statement of the template function corresponding to the operator according to the mapping relationship between the front-end operator and the operator call template.

[0061] In the field of AI compilers, layers are called front-ends, and the operator layers on the hardware platform are called back-ends. Operators in layers are front-end operators, while operators on the hardware platform are back-end operators. For example, a batch matrix multiplication (batch_mutmul) operator and a fully connected layer (dense) operator in the front-end computation graph will be mapped to different back-end operators when mapped to different hardware platforms. For example, on hardware platform A, both operators are mapped to the dot operator, while on hardware platform B, they are mapped to the batch_dot and dot operators, respectively.

[0062] The server can parse the obtained computational graph to determine the front-end operators corresponding to the computational graph, such as Dense, Conv, Relu, etc. In addition, the server can also determine the topological relationship between the front-end operators.

[0063] The server can then generate a declaration statement for the operator call template based on the mapping relationship between the front-end operator and the operator call template.

[0064] Among them, the above mapping relationship can be determined according to the configuration information of the front-end operator. Developers can set the configuration information of different operators in advance. For each front-end operator, the configuration information corresponding to the front-end operator may include: the name of the operator call template, the number of tensors input to the operator, the number of tensors output by the operator, and the description object declaration of the operation of the back-end operator corresponding to the front-end operator (used to specify the description object of the operation), the operation operation declaration (used to specify the operation operation of the operator), and the memory release statement of the description object (used to release the memory after the operation is completed).

[0065] The configuration information can be expressed as:

[0066] static std:map<std:string,std:string>TopsOpMap={{"ADD","topsAdd"},…};

[0067] static TopsOp CreateOpByName(std:string funcName){if(funcName=="topsAdd"){return TopsOp(funcName,2,1,{"TENSORND","TENSORND"},{"TENSORND"});}

[0068] else if(…)

[0069] else{std:cout<<"CreateOpByName#Unrecognized op:"<<funcName<<std:endl;throw"#Unrecognized op!";}}

[0070] static std:string Print Tops Op(const std:string&op Name){std:string s;

[0071] if(opName=="topsAdd"){s=PrintTopsBinaryOp("TOPS_BINARY_OP_ADD");}

[0072] else if(…)

[0073] else{std:cout<<"createOpByName#Unrecognized op:"<<opName<<std:endl;throw"#Unrecognized op!";}return s;}

[0074] static std:string Print TopsBinaryOp(const std:string&mode){std:ostringstream code_stream_;

[0075] code_stream_ << "topsBinaryOp(deviceCtx, " << mode << ", desc_i_0, mem_i_0, desc_i_1, mem_i_1, desc_o_0, &mem_o_0);\n\n";

[0076] return code_stream_.str();

[0077] Among them, 'static std::map<std::string, std::string> TopsOpMap = {{"ADD", "topsAdd"},...};' represents the mapping relationship between the front-end operator and the operator call template.

[0078] 'static TopsOp CreateOpByName(std::string funcName) { if (funcName == "topsAdd") { return TopsOp(funcName, 2, 1, {"TENSORND", "TENSORND"}, {"TENSORND"});} else if (...) else { std::cout << "CreateOpByName#Unrecognized op: " << funcName << std::endl; throw "#Unrecognized op!";}}' represents the basic information of the operator, indicating that the topsAdd operator has 2 input tensors, 1 output tensor, and the types of the input and output tensors are both "TENSORND".

[0079] 'static std::string PrintTopsOp(const std::string& opName) { std::string s; if (opName == "topsAdd") { s = PrintTopsBinaryOp("TOPS_BINARY_OP_ADD");} else if (...) else { std::cout << "createOpByName#Unrecognized op: " << opName << std::endl; throw "#Unrecognized op!";} return s;}' and'static std::string PrintTopsBinaryOp(const std::string& mode) { std::ostringstream code_stream_; code_stream_ << "topsBinaryOp(deviceCtx, " << mode << ", desc_i_0, mem_i_0, desc_i_1, mem_i_1, desc_o_0, &mem_o_0);\n\n"; return code_stream_.str();' represent the declaration of the description object and the operation statement for the corresponding backend operator operation.

[0080] In this disclosure, a static key-value pair (key-value) set map object can be used to maintain the mapping relationship between the front-end operator and the operator call template. The key of the map object is the operator name defined in the front-end computation graph, and the value is the custom operator call template name.

[0081] For each front-end operator, the server can obtain the target key-value pair with the name of the front-end operator as the key, and then determine the operator call template corresponding to the value in the target key-value pair, and generate a declaration statement and a call statement. The declaration statement of the operator call template can be expressed as: "void topsAdd(float* input0, float* input1, float* res)" to indicate the front-end operator corresponding to the operator call template and call the backend operator. The generated call statement for the template function can be expressed as: "topsAdd(x0, x1, buf_0);" to call the template function of the operator call template.

[0082] It should be noted that the mapping relationship between front-end operators and back-end operators is not one-to-one. Multiple different front-end operators may correspond to the operator call template of the same back-end operator, and the operator call template patterns of the corresponding back-end operators may be the same or different. To facilitate understanding, this disclosure provides a schematic diagram of the mapping relationship between front-end operators and operator call targets, as shown in Figure 2.

[0083] FIG2 is a schematic diagram of a mapping relationship between a front-end operator and an operator call target provided in the present disclosure.

[0084] Among them, front-end operators 1 to 4 can be: ADD, SUB, nn.dense, nn.batch_matmul, respectively. Operator call templates 1 to 3 can be: topsADD, topsSub, topsDot, respectively. ADD and SUB correspond to two modes respectively. Back-end operator A can be topsBinaryOp(mode), and back-end operator B can be topsDot.

[0085] S105: Generate a calling code for a backend operator according to the code header, the declaration statement, the calling statement, and the configuration information corresponding to the operator.

[0086] S106: calling the backend operator of the backend hardware platform according to the calling code of the backend operator, so as to execute the computing task through the backend operator.

[0087] The server can call the template function of the operator call template based on the declaration statement and call statement, and then generate the complete backend operator call code based on the template function, code header, and configuration information. This includes the operator calling the template function code, parsing the parameters passed in by the frontend, calling the template function, and finally storing the calculation results in the specified memory location.

[0088] In the present disclosure, the name of the backend operator call template can be "topsAdd"; the tensor description type corresponding to the input and output tensors of the backend operator can be "TENSORND"; the operation statement of the operation corresponding to the backend operator can be "topsBinaryOp(deviceCtx, TOPS_BINARY_OP_ADD, desc_i_0, mem_i_0, desc_i_1, mem_i_1, desc_o_0, &mem_o_0);".

[0089] Furthermore, the template function corresponding to the operator call template includes module code for each functional module. These module codes may include: device management module code, memory allocation module code, tensor declaration module code, data handling module code, operation module code, and memory release module code, corresponding to the six functional modules in the backend operator call process. Of course, module code corresponding to other functional modules may also be included, and this disclosure does not specifically limit this.

[0090] For ease of understanding, the present disclosure provides a structural diagram of an operator call template, as shown in FIG3 .

[0091] FIG3 is a schematic diagram of the structure of an operator call template provided in the present disclosure.

[0092] Among them, the device management module is used to manage the current background device (AI accelerator), the memory declaration module is used to indicate the memory information occupied by calling the back-end operator, the tensor declaration module is used to indicate the tensor information of each tensor, the data handling module is used to transfer data in the server memory (main memory) to the acceleration chip memory and transfer data in the acceleration chip memory to the server memory, the operation module is used to execute the operation logic corresponding to the current operator, and the memory release module is used to release the memory after completing the operation.

[0093] The server can generate the calling code for each backend operator based on the topological relationship between each front-end operator. During the training of the deep model through the deep learning framework, the corresponding backend operator can be called based on each operator calling code, thereby executing the computing tasks for the deep learning model.

[0094] As can be seen from the above method, this solution can parse the computational graph, obtain computational nodes, and map them to operators on a specific backend hardware platform through code written in C++. It automatically generates operator call code and outputs C++ source files. This disclosure abstracts the operator call code template, extracting six modules: device management, memory application, tensor declaration, data handling, operation, and memory release. Among them, common code is written for the five modules of device management, memory application, data handling, and memory release. The tensor declaration and operation modules that are different for each operator are implemented as configured reading, which simplifies the tedious writing of operator call code templates and improves development efficiency.

[0095] When adding a new operator, there's no need to write a new operator call code template. By adding a set of new operator configuration information, the corresponding operator call code template can be automatically generated. Furthermore, by calling this source file, the computational nodes in the computational graph can be assigned to a specific hardware platform for computation and then the computation results can be obtained. This feature allows specific AI accelerator chips to be integrated into the Tensor Virtual Machine (TVM), enabling the computational graph to be distributed to specific AI accelerator chips in the TVM for computation.

[0096] The above are one or more methods for automatically generating operator call codes according to the present disclosure. Based on the same idea, the present disclosure also provides a corresponding device for automatically generating operator call codes, as shown in FIG4 .

[0097] FIG4 is a schematic diagram of an automatic operator call code generation device provided by the present disclosure, comprising:

[0098] Acquisition module 401 is used to obtain basic information of the operator library corresponding to the backend hardware platform and the calculation graph of the target deep learning algorithm;

[0099] A first generating module 402 is configured to generate a code header of an operator calling code according to the basic information of the operator library, wherein the code header is used to introduce the operator library and dependent libraries of the hardware platform;

[0100] The parsing module 403 is used to parse the computation graph and determine each front-end operator in the computation graph;

[0101] Determination module 404 is used to determine, for each front-end operator, the declaration statement of the operator call template and the calling statement of the template function corresponding to the operator according to the mapping relationship between the front-end operator and the operator call template;

[0102] A second generation module 405 is configured to generate a call code for a backend operator based on the code header, the declaration statement, the call statement, and the configuration information corresponding to the operator;

[0103] The calling module 406 is configured to call the backend operator of the backend hardware platform according to the calling code of the backend operator, so as to execute the computing task through the backend operator.

[0104] Optionally, the basic information of the operator library includes: the path and name of the header file of the backend hardware platform operator library;

[0105] The first generation module 402 is used to generate the import information of the dependent library and the import information of the operator library according to the path and name of the header file of the operator library; and generate the code header according to the import information of the dependent library and the import information of the operator library.

[0106] Optionally, for each front-end operator, before determining the declaration statement of the operator call template corresponding to the operator and the calling statement of the template function based on the mapping relationship between the front-end operator and the operator call template, the determination module 404 is also used to determine the mapping relationship between the front-end operator and the operator call template based on the configuration information corresponding to the front-end operator.

[0107] Optionally, the determination module 404 is used to obtain a target key-value pair with the name of the front-end operator as the key; determine the operator call template corresponding to the value in the target key-value pair, and generate the declaration statement and the call statement, wherein, for each operator call template, the operator call template corresponds to at least one front-end operator.

[0108] Optionally, the configuration information includes: the name of the operator call template, the number of input tensors, the number of output tensors, and the description object declaration of the backend operator corresponding to the operation, the operation declaration of the operation, and the memory release statement of the description object.

[0109] Optionally, the second generating module 405 is configured to call the complete function body of the template function corresponding to the operator call template according to the declaration statement and the call statement;

[0110] Generate the calling code of the backend operator according to the template function, the code header and the configuration information.

[0111] Optionally, the template function corresponding to the operator call template contains module codes of various functional modules, and the module codes include: device management module code, memory application module code, tensor declaration module code, data handling module code, operation module code and memory release module code.

[0112] The present disclosure also provides a computer-readable storage medium storing a computer program, which can be used to execute the method for automatically generating an operator call code provided in FIG. 1 .

[0113] The present disclosure also provides a schematic structural diagram of an electronic device corresponding to Figure 1 as shown in Figure 5. As shown in Figure 5, at the hardware level, the electronic device includes a processor, an internal bus, a network interface, a memory and a non-volatile memory, and of course may also include hardware required for other services. The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it to implement the method for automatic generation of operator call code described in Figure 1 above. Of course, in addition to software implementation, the present disclosure does not exclude other implementation methods, such as logic devices or a combination of software and hardware, etc., that is to say, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.

[0114] Improvements to a technology can be clearly distinguished as either hardware improvements (for example, improvements to circuit structures such as diodes, transistors, and switches) or software improvements (improvements to process flows). However, with technological advancements, many process flow improvements can now be considered direct improvements to hardware circuit structures. Designers almost always create the corresponding hardware circuit structure by programming the improved process flow into the hardware circuit. Therefore, it cannot be said that a process flow improvement cannot be implemented using a hardware module. For example, a programmable logic device (PLD), such as a field programmable gate array (FPGA), is an integrated circuit whose logical function is determined by user programming. Designers can "integrate" a digital system onto a PLD by programming it themselves, without having to hire a chip manufacturer to design and manufacture a dedicated integrated circuit chip. Moreover, nowadays, instead of manually fabricating integrated circuit chips, this programming is mostly performed using "logic compiler" software. This is similar to the software compilers used during program development. Before compilation, the original code must be written in a specific programming language, called a hardware description language (HDL). There are many different HDLs, including ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, and RHDL (Ruby Hardware Description Language). Currently, the most commonly used are VHDL (Very-High-Speed ​​Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art will also appreciate that by simply programming the method flow in one of these hardware description languages ​​and then programming it into an integrated circuit, a hardware circuit that implements the logic method flow can be easily obtained.

[0115] The controller can be implemented in any suitable manner. For example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also know that in addition to implementing the controller in a purely computer-readable program code format, the controller can be implemented in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers by logically programming the method steps. Therefore, such a controller can be considered a hardware component, and the devices included therein for implementing various functions can also be considered as structures within the hardware component. Or even, the devices for implementing various functions can be considered as both software modules that implement the method and structures within the hardware component.

[0116] The systems, devices, modules, or units described in the above embodiments may be implemented by computer chips or entities, or by products having certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.

[0117] For the convenience of description, the above devices are described as being divided into various units according to their functions. Of course, when implementing the present disclosure, the functions of each unit can be implemented in the same or multiple software and / or hardware.

[0118] Those skilled in the art will appreciate that the embodiments of the present disclosure may be provided as methods, systems, or computer program products. Therefore, the present disclosure may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present disclosure may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0119] The present disclosure is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present disclosure. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device produce a device for implementing the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.

[0120] These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a product including an instruction device that implements the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.

[0121] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.

[0122] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.

[0123] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.

[0124] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media (transitory media), such as modulated data signals and carrier waves.

[0125] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a list of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a..." does not preclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.

[0126] Those skilled in the art will appreciate that embodiments of the present disclosure may be provided as methods, systems, or computer program products. Thus, the present disclosure may take the form of a fully hardware embodiment, a fully software embodiment, or an embodiment combining software and hardware. Furthermore, the present disclosure may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0127] The present disclosure may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, and the like that perform specific tasks or implement specific abstract data types. The present disclosure may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communications network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.

[0128] The various embodiments of this disclosure are described in a progressive manner. Similar portions between the various embodiments can be referenced to each other. Each embodiment focuses on the differences between the other embodiments. In particular, the system embodiments are generally similar to the method embodiments, so their description is relatively simple. For relevant portions, refer to the description of the method embodiments.< / memory> < / iostream>

Claims

1. A method for automatically generating operator call code, characterized in that: The method is applied to a deep learning framework, including: Obtain basic information about the operator library corresponding to the backend hardware platform and the computational graph of the target deep learning algorithm; Generate a code header of the operator calling code according to the basic information of the operator library, wherein the code header is used to introduce the operator library and dependent library of the hardware platform; Parsing the computation graph to determine each front-end operator in the computation graph; For each front-end operator, determine the declaration statement of the operator call template and the calling statement of the template function corresponding to the operator according to the mapping relationship between the front-end operator and the operator call template; Generate a calling code for a backend operator according to the code header, the declaration statement, the calling statement, and configuration information corresponding to the operator; The backend operator of the backend hardware platform is called according to the calling code of the backend operator to execute the computing task through the backend operator.

2. The method according to claim 1, characterized in that The basic information of the operator library includes: the path and name of the header file of the backend hardware platform operator library; Generate a code header of the operator call code according to the basic information of the operator library, including: Generate the import information of the dependent library and the import information of the operator library according to the path and name of the header file of the operator library; The code header is generated according to the import information of the dependent library and the import information of the operator library.

3. The method according to claim 1, characterized in that For each front-end operator, before determining the declaration statement of the operator call template and the calling statement of the template function corresponding to the operator according to the mapping relationship between the front-end operator and the operator call template, the method further includes: According to the configuration information corresponding to the front-end operator, a mapping relationship between the front-end operator and the operator calling template is determined.

4. The method according to claim 1, characterized in that For each front-end operator, according to the mapping relationship between the front-end operator and the operator call template, determine the declaration statement of the operator call template corresponding to the operator and the call statement of the template function, including: Get the target key-value pair with the name of the front-end operator as the key; An operator call template corresponding to the value in the target key-value pair is determined, and the declaration statement and the call statement are generated, wherein for each operator call template, the operator call template corresponds to at least one front-end operator.

5. The method according to claim 1, characterized in that The configuration information includes: the name of the operator call template, the number of input tensors, the number of output tensors, and the description object declaration of the corresponding operation of the backend operator, the operation declaration of the operation, and the memory release statement of the description object.

6. The method according to claim 1, characterized in that Generate a complete backend operator calling code according to the code header, the declaration statement, the calling statement, and the configuration information corresponding to the operator, including: Calling the complete function body of the template function corresponding to the operator calling template according to the declaration statement and the call statement; Generate a calling code for the backend operator according to the template function, the code header, and the configuration information.

7. The method according to claim 1, characterized in that The template function corresponding to the operator call template contains module codes of various functional modules, and the module codes include: device management module code, memory application module code, tensor declaration module code, data handling module code, operation module code and memory release module code.

8. An operator call code automatic generation device, characterized in that: include: Get the module to obtain the basic information of the operator library corresponding to the backend hardware platform and the calculation graph of the target deep learning algorithm; A first generation module generates a code header of an operator call code according to the basic information of the operator library, wherein the code header is used to introduce the operator library and dependent library of the hardware platform; A parsing module, which parses the computation graph and determines each front-end operator in the computation graph; A determination module determines, for each front-end operator, a declaration statement of the operator call template corresponding to the operator and a call statement of the template function according to a mapping relationship between the front-end operator and the operator call template; A second generation module generates a call code for a backend operator according to the code header, the declaration statement, the call statement, and configuration information corresponding to the operator; A calling module calls the backend operator of the backend hardware platform according to the calling code of the backend operator, so as to execute the computing task through the backend operator.

9. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Special back-end code generation method and device supporting machine learning training

    CN113885871A

  • Generation method and device of operator, equipment and storage medium

    CN114911465A

  • Interface file generation method and device of operator, equipment and storage medium

    CN116185416A

  • Method and device for automatically generating operator calling code, medium and equipment

    CN116932092A

  • Detecting malicious activities by imported software packages

    US10019572B1

Cited By

  • Model code generation method and system based on computational graph

    CN120255872A