Algorithm relation adjustment method and device, computer readable storage medium and equipment
By comparing the algorithm execution time and adjusting the execution order, the resource competition problem caused by the parallel execution of algorithms that rely on the same hardware resources is solved, the algorithm execution efficiency is improved and the hardware load is reduced.
Patent Information
- Application Number
- CN202310325852.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-28
- Publication Date
- 2024-10-01
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In terminal devices, parallel execution of algorithms that rely on the same hardware resources can easily lead to resource competition, resulting in reduced algorithm execution efficiency.
By comparing the execution time of the first algorithm and the target algorithm, if the execution time of the first algorithm is longer than the target execution time, adjust the relationship from parallel to serial to avoid resource competition and improve the overall algorithm execution efficiency.
It effectively avoids resource competition issues, improves algorithm execution efficiency, reduces device hardware load, and avoids excessive consumption of hardware life.
Smart Images

Figure CN118733286A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to an algorithm relationship adjustment method, device, computer-readable storage medium and equipment. Background Art
[0002] In terminal devices, there are usually a variety of hardware for executing algorithms, such as central processing unit (CPU), digital signal processor (DSP), embedded neural network processor (NPU), graphics processing unit (GPU), image signal processing (ISP), etc.
[0003] Different functions generally require different algorithms to implement, and a function may require multiple algorithms to implement. Some algorithms rely on the same hardware resources, and some algorithms rely on different hardware resources. Algorithms that rely on different hardware resources can be executed in parallel because the hardware resources that these algorithms rely on are physically isolated. There will be no resource competition when executing these algorithms in parallel.
[0004] However, for algorithms that rely on the same hardware resources, parallel execution is prone to resource competition. Resource competition can easily lead to reduced algorithm execution efficiency. Therefore, how to avoid algorithm resource competition has become an urgent problem to be solved.
[0005] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present application, and therefore may include information that does not constitute relevant technology known to ordinary technicians in the field. Summary of the invention
[0006] The purpose of the present application is to provide an algorithm relationship adjustment method, device, computer-readable storage medium and electronic device. When there is a second algorithm that needs to be run in parallel with the first algorithm, the execution time of the first algorithm and the target algorithm can be compared (the first algorithm and the target algorithm rely on different hardware resources, while the first algorithm and the second algorithm rely on the same hardware resources). When the execution time of the first algorithm is longer, it means that the first algorithm has not been completed after the target algorithm is executed. At this time, if the second algorithm is executed in parallel, the first algorithm and the second algorithm will occupy the same hardware resources at the same time, which may easily lead to a decrease in the processing power of the hardware, and then cause the execution efficiency of the first algorithm and the second algorithm to decrease. The present application can adjust the relationship between the first algorithm and the second algorithm from parallel to serial, so that the second algorithm is executed after the first algorithm is executed, thereby avoiding resource competition problems and improving the overall algorithm execution efficiency.
[0007] Other features and advantages of the present application will become apparent from the following detailed description, or may be learned in part by the practice of the present application.
[0008] According to one aspect of the present application, a method for adjusting an algorithm relationship is provided, the method comprising:
[0009] Determining a first execution duration of a first algorithm and a target execution duration of a target algorithm that is parallel to the first algorithm; wherein the target algorithm and the first algorithm rely on different hardware resources;
[0010] If the first execution time is longer than the target execution time, it is determined that there is a resource competition relationship between the second algorithm and the first algorithm; wherein the second algorithm is serial with the target algorithm, and the second algorithm and the first algorithm rely on the same hardware resources;
[0011] The relationship between the first algorithm and the second algorithm is adjusted from parallel to serial.
[0012] According to one aspect of the present application, there is provided an algorithm relationship adjustment device, the device comprising:
[0013] An execution duration determining unit, used to determine a first execution duration of a first algorithm and a target execution duration of a target algorithm that is parallel to the first algorithm; wherein the target algorithm and the first algorithm rely on different hardware resources;
[0014] a resource relationship determination unit, configured to determine, when the first execution time is longer than the target execution time, that there is a resource competition relationship between the second algorithm and the first algorithm; wherein the second algorithm is serially connected to the target algorithm, and the second algorithm and the first algorithm rely on the same hardware resources;
[0015] The resource relationship adjustment unit is used to adjust the relationship between the first algorithm and the second algorithm from parallel to serial.
[0016] According to one aspect of the present application, a computer program product or a computer program is provided, the computer program product or the computer program comprising computer instructions, the computer instructions being stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the methods provided in the above-mentioned various optional implementations.
[0017] According to one aspect of the present application, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, any one of the above methods is implemented.
[0018] According to one aspect of the present application, an electronic device is provided, comprising: a processor; and a memory for storing executable instructions of the processor; wherein the processor is configured to perform any one of the above methods by executing the executable instructions.
[0019] The exemplary embodiments of the present application may have some or all of the following beneficial effects:
[0020] In the algorithm relationship adjustment method provided in an example implementation of the present application, when there is a second algorithm that needs to be executed in parallel with the first algorithm, the execution time of the first algorithm and the target algorithm can be compared (the first algorithm and the target algorithm rely on different hardware resources, while the first algorithm and the second algorithm rely on the same hardware resources). When the execution time of the first algorithm is longer, it means that after the target algorithm is executed, the first algorithm has not been executed. At this time, if the second algorithm is executed in parallel, it will cause the first algorithm and the second algorithm to occupy the same hardware resources at the same time, which is likely to cause the processing power of the hardware to decrease, and then cause the execution efficiency of the first algorithm and the second algorithm to decrease. The present application can adjust the relationship between the first algorithm and the second algorithm from parallel to serial, so that the second algorithm is executed after the first algorithm is executed, thereby avoiding the problem of resource competition and improving the overall algorithm execution efficiency. In addition, since the present application can avoid the problem of resource competition, it can also reduce the hardware load of the device and avoid excessive consumption of hardware life.
[0021] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] The drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present application, and together with the specification are used to explain the principles of the present application. Obviously, the drawings described below are only some embodiments of the present application, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0023] Figure 1 A flowchart of an algorithm relationship adjustment method according to an embodiment of the present application is schematically shown;
[0024] Figure 2 A schematic diagram of an example of algorithm relationship adjustment according to an embodiment of the present application is shown schematically;
[0025] Figure 3 Schematically shows an example diagram of algorithm relationship adjustment according to another embodiment of the present application;
[0026] Figure 4 A flowchart of an algorithm relationship adjustment method according to another embodiment of the present application is schematically shown;
[0027] Figure 5 A schematic diagram of the structure of an algorithm relationship adjustment device according to an embodiment of the present application is shown;
[0028] Figure 6 The structure diagram of a computer system suitable for implementing an electronic device of an embodiment of the present application is schematically shown. DETAILED DESCRIPTION
[0029] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as being limited to the examples set forth herein; on the contrary, these embodiments are provided so that the present application will be more comprehensive and complete, and the concept of the example embodiments will be fully conveyed to those skilled in the art. The described features, structures, or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present application. However, those skilled in the art will appreciate that the technical solutions of the present application may be practiced while omitting one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known technical solutions are not shown or described in detail to avoid obscuring various aspects of the present application.
[0030] See also Figure 1 , Figure 1 The flowchart of the algorithm relationship adjustment method according to an embodiment of the present application is schematically shown. Figure 1 As shown, the method includes the following steps.
[0031] Step S110: Determine a first execution duration of the first algorithm and a target execution duration of a target algorithm that is run in parallel with the first algorithm; wherein the target algorithm and the first algorithm rely on different hardware resources.
[0032] Step S120: If the first execution time is greater than the target execution time, it is determined that there is a resource competition relationship between the second algorithm and the first algorithm; wherein the second algorithm and the target algorithm are serial, and the second algorithm and the first algorithm rely on the same hardware resources.
[0033] Step S130: Adjust the relationship between the first algorithm and the second algorithm from parallel to serial.
[0034] Implementation Figure 1 The method shown can compare the execution time of the first algorithm and the target algorithm when there is a second algorithm that needs to be run in parallel with the first algorithm (the first algorithm and the target algorithm rely on different hardware resources, while the first algorithm and the second algorithm rely on the same hardware resources). When the execution time of the first algorithm is longer, it means that after the target algorithm is executed, the first algorithm has not been executed. At this time, if the second algorithm is executed in parallel, it will cause the first algorithm and the second algorithm to occupy the same hardware resources at the same time, which is likely to cause the processing power of the hardware to decrease, and then cause the execution efficiency of the first algorithm and the second algorithm to decrease. The present application can adjust the relationship between the first algorithm and the second algorithm from parallel to serial, so that the second algorithm is executed after the first algorithm is executed, thereby avoiding the problem of resource competition and improving the overall algorithm execution efficiency. In addition, since the present application can avoid the problem of resource competition, it can also reduce the hardware load of the device and avoid excessive consumption of hardware life.
[0035] Next, the above steps of this exemplary embodiment are described in more detail.
[0036] In step S110, a first execution duration of the first algorithm and a target execution duration of a target algorithm that is parallel to the first algorithm are determined; wherein the target algorithm and the first algorithm rely on different hardware resources.
[0037] Specifically, the functions to be implemented by the terminal device usually need to rely on multiple algorithms. For example, for the camera function to be implemented, the algorithm sequence that needs to be relied on includes: beauty algorithm A, focus algorithm B, cropping algorithm C, etc. Assuming that the algorithms need to rely on the same hardware resources (such as GPU resources), in order to improve the efficiency of function implementation, the algorithm execution relationship will be arranged according to the hardware resources (such as CPU resources) that the algorithms rely on at the same time.
[0038] In related technologies, the execution time required for the beautification algorithm A, the focusing algorithm B, and the cropping algorithm C is usually determined first, such as 50ms, 80ms, and 100ms. If the execution time required for the synchronous algorithm is 100ms, then the beautification algorithm A and the focusing algorithm B are usually executed in series and then in parallel with the synchronous algorithm, and then the cropping algorithm C is executed in series with the synchronous algorithm. In the first 100ms of the algorithm execution, the synchronous algorithm is executed, the beautification algorithm A is executed, and the focusing algorithm B is not executed and still needs 30ms. At this time, the cropping algorithm C and the focusing algorithm B are executed in parallel, that is, the cropping algorithm C and the focusing algorithm B consume GPU resources at the same time, that is, the two are in an implicit parallel state.
[0039] Generally speaking, the total GPU efficiency will decrease during parallel processing. For example, if the total GPU efficiency decreases by 10%, then when the GPU processes 30ms of the focusing algorithm B and 30ms of the cropping algorithm C at the same time, it does not take 30ms+30ms=60ms, but 60ms*110%=66ms. Based on this, through the statistics of the above duration, it can be seen that in the related art, it takes a total of 100+66+(100-30)=236ms to complete the execution of the above algorithms.
[0040] In order to solve this problem, the present application can determine the first execution time of the first algorithm and the target execution time of the target algorithm parallel to the first algorithm. If the first execution time is longer than the target execution time, the relationship between the first algorithm and the second algorithm is adjusted from parallel to serial. In this case, the implicit parallel state can be avoided, thereby avoiding the decline in hardware efficiency. For the above case, it takes a total of 100+30+100=230ms to execute the above algorithm.
[0041] As an optional embodiment, determining the first execution time of the first algorithm includes: if the first algorithm includes multiple sub-algorithms, determining the sub-execution time of each sub-algorithm; and determining the first execution time of the first algorithm based on each sub-execution time. This can be applicable to scenarios where multiple sub-algorithms are serially executed. When the first algorithm includes multiple sub-algorithms, resource competition problems can also be avoided based on the sub-execution time of each sub-algorithm.
[0042] Specifically, the first algorithm can be understood as an algorithm for implementing software functions, or as an algorithm sequence. When used as an algorithm sequence (for example, a photo-taking algorithm sequence), the first algorithm can include multiple sub-algorithms (such as beautification algorithm A, focusing algorithm B, and cropping algorithm C).
[0043] Wherein, the sub-execution duration corresponding to each sub-algorithm may be different. Based on this, determining the first execution duration of the first algorithm according to each sub-execution duration includes: summing up each sub-execution duration to obtain the first execution duration; or determining a weight value according to the total duration corresponding to each sub-execution duration, and performing a weighted sum of each sub-execution duration based on the weight value to obtain the first execution duration.
[0044] Among them, when the number of sub-algorithms is large, the same hardware needs to work for a long time. Considering the temperature and power consumption issues, the same hardware is prone to heat up when working for a long time. In order to protect against overheating, the equipment usually reduces the performance of the hardware, which will cause the execution time of each sub-algorithm to be extended. Therefore, a weight value can be determined based on the total time corresponding to each sub-execution time calculated in advance, and the sub-execution time is weighted and calculated based on the weight value. The obtained first execution time will be more accurate, which is conducive to the subsequent algorithm relationship adjustment to obtain better results.
[0045] In step S120, if the first execution time is greater than the target execution time, it is determined that there is a resource competition relationship between the second algorithm and the first algorithm; wherein the second algorithm and the target algorithm are serial, and the second algorithm and the first algorithm rely on the same hardware resources.
[0046] Specifically, if the first execution time is less than or equal to the target execution time, it is determined that there is no resource competition relationship between the second algorithm and the first algorithm.
[0047] As an optional embodiment, if the first execution time is longer than the target execution time, it is determined that there is a resource competition relationship between the second algorithm and the first algorithm, including: if the first execution time is longer than the target execution time, and the second algorithm is not the last algorithm in the algorithm sequence, it is determined that there is a resource competition relationship between the second algorithm and the first algorithm. In this way, when the second algorithm is not the last algorithm, the resource competition relationship can be determined in time to avoid the resource competition problem.
[0048] Specifically, algorithms that have a resource competition relationship may exist in the same algorithm sequence, and algorithms that do not have a resource competition relationship may not exist in the same algorithm sequence.
[0049] As an optional embodiment, it further includes: if the first execution time is longer than the target execution time, and the second algorithm is the last algorithm in the algorithm sequence, maintaining the parallel relationship between the first algorithm and the second algorithm. In this way, when the second algorithm is not the last algorithm, the algorithm relationship is not adjusted, thus saving device resources.
[0050] Specifically, if the first execution time is greater than the target execution time, and the second algorithm is the last algorithm in the algorithm sequence (that is, the algorithm corresponding to the last sequence number in the sequence sorting), it means that when the first algorithm and the second algorithm are executed in parallel, it does not affect the subsequent algorithm implementation. Therefore, the parallel relationship between the first algorithm and the second algorithm does not need to be adjusted.
[0051] In step S130, the relationship between the first algorithm and the second algorithm is adjusted from parallel to serial.
[0052] As an optional embodiment, it also includes: obtaining the specific execution time corresponding to the flexible algorithm of the algorithm relationship to be determined; determining the sum of the execution time of a category of the first algorithm and the second algorithm; and determining the relationship between the flexible algorithm and other algorithms based on the sum of the execution time of a category, the target execution time, and the specific execution time. In this way, the execution time can be determined for the flexible algorithm based on the sum of the execution time of a category, the target execution time, and the specific execution time to ensure that there is no resource competition problem.
[0053] Specifically, the flexible algorithm of the algorithm relationship to be determined can be understood as an algorithm whose execution order is not specified. When a flexible algorithm exists, the execution time of the flexible algorithm can be determined according to the execution time of each algorithm to flexibly avoid the resource competition problem.
[0054] For example, the total execution time of a class of the first algorithm and the second algorithm is 150ms, the target execution time is 100ms, the execution time of the first post-algorithm serially after the target algorithm is 80ms, and the execution time of the second post-algorithm serially after the first post-algorithm is 70ms. This means that the total execution time of a class is greater than the sum of the execution times of the target algorithm and the first post-algorithm. If it is necessary to avoid the problem of resource competition, the flexible algorithm and the second algorithm can be made serial, or the flexible algorithm and the second post-algorithm can be made parallel; wherein, the target algorithm, the first post-algorithm, and the second post-algorithm rely on the same hardware resources.
[0055] As an optional embodiment, the relationship between the flexible algorithm and other algorithms is determined according to the sum of the execution time of a class, the target execution time, and the specific execution time, including: if the sum of the execution time of a class is greater than the target execution time, and there is no post-algorithm after the target algorithm, the flexible algorithm is adjusted to be in series with the target algorithm; if the sum of the execution time of a class is greater than the target execution time, and there is a post-algorithm after the target algorithm, the relationship between the flexible algorithm and other algorithms is determined according to the specific execution time and the post-algorithm; if the sum of the execution time of a class is equal to the target execution time, the flexible algorithm is adjusted to be in series with the second algorithm, or the flexible algorithm is adjusted to be in series with the target algorithm; if the sum of the execution time of a class is less than the target execution time, the flexible algorithm is adjusted to be in series with the second algorithm. In this way, algorithm adjustment methods can be provided in various situations to avoid resource competition problems in a variety of scenarios.
[0056] As an optional embodiment, the relationship between the flexible algorithm and other algorithms is determined based on the specific execution time and the post-algorithm, including: determining the post-execution time of the post-algorithm; wherein the post-algorithm and the target algorithm rely on the same hardware resources; determining the sum of the two types of execution time of the post-execution time and the target execution time, and the difference between the sum of the first type of execution time and the sum of the second type of execution time; and determining the relationship between the flexible algorithm and other algorithms based on the relationship between the difference and the specific execution time. In this way, a suitable algorithm relationship can be determined for the flexible algorithm based on its specific execution time, avoiding resource competition problems.
[0057] Specifically, the post-algorithm of the target algorithm can be understood as an algorithm that is serially placed after the target algorithm. When the difference between the sum of the two types of execution times, the post-algorithm execution time and the target execution time, and the sum of the first type of execution time is greater than a specific execution time, the flexible algorithm can be placed in parallel on the first post-algorithm after the target algorithm. If the difference is less than the specific execution time, the flexible algorithm can be placed in parallel on the second post-algorithm after the target algorithm.
[0058] See also Figure 2 , Figure 2 The following is a schematic diagram showing an example of adjusting the algorithm relationship according to an embodiment of the present application. Figure 2As shown, in algorithm relationship 240, algorithm B1 (GPU) 210 that relies on GPU and algorithm A1 (CPU) 230 that relies on CPU are executed in parallel, and algorithm B2 (GPU) 220 that relies on GPU and algorithm A1 (CPU) 230 that relies on CPU are executed in series. However, the execution time of algorithm B1 (GPU) 210 is longer than that of algorithm A1 (CPU) 230. After algorithm A1 (CPU) 230 is executed, algorithm B1 (GPU) 210 is not executed yet, and needs to occupy GPU resources in parallel with algorithm B2 (GPU) 220, which easily leads to resource competition problems between algorithm B1 (GPU) 210 and algorithm B2 (GPU) 220. Based on this, algorithm relationship 240 can be adjusted to algorithm relationship 250, in which B1 (GPU) 210 and B2 (GPU) 220 are executed in series, which can avoid resource competition problems.
[0059] See also Figure 3 , Figure 3 The following schematically shows an example of algorithm relationship adjustment according to another embodiment of the present application. Figure 3 As shown, in the algorithm relationship 360, there is a flexible algorithm B3 (GPU) 350, algorithm B1 (GPU) 310 and algorithm B2 (GPU) 320 are serial, and algorithm A1 (CPU) 330 and algorithm A2 (CPU) 340 are serial. It can be seen that the sum of the execution time of algorithm B1 (GPU) 310 and algorithm B2 (GPU) 320 is less than the sum of the execution time of algorithm A1 (CPU) 330 and algorithm A2 (CPU) 340, and the difference between the two is less than the execution time of flexible algorithm B3 (GPU) 350. In order to avoid the problem of resource competition, the algorithm relationship 370 can be adjusted, that is, the flexible algorithm B3 (GPU) 350 is parallel after the algorithm B2 (GPU) 320.
[0060] See also Figure 4 , Figure 4 The flowchart of the algorithm relationship adjustment method according to another embodiment of the present application is schematically shown. Figure 4 As shown, the algorithm relationship adjustment method includes: steps S400 to S408.
[0061] Step S400: Determine the first execution time of the first algorithm and the target execution time of the target algorithm that is parallel to the first algorithm; wherein the target algorithm and the first algorithm rely on different hardware resources. If the first execution time is greater than the target execution time, and the second algorithm is not the last algorithm in the algorithm sequence, then execute step S402. If the first execution time is greater than the target execution time, and the second algorithm is the last algorithm in the algorithm sequence, then execute step S404.
[0062] Step S402: determine whether there is a resource competition relationship between the second algorithm and the first algorithm, and adjust the relationship between the first algorithm and the second algorithm from parallel to serial.
[0063] Step S404: Maintaining the parallel relationship between the first algorithm and the second algorithm.
[0064] Step S406: obtaining the specific execution duration corresponding to the flexible algorithm of the algorithm relationship to be determined, and determining the sum of the execution durations of the first algorithm and the second algorithm.
[0065] Step S408: If the total of one type of execution time is greater than the target execution time, and there is no post-algorithm after the target algorithm, the flexible algorithm is adjusted to be serial with the target algorithm; if the total of one type of execution time is greater than the target execution time, and there is a post-algorithm after the target algorithm, the post-execution time of the post-algorithm is determined, wherein the post-algorithm and the target algorithm rely on the same hardware resources, and then the sum of the two types of execution times, the post-execution time and the target execution time, and the difference between the sum of one type of execution time and the sum of the two types of execution time are determined, and the relationship between the difference and the specific execution time can be determined. The relationship between the flexible algorithm and the other algorithms can be determined; if the sum of one type of execution time is equal to the target execution time, the flexible algorithm is adjusted to be serial with the second algorithm, or the flexible algorithm is adjusted to be serial with the target algorithm; if the total of one type of execution time is less than the target execution time, the flexible algorithm is adjusted to be serial with the second algorithm.
[0066] It should be noted that steps S400 to S408 are Figure 1 The steps and their embodiments shown correspond to each other. For the specific implementation of steps S400 to S408, please refer to Figure 1 The steps and embodiments shown are not described in detail here.
[0067] It can be seen that implementation Figure 4 The method shown can compare the execution time of the first algorithm and the target algorithm when there is a second algorithm that needs to be run in parallel with the first algorithm (the first algorithm and the target algorithm rely on different hardware resources, while the first algorithm and the second algorithm rely on the same hardware resources). When the execution time of the first algorithm is longer, it means that after the target algorithm is executed, the first algorithm has not been executed. At this time, if the second algorithm is executed in parallel, it will cause the first algorithm and the second algorithm to occupy the same hardware resources at the same time, which is likely to cause the processing power of the hardware to decrease, and then cause the execution efficiency of the first algorithm and the second algorithm to decrease. The present application can adjust the relationship between the first algorithm and the second algorithm from parallel to serial, so that the second algorithm is executed after the first algorithm is executed, thereby avoiding the problem of resource competition and improving the overall algorithm execution efficiency. In addition, since the present application can avoid the problem of resource competition, it can also reduce the hardware load of the device and avoid excessive consumption of hardware life.
[0068] See also Figure 5 , Figure 5 The structure block diagram of the algorithm relationship adjustment device in one embodiment of the present application is schematically shown. Figure 5 As shown, the algorithm relationship adjustment device 500 may include the following units.
[0069] An execution duration determining unit 501 is used to determine a first execution duration of a first algorithm and a target execution duration of a target algorithm that is parallel to the first algorithm; wherein the target algorithm and the first algorithm rely on different hardware resources;
[0070] A resource relationship determination unit 502, configured to determine, when the first execution time is longer than the target execution time, that there is a resource competition relationship between the second algorithm and the first algorithm; wherein the second algorithm is serially connected to the target algorithm, and the second algorithm and the first algorithm rely on the same hardware resources;
[0071] The resource relationship adjustment unit 503 is used to adjust the relationship between the first algorithm and the second algorithm from parallel to serial.
[0072] It can be seen that implementation Figure 5 The device shown can compare the execution time of the first algorithm and the target algorithm when there is a second algorithm that needs to be run in parallel with the first algorithm (the first algorithm and the target algorithm rely on different hardware resources, while the first algorithm and the second algorithm rely on the same hardware resources). When the execution time of the first algorithm is longer, it means that after the target algorithm is executed, the first algorithm has not been executed. At this time, if the second algorithm is executed in parallel, it will cause the first algorithm and the second algorithm to occupy the same hardware resources at the same time, which is likely to cause the processing power of the hardware to decrease, and then cause the execution efficiency of the first algorithm and the second algorithm to decrease. The present application can adjust the relationship between the first algorithm and the second algorithm from parallel to serial, so that the second algorithm is executed after the first algorithm is executed, thereby avoiding the problem of resource competition and improving the overall algorithm execution efficiency. In addition, since the present application can avoid the problem of resource competition, it can also reduce the hardware load of the device and avoid excessive consumption of hardware life.
[0073] As an optional embodiment, the execution duration determining unit 501 determines the first execution duration of the first algorithm, including:
[0074] If the first algorithm includes multiple sub-algorithms, determining the sub-execution duration of each sub-algorithm;
[0075] The first execution duration of the first algorithm is determined according to each sub-execution duration.
[0076] It can be seen that the implementation of this optional embodiment can be applicable to the scenario where multiple sub-algorithms are executed serially. When the first algorithm includes multiple sub-algorithms, the resource competition problem can also be avoided based on the sub-execution time of each sub-algorithm.
[0077] As an optional embodiment, when the first execution time is longer than the target execution time, the resource relationship determining unit 502 determines that there is a resource competition relationship between the second algorithm and the first algorithm, including:
[0078] If the first execution time is greater than the target execution time, and the second algorithm is not the last algorithm in the algorithm sequence, it is determined that there is a resource competition relationship between the second algorithm and the first algorithm.
[0079] It can be seen that by implementing this optional embodiment, when the second algorithm is not the last algorithm, the resource competition relationship can be determined in time to avoid the resource competition problem.
[0080] As an optional embodiment, wherein:
[0081] The resource relationship determination unit 502 is further configured to maintain the parallel relationship between the first algorithm and the second algorithm when the first execution duration is greater than the target execution duration and the second algorithm is the last algorithm in the algorithm sequence.
[0082] It can be seen that by implementing this optional embodiment, when the second algorithm is not the last algorithm, the algorithm relationship does not need to be adjusted, thereby saving device resources.
[0083] As an optional embodiment, wherein:
[0084] The execution time determination unit 501 is further used to obtain the specific execution time corresponding to the flexible algorithm of the algorithm relationship to be determined;
[0085] The execution time determination unit 501 is further used to determine the sum of the execution times of the first algorithm and the second algorithm;
[0086] The resource relationship determination unit 502 is further used to determine the relationship between the flexible algorithm and other algorithms according to the total execution time of a category, the target execution time, and the specific execution time.
[0087] It can be seen that by implementing this optional embodiment, the execution timing can be determined based on a flexible algorithm including the total execution time of a type, the target execution time, and the specific execution time to ensure that resource competition does not occur.
[0088] As an optional embodiment, the resource relationship determination unit 502 determines the relationship between the flexible algorithm and other algorithms according to the total execution time of a category, the target execution time, and the specific execution time, including:
[0089] If the total execution time of a category is greater than the target execution time, and there is no post-algorithm after the target algorithm, the flexible algorithm is adjusted to be serial with the target algorithm;
[0090] If the sum of execution times of a category is greater than the target execution time, and there is a post-algorithm after the target algorithm, the relationship between the flexible algorithm and other algorithms is determined based on the specific execution time and post-algorithm;
[0091] If the sum of the execution time of one type is equal to the target execution time, the flexible algorithm is adjusted to be serial with the second algorithm, or the flexible algorithm is adjusted to be serial with the target algorithm;
[0092] If the total execution time of one type is less than the target execution time, the flexible algorithm is adjusted to be serial with the second algorithm.
[0093] It can be seen that implementing this optional embodiment can provide algorithm adjustment methods in various situations to avoid resource competition problems in various scenarios.
[0094] As an optional embodiment, the resource relationship determination unit 502 determines the relationship between the flexible algorithm and other algorithms according to the specific execution time and the post-algorithm, including:
[0095] Determine the post-execution time of the post-algorithm; wherein the post-algorithm and the target algorithm rely on the same hardware resources;
[0096] Determine the sum of the two types of execution time, the post-execution time and the target execution time, and the difference between the sum of the first type of execution time and the sum of the second type of execution time;
[0097] Based on the relationship between the difference and the specific execution time, the relationship between the flexible algorithm and other algorithms is determined.
[0098] It can be seen that by implementing this optional embodiment, a suitable algorithm relationship can be determined for the flexible algorithm based on the specific execution time of the flexible algorithm, thereby avoiding the problem of resource competition.
[0099] It should be noted that, although several modules or units of the equipment for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present application, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into being embodied by multiple modules or units.
[0100] Since the various functional modules of the algorithm relationship adjustment device of the example embodiment of the present application correspond to the steps of the example embodiment of the algorithm relationship adjustment device described above, for details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the algorithm relationship adjustment device described above in the present application.
[0101] See also Figure 6 , Figure 6 A schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present application is shown.
[0102] It should be noted that Figure 6 The computer system 600 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0103] like Figure 6 As shown, computer system 600 includes a central processing unit (CPU) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage part 608 into a random access memory (RAM) 603. Various programs and data required for system operation are also stored in RAM 603. CPU 601, ROM 602 and RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to bus 604.
[0104] The following components are connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed, so that a computer program read therefrom is installed into the storage section 608 as needed.
[0105] In particular, according to an embodiment of the present application, the process described below with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication section 609, and / or installed from a removable medium 611. When the computer program is executed by a central processing unit (CPU) 601, various functions defined in the method and apparatus of the present application are executed.
[0106] As another aspect, the present application also provides a computer-readable medium, which may be included in the electronic device described in the above embodiment; or may exist independently without being assembled into the electronic device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by an electronic device, the electronic device implements the method in the above embodiment.
[0107] It should be noted that the computer-readable medium shown in the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0108] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the above-mentioned module, program segment or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0109] The units involved in the embodiments described in this application may be implemented by software or hardware, and the units described may also be set in a processor. The names of these units do not, in some cases, constitute limitations on the units themselves.
[0110] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary technical means in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the claims.
Claims
1. A method for adjusting an algorithm relationship, characterized in that: include: Determining a first execution duration of a first algorithm and a target execution duration of a target algorithm that is executed in parallel with the first algorithm; wherein the target algorithm and the first algorithm rely on different hardware resources; If the first execution time is longer than the target execution time, it is determined that there is a resource competition relationship between the second algorithm and the first algorithm; wherein the second algorithm is serial with the target algorithm, and the second algorithm and the first algorithm rely on the same hardware resources; The relationship between the first algorithm and the second algorithm is adjusted from parallel to serial.
2. The method according to claim 1, characterized in that: If the first execution time is greater than the target execution time, determining that there is a resource competition relationship between the second algorithm and the first algorithm includes: If the first execution time is greater than the target execution time, and the second algorithm is not the last algorithm in the algorithm sequence, it is determined that there is a resource competition relationship between the second algorithm and the first algorithm.
3. The method according to claim 2, characterized in that Also includes: If the first execution time is greater than the target execution time, and the second algorithm is the last algorithm in the algorithm sequence, the parallel relationship between the first algorithm and the second algorithm is maintained.
4. The method according to claim 1, characterized in that: Determining a first execution duration of a first algorithm includes: If the first algorithm includes multiple sub-algorithms, determining the sub-execution duration of each sub-algorithm; The first execution duration of the first algorithm is determined according to each sub-execution duration.
5. The method according to claim 1, characterized in that Also includes: Obtaining a specific execution time corresponding to the flexible algorithm of the algorithmic relationship to be determined; Determine a total execution time of the first algorithm and the second algorithm; The relationship between the flexible algorithm and other algorithms is determined according to the total execution time of one type, the target execution time, and the specific execution time.
6. The method according to claim 5, characterized in that Determining the relationship between the flexible algorithm and other algorithms according to the sum of the execution durations of the category, the target execution duration, and the specific execution duration includes: If the sum of the execution durations of the one type is greater than the target execution duration, and there is no subsequent algorithm after the target algorithm, the flexible algorithm is adjusted to be serial with the target algorithm; If the sum of the execution durations of the one type is greater than the target execution duration, and there is a post-algorithm after the target algorithm, then determining the relationship between the flexible algorithm and other algorithms according to the specific execution duration and the post-algorithm; If the sum of the execution durations of the one type is equal to the target execution duration, the flexible algorithm is adjusted to be serially connected with the second algorithm, or the flexible algorithm is adjusted to be serially connected with the target algorithm; If the sum of the execution durations of the type is less than the target execution duration, the flexible algorithm is adjusted to be serially executed with the second algorithm.
7. The method according to claim 6, characterized in that Determining the relationship between the flexible algorithm and other algorithms according to the specific execution time and the post-algorithm includes: Determining a post-execution duration of the post-algorithm; wherein the post-algorithm and the target algorithm rely on the same hardware resources; Determine the sum of the two types of execution durations, namely, the post-execution duration and the target execution duration, and the difference between the sum of the one type of execution duration and the sum of the two types of execution durations; According to the relationship between the difference and the specific execution time, the relationship between the flexible algorithm and other algorithms is determined.
8. An algorithm relationship adjustment device, characterized in that: include: An execution duration determining unit, configured to determine a first execution duration of a first algorithm and a target execution duration of a target algorithm that is executed in parallel with the first algorithm; wherein the target algorithm and the first algorithm rely on different hardware resources; a resource relationship determination unit, configured to determine, when the first execution time is longer than the target execution time, that there is a resource competition relationship between the second algorithm and the first algorithm; wherein the second algorithm is serially connected to the target algorithm, and the second algorithm and the first algorithm rely on the same hardware resources; The resource relationship adjustment unit is used to adjust the relationship between the first algorithm and the second algorithm from parallel to serial.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
10. An electronic device, characterized in that: include: processor; as well as A memory, configured to store executable instructions of the processor; The processor is configured to perform the method of any one of claims 1 to 7 by executing the executable instructions.
