A method, device and medium for running a deep learning model
By allocating zero-copy shared memory to adjacent computing tasks and reasonably setting up hardware computing units, the problem of frequent data copying between different hardware computing units in mobile devices is solved, and the processing efficiency and running speed of the deep learning model are improved, achieving effectively accelerate the model.
Patent Information
- Application Number
- CN202010918324.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-02
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2040-09-02
AI Technical Summary
When running a deep learning model, frequent data copy operations between different hardware computing units of mobile devices lead to slow interaction and reduce the acceleration effect of the hardware on the model.
By allocating zero-copy shared memory to adjacent computing tasks and setting appropriate hardware computing units according to the computing capabilities of the computing tasks, data duplication is avoided and processing efficiency and running speed are improved.
It improves the processing efficiency and running speed of deep learning models, reduces resource occupation and overall power consumption, and ensures the acceleration effect of deep learning models.
Smart Images

Figure CN111984423B
Abstract
Description
Technical Field
[0001] This article relates to the field of deep learning technology, and in particular to a method, device and medium for running a deep learning model. Background Art
[0002] There are many hardware computing units in mobile devices, such as central processing unit (CPU), graphics processing unit (GPU), digital signal processor (DSP), neural network processing unit (NPU), etc. When running deep learning models, various hardware computing units often need to collaborate in computing, resulting in a large number of data interaction operations. The usual processing method is to copy memory data between two hardware computing units in large quantities, resulting in a slow interaction speed between devices, reducing the acceleration effect of the hardware computing units on the deep learning model. Summary of the invention
[0003] In order to overcome the problems existing in the related art, this article provides a method, device and medium for running a deep learning model.
[0004] According to a first aspect of the embodiments of this document, a method for running a deep learning model is provided, the method comprising:
[0005] Determine a hardware computing unit for processing each computing task in a deep learning model, each computing task corresponding to a hardware computing unit, and the deep learning model includes more than one computing task arranged in sequence;
[0006] Allocate a shared memory for every two adjacent computing tasks, and when the hardware computing units corresponding to the adjacent computing tasks are different, allocate a shared memory of a zero-copy type for the adjacent computing tasks;
[0007] The deep learning model is run using the shared memory.
[0008] In one embodiment, the method further comprises:
[0009] When the hardware computing units corresponding to adjacent computing tasks are the same, a shared memory of a non-zero copy type is allocated to the adjacent computing tasks.
[0010] In one embodiment, the method further comprises:
[0011] When the hardware computing units corresponding to adjacent computing tasks are the same, a shared memory of a zero-copy type is allocated to the adjacent computing tasks.
[0012] In one embodiment, the method further comprises: allocating an input memory for storing input data of the deep learning model, wherein the type of the input memory is a zero-copy type;
[0013] An output memory is allocated for storing output data of the deep learning model, wherein the type of the output memory is a zero-copy type.
[0014] In one embodiment, the method further includes: setting a hardware computing unit for processing each computing task according to the computing capability of each computing task.
[0015] According to a second aspect of the embodiments of this document, there is provided a device for running a deep learning model, including:
[0016] A first determination module is configured to determine a hardware computing unit for processing each computing task in a deep learning model, each computing task corresponds to a hardware computing unit, and the deep learning model includes more than one computing tasks arranged in sequence;
[0017] A first allocation module is configured to allocate a shared memory to every two adjacent computing tasks, and when the hardware computing units corresponding to the adjacent computing tasks are different, allocate a shared memory of a zero-copy type to the adjacent computing tasks;
[0018] A running module is configured to run the deep learning model using the shared memory.
[0019] In one embodiment, the first allocation module is further configured to allocate a shared memory of a non-zero copy type to adjacent computing tasks when the hardware computing units corresponding to the adjacent computing tasks are the same.
[0020] In one embodiment, the first allocation module is further configured to allocate a shared memory of a zero-copy type to adjacent computing tasks when the hardware computing units corresponding to the adjacent computing tasks are the same.
[0021] In one embodiment, the device further comprises:
[0022] The second allocation module is configured to allocate input memory for storing input data of the deep learning model, and the type of the input memory is a zero-copy type; allocate output memory for storing output data of the deep learning model, and the type of the output memory is a zero-copy type.
[0023] In one embodiment, the device further comprises:
[0024] The setting module is configured to set a hardware computing unit for processing each computing task according to the computing capability of each computing task.
[0025] According to a third aspect of the embodiments of this document, there is provided a device for running a deep learning model, including:
[0026] processor;
[0027] a memory for storing processor-executable instructions;
[0028] Wherein, the processor is configured to execute the method.
[0029] According to a fourth aspect of the embodiments of this document, a non-transitory computer-readable storage medium is provided, which enables the mobile terminal to execute the method when instructions in the storage medium are executed by a processor of the mobile terminal.
[0030] The technical solution provided by the embodiments of the present disclosure may include the following beneficial effects: when the hardware computing units corresponding to adjacent computing tasks are different, a shared memory of the zero-copy type is allocated to the adjacent computing tasks, thereby avoiding frequent copying of memory data between different hardware computing units when executing adjacent computing tasks during the operation of the deep learning model, thereby improving processing efficiency, increasing operating speed, reducing resource usage, reducing overall power consumption, and ensuring the acceleration effect on the deep learning model.
[0031] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present invention and, together with the description, serve to explain the principles of the present invention.
[0033] Figure 1 is a flowchart of a method for running a deep learning model according to an exemplary embodiment;
[0034] Figure 2 is a structural diagram of a device for running a deep learning model according to an exemplary embodiment;
[0035] Figure 3 It is a structural diagram of a device for running a deep learning model according to an exemplary embodiment. DETAILED DESCRIPTION
[0036] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with this document. Instead, they are merely examples of devices and methods consistent with some aspects of this document as detailed in the appended claims.
[0037] The present disclosure provides a method for running a deep learning model. Figure 1 , Figure 1 FIG. 1 is a flow chart of a method for running a deep learning model according to an exemplary embodiment. Figure 1 As shown, this method includes:
[0038] Step S11, determining a hardware computing unit for processing each computing task in the deep learning model, each computing task corresponds to a hardware computing unit, and the deep learning model includes more than one computing tasks arranged in sequence.
[0039] Step S12, allocating a shared memory to every two adjacent computing tasks. When the hardware computing units corresponding to the adjacent computing tasks are different, a shared memory of a zero-copy type is allocated to the adjacent computing tasks.
[0040] Step S13, using the shared memory to run the deep learning model.
[0041] Among them, the hardware computing units include the central processing unit (CPU), graphics processing unit (GPU), digital signal processor (DSP), neural network processor (NPU), etc.
[0042] When different hardware computing units operate on the same zero-copy type of memory, there is no need to copy data. When different hardware computing units operate on the same non-zero-copy type of memory, data copying is required.
[0043] The shared memory of adjacent computing tasks is used to store shared data, which is output data of a previous computing task of the adjacent computing task and input data of a subsequent computing task.
[0044] In one implementation, the zero-copy type memory refers to an ION buffer.
[0045] In this embodiment, when the hardware computing units corresponding to adjacent computing tasks are different, shared memory of the zero-copy type is allocated to the adjacent computing tasks to avoid frequent copying of memory data between different hardware computing units when executing adjacent computing tasks during the operation of the deep learning model. This can improve processing efficiency and operating speed, reduce resource usage and overall power consumption, and ensure the acceleration effect on the deep learning model.
[0046] The present disclosure provides a method for running a deep learning model, the method comprising: Figure 1 The method shown, and: when the hardware computing units corresponding to adjacent computing tasks are the same, a shared memory of a non-zero copy type is allocated to the adjacent computing tasks.
[0047] When the hardware computing units corresponding to adjacent computing tasks are the same, when non-zero copy type memory is used, the requirements for memory alignment are lower, which can avoid memory waste caused by memory alignment.
[0048] The present disclosure provides a method for running a deep learning model, the method comprising: Figure 1 The method shown, and: when the hardware computing units corresponding to adjacent computing tasks are the same, a shared memory of a zero-copy type is allocated to the adjacent computing tasks.
[0049] This embodiment Figure 1 Based on the method shown, the processing efficiency and operation speed can be further improved, and the resource occupation and overall power consumption can be further reduced.
[0050] The present disclosure provides a method for running a deep learning model, the method comprising: Figure 1 The method shown, and: allocating input memory for storing input data of the deep learning model, the type of the input memory is a zero-copy type; allocating output memory for storing output data of the deep learning model, the type of the output memory is a zero-copy type.
[0051] This embodiment Figure 1 Based on the method shown, it is possible to effectively prevent frequent data duplication from occurring when the hardware computing unit used to output the input data of the deep learning model is different from the hardware computing unit used to process the first computing task, and to prevent frequent data duplication from occurring when the hardware computing unit used to extract the output data of the output deep learning model is different from the hardware computing unit used to process the last computing task.
[0052] The present disclosure provides a method for running a deep learning model, the method comprising: Figure 1 The method shown, and:
[0053] When the hardware computing units corresponding to adjacent computing tasks are the same, a shared memory of a zero-copy type is allocated to the adjacent computing tasks.
[0054] An input memory is allocated for storing input data of the deep learning model, and the type of the input memory is a zero-copy type; an output memory is allocated for storing output data of the deep learning model, and the type of the output memory is a zero-copy type.
[0055] This embodiment Figure 1 Based on the method shown, zero copy can be achieved in the entire process of running deep learning models.
[0056] The present disclosure provides a method for running a deep learning model, the method comprising: Figure 1 The method shown in the figure also includes: setting a hardware computing unit for processing each computing task according to the computing power of each computing task. Specifically, when the computing task requires stronger computing power, a hardware computing unit with stronger computing power is allocated to the computing task, and when the computing task requires less computing power, a hardware computing unit with less computing power is allocated to the computing task, thereby realizing the rational allocation of computing power resources.
[0057] The present disclosure provides a method for operating a deep learning model, which includes: Figure 1 The method shown also includes: determining the capacity of the corresponding memory according to the data volume and data type of the input data of each computing task in the deep learning model. For example, when the input data is a matrix, the data volume is the number of elements contained in the matrix, the data type is the data precision, and when the data precision is a real number, the precision is determined according to the number of exact digits of the real number.
[0058] The following describes it in detail through two specific embodiments. Specific embodiment 1
[0060] The deep learning model consists of a total of four computing tasks connected in sequence.
[0061] The first computing task is a convolution operation, and the hardware computing unit corresponding to the first computing task is a GPU;
[0062] The second computing task is convolution operation, and the hardware computing unit corresponding to the second computing task is GPU;
[0063] The third computing task is pooling computing, and the hardware computing unit corresponding to the third computing task is the CPU;
[0064] The fourth computing task is pooling operation, and the hardware computing unit corresponding to the fourth computing task is NPU.
[0065] A first memory is set to store input data of a first computing task. The first memory is an ION memory, which is a type of zero-copy memory.
[0066] The hardware computing units corresponding to the first computing task and the second computing task are the same. The first computing task and the second computing task share the second memory. The second memory is ordinary memory. The ordinary memory is non-zero copy memory. The shared data stored in the second memory is the output data of the first computing task and the input data of the second computing task.
[0067] The hardware computing units corresponding to the second computing task and the third computing task are different. The second computing task and the third computing task share the third memory, which is the ION memory. The shared data stored in the third memory is the output data of the second computing task and the input data of the third computing task.
[0068] The hardware computing units corresponding to the third computing task and the fourth computing task are different. The third computing task and the fourth computing task share the fourth memory. The fourth memory is ION memory. The shared data stored in the fourth memory is the output data of the third computing task and the input data of the fourth computing task.
[0069] The fifth memory is set to store the output data of the fourth computing task. The fifth memory is an ION memory.
[0070] During the operation of the deep learning model, the input data of the deep learning model is directly stored in the first memory. When executing the first computing task, the input data is read from the first memory, and the output data after the first computing task is completed is stored in the second memory. When executing the second computing task, the input data is read from the second memory, and the output data after the second computing task is completed is stored in the third memory, and so on, until the deep learning model is finished, the output data of the deep learning model is read from the fifth memory. During the execution process, the hardware computing units corresponding to the first computing task and the second computing task are both GPUs, and the GPU uses ordinary memory for data replication. The same GPU has a higher processing efficiency when using ordinary memory for data replication. Except for the second memory, other memories are zero-copy memories, thereby avoiding frequent copying of memory data between different hardware computing units. Specific embodiment 2
[0072] The deep learning model in the specific embodiment is the same as the deep learning model in the specific embodiment 1. The difference from the specific embodiment 1 in setting the memory is that the first memory, the second memory, the third memory, the fourth memory, and the fifth memory are all ION memories. This achieves zero copy of memory data in the entire process of running the deep learning model.
[0073] In an embodiment of the present disclosure, a device for operating a deep learning model is provided. Figure 2 , Figure 2 FIG. 1 is a structural diagram of a device for running a deep learning model according to an exemplary embodiment. Figure 2 As shown, the device comprises:
[0074] A first determination module 201 is configured to determine a hardware computing unit for processing each computing task in a deep learning model, each computing task corresponding to a hardware computing unit, and the deep learning model includes more than one computing task arranged in sequence;
[0075] A first allocation module 202 is configured to allocate a shared memory to every two adjacent computing tasks, and when the hardware computing units corresponding to the adjacent computing tasks are different, allocate a shared memory of a zero-copy type to the adjacent computing tasks;
[0076] The running module 203 is configured to run the deep learning model using the shared memory.
[0077] The present disclosure provides a device for running a deep learning model, which includes Figure 2 The device shown, and: the first allocation module 202 is also configured to allocate a shared memory of a non-zero copy type to the adjacent computing tasks when the hardware computing units corresponding to the adjacent computing tasks are the same.
[0078] The present disclosure provides a device for running a deep learning model, which includes Figure 2 The device shown, and: the first allocation module 202 is also configured to allocate a shared memory of a zero-copy type to the adjacent computing tasks when the hardware computing units corresponding to the adjacent computing tasks are the same.
[0079] The present disclosure provides a device for running a deep learning model, which includes Figure 2 The device shown, and: the device also includes: a second allocation module, configured to allocate input memory for storing input data of the deep learning model, and the type of the input memory is a zero-copy type; allocate output memory for storing output data of the deep learning model, and the type of the output memory is a zero-copy type.
[0080] The present disclosure provides a device for running a deep learning model, which includes Figure 2 The device shown in the figure also includes a setting module configured to set a hardware computing unit for processing each computing task according to the computing power of each computing task.
[0081] The present disclosure provides a device for running a deep learning model, including:
[0082] processor;
[0083] a memory for storing processor-executable instructions;
[0084] Wherein, the processor is configured to execute the method.
[0085] In an embodiment of the present disclosure, a non-transitory computer-readable storage medium is provided. When instructions in the storage medium are executed by a processor of a mobile terminal, the mobile terminal is enabled to execute the method.
[0086] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0087] Figure 3 1 is a block diagram of an apparatus 300 for running a deep learning model according to an exemplary embodiment. For example, the apparatus 300 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0088] Reference Figure 3 , the device 300 may include one or more of the following components: a processing component 302 , a memory 304 , a power component 306 , a multimedia component 308 , an audio component 310 , an input / output (I / O) interface 312 , a sensor component 314 , and a communication component 316 .
[0089] The processing component 302 generally controls the overall operation of the device 300, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 302 may include one or more processors 320 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 302 may include one or more modules to facilitate the interaction between the processing component 302 and other components. For example, the processing component 302 may include a multimedia module to facilitate the interaction between the multimedia component 308 and the processing component 302.
[0090] The memory 304 is configured to store various types of data to support operations on the device 300. Examples of such data include instructions for any application or method operating on the device 300, contact data, phone book data, messages, pictures, videos, etc. The memory 304 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0091] The power supply component 306 provides power to the various components of the device 300. The power supply component 306 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the device 300.
[0092] The multimedia component 308 includes a screen that provides an output interface between the device 300 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 308 includes a front camera and / or a rear camera. When the device 300 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0093] The audio component 310 is configured to output and / or input audio signals. For example, the audio component 310 includes a microphone (MIC), and when the device 300 is in an operating mode, such as a call mode, a recording mode, and a speech recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 304 or sent via the communication component 316. In some embodiments, the audio component 310 also includes a speaker for outputting audio signals.
[0094] I / O interface 312 provides an interface between processing component 302 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.
[0095] The sensor assembly 314 includes one or more sensors for providing various aspects of status assessment for the device 300. For example, the sensor assembly 314 can detect the open / closed state of the device 300, the relative positioning of components, such as the display and keypad of the device 300, the sensor assembly 314 can also detect the position change of the device 300 or a component of the device 300, the presence or absence of user contact with the device 300, the orientation or acceleration / deceleration of the device 300, and the temperature change of the device 300. The sensor assembly 314 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 314 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 314 may also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0096] The communication component 316 is configured to facilitate wired or wireless communication between the device 300 and other devices. The device 300 can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 316 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 316 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0097] In an exemplary embodiment, the apparatus 300 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors or other electronic components to perform the above method.
[0098] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 304 including instructions, and the instructions can be executed by the processor 320 of the device 300 to perform the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0099] Those skilled in the art will readily appreciate other embodiments of the present invention after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses or adaptations of the present invention that follow the general principles of the present invention and include common knowledge or customary techniques in the art that are not disclosed herein. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present invention are indicated by the following claims.
[0100] It should be understood that the present invention is not limited to the exact construction that has been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present invention is limited only by the appended claims.
Claims
1. A method for running a deep learning model, characterized in that: include: Determine a hardware computing unit for processing each computing task in a deep learning model, each computing task corresponding to a hardware computing unit, and the deep learning model includes more than one computing task arranged in sequence; Allocate a shared memory for every two adjacent computing tasks, and when the hardware computing units corresponding to the adjacent computing tasks are different, allocate a shared memory of a zero-copy type for the adjacent computing tasks; The deep learning model is run using the shared memory.
2. The method according to claim 1, characterized in that The method further comprises: When the hardware computing units corresponding to adjacent computing tasks are the same, a shared memory of a non-zero copy type is allocated to the adjacent computing tasks.
3. The method according to claim 1, characterized in that The method further comprises: When the hardware computing units corresponding to adjacent computing tasks are the same, a shared memory of a zero-copy type is allocated to the adjacent computing tasks.
4. The method according to claim 1, characterized in that The method further includes: allocating an input memory for storing input data of the deep learning model, wherein the type of the input memory is a zero-copy type; An output memory is allocated for storing output data of the deep learning model, wherein the type of the output memory is a zero-copy type.
5. The method according to claim 1, characterized in that The method further includes: setting a hardware computing unit for processing each computing task according to the computing capability of each computing task.
6. A device for running a deep learning model, characterized in that: include: A first determination module is configured to determine a hardware computing unit for processing each computing task in a deep learning model, each computing task corresponds to a hardware computing unit, and the deep learning model includes more than one computing tasks arranged in sequence; A first allocation module is configured to allocate a shared memory to every two adjacent computing tasks, and when the hardware computing units corresponding to the adjacent computing tasks are different, allocate a shared memory of a zero-copy type to the adjacent computing tasks; A running module is configured to run the deep learning model using the shared memory.
7. The device according to claim 6, characterized in that The first allocation module is further configured to allocate a shared memory of a non-zero copy type to adjacent computing tasks when the hardware computing units corresponding to the adjacent computing tasks are the same.
8. The device according to claim 6, characterized in that The first allocation module is further configured to allocate a shared memory of a zero-copy type to adjacent computing tasks when the hardware computing units corresponding to the adjacent computing tasks are the same.
9. The device according to claim 6, characterized in that The device also includes: The second allocation module is configured to allocate input memory for storing input data of the deep learning model, and the type of the input memory is a zero-copy type; allocate output memory for storing output data of the deep learning model, and the type of the output memory is a zero-copy type.
10. The device according to claim 6, characterized in that The device also includes: The setting module is configured to set a hardware computing unit for processing each computing task according to the computing capability of each computing task.
11. A device for running a deep learning model, characterized in that: include: processor; a memory for storing processor-executable instructions; The processor is configured to execute the method of any one of claims 1 to 5.
12. A non-transitory computer-readable storage medium, when instructions in the storage medium are executed by a processor of a mobile terminal, the mobile terminal is enabled to execute the method of any one of claims 1 to 5.
