Middleware and method for deep learning framework adaptation to hardware devices
Through the common interface and internal execution components of the deep learning framework middleware, abstract operators are created to isolate the deep learning framework and the device operator library, which solves the problems of high hardware device adaptation and update costs and poor migration and replication characteristics of the deep learning framework, and achieves Reduce costs and improve portability.
Patent Information
- Application Number
- CN202411104719.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-13
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2044-08-13
AI Technical Summary
In the existing technology, the adaptation and update of deep learning frameworks to hardware devices is costly and has poor migration and replication characteristics. In particular, when hardware devices are replaced, a large number of intrusive modifications or plug-in update operations are required.
Provides a middleware that creates abstract operators through common interface components and internal execution components to isolate the deep learning framework and device operator libraries, allowing abstract operators to call device-specific operators on demand, avoiding plug-in deployment and single device-specific operators. Sub-granular update operations.
It reduces the cost of adapting and updating the deep learning framework to hardware devices, improves the migration and copying characteristics of the adaptation update, protects hardware information, and achieves compatibility with different framework types and the security of hardware information.
Smart Images

Figure CN118626172B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a middleware for adapting a deep learning framework to a hardware device, a method for adapting a deep learning framework to a hardware device, an electronic device, a non-transitory computer-readable storage medium, and a computer program product. Background Art
[0002] The performance of the deep learning (DL) framework depends on the computing power of the hardware. As the computing power requirements of the deep learning framework increase, the hardware devices equipped for the deep learning framework need to be upgraded and replaced, and the deep learning framework needs to be re-adapted to the new hardware devices after replacement.
[0003] In the related art, the replacement and adaptation of the deep learning framework to the hardware device can be achieved by intrusive modification of the deep learning framework, but the implementation of intrusive modification is difficult and the development cycle is long. In order to avoid intrusive modification of the deep learning framework, the related art can also allow the deep learning framework developed by plug-in to deploy device-specific operators in the form of plug-ins, and the device-specific operators can be updated through the plug-in update operation.
[0004] However, due to the large number of device-specific operators deployed in the form of plug-ins, the adaptation and update cost (including labor cost and time cost) of the deep learning framework for hardware devices is high.
[0005] Moreover, for deep learning frameworks of different framework types, there are significant differences in the plug-in deployment methods of device-specific operators. Therefore, the adaptation update method based on operator updates has poor migration and replication characteristics between different framework types.
[0006] As can be seen from the above, how to reduce the adaptation and update cost of the deep learning framework for hardware devices while avoiding invasive modifications to the deep learning framework, and how to improve the migration and replication characteristics of the adaptation and update of the deep learning framework for hardware devices, has become a technical problem to be solved in the prior art. Summary of the invention
[0007] Embodiments of the present application provide a middleware for adapting a deep learning framework to a hardware device, a method for adapting a deep learning framework to a hardware device, an electronic device, a non-transitory computer-readable storage medium, and a computer program product, which help to reduce the adaptation and update costs of the deep learning framework to the hardware device while avoiding the use of invasive modifications to the deep learning framework, and improve the migration and replication characteristics of the adaptation and update of the deep learning framework to the hardware device.
[0008] In one embodiment of the present application, a middleware for adapting a deep learning framework to a hardware device is provided, the middleware comprising:
[0009] A general interface component, used to connect to a deep learning framework of any framework type, and to create an abstract operator based on general configuration parameters provided by the deep learning framework; wherein the general configuration parameters are used to describe an abstract operation rule of a tensor operation, and the abstract operator is used to perform the tensor operation according to the abstract operation rule;
[0010] an internal execution component, for interfacing with a device operator library adapted to a current hardware device of the deep learning framework, and associating the abstract operator with a target operator selected from all device-specific operators in the device operator library; wherein the abstract operator calls the target operator according to the abstract operation rule, and the tensor operation is implemented by causing the current hardware device to perform a corresponding hardware operation when the target operator is called;
[0011] The general interface component isolates the internal execution component and the device operator library from the deep learning framework, and the abstract operator is created in the internal execution component.
[0012] In some examples, optionally, operator registration information is also recorded in the internal execution component, where the operator registration information is used to characterize the currently registered operator among all device-specific operators in the device operator library, and the target operator is selected and determined from the currently registered operators.
[0013] In some examples, optionally, the device operator library has an update maintenance interface for operator updates.
[0014] In some examples, optionally, the general interface component is also used to convert first tensor data provided by the deep learning framework into second tensor data in the internal execution component, the abstract operator performs the tensor operation on the second tensor data, and third tensor data obtained by the tensor operation is returned from the general interface component to the deep learning framework; wherein the first tensor data and the third tensor data both have a general data structure adapted to the external memory of the current hardware device of the deep learning framework, and the second tensor data has a specified data structure adapted to the device memory of the current hardware device.
[0015] In some examples, optionally, the object instance in the general interface component includes an operator parameter instance and an operator execution instance, and the object instance in the internal execution component includes an internal operator instance and an operator selection instance; wherein: the operator parameter instance is used to save the general configuration parameters; the operator execution instance is used to execute the creation and operation of the internal operator instance in the internal execution component based on the general configuration parameters; the internal operator instance is used to implement the abstract operator; the operator selection instance is used to execute the selection of the target operator, and, by associating the target operator with the internal operator instance, the association of the abstract operator with the target operator is implemented.
[0016] In some examples, optionally, the general configuration parameters include instance parameters of the internal operator instance, the instance parameters include base class parameters and subclass parameters of the internal operator instance, and the base class parameters and the subclass parameters are used to describe the abstract operation rules; the operator execution instance is used to determine the operator base class and the operator subclass of the internal operator instance based on the base class parameters and the subclass parameters, respectively; and the operator selection instance is used to perform selection and association of the target operator based on the operator base class and the operator subclass.
[0017] In some examples, optionally, the object instance in the general interface component also includes a tensor instance, and the object instance in the internal execution component also includes a device tensor instance; wherein: the tensor instance is used to save the first tensor data provided by the deep learning framework, and the first tensor data has a general data structure adapted to the external memory of the current hardware device of the deep learning framework; the operator execution instance is also used to convert the first tensor data into second tensor data, and the second tensor data has a specified data structure adapted to the device memory of the current hardware device; the device tensor instance is used to save the second tensor data, and the abstract operator performs the tensor operation on the second tensor data; the operator execution instance is also used to convert the tensor operation result of performing the tensor operation on the second tensor data into a third tensor data, and the third tensor data has a general data structure adapted to the external memory; the operator execution instance is also used to output the third tensor data to the tensor instance, and the third tensor data is returned from the tensor instance to the deep learning framework.
[0018] In some examples, optionally, the object instance in the internal execution component also includes an operator registration instance, which is used to record operator registration information, the operator registration information is used to characterize the currently registered operator among all device-specific operators in the device operator library, and the operator selection instance is used to select the target operator from the currently registered operators based on the operator registration information.
[0019] In some examples, optionally, the object instance in the internal execution component also includes a tensor management instance, which is used to manage the tensor lifecycle of the device tensor instance, and the tensor lifecycle is greater than or equal to the duration of the tensor operation executed at least once on the second tensor data.
[0020] In some examples, optionally, the object instance in the internal execution component also includes a memory management instance, and the memory management instance is used to manage the memory space occupied by the device tensor instance in the device memory.
[0021] In another embodiment of the present application, a method for adapting a deep learning framework to a hardware device includes:
[0022] Using a general interface for docking with a deep learning framework of any framework type, obtaining general configuration parameters provided by the deep learning framework; wherein the general configuration parameters are used to describe abstract operation rules of tensor operations;
[0023] Creating an abstract operator based on the general configuration parameters; wherein the abstract operator is used to perform the tensor operation according to the abstract operation rule; wherein the abstract operator is isolated from the deep learning framework;
[0024] Selecting a target operator for the abstract operator from among all device-specific operators of a device operator library adapted to a current hardware device of the deep learning framework; wherein the device operator library and the target operator selected in the device operator library are isolated from the deep learning framework;
[0025] The abstract operator is associated with the target operator so that the abstract operator calls the target operator according to the abstract operation rule; wherein the tensor operation is implemented by the corresponding hardware operation performed by the current hardware device when the target operator is called.
[0026] In some examples, optionally, it also includes recording operator registration information, where the operator registration information is used to characterize the currently registered operator among all device-specific operators in the device operator library, and selecting a target operator for the abstract operator among all device-specific operators in the device operator library adapted to the current hardware device of the deep learning framework includes: selecting the target operator from the currently registered operators based on the operator registration information.
[0027] In some examples, optionally, the method further includes: performing operator update on the device operator library.
[0028] In some examples, optionally, it also includes: converting the first tensor data provided by the deep learning framework into second tensor data isolated from the deep learning framework, the abstract operator performing the tensor operation on the second tensor data, and returning the third tensor data obtained by the tensor operation to the deep learning framework using the general interface; wherein the first tensor data and the third tensor data both have a general data structure adapted to the external memory of the current hardware device of the deep learning framework, and the second tensor data has a specified data structure adapted to the device memory of the current hardware device.
[0029] In some examples, optionally, creating the abstract operator based on the general configuration parameters includes: creating an internal operator instance isolated from the deep learning framework; wherein the internal operator instance is used to implement the abstract operator; and associating the abstract operator with the target operator includes: associating the target operator with the internal operator instance.
[0030] In some examples, optionally, the general configuration parameters include instance parameters of the internal operator instance, the instance parameters include base class parameters and subclass parameters of the internal operator instance, and the base class parameters and the subclass parameters are used to describe the abstract operation rules; the creation of the internal operator instance isolated from the deep learning framework includes: based on the base class parameters and the subclass parameters, respectively determining the operator base class and the operator subclass of the internal operator instance; wherein the selection of the target operator and the association of the internal operator instance with the target operator are based on the operator base class and the operator subclass.
[0031] In another embodiment of the present application, an electronic device is provided, including a processor, wherein the processor is used to run the middleware described in the foregoing embodiment, or execute the method described in the foregoing embodiment.
[0032] In another embodiment of the present application, a non-transitory computer-readable storage medium is also provided, which stores instructions that, when executed by a processor, enable the processor to run the middleware described in the aforementioned embodiment, or execute the method described in the aforementioned embodiment.
[0033] In another embodiment of the present application, a computer program product is provided, including computer executable instructions. When these computer executable instructions are executed by a processor, they can run the middleware described in the foregoing embodiment, or perform the method described in the foregoing embodiment.
[0034] Based on the embodiments of the present application, the device-specific operators adapted to the current hardware devices of the deep learning framework can be centrally stored in the device operator library without the need to be actually deployed in the deep learning framework in the form of plug-ins, and the device-specific operators in the device operator library can be called on demand by abstract operators decoupled from the current hardware devices through the general interface access of the deep learning framework. Therefore, when the current hardware devices of the deep learning framework are changed, the adaptation of the deep learning framework to the new hardware devices can be achieved by replacing the device operator library as a whole, without the need to perform a large number of plug-in update operations on the deep learning framework at the granularity of a single device-specific operator, thereby reducing the adaptation and update costs of the deep learning framework for hardware devices; moreover, the device operator library and general interface on which the deep learning framework relies for the adaptation of the hardware devices can be compatible with different framework types of the deep learning framework, thereby improving the migration and replication characteristics of the deep learning framework for the adaptation and update of the hardware devices. In addition, compared with the solution of actually deploying device-specific operators in the deep learning framework as plug-ins, encapsulating device-specific operators in a device operator library isolated from the deep learning framework and calling them on demand while keeping the device-specific operators isolated from the deep learning framework can avoid the device-specific operators from exposing the hardware information of the hardware devices in the form of plug-ins, thereby helping to improve the hardware information protection of the hardware devices. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] The following drawings are only used to illustrate and explain the present application, and do not limit the scope of the present application:
[0036] Figure 1 A schematic diagram of the deployment principle of the middleware used for deep learning framework adaptation hardware devices in an embodiment of the present application;
[0037] Figure 2 This is an exemplary structural diagram of a middleware for deep learning framework adaptation hardware device in an embodiment of the present application;
[0038] Figure 3 This is a schematic diagram of the working principle of the middleware used for deep learning framework adaptation hardware devices in an embodiment of the present application;
[0039] Figure 4 This is a schematic diagram of an example structure of a middleware for adapting a deep learning framework to a hardware device in an embodiment of the present application;
[0040] Figure 5 This is a schematic diagram of a working example of a middleware for adapting a deep learning framework to a hardware device in an embodiment of the present application;
[0041] Figure 6 A schematic diagram of an extended example of a middleware for adapting a deep learning framework to a hardware device in an embodiment of the present application;
[0042] Figure 7 This is a schematic diagram of an exemplary process of a method for adapting a deep learning framework to a hardware device in an embodiment of the present application. DETAILED DESCRIPTION
[0043] In order to make the objectives, technical solutions and advantages of the present application more clearly understood, the present application is further described in detail below with reference to the accompanying drawings and examples.
[0044] Figure 1 This is a schematic diagram of the deployment principle of the middleware used for deep learning framework adaptation hardware devices in the embodiment of this application. Figure 1 In an embodiment of the present application, device-specific operators adapted to the current hardware device of the deep learning framework 10 can be centrally stored in the device operator library 50, and an embodiment of the present application provides a middleware 30 for the deep learning framework 10 to adapt to the hardware device. Among them, the middleware 30 can be deployed between the deep learning framework 10 and the device operator library 50, the middleware 30 can isolate the deep learning framework 10 and the device operator library 50 from each other, the middleware 30 can provide a general interface for the deep learning framework 10, and the middleware 30 can also respond to the deep learning framework 10's access to the general interface when tensor operations are required, and implement on-demand calls to device-specific operators in the device operator library 50, so as to utilize the hardware operation operations generated by the on-demand calls to device-specific operators to complete the tensor operations required by the deep learning framework 10.
[0045] On the one hand, based on the embodiments of the present application, the hardware computing operations for implementing tensor operations of the deep learning framework 10 can be implemented by the middleware 30 calling device-specific operators without the deep learning framework 10 executing the call to the device-specific operators. Therefore, the device-specific operators do not need to be actually deployed in the deep learning framework 10 in the form of plug-ins.
[0046] In a deep learning framework developed using a plug-in approach, a device-specific operator is deployed separately for each hardware operation required for each tensor operation, that is, the device-specific operator is deployed in a plug-in deployment mode of "one operator, one implementation". Therefore, whenever a corresponding tensor operation needs to be performed using the current hardware device, the deep learning framework can call the corresponding device-specific operator for each hardware operation required for the tensor operation through a plug-in call. Moreover, for a deep learning framework developed using a plug-in approach, the adaptation between the deep learning framework and the hardware device mainly depends on the device-specific operator, and if the hardware device used by the deep learning framework is replaced, then all device-specific operators deployed in the deep learning framework in a plug-in manner need to be updated by performing an operator update operation, that is, the operator update of the deep learning framework needs to perform a large number of plug-in update operations at the granularity of a single device-specific operator, and even if there are multiple identical device-specific operators in the deep learning framework, the plug-in update operation still needs to be repeated for the multiple identical device-specific operators. Since the number of device-specific operators deployed in the "one operator one implementation" plug-in deployment method is extremely large, the number of plug-in update operations will be equally large, which in turn leads to high adaptation and update costs (including labor costs and time costs) for the deep learning framework to the hardware devices.
[0047] In contrast, when the current hardware device of the deep learning framework 10 is changed, the embodiment of the present application can achieve the adaptation of the deep learning framework 10 to the new hardware device by replacing the device operator library 50 as a whole (exemplarily, Figure 1 The dotted arc arrow located at the corner of the rectangular frame representing the device operator library 50 indicates that it is replaceable), without the need to perform a large number of plug-in update operations on the deep learning framework at the granularity of a single device-specific operator (especially the plug-in update operations repeatedly performed on multiple identical device-specific operators), thereby reducing the adaptation and update costs of the deep learning framework 10 for hardware devices.
[0048] Exemplarily, in an embodiment of the present application, the current hardware device of the deep learning framework 10 may be a hardware device of any specification of any one of the processors including a CPU (Central Processing Unit), a GPU (Graphics Processing Unit), a TPU (Tensor Processing Unit), a NPU (Neural network Processing Unit), a DPU (Deep learning Processing Unit), an APU (Accelerated Processing Unit), and a GPGPU (General-Purpose computing on Graphics Processing Unit).
[0049] On the other hand, the device operator library 50 and the general interface that the deep learning framework 10 relies on for the adaptation of the hardware device can be compatible with different framework types of the deep learning framework 10. For example, Figure 1 It is shown in FIG. 1 that the device operator library 50 and the deep learning framework 10 are isolated on both sides of the middleware 30, which at least indicates that the framework type of the device operator library 50 and the deep learning framework 10 are decoupled; and, Figure 1 The multiple stacked rectangular boxes marked with reference numeral "10" represent deep learning frameworks of different framework types, and the stacked rectangular boxes are connected to the middleware 30 through the same bidirectional arrow, which indicates that the universal interface is compatible with deep learning frameworks of different framework types. Thus, the migration and replication characteristics of the deep learning framework 10 for the adaptation and update of hardware devices can be improved.
[0050] Exemplarily, in an embodiment of the present application, the framework type of the deep learning framework 10 may include PyTorch, TensorFlow, PaddlePaddle, etc.
[0051] In addition, compared to the solution of actually deploying device-specific operators in the deep learning framework 10 in the form of plug-ins, encapsulating the device-specific operators in a device operator library 50 isolated from the deep learning framework 10 and calling them on demand while keeping the device-specific operators isolated from the deep learning framework 10 can avoid the device-specific operators from exposing the hardware information of the hardware devices in the form of plug-ins, thereby helping to improve the hardware information protection of the hardware devices.
[0052] Figure 2This is an exemplary structural diagram of the middleware used to adapt the deep learning framework to the hardware device in the embodiment of the present application. Figure 3 This is a schematic diagram of the working principle of the middleware used for deep learning framework adaptation hardware devices in the embodiment of this application. Figure 2 and Figure 3 In an embodiment of the present application, the middleware 30 for adapting the deep learning framework to the hardware device may include a general interface component 31 and an internal execution component 36.
[0053] In an embodiment of the present application, a universal interface component 31 can provide a universal interface compatible with different framework types of a deep learning framework 10. The universal interface component 31 can be used to connect (for example, using the universal interface to connect) a deep learning framework 10 of any framework type, and create (for example, create in the internal execution component 36) an abstract operator OP_abs based on the universal configuration parameter Prm_OP provided by the deep learning framework 10 (for example, using the universal interface); wherein the universal configuration parameter Prm_OP is used to describe the abstract operation rules of the current tensor operation of the deep learning framework 10, and the abstract operator OP_abs is used to perform the current tensor operation of the deep learning framework 10 according to the abstract operation rules described by the universal configuration parameter Prm_OP.
[0054] Exemplarily, in an embodiment of the present application, the general interface component 31 can also be used to obtain the first tensor data Tsr_inp provided by the deep learning framework 10 (for example, provided by using the general interface). The first tensor data Tsr_inp is used to characterize the operation object of the current tensor operation of the deep learning framework 10, and the first tensor data Tsr_inp has a general data structure adapted to the external memory of the current hardware device 70 of the deep learning framework, and the general data structure of the first tensor data Tsr_inp is decoupled from the framework type of the deep learning framework 10 and the current hardware device 70.
[0055] Exemplarily, in an embodiment of the present application, the internal execution component 36 is used to connect to the device operator library 50 adapted to the current hardware device 70 of the deep learning framework 10, select the target operator of the abstract operator OP_abs from all device-specific operators OP_dvc of the device operator library 50, and associate the abstract operator OP_abs with the target operator selected from all device-specific operators OP_dvc of the device operator library 50; wherein the abstract operator OP_abs calls the associated target operator according to the abstract operation rule described by the general configuration parameter Prm_OP to perform the current tensor operation of the deep learning framework 10; and the tensor operation can be performed by the corresponding hardware operation operation (for example, Figure 3This is achieved by using the dashed arc arrow in the rectangular box indicated by the reference numeral in the figure).
[0056] Exemplarily, in an embodiment of the present application, the internal execution component 36 may select a strategy based on the performance data of all device-specific operators OP_dvc in the device operator library 50, with the target operator minimizing the hardware overhead of the current hardware device 70 while ensuring the current tensor operations of the deep learning framework 10.
[0057] Exemplarily, in an embodiment of the present application, the general interface component 31 may also be used to convert the first tensor data Tsr_inp provided by the deep learning framework 10 (for example, provided by using the general interface) into the second tensor data Tsr_dvc (for example, converted into the second tensor data Tsr_dvc in the internal execution component 36). The abstract operator OP_abs may perform the current tensor operation of the deep learning framework 10 on the second tensor data Tsr_dvc, and the second tensor data Tsr_dvc has a specified data structure adapted to the device memory of the current hardware device 70 (for example, the display memory of the GPU, or the integrated memory of the CPU, or the on-chip memory of the GPGPU). For example, the second tensor data Tsr_dvc may include the data content and data attributes of the first tensor data Tsr_inp, and the data attributes may include data dimension, data type, data arrangement, etc. On this basis, the second tensor data Tsr_dvc may also include the hardware information of the current hardware device 70 of the deep learning framework 10, and the hardware information of the current hardware device 70 included in the second tensor data Tsr_dvc may specifically include memory addresses and memory specifications of device memory, etc. In this case, the second tensor data Tsr_dvc may be transferred to the device memory of the current hardware device 70, and the second tensor data Tsr_dvc may be executed in the device memory of the current hardware device 70 by the hardware operation corresponding to the target operator called by the abstract operator OP_abs.
[0058] Exemplarily, in an embodiment of the present application, the tensor operation result Tsr_rsl obtained by the abstract operator OP_abs performing a tensor operation on the second tensor data Tsr_dvc may have the same specified data structure as the second tensor data Tsr_dvc, and the tensor operation result Tsr_rsl may be converted into a third tensor data Tsr_out by the external interface component 31, the third tensor data Tsr_out may have the same general data structure as the first tensor data Tsr_inp, and the third tensor data Tsr_out obtained by the tensor operation may be returned to the deep learning framework 10 by the general interface component 31.
[0059] Exemplarily, in an embodiment of the present application, the general interface component 31 can isolate the internal execution component 36 and the device operator library 50 from the deep learning framework 10, and the abstract operator OP_abs is created in the internal execution component 36, so the abstract operator OP_abs and the abstract operator OP_abs's call to the target operator in the device operator library 50 are also isolated from the deep learning framework 10.
[0060] Based on the above embodiment, through the general interface access of the deep learning framework 10 to the general interface component 31, the device-specific operator OP_dvc in the device operator library 50 can be called on demand by the internal execution component 36 using the abstract operator OP_abs decoupled from the current hardware device 70. Thus, the aforementioned technical effects of reducing the adaptation and update cost of the deep learning framework 10 for the hardware device, improving the migration and replication characteristics of the adaptation and update of the deep learning framework 10 for the hardware device, and improving the hardware information protection of the current hardware device 70 can be produced.
[0061] Figure 4 This is a schematic diagram of the example structure of the middleware used to adapt the deep learning framework to the hardware device in the embodiment of the present application. Figure 5 This is a working example diagram of the middleware used to adapt the deep learning framework to the hardware device in the embodiment of this application. Figure 4 and Figure 5 In an embodiment of the present application, the object instance in the general interface component 31 may include an operator execution instance 310, a tensor instance 311, and an operator parameter instance 312, and the object instance in the internal execution component 36 may include an internal operator instance 360, a device tensor instance 361, and an operator selection instance 362.
[0062] Exemplarily, in an embodiment of the present application, the instance name of the tensor instance 311 may be defined as "Tensor", and the tensor instance 311 may be used to save the first tensor data Tsr_inp provided by the deep learning framework 10 (for example, provided through a universal interface), and the third tensor data Tsr_out to be returned (for example, returned through a universal interface) to the deep learning framework 10. That is, in an embodiment of the present application, the universal interface component 31 may be specifically configured to save the first tensor data Tsr_inp provided by the deep learning framework 10 (for example, provided through a universal interface), and the third tensor data Tsr_out to be returned (for example, returned through a universal interface) to the deep learning framework 10.
[0063] Exemplarily, in an embodiment of the present application, the instance name of the operator parameter instance 312 can be defined as "OpParams (operator parameters)", and the operator parameter instance 312 can be used to save the general configuration parameters Prm_OP provided by the deep learning framework 10 (for example, provided through a general interface).
[0064] For example, in an embodiment of the present application, the instance name of the operator execution instance 310 may be defined as “OpExecutor”, and the operator execution instance 310 may be used for:
[0065] By converting the first tensor data Tsr_inp of the tensor instance 311 into the second tensor data Tsr_dvc, creating a device tensor instance 361 including the second tensor data Tsr_dvc;
[0066] Based on the general configuration parameter Prm_OP of the operator parameter instance 312, the creation and operation of the internal operator instance 360 in the internal execution component 36 and the configuration of the operator selection instance 362 are executed; and,
[0067] The tensor operation result Tsr_rsl obtained by performing a tensor operation on the second tensor data Tsr_dvc (for example, obtained from the device tensor instance 361 ) is converted into third tensor data Tsr_out, and the third tensor data Tsr_out is output to the tensor instance 311 .
[0068] Exemplarily, in an embodiment of the present application, the operator execution instance 310 may include a tensor input instance interface that may be named "AddInputTensor", a tensor output instance interface that may be named "AddOutputTensor", a compilation instance interface that may be named "CompileOp", an execution instance interface that may be named "Execute", and a clearing instance interface that may be named "Clear". Among them:
[0069] The tensor input instance interface “AddInputTensor” can be used to input the first tensor data Tsr_inp from the tensor instance 311 into the operator execution instance 310;
[0070] The tensor output instance interface "AddOutputTensor" can be used to input the tensor operation result Tsr_rsl in the converted form of the third tensor data Tsr_out;
[0071] The compile instance interface "CompileOp" may be used to create a device tensor instance 361 by converting first tensor data Tsr_inp into second tensor data Tsr_dvc, create an internal operator instance 360 based on a general configuration parameter Prm_OP, and configure an operator selection instance 362 based on the general configuration parameter Prm_OP;
[0072] The execution instance interface “Execute” is used to run the internal operator instance 360 (i.e., the abstract operator OP_abs);
[0073] The clear instance interface “Clear” is used to clear the device tensor instance 361 and the internal operator instance 360 , and reset the operator selection instance 362 .
[0074] Exemplarily, in an embodiment of the present application, the instance name of the device tensor instance 361 can be defined as "DeviceTensor", and the device tensor instance 361 can be used to save the second tensor data Tsr_dvc, send the second tensor data Tsr_dvc to the device memory of the current hardware device 70 of the deep learning framework 10, and obtain the tensor operation result Tsr_rsl after the second tensor data Tsr_dvc is subjected to the tensor operation (i.e., the hardware operation operation corresponding to the tensor operation) from the device memory of the current hardware device 70 of the deep learning framework 10.
[0075] Exemplarily, in an embodiment of the present application, the instance name of the operator selection instance 362 can be defined as "OperatorKernelSelector", and the operator selection instance 362 can be used to perform selection of a target operator for the abstract operator OP_abs (for example, further performing the selection based on performance data of all device-specific operators OP_dvc), and, by associating the selected target operator with the internal operator instance 360, the association of the abstract operator OP_abs abstract operator with the target operator is achieved.
[0076] Exemplarily, in an embodiment of the present application, the general configuration parameter Prm_OP may include instance parameters of the internal operator instance 360, which may include base class parameters and subclass parameters of the internal operator instance 360. For example, the subclass parameters may include convolution operation parameters OpParams of an operation subclass of a convolution operation (Convolution, Conv), and function parameters ReLUOpParams of an activation function subclass such as a Reflected Linear Unit (ReLU); and the base class parameters and the subclass parameters of the internal operator instance 360 are used to describe the abstract operation rules of the current tensor operation of the deep learning framework 10. In this case, the operator execution instance 310 can be used to determine the operator base class and operator subclass of the internal operator instance 360 based on the base class parameters and subclass parameters of the instance parameters in the general configuration parameter Prm_OP, respectively. For example, the operator subclass under the operator base class of the internal operator instance 360 may include a convolution operation operator ConvOp and an activation function operator ReLUOp, and the operator selection instance 362 can be configured by the operator execution instance to perform selection and association of the target operator according to the operator base class and operator subclass determined by the operator execution instance 310 for the internal operator instance 360.
[0077] Exemplarily, in an embodiment of the present application, the instance name of the internal operator instance 360 can be defined as "IOp (Internal Operator)", and the internal operator instance 360 is used to implement the abstract operator OP_abs, and by calling the associated target operator, the second tensor data Tsr_dvc sent by the device tensor instance 361 into the device memory of the current hardware device 70 is executed the hardware operation corresponding to the tensor operation.
[0078] Figure 6 This is a schematic diagram of an extended example of a middleware used to adapt a deep learning framework to a hardware device in an embodiment of the present application. Figure 6 In an embodiment of the present application, the internal execution component 36 may further include at least one of an operator registration instance 363 , a tensor management instance 364 , and a memory management instance 365 .
[0079] Exemplarily, in an embodiment of the present application, the instance name of the operator registration instance 363 can be defined as "OperatorKernelRegister", and any device-specific operator OP_dvc in the device operator library 50 can be registered as the current registered operator in the operator registration instance 363, or unregistered in the operator registration instance 363. The operator registration instance 363 can be used to record operator registration information. For example, the operator registration information may include the operator identifier, operator function, and performance data of the current registered operator. The operator registration information of the operator registration instance 363 is used to characterize the current registered operator in all device-specific operators OP_dvc of the device operator library 50, and the operator selection instance 362 can be used to select a target operator from all currently registered operators in the device operator library 50 based on the operator registration information in the operator registration instance 363.
[0080] That is, in the embodiment of the present application, the internal execution component 36 may also record the operator registration information. In this case, the target operator may be selected and determined from the currently registered operators represented by the operator registration information of the device operator library 50, that is, the internal execution component 36 may also be used to select the target operator from all currently registered operators of the device operator library 50 according to the operator registration information in the operator registration instance 363. Thus, by introducing the operator registration mechanism, the device-specific operators in the device operator library are selectively enabled and effective, and further, the device-specific operators OP_dvc in the device operator library 50 that can be selected as the target operator can be dynamically adjusted.
[0081] Exemplarily, in an embodiment of the present application, the device operator library 50 may also have an update maintenance interface for updating the device-specific operator OP_dvc. Thus, by providing the update maintenance interface for the device operator library 50, the device-specific operators in the device operator library 50 may be allowed to be dynamically updated, and the device-specific operators OP_dvc in the device operator library 50 that may be selected as the target operator may also be dynamically adjusted.
[0082] As can be seen above, in the embodiments of the present application, whether using the registration mechanism to adjust the selection range of the device-specific operator OP_dvc in the device operator library 50, or updating the device-specific operator OP_dvc in the device operator library 50, it helps to improve the scalability of the deep learning framework 10 for adapting and updating the current hardware device 70.
[0083] Exemplarily, in an embodiment of the present application, the instance name of the tensor management instance 364 can be defined as "TensorManager", and the tensor management instance 364 can be used to manage the tensor life cycle of the device tensor instance 361, and the tensor life cycle of the device tensor instance 361 can be greater than or equal to the operation time of the second tensor data Tsr_dvc being executed at least once in the device memory of the current hardware device 70 (that is, executing at least one set of hardware operation operations corresponding to at least one tensor operation).
[0084] For example, in an embodiment of the present application, the second tensor data Tsr_dvc of the device tensor instance 361 can be continuously executed by at least two abstract operators OP_abr created successively to perform at least two tensor operations with different abstract operation rules, that is, the second tensor data Tsr_dvc sent by the device tensor instance 361 to the device memory of the current hardware device 70 can be continuously executed by at least two groups of hardware operation operations corresponding to at least two tensor operations. In this case, the tensor management instance 364 can continue to extend the tensor life cycle of the device tensor instance 361 after a group of hardware operation operations corresponding to the previous tensor operation is completed until at least two groups of hardware operation operations corresponding to at least two tensor operations are all completed.
[0085] Exemplarily, in an embodiment of the present application, the device tensor instance 361 may return the tensor operation result Tsr_rsl of the currently completed tensor operation to the general interface component 31 (e.g., the operator execution instance 310) in response to the completion of a set of hardware operation operations corresponding to each tensor operation; or, the device tensor instance 361 may also return the tensor operation result Tsr_rsl of at least two consecutive tensor operations to the general interface component 31 (e.g., the operator execution instance 310) in response to the end of the tensor life cycle.
[0086] Exemplarily, in an embodiment of the present application, the instance name of the memory management instance 365 may be defined as "MemoryManager", and the memory management instance 365 may be used to manage the memory space occupied by the device tensor instance 361 in the device memory. For example, in response to the start of the tensor lifecycle of the device tensor instance 361, the memory management instance 365 may apply to the current hardware device 70 for the memory space that can be occupied (for example, occupied by the second tensor data Tsr_dvc) in the device memory for the device tensor instance 361; and, in response to the end of the tensor lifecycle of the device tensor instance 361, instruct the current hardware device 70 to release the memory space occupied by the device tensor instance 361 in the device memory (for example, occupied by the second tensor data Tsr_dvc).
[0087] Figure 7This is an exemplary flow chart of the method for adapting a deep learning framework to a hardware device in an embodiment of the present application. Figure 7 , an embodiment of the present application further provides a method for adapting a deep learning framework to a hardware device, and the method may include:
[0088] S710: Using a general interface for docking with a deep learning framework of any framework type, obtaining general configuration parameters provided by the deep learning framework; wherein the general configuration parameters are used to describe abstract operation rules of tensor operations of the deep learning framework;
[0089] S730: Creating an abstract operator based on the general configuration parameters provided by the deep learning framework; wherein the abstract operator is used to perform tensor operations of the deep learning framework according to the abstract operation rules, and the abstract operator is isolated from the deep learning framework;
[0090] S750: Select a target operator for the abstract operator from among all device-specific operators of a device operator library adapted to a current hardware device of the deep learning framework; wherein the device operator library and the target operator selected from the device operators are isolated from the deep learning framework;
[0091] S770: Associating the abstract operator with the target operator so that the abstract operator calls the target operator according to the abstract operation rules of the tensor operation of the deep learning framework; wherein the tensor operation of the deep learning framework is implemented by the corresponding hardware operation performed by the current hardware device of the deep learning framework when the target operator is called.
[0092] Based on the above process, the device-specific operators adapted to the current hardware devices of the deep learning framework can be centrally stored in the device operator library without the need to be actually deployed in the deep learning framework in the form of plug-ins. Moreover, through the general interface access of the deep learning framework, the device-specific operators in the device operator library can be called on demand by the abstract operators decoupled from the current hardware devices. Therefore, when the current hardware devices of the deep learning framework are changed, the adaptation of the deep learning framework to the new hardware devices can be achieved by replacing the device operator library as a whole, without the need to perform a large number of plug-in update operations on the deep learning framework at the granularity of a single device-specific operator, thereby reducing the adaptation and update costs of the deep learning framework for hardware devices; moreover, the device operator library and general interface on which the deep learning framework relies for the adaptation of hardware devices can be compatible with different framework types of the deep learning framework, thereby improving the migration and replication characteristics of the deep learning framework for the adaptation and update of hardware devices. In addition, compared with the solution of actually deploying device-specific operators in the deep learning framework as plug-ins, encapsulating device-specific operators in a device operator library isolated from the deep learning framework and calling them on demand while keeping the device-specific operators isolated from the deep learning framework can avoid the device-specific operators from exposing the hardware information of the hardware devices in the form of plug-ins, thereby helping to improve the hardware information protection of the hardware devices.
[0093] Exemplarily, in an embodiment of the present application, the method for adapting a deep learning framework to a hardware device may further include: recording operator registration information, the operator registration information being used to characterize the currently registered operator in the device-specific operators of the device operator library, and S750 may specifically include: selecting a target operator from the currently registered operators based on the recorded operator registration information.
[0094] Exemplarily, in an embodiment of the present application, the method for adapting a deep learning framework to a hardware device may further include: converting a first tensor data provided by the deep learning framework into a second tensor data isolated from the deep learning framework, an abstract operator performing the tensor operation on the second tensor data, and returning the third tensor data obtained by the tensor operation to the deep learning framework using a general interface; wherein the first tensor data and the third tensor data both have a general data structure of the external memory of the current hardware device adapted to the deep learning framework, and the second tensor data has a specified data structure of the device memory adapted to the current hardware device.
[0095] Exemplarily, in an embodiment of the present application, the method for adapting a deep learning framework to a hardware device may further include: creating an internal operator instance isolated from the deep learning framework; wherein the internal operator instance is used to implement an abstract operator; and S770 may specifically include: associating a target operator with the internal operator instance.
[0096] Exemplarily, in an embodiment of the present application, the general configuration parameters provided by the deep learning framework may include instance parameters of an internal operator instance, which may include base class parameters and subclass parameters of the internal operator instance, and the base class parameters and the subclass parameters are used to describe the abstract operation rules. In this case, the process of creating an internal operator instance isolated from the deep learning framework at S730 may include: determining the operator base class and operator subclass of the internal operator instance based on the base class parameters and the subclass parameters, respectively; and the selection of the target operator at S750 and the association of the internal operator instance with the target operator at S770 are based on the operator base class and operator subclass of the internal operator instance.
[0097] It can be understood that, in the embodiments of the present application, the various parts of the contents exemplified can be in an "and / or" relationship. In this article, the meaning of "and / or" refers to the contexts connected by it, which can be in a common limiting relationship of "and", or can also be in an alternative limiting relationship of "or". Therefore, the various parts of the contents with an "and / or" relationship can be understood as including different combinations of situations in which "and / or" between each two parts of the contents respectively represents a common limiting relationship of "and" or an alternative limiting relationship of "or", and this combination of different situations can be considered to be basically equivalent to the limiting scope of "at least one of the parts".
[0098] Another embodiment of the present application further provides an electronic device, including a processor, wherein the processor is used to run the middleware described in the foregoing embodiment, or execute the method described in the foregoing embodiment.
[0099] Another embodiment of the present application also provides a non-transitory computer-readable storage medium, which stores instructions that, when executed by a processor, enable the processor to run the middleware described in the aforementioned embodiment, or execute the method described in the aforementioned embodiment.
[0100] Another embodiment of the present application further provides a computer program product, including computer executable instructions, which, when executed by a processor, can run the middleware described in the foregoing embodiment, or execute the method described in the foregoing embodiment.
[0101] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the scope of protection of the present application.
Claims
1. A middleware for deep learning framework adaptation to hardware devices, characterized in that: include: A general interface component, used to connect to a deep learning framework of any framework type, and to create an abstract operator based on general configuration parameters provided by the deep learning framework; wherein the general configuration parameters are used to describe an abstract operation rule of a tensor operation, and the abstract operator is used to perform the tensor operation according to the abstract operation rule; an internal execution component, for interfacing with a device operator library adapted to a current hardware device of the deep learning framework, and associating the abstract operator with a target operator selected from all device-specific operators in the device operator library; wherein the abstract operator calls the target operator according to the abstract operation rule, and the tensor operation is implemented by causing the current hardware device to perform a corresponding hardware operation when the target operator is called; The general interface component isolates the internal execution component and the device operator library from the deep learning framework, and the abstract operator is created in the internal execution component.
2. The middleware according to claim 1, characterized in that: The internal execution component also records operator registration information, where the operator registration information is used to represent a currently registered operator among all device-specific operators in the device operator library, and the target operator is selected and determined from the currently registered operators; and / or, The device operator library has an update maintenance interface for operator update; and / or, The general interface component is also used to convert the first tensor data provided by the deep learning framework into the second tensor data in the internal execution component, the abstract operator performs the tensor operation on the second tensor data, and the third tensor data obtained by the tensor operation is returned from the general interface component to the deep learning framework; wherein the first tensor data and the third tensor data both have a general data structure adapted to the external memory of the current hardware device of the deep learning framework, and the second tensor data has a specified data structure adapted to the device memory of the current hardware device.
3. The middleware according to claim 1, characterized in that: The object instances in the general interface component include operator parameter instances and operator execution instances, and the object instances in the internal execution component include internal operator instances and operator selection instances; wherein: The operator parameter instance is used to store the general configuration parameters; The operator execution instance is used to execute the creation and operation of the internal operator instance in the internal execution component based on the general configuration parameters; The internal operator instance is used to implement the abstract operator; The operator selection instance is used to perform selection of the target operator, and, by associating the target operator with the internal operator instance, the association between the abstract operator and the target operator is achieved.
4. The middleware according to claim 3, characterized in that: The general configuration parameters include instance parameters of the internal operator instance, the instance parameters include base class parameters and subclass parameters of the internal operator instance, and the base class parameters and the subclass parameters are used to describe the abstract operation rule; The operator execution instance is used to determine the operator base class and the operator subclass of the internal operator instance based on the base class parameter and the subclass parameter respectively; The operator selection instance is used to perform selection and association of the target operator according to the operator base class and the operator subclass.
5. The middleware according to claim 3, characterized in that: The object instance in the general interface component further includes a tensor instance, and the object instance in the internal execution component further includes a device tensor instance; wherein: The tensor instance is used to store first tensor data provided by the deep learning framework, and the first tensor data has a general data structure adapted to the external memory of the current hardware device of the deep learning framework; The operator execution instance is further used to convert the first tensor data into second tensor data, and the second tensor data has a specified data structure adapted to the device memory of the current hardware device; The device tensor instance is used to store the second tensor data, and the abstract operator performs the tensor operation on the second tensor data; The operator execution instance is further used to convert a tensor operation result of performing the tensor operation on the second tensor data into third tensor data, wherein the third tensor data has a general data structure adapted to the external memory; The operator execution instance is further used to output the third tensor data to the tensor instance, and the third tensor data is returned from the tensor instance to the deep learning framework.
6. The middleware according to claim 5, characterized in that: The object instance in the internal execution component further includes an operator registration instance, the operator registration instance is used to record operator registration information, the operator registration information is used to characterize the currently registered operator among all device-specific operators in the device operator library, and the operator selection instance is used to select the target operator among the currently registered operators according to the operator registration information; and / or, The object instance in the internal execution component further includes a tensor management instance, which is used to manage the tensor lifecycle of the device tensor instance, and the tensor lifecycle is greater than or equal to the operation time taken by the second tensor data to perform the tensor operation at least once; and / or, The object instance in the internal execution component also includes a memory management instance, and the memory management instance is used to manage the memory space occupied by the device tensor instance in the device memory.
7. A method for adapting a deep learning framework to a hardware device, characterized in that: include: Using a general interface for docking with a deep learning framework of any framework type, obtaining general configuration parameters provided by the deep learning framework; wherein the general configuration parameters are used to describe abstract operation rules of tensor operations; Creating an abstract operator based on the general configuration parameters; wherein the abstract operator is used to perform the tensor operation according to the abstract operation rule; wherein the abstract operator is isolated from the deep learning framework; Selecting a target operator for the abstract operator from among all device-specific operators of a device operator library adapted to a current hardware device of the deep learning framework; wherein the device operator library and the target operator selected in the device operator library are isolated from the deep learning framework; The abstract operator is associated with the target operator so that the abstract operator calls the target operator according to the abstract operation rule; wherein the tensor operation is implemented by the corresponding hardware operation performed by the current hardware device when the target operator is called.
8. An electronic device, characterized in that: The method comprises a processor configured to run the middleware according to any one of claims 1 to 6.
9. A non-transitory computer-readable storage medium, characterized in that The non-transitory computer-readable storage medium stores instructions which, when executed by a processor, cause the processor to execute the middleware according to any one of claims 1 to 6.
10. A computer program product, characterized in that The method comprises computer executable instructions, which, when executed by a processor, run the middleware according to any one of claims 1 to 6.
Citation Information
Patent Citations
Domestic platform artificial intelligence environment adaptation method and compatibility test method
CN113076143A
Method, device and equipment for accessing chip operator library into deep learning framework, and medium
CN118394822A
Deep learning framework operator calling method, storage medium and electronic equipment
CN118428426A
Method for adapting deep learning framework to hardware device based on unified backend engine
US20230162048A1
