Computer vision operator acceleration method, system and electronic device based on NPU
By receiving and converting configuration parameters in the NPU hardware, generating operating instructions and building inference models, it solves the problem of excessive OpenCV operator processing resources and device complexity, and achieves efficient image operator acceleration and applicability.
Patent Information
- Application Number
- CN202410978963.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-22
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2044-07-22
AI Technical Summary
In the existing technology, OpenCV operator processing mainly relies on the CPU or DSP, which leads to excessive use of computing resources and affects the performance of other tasks. In addition, designing hardware circuits or processors increases device complexity and cost, and cannot cover the processing of all operators. This leads to limitations in operator processing.
The NPU-based computer vision operator acceleration method is adopted to receive configuration parameters, convert them into configuration parameters suitable for the neural processing unit, generate operation instructions, build an inference model, and perform inference tasks in the neural processing unit, saving context information to accelerate images. processing to avoid occupying CPU or DSP resources.
It improves the image operator processing speed, adapts to different image processing scenarios, reduces equipment complexity and cost, and expands the applicability and efficiency of operator processing.
Smart Images

Figure CN118505490B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a computer vision operator acceleration method, system and electronic device based on NPU. Background Art
[0002] Operator processing is one of the links in image processing. Operators refer to algorithms or functions used to perform specific image processing tasks, such as filtering, edge detection, morphological operations, etc. These operators can be applied to application scenarios such as machine vision, computer vision, and image processing to extract useful information from complex image data, thereby achieving image enhancement, analysis, and recognition.
[0003] In order to perform operator processing, OpenCV (Open Source Computer Vision Library) can be transplanted into electronic devices in terms of software, and various image processing tasks can be performed through the image processing operators provided by OpenCV. For example, the OpenCV library is compiled and configured according to the operating system and hardware architecture of the electronic device so that the electronic device can call the operator functions provided by OpenCV. However, OpenCV mainly runs on the CPU or DSP, which will occupy more computing resources, resulting in the performance of other tasks being affected.
[0004] Therefore, in order to improve the performance degradation caused by porting OpenCV in software, hardware circuits or processors such as IVE (Image Video Engine) can also be designed to perform operator processing to improve the efficiency and performance of image processing tasks. However, due to the diversity of operators, designing hardware circuits or processors will increase the complexity and cost of electronic devices, such as increasing the area of the chip, and operators not covered by the hardware circuits or processors cannot be executed, resulting in increased limitations of operator processing in electronic devices. Summary of the invention
[0005] The present application provides a computer vision operator acceleration method, system and electronic device based on NPU to solve the problem of high operator processing limitations in electronic devices.
[0006] In a first aspect, some embodiments of the present application provide a computer vision operator acceleration method based on an NPU, the method comprising the following steps:
[0007] Receiving a first configuration parameter, the first configuration parameter being used to set an operation target of a target image operator, the target image operator being a transformation function for execution in a neural processing unit, a first interface corresponding to the target image operator being aligned with a second interface corresponding to the computer vision operator;
[0008] Converting the first configuration parameter into a second configuration parameter, where the second configuration parameter is a configuration parameter applicable to the neural processing unit;
[0009] generating an operation instruction according to the second configuration parameter;
[0010] Building a reasoning model according to the operation instruction and the second configuration parameter;
[0011] Sending the inference model to the neural processing unit so that the neural processing unit performs the inference task according to the inference model;
[0012] The context information of the neural processing unit performing the reasoning task is saved so that the target image operator performs image processing through the context information.
[0013] In some embodiments of the present application, the first configuration parameter includes at least one of an interpolation method, an alignment method, a scaling factor, a data storage address, and a convolution kernel of a filtering operator.
[0014] In some embodiments of the present application, converting the first configuration parameter into the second configuration parameter includes: parsing the data format of the first configuration parameter; when the data format is the same as a preset template format, modifying the data structure and / or data type of the first configuration parameter through the first interface to generate the second configuration parameter; passing the second configuration parameter to the operator layer of the neural processing unit so that the operator layer generates the operation instruction according to the second configuration parameter.
[0015] In some embodiments of the present application, generating an operation instruction according to the second configuration parameter includes: calling a tool chain application through the operator layer to generate instruction code, the tool chain application is an application of the tool chain corresponding to the neural processing unit, and the instruction code includes at least one of an opcode field, an operand field, and a control bit field; encapsulating the instruction code to generate the operation instruction.
[0016] In some embodiments of the present application, before calling the tool chain application to generate instruction code through the operator layer, it also includes: detecting the operator type of the target image operator; if the target image operator is a combination operator, executing the step of calling the tool chain application to generate instruction code through the operator layer, and generating a scheduling instruction for the target image operator according to a preset scheduling logic, so that the operator layer schedules the order of the operation instructions according to the scheduling instruction; the combination operator is an image operator generated by splicing multiple neural network units.
[0017] In some embodiments of the present application, constructing an inference model according to the operation instructions and the second configuration parameters includes: packaging the operation instructions, the second configuration parameters, the operator layer parameters of the operator layer in the neural processing unit, and associated parameters into a model file, the associated parameters including activation function parameters, optimization parameters, and at least one of the meta-information of the inference model; generating the inference model according to the model file.
[0018] In some embodiments of the present application, sending the inference model to the neural processing unit includes: loading a model file of the inference model; passing the model file to the inference engine of the neural processing unit; and passing the model file to the neural processing unit through the inference engine.
[0019] In some embodiments of the present application, the first interface includes a synchronous interface and an asynchronous interface, and the method further includes: loading the context information through the first interface; executing the reasoning task according to the context information to speed up the processing speed of the target image operator.
[0020] In a second aspect, some embodiments of the present application further provide a computer vision operator acceleration system based on an NPU, comprising a first interface, an operator processing unit, and a neural processing unit, wherein:
[0021] The first interface is configured to receive a first configuration parameter, where the first configuration parameter is used to set an operation target of a target image operator, where the target image operator is a transformation function for execution in a neural processing unit, and where the first interface corresponding to the target image operator is aligned with the second interface corresponding to the computer vision operator; and convert the first configuration parameter into a second configuration parameter, where the second configuration parameter is a configuration parameter applicable to the neural processing unit.
[0022] The operator processing unit is configured to generate an operation instruction according to the second configuration parameters; build an inference model according to the operation instruction and the second configuration parameters; and send the inference model to the neural processing unit.
[0023] The neural processing unit is configured to perform reasoning tasks according to the reasoning model and send the reasoning tasks to the first interface so that the first interface saves context information of the neural processing unit performing the reasoning tasks, and the context information is used to perform image processing of the target image operator.
[0024] In a third aspect, some embodiments of the present application further provide an electronic device, including a processor, a memory, and a bus. The processor and the memory are communicatively connected via the bus, the memory stores computer program instructions executable by the processor, and the processor is configured to:
[0025] Receiving a first configuration parameter, the first configuration parameter being used to set an operation target of a target image operator, the target image operator being a transformation function for execution in a neural processing unit, a first interface corresponding to the target image operator being aligned with a second interface corresponding to the computer vision operator;
[0026] Converting the first configuration parameter into a second configuration parameter, where the second configuration parameter is a configuration parameter applicable to the neural processing unit;
[0027] generating an operation instruction according to the second configuration parameter;
[0028] Building a reasoning model according to the operation instruction and the second configuration parameter;
[0029] Sending the inference model to the neural processing unit so that the neural processing unit performs the inference task according to the inference model;
[0030] The context information of the neural processing unit performing the reasoning task is saved so that the target image operator performs image processing through the context information.
[0031] It can be seen from the above technical solutions that the computer vision operator acceleration method, system and electronic device based on NPU provided by some embodiments of the present application can receive a first configuration parameter. Among them, the first configuration parameter is used to set the operation target of the target image operator, the target image operator is a transformation function for execution in the neural processing unit, and the first interface corresponding to the target image operator is aligned with the second interface corresponding to the computer vision operator. The first configuration parameter is then converted into a second configuration parameter applicable to the neural processing unit, and an operation instruction is generated according to the second configuration parameter. An inference model is constructed according to the operation instruction and the second configuration parameter, and the inference model is sent to the neural processing unit so that the neural processing unit performs the inference task according to the inference model. The context information of the neural processing unit performing the inference task is then saved so that the target image operator performs image processing through the context information. The method does not need to occupy the computing resources of the CPU or DSP, can improve the processing speed of the image operator, and is suitable for different image processing scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0033] Figure 1A schematic diagram of an NPU architecture provided for some embodiments of the present application;
[0034] Figure 2 A flowchart of a method for accelerating a computer vision operator based on an NPU provided in some embodiments of the present application;
[0035] Figure 3 A schematic diagram of a process for converting configuration parameters provided in some embodiments of the present application;
[0036] Figure 4 A schematic diagram of a generation process of operation instructions provided in some embodiments of the present application;
[0037] Figure 5 A schematic diagram of a process for constructing an NPU model provided in some embodiments of the present application;
[0038] Figure 6 A schematic diagram of the flow of the NPU-CV operator provided in some embodiments of the present application;
[0039] Figure 7 An architecture diagram of a computer vision operator acceleration system based on an NPU provided in some embodiments of the present application;
[0040] Figure 8 A schematic diagram of the structure of an electronic device provided for some embodiments of the present application. DETAILED DESCRIPTION
[0041] In order to make the purpose, technical solutions and advantages of the exemplary embodiments of the present application clearer, the technical solutions in the exemplary embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the exemplary embodiments of the present application. Obviously, the described exemplary embodiments are only part of the embodiments of the present application, not all of the embodiments.
[0042] Based on the exemplary embodiments shown in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application. In addition, although the disclosure in this application is introduced according to one or several exemplary examples, it should be understood that each aspect of these disclosures can also constitute a complete technical solution separately.
[0043] It should be understood that the terms "first", "second", "third", etc. in the specification and the above-mentioned drawings of this application are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, for example, they can be implemented according to an order other than those given in the diagrams or descriptions of the embodiments of this application.
[0044] In addition, the terms "include" and "have" and any variations thereof are intended to cover but not exclude inclusion, for example, a product or device comprising a list of components is not necessarily limited to those components expressly listed but may include other components not expressly listed or inherent to such products or devices.
[0045] In the field of image processing, a variety of different operator processing is required to perform various operations, such as edge detection, feature extraction, filtering, etc. Therefore, in some embodiments, in terms of software, OpenCV (Open Source Computer Vision Library) can be ported to electronic devices to accelerate the process of operator processing.
[0046] For example, OpenCV can provide edge detection operators, such as Sobel operator, Canny operator, etc.; filter operators, such as Gaussian filter, median filter, etc.; corner detection operators, such as Harris corner detection, Shi-Tomasi corner detection, etc.; morphological operations, such as dilation, erosion, etc. After porting OpenCV to electronic devices, OpenCV can provide a variety of APIs and functions, and electronic devices can directly implement the above operators in software. Developers can process images by calling corresponding functions, such as cv::Sobel(), cv::Canny(), cv::GaussianBlur(), etc.
[0047] However, OpenCV mainly runs on the CPU or DSP of electronic devices, which will occupy more computing resources, resulting in the performance of other tasks being affected. When the CPU or DSP resources are relatively tight, the speed of operator processing is also low, affecting the efficiency of operator processing.
[0048] To this end, in some embodiments, a hardware circuit or processor such as an IVE (Image Video Engine) may be designed to perform operator processing to improve the efficiency and performance of image processing tasks. For example, an ASIC (Application Specific Integrated Circuit) may be used to optimize a specific operator to improve the speed of operator processing.
[0049] However, designing hardware circuits or processors will increase the complexity and cost of electronic devices, such as increasing the chip area and chip logic design. In addition, due to the diversity of operators, the hardware circuits or processors designed for specific operators can only perform operator processing of specific operators, while operators not covered by the hardware circuits or processors cannot be executed, resulting in increased limitations on operator processing in electronic devices.
[0050] To this end, some embodiments of the present application provide a computer vision operator acceleration method based on NPU, which implements operator acceleration based on NPU (Neural Processing Unit) hardware and can be expressed as NPU-CV operator. Operator acceleration implemented by NPU hardware can not only improve the system resource shortage problem caused by porting OpenCV, but also improve the limitations of designing specific hardware circuits or processors, thereby improving the computational efficiency and applicability of operator processing in electronic devices.
[0051] like Figure 1 As shown, in some embodiments, the NPU may include multiple EU working units, each EU is responsible for different calculations, and each EU can perform calculations in parallel. Figure 1 In the DMA, DMA (Direct Memory Access) is responsible for data movement between the main memory such as RAM, and can read or write data directly from the main memory without CPU intervention, such as DMA-EU, DMA-EU is a specific version and identifier of DMA. DMA can be used to perform DMA read and write, indicating that DMA supports the function of reading and writing data from external storage; CCM (Color Correction Module) is used to adjust or optimize the color of the image; YUV format is a color encoding method, where Y represents the brightness component, and U and V represent the chrominance components; affine (affine transformation) is a two-dimensional coordinate transformation that can maintain the flatness of the image and is used for operations such as scaling, rotation, and translation.
[0052] Tesseract engine-EU is a module used to perform computing tasks. It can be used to perform DMA reading and writing, which means that DMA supports the functions of reading and writing data from external storage; tensor addition / subtraction / multiplication / division, which means basic mathematical operations on tensors such as multidimensional arrays; tensor transport, which is a mechanism for transmitting tensor data within the NPU or between other devices.
[0053] CV (Computer Vision) is used to handle computer vision-related tasks, such as image recognition, object detection, etc. CV-EU is a specific version and logo of CV. CV can be used to perform blend (color mixing); wrap is a boundary processing or data packaging technology used to handle edge cases of images or data; remap is used to rearrange or transform images or data.
[0054] Com (Communication) is responsible for the communication and data exchange between NPU and external devices or systems. Com-EU is a specific version and identifier of Com. Com can be used to perform conv1×1 and convN×M. Convolution operations are different forms of convolution operations. 1×1 convolution can be used to adjust the number of channels or the depth of feature maps, and N×M convolution can be used to extract features in space. Affine is a two-dimensional coordinate transformation that maintains the flatness of the image and is used for operations such as scaling, rotation, and translation.
[0055] The sync manager is a component used to ensure data synchronization and coordination between various modules within the NPU.
[0056] based on Figure 1 In the NPU architecture shown, in some embodiments, multiple EU working units can be configured inside the NPU, and each EU is responsible for different calculations, and each EU can calculate in parallel. In addition, each EU has the ability to independently read and write DDR and OCM (On-Chip Memory). For complex combinatorial operator calculations, multiple EU units need to be used in combination, and OCM can be used as a cache for intermediate data, where OCM has high bandwidth and low latency characteristics. When EUs calculate in parallel, there will be calculation timing and data dependencies, so a sync manager is needed to control the calculation timing of the EU.
[0057] It should be noted that Figure 1 The NPU architecture diagram shown exemplarily shows the various modules and functions inside the NPU, as well as the data flow and communication paths between the modules, but is not intended to limit them. The NPU may include more or fewer other modules or components.
[0058] like Figure 2 As shown, the NPU-based computer vision operator acceleration method provided in some embodiments of the present application may include the following steps:
[0059] S201: Receive a first configuration parameter.
[0060] In the embodiment of the present application, the CV operator implemented based on the NPU is represented as the target image operator, that is, the NPU-CV operator. The NPU-CV operator is configured in the NPU hardware, and the interface corresponding to the target image operator in the NPU hardware is represented as the first interface, and each first interface is aligned with the second interface corresponding to the computer vision operator. That is, one NPU-CV operator corresponds to one OpenCV software operator interface. In this way, the acceleration of the CV operator can be achieved through the NPU hardware.
[0061] The first configuration parameter is used to set the operation target of the target image operator, which is an external configuration parameter; the target image operator is a transformation function for execution in the neural processing unit, that is, a computer vision operator aligned with OpenCV. In some embodiments, the first configuration parameter may include at least one of an interpolation method, an alignment method, a scaling factor, a data storage address, and a convolution kernel of a filter operator.
[0062] S202: Convert the first configuration parameter into a second configuration parameter.
[0063] After receiving the first configuration parameter through the first interface of the NPU-CV operator, the first configuration parameter is converted into a second configuration parameter, wherein the second configuration parameter is a configuration parameter applicable to the neural processing unit, that is, a parameter applicable to the NPU.
[0064] like Figure 3 As shown, in some embodiments, the first configuration parameter may be parsed and checked to determine whether the first configuration parameter is legal and valid. That is, the data format of the first configuration parameter is parsed, and when the data format is the same as the preset template format, the data structure and / or data type of the first configuration parameter is modified through the first interface to generate the second configuration parameter. The second configuration parameter is then passed to the operator layer of the neural processing unit so that the operator layer generates the corresponding operation instruction according to the second configuration parameter.
[0065] In some embodiments, the template format can be used to determine whether the parameter format of the first configuration parameter is correct and complete, whether it complies with predefined parameter range or type requirements, and whether there are illegal values or unsupported configuration options.
[0066] In some embodiments, modifying the data structure and / or data type of the configuration parameter through the first interface may include: converting the parsed and verified first configuration parameter into a corresponding second parameter format according to the requirements of the NPU operator layer, that is, converting the external configuration parameter into the internal configuration parameter of the NPU. For example, data type conversion, such as from floating point to fixed point, etc.; data structure modification, such as organizing the parameters into a specific data structure that the NPU operator layer can understand, etc.
[0067] S203: Generate an operation instruction according to the second configuration parameter.
[0068] After converting the first configuration parameter into the second configuration parameter, a corresponding operation instruction is generated according to the second configuration parameter, wherein the generated operation instruction is an instruction required by the NPU hardware.
[0069] In some embodiments, when generating an operation instruction according to the second configuration parameter, Figure 4As shown, the tool chain application can be called by the operator layer of the neural processing unit to generate instruction code. The tool chain application is an application in the tool chain corresponding to the neural processing unit, and the instruction code can include at least one of the opcode field, the operand field, and the control bit field. The instruction code is then encapsulated to generate an operation instruction.
[0070] Exemplarily, the operator layer generates the operation instructions required by the NPU hardware by calling the online software of the NPU tool chain. In the process of generating the operation instructions, the operation instructions including fields such as operation code, operand, and control bit can be generated based on the specific implementation of the target image operator, the format and size of the input data, and the characteristics and limitations of the hardware. Among them, the operation code can be a field used to indicate the type of operation to be performed, the operand can be a field used to indicate the data or address of the specified operation, and the control bit can be a field used to control the behavior or status of the operation.
[0071] For combinatorial operators, in some embodiments, such as Figure 4 As shown, before generating the operation instruction, the operator type of the target image operator can also be detected. If the target image operator is a combination operator, the step of generating the instruction encoding by calling the tool chain application through the operator layer is executed, and the scheduling instruction of the target image operator is generated according to the preset scheduling logic, so that the operator layer schedules the order of the operation instructions according to the scheduling instruction. Among them, the combination operator is an image operator generated by splicing multiple neural network units. That is, the execution order of each operation instruction is also scheduled through the scheduling instruction.
[0072] For example, for a combination operator composed of multiple NPU hardware operators, you can use Figure 1 The hardware sync_manager or similar mechanism in the architecture shown controls the scheduling timing of the operation instructions to determine the correct synchronization and data transmission between the various operation instructions. The sync_manager scheduling timing corresponds to the NPU sync instruction. Among them, scheduling can be based on different strategies, such as static scheduling, which determines the execution order of the operation instructions at compile time; or dynamic scheduling, which dynamically adjusts the execution order of the operation instructions at runtime according to the hardware status and task requirements.
[0073] To facilitate identification, in some embodiments, it is possible to detect whether the operator type of the target image operator is a combination operator through description information or parameter configuration of the target image operator.
[0074] In some embodiments, the generated operation instructions may include operation instructions for tasks such as image processing, feature extraction, and target detection, and these operation instructions may be used for operations such as image scaling, rotation, filtering, and convolution. Alternatively, in some embodiments, the generated operation instructions may also include operation instructions for auxiliary operations such as data transmission, memory access, and control flow, and these operation instructions are used to ensure the correct operation of the NPU hardware.
[0075] S204: Constructing an inference model according to the operation instruction and the second configuration parameter.
[0076] After the corresponding operation instruction is generated according to the second configuration parameter, the operation instruction and the second configuration parameter can be packaged into an inference model, and the inference model is also represented as an NPU model in the embodiment of the present application. For example, the operation instruction and the second configuration parameter are packaged into a specific model file to construct the corresponding NPU model.
[0077] like Figure 5 As shown, in some embodiments, when constructing an inference model according to the operation instruction and the second configuration parameter, the operation instruction, the second configuration parameter, the operator layer parameters of the operator layer in the neural processing unit, and the associated parameters are packaged into a model file. Among them, the associated parameters include at least one of the activation function parameters, the optimization parameters, and the meta information of the inference model. Then, the inference model, i.e., the NPU model, is generated according to the model file.
[0078] For example, the optimization parameters may be quantization parameters, memory management parameters, etc.; the meta information may be the model version, generation time, creator, etc. The above parameters are packaged into the model file so that the NPU-CV operator can be correctly configured and executed when executed on the NPU hardware.
[0079] S205: Send the inference model to the neural processing unit so that the neural processing unit performs the inference task according to the inference model.
[0080] After the inference model is built, the inference model (NPU model) can be sent to the neural processing unit (NPU) for processing, so that the neural processing unit performs the corresponding inference task according to the inference model. For example, the NPU model can be sent to the NPU HW (Hardware) through the NPU inference engine for NPU inference.
[0081] In some embodiments, when sending the inference model to the neural processing unit, a model file of the inference model can be loaded, and then the model file is passed to the inference engine of the neural processing unit, and the model file is passed to the neural processing unit, i.e., NPU, through the inference engine.
[0082] S206: Save the context information of the neural processing unit performing the reasoning task, so that the target image operator performs image processing through the context information.
[0083] After the neural processing unit completes the inference, it returns the inference result to the first interface, which is the software interface of the NPU-CV operator. In some embodiments, the first interface is configured with context saving capability, and the context information of the inference model can be saved through the context saving capability of the neural processing unit, so that it can be directly loaded according to the context information in the future, without repeated calculations, thereby achieving the acceleration effect of the target image operator.
[0084] In some embodiments, the first interface may include a synchronous interface and an asynchronous interface to adapt to different scene requirements. In the subsequent use process, the saved context information can be loaded through the first interface, and the reasoning task can be performed according to the context information, thereby speeding up the processing speed of the target image operator.
[0085] Exemplarily, the NPU returns the result of the inference task to the upper-level software interface that calls it, that is, the first interface corresponding to the NPU-CV operator. The first interface can save these contexts for reuse in subsequent tasks, thereby saving computing resources and time. For example, if a task needs to use the same model or parameters multiple times, the saved context can be directly loaded in subsequent calls without recalculation or loading.
[0086] The first interface corresponding to the NPU-CV operator supports asynchronous and synchronous interfaces. Among them, the asynchronous interface allows the application to continue to perform other tasks while the NPU performs inference calculations. When the NPU completes the calculation, it will notify the application that the result is available through a callback function or other mechanism. The synchronous interface requires the application to wait for the NPU to complete the inference calculation before continuing to execute, which ensures that the inference result is obtained before continuing to execute subsequent tasks.
[0087] In some embodiments, the target image operator, i.e., the NPU-CV operator, can be co-scheduled and controlled with the offline model of the NPU without disrupting the normal reasoning of the NPU model. In this way, the NPU-CV operator can work in conjunction with the offline model pre-loaded into the NPU.
[0088] like Figure 6 As shown, the processing flow of the NPU-CV operator is as follows Figure 6The software interface of NPU-CV is the first interface, the NPU tool chain operator layer interface is used to transfer data to the operator layer, the NPU tool chain software is used to generate operation instructions and build the corresponding NPU model according to the operation instructions, the NPU inference engine is used to transfer data to the NPU hardware, and the NPU hardware is used to perform inference tasks.
[0089] According to the above-mentioned computer vision operator acceleration method, in some embodiments, the computer vision operator acceleration method provided in the embodiment of the present application can regard the NPU-CV operator as an NPU model for scheduling execution. By encapsulating the NPU-CV operator, exposing the necessary operator parameters to the outside, constructing the NPU-CV operator into an NPU model, and supporting the online NPU model construction to support the configuration and online generation of operator parameters. By porting the necessary parts of the NPU tool chain to the SDK (Software Development Kit), online model compilation is supported, and NPU instructions are generated to schedule the NPU hardware. The NPU-CV operator interface increases the context storage capability to adapt to the reuse of a single operator. The same operator and parameters do not need to be compiled repeatedly, which can reduce software overhead. The computer vision operator acceleration method provided in the embodiment of the present application has good portability and compatibility.
[0090] Based on the above-mentioned computer vision operator acceleration method, some embodiments of the present application also provide a computer vision operator acceleration system, which can be applied to execute the NPU-based computer vision operator acceleration system provided in the above-mentioned embodiment, such as Figure 7 As shown, the system includes a first interface 100, an operator processing unit 200 and a neural processing unit 300, wherein:
[0091] The first interface 100 is configured to: receive a first configuration parameter, the first configuration parameter is used to set the operation target of the target image operator, the target image operator is a transformation function for execution in the neural processing unit, and the first interface corresponding to the target image operator is aligned with the second interface corresponding to the computer vision operator; convert the first configuration parameter into a second configuration parameter, the second configuration parameter is a configuration parameter applicable to the neural processing unit. The first interface 100 is the software interface of the NPU-CV operator.
[0092] The operator processing unit 200 is configured to: generate an operation instruction according to the second configuration parameter; construct an inference model according to the operation instruction and the second configuration parameter; and send the inference model to the neural processing unit. The operator processing unit 200 includes an operator layer of the NPU and an NPU inference engine, etc.
[0093] The neural processing unit 300 performs the reasoning task according to the reasoning model and sends the reasoning task to the first interface so that the first interface saves the context information of the neural processing unit performing the reasoning task, and the context information is used to perform the image processing of the target image operator. The neural processing unit 300 is the NPU hardware.
[0094] Based on the above-mentioned computer vision operator acceleration method and computer vision operator acceleration system, some embodiments of the present application also provide an electronic device 500, which may include the above-mentioned computer vision operator acceleration system for executing the computer vision operator acceleration method.
[0095] In some embodiments, Figure 8 As shown, the electronic device 500 includes: at least one processor 501, at least one communication interface 502, at least one memory 503 and at least one bus 504. Among them, the bus 504 is used to realize the direct connection and communication of these components, the communication interface 502 is used to communicate signaling or data with other node devices, and the memory 503 stores computer program instructions that can be executed by the processor 501. When the electronic device 500 is running, the processor 501 communicates with the memory 503 through the bus 504, the processor 501 can call the computer program stored in the memory 503, and the execution of the computer program can realize the computer vision operator acceleration method provided in the embodiment of the present application.
[0096] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
[0097] For the convenience of explanation, the above description has been made in conjunction with specific embodiments. However, the above exemplary discussion is not intended to be exhaustive or limit the embodiments to the specific forms disclosed above. Based on the above teachings, various modifications and variations can be obtained. The selection and description of the above embodiments are to better explain the principles and practical applications, so that those skilled in the art can better use the embodiments and various different variations of the embodiments suitable for specific use considerations.
Claims
1. A computer vision operator acceleration method based on NPU, characterized in that: include: Receiving a first configuration parameter, the first configuration parameter being used to set an operation target of a target image operator, the target image operator being a transformation function for execution in a neural processing unit, a first interface corresponding to the target image operator being aligned with a second interface corresponding to the computer vision operator; Converting the first configuration parameter into a second configuration parameter, where the second configuration parameter is a configuration parameter applicable to the neural processing unit; generating an operation instruction according to the second configuration parameter; Building a reasoning model according to the operation instruction and the second configuration parameter; Sending the inference model to the neural processing unit so that the neural processing unit performs the inference task according to the inference model; The context information of the neural processing unit performing the reasoning task is saved so that the target image operator performs image processing through the context information.
2. The NPU-based computer vision operator acceleration method according to claim 1, characterized in that: The first configuration parameter includes at least one of an interpolation method, an alignment method, a scaling factor, a data storage address, and a convolution kernel of a filter operator.
3. The NPU-based computer vision operator acceleration method according to claim 1, characterized in that: The converting the first configuration parameter into a second configuration parameter comprises: Parsing the data format of the first configuration parameter; When the data format is the same as the preset template format, modifying the data structure and / or data type of the first configuration parameter through the first interface to generate the second configuration parameter; The second configuration parameter is passed to the operator layer of the neural processing unit so that the operator layer generates the operation instruction according to the second configuration parameter.
4. The NPU-based computer vision operator acceleration method according to claim 3, characterized in that: The generating an operation instruction according to the second configuration parameter includes: Generate instruction code by calling a tool chain application through the operator layer, where the tool chain application is an application of a tool chain corresponding to the neural processing unit, and the instruction code includes at least one of an opcode field, an operand field, and a control bit field; The instruction code is encapsulated to generate the operation instruction.
5. The NPU-based computer vision operator acceleration method according to claim 4, characterized in that: Before the operator layer calls the tool chain application to generate instruction code, it also includes: Detecting an operator type of the target image operator; If the target image operator is a combination operator, execute the step of calling the tool chain application to generate instruction code through the operator layer, and generate scheduling instructions for the target image operator according to the preset scheduling logic, so that the operator layer schedules the order of the operation instructions according to the scheduling instructions; the combination operator is an image operator generated by splicing multiple neural network units.
6. The NPU-based computer vision operator acceleration method according to claim 1, characterized in that: The constructing the inference model according to the operation instruction and the second configuration parameter includes: Packing the operation instruction, the second configuration parameter, the operator layer parameters of the operator layer in the neural processing unit, and associated parameters into a model file, wherein the associated parameters include at least one of an activation function parameter, an optimization parameter, and meta information of the inference model; The inference model is generated according to the model file.
7. The NPU-based computer vision operator acceleration method according to claim 1, characterized in that: The sending the inference model to the neural processing unit includes: Loading a model file of the inference model; passing the model file to an inference engine of the neural processing unit; The model file is passed to the neural processing unit through the inference engine.
8. The NPU-based computer vision operator acceleration method according to claim 1, characterized in that: The first interface includes a synchronous interface and an asynchronous interface, and the method further includes: loading the context information through the first interface; The reasoning task is performed according to the context information to speed up the processing speed of the target image operator.
9. A computer vision operator acceleration system based on NPU, characterized in that: include: A first interface configured to receive a first configuration parameter, the first configuration parameter being used to set an operation target of a target image operator, the target image operator being a transformation function for execution in a neural processing unit, the first interface corresponding to the target image operator being aligned with the second interface corresponding to the computer vision operator; Converting the first configuration parameter into a second configuration parameter, where the second configuration parameter is a configuration parameter applicable to the neural processing unit; An operator processing unit is configured to generate an operation instruction according to the second configuration parameter; construct an inference model according to the operation instruction and the second configuration parameter; and send the inference model to the neural processing unit; A neural processing unit is configured to perform reasoning tasks according to the reasoning model and send the reasoning tasks to the first interface so that the first interface saves context information of the neural processing unit performing the reasoning tasks, and the context information is used to perform image processing of the target image operator.
10. An electronic device, characterized in that: Includes processor, memory and bus; The processor and the memory are communicatively connected via the bus; The memory stores computer program instructions executable by the processor, the processor being configured to: Receiving a first configuration parameter, the first configuration parameter being used to set an operation target of a target image operator, the target image operator being a transformation function for execution in a neural processing unit, a first interface corresponding to the target image operator being aligned with a second interface corresponding to the computer vision operator; Converting the first configuration parameter into a second configuration parameter, where the second configuration parameter is a configuration parameter applicable to the neural processing unit; generating an operation instruction according to the second configuration parameter; Building a reasoning model according to the operation instruction and the second configuration parameter; Sending the inference model to the neural processing unit so that the neural processing unit performs the inference task according to the inference model; The context information of the neural processing unit performing the reasoning task is saved so that the target image operator performs image processing through the context information.
Citation Information
Patent Citations
Device and method for realizing data synchronization in neural network inference
CN113169989A
Neural network algorithm task compiling and executing method, chip and electronic equipment
CN116010049A
