Operator processing method of deep learning framework, device and storage medium
An operator processing method of a deep learning framework an electronic device, and a storage medium are provided, which relate to a field of computer technology, especially in a field of artificial intelligence technology such as deep learning. The specific implementation scheme includes: acquiring an operator to be processed, where the operator to be processed includes a template parameter independent of the deep learning framework and an operator kernel function; parsing, in response to receiving an input information for the operator to be processed, the template parameter by using the input information to obtain a plurality of complete template parameters related to the deep learning framework; and processing the operator kernel function according to the plurality of complete template parameters, to obtain an available operator for the deep learning framework.
1 . An operator processing method of a deep learning framework, comprising:
acquiring an operator to be processed, wherein the operator to be processed comprises a template parameter independent of the deep learning framework and an operator kernel function;
parsing, in response to receiving an input information for the operator to be processed, the template parameter by using the input information to obtain a plurality of complete template parameters related to the deep learning framework; and
processing the operator kernel function according to the plurality of complete template parameters, to obtain an available operator for the deep learning framework,
wherein the parsing, in response to receiving an input information for the operator to be processed, the template parameter by using the input information to obtain the plurality of complete template parameters related to the deep learning framework, comprises:
creating a variable parameter list by using a macro; and
iteratively parsing the template parameter based on the variable parameter list, wherein the input information is implemented as a macro parameter of the macro,
wherein the iteratively parsing the template parameter based on the variable parameter list further comprises:
iteratively parsing the template parameter by using the variable parameter list to obtain a plurality of internal template parameters; and
performing a concatenation on the plurality of internal template parameters to obtain the plurality of complete template parameters,
wherein the processing the operator kernel function according to the plurality of complete template parameters, to obtain an available operator for the deep learning framework, comprises:
for each complete template parameter among the plurality of complete template parameters,
determining a function parameter type for the complete template parameter;
converting an input information of the complete template parameter into a corresponding parameter information according to the function parameter type; and
recording the corresponding parameter information.
2 . The method of claim 1 , wherein the variable parameter list comprises:
a name of the operator to be processed;
a name of the operator kernel function;
a data layout of the operator kernel function;
a device type for implementing the deep learning framework; and
a data type for implementing the deep learning framework.
3 . The method of claim 1 , wherein the iteratively parsing the template parameter based on the variable parameter list comprises:
determining a number of parameters comprised in the macro;
determining an end position of an iteration according to the number of the parameters; and
iteratively processing the input information according to the end position of the iteration by using the variable parameter list.
4 . The method of claim 1 , wherein the plurality of internal template parameters comprise a plurality of strings; and the performing a concatenation on the plurality of internal template parameters to obtain the plurality of complete template parameters comprises:
performing the concatenation on the plurality of strings according to the input information, to obtain the plurality of complete template parameters for the operator to be processed.
5 . The method of claim 1 , wherein the processing the operator kernel function according to the plurality of complete template parameters, to obtain an available operator for the deep learning framework, comprises:
processing the operator kernel function by explicitly instantiating the plurality of complete template parameters, to obtain the available operator for the deep learning framework.
6 . The method of claim 5 , wherein the plurality of complete template parameters respectively comprise a template function description information and a template function information; and the processing the operator kernel function by explicitly instantiating the plurality of complete template parameters, to obtain the available operator for the deep learning framework comprises:
instantiating the template function description information into a header file; and
instantiating the template function information into a source code file.
7 . The method of claim 1 , further comprising:
creating an operator to be registered based on the deep learning framework according to the plurality of complete template parameters; and
registering the operator to be registered into a global operator table in the deep learning framework.
8 . The method of claim 7 , wherein the operator to be registered comprises a description information of the operator to be registered and a kernel function of the operator to be registered, the kernel function of the operator to be registered comprises a normalized input information and a normalized function pointer; and creating the operator to be registered based on the deep learning framework according to the plurality of complete internal template functions comprises:
determining, for each complete template parameter among the plurality of complete template parameters, a structure corresponding to the complete template parameter, wherein the structure contains a static function, and the static function has a normalized form;
determining an input information of the static function as the normalized input information; and
determining a function pointer of the static function as the normalized function pointer.
9 . The method of claim 8 , wherein the input information of the static function forms an input information list, the input information list comprises an input tensor list; the structure comprises at least one specialization sub-structure, and each of the at least one specialization sub-structure has a respective corresponding data type.
10 . The method of claim 7 , wherein the global operator table comprises:
an operator kernel factory class;
an operator kernel name class and a kernel key value class; and
an operator kernel class.
11 . The method of claim 10 , wherein the operator kernel class comprises at least one of:
a pointer of the operator kernel function;
a description information of an input parameter of the operator kernel function; and
a description information of an output parameter of the operator kernel function.
12 . The method of claim 1 , wherein the template parameter independent of the deep learning framework is implemented to distribute the operator to be processed; and the template parameter independent of the deep learning framework comprises a template parameter which is independent of an implementation device of the deep learning framework and a data type of the deep learning framework.
13 . The method of claim 1 , further comprising:
calling the available operator in response to a calling instruction for the available operator; and
performing a functionality of a function corresponding to the available operator by compiling the called available operator.
14 . An electronic device, comprising:
at least one processor; and
a memory communicatively coupled with the at least one processor;
wherein the memory stores instructions executable by the at least one processor, and the instructions, when executed by the at least one processor, cause the at least one processor to:
acquire an operator to be processed, wherein the operator to be processed comprises a template parameter independent of the deep learning framework and an operator kernel function;
parse, in response to receiving an input information for the operator to be processed, the template parameter by using the input information to obtain a plurality of complete template parameters related to the deep learning framework; and
process the operator kernel function according to the plurality of complete template parameters, to obtain an available operator for the deep learning framework,
wherein the at least one processor is further configured to:
create a variable parameter list by using a macro; and
iteratively parse the template parameter based on the variable parameter list, wherein the input information is implemented as a macro parameter of the macro,
wherein the at least one processor is further configured to:
iteratively parse the template parameter by using the variable parameter list to obtain a plurality of internal template parameters; and
perform a concatenation on the plurality of internal template parameters to obtain the plurality of complete template parameters,
wherein the at least one processor is further configured to:
for each complete template parameter among the plurality of complete template parameters,
determine a function parameter type for the complete template parameter;
convert an input information of the complete template parameter into a corresponding parameter information according to the function parameter type; and
record the corresponding parameter information.
15 . The electronic device of claim 14 , wherein the variable parameter list comprises:
a name of the operator to be processed;
a name of the operator kernel function;
a data layout of the operator kernel function;
a device type for implementing the deep learning framework; and
a data type for implementing the deep learning framework.
16 . The electronic device of claim 14 , wherein the at least one processor is further configured to:
determine a number of parameters comprised in the macro;
determine an end position of an iteration according to the number of the parameters; and
iteratively process the input information according to the end position of the iteration by using the variable parameter list.
17 . The electronic device of claim 14 , wherein the plurality of internal template parameters comprise a plurality of strings; and wherein the at least one processor is further configured to:
perform the concatenation on the plurality of strings according to the input information, to obtain the plurality of complete template parameters for the operator to be processed.
18 . The electronic device of claim 14 , wherein the at least one processor is further configured to:
process the operator kernel function by explicitly instantiating the plurality of complete template parameters, to obtain the available operator for the deep learning framework.
19 . The electronic device of claim 18 , wherein the plurality of complete template parameters respectively comprise a template function description information and a template function information; and wherein the at least one processor is further configured to:
instantiate the template function description information into a header file; and
instantiate the template function information into a source code file.
20 . A non-transitory computer readable storage medium storing computer instructions, wherein the computer instructions are configured to cause a computer to:
acquire an operator to be processed, wherein the operator to be processed comprises a template parameter independent of the deep learning framework and an operator kernel function;
parse, in response to receiving an input information for the operator to be processed, the template parameter by using the input information to obtain a plurality of complete template parameters related to the deep learning framework; and
process the operator kernel function according to the plurality of complete template parameters, to obtain an available operator for the deep learning framework,
wherein the computer instructions are further configured to cause the computer to:
create a variable parameter list by using a macro; and
iteratively parse the template parameter based on the variable parameter list, wherein the input information is implemented as a macro parameter of the macro,
wherein the computer instructions are further configured to cause the computer to:
iteratively parse the template parameter by using the variable parameter list to obtain a plurality of internal template parameters; and
perform a concatenation on the plurality of internal template parameters to obtain the plurality of complete template parameters,
wherein the computer instructions are further configured to cause the computer to:
for each complete template parameter among the plurality of complete template parameters,
determine a function parameter type for the complete template parameter;
convert an input information of the complete template parameter into a corresponding parameter information according to the function parameter type; and
record the corresponding parameter information.