GPU memory release method and related device
By adjusting the GPU memory release ratio according to the image size and application status of the texture resource, the problem of not being able to effectively reduce GPU memory footprint in the existing technology is solved, and efficient GPU rendering and memory management are achieved.
Patent Information
- Application Number
- CN202311063459.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-22
- Publication Date
- 2025-02-25
Smart Images

Figure CN119515657A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the computer field, and in particular to a GPU memory release method and related devices. Background Art
[0002] A graphics processing unit (GPU) is a dedicated microprocessor that can perform graphics operations. The GPU can generate two-dimensional or three-dimensional graphics images and videos, thereby supporting window-based operating systems, graphical user interfaces, video games, visual image applications, video playback, etc. Summary of the invention
[0003] The present application provides a GPU memory release method and related devices, which realizes that when releasing the texture resources of an application, the release amount of texture resources of different sizes is determined according to the size of the texture resources, ensuring that the GPU memory occupied by the application is reduced as much as possible while meeting the rendering requirements.
[0004] In a first aspect, the present application provides a GPU memory release method, the method comprising: an electronic device switches a first application from the foreground to the background; the electronic device releases part of the texture resources of the first application according to the image size of the texture resources of the first application cached in the GPU memory, wherein the texture resources of the first application include a first texture resource and a second texture resource, the image size of the first texture resource is smaller than the image size of the second texture resource, and the release amount of the first texture resource is greater than the release amount of the second texture resource.
[0005] By implementing the method provided in the first aspect, the release ratio of texture resources of different sizes can be flexibly adjusted according to the image size of the texture resources cached in the GPU memory by the first application. A larger release ratio can be selected for cached small-sized texture resources. In this way, even if the GPU needs to re-render these small-sized texture resources, it will not take too much time. For cached large-sized texture resources, a smaller release ratio can be selected. In this way, the GPU can be prevented from re-rendering these large-sized image textures as much as possible, which would waste too much time. The cached texture resources can be directly used to ensure the efficiency of GPU rendering as much as possible, and reduce the impact of GPU resource cleaning on GPU rendering.
[0006] In combination with the first aspect, in one implementation, after the electronic device switches the first application from the foreground to the background, the amount of data released by the texture resources of the first application when the first application has background activities is less than the amount of data released when the first application has no background activities.
[0007] In other words, the amount of texture resources released for an application can be determined based on whether the application has background activities, so that the application can run smoothly as much as possible when there are background activities, and the memory size occupied by the application in the GPU can be reduced as much as possible when there are no background activities.
[0008] In combination with the first aspect, in one implementation, after the electronic device switches the first application from the foreground to the background, the less free memory in the GPU memory, the more texture resources of the first application released by the electronic device.
[0009] In other words, the amount of texture resources released for an application can be determined based on the memory pressure of the GPU. When the memory pressure of the GPU is high, the memory pressure of the GPU can be alleviated by releasing the texture resources of the first application. When the memory pressure of the GPU is low, the rendering efficiency of the application can be guaranteed as much as possible.
[0010] In combination with the first aspect, in one implementation, a ratio of a release amount of the first texture resource to a release amount of the second texture resource is equal to a ratio of a hard decoding time corresponding to the second texture resource to a hard decoding time corresponding to the first texture resource.
[0011] It can be seen that the electronic device can accurately calculate the release ratio of texture resources of different sizes through the hard decoding time corresponding to the texture resources.
[0012] In combination with the first aspect, in one implementation, the method further includes: the electronic device closing the first application; and the electronic device releasing all texture resources of the first application cached in the CPU memory.
[0013] In other words, after the application is closed, all the resources cached by the application in the GPU memory can be cleared, thereby improving the utilization of the GPU memory.
[0014] In combination with the first aspect, in one implementation, after the electronic device switches the first application from the foreground to the background, the method further includes: the electronic device releases the font resources and shader resources of the first application cached in the GPU memory.
[0015] That is, after the application switches from the foreground to the background, in addition to releasing texture resources, other resources cached by the application can also be released.
[0016] In combination with the first aspect, in one implementation, when the electronic device releases the texture resources of the first application, it preferentially releases the texture resources with the lowest probability of being used when the electronic device runs the first application in the foreground again.
[0017] Prioritizing the release of texture resources with a lower probability of use can avoid the need to recalculate the texture resources required for GPU rendering when the application returns to the foreground, thereby shortening the application rendering time as much as possible.
[0018] In combination with the first aspect, in one implementation, before the electronic device switches the first application from the foreground to the background, the method further includes: the electronic device detects a first operation, and the first operation is used to trigger switching the first application to the background.
[0019] In a second aspect, an embodiment of the present application provides an electronic device, comprising a memory, one or more processors, and one or more programs; when the one or more processors execute the one or more programs, the electronic device implements the method described in the first aspect or any one of the implementation methods in the first aspect.
[0020] In a third aspect, an embodiment of the present application provides a computer-readable storage medium, comprising instructions, which, when executed on an electronic device, causes the electronic device to execute a method as described in the first aspect or any one of the implementations of the first aspect.
[0021] In a fourth aspect, an embodiment of the present application provides a computer program product. When the computer program product runs on a computer, it enables the computer to execute the method described in the first aspect or any one of the implementations of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 This is a schematic diagram of the GPU rendering pipeline during the rendering process;
[0023] Figure 2 A schematic diagram of GPU memory release during the operation of a video playback application provided in an embodiment of the present application;
[0024] Figure 3 A flowchart of a GPU memory release method provided in an embodiment of the present application;
[0025] Figure 4 A schematic diagram of the total recovery rate of the application under different conditions provided in the embodiment of the present application;
[0026] Figure 5 A schematic diagram of the hardware structure of an electronic device 100 provided in an embodiment of the present application;
[0027] Figure 6 It is a software structure block diagram of the electronic device 100 according to an embodiment of the present application. DETAILED DESCRIPTION
[0028] The technical solutions in the embodiments of the present application will be described clearly and in detail below in conjunction with the accompanying drawings. In the description of the embodiments of the present application, unless otherwise specified, " / " means or, for example, A / B can mean A or B; "and / or" in the text is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, "multiple" means two or more than two.
[0029] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as suggesting or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features, and in the description of the embodiments of the present application, unless otherwise specified, "plurality" means two or more.
[0030] Rendering is the process of converting shapes stored in computer memory into corresponding patterns actually drawn on the display screen. GPU plays a very important role in image rendering.
[0031] Figure 1 This is a schematic diagram of the GPU rendering pipeline during the rendering process.
[0032] like Figure 1 As shown in the figure, when the current page of the application needs to change, the relevant data (including data downloaded from the network) will be loaded. After the data is loaded, part of the data will be sent by the central processor unit (CPU) to the GPU for processing, including shader compilation, font decoding, image decoding, etc., so as to calculate the GPU resources required for rendering. Finally, the GPU sends the rendered data to the display to realize the display of the changed application page.
[0033] However, if the page is displayed in the above manner every time a page changes, the rendering time will increase. Therefore, some resources used for GPU rendering are generally cached, where the GPU cached resources may include: shader resources, font resources, texture resources, etc. The next time rendering is performed, the cached GPU resources can be used directly, thereby reducing the rendering time, but at the same time, the cached GPU resources will take up a lot of storage space.
[0034] To prevent GPU resources from occupying storage space all the time, there are two levels of GPU memory release after the application goes to the background: the first is for applications that still have background activities after going to the background, the system will release about 50% of the font resources and texture resources cached by the application; the second is for applications that have no background activities after going to the background. When the memory pressure of the entire machine is high, the resources cached in the GPU memory of the application will be cleared.
[0035] For example, Figure 2 Taking a video playback application as an example, a schematic diagram of GPU memory release during the running of the video playback application is shown.
[0036] like Figure 2 As shown, after the video playback application switches from foreground operation to background operation, it will trigger the release of the GPU resources cached by the application. When the application has just switched from the foreground to the background and is in background playback, background pause, or other running states, the application has the above-mentioned first level of GPU memory release: releasing 50% of the font resources and texture resources. If the application is in the background paused running state for more than a certain period of time, the application is in the above-mentioned second level of GPU memory release: clearing the GPU resources of the application.
[0037] It can be seen that the GPU memory release method only mentions releasing a fixed proportion of GPU resources, or releasing all of them, and cannot flexibly release GPU memory.
[0038] The embodiment of the present application provides a GPU memory release method, which can release part of the texture resources cached by the application according to the image size of the texture resources of the application cached in the GPU resources when the application switches from the foreground to the background and needs to clean up the GPU resources of the application. The amount of texture resources of small size released can be greater than the amount of texture resources of large size released.
[0039] Considering that the image size of texture resources is related to decoding performance, generally speaking, small-sized texture resources have higher hard decoding performance. In other words, the GPU spends less time rendering small-sized texture resources, while large-sized texture resources have lower hard decoding performance. In other words, the GPU spends more time rendering large-sized texture resources. Therefore, for cached small-sized texture resources, a larger release ratio can be selected, so that even if the GPU needs to re-render these small-sized texture resources, it will not take too much time. For cached large-sized texture resources, a smaller release ratio can be selected, so that the GPU can be prevented from re-rendering these large-sized image textures as much as possible, which would waste too much time, and the cached texture resources can be used directly.
[0040] It can be seen that the GPU memory release method provided in the embodiment of the present application fully considers the impact of the image size of texture resources on GPU rendering, and flexibly adjusts the release ratio of texture resources of different sizes when releasing GPU memory resources according to the size of texture resources. While releasing the GPU memory, the efficiency of GPU rendering is guaranteed as much as possible, and the impact of GPU resource cleaning on GPU rendering is reduced, thereby ensuring the smoothness of application operation while reducing the memory size occupied by the cache resources of the application in the GPU as much as possible.
[0041] Figure 3 A flowchart of a GPU memory release method provided in an embodiment of the present application.
[0042] like Figure 3 As shown, the GPU memory release method provided in the embodiment of the present application may include the following steps:
[0043] S101. The electronic device 100 switches the first application from the foreground to the background.
[0044] From the user's perspective, foreground operation means that the electronic device 100 runs an application, and the user interface of the application is visible to the user, that is, the user can view the user interface of the application through the display screen of the electronic device 100, and the user can interact with the application. For example, for a music application running in the foreground, the user can view the music playlist by browsing to the user interface of the music application. Background operation means that the electronic device 100 runs an application, and the user interface of the application is invisible to the user, that is, the user cannot view the user interface of the application through the display screen of the electronic device 100, and the user cannot interact with the application. For example, for a music application running in the background, the user cannot view the user interface of the music application, but can hear the music played by the music application.
[0045] From the perspective of the device, the process-related parameters of the first application can be used to determine whether the application is running in the foreground or in the background. Exemplarily, the process priority value ADJ of the first application can be used to determine whether the application is running in the foreground or in the background. For example, if ADJ≤100, the first application is in the foreground running state, and if ADJ≥900, the first application is in the background running state. Therefore, it can be determined whether the first application switches from the foreground to the background by judging whether ADJ is greater than or equal to 900.
[0046] Exemplarily, the electronic device 100 may trigger the switching of the first application from the foreground to the background after detecting the user's operation (e.g., the first operation) on the first application. For example, during the process of the electronic device 100 displaying the user interface of the first application, if the electronic device 100 detects an operation of sliding up on the user interface, in response to the operation, the electronic device 100 may switch from the user interface of the first application to the desktop, and at the same time switch the first application from the foreground to the background.
[0047] After the first application is switched to the background, the electronic device 100 no longer displays the user interface of the first application, that is, the electronic device 100 no longer needs to render the relevant display content of the first application in real time. The electronic device 100 can trigger the recovery of the memory resources occupied by the first application in the GPU memory.
[0048] S102. The electronic device 100 determines the recycling ratio of texture resources of different sizes according to the image size of the texture resources of the first application cached in the GPU memory.
[0049] Texture resources are used to store element values of image colors. In the process of rendering images, texture resources are needed to determine the color, pattern, etc. of the image. The texture resources include multiple image textures, which may include data downloaded from the Internet by the electronic device 100 and decoded.
[0050] It should be understood that since the units of the texture resources of the first application cached in the GPU memory are different from those of the images, the electronic device 100 further includes determining the image size of the texture resources of the first application cached in the GPU memory before determining the recovery ratio of texture resources of different sizes based on the image size of the texture resources of the first application cached in the GPU memory, wherein the electronic device 100 can convert the texture resources of the first application cached in the GPU memory into data represented by the image size by formula conversion.
[0051] Considering that texture resources of different sizes have different hard decoding performances, texture resources of different sizes may be released in different proportions according to the image size of the texture resources.
[0052] Table 1 shows a decoding performance table obtained by testing image textures of different sizes contained in texture resources in an embodiment of the present application.
[0053] Table 1
[0054] Width (px) Height (px) Soft decoding performance (ms) Hardware decoding performance (ms) Memory (MB) 8192 8192 468.179 129.807 256 7744 4764 426.809 108.64 140 6016 6016 370.347 106.777 138 6000 6000 410.087 112.764 137 5676 3942 172.939 51.78 85 4912 1080 60.644 17.997 20 4000 3000 98.806 31.161 45 2272 1704 43.441 15.276 14 1600 1200 34.571 11.484 7
[0055] Among them, decoding refers to converting a signal into the information it represents. Here, it can refer to the process of converting data into image textures. The CPU is responsible for soft decoding, and the GPU is responsible for hard decoding. Memory can refer to the memory size occupied by the device when decoding the image texture.
[0056] As can be seen from Table 1, when GPU decodes image textures, the corresponding decoding time is different for image textures of different sizes. Taking the image texture of 1600px*1200px size as an example, the hard decoding time is 11.484ms, and the memory occupied is 7M; taking the image texture of 8192px*8192px size as an example, the hard decoding time is 129.807ms, and the memory occupied is 256M.
[0057] That is to say, from the overall perspective, among texture resources, the larger the size of the image texture, the longer the hard decoding time consumed, and the smaller the size of the image texture, the shorter the hard decoding time consumed. Therefore, when releasing texture resources, you can release smaller texture resources as much as possible and retain larger texture resources. In other words, texture resources with larger sizes choose a smaller recycling ratio, and texture resources with smaller sizes choose a larger recycling ratio. Among them, the recycling ratio of texture resources of a certain size can refer to the ratio of the resource release amount of texture resources of this size to the total release amount of texture resources of the first application cached in the GPU memory, and the recycling ratio of texture resources indicates the release amount of texture resources of this size.
[0058] For example, the texture resources cached by the first application can be divided into three levels according to the image size. The first level includes texture resources with a width and height in the range of 6000px-9000px, the second level includes texture resources with a width and height in the range of 4000px-6000px, and the third level includes texture resources with a width and height in the range of 1000px-4000px. Then, the texture resources cached by the first application are released in a ratio of 2:3:5 from large to small according to the image size level. In other words, among the texture resources released by the first application, the recycling ratio of the texture resources of the first level is 20%, the recycling ratio of the texture resources of the second level is 30%, and the recycling ratio of the texture resources of the third level is 50%.
[0059] That is to say, if the texture resources cached by the first application include the first texture resource and the second texture resource, and the image size of the first texture resource is smaller than the image size of the second texture resource, then the release amount of the first texture resource can be greater than the release amount of the second texture resource, for example, the release amount of the first texture resource is twice the release amount of the second texture resource. The image size of the first texture resource or the second texture resource can refer to a specific image size or a range of image sizes, which is not limited in the embodiments of the present application.
[0060] In addition, since the rendering efficiency of image textures is related to the hard decoding time of image textures, when actually calculating the recycling ratio of texture resources of different sizes, the decoding performance of image textures of different sizes can also be compared to determine the recycling ratio of texture resources based on the decoding performance.
[0061] Exemplarily, the electronic device 100 may also determine the recycling ratio of texture resources of different sizes in combination with the hard decoding time of the image textures of different sizes shown in Table 1.
[0062] For example, the electronic device 100 may calculate the recycling ratios of texture resources 1, 2, 3, ... of different sizes according to the following formula 1:
[0063] D1:D2:D3…=…T3:T2:T1 Formula 1
[0064] Among them, D1 is the recycling ratio of texture resource 1, T1 is the hard decoding time of texture resource 1, D2 is the recycling ratio of texture resource 2, T2 is the hard decoding time of texture resource 2, D3 is the recycling ratio of texture resource 3, and T3 is the hard decoding time of texture resource 3.
[0065] In addition, Table 1 is a mapping table obtained by developers by performing decoding tests on the device based on image textures of different sizes. The mapping table describes the decoding performance and memory occupied by image textures of different sizes. Since decoding performance is also related to other factors, such as the performance of the hardware equipped in the device, the decoding performance and memory occupied by image textures of different sizes may be different in different devices. Therefore, in a specific implementation, the mapping table obtained by performing decoding tests on image textures by the device can be pre-set in different devices, so that the device can use the mapping table to more accurately calculate the recycling ratio of texture resources of different sizes.
[0066] S103. The electronic device 100 releases the texture resources of the first application cached in the GPU memory according to the recycling ratios of texture resources of different sizes.
[0067] When releasing the texture resources of the first application, the electronic device 100 may give priority to releasing the texture resources with the lowest probability of being used when the first application returns to the foreground. For example, if the first application switches from the first page to the second page before switching from the foreground to the background, even if the first application returns to the foreground, the second page after switching will be displayed. Therefore, the texture resources corresponding to the first page may be released first.
[0068] In addition, in addition to determining the recycling ratio of texture resources of different sizes, the total recycling rate of texture resources can also be determined, which represents the ratio of the total release amount of texture resources of the first application to the texture resources cached in the GPU memory. Exemplarily, the total recycling rate can be a fixed value, such as 50%. In this way, the electronic device 100 can determine the release amount of texture resources of each size based on the total recycling rate of texture resources and the recycling ratio of texture resources of different sizes.
[0069] Exemplarily, the release amounts of texture resources 1, 2, 3, ... of different sizes may be calculated by the following formula 2:
[0070] Li=Di*L*S Formula 2
[0071] Among them, i=1,2,3 represents texture resource i, Li represents the release amount of texture resource i, Di represents the recycling ratio of texture resource i, L represents the total recycling rate, and S represents the total amount of texture resources cached in the GPU memory.
[0072] In some embodiments, the electronic device 100 may also determine the total recovery rate in combination with the running status of the application.
[0073] Exemplarily, the electronic device 100 can be divided into multiple levels according to different running states of the application, and different levels correspond to different total recovery rates. Among them, different running states reflect the different levels of activity of the application. The more active the application is, the lower the total recovery rate can be. For example, the total recovery rate when the application is running in the background and there is background activity is less than the total recovery rate when the application is running in the background and there is no background activity. In other words, when releasing the texture resources of the application, the amount of data released when the application has background activity is less than the amount of data released when the application has no background activity.
[0074] Among them, background activities include background navigation, background playback, background updates, etc.
[0075] In a specific implementation, the electronic device 100 can determine whether the application has background activity by the process state value procState, which reflects the state of the process. For example, if 4≤procState<7, the application has background activity, and if procState≥7, the application has no background activity.
[0076] It is understandable that the electronic device 100 may also determine whether there is background activity of the application in other ways, and the embodiment of the present application does not limit this.
[0077] In addition, the electronic device 100 may also determine the total recovery rate in combination with the GPU memory pressure. If the GPU memory pressure is large, that is, the free memory of the GPU memory is small, the total recovery rate is large, and if the GPU memory pressure is small, that is, the free memory of the GPU memory is large, the total recovery rate is small. In other words, if there is less free memory in the GPU memory, more texture resources of the first application are released, and if there is more free memory in the GPU memory, fewer texture resources of the first application are released.
[0078] Exemplarily, the electronic device 100 may determine the total recycling rate of texture resources in combination with background activities and GPU memory pressure. Figure 4 A schematic diagram of the total recovery rate of the application under different conditions provided in the embodiments of the present application.
[0079] like Figure 4 As shown, the electronic device 100 can be set to five levels:
[0080] 1) Level 1
[0081] If the app is running in the foreground, the total recycling rate of the app's texture resources is 0%.
[0082] 2) Level 2
[0083] When the app is running in the background and there is background activity, the total recycling rate of the app's texture resources is 50%.
[0084] 3) Level 3
[0085] When the app is running in the background, there is no background activity, and the GPU memory pressure is low, the total recycling rate of the app's texture resources is 70%.
[0086] 4) Level 4
[0087] When the app is running in the background, there is no background activity, and the GPU memory pressure is high, the total recycling rate of the app's texture resources is 90%.
[0088] 5) Level 5
[0089] When the app is closed, the total recycling rate of the app's texture resources is 100%.
[0090] It can be seen that the electronic device 100 can flexibly adjust the total recovery rate of texture resources in combination with multiple factors, including the foreground and background running status of the application, whether there is background activity, GPU memory pressure, etc. In this way, the GPU memory can be released as much as possible while ensuring the rendering efficiency of the application. In addition, when the electronic device 100 releases texture resources, it also includes releasing other resources of the application cached in the GPU memory, including shader resources, font resources, etc. The total recovery rate of these resources can also change dynamically with the difference in the total recovery rate of texture resources.
[0091] It is understandable that the total recovery rates of the above-mentioned texture resources of different levels are only for the purpose of facilitating the understanding of the present solution, and the listed values do not constitute a limitation to the application.
[0092] In general, the GPU memory release method provided in the embodiment of the present application can flexibly adjust the texture resources of the application cached in the GPU memory. In this way, when the application returns to the foreground and needs to be re-rendered, it not only ensures the time requirement for device re-rendering, but also minimizes the memory occupied by the application.
[0093] Figure 5 A schematic diagram of the hardware structure of the electronic device 100 is shown.
[0094] The electronic device 100 may be a mobile phone, a tablet computer, a desktop computer, a laptop computer, a handheld computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a cellular phone, a personal digital assistant (PDA), an augmented reality (AR) device, a virtual reality (VR) device, an artificial intelligence (AI) device, a wearable device, an in-vehicle device, a smart home device and / or a smart city device. The embodiments of the present application do not impose any special restrictions on the specific type of the electronic device.
[0095] The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0096] It is to be understood that the structure illustrated in the embodiment of the present invention does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or separate some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0097] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0098] In some embodiments, the GPU may be used to store resources required for rendering images. For example, for rendering the user interface of the first application, the GPU may be used to cache shader resources, font resources, texture resources, etc. required for displaying the user interface of the first application. After the processor 110 detects that the application switches from the foreground to the background, the GPU may be triggered to release the cached texture resources of the application, and determine the release amount of texture resources of different image sizes according to the image size of the texture resources.
[0099] The controller can generate operation control signals according to the instruction operation code and timing signal to complete the control of instruction fetching and execution.
[0100] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0101] The charging management module 140 is used to receive charging input from a charger.
[0102] The power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140, and supplies power to the processor 110, the internal memory 121, the display screen 194, the camera 193, and the wireless communication module 160. The power management module 141 can also be used to monitor parameters such as battery capacity, battery cycle number, battery health status (leakage, impedance), etc. In some other embodiments, the power management module 141 can also be set in the processor 110. In other embodiments, the power management module 141 and the charging management module 140 can also be set in the same device.
[0103] The wireless communication function of the electronic device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor and the baseband processor.
[0104] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of antennas. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In some other embodiments, the antenna can be used in combination with a tuning switch.
[0105] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to the electronic device 100. The mobile communication module 150 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves from the antenna 1, and filter, amplify, and process the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the processor 110. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the same device as at least some of the modules of the processor 110.
[0106] The modem processor may include a modulator and a demodulator. Among them, the modulator is used to modulate the low-frequency baseband signal to be sent into a medium-high frequency signal. The demodulator is used to demodulate the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After the low-frequency baseband signal is processed by the baseband processor, it is passed to the application processor. The application processor outputs a sound signal through an audio device (not limited to a speaker 170A, a receiver 170B, etc.), or displays an image or video through a display screen 194. In some embodiments, the modem processor may be an independent device. In other embodiments, the modem processor may be independent of the processor 110 and be set in the same device as the mobile communication module 150 or other functional modules.
[0107] The wireless communication module 160 can provide wireless communication solutions including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc., which are applied to the electronic device 100. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, demodulates and filters the electromagnetic wave signals, and sends the processed signals to the processor 110. The wireless communication module 160 can also receive the signal to be sent from the processor 110, modulate the frequency, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.
[0108] In some embodiments, the antenna 1 of the electronic device 100 is coupled to the mobile communication module 150, and the antenna 2 is coupled to the wireless communication module 160, so that the electronic device 100 can communicate with the network and other devices through wireless communication technology. The wireless communication technology may include global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), wideband code division multiple access (WCDMA), time-division code division multiple access (TD-SCDMA), long term evolution (LTE), BT, GNSS, WLAN, NFC, FM, and / or IR technology. The GNSS may include a global positioning system (GPS), a global navigation satellite system (GLONASS), a Beidou navigation satellite system (BDS), a quasi-zenith satellite system (QZSS) and / or a satellite based augmentation system (SBAS).
[0109] The electronic device 100 implements the display function through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.
[0110] The display screen 194 is used to display images, videos, etc. In some embodiments, the electronic device may include 1 or N display screens 194 , where N is a positive integer greater than 1.
[0111] The electronic device 100 can realize the shooting function through ISP, camera 193, video codec, GPU, display screen 194 and application processor.
[0112] The camera 193 is used to capture still images or videos. In some embodiments, the electronic device 100 may include 1 or N cameras 193, where N is a positive integer greater than 1.
[0113] The digital signal processor is used to process digital signals, and can process not only digital image signals but also other digital signals. For example, when the electronic device 100 is selecting a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.
[0114] Video codecs are used to compress or decompress digital videos. The electronic device 100 may support one or more video codecs. Thus, the electronic device 100 may play or record videos in a variety of coding formats, such as Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, MPEG4, etc.
[0115] The internal memory 121 may include one or more random access memories (RAM) and one or more non-volatile memories (NVM).
[0116] The random access memory can be directly read and written by the processor 110, and can be used to store executable programs (such as machine instructions) of the operating system or other running programs, and can also be used to store user and application data.
[0117] The non-volatile memory may also store executable programs and user and application data, etc., and may be loaded into the random access memory in advance for direct reading and writing by the processor 110 .
[0118] The external memory interface 120 can be used to connect to an external non-volatile memory to expand the storage capacity of the electronic device 100. The external non-volatile memory communicates with the processor 110 through the external memory interface 120 to implement a data storage function.
[0119] The electronic device 100 can implement audio functions such as music playing and recording through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone jack 170D, and the application processor.
[0120] The audio module 170 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals.
[0121] The speaker 170A, also called a "speaker", is used to convert an audio electrical signal into a sound signal. The electronic device 100 can listen to music or listen to a hands-free call through the speaker 170A.
[0122] The receiver 170B, also called a "handset", is used to convert audio electrical signals into sound signals.
[0123] Microphone 170C, also called "microphone" or "microphone", is used to convert sound signals into electrical signals.
[0124] The earphone jack 170D is used to connect a wired earphone.
[0125] The pressure sensor 180A is used to sense pressure signals and convert the pressure signals into electrical signals.
[0126] The gyro sensor 180B may be used to determine the motion posture of the electronic device 100 .
[0127] The air pressure sensor 180C is used to measure air pressure. In some embodiments, the electronic device 100 calculates the altitude through the air pressure value measured by the air pressure sensor 180C to assist positioning and navigation.
[0128] The magnetic sensor 180D includes a Hall sensor. The electronic device 100 can use the magnetic sensor 180D to detect the opening and closing of the flip leather case. In some embodiments, when the electronic device 100 is a flip phone, the electronic device 100 can detect the opening and closing of the flip cover according to the magnetic sensor 180D. Then, according to the detected opening and closing state of the leather case or the opening and closing state of the flip cover, the flip cover can be automatically unlocked.
[0129] The acceleration sensor 180E can detect the magnitude of the acceleration of the electronic device 100 in various directions (generally three axes).
[0130] The distance sensor 180F is used to measure the distance. The electronic device 100 can measure the distance by infrared or laser.
[0131] The proximity light sensor 180G may include, for example, a light emitting diode (LED) and a light detector, such as a photodiode. The light emitting diode may be an infrared light emitting diode. The electronic device 100 emits infrared light outward through the light emitting diode. The electronic device 100 uses the photodiode to detect infrared reflected light from nearby objects. When sufficient reflected light is detected, it can be determined that there is an object near the electronic device 100. When insufficient reflected light is detected, the electronic device 100 can determine that there is no object near the electronic device 100.
[0132] The ambient light sensor 180L is used to sense the brightness of ambient light.
[0133] The fingerprint sensor 180H is used to collect fingerprints.
[0134] The temperature sensor 180J is used to detect the temperature.
[0135] The touch sensor 180K is also called a "touch control device". The touch sensor 180K can be set on the display screen 194. The touch sensor 180K and the display screen 194 form a touch screen, also called a "touch control screen". The touch sensor 180K is used to detect a touch operation acting on or near it. The touch sensor can pass the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through the display screen 194.
[0136] The bone conduction sensor 180M can obtain a vibration signal. In some embodiments, the bone conduction sensor 180M can obtain a vibration signal of a vibrating bone block of a human vocal part.
[0137] The key 190 includes a power key, a volume key, etc. The key 190 may be a mechanical key or a touch key. The electronic device 100 may receive key input and generate key signal input related to user settings and function control of the electronic device 100.
[0138] Motor 191 can generate vibration prompts. Motor 191 can be used for incoming call vibration prompts, and can also be used for touch vibration feedback.
[0139] Indicator 192 may be an indicator light, which may be used to indicate charging status, power changes, messages, missed calls, notifications, etc.
[0140] The SIM card interface 195 is used to connect a SIM card.
[0141] The electronic device may be a portable terminal device equipped with iOS, Android, Microsoft or other operating systems, such as a mobile phone, a tablet computer, a wearable device, etc., and may also be a non-portable terminal device such as a laptop computer with a touch-sensitive surface or a touch panel, a desktop computer with a touch-sensitive surface or a touch panel. The software system of the electronic device 100 may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present invention takes the Android system of the layered architecture as an example to exemplify the software structure of the electronic device 100.
[0142] Figure 6 It is a software structure block diagram of the electronic device 100 according to an embodiment of the present application.
[0143] The layered architecture divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom: the application layer, the application framework layer, the Android runtime and system library, and the kernel layer.
[0144] The application layer can include a series of application packages.
[0145] like Figure 6 As shown, the application package may include applications such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message, etc.
[0146] The application framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer includes some predefined functions.
[0147] like Figure 6 As shown, the application framework layer may include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, and the like.
[0148] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, capture the screen, etc.
[0149] Content providers are used to store and retrieve data and make it accessible to applications. The data may include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
[0150] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying images.
[0151] The phone manager is used to provide communication functions of the electronic device 100, such as management of call status (including connecting, hanging up, etc.).
[0152] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.
[0153] The notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is displayed in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.
[0154] Android Runtime includes core libraries and virtual machines. Android runtime is responsible for scheduling and management of the Android system.
[0155] The core library consists of two parts: one part is the function that needs to be called by the Java language, and the other part is the Android core library.
[0156] The application layer and the application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.
[0157] The system library may include multiple functional modules, such as surface manager, media library, 3D graphics processing library (such as OpenGL ES), 2D graphics engine (such as SGL), etc.
[0158] The surface manager is used to manage the display subsystem and provide the fusion of 2D and 3D layers for multiple applications.
[0159] The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
[0160] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.
[0161] A 2D graphics engine is a drawing engine for 2D drawings.
[0162] The kernel layer is the layer between hardware and software. The kernel layer contains at least display driver, camera driver, audio driver, and sensor driver.
[0163] The following is an illustrative description of the workflow of the software and hardware of the electronic device 100 in conjunction with capturing a photo scene.
[0164] When the touch sensor 180K receives a touch operation, the corresponding hardware interrupt is sent to the kernel layer. The kernel layer processes the touch operation into a raw input event (including touch coordinates, timestamp of the touch operation, and other information). The raw input event is stored in the kernel layer. The application framework layer obtains the raw input event from the kernel layer and identifies the control corresponding to the input event. For example, if the touch operation is a touch single-click operation and the control corresponding to the single-click operation is the control of the camera application icon, the camera application calls the interface of the application framework layer to start the camera application, and then starts the camera driver by calling the kernel layer to capture static images or videos through the camera 193.
[0165] It should be understood that each step in the above method embodiment can be completed by an integrated logic circuit of hardware in a processor or by instructions in the form of software. The method steps disclosed in the embodiments of the present application can be directly embodied as being executed by a hardware processor, or by a combination of hardware and software modules in a processor.
[0166] The present application also provides an electronic device, which may include: a memory and a processor. The memory may be used to store a computer program; the processor may be used to call the computer program in the memory, so that the electronic device executes the method executed by the electronic device 100 in any of the above embodiments.
[0167] The present application also provides a chip system, which includes at least one processor for implementing the functions involved in the method performed by the electronic device 100 in any of the above embodiments.
[0168] In one possible design, the chip system also includes a memory, which is used to store program instructions and data, and the memory is located inside or outside the processor.
[0169] The chip system may be composed of the chip, or may include the chip and other discrete devices.
[0170] Optionally, the processor in the chip system may be one or more. The processor may be implemented by hardware or by software. When implemented by hardware, the processor may be a logic circuit, an integrated circuit, etc. When implemented by software, the processor may be a general-purpose processor implemented by reading software code stored in a memory.
[0171] Optionally, the memory in the chip system may also be one or more. The memory may be integrated with the processor or may be separately arranged with the processor, which is not limited in the embodiments of the present application. Exemplarily, the memory may be a non-transient processor, such as a read-only memory ROM, which may be integrated with the processor on the same chip or may be arranged on different chips respectively. The embodiments of the present application do not specifically limit the type of memory and the arrangement of the memory and the processor.
[0172] Exemplarily, the chip system can be a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on chip (SoC), a central processor unit (CPU), a network processor (NP), a digital signal processor (DSP), a microcontroller unit (MCU), a programmable logic device (PLD) or other integrated chips.
[0173] The present application also provides a computer program product, which includes: a computer program (also referred to as code, or instruction), which, when executed, enables a computer to execute a method executed by any one of the electronic devices 100 in any of the above embodiments.
[0174] The present application also provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program (also referred to as code or instruction). When the computer program is executed, the computer executes any method executed by the electronic device 100 in any of the above embodiments.
[0175] It should be understood that the processor in the embodiment of the present application can be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method embodiment can be completed by the hardware integrated logic circuit or software instructions in the processor. The above processor can be a general processor, a digital signal processor (digitalsignal processor, DSP), an application specific integrated circuit (AP 800plication specific integrated circuit, ASIC), a field programmable gate array (field programmable gate array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general processor can be a microprocessor or the processor can also be any conventional processor. The steps of the method disclosed in the embodiment of the present application can be directly embodied as a hardware decoding processor to perform, or the hardware and software modules in the decoding processor are combined to perform. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps of the above method in combination with its hardware.
[0176] In addition, an embodiment of the present application further provides a device. The device may be a component or a module, and the device may include one or more processors and a memory connected to each other. The memory is used to store a computer program. When the computer program is executed by one or more processors, the device executes the method in each of the above method embodiments.
[0177] Among them, the device, computer-readable storage medium, computer program product or chip provided in the embodiments of the present application are used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above, and will not be repeated here.
[0178] The various implementation modes of the present application can be combined arbitrarily to achieve different technical effects.
[0179] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) mode. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state disk (SSD)), etc.
[0180] Those skilled in the art can understand that to implement all or part of the processes in the above-mentioned embodiments, the processes can be completed by computer programs to instruct related hardware, and the programs can be stored in computer-readable storage media. When the programs are executed, they can include the processes of the above-mentioned method embodiments. The aforementioned storage media include: ROM or random access memory RAM, magnetic disk or optical disk and other media that can store program codes.
[0181] In short, the above description is only an embodiment of the technical solution of the present invention, and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made according to the disclosure of the present invention shall be included in the protection scope of the present invention.
Claims
1. A GPU memory release method, characterized in that: The method comprises: The electronic device switches the first application from the foreground to the background; The electronic device releases part of the texture resources of the first application according to the image size of the texture resources of the first application cached in the GPU memory, wherein the texture resources of the first application include a first texture resource and a second texture resource, the image size of the first texture resource is smaller than the image size of the second texture resource, and the release amount of the first texture resource is greater than the release amount of the second texture resource.
2. The method according to claim 1, characterized in that: After the electronic device switches the first application from the foreground to the background, The amount of data released by the texture resource of the first application when the first application has background activity is less than the amount of data released when the first application has no background activity.
3. The method according to claim 1 or 2, characterized in that: After the electronic device switches the first application from the foreground to the background, the less free memory in the GPU memory, the more texture resources of the first application released by the electronic device.
4. The method according to any one of claims 1 to 3, characterized in that: The ratio of the release amount of the first texture resource to the release amount of the second texture resource is equal to the ratio of the hard decoding time corresponding to the second texture resource to the hard decoding time corresponding to the first texture resource.
5. The method according to any one of claims 1 to 4, characterized in that: The method further comprises: The electronic device closes the first application; The electronic device releases all texture resources of the first application cached in the CPU memory.
6. The method according to any one of claims 1 to 5, characterized in that: After the electronic device switches the first application from the foreground to the background, the method further includes: The electronic device releases the font resources and shader resources of the first application cached in the GPU memory.
7. The method according to any one of claims 1 to 6, characterized in that: When the electronic device releases the texture resource of the first application, it gives priority to releasing the texture resource with the smallest probability of being used when the electronic device runs the first application in the foreground again.
8. The method according to any one of claims 1 to 7, characterized in that: Before the electronic device switches the first application from the foreground to the background, the method further includes: The electronic device detects a first operation, where the first operation is used to trigger switching the first application to background operation.
9. An electronic device, characterized in that: The electronic device comprises a memory, one or more processors, and one or more programs; when the one or more processors execute the one or more programs, the electronic device implements the method as claimed in any one of claims 1 to 8.
10. A computer-readable storage medium comprising instructions, characterized in that: When the instructions are executed on an electronic device, the electronic device is enabled to execute the method according to any one of claims 1 to 8.