Instruction optimization method and device
By obtaining the monitoring data of the AI processor and optimizing the instruction combination, the inefficiency problem caused by redundant repetition when executing the instruction combination is solved, and the effect of improving the operation efficiency of the AI processor is achieved.
Patent Information
- Application Number
- CN201911426093.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-12-31
- Publication Date
- 2025-02-14
- Estimated Expiration
- 2039-12-31
AI Technical Summary
During the process of executing binary instruction code by the AI processor, due to the redundant repetition of the tool chain for combining instructions, the AI processor takes more time to run the instruction combination, resulting in lower efficiency.
By obtaining the monitoring data of the AI processor when executing the instruction combination, analyzing it with the instruction combination, determining the optimization data of the instruction combination, and optimizing the instruction combination based on the optimization data, avoiding redundant and duplicate instructions.
It reduces the instructions that the AI processor needs to run, improves the efficiency of the AI processor running instruction combination, and reduces the time it takes to run instruction combination.
Smart Images

Figure CN113127062B_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of artificial intelligence technology, and in particular, relates to an instruction optimization method and device. Background Art
[0002] With the continuous development of artificial intelligence technology, terminal devices equipped with AI (Artificial Intelligence) processors can intelligently allocate hardware resources of terminal devices and predict the operations triggered by users on terminal devices and user behaviors.
[0003] In the related technology, the terminal device can combine multiple instructions in the instruction set through a pre-set tool chain, generate an instruction combination in code form, and send the instruction combination to the AI processor. The AI processor can then run the instruction combination, thereby performing vector operations, floating-point operations or convolution operations through multiple computing units arranged in the AI processor, thereby completing the function indicated by the instruction combination.
[0004] However, when the AI processor executes binary instruction codes, the tool chain performs redundant and repetitive encoding of instruction combinations, which causes the AI processor to spend more time running the instruction combination, resulting in low efficiency. Summary of the invention
[0005] The embodiments of the present application provide an instruction optimization method and device, which can solve the problem that it takes a long time to execute an instruction combination, resulting in low efficiency.
[0006] In a first aspect, an embodiment of the present application provides an instruction optimization method, comprising:
[0007] Acquire monitoring data, where the monitoring data is obtained by monitoring the AI processor when the AI processor executes the instruction combination, and is used to record the operating efficiency of each computing unit in the AI processor;
[0008] According to the monitoring data, the instruction combination is analyzed to determine the optimization data of the instruction combination;
[0009] The instruction combination is optimized according to the optimization data.
[0010] Optionally, the determining the optimization data of the instruction combination by analyzing the monitoring data in combination with the instruction combination includes:
[0011] For each instruction in the instruction combination, determining whether the instruction is a commonly used instruction;
[0012] If the instruction is a commonly used instruction, the encapsulated instruction is used as the optimization data of the instruction combination.
[0013] Optionally, the encapsulating instruction as the optimization data of the instruction combination includes:
[0014] For each instruction in the instruction combination, if the instruction appears multiple times in a loop in the instruction combination, encapsulating the loop as the optimization data of the instruction combination;
[0015] If the instruction appears randomly multiple times in the instruction combination, a function call is encapsulated as the optimization data of the instruction combination.
[0016] Optionally, after optimizing the instruction combination according to the optimization data, the method further includes:
[0017] Acquire multiple instruction combinations, each of which is optimized based on a previous instruction combination;
[0018] Determine the monitoring data corresponding to each of the instruction combinations;
[0019] According to the plurality of monitoring data, a target instruction combination is determined from the plurality of instruction combinations, and the operating efficiency of each computing unit in the AI processor indicated by the monitoring data corresponding to the target instruction combination is the highest.
[0020] Optionally, before acquiring the monitoring data, the method further includes:
[0021] Get multiple instructions from a preset instruction set;
[0022] Generating the instruction combination according to the logical relationship between the instructions;
[0023] The instruction combination is executed by the AI processor.
[0024] In a second aspect, an embodiment of the present application provides an instruction optimization device, comprising:
[0025] A first acquisition module is used to acquire monitoring data, where the monitoring data is obtained by monitoring the AI processor when the AI processor executes the instruction combination, and is used to record the operating efficiency of each computing unit in the AI processor;
[0026] A first determination module, configured to perform analysis based on the monitoring data in combination with the instruction combination to determine optimization data of the instruction combination;
[0027] An optimization module is used to optimize the instruction combination according to the optimization data.
[0028] Optionally, the first determination module is further used to determine, for each instruction in the instruction combination, whether the instruction is a commonly used instruction; if the instruction is a commonly used instruction, encapsulating the instruction as the optimization data of the instruction combination.
[0029] Optionally, the first determination module is also used to, for each instruction in the instruction combination, if the instruction appears multiple times in a loop in the instruction combination, encapsulate the loop as the optimization data of the instruction combination; if the instruction appears multiple times randomly in the instruction combination, encapsulate the function call as the optimization data of the instruction combination.
[0030] Optionally, the device further comprises:
[0031] A second acquisition module is used to acquire multiple instruction combinations, each of which is optimized based on a previous instruction combination;
[0032] A second determination module, used to determine the monitoring data corresponding to each of the instruction combinations;
[0033] The third determination module is used to determine a target instruction combination from the multiple instruction combinations based on the multiple monitoring data, and the operating efficiency of each computing unit in the AI processor indicated by the monitoring data corresponding to the target instruction combination is the highest.
[0034] Optionally, the device further comprises:
[0035] A third acquisition module is used to acquire multiple instructions from a preset instruction set;
[0036] A generating module, used for generating the instruction combination according to the logical relationship between the instructions;
[0037] An execution module is used to execute the instruction combination through the AI processor.
[0038] In a third aspect, an embodiment of the present application provides a terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the instruction optimization method as described in any one of the first aspects above is implemented.
[0039] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the instruction optimization method as described in any one of the above-mentioned first aspects is implemented.
[0040] In a fifth aspect, an embodiment of the present application provides a computer program product, which, when executed on a terminal device, enables the terminal device to execute the instruction optimization method described in any one of the above-mentioned first aspects.
[0041] It can be understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here.
[0042] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0043] The embodiment of the present application obtains monitoring data obtained by monitoring when the AI processor executes the instruction combination, and analyzes the monitoring data in combination with the instruction combination to determine the optimization data of the instruction combination, and then optimizes the instruction combination according to the optimization data. By obtaining the monitoring data obtained by monitoring, analyzing the monitoring data and the instruction combination, determining the optimization data of the optimized instruction combination, and then optimizing the instruction combination according to the optimization data, redundant and repeated instructions in the instruction combination are avoided, and the instructions that the AI processor needs to run are reduced. When the AI processor runs the optimized instruction combination, the time spent on running the instruction combination can be reduced, and the operating efficiency of the AI processor running the instruction combination is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0045] Figure 1 A schematic diagram of the system structure of an instruction optimization system involved in the instruction optimization method provided by the present application is shown;
[0046] Figure 2 A schematic flow chart of an instruction optimization method provided by the present application is shown;
[0047] Figure 3 A schematic flow chart of another instruction optimization method provided by the present application is shown;
[0048] Figure 4 A structural block diagram of an instruction optimization device provided in an embodiment of the present application is shown;
[0049] Figure 5 A structural block diagram of another instruction optimization device provided in an embodiment of the present application is shown;
[0050] Figure 6A structural block diagram of another instruction optimization device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0051] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0052] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.
[0053] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0054] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.
[0055] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.
[0056] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0057] The instruction optimization method provided in the embodiments of the present application can be applied to terminal devices such as mobile phones, tablet computers, wearable devices, vehicle-mounted devices, augmented reality (AR) / virtual reality (VR) devices, laptop computers, ultra-mobile personal computers (UMPC), netbooks, personal digital assistants (PDA), etc. The embodiments of the present application do not impose any restrictions on the specific types of terminal devices.
[0058] For example, the terminal device can be a station (STAION, ST) in a WLAN, a cellular phone, a cordless phone, a Session Initiation Protocol (SIP) phone, a Wireless Local Loop (WLL) station, a Personal Digital Assistant (PDA) device, a handheld device with wireless communication function, a computing device or other processing device connected to a wireless modem, a vehicle-mounted device, a vehicle networking terminal, a computer, a laptop computer, a handheld communication device, a handheld computing device, a satellite wireless device, a wireless modem card, a TV set top box (STB), a customer premises equipment (CPE) and / or other devices for communicating on a wireless system and a next-generation communication system, such as a mobile terminal in a 5G network or a mobile terminal in a future evolved Public Land Mobile Network (PLMN) network, etc.
[0059] Figure 1 A schematic diagram of the system structure of the instruction optimization system involved in the instruction optimization method provided in this application is shown in FIG. Figure 1 The system structure diagram may include: a terminal device 110, an AI processor 120 and a Mac monitor 130.
[0060] The terminal device 110 is equipped with an AI processor 120 and a Mac monitor 130. Moreover, the AI processor 120 is arranged with a Mac matrix, and each Mac unit in the Mac matrix can be a computing unit. When the AI processor 120 runs the instruction combination, each computing unit can run the instruction combination to improve the efficiency of the AI processor 120 running the instruction combination.
[0061] Correspondingly, the Mac monitor 130 can monitor whether each computing unit in the AI processor 120 has run the instruction combination, and if the instruction combination has been run, whether each computing unit has fully exerted the hardware performance of the computing unit, thereby obtaining monitoring data.
[0062] In one possible implementation, the terminal device 110 can obtain multiple instructions in a pre-stored instruction set based on a pre-set tool chain application, and combine the multiple instructions according to the logical relationship between the instructions to obtain an instruction combination, so as to implement a certain function through the instruction combination, and then run the instruction combination through the AI processor 120. At the same time, the Mac monitor 130 can be controlled to monitor the AI processor 120 to obtain monitoring data, thereby generating optimization data based on the monitoring data and the instruction combination, and then optimizing the instruction combination based on the optimization data to obtain an optimized instruction combination that the AI processor 120 can run more efficiently.
[0063] It should be noted that in actual applications, not only can the instruction combination be optimized through the terminal device 110, but the instructions in the instruction set, the Mac matrix of the AI processor 120, and the size of the instruction combination can also be optimized based on the user's experience. The embodiments of the present application do not limit this.
[0064] For example, when the Mac matrix of the AI processor 120 has not yet been solidified, the unused computing units of the Mac matrix in the AI processor 120 can be determined based on the monitoring data, so as to optimize the arrangement of the Mac matrix.
[0065] Figure 2 A schematic flow chart of an instruction optimization method provided by the present application is shown. As an example but not a limitation, the method can be applied to the above-mentioned terminal device, see Figure 2 , the method comprising:
[0066] S201. Acquire monitoring data, where the monitoring data is obtained by monitoring the AI processor when the AI processor executes an instruction combination, and is used to record the operating efficiency of each computing unit in the AI processor.
[0067] When executing instruction combinations through the AI processor, the terminal device can perform calculations based on the various computing units arranged in the AI processor, thereby improving the efficiency of running the instruction combination. However, in actual applications, due to the influence of the instruction combination and the arrangement of the computing units, the AI processor will be affected by the redundant and repeated instructions in the instruction combination during the execution of the instruction combination, resulting in low efficiency of the AI processor.
[0068] Therefore, before the AI processor runs the instruction combination, the instruction combination can be optimized to improve the operating efficiency of the AI processor. Accordingly, in the process of optimizing the instruction combination, the monitoring data of the AI processor can be obtained first, so that in subsequent steps, the instruction combination can be optimized according to the monitoring data.
[0069] For example, the terminal device can receive monitoring data sent by the Mac monitor and establish a correspondence between the monitoring data and the instruction combination executed by the AI processor, so as to determine the target instruction combination with the highest operating efficiency of the computing unit of the AI processor among multiple instruction combinations based on the correspondence.
[0070] S202: Analyze the monitoring data in combination with the instruction combination to determine optimization data of the instruction combination.
[0071] After obtaining the monitoring data, the terminal device may analyze the monitoring data in combination with each instruction in the instruction combination to determine an optimization method for optimizing the instruction combination, thereby obtaining optimization data composed of at least one optimization method.
[0072] In one possible implementation, the terminal device can determine the position and number of times each identical instruction in the instruction combination appears in the instruction combination, and determine whether the instruction needs to be optimized in combination with the operating efficiency of the computing unit indicated in the monitoring data. If it is determined that the instruction needs to be optimized, the optimization method for optimizing the instruction can be determined in combination with the position and number of times the instruction appears, thereby obtaining an optimization method for the instruction.
[0073] Similarly, after determining the optimization method for each instruction in the above manner, the optimization data for the instruction combination can be obtained.
[0074] S203: Optimize the instruction combination according to the optimization data.
[0075] After the terminal device generates optimization data, each instruction in the instruction combination can be optimized according to at least one optimization method in the optimization data to obtain an optimized instruction combination, so that the AI processor can improve its operating efficiency when running the optimized instruction combination.
[0076] In a possible implementation, the terminal device may optimize each instruction in the instruction combination by using a corresponding optimization method for each instruction according to the optimization method for different instructions in the optimization data, thereby completing the optimization of the instruction combination.
[0077] For example, if an instruction in an instruction combination appears multiple times in a loop, the instruction can be optimized by loop encapsulation; if an instruction in an instruction combination appears multiple times randomly in the instruction combination, the instruction can be optimized by function call encapsulation.
[0078] In summary, the instruction optimization method provided in the embodiment of the present application obtains the monitoring data obtained by the AI processor when executing the instruction combination, and analyzes the instruction combination according to the monitoring data to determine the optimization data of the instruction combination, and then optimizes the instruction combination according to the optimization data. By obtaining the monitoring data obtained by monitoring, and analyzing the monitoring data and the instruction combination, determining the optimization data of the optimized instruction combination, and then optimizing the instruction combination according to the optimization data, redundant and repeated instructions in the instruction combination are avoided, and the instructions that the AI processor needs to run are reduced. When the AI processor runs the optimized instruction combination, the time spent running the instruction combination can be reduced, and the operating efficiency of the AI processor running the instruction combination is improved.
[0079] Figure 3 A schematic flow chart of another instruction optimization method provided by the present application is shown. As an example but not a limitation, the method can be applied to the above-mentioned terminal device, see Figure 3 , the method comprising:
[0080] S301: Generate an instruction combination.
[0081] In the process of running the instruction combination through the AI processor, the terminal device can first generate the instruction combination according to a pre-set instruction set including multiple instructions, combined with an optimized method of generating instruction combinations, so that in subsequent steps, it can be optimized again based on the generated instruction combination.
[0082] Optionally, the terminal device can obtain multiple instructions from a pre-set instruction set, and generate an instruction combination based on the logical relationship between the various instructions, and then run the instruction combination through the AI processor.
[0083] In one possible implementation, the terminal device can obtain multiple instructions in the storage space corresponding to the instruction set, and determine the logical relationship between the instructions, so as to generate an instruction combination for implementing a certain function based on the logical relationship between the instructions and combining the instructions.
[0084] Correspondingly, after obtaining the instruction combination, the terminal device can control the AI processor to run the instruction combination, and monitor the operating efficiency of the AI processor through the Mac monitor during the process of the AI processor running the instruction combination, that is, monitor the operating efficiency of each computing unit in the AI processor, determine whether each computing unit participates in running the instruction combination, and determine whether each computing unit has fully exerted its hardware performance, thereby obtaining monitoring data for the AI processor running the instruction combination.
[0085] For example, if the terminal device needs to implement the function of writing data, it can obtain from the instruction set: text acquisition instructions, text deletion instructions and text addition instructions, and based on the logical relationship between the instructions, combine them in the order of text deletion instructions, text acquisition instructions and text addition instructions to obtain the instruction combination that implements the function of writing data.
[0086] S302. Acquire monitoring data. The monitoring data is obtained by monitoring the AI processor when the AI processor executes the instruction combination, and is used to record the operating efficiency of each computing unit in the AI processor.
[0087] Since S302 is similar to S201, it will not be described again here.
[0088] S303: Analyze the monitoring data in combination with the instruction combination to determine the optimization data of the instruction combination.
[0089] After the monitoring data is obtained, an optimization method for optimizing the instruction combination can be determined according to the monitoring data, so that optimization data can be generated according to at least one optimization method, so that in subsequent steps, the instruction combination can be optimized according to the optimization data.
[0090] Optionally, for each instruction in the instruction combination, the terminal device may determine whether the instruction is a commonly used instruction. If the instruction is a commonly used instruction, the encapsulated instruction may be used as optimization data for the instruction combination.
[0091] In a possible implementation, the terminal device can traverse each instruction in the instruction combination, and for each instruction, the terminal device can determine whether the instruction is a common instruction. If it is not a common instruction, the instruction cannot be optimized.
[0092] However, if the instruction is a common instruction, the position and number of occurrences of the instruction can be determined, and based on the position and number of occurrences, the optimization method for optimizing the instruction can be determined. After traversing each instruction, at least one optimization method can be obtained, thereby obtaining optimization data generated by at least one optimization method.
[0093] Furthermore, for each instruction in the instruction combination, if the instruction appears multiple times in the instruction combination in a loop, the loop encapsulation can be used as the optimization data of the instruction combination. Similarly, if the instruction appears multiple times randomly in the instruction combination, the function call encapsulation can be used as the optimization data of the instruction combination.
[0094] In one possible implementation, the terminal device can determine whether the instruction is a cyclically appearing instruction in the instruction combination based on the position and number of times the instruction appears. If it is a cyclically appearing instruction, the instruction can be optimized using a loop encapsulation method, and the loop encapsulation optimization method can be used as an optimization method in the optimization data.
[0095] Similarly, if the instruction is not a cyclic instruction, then the number of times the instruction appears can be used to determine whether the instruction appears multiple times in the instruction combination. If the instruction appears multiple times, the instruction can be optimized by using function call encapsulation. The function call encapsulation optimization method can be used as another optimization method in the optimization data.
[0096] In addition, the terminal device can also optimize the instruction combination according to the size of the preset storage space. If the size of the storage space occupied by the instruction combination is larger than the size of the preset storage space, the optimization data can be generated by combining the method of reducing the storage space.
[0097] For example, if the size of the preset storage space is 64 Kb (kilobytes), and the storage space occupied by the instruction combination is 70 Kb, the storage space occupied by the instruction combination needs to be reduced.
[0098] Of course, in practical applications, other optimization methods can also be used as optimization data, and the embodiments of the present application do not limit the optimization methods.
[0099] S304: Optimize the instruction combination according to the optimization data.
[0100] Since S304 is similar to S203, it will not be described again here.
[0101] S305. Determine a target instruction combination, wherein the operation efficiency of each computing unit in the AI processor indicated by the monitoring data corresponding to the target instruction combination is the highest.
[0102] The terminal device can execute S301 to S304 above in a loop. When the optimized instruction combination meets the preset optimization conditions, or the number of optimizations reaches a preset optimization threshold, the target instruction combination with the highest operating efficiency of the AI processor can be selected from the multiple instruction combinations obtained by optimization, thereby completing the optimization of the instruction combination and determining the method of optimizing the instruction combination.
[0103] Optionally, the terminal device may obtain multiple instruction combinations, determine monitoring data corresponding to each instruction combination, and then determine a target instruction combination from the multiple instruction combinations based on the multiple monitoring data.
[0104] Each instruction combination is optimized based on the previous instruction combination. For example, after running the first instruction combination, the AI processor can monitor and obtain the first monitoring data, and optimize the first instruction combination based on the first monitoring data and the first instruction combination to obtain the second instruction combination. After that, the AI processor can run the second instruction combination again and obtain the second monitoring data through the Mac monitor, thereby obtaining multiple instruction combinations and monitoring data corresponding to each instruction combination.
[0105] Moreover, the operating efficiency of each computing unit in the AI processor indicated by the monitoring data corresponding to the target instruction combination is the highest, that is, when the AI processor runs the target instruction combination, the operating efficiency of each computing unit in the AI processor is the highest.
[0106] In one possible implementation, the terminal device can record each optimized instruction combination, and after the AI processor runs the instruction combination, determine whether the preset optimization conditions are met. If the target operating efficiency indicated in the optimization conditions is met, or the number of optimizations reaches a preset optimization threshold, multiple optimized instruction combinations can be obtained, and the operating efficiency indicated by the monitoring data corresponding to each instruction combination can be determined, so as to select the instruction combination corresponding to the operating efficiency with the largest parameter value from the multiple operating efficiencies, and then use the selected instruction combination as the target instruction combination.
[0107] It should be noted that the target operating efficiency or optimization threshold indicated by the optimization condition can be set according to the operating efficiency of other AI processors or according to user experience. The embodiment of the present application does not limit the setting method of the target operating efficiency and the optimization threshold.
[0108] In summary, the instruction optimization method provided in the embodiment of the present application obtains the monitoring data obtained by the AI processor when executing the instruction combination, and analyzes the instruction combination according to the monitoring data to determine the optimization data of the instruction combination, and then optimizes the instruction combination according to the optimization data. By obtaining the monitoring data obtained by monitoring, and analyzing the monitoring data and the instruction combination, determining the optimization data of the optimized instruction combination, and then optimizing the instruction combination according to the optimization data, redundant and repeated instructions in the instruction combination are avoided, and the instructions that the AI processor needs to run are reduced. When the AI processor runs the optimized instruction combination, the time spent running the instruction combination can be reduced, and the operating efficiency of the AI processor running the instruction combination is improved.
[0109] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0110] Corresponding to the instruction optimization method described in the above embodiment, Figure 4 A structural block diagram of an instruction optimization device provided in an embodiment of the present application is shown. For ease of explanation, only the parts related to the embodiment of the present application are shown.
[0111] Reference Figure 4 , the device comprises:
[0112] A first acquisition module 401 is used to acquire monitoring data, where the monitoring data is obtained by monitoring the AI processor when the AI processor executes the instruction combination, and is used to record the operating efficiency of each computing unit in the AI processor;
[0113] A first determination module 402 is used to perform analysis based on the monitoring data and the instruction combination to determine optimization data of the instruction combination;
[0114] The optimization module 403 is used to optimize the instruction combination according to the optimization data.
[0115] Optionally, the first determination module 402 is further configured to determine, for each instruction in the instruction combination, whether the instruction is a commonly used instruction; if the instruction is a commonly used instruction, encapsulate the instruction as the optimization data of the instruction combination.
[0116] Optionally, the first determination module 402 is also used to, for each instruction in the instruction combination, if the instruction appears multiple times in a loop in the instruction combination, encapsulate the loop as the optimization data of the instruction combination; if the instruction appears multiple times randomly in the instruction combination, encapsulate the function call as the optimization data of the instruction combination.
[0117] Optional, see Figure 5 , the device further comprises:
[0118] A second acquisition module 404 is used to acquire multiple instruction combinations, each of which is obtained by optimizing a previous instruction combination;
[0119] The second determination module 405 is used to determine the monitoring data corresponding to each instruction combination;
[0120] The third determination module 406 is used to determine a target instruction combination from the multiple instruction combinations based on the multiple monitoring data, and the operating efficiency of each computing unit in the AI processor indicated by the monitoring data corresponding to the target instruction combination is the highest.
[0121] Optional, see Figure 6 , the device further comprises:
[0122] The third acquisition module 407 is used to acquire multiple instructions from a preset instruction set;
[0123] A generating module 408, configured to generate the instruction combination according to the logical relationship between the instructions;
[0124] The running module 409 is used to run the instruction combination through the AI processor.
[0125] In summary, the instruction optimization device provided in the embodiment of the present application obtains the monitoring data obtained by the AI processor when executing the instruction combination, and analyzes the instruction combination according to the monitoring data to determine the optimization data of the instruction combination, and then optimizes the instruction combination according to the optimization data. By obtaining the monitoring data obtained by monitoring, and analyzing the monitoring data and the instruction combination to determine the optimization data of the optimized instruction combination, and then optimizing the instruction combination according to the optimization data, redundant and repeated instructions in the instruction combination are avoided, and the instructions that the AI processor needs to run are reduced. When the AI processor runs the optimized instruction combination, the time spent running the instruction combination can be reduced, and the operating efficiency of the AI processor running the instruction combination is improved.
[0126] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / units are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.
[0127] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0128] An embodiment of the present application provides a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps in the above-mentioned method embodiments can be implemented.
[0129] An embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented.
[0130] An embodiment of the present application provides a computer program product. When the computer program product runs on a mobile terminal, the mobile terminal can implement the steps in the above-mentioned method embodiments when executing the computer program product.
[0131] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium can at least include: any entity or device that can carry the computer program code to the camera / terminal device, recording medium, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, RandomAccess Memory), electric carrier signal, telecommunication signal and software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk or an optical disk. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electric carrier signals and telecommunication signals.
[0132] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0133] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0134] In the embodiments provided in the present application, it should be understood that the disclosed devices / network equipment and methods can be implemented in other ways. For example, the device / network equipment embodiments described above are merely schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0135] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0136] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. An instruction optimization method, characterized in that: include: Acquire monitoring data, where the monitoring data is obtained by monitoring the AI processor when the AI processor executes the instruction combination, and is used to record the operating efficiency of each computing unit in the AI processor; According to the monitoring data, the instruction combination is analyzed to determine the optimization data of the instruction combination; wherein, the position and number of occurrences of each identical instruction in the instruction combination in the instruction combination are determined, and combined with the operation efficiency of the computing unit indicated in the monitoring data, it is determined whether the instruction needs to be optimized, and if it is determined that the instruction needs to be optimized, then the optimization method for optimizing the instruction is determined in combination with the position and number of occurrences of the instruction; The instruction combination is optimized according to the optimization data.
2. The method according to claim 1, characterized in that The step of analyzing the monitoring data in combination with the instruction combination to determine the optimization data of the instruction combination includes: For each instruction in the instruction combination, determining whether the instruction is a common instruction; If the instruction is a commonly used instruction, the encapsulated instruction is used as the optimization data of the instruction combination.
3. The method according to claim 2, characterized in that The encapsulating instruction as the optimization data of the instruction combination comprises: For each instruction in the instruction combination, if the instruction appears multiple times in a loop in the instruction combination, encapsulating the loop as the optimization data of the instruction combination; If the instruction appears randomly multiple times in the instruction combination, a function call is encapsulated as the optimization data of the instruction combination.
4. The method according to claim 1, characterized in that After optimizing the instruction combination according to the optimization data, the method further includes: Acquire multiple instruction combinations, each of which is optimized based on a previous instruction combination; Determine the monitoring data corresponding to each of the instruction combinations; According to the plurality of monitoring data, a target instruction combination is determined from the plurality of instruction combinations, and the operating efficiency of each computing unit in the AI processor indicated by the monitoring data corresponding to the target instruction combination is the highest.
5. The method according to any one of claims 1 to 4, characterized in that: Before acquiring the monitoring data, the method further includes: Get multiple instructions from a preset instruction set; Generating the instruction combination according to the logical relationship between the instructions; The instruction combination is executed by the AI processor.
6. An instruction optimization device, characterized in that: include: A first acquisition module is used to acquire monitoring data, where the monitoring data is obtained by monitoring the AI processor when the AI processor executes the instruction combination, and is used to record the operating efficiency of each computing unit in the AI processor; A first determination module is used to parse the monitoring data in combination with the instruction combination to determine optimization data of the instruction combination; wherein, the position and number of occurrences of each identical instruction in the instruction combination in the instruction combination are determined, and combined with the operating efficiency of the computing unit indicated in the monitoring data, it is determined whether the instruction needs to be optimized, and if it is determined that the instruction needs to be optimized, then the optimization method for optimizing the instruction is determined in combination with the position and number of occurrences of the instruction; An optimization module is used to optimize the instruction combination according to the optimization data.
7. The device according to claim 6, characterized in that The first determination module is further configured to determine, for each instruction in the instruction combination, whether the instruction is a commonly used instruction; if the instruction is a commonly used instruction, use the encapsulated instruction as the optimization data of the instruction combination.
8. The device according to claim 7, characterized in that The first determining module is further configured to encapsulate each instruction in the instruction combination as the optimization data of the instruction combination if the instruction appears multiple times in a loop in the instruction combination; If the instruction appears randomly multiple times in the instruction combination, a function call is encapsulated as the optimization data of the instruction combination.
9. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 5 is implemented.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Gaming system with performance tuning and optimized data sharing functions
US20140073432A1