A matrix image memory management optimization method, system, terminal and medium
Through the registration interface mechanism and conversion function generation, the problem of image memory management differences between different application platforms is solved, fast and efficient platform transplantation and memory management are achieved, the development difficulty and error rate are reduced, and the reliability and reliability of the system are improved. Memory safety.
Patent Information
- Application Number
- CN202410895307.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-05
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2044-07-05
AI Technical Summary
In the existing technology, the image memory management structures provided by various manufacturers are different, which leads to the need for multiple program development when converting images between different application platforms, and frequent underlying development is required as demand changes over time, which increases the development difficulty and error rate. .
Provides a matrix image memory management optimization method. Through the registration interface mechanism, a conversion function is generated to realize matrix image memory management between different application platforms, isolate the coupling relationship between the bottom layer and the application, provide a unified development structure, and simplify platform transplantation and structure. Convert.
It achieves fast and efficient platform transplantation, reduces the possibility of structural conversion, ensures the correct acquisition and release of resources, and improves system reliability and memory security.
Smart Images

Figure CN118426978B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer applications, and more specifically, to a matrix image memory management optimization method, system, terminal and medium. Background Art
[0002] Currently, SOCs (system-on-chip) for image processing will provide hard cores for image processing such as VPU (Video Processing Unit) / MPP (Media Processing Platform), and provide corresponding SDKs (software development kits) for developers to use.
[0003] However, different manufacturers and even the same manufacturer provide different image memory management structures for different hard cores. When converting images between application platforms, it is necessary to develop a program for image conversion between two application platforms. When one application platform has multiple conversion requirements with multiple other application platforms, multiple program developments are required. In addition, when a new application platform is added to a system, the conversion requirements between the application platforms may change over time. If the requirements increase, the underlying layer needs to be redeveloped, which increases the difficulty of development and the chance of errors.
[0004] Therefore, how to study and design a matrix image memory management optimization method, system, terminal and medium that can overcome the above-mentioned defects is a problem that we urgently need to solve. Summary of the invention
[0005] To address the deficiencies in the prior art, the present invention aims to provide a matrix image memory management optimization method, system, terminal and medium, provide a registration mechanism for converting various image memory management structures to a registration interface, register different conversion methods for different structures, provide a unified structure for users to develop, quickly and efficiently transplant the platform, and isolate the coupling relationship between the bottom layer and the application, greatly simplify the use learning cost, and reduce the possibility of processing structure conversion.
[0006] The above technical objectives of the present invention are achieved through the following technical solutions:
[0007] In a first aspect, a matrix image memory management optimization method is provided, comprising the following steps:
[0008] Obtaining a registration request sent by an unregistered application platform, the registration request including an image description structure and an image memory operation program;
[0009] Filter out the first information that is the same description object as the standard description structure in the mat class from the image description structure, and the remaining information in the image description structure is the second information;
[0010] Generate a conversion function according to the conversion logic between the first information and the standard description structure, and save the conversion function in the mat class;
[0011] Using the second information as an information header of the image memory operation program, and registering the information header and the image memory operation program as a registration interface corresponding to the unregistered application platform;
[0012] Matrix image memory management between different application platforms is achieved by calling the registration interface and the corresponding associated conversion functions.
[0013] Furthermore, the standard description structure includes the image data memory address, image width and height, channel interval length, image format, element width and number of channels;
[0014] The image data memory address includes at least one of a channel physical address and a channel virtual address.
[0015] Furthermore, the channel physical address records the value of the physical address of the channel, and the channel virtual address records the pointer of the virtual address of the channel;
[0016] The image width and height include the number of channel rows and the number of channel columns; the number of channel rows records the number of rows of the channel image, and its value is equal to the image height; the number of channel columns records the number of columns of the channel image, and its value is equal to the image element width;
[0017] The channel interval length records the actual byte width of the channel;
[0018] The image format record describes the definition of the image format;
[0019] The element width records the byte width of a single pixel element of the channel;
[0020] And, the number of channels records the number of channels of a single image.
[0021] Furthermore, the information header reserves variable-length user data and a user data release procedure for registration;
[0022] The release process of the user data is specifically as follows:
[0023] Use the friend class to access the reserved pointer in the matrix image memory management method class and apply for space for empty user data when registering;
[0024] Using the smart pointer feature, register the release procedure when the user data is created;
[0025] Also, when the image memory is released, the registered release procedure is called and the requested user data space is released.
[0026] Furthermore, the conversion function is saved using a global key-value pair, and the key value is queried to call the conversion function when used;
[0027] And, the key-value pairs that save the conversion functions are managed using a hash tree.
[0028] Furthermore, the method also includes:
[0029] Determine the memory usage coefficient of each description object in the corresponding information header according to the ratio of the actual memory usage of the information header in each registration interface to the initial allocated memory;
[0030] Determine the distribution of the same description object in all image description structures, and calculate the conversion priority value of the corresponding description object in combination with the memory usage coefficient;
[0031] If the conversion priority value is greater than or equal to the preset threshold, the corresponding description object is written into the standard description structure to implement the update of the standard description structure, and the information headers in each image description structure are updated synchronously.
[0032] Furthermore, the calculation formula of the conversion priority value is specifically:
[0033] ;
[0034] in, Represents the description object The conversion priority value of Indicates that all registered interfaces contain description objects The number of corresponding information headers; Indicates the total number of registered interfaces; Indicates The memory usage coefficient of each description object in the information header; Indicates The memory usage coefficient of each description object in the information header; Indicates The actual memory occupied by each information header; Indicates Initial allocation of memory for each header.
[0035] In a second aspect, a matrix image memory management optimization system is provided, the system is used to implement a matrix image memory management optimization method as described in any one of the first aspects, including:
[0036] A registration receiving module is used to obtain a registration request sent by an unregistered application platform, wherein the registration request includes an image description structure and an image memory operation program;
[0037] An information screening module is used to screen out first information that is the same description object as the standard description structure in the mat class from the image description structure, and the remaining information in the image description structure is the second information;
[0038] A function generation module, used for generating a conversion function according to the conversion logic between the first information and the standard description structure, and saving the conversion function in a mat class;
[0039] An interface registration module, used to use the second information as an information header of the image memory operation program, and register the information header and the image memory operation program as a registration interface corresponding to the unregistered application platform;
[0040] The image conversion module is used to implement matrix image memory management between different application platforms by calling the registration interface and the corresponding associated conversion function.
[0041] In a third aspect, a computer terminal is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, a matrix image memory management optimization method as described in any one of the first aspects is implemented.
[0042] In a fourth aspect, a computer-readable medium is provided, on which a computer program is stored, and the computer program is executed by a processor to implement a matrix image memory management optimization method as described in any one of the first aspects.
[0043] Compared with the prior art, the present invention has the following beneficial effects:
[0044] 1. The present invention provides a matrix image memory management optimization method, which provides a registration mechanism for converting various image memory management structures to a registration interface. Different conversion methods can be registered for different structures, providing users with a unified structure for development, which can quickly and efficiently transplant the platform and isolate the coupling relationship between the bottom layer and the application, greatly simplifying the use learning cost and reducing the possibility of processing structure conversion;
[0045] 2. In the present invention, when a new structure is added, compared with the prior art which needs to provide N conversion methods (N is the number of original structures), each structure only needs to register its corresponding conversion method once to achieve conversion to all registered structures;
[0046] 3. The present invention uses the conversion function and registration interface stored in mat to query and call the method registered by mat class to complete the memory management of matrix image when obtaining other structures, completes the isolation of user interface to platform-related structures, applies for and manages memory when creating or setting, and releases memory when destroying, thereby ensuring the correct acquisition and release of resources, avoiding resource leakage caused by manual management, and greatly improving reliability;
[0047] 4. Compared with the previous one structure and one memory release method corresponding to one set of interfaces, the present invention always maintains a unified interface and ensures memory security;
[0048] 5. The present invention reserves user data of variable length that can be registered in the information header, which can flexibly realize differentiated conversion between different structures, and dynamically updates the standard description structure in the mat class according to the distribution of each description object in all information headers and the occupancy of user data in the information header, so that the application space of user data in the information header is relatively stable. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] The drawings described herein are used to provide a further understanding of the embodiments of the present invention, constitute a part of this application, and do not constitute a limitation of the embodiments of the present invention. In the drawings:
[0050] Figure 1 is a flow chart of Embodiment 1 of the present invention;
[0051] Figure 2 It is a system block diagram in Example 2 of the present invention. DETAILED DESCRIPTION
[0052] In order to make the objectives, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with embodiments and drawings. The exemplary embodiments of the present invention and their description are only used to explain the present invention and are not intended to limit the present invention.
[0053] Embodiment 1: A matrix image memory management optimization method, such as Figure 1 As shown, the following steps are included:
[0054] S1: Obtain a registration request sent by an unregistered application platform, the registration request including an image description structure and an image memory operation program;
[0055] S2: Filter out the first information that is the same description object as the standard description structure in the mat class (a class for processing or representing matrices) from the image description structure, and the remaining information in the image description structure is the second information;
[0056] S3: Generate a conversion function according to the conversion logic between the first information and the standard description structure, and save the conversion function in the mat class;
[0057] S4: using the second information as an information header of the image memory operation program, and registering the information header and the image memory operation program as a registration interface corresponding to the unregistered application platform;
[0058] S5: Implement matrix image memory management between different application platforms by calling the registration interface and the corresponding associated conversion function.
[0059] It should be noted that the standard description structure includes but is not limited to the image data memory address, image width and height, channel interval length, image format, element width and number of channels. Among them, the image data memory address includes at least one of the channel physical address and the channel virtual address. An image may have multiple channels, and the multiple channels may not be continuous, so they are abstracted as channel addresses and saved in an array. The channel physical address can be empty because the real channel physical address may not be obtained in some systems (it may not exist), and the channel virtual address may not exist. In some scenarios, the virtual address is not required, but one of the two must be present.
[0060] Specifically, the channel physical address records the value of the physical address of the channel, and the channel virtual address records the pointer to the virtual address of the channel; the image width and height include the number of channel rows and the number of channel columns; the number of channel rows records the number of rows of the channel image, and its value is equal to the image height; the number of channel columns records the number of columns of the channel image, and its value is equal to the image element width; the channel interval length records the actual byte width of the channel; the image format records the definition of the image format; the element width records the byte width of a single pixel element of the channel; and the number of channels records the number of channels of a single image.
[0061] In addition, the standard description structure can also include information such as channel size, empty flag, and total memory. The channel size records the total length of the channel, the empty flag records whether the image is empty, and the total memory records the memory size occupied by the entire image.
[0062] Taking the HiSilicon chip HI3559AV100 as an example, in the SDK it provides, there is an image description structure VIDEO_FRAME_S used inside the MPP subsystem to describe the image structure as follows: 1. Image width, recorded as: u32Width; 2. Image height, recorded as: u32Height; 3. Image format, recorded as: enPixelFormat, supporting many image formats; 4. Video domain, recorded as: enField; 5. Video format, recorded as: enVideoFormat; 6. Compression format, recorded as: enCompressMode; 7. Dynamic range, recorded as: enDynamicRange; 8. Image header channel information; 9. Channel physical address, recorded as: u64PhyAddr; 10. Channel virtual address, recorded as: u64VirAddr; 11. Channel interval length, recorded as: u32Stride; 12. Image recording time, recorded as u32TimeRef.
[0063] In its ive system, the image description structure is IVE_IMAGE_S, and the required structure is: 1. Channel physical address, recorded as: au64PhyAddr; 2. Channel virtual address, recorded as: au64VirAddr; 3. Channel interval length, recorded as: au32Stride; 4. Image width, recorded as: u32Width; 5. Image height, recorded as: u32Height; 6. Image format, recorded as: enType, only a small number of image formats are supported.
[0064] There are other structures that are similar, and each structure adds additional information to itself for its own system to implement its own functions.
[0065] In this embodiment, the information header reserves variable-length user data and a release program for the user data, and the registration elements of the release program include: a) data length: specified data length; b) user data: user data itself; c) release method: a release method using user data.
[0066] The specific process of releasing user data is as follows: using the friend class to access the reserved pointer in the matrix image memory management method class, and applying for space for empty user data when registering; using the smart pointer feature to register a release program when user data is created; and, calling the registered release program when the image memory is released, and releasing the applied user data space, to achieve fully automatic release and avoid memory leaks caused by manual release.
[0067] In this embodiment, the conversion function is saved using a global key-value pair. When used, the key value is queried to call the conversion function. The key-value pair that saves the conversion function is managed using a hash tree to minimize the time loss caused by the query.
[0068] In order to make the application space of user data in the information header relatively stable, a matrix image memory management optimization method recorded in the present invention also includes the following steps: determining the memory usage coefficient of each description object in the corresponding information header according to the ratio of the actual occupied memory of the information header in each registration interface to the initial allocated memory; determining the distribution of the same description object in all image description structures, and calculating the conversion priority value of the corresponding description object in combination with the memory usage coefficient; if the conversion priority value is greater than or equal to a preset threshold, writing the corresponding description object into the standard description structure to implement the update of the standard description structure, and synchronously updating the information headers in each image description structure.
[0069] In this embodiment, the calculation formula of the conversion priority value is specifically:
[0070] ;
[0071] in, Represents the description object The conversion priority value of Indicates that all registered interfaces contain description objects The number of corresponding information headers; Indicates the total number of registered interfaces; Indicates The memory usage coefficient of each description object in the information header; Indicates The memory usage coefficient of each description object in the information header; Indicates The actual memory occupied by each information header; Indicates Initial allocation of memory for each header.
[0072] The present invention can be applied to embedded platforms, and its purpose is to provide a more convenient transplantation interface, so that the application program is isolated from the bottom layer, and a registration interface (memory management, structure conversion, user data storage) is provided to the bottom layer, while a unified and unchanged interface (obtaining image information) is provided to the application layer. In this way, when facing different chips and different development platforms, the user only needs to register the bottom layer interface according to the rules with the registration interface provided by the design to run the original application, thereby reducing the development cycle and the workload caused by platform transplantation.
[0073] Embodiment 2: A matrix image memory management optimization system, the system is used to implement a matrix image memory management optimization method as described in Embodiment 1, such as Figure 2 As shown, it includes a registration receiving module, an information screening module, a function generating module, an interface registration module and an image conversion module.
[0074] Among them, the registration receiving module is used to obtain the registration request sent by the unregistered application platform, and the registration request includes an image description structure and an image memory operation program; the information screening module is used to screen out the first information that is the same description object as the standard description structure in the mat class from the image description structure, and the remaining information in the image description structure is the second information; the function generation module is used to generate a conversion function according to the conversion logic between the first information and the standard description structure, and save the conversion function in the mat class; the interface registration module is used to use the second information as the information header of the image memory operation program, and register the information header and the image memory operation program as the registration interface corresponding to the unregistered application platform; the image conversion module is used to realize the matrix image memory management between different application platforms by calling the registration interface and the corresponding associated conversion function.
[0075] The present invention also describes a computer terminal, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, a matrix image memory management optimization method as described in Example 1 is implemented.
[0076] The present invention also describes a computer-readable medium on which a computer program is stored. The computer program is executed by a processor to implement a matrix image memory management optimization method as described in Example 1.
[0077] Working principle: The present invention provides a registration mechanism for converting various image memory management structures to a registration interface. Different conversion methods can be registered for different structures, and a unified structure is provided for users to develop. The platform can be transplanted quickly and efficiently, and the coupling relationship between the bottom layer and the application is isolated, which greatly simplifies the use and learning cost and reduces the possibility of processing structure conversion. In addition, when a new structure is added in the present invention, compared with the need to provide N types (N is the number of original structures) of conversion methods in the prior art, each structure only needs to register its corresponding conversion method once to achieve conversion to all registered structures. In addition, the present invention uses the conversion function and registration interface stored in mat, queries and calls the method registered by the mat class when obtaining other structures to complete the matrix image memory management, completes the isolation of the user interface to the platform-related structure, applies for and manages memory when creating or setting, and releases memory when destroying, thereby ensuring the correct acquisition and release of resources, avoiding resource leakage caused by manual management, and greatly improving reliability.
[0078] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0079] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1A device that provides the functions specified in a block or multiple blocks.
[0080] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0081] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0082] The specific implementation methods described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific implementation method of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A matrix image memory management optimization method, characterized in that: The following steps are involved: Obtaining a registration request sent by an unregistered application platform, the registration request including an image description structure and an image memory operation program; Filter out the first information having the same description object as the standard description structure in the mat class from the image description structure, and the remaining information in the image description structure is the second information; Generate a conversion function according to the conversion logic between the first information and the standard description structure, and save the conversion function in the mat class; Using the second information as an information header of the image memory operation program, and registering the information header and the image memory operation program as a registration interface corresponding to the unregistered application platform; Matrix image memory management between different application platforms is achieved by calling the registration interface and the corresponding associated conversion functions.
2. A matrix image memory management optimization method according to claim 1, characterized in that: The standard description structure includes the image data memory address, image width and height, channel interval length, image format, element width and number of channels; The image data memory address includes at least one of a channel physical address and a channel virtual address.
3. A matrix image memory management optimization method according to claim 2, characterized in that: The channel physical address records the value of the physical address of the channel, and the channel virtual address records the pointer of the virtual address of the channel; The image width and height include the number of channel rows and the number of channel columns; the number of channel rows records the number of rows of the channel image, and its value is equal to the image height; the number of channel columns records the number of columns of the channel image, and its value is equal to the image element width; The channel interval length records the actual byte width of the channel; The image format record describes the definition of the image format; The element width records the byte width of a single pixel element of the channel; And, the number of channels records the number of channels of a single image.
4. A matrix image memory management optimization method according to claim 1, characterized in that: The information header reserves variable-length user data and a user data release program for registration; The release process of the user data is specifically as follows: Use the friend class to access the reserved pointer in the matrix image memory management method class and apply for space for empty user data when registering; Using the smart pointer feature, register the release procedure when the user data is created; Also, when the image memory is released, the registered release procedure is called and the requested user data space is released.
5. A matrix image memory management optimization method according to claim 1, characterized in that: The conversion function is saved using a global key-value pair, and the key value is queried to call the conversion function when used; And, the key-value pairs that save the conversion functions are managed using a hash tree.
6. A matrix image memory management optimization method according to claim 1, characterized in that: The method further includes: Determine the memory usage coefficient of each description object in the corresponding information header according to the ratio of the actual memory usage of the information header in each registration interface to the initial allocated memory; Determine the distribution of the same description object in all image description structures, and calculate the conversion priority value of the corresponding description object in combination with the memory usage coefficient; If the conversion priority value is greater than or equal to the preset threshold, the corresponding description object is written into the standard description structure to implement the update of the standard description structure, and the information headers in each image description structure are updated synchronously.
7. A matrix image memory management optimization method according to claim 6, characterized in that: The calculation formula of the conversion priority value is specifically: Among them, D a Indicates the conversion priority value of description object a; n indicates the number of information headers corresponding to description object a in all registered interfaces; N indicates the total number of registered interfaces; K i K represents the memory usage coefficient of each description object in the i-th information header; j Indicates the memory usage coefficient of each description object in the jth information header; M i,s Indicates the actual memory occupied by the i-th information header; M i,f Represents the initial allocated memory for the i-th information header.
8. A matrix image memory management optimization system, characterized in that: The system is used to implement a matrix image memory management optimization method as described in any one of claims 1 to 7, comprising: A registration receiving module is used to obtain a registration request sent by an unregistered application platform, wherein the registration request includes an image description structure and an image memory operation program; An information screening module is used to screen out first information having the same description object as the standard description structure in the mat class from the image description structure, and the remaining information in the image description structure is the second information; A function generation module, used for generating a conversion function according to the conversion logic between the first information and the standard description structure, and saving the conversion function in a mat class; An interface registration module, used to use the second information as an information header of the image memory operation program, and register the information header and the image memory operation program as a registration interface corresponding to the unregistered application platform; The image conversion module is used to implement matrix image memory management between different application platforms by calling the registration interface and the corresponding associated conversion function.
9. A computer terminal comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the matrix image memory management optimization method as described in any one of claims 1 to 7 is implemented.
10. A computer readable medium having a computer program stored thereon, characterized in that: The computer program is executed by a processor to implement a matrix image memory management optimization method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Data conversion method and device, equipment and storage medium
CN111382556A
Unified management method and system for multiple types of registration centers of cloud native platform
CN116016667A
Multi-source data service REST API interface construction method and device
CN116048991A
Concise configuration type rest interface management and message conversion method and device
CN116627486A
Method and system for automatically adapting and converting API (Application Program Interface) message format
CN117555957A
