Operator registration system and method for adding operator in compiler
By introducing the operator registration system into the TVM compiler, the operator registration process is simplified, target files are generated and compiled, and registration information is supported in external folders. This solves the problem of cumbersome operator registration steps in the compiler and achieves high efficiency and convenience. Operator registration and development efficiency are improved.
Patent Information
- Application Number
- CN202410703470.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-31
- Publication Date
- 2024-08-30
AI Technical Summary
The steps to add operators in the TVM compiler are cumbersome and require many files to be modified. Modifying the configuration parameters in the registration code requires recompiling, running, and debugging, resulting in high operator registration costs and low efficiency.
Provides an operator registration system, including a creation module, a compilation module and a calling module. Through the creation module, the configuration parameters of the target operator are input, the target file is generated and compiled into a library file, the operator registration process is simplified, and the operator is added in the compiler. Call the interface to call library files, support searching for registration information from external folders, reduce registration costs and improve development efficiency.
The operator registration process is simplified, the efficiency of adding operators is greatly improved, the operator registration cost is reduced, efficient and convenient operator registration is achieved, and the scalability and development efficiency of the TVM compiler operator library are improved.
Smart Images

Figure CN118569361A
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the technical field of deep learning compilers, and in particular to an operator registration system, a method for adding an operator in a compiler, an electronic device, and a computer-readable storage medium. Background Art
[0002] Deep learning compilers generally adopt a layered design, which mainly includes the compiler front end, IR (Intermediate Representation) and compiler back end. Figure 1 , shows the structural diagram of the deep learning compiler, which inputs neural network models of different frameworks (such as Tensorflow, PyTorch, Caffe2, MXNet) into the deep learning compiler and converts them into multi-level IR. The high-order IR is located at the front end and optimized for the high-order IR; the low-order IR is located at the back end and optimized, code generated, and compiled for specific hardware (such as GPGPU, CPU, etc.) through executable modules. Due to the continuous update of neural network models, more and more new operators are proposed. At this time, it is necessary to expand the operator library of the deep learning compiler, otherwise it is likely that errors will occur in generating IR and the neural network model will not be compatible. Summary of the invention
[0003] The embodiment of the present invention provides an operator registration system, a method for adding an operator in a TVM compiler, an electronic device, and a computer-readable storage medium to solve the problem in the prior art that the steps for adding an operator in a TVM compiler are cumbersome, many files are modified, and the configuration parameters in the registration code need to be recompiled, run, and debugged after modification, which leads to high operator registration costs and low efficiency.
[0004] The embodiment of the present invention discloses an operator registration system, which is applied in a compiler and includes: a creation module, a compilation module and a calling module;
[0005] The creation module is used to input configuration parameters of the target operator and create a target file corresponding to the target operator according to the configuration parameters;
[0006] The compiling module is used to compile the target file to obtain a library file corresponding to the target operator;
[0007] The calling module is used to add a calling interface in the compiler, and the calling interface is used to call the library file.
[0008] Optionally, the configuration parameters include an operator name, attribute information, operator input information, and operator output information. The creation module is used to input the configuration parameters of the target operator and create a target file corresponding to the target operator according to the configuration parameters, including:
[0009] The creation module is used to input the configuration parameters, and create a target file with the name of the operator according to the configuration parameters; the target file includes a target structure, and the target structure is used to store the configuration parameters;
[0010] The creation module is used to declare the properties of the target operator in the target file according to the property information, and to set the description and default value of the properties of the target operator;
[0011] The creation module is used to determine the number of the target operator input and output in the target file according to the operator input information and the operator output information, and define the size relationship between the target operator input and output;
[0012] The creation module is used to register the target operator in the target file according to the configuration parameters, obtain registration information of the target operator, and store the registration information in the target file.
[0013] Optionally, it also includes: a display module;
[0014] The display module is used to display the target code or the configuration parameters in the target file; the target code is generated according to the configuration parameters;
[0015] The display module is used to modify the target file to obtain a modified target file.
[0016] Optionally, a compilation file is pre-installed in the compilation module, and the compilation module is used to compile the target file to obtain a library file corresponding to the target operator, including:
[0017] The compilation module is used to compile the target code through the compilation file, obtain the library file corresponding to the target operator, and store it in the target folder; wherein the compilation file is used to define the information required for compiling the target code.
[0018] Optionally, it also includes: a testing module;
[0019] The test module is used to input test data and select test operators, test the test operators, and obtain test results;
[0020] The test module is used to determine whether the test result is consistent with the expected result; if the test result is inconsistent with the expected result, it is considered that the adding process of the test operator is unsuccessful; if the test result is consistent with the expected result, the model corresponding to the test operator is input into the compiler; wherein the test operator includes the target operator and the initial operator in the registration file of the compiler.
[0021] Optionally, the test module is used to input test data and select a test operator, test the test operator, and obtain a test result, including:
[0022] The test module is used to search the library file or the registration file according to the operator name of the test operator and call the calculation method corresponding to the test operator;
[0023] The test module is used to automatically generate a test code template according to the test data and the calculation method corresponding to the test operator, so as to test the test operator and obtain a test result.
[0024] Optionally, the test module is used to search in the library file or the registration file according to the operator name of the test operator and call the calculation method corresponding to the test operator, including:
[0025] The test module is used to search for the test operator in the registration file according to the operator name of the test operator. If the test operator is not found in the registration file, the test module is used to search for the test operator in the library file according to the operator name of the test operator. If the test operator is not found in the library file, the test operator is added through the operator adding platform. If the test operator is found in the library file or the registration file according to the operator name of the test operator, the calculation method corresponding to the test operator is called.
[0026] The embodiment of the present invention further discloses a method for adding an operator in a compiler, the method comprising:
[0027] Input the configuration parameters of the target operator in the operator registration system, and create a target file corresponding to the target operator according to the configuration parameters;
[0028] Compile the target file to obtain a library file corresponding to the target operator;
[0029] A calling interface is added in the compiler, where the calling interface is used to call the library file.
[0030] The embodiment of the present invention further discloses an electronic device, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;
[0031] The memory is used to store computer programs;
[0032] The processor is used to implement the method described in the embodiment of the present invention when executing the program stored in the memory.
[0033] The embodiment of the present invention further discloses a computer program product, which is stored in a storage medium and is executed by at least one processor to implement the system as described in the embodiment of the present invention.
[0034] The embodiment of the present invention further discloses a computer-readable storage medium having instructions stored thereon, which, when executed by one or more processors, enables the processors to execute the system as described in the embodiment of the present invention.
[0035] The embodiments of the present invention include the following advantages:
[0036] An operator registration system provided by an embodiment of the present invention allows a user to automatically create a class of the operator and a file containing the operator class by creating operator configuration information and parameter information input by a module, and compile the file containing the operator class into a library file. This does not require the user to define the parameter information and configuration information of the operator in multiple files in the compiler, but rather puts the configuration parameters of the operator into the operator class by creating module input, thereby simplifying the operator registration process and greatly improving the efficiency of adding operators. On the other hand, the location of the REGISTER information is obtained in the TVM compiler, and a method for calling an external target folder is added. In this way, when the TVM compiler searches for a registered operator, it can search from the REGISTER information or from an external library file. This is an expansion of the TVM compiler operator library, which realizes efficient and convenient operator registration, reduces the operator registration cost, and improves the operator development efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Figure 1 This is a schematic diagram of the structure of the deep learning compiler;
[0038] Figure 2 is a schematic diagram of an application environment provided in an embodiment of the present invention;
[0039] Figure 3 is a structural block diagram of an operator registration system provided in an embodiment of the present invention;
[0040] Figure 4is a flowchart of a method for adding an operator in a compiler provided in an embodiment of the present invention;
[0041] Figure 5 It is a schematic diagram of a process of adding a target operator in a compiler provided by an embodiment of the present invention;
[0042] Figure 6 is a schematic diagram of the hardware structure of an electronic device for implementing various embodiments of the present invention;
[0043] Figure 7 is a schematic diagram of a computer-readable medium provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0044] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0045] Reference Figure 2 , showing a schematic diagram of an application environment provided in an embodiment of the present invention, the compiler can call the operator registered in the operator registration system.
[0046] Reference Figure 3 , shows a structural block diagram of an operator registration system provided in an embodiment of the present invention, specifically including: a creation module, a compilation module and a calling module;
[0047] The creation module is used to input configuration parameters of the target operator and create a target file corresponding to the target operator according to the configuration parameters;
[0048] In an embodiment of the present invention, a creation module is divided into a front end and a back end. The front end of the creation module is a visual interface. The user can input the relevant configuration information and parameter information of the target operator into the corresponding position of the interface according to his own needs. The interface setting can use the Qt Designer tool. The configuration parameters of the target operator input by the user include the operator name, attribute name, type and default value of the target operator, the type and size of the input and output of the target operator and other information.
[0049] At the front end of the creation module, it is only used to provide users with input of various configuration parameters of the target operator. After reading the configuration parameters input by the user, the creation module first creates a target file named after the operator name of the target operator, and then calls the "code template" of the various configuration parameters of the target operator (the "code template" here is not a C++ template function), generates the code of each configuration parameter as the target code, and saves the target code to the target file.
[0050] Specifically, after the configuration parameters entered by the user enter the backend of the creation module, a target file named as the operator name of the target operator is created. The target file contains a structure such as struct op_nameAttrs. TVM_DECLARE_ATTRS is used to declare the attributes of the operator, and TVM_ATTR_FIELD is used to set the attribute description and default value. There is a function such as op_nameRel to check the number of inputs and outputs, and define the size relationship between the input and output. RELAY_REGISTER_OP is used to register the operator, which requires the number of inputs, input name, op_nameRel, and other information of the operator optimization. There is a Makeop_name method that returns a CallNode, and Op::Get can be used to obtain the registration information of the operator to the CallNode.
[0051] The CallNode here is part of the specific implementation process of operator registration. It is a data type in TVM. The operation of the backend operator of the compiler is a CallNode, which saves the configuration parameters created in the target file (such as the properties of the target operator) in the CallNode. In Relay, each data flow node is a CallNode. For example, in the expression %24=nn.bias_add(%23,meta[relay.Constant]
[18] / *ty=Tensor[(256),float32]* / ) / *ty=Tensor[(1,256,56,56),float32]* / , "%24" is a CallNode.
[0052] The compiling module is used to compile the target file to obtain a library file corresponding to the target operator;
[0053] After the user clicks the "Submit" button in the display module, the generated target file is transferred to the compilation module, and then the target file is compiled by the compilation module to obtain the library file corresponding to the target operator.
[0054] In the embodiment of the present invention, the Makefile used for compilation is written inside the compilation module, and no user submission is required. Here, no user submission is required, which can be specifically understood as: the Makefile file is built into the compilation module, and the Makefile file is an important file required for C++ code compilation. Which libraries are required for the generated code to compile, and which environment information are defined in the Makefile. The Makefile here is written and does not need to be provided by the user.
[0055] The calling module is used to add a calling interface in the compiler, and the calling interface is used to call the library file.
[0056] In the prior art, when the compiler is working, it will search in the operators of the register to see whether the operators used by the input neural network model can be found in the registered operators. In the embodiment of the present invention, after the aforementioned steps, the target operator can be registered. The library file obtained after the registration is completed is stored in the external target folder. In order to enable the compiler to search the external target folder, it is necessary to add a call to the target folder in the compiler so that the compiler will not only search in the internal registered operators, but also in the external target folder.
[0057] An operator registration system provided by an embodiment of the present invention allows a user to automatically create a class of the operator and a file containing the operator class by creating operator configuration information and parameter information input by a module, and compile the file containing the operator class into a library file. This does not require the user to define the parameter information and configuration information of the operator in multiple files in the compiler, but rather puts the configuration parameters of the operator into the operator class by creating module input, thereby simplifying the operator registration process and greatly improving the efficiency of adding operators. On the other hand, the location of the REGISTER information is obtained in the TVM compiler, and a method for calling an external target folder is added. In this way, when the TVM compiler searches for a registered operator, it can search from the REGISTER information or from an external library file. This is an expansion of the TVM compiler operator library, which realizes efficient and convenient operator registration, reduces the operator registration cost, and improves the operator development efficiency.
[0058] In one embodiment of the present invention, the configuration parameters include an operator name, attribute information, operator input information, and operator output information. The creation module is used to input the configuration parameters of the target operator and create a target file corresponding to the target operator according to the configuration parameters, including:
[0059] The creation module is used to input the configuration parameters, and create a target file with the name of the operator according to the configuration parameters; the target file includes a target structure, and the target structure is used to store the configuration parameters;
[0060] The creation module is used to declare the properties of the target operator in the target file according to the property information, and to set the description and default value of the properties of the target operator;
[0061] The creation module is used to determine the number of the target operator input and output in the target file according to the operator input information and the operator output information, and define the size relationship between the target operator input and output;
[0062] The creation module is used to register the target operator in the target file according to the configuration parameters, obtain registration information of the target operator, and store the registration information in the target file.
[0063] In an embodiment of the present invention, a creation module is divided into a front end and a back end. The front end of the creation module is a visual interface. The user can input the relevant configuration information and parameter information of the target operator into the corresponding position of the interface according to his own needs. The interface setting can use the Qt Designer tool. The configuration parameters of the target operator input by the user include the operator name, attribute name, type and default value of the target operator, the type and size of the input and output of the target operator and other information.
[0064] At the front end of the creation module, it is only used to provide users with input of various configuration parameters of the target operator. After reading the configuration parameters input by the user, the creation module first creates a target file named after the operator name of the target operator, and then calls the "code template" of the various configuration parameters of the target operator (the "code template" here is not a C++ template function), generates the code of each configuration parameter as the target code, and saves the target code to the target file.
[0065] Here, the target code for registering the target operator is generated according to the various configuration parameters input by the user, and the existing code registration method is adopted. The difference is that in the existing registration method, the registration information of the target operator is distributed in multiple files, while in the embodiment of the present invention, the registration code of the target operator is placed in a target file, and the library file corresponding to the target operator is subsequently compiled and stored in an external target folder, so that the subsequent compiler can directly call the target operator that has been registered in the target folder, thereby reducing the registration cost of the target operator and expanding the operator library of the compiler.
[0066] Specifically, after the configuration parameters input by the user enter the backend of the creation module, a target file named as the operator name of the target operator is created.
[0067] This target file contains a key structure struct op_nameAttrs, which is designed to store various configuration parameters entered by the user to ensure that they can be correctly accessed and used during the execution of the target operator;
[0068] To declare the attributes of the target operator, the macro TVM_DECLARE_ATTRS is used. This macro defines the attribute set of the target operator. The description and default value of the attribute can be set through the TVM_ATTR_FIELD macro. This not only helps the readability of the code, but also ensures that the target operator can run with the default configuration without user-defined parameters.
[0069] The target file also contains a function called op_nameRel, which is used to check the number of inputs and outputs of the target operator and define the size relationship between the inputs and outputs. This function is key to ensuring the correct execution of the target operator because it verifies whether the inputs and outputs of the target operator meet the expected format and quantity.
[0070] In order to register the target operator with TVM's Relay, the RELAY_REGISTER_OP macro is used. This macro requires the operator's input number, input name, op_nameRel function, and other information of the operator optimization. Through this registration process, the target operator is integrated into TVM's Relay runtime, so that the target operator can be called and executed by other components.
[0071] In addition, a method named Makeop_name is defined in the target file. This method returns a CallNode object. CallNode is a data structure that represents a function call. When the target operator is called, the registration information of the target operator can be obtained through the Op::Get method and applied to CallNode. This process ensures that the call of the target operator is based on its registered properties and configuration, thereby ensuring the correctness and efficiency of the execution of the target operator.
[0072] In one embodiment of the present invention, the system further comprises: a display module;
[0073] The display module is used to display the target code or the configuration parameters in the target file; the target code is generated according to the configuration parameters;
[0074] The display module is used to modify the target file to obtain a modified target file.
[0075] In the embodiment of the present invention, after the target file of the target operator is created by the creation module, the generated target code can be displayed by the display module for the user to check and customize, and the operator name, attribute name, type and default value of the target operator, the type and size of the input and output of the target operator and other information can also be displayed. The target code specifically includes the operator name, attribute name, type and default value of the target operator, the type and size of the input and output of the target operator, and other information. This information is the basic information of the target operator registration, that is, the configuration parameters entered by the user through the creation module.
[0076] The display module is the same as the front end of the creation module, and is also a visualization interface. Although both are visualization interfaces, in the embodiment of the present invention, it is not considered to merge the two interfaces together. Instead, the interface of the creation module and the interface of the display module are different, and the functional implementation between the two modules is relatively independent. That is, the registration information of the target operator (various configuration parameters entered by the user) is created and saved in the target file, which is not related to the creation module. Subsequent operations such as addition, deletion, and modification are all for the target file, which makes the functional implementation more convenient.
[0077] In the embodiment of the present invention, the user can also modify the displayed target code or configuration parameters through the display module.
[0078] In the existing solution, the original operator registration is to hard-code the operator parameters in the corresponding file. When modifying, you need to find the corresponding file and modify the specific location. Then the modification in TVM involves many files, involving the modification of C++ code. Even a small modification requires recompilation. For example, the structure of the operator attribute is defined in the include / tvm / relay / attrs / transform.h file, and the type relationship and registration of the operator are defined in the src / relay / op / tensor / transform.cc file. Because the definition content is relatively large, the definition is relatively cumbersome. The scheduling of the operator is defined in the python / tvm / relay / op / _transform.py file. In addition, an interface for calling the operator is defined on the python side, which can be defined in python / tvm / relay / op / transform.py;
[0079] The modification method provided by the embodiment of the present invention is to modify the configuration information of the target operator in the display module, and automatically compile it after the user confirms it, without the need for manual compilation by the user, thus saving the developer's time. In addition, the user can also ensure the consistency of the parameter before and after modification through the interface. For example, if the value of the scale parameter is modified, the location where this value is used in other files must also be modified accordingly, and the problem of forgetting to modify and being inconsistent may occur.
[0080] By using the modification method provided in the embodiment of the present invention, the registration cost of the target operator can be reduced from the aspect of operator modification, and the development efficiency can be improved.
[0081] In the display module, after the user confirms that the configuration parameters of the displayed target operator are correct, click the "Submit" button in the display module to transfer the generated target file to the compilation module so that the target file can be processed in the compilation module later.
[0082] In one embodiment of the present invention, the compiling module has a compiling file pre-installed therein, and the compiling module is used to compile the target file to obtain a library file corresponding to the target operator, including:
[0083] The compilation module is used to compile the target code through the compilation file, obtain the library file corresponding to the target operator, and store it in the target folder; wherein the compilation file is used to define the information required for compiling the target code.
[0084] In the embodiment of the present invention, by integrating the Makefile used for compilation into the compilation module in advance, the user does not need to manually submit the Makefile file every time the compilation is performed, which greatly simplifies the user's operation process. The Makefile file is an important file required for C++ code compilation, which contains all necessary compilation instructions and dependencies, defines the library and environment information required in the compilation process, and ensures that the target code can be smoothly converted from the source code to an executable program (library file).
[0085] In addition, this built-in Makefile design can also improve the consistency and repeatability of compilation. Since the Makefile file is fixed, all users will get the same results when compiling the same code, which helps ensure the stability and reliability of the software. At the same time, this also reduces compilation problems caused by differences in user environments, making the compilation process smoother.
[0086] In one embodiment of the present invention, the system further comprises a testing module;
[0087] The test module is used to input test data and select test operators, test the test operators, and obtain test results;
[0088] The test module is used to determine whether the test result is consistent with the expected result; if the test result is inconsistent with the expected result, it is considered that the adding process of the test operator is unsuccessful; if the test result is consistent with the expected result, the model corresponding to the test operator is input into the compiler; wherein the test operator includes the target operator and the initial operator in the registration file of the compiler.
[0089] In the embodiment of the present invention, the defined operator needs to be unit tested to verify the correctness and stability of the operator, usually checking the correctness of the size and type of the operator output, and this part of the function is implemented by the test module. The test module mainly tests the target operator added in the above process.
[0090] In the test module, the user can set specific input parameters (i.e., test data) by himself, select the name of the operator to be called (i.e., the added operator, which can also be understood as any test operator), and call the template of the automatically generated unit test code in the test module according to the input parameters set by the user. The operator is tested through the template of the unit test code to obtain the test result. In the above definition of the operator, there is a certain expectation for the output of the operator. For example, the add operator hopes to obtain a tensor of the same size and type as the input. At this time, the tensor is defined as the expected result, and the implementation of the operator in the framework such as pytorch / tensorflow can also be compared as the expected result. Through the test module in the embodiment of the present invention, the operator can be tested quickly and conveniently, which greatly shortens the user's testing time.
[0091] If after the test module runs, the output in the test results is not the correct size or type, then something went wrong with the addition process.
[0092] Specifically, the input parameters (i.e., test data) set by the user are the input and parameters of the operator. The input of the operator refers to, for example, binary addition, there are two inputs and one output, what type and size the two inputs are respectively. The type of the operator input and output refers to, for example, if only int type addition is defined, then when the input is float type, it cannot be calculated. If the two inputs are int type, then the output is also int type for addition (although it is obvious, this item must also be defined in the specific implementation). The parameters refer to other attribute values of the operator, which are defined in the aforementioned creation module. For example, for the sum operation of the matrix, an axis parameter can be set to indicate along which dimension to sum.
[0093] While automatically generating the template for the unit test code, the test case will also be automatically generated. In the test module, this part of the code will be displayed to the user, and the user will be provided with the function of custom modification, which greatly shortens the user's testing time.
[0094] Furthermore, the template of the automatically generated unit test code can be saved in a corresponding file or cache area. When performing operator testing, the input parameters corresponding to multiple operators can be set through the test module to further shorten the user's testing time for the operator.
[0095] In one embodiment of the present invention, the test module is used to input test data and select a test operator, test the test operator, and obtain a test result, including:
[0096] The test module is used to search the library file or the registration file according to the operator name of the test operator and call the calculation method corresponding to the test operator;
[0097] The test module is used to automatically generate a test code template according to the test data and the calculation method corresponding to the test operator, so as to test the test operator and obtain a test result.
[0098] In the register-related files of TVM, dlopen is used to open the library file, and dlsym calls the Makeop_name method in the library file. In this way, if the operator is not found in the internal operator library of TVM, it is searched in the external library file. In the embodiment of the present invention, the compiler not only searches for the internal registered operators, but also searches for the external target folder.
[0099] Operator search is performed in the internally registered operators or in the external target folder. The specific implementation is achieved through if-else branches. If (can be found in the operators registered by TVM): the method of the operator is called; elif (can be found in the external library file): the method of the operator in the library file is called; else: this operator is not defined;
[0100] Operators registered by TVM refer to the operators registered in the registration file inside TVM. The registered operators are placed in a map, which is a mapping between operator names and corresponding implementation methods.
[0101] If this operator is not defined, you can add the operator again by following the above steps.
[0102] In one embodiment of the present invention, the test module is used to search according to the operator name of the test operator in the library file or the registration file, and call the calculation method corresponding to the test operator, including:
[0103] The test module is used to search for the test operator in the registration file according to the operator name of the test operator. If the test operator is not found in the registration file, the test module is used to search for the test operator in the library file according to the operator name of the test operator. If the test operator is not found in the library file, the test operator is added through the operator adding platform. If the test operator is found in the library file or the registration file according to the operator name of the test operator, the calculation method corresponding to the test operator is called.
[0104] In the embodiment of the present invention, the if-else branch is used to search for an operator in a registration file or a target folder. If (it can be found in the operator registered in TVM): the method of the operator is called; elif (it can be found in an external library file): the method of the operator in the library file is called; else: the operator is not defined;
[0105] In an embodiment of the present invention, a user can automatically create a class of the operator and a file containing the operator class by creating the operator configuration information and parameter information input by the module, and display the file to the user in the display interface. After the user selects and confirms, the file containing the operator class is compiled into a library file. In this way, the user does not need to define the parameter information and configuration information of the operator in multiple files in the compiler. Instead, the configuration parameters of the operator are put into the operator class by creating the module input, which simplifies the process of operator registration and greatly improves the efficiency of adding operators. On the other hand, the location of the REGISTER information is obtained in the compiler, and a method for calling an external target folder is added. In this way, when the compiler searches for a registered operator, it can search from the REGISTER information or in an external library file. This is an expansion of the compiler operator library, which realizes efficient and convenient operator registration, reduces the operator registration cost, and improves the operator development efficiency.
[0106] Reference Figure 4 , shows a flowchart of a method for adding an operator in a compiler provided in an embodiment of the present invention, which may specifically include the following steps:
[0107] Step 401: input configuration parameters of a target operator into an operator registration system, and create a target file corresponding to the target operator according to the configuration parameters;
[0108] Step 402: compile the target file to obtain a library file corresponding to the target operator;
[0109] Step 403: Add a calling interface in the compiler, where the calling interface is used to call the library file.
[0110] In an embodiment of the present invention, a user can automatically create a class of the operator and a file containing the operator class by creating the operator configuration information and parameter information input by the module, and compile the file containing the operator class into a library file, so that the user does not need to define the parameter information and configuration information of the operator in multiple files in the compiler, but puts the configuration parameters of the operator into the operator class by creating the module input, which simplifies the process of operator registration and greatly improves the efficiency of adding operators. On the other hand, the location of the REGISTER information is obtained in the TVM compiler, and a method for calling an external target folder is added. In this way, when the TVM compiler searches for a registered operator, it can search from the REGISTER information or in an external library file. This is an expansion of the TVM compiler operator library, which realizes efficient and convenient operator registration, reduces the operator registration cost, and improves the operator development efficiency.
[0111] Reference Figure 5 , shows a schematic diagram of a process of adding a target operator in a TVM compiler provided by an embodiment of the present invention. Specifically, a user inputs configuration parameters of the target operator in the front end of a creation module, and then generates a library file corresponding to the defined target operator and stores it in a target folder through the back end of the creation module, the display module, and the compilation module in sequence, and adds an interface for calling the target folder in the compiler.
[0112] In addition, an embodiment of the present invention further provides an electronic device, including: a processor, a memory, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, the various processes of the embodiment of the above-mentioned operator registration system are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be described here.
[0113] The embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, each process of the embodiment of the operator registration system described above is implemented, and the same technical effect can be achieved. To avoid repetition, it is not repeated here. The computer-readable storage medium is, for example, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0114] An embodiment of the present invention further provides a computer program product, which is stored in a storage medium and is executed by at least one processor to implement the various processes of the embodiment of the operator registration system as described above, and can achieve the same technical effect. To avoid repetition, it will not be described here.
[0115] Figure 6A schematic diagram of the hardware structure of an electronic device for implementing various embodiments of the present invention.
[0116] The electronic device 600 includes but is not limited to: a radio frequency unit 601, a network module 602, an audio output unit 603, an input unit 604, a sensor 605, a display unit 606, a user input unit 607, an interface unit 608, a memory 609, a processor 610, and a power supply 611. Those skilled in the art will appreciate that Figure 6 The electronic device structure shown in the figure does not constitute a limitation on the electronic device, and the electronic device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. In the embodiments of the present invention, the electronic device includes but is not limited to a mobile phone, a tablet computer, a laptop computer, a PDA, a vehicle-mounted terminal, a wearable device, and a pedometer.
[0117] It should be understood that in the embodiment of the present invention, the radio frequency unit 601 can be used for receiving and sending signals during information transmission or communication. Specifically, after receiving downlink data from the base station, it is sent to the processor 610 for processing; in addition, uplink data is sent to the base station. Generally, the radio frequency unit 601 includes but is not limited to an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier, a duplexer, etc. In addition, the radio frequency unit 601 can also communicate with the network and other devices through a wireless communication system.
[0118] The electronic device provides users with wireless broadband Internet access through the network module 602, such as helping users to send and receive emails, browse web pages, and access streaming media.
[0119] The audio output unit 603 can convert the audio data received by the RF unit 601 or the network module 602 or stored in the memory 609 into an audio signal and output it as sound. Moreover, the audio output unit 603 can also provide audio output related to a specific function performed by the electronic device 600 (for example, a call signal reception sound, a message reception sound, etc.). The audio output unit 603 includes a speaker, a buzzer, a receiver, etc.
[0120] The input unit 604 is used to receive audio or video signals. The input unit 604 may include a graphics processor (GPU) 6041 and a microphone 6042, and the graphics processor 6041 processes the image data of a static picture or video obtained by an image capture device (such as a camera) in a video capture mode or an image capture mode. The processed image frame can be displayed on the display unit 606. The image frame processed by the graphics processor 6041 can be stored in the memory 609 (or other storage medium) or sent via the radio frequency unit 601 or the network module 602. The microphone 6042 can receive sound and can process such sound into audio data. The processed audio data can be converted into a format output that can be sent to a mobile communication base station via the radio frequency unit 601 in the case of a telephone call mode.
[0121] The electronic device 600 also includes at least one sensor 605, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor includes an ambient light sensor and a proximity sensor, wherein the ambient light sensor can adjust the brightness of the display panel 6061 according to the brightness of the ambient light, and the proximity sensor can turn off the display panel 6061 and / or the backlight when the electronic device 600 is moved to the ear. As a type of motion sensor, the accelerometer sensor can detect the magnitude of acceleration in each direction (generally three axes), and can detect the magnitude and direction of gravity when stationary, which can be used to identify the posture of the electronic device (such as horizontal and vertical screen switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer, tapping), etc.; the sensor 605 can also include a fingerprint sensor, a pressure sensor, an iris sensor, a molecular sensor, a gyroscope, a barometer, a hygrometer, a thermometer, an infrared sensor, etc., which will not be repeated here.
[0122] The display unit 606 is used to display information input by the user or information provided to the user. The display unit 606 may include a display panel 6061, which may be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), or the like.
[0123] The user input unit 607 can be used to receive input digital or character information, and to generate key signal input related to user settings and function control of the electronic device. Specifically, the user input unit 607 includes a touch panel 6071 and other input devices 6072. The touch panel 6071, also known as a touch screen, can collect the user's touch operation on or near it (such as the user's operation on the touch panel 6071 or near the touch panel 6071 using any suitable object or accessory such as a finger, stylus, etc.). The touch panel 6071 may include two parts: a touch detection device and a touch controller. Among them, the touch detection device detects the user's touch orientation, detects the signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts it into contact coordinates, and then sends it to the processor 610, receives the command sent by the processor 610 and executes it. In addition, the touch panel 6071 can be implemented in various types such as resistive, capacitive, infrared and surface acoustic waves. In addition to the touch panel 6071, the user input unit 607 may also include other input devices 6072. Specifically, other input devices 6072 may include but are not limited to a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, and a joystick, which will not be described in detail here.
[0124] Furthermore, the touch panel 6071 may be overlaid on the display panel 6061. When the touch panel 6071 detects a touch operation on or near it, it is transmitted to the processor 610 to determine the type of touch event. Then, the processor 610 provides corresponding visual output on the display panel 6061 according to the type of touch event. Figure 6 In the figure, the touch panel 6071 and the display panel 6061 are used as two independent components to realize the input and output functions of the electronic device. However, in some embodiments, the touch panel 6071 and the display panel 6061 can be integrated to realize the input and output functions of the electronic device, which is not limited here.
[0125] The interface unit 608 is an interface for connecting an external device to the electronic device 600. For example, the external device may include a wired or wireless headset port, an external power supply (or battery charger) port, a wired or wireless data port, a memory card port, a port for connecting a device with an identification module, an audio input / output (I / O) port, a video I / O port, a headphone port, etc. The interface unit 608 may be used to receive input (e.g., data information, power, etc.) from an external device and transmit the received input to one or more elements within the electronic device 600 or may be used to transmit data between the electronic device 600 and an external device.
[0126] The memory 609 can be used to store software programs and various data. The memory 609 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the mobile phone (such as audio data, a phone book, etc.), etc. In addition, the memory 609 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0127] The processor 610 is the control center of the electronic device. It uses various interfaces and lines to connect various parts of the entire electronic device. By running or executing software programs and / or modules stored in the memory 609 and calling data stored in the memory 609, it performs various functions of the electronic device and processes data, thereby monitoring the electronic device as a whole. The processor 610 may include one or more processing units; preferably, the processor 610 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 610.
[0128] The electronic device 600 may also include a power supply 611 (such as a battery) for supplying power to each component. Preferably, the power supply 611 may be logically connected to the processor 610 through a power management system, thereby implementing functions such as charging, discharging, and power consumption management through the power management system.
[0129] In addition, the electronic device 600 includes some functional modules not shown, which will not be described in detail here.
[0130] like Figure 7 As shown, in another embodiment provided by the present invention, a computer-readable storage medium 701 is further provided, in which instructions are stored. When the instructions are run on a computer, the computer executes the operator registration system described in the above embodiment.
[0131] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0132] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0133] The embodiments of the present invention are described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific implementation modes, which are merely illustrative rather than restrictive. Under the guidance of the present invention, ordinary technicians in this field can also make many forms without departing from the scope of protection of the present invention and the claims, all of which are within the protection of the present invention.
[0134] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed in the embodiments of the present invention can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0135] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0136] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0137] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0138] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0139] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as USB flash drives, mobile hard disks, ROM, RAM, magnetic disks, or optical disks.
[0140] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. An operator registration system, applied to a compiler, characterized in that: include: Create modules, compile modules and call modules; The creation module is used to input configuration parameters of the target operator and create a target file corresponding to the target operator according to the configuration parameters; The compiling module is used to compile the target file to obtain a library file corresponding to the target operator; The calling module is used to add a calling interface in the compiler, and the calling interface is used to call the library file.
2. The system according to claim 1, characterized in that The configuration parameters include operator name, attribute information, operator input information and operator output information. The creation module is used to input the configuration parameters of the target operator and create a target file corresponding to the target operator according to the configuration parameters, including: The creation module is used to input the configuration parameters, and create a target file with the name of the operator according to the configuration parameters; the target file includes a target structure, and the target structure is used to store the configuration parameters; The creation module is used to declare the properties of the target operator in the target file according to the property information, and to set the description and default value of the properties of the target operator; The creation module is used to determine the number of the target operator input and output in the target file according to the operator input information and the operator output information, and define the size relationship between the target operator input and output; The creation module is used to register the target operator in the target file according to the configuration parameters, obtain registration information of the target operator, and store the registration information in the target file.
3. The system according to claim 2, characterized in that Also includes: Display module; The display module is used to display the target code or the configuration parameters in the target file; The target code is generated according to the configuration parameters; The display module is used to modify the target file to obtain a modified target file.
4. The system according to claim 3, characterized in that The compilation module has a compilation file pre-installed therein, and the compilation module is used to compile the target file to obtain a library file corresponding to the target operator, including: The compilation module is used to compile the target code through the compilation file, obtain the library file corresponding to the target operator, and store it in the target folder; wherein the compilation file is used to define the information required for compiling the target code.
5. The system according to claim 1, characterized in that Also includes: Test module; The test module is used to input test data and select test operators, test the test operators, and obtain test results; The test module is used to determine whether the test result is consistent with the expected result; If the test result is inconsistent with the expected result, it is considered that the process of adding the test operator is unsuccessful; if the test result is consistent with the expected result, the model corresponding to the test operator is input into the compiler; wherein the test operator includes the target operator and the initial operator in the registration file of the compiler.
6. The system according to claim 5, characterized in that The test module is used to input test data and select test operators, test the test operators, and obtain test results, including: The test module is used to search the library file or the registration file according to the operator name of the test operator and call the calculation method corresponding to the test operator; The test module is used to automatically generate a test code template according to the test data and the calculation method corresponding to the test operator, so as to test the test operator and obtain a test result.
7. The system according to claim 6, characterized in that The test module is used to search the library file or the registration file according to the operator name of the test operator and call the calculation method corresponding to the test operator, including: The test module is used to search for the test operator in the registration file according to the operator name of the test operator. If the test operator is not found in the registration file, the test module is used to search for the test operator in the library file according to the operator name of the test operator. If the test operator is not found in the library file, the test operator is added through the operator adding platform. If the test operator is found in the library file or the registration file according to the operator name of the test operator, the calculation method corresponding to the test operator is called.
8. A method for adding an operator in a compiler, characterized in that: The method comprises: Input the configuration parameters of the target operator in the operator registration system, and create a target file corresponding to the target operator according to the configuration parameters; Compile the target file to obtain a library file corresponding to the target operator; A calling interface is added in the compiler, where the calling interface is used to call the library file.
9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; The memory is used to store computer programs; The processor is used to implement the system according to any one of claims 1 to 7 when executing the program stored in the memory.
10. A computer-readable storage medium having instructions stored thereon, which, when executed by one or more processors, cause the processors to execute the system according to any one of claims 1 to 7.
Citation Information
Cited By
Model precision alignment test method and system based on code block and electronic equipment
CN121365009A
Code block-based model precision alignment test method, system and electronic device
CN121365009B
