Patent Publication Number: US-2017351525-A1

Title: Method and Apparatus for Allocating Hardware Acceleration Instruction to Memory Controller

Description:
CROSS-REFERENCE TO RELATED APPLICATIONS 
     This application is a continuation of International Patent Application No. PCT/CN2016/074450 filed on Feb. 24, 2016, which claims priority to Chinese Patent Application No. 201510092224.4 filed on Feb. 28, 2015. The disclosures of the aforementioned applications are hereby incorporated by reference in their entireties. 
    
    
     TECHNICAL FIELD 
     Embodiments of the present disclosure relate to the field of computer technologies, and in particular, to a method and an apparatus for allocating a hardware acceleration instruction to a memory controller. 
     BACKGROUND 
     A computer system includes two parts, computer hardware and software. The hardware includes a processor, a register, a cache, a memory, an external storage, and the like. The software is running programs of a computer and corresponding documents. When running a program, a computer operating system transmits data related to an instruction in the program to the cache or the register from the memory using a memory bus. Then, the processor obtains the data to execute the instruction, and further finish running of the program. Therefore, when a program is running, transmission of data related to an instruction in the program is a key factor that restricts a running speed of the program. Currently, to accelerate a running speed of a program, a mainly used method includes a method for accelerating a running speed of a program by increasing a physical bandwidth. For example, memory bus frequency is increased by increasing a transmission rate of a single pin, and memory access channels are increased by increasing a quantity of pins. However, due to a limit of a current packaging technology, it is difficult to expand a pin quantity of a chip on a large scale, and significantly increase a transmission rate of a single pin. 
     In consideration of the limit of the current packaging technology, and to adapt to applications of cloud computing and big data by increasing an execution speed of a software program, a method for increasing an execution speed of a software program in other approaches may include disposing a memory controller between the memory and the cache, and replacing some instructions of large-scale operations in a program with one or more variable-granularity hardware acceleration instructions. Therefore, these hardware acceleration instructions are run using the memory controller. This effectively reduces data transmission between the memory and the processor, and indirectly improves memory bandwidth usage. In addition, the instructions of large-scale operations in the program less occupy the processor. 
     However, when the hardware acceleration instruction is run using the memory controller, load imbalance of multiple memory controllers may be caused. Therefore, performance of the computer operating system is affected, and the applications of the cloud computing and the big data cannot be well adapted. 
     SUMMARY 
     Embodiments of the present disclosure provide a method and an apparatus for allocating a hardware acceleration instruction to a memory controller. Load balancing of memory controllers is implemented when multiple memory controllers in a computer system execute hardware acceleration instructions. Therefore, performance of the computer system is improved, and applications of cloud computing and big data are better satisfied. 
     According to a first aspect, an embodiment of the present disclosure provides a method for allocating a hardware acceleration instruction to a memory controller, where the method is applied to a computer system, the computer system includes multiple memory controllers that can execute hardware acceleration instructions, and the method includes the following steps. Dividing multiple hardware acceleration instructions into different instruction sets according to dependency relationships among the multiple hardware acceleration instructions, where hardware acceleration instructions that belong to a same instruction set have a single-dependency relationship, and the single-dependency relationship indicates that if input data of one hardware acceleration instruction in the multiple hardware acceleration instructions is output data of another hardware acceleration instruction, the hardware acceleration instruction is singly dependent on the other hardware acceleration instruction, obtaining a first mapping relationship between the instruction sets and the memory controllers in the computer system according to a rule that different instruction sets whose hardware acceleration instructions do not have a dependency relationship are allocated to different memory controllers, where the dependency relationship indicates that if input data of one hardware acceleration instruction in the multiple hardware acceleration instructions is output data of another one or more hardware acceleration instructions, the hardware acceleration instruction is dependent on the other one or more hardware acceleration instructions, and memory controllers in the first mapping relationship compose a first memory controller set, adjusting the first mapping relationship according to load of the memory controllers in the first memory controller set in order to obtain a second mapping relationship between the instruction sets and the memory controllers in the computer system, where memory controllers in the second mapping relationship compose a second memory controller set, load of the memory controllers in the second memory controller set is not greater than a first preset threshold, and the load includes execution time slices of hardware acceleration instructions allocated to the memory controllers in the first memory controller set, and allocating hardware acceleration instructions in the instruction sets to the memory controllers in the second memory controller set according to the second mapping relationship, where hardware acceleration instructions in a same instruction set are allocated to a same memory controller for execution. 
     With reference to the first aspect, in a first implementation manner of the first aspect, adjusting includes randomly allocating an instruction set that is in the first mapping relationship and allocated to the memory controller whose load is greater than the first preset threshold, to another memory controller, in the computer system, whose load is less than the first preset threshold when a proportion of a memory controller, in the first memory controller set, whose load is greater than the first preset threshold is less than a second preset threshold in order to obtain the second mapping relationship between the instruction sets and the memory controllers in the computer system. 
     With reference to the first aspect, in a second implementation manner of the first aspect, adjusting includes obtaining a third memory controller set in the computer system, where load of memory controllers in the third memory controller set is not greater than the first preset threshold when a proportion of a memory controller, in the first memory controller set, whose load is greater than the first preset threshold is not less than a second preset threshold, and obtaining a second mapping relationship between the instruction sets and the memory controllers in the third memory controller set according to the rule that different instruction sets whose hardware acceleration instructions do not have a dependency relationship are allocated to different memory controllers. 
     With reference to the first aspect or the first implementation manner of the first aspect or the second implementation manner of the first aspect, in a third implementation manner of the first aspect, obtaining a first mapping relationship between the instruction sets and the memory controllers in the computer system includes obtaining a mapping relationship between an instruction set to a memory controller whose load is the smallest in at least two memory controllers that match the instruction set if the at least two memory controllers match the instruction set. 
     With reference to the first aspect or the first implementation manner of the first aspect or the second implementation manner of the first aspect, in a fourth implementation manner of the first aspect, an execution time slice of the hardware acceleration instruction is latency i (Fixed i ,Variable i )=Fixed i +Variable i (α i *data i /base_granularity i ), Fixed i  is a fixed execution time slice of the hardware acceleration instruction, Variable i  is a variable execution time slice of the hardware acceleration instruction, α i  is a data execution ratio of the hardware acceleration instruction, data i  is a data amount of the hardware acceleration instruction, and base_granularity i  is a smallest data granularity of the hardware acceleration instruction. 
     According to a second aspect, an embodiment of the present disclosure provides an apparatus for allocating a hardware acceleration instruction to a memory controller, where the apparatus is applied to a computer system, the computer system includes multiple memory controllers that can execute hardware acceleration instructions, and the apparatus includes a division module configured to divide multiple hardware acceleration instructions into different instruction sets according to dependency relationships among the multiple hardware acceleration instructions, where hardware acceleration instructions that belong to a same instruction set have a single-dependency relationship, and the single-dependency relationship indicates that if input data of one hardware acceleration instruction in the multiple hardware acceleration instructions is output data of another hardware acceleration instruction, the hardware acceleration instruction is singly dependent on the other hardware acceleration instruction, an obtaining module configured to obtain a first mapping relationship between the instruction sets and the memory controllers in the computer system according to a rule that different instruction sets whose hardware acceleration instructions do not have a dependency relationship are allocated to different memory controllers. The dependency relationship indicates that if input data of one hardware acceleration instruction in the multiple hardware acceleration instructions is output data of another one or more hardware acceleration instructions, the hardware acceleration instruction is dependent on the other one or more hardware acceleration instructions, and memory controllers in the first mapping relationship compose a first memory controller set, an adjustment module configured to adjust the first mapping relationship according to load of the memory controllers in the first memory controller set in order to obtain a second mapping relationship between the instruction sets and the memory controllers in the computer system. The memory controllers in the second mapping relationship compose a second memory controller set, load of the memory controllers in the second memory controller set is not greater than a first preset threshold, and the load includes execution time slices of hardware acceleration instructions allocated to the memory controllers in the first memory controller set, and an allocation module configured to allocate hardware acceleration instructions in the instruction sets to the memory controllers in the second memory controller set according to the second mapping relationship, where hardware acceleration instructions in a same instruction set are allocated to a same memory controller for execution. 
     With reference to the second aspect, in a first implementation manner of the second aspect, when a proportion of a memory controller, in the first memory controller set, whose load is greater than the first preset threshold is less than a second preset threshold, the adjustment module is further configured to randomly allocate an instruction set that is in the first mapping relationship and allocated to the memory controller whose load is greater than the first preset threshold, to another memory controller, in the computer system, whose load is less than the first preset threshold in order to obtain the second mapping relationship between the instruction sets and the memory controllers in the computer system. 
     With reference to the second aspect, in a second implementation manner of the second aspect, when a proportion of a memory controller, in the first memory controller set, whose load is greater than the first preset threshold is not less than a second preset threshold, the adjustment module is further configured to obtain a third memory controller set in the computer system, where load of memory controllers in the third memory controller set is not greater than the first preset threshold, and obtain a second mapping relationship between the instruction sets and the memory controllers in the third memory controller set according to the rule that different instruction sets whose hardware acceleration instructions do not have a dependency relationship are allocated to different memory controllers. 
     With reference to the second aspect or the first implementation manner of the second aspect or the second implementation manner of the second aspect, in a third implementation manner of the second aspect, the obtaining module is further configured to obtain a mapping relationship between an instruction set and a memory controller whose load is the smallest in at least two memory controllers that match the instruction set if the at least two memory controllers match the instruction set. 
     With reference to the second aspect or the first implementation manner of the second aspect or the second implementation manner of the second aspect, in a fourth implementation manner of the second aspect, an execution time slice of the hardware acceleration instruction is latency i (Fixed i ,Variable i )=Fixed i +Variable i (α i *data i /base_granularity i ), Fixed i  is a fixed execution time slice of the hardware acceleration instruction, Variable i  is a variable execution time slice of the hardware acceleration instruction, α i  is a data execution ratio of the hardware acceleration instruction, data i  is a data amount of the hardware acceleration instruction, and base_granularity i  is a smallest data granularity of the hardware acceleration instruction. 
     According to the method and the apparatus for allocating a hardware acceleration instruction provided in the embodiments of the present disclosure, multiple hardware acceleration instructions are divided into different instruction sets according to dependency relationships among the multiple hardware acceleration instructions. Hardware acceleration instructions that belong to a same instruction set have a single-dependency relationship, and the single-dependency relationship indicates that if input data of one hardware acceleration instruction in the multiple hardware acceleration instructions is output data of another hardware acceleration instruction, the hardware acceleration instruction is singly dependent on the other hardware acceleration instruction. A first mapping relationship between the instruction sets and memory controllers in a computer system is obtained according to a rule that different instruction sets whose hardware acceleration instructions do not have a dependency relationship are allocated to different memory controllers. The dependency relationship indicates that if input data of one hardware acceleration instruction in the multiple hardware acceleration instructions is output data of another one or more hardware acceleration instructions, the hardware acceleration instruction is dependent on the other one or more hardware acceleration instructions, and memory controllers in the first mapping relationship compose a first memory controller set. The first mapping relationship is adjusted according to load of the memory controllers in the first memory controller set in order to obtain a second mapping relationship between the instruction sets and the memory controllers in the computer system. Memory controllers in the second mapping relationship compose a second memory controller set, load of the memory controllers in the second memory controller set is not greater than a first preset threshold, and the load includes execution time slices of hardware acceleration instructions allocated to the memory controllers in the first memory controller set. Hardware acceleration instructions in the instruction sets are allocated to the memory controllers in the second memory controller set according to the second mapping relationship. Hardware acceleration instructions in a same instruction set are allocated to a same memory controller for execution. Load balancing of memory controllers is implemented when multiple memory controllers in the computer system execute hardware acceleration instructions. Therefore, performance of the computer system is improved, and applications of cloud computing and big data are better satisfied. 
    
    
     
       BRIEF DESCRIPTION OF DRAWINGS 
       To describe the technical solutions in the embodiments of the present disclosure more clearly, the following briefly describes the accompanying drawings required for describing the embodiments. The accompanying drawings in the following description are merely accompanying drawings of some embodiments of the present disclosure. 
         FIG. 1  is a flowchart of a method for allocating a hardware acceleration instruction to a memory controller according to an embodiment of the present disclosure; 
         FIG. 2  is a schematic diagram of dependency relationships among multiple hardware acceleration instructions according to an embodiment of the present disclosure; 
         FIG. 3A  and  FIG. 3B  are a flowchart of another method for allocating a hardware acceleration instruction to a memory controller according to an embodiment of the present disclosure; and 
         FIG. 4  is a schematic structural diagram of an apparatus for allocating a hardware acceleration instruction to a memory controller according to an embodiment of the present disclosure. 
     
    
    
     DESCRIPTION OF EMBODIMENTS 
     To make the objectives, technical solutions, and advantages of the embodiments of the present disclosure clearer, the following clearly describes the technical solutions in the embodiments of the present disclosure with reference to the accompanying drawings in the embodiments of the present disclosure. The described embodiments are some but not all of the embodiments of the present disclosure. 
       FIG. 1  is a flowchart of a method for allocating a hardware acceleration instruction to a memory controller according to an embodiment of the present disclosure. As shown in  FIG. 1 , this embodiment is executed by a computer. The method is applied to a computer system, and the computer system includes multiple memory controllers that can execute hardware acceleration instructions. Further, the method may be implemented in a manner of hardware or a combination of software and hardware. The method includes the following steps. 
     Step  101 : Divide multiple hardware acceleration instructions into different instruction sets according to dependency relationships among the multiple hardware acceleration instructions. 
     In this embodiment, a hardware acceleration instruction refers to an instruction, in a program, that can be independently executed on the memory controller. The hardware acceleration instruction is generally an instruction, in a program, that requires a large-scale operation and a small computing amount. For example, a matrix transpose instruction, a matrix reset instruction, and a variable-granularity read/write instruction in a form of a message packet. 
     In this embodiment, before an instruction in a program is executed, when performing static compilation on the program, a compiler uses a conventional compiling identification method, and identifies multiple hardware acceleration instructions in the program. 
     After the compiler identifies the multiple hardware acceleration instructions in the program, the multiple hardware acceleration instructions are divided into different instruction sets according to dependency relationships among the multiple hardware acceleration instructions. 
     The dependency relationship indicates that if input data of one hardware acceleration instruction in multiple hardware acceleration instructions is output data of another one or more hardware acceleration instructions, the hardware acceleration instruction is dependent on the other one or more hardware acceleration instructions. 
     The dependency relationship includes a single-dependency relationship and a multiple-dependency relationship. If input data of one hardware acceleration instruction in multiple hardware acceleration instructions is output data of another hardware acceleration instruction, the hardware acceleration instruction is singly dependent on the other hardware acceleration instruction. This dependency relationship is a single-dependency relationship. If input data of one hardware acceleration instruction in multiple hardware acceleration instructions is output data of multiple other hardware acceleration instructions, the hardware acceleration instruction is multiply dependent on the multiple other hardware acceleration instructions. This dependency relationship is a multiple-dependency relationship. 
     If there is a dependency relationship among hardware acceleration instructions, one or more hardware acceleration instructions on which one hardware acceleration instruction is dependent are parent hardware acceleration instructions, and the dependent hardware acceleration instruction is a son hardware acceleration instruction. When a program is being executed, parent hardware acceleration instructions are executed before a son hardware acceleration instruction. Therefore, when multiple hardware acceleration instructions in the program are allocated to the memory controllers in the computer system, the parent hardware acceleration instructions are first allocated, and then the son hardware acceleration instruction is allocated. 
     In this embodiment, when executing hardware acceleration instructions, the memory controllers execute parent hardware acceleration instructions before a son hardware acceleration instruction. Therefore, when multiple hardware acceleration instructions are being allocated to the memory controllers, hardware acceleration instructions that have a single-dependency relationship may be allocated to a same memory controller for execution. Therefore, in this embodiment, multiple hardware acceleration instructions are divided into different instruction sets according to dependency relationships among the multiple hardware acceleration instructions. 
     Hardware acceleration instructions that belong to a same instruction set have a single-dependency relationship. Therefore, hardware acceleration instructions in different instruction sets have two sorts of relationships. The first relationship is that the hardware acceleration instructions in different instruction sets do not have a dependency relationship. The other relationship is that the hardware acceleration instructions in different instruction sets have a multiple-dependency relationship. 
       FIG. 2  is a schematic diagram of dependency relationships among multiple hardware acceleration instructions according to an embodiment of the present disclosure. As shown in  FIG. 2 , the program includes seven hardware acceleration instructions in total. If there is one arrow between hardware acceleration instructions, it indicates that the hardware acceleration instructions have a single-dependency relationship. If there are multiple arrows between hardware acceleration instructions, it indicates that the hardware acceleration instructions have a multiple-dependency relationship. A hardware acceleration instruction from which an arrow extends is a parent hardware acceleration instruction, and a hardware acceleration instruction to which an arrow points is a son hardware acceleration instruction. In  FIG. 2 , hardware acceleration instructions 1, 2, and 3 have a single-dependency relationship, and compose an instruction set a. Hardware acceleration instructions 4 and 5 have a single-dependency relationship, and compose an instruction set b. Hardware acceleration instructions 6 and 7 have a single-dependency relationship, and compose an instruction set c. Hardware acceleration instructions that are in the instruction set a and the instruction set b do not have a dependency relationship. The hardware acceleration instruction 6 in the instruction set c, the hardware acceleration instruction 3 in the instruction set a, and the hardware acceleration instruction 5 in the instruction set b have a multiple-dependency relationship. 
     Step  102 : Obtain a first mapping relationship between the instruction sets and the memory controllers in the computer system according to a rule that different instruction sets whose hardware acceleration instructions do not have a dependency relationship are allocated to different memory controllers. 
     In this embodiment, after the multiple hardware acceleration instructions are divided into different instruction sets, when the multiple instruction sets are being allocated, if hardware acceleration instructions in different instruction sets do not have a dependency relationship, it indicates that the hardware acceleration instructions in the different instruction set do not have a time sequence relationship and can be concurrently executed in the memory controllers in the computer system. Therefore, to reduce an execution time, in the memory controllers of the computer system, of hardware acceleration instructions in a program, different instruction sets are allocated to the memory controllers in the computer system according to the rule that different instruction sets whose hardware acceleration instructions do not have a dependency relationship are allocated to different memory controllers in order to obtain the first mapping relationship between the instruction sets and the memory controllers in the computer system. 
     In the foregoing example, when the first mapping relationship between the instruction sets and the memory controllers in the computer system is obtained according to the rule that different instruction sets whose hardware acceleration instructions do not have a dependency relationship are allocated to different memory controllers. For an example, with respect to  FIG. 2 , the instruction set a and the instruction set b are allocated to different memory controllers. The instruction set c may be allocated to a memory controller same as that of the instruction set a or the instruction set b, or the instruction set c may be allocated to a memory controller different from that of the instruction set a and the instruction set b. 
     Memory controllers in the obtained first mapping relationship between the instruction sets and the memory controllers in the computer system compose a first memory controller set. The first memory controller set may be a part or all of the memory controllers in the computer system. If a quantity of the instruction sets is less than a quantity of the memory controllers, the first memory controller set includes a part of the memory controllers in the computer system. If a quantity of the instruction sets is not less than a quantity of the memory controllers, the first memory controller set in the first mapping relationship between the instruction sets and the memory controllers in the computer system includes a part or all of the memory controllers in the computer system, where the first mapping relationship is obtained according to the rule that different instruction sets whose hardware acceleration instructions do not have a dependency relationship are allocated to different memory controllers. 
     Step  103 : Adjust the first mapping relationship according to load of memory controllers in a first memory controller set in order to obtain a second mapping relationship between the instruction sets and the memory controllers in the computer system. 
     In this embodiment, when the first mapping relationship between the instruction sets and the memory controllers in the computer system is obtained in order to reduce execution time slices of hardware acceleration instructions allocated to all memory controllers in the first memory controller set, the followed rule does not fully consider whether the execution time slices of the hardware acceleration instructions allocated to the memory controllers in the first memory controller set are balanced. Therefore, after the first mapping relationship is obtained, the first mapping relationship is adjusted according to the load of the memory controllers in the first memory controller set in order to obtain the second mapping relationship between the instruction sets and the memory controllers in the computer system. 
     Memory controllers in the second mapping relationship compose a second memory controller set after the first mapping relationship is adjusted. Load of the memory controllers in the second memory controller set is not greater than a first preset threshold. 
     In this embodiment, the first preset threshold may be preset according to the load of the memory controllers in the first memory controller set before the hardware acceleration instruction in the program is executed. 
     The load includes execution time slices of hardware acceleration instructions allocated to the memory controllers in the first memory controller set. 
     Step  104 : Allocate hardware acceleration instructions in the instruction sets to memory controllers in a second memory controller set according to the second mapping relationship. 
     In this embodiment, hardware acceleration instructions in a same instruction set have a single-dependency relationship, that is, the hardware acceleration instructions in the same instruction set have a time sequence relationship that a parent hardware acceleration instruction is executed before a son hardware acceleration instruction. Therefore, the hardware acceleration instructions in the same instruction set are allocated to a same memory controller for execution. 
     In this embodiment, the hardware acceleration instructions in the instruction sets are allocated to the memory controllers in the second memory controller set according to the second mapping relationship. The memory controllers in the second memory controller set execute the hardware acceleration instructions according to an allocation sequence. 
     In this embodiment, multiple hardware acceleration instructions are divided into different instructions sets according to dependency relationships among the multiple hardware acceleration instructions. A first mapping relationship between the instruction sets and memory controllers in a computer system is obtained according to a rule that different instruction sets whose hardware acceleration instructions do not have a dependency relationship are allocated to different memory controllers. The first mapping relationship is adjusted according to load of memory controllers in a first memory controller set in order to obtain a second mapping relationship between the instruction sets and the memory controllers in the computer system. Memory controllers in the second mapping relationship compose a second memory controller set. Load of the memory controllers in the second memory controller set is not greater than a first preset threshold. Hardware acceleration instructions in the instruction sets are allocated to the memory controllers in the second memory controller set according to the second mapping relationship. The first mapping relationship is adjusted, and the load of the memory controllers in the obtained second mapping relationship is not greater than the first preset threshold. Therefore, when the hardware acceleration instructions in the instruction sets are executed according to the second mapping relationship, load balancing of the memory controllers in the computer system is implemented, performance of a computer operating system is further improved, and applications of cloud computing and big data are better satisfied. 
       FIG. 3A  and  FIG. 3B  are a flowchart of another method for allocating a hardware acceleration instruction to a memory controller according to an embodiment of the present disclosure. As shown in  FIG. 3A  and  FIG. 3B , this embodiment is executed by a computer. The method is applied to a computer system, and the computer system includes multiple memory controllers that can execute hardware acceleration instructions. Further, the method may be implemented in a manner of hardware or a combination of software and hardware. The method includes the following steps. 
     Step  301 : Divide multiple hardware acceleration instructions into different instruction sets according to dependency relationships among the multiple hardware acceleration instructions. 
     Hardware acceleration instructions that belong to a same instruction set have a single-dependency relationship. The single-dependency relationship indicates that if input data of one hardware acceleration instruction in multiple hardware acceleration instructions is output data of another hardware acceleration instruction, the hardware acceleration instruction is singly dependent on the other hardware acceleration instruction. 
     In this embodiment, step  301  is the same as step  101  in Embodiment 1 of the method for allocating a hardware acceleration instruction to a memory controller in the present disclosure, and is not repeatedly described herein. 
     Step  302 : Obtain a first mapping relationship between the instruction sets and the memory controllers in the computer system according to a rule that different instruction sets whose hardware acceleration instructions do not have a dependency relationship are allocated to different memory controllers, where memory controllers in the first mapping relationship compose a first memory controller set. 
     In this embodiment, the first memory controller set may be a part or all of the memory controllers in the computer system. The first memory controller set includes a part of the memory controllers in the computer system if a quantity of the instruction sets is less than a quantity of the memory controllers, or the first memory controller set in the first mapping relationship between the instruction sets and the memory controllers in the computer system includes a part or all of the memory controllers in the computer system if a quantity of the instruction sets is not less than a quantity of the memory controllers, where the first mapping relationship is obtained according to the rule that different instruction sets whose hardware acceleration instructions do not have a dependency relationship are allocated to different memory controllers. 
     Further, in this embodiment, when the first mapping relationship between the instruction sets and the memory controllers in the computer system is obtained, if there are at least two memory controllers that match one instruction set, the instruction set is allocated to a memory controller whose load is the smallest in the at least two memory controllers that match the instruction set. 
     In this embodiment, when the first mapping relationship between the instruction sets and the memory controllers in the computer system is obtained according to the rule that different instruction sets whose hardware acceleration instructions do not have a dependency relationship are allocated to different memory controllers, the instruction set is allocated to a memory controller whose load is the smallest in the at least two memory controllers that match the instruction set if there are at least two memory controllers that match one instruction set. The memory controllers in the first memory controller set are load-balanced as much as possible while load of the memory controllers in the first memory controller set is reduced. 
     The load includes execution time slices of hardware acceleration instructions allocated to the memory controllers in the first memory controller set. 
     Further, in this embodiment, because specific operations and computing data of multiple hardware acceleration instructions in a program are different, an execution time slice of each hardware acceleration instruction is also different. 
     Further, an execution time slice latency i (Fixed i ,Variable i ) of a hardware acceleration instruction may be indicated by formula (1): 
       latency i (Fixed i ,Variable i )=Fixed i +Variable i (α i *data i /base_granularity i ),  (1)
 
     where Fixed i  is a fixed execution time slice of an i th  hardware acceleration instruction, and indicates a time slice required for parsing and scheduling the hardware acceleration instruction. Because time slices for parsing and scheduling all hardware acceleration instructions are approximately equal, fixed execution time slices of all the hardware acceleration instructions are approximately equal. In this embodiment, the fixed execution time slices of all the hardware acceleration instructions may be set to a same value. 
     Variable i  is a variable execution time slice of the hardware acceleration instruction. Each hardware acceleration instruction has a different variable execution time. For example, if a hardware acceleration instruction is a read instruction, a variable execution time slice of the hardware acceleration instruction is much affected by a data amount of the read instruction and a smallest data granularity of the read instruction. For another example, if a hardware acceleration instruction is a matrix transpose instruction, a variable execution time slice of the hardware acceleration instruction is affected by a data amount of a matrix and a smallest data granularity during matrix transposition, and is also affected by a data execution rate. For a different hardware acceleration instruction, a variable execution time slice of the hardware acceleration instruction is computed according to a data execution rate α i  of the hardware acceleration instruction, a data amount data i  of the hardware acceleration instruction, and a smallest data granularity base_granularity i  of the hardware acceleration instruction. 
     In this embodiment, an execution time slice of each hardware acceleration instruction is a sum of a fixed execution time slice and a variable execution time slice of the hardware acceleration instruction. 
     In this embodiment, load allocated to the memory controllers in the computer system can be accurately computed according to the execution time slices of all the hardware acceleration instructions. A load-balancing level of the memory controllers is further improved when the hardware acceleration instructions in the instruction sets are allocated to the memory controllers in the computer system, and the memory controllers execute the hardware acceleration instructions. 
     Step  303 : Determine whether a proportion of a memory controller, in the first memory controller set, whose load is greater than a first preset threshold is less than a second preset threshold, and if the proportion is less than the second preset threshold, execute step  304 , or if the proportion is not less than the second preset threshold, execute step  305 . 
     In this embodiment, the first preset threshold may be preset according to the load of the memory controllers in the first memory controller set before the hardware acceleration instruction in the program is executed. The second preset threshold may be preset, for example, 2/5, or may be another threshold. This is not limited in this embodiment. 
     Step  304 : Randomly allocate an instruction set that is in the first mapping relationship and allocated to the memory controllers whose load is greater than the first preset threshold, to another memory controller, in the computer system, whose load is less than the first preset threshold in order to obtain a second mapping relationship between the instruction sets and the memory controllers in the computer system. 
     In this embodiment, when the proportion of the memory controller, in the first memory controller set, whose load is greater than the first preset threshold is less than the second preset threshold, it indicates that, if there are at least two memory controllers that match one instruction set, according to the rule that different instruction sets whose hardware acceleration instructions do not have a dependency relationship are allocated to different memory controllers, the instruction set is allocated to a memory controller whose load is the smallest in the at least two memory controllers that match the instruction set. In the obtained first mapping relationship between the instruction sets and the memory controllers in the computer system, load of the memory controllers in the first memory controller set is relatively balanced. In order that no instruction set is allocated anymore to the memory controller whose load is greater that the first preset threshold, the instruction set that is in the first mapping relationship and allocated to the memory controller whose load is greater than the first preset threshold is randomly allocated to another memory controller, in the computer system, whose load is less than the first preset threshold in order to obtain the second mapping relationship between the instruction sets and the memory controllers in the computer system. 
     Step  305 : Obtain a third memory controller set in the computer system, where load of memory controllers in the third memory controller set is not greater than the first preset threshold, and obtain a second mapping relationship between the instruction sets and the memory controllers in the third memory controller set according to the rule that different instruction sets whose hardware acceleration instructions do not have a dependency relationship are allocated to different memory controllers. 
     In this embodiment, when the proportion of the memory controller, in the first memory controller set, whose load is greater than the first preset threshold is not less than the second preset threshold, it indicates that, if there are at least two memory controllers that match one instruction set, according to the rule that different instruction sets whose hardware acceleration instructions do not have a dependency relationship are allocated to different memory controllers, the instruction set is allocated to a memory controller whose load is the smallest in the at least two memory controllers that match the instruction set. In the obtained first mapping relationship between the instruction sets and the memory controllers in the computer system, a load balancing effect of the memory controllers in the first memory controller set is not good. To ensure load balancing of the memory controllers in the computer system, memory controllers, in the computer system, whose load is not greater than the first preset threshold are obtained, and the memory controllers, in the computer system, whose load is not greater than the first preset threshold compose the third memory controller set. 
     After the third memory controller set in the computer system is obtained, the second mapping relationship between the instruction sets and the memory controllers in the third memory controller set is obtained according to the rule that different instruction sets whose hardware acceleration instructions do not have a dependency relationship are allocated to different memory controllers. 
     Further, in this embodiment, when the second mapping relationship between the instruction sets and the memory controllers in the third memory controller set is obtained, if there are at least two memory controllers that match one instruction set, the instruction set is allocated to a memory controller whose load is the smallest in the at least two memory controllers that match the instruction set. 
     Step  306 : Allocate hardware acceleration instructions in the instruction sets to memory controllers in a second memory controller set according to the second mapping relationship. 
     In this embodiment, hardware acceleration instructions in a same instruction set have a single-dependency relationship, that is, the hardware acceleration instructions in the same instruction set have a time sequence relationship that a parent hardware acceleration instruction is executed before a son hardware acceleration instruction. Therefore, the hardware acceleration instructions in the same instruction set are allocated to a same memory controller for execution. 
     In this embodiment, when a first mapping relationship between instruction sets and memory controllers in a computer system is obtained, if there are at least two memory controllers that match one instruction set, the instruction set is allocated to a memory controller whose load is the smallest in the at least two memory controllers that match the instruction set. This improves a load balancing level of memory controllers in a first memory controller set of the obtained first mapping relationship. In addition, when a proportion of a memory controller, in the first memory controller set, whose load is greater than a first preset threshold is less than a second preset threshold, an instruction set that is in the first mapping relationship and allocated to the memory controller whose load is greater than the first preset threshold is randomly allocated to another memory controller, in the computer system, whose load is less than the first preset threshold. When a proportion of a memory controller, in the first memory controller set, whose load is greater than a first preset threshold is not less than a second preset threshold, a second mapping relationship between the instruction sets and memory controllers in a third memory controller set is obtained according to a rule that different instruction sets whose hardware acceleration instructions do not have a dependency relationship are allocated to different memory controllers such that load of memory controllers in the second mapping relationship is not greater than the first preset threshold. Therefore, in this embodiment, when multiple hardware acceleration instructions are allocated to the memory controllers in the computer system, two time slices of load balancing processing is performed successively such that when multiple memory controllers in the computer system execute hardware acceleration instructions, the memory controllers are more load-balanced. 
       FIG. 4  is a schematic structural diagram of an apparatus for allocating a hardware acceleration instruction to a memory controller according to an embodiment of the present disclosure. The apparatus is applied to a computer system, and the computer system includes multiple memory controllers that can execute hardware acceleration instructions. As shown in  FIG. 4 , the apparatus for allocating a hardware acceleration instruction to a memory controller includes a division module  401 , an obtaining module  402 , an adjustment module  403 , and an allocation module  404 . 
     The division module  401  is configured to divide multiple hardware acceleration instructions into different instruction sets according to dependency relationships among the multiple hardware acceleration instructions. 
     Hardware acceleration instructions that belong to a same instruction set have a single-dependency relationship. The single-dependency relationship indicates that if input data of one hardware acceleration instruction in multiple hardware acceleration instructions is output data of another hardware acceleration instruction, the hardware acceleration instruction is singly dependent on the other hardware acceleration instruction. 
     The obtaining module  402  is configured to obtain a first mapping relationship between the instruction sets and the memory controllers in the computer system according to a rule that different instruction sets whose hardware acceleration instructions do not have a dependency relationship are allocated to different memory controllers. 
     The dependency relationship indicates that if input data of one hardware acceleration instruction in multiple hardware acceleration instructions is output data of another one or more hardware acceleration instructions, the hardware acceleration instruction is dependent on the other one or more hardware acceleration instructions. Memory controllers in the first mapping relationship compose a first memory controller set. 
     In this embodiment, the dependency relationship includes a single-dependency relationship and a multiple-dependency relationship. The multiple-dependency relationship indicates that if input data of one hardware acceleration instruction in multiple hardware acceleration instructions is output data of multiple other hardware acceleration instructions, the hardware acceleration instruction is multiply dependent on the multiple other hardware acceleration instructions. 
     The adjustment module  403  is configured to adjust the first mapping relationship according to load of memory controllers in the first memory controller set in order to obtain a second mapping relationship between the instruction sets and the memory controllers in the computer system. 
     Memory controllers in the second mapping relationship compose a second memory controller set. Load of the memory controllers in the second memory controller set is not greater than a first preset threshold. The load includes execution time slices of hardware acceleration instructions allocated to the memory controllers in the first memory controller set. 
     In this embodiment, the first preset threshold may be preset according to the load of the memory controllers in the first memory controller set before the hardware acceleration instruction in the program is executed. 
     The allocation module  404  is configured to allocate hardware acceleration instructions in the instruction sets to the memory controllers in the second memory controller set according to the second mapping relationship. 
     Hardware acceleration instructions in a same instruction set are allocated to a same memory controller for execution. 
     The apparatus for allocating a hardware acceleration instruction to a memory controller in this embodiment may be configured to execute the technical solution in the method embodiment shown in  FIG. 1 . Implementation rules and technical effects of the apparatus are similar to those of the method, and details are not described herein. 
     The adjustment module  403  is further configured to randomly allocate an instruction set that is in the first mapping relationship and allocated to the memory controller whose load is greater than the first preset threshold, to another memory controller, in the computer system, whose load is less than the first preset threshold in order to obtain the second mapping relationship between the instruction sets and the memory controllers in the computer system when a proportion of the memory controller, in the first memory controller set, whose load is greater than the first preset threshold is less than a second preset threshold. 
     Alternatively, when a proportion of a memory controller, in the first memory controller set, whose load is greater than the first preset threshold is not less than a second preset threshold, the adjustment module  403  is further configured to obtain a third memory controller set in the computer system, where load of memory controllers in the third memory controller set is not greater than the first preset threshold, and obtain a second mapping relationship between the instruction sets and the memory controllers in the third memory controller set according to the rule that different instruction sets whose hardware acceleration instructions do not have a dependency relationship are allocated to different memory controllers. 
     Further, if there are at least two memory controllers that match one instruction set, the obtaining module  402  is further configured to allocate the instruction set to a memory controller whose load is the smallest in the at least two memory controllers that match the instruction set. 
     Further, an execution time slice of a hardware acceleration instruction in this embodiment is latency i (Fixed i ,Variable i )=Fixed i +Variable i (α i *data i /base —  granularity i ), Fixed i  is a fixed execution time slice of the hardware acceleration instruction, Variable i  is a variable execution time slice of the hardware acceleration instruction, α i  is a data execution rate of the hardware acceleration instruction, data i  is a data amount of the hardware acceleration instruction, and base_granularity i  is a smallest data granularity of the hardware acceleration instruction. 
     Further, Fixed i  is a fixed execution time slice of an i th  hardware acceleration instruction, and indicates a time slice required for parsing and scheduling the hardware acceleration instruction. Because time slices for parsing and scheduling all hardware acceleration instructions are approximately equal, fixed execution time slices of all the hardware acceleration instructions are approximately equal. In this embodiment, the fixed execution time slices of all the hardware acceleration instructions may be set to a same value. Each hardware acceleration instruction has a different variable execution time. In this embodiment, a variable execution time slice Variable i  of a hardware acceleration instruction is computed according to a data execution rate α i  of the hardware acceleration instruction, a data amount data i  of the hardware acceleration instruction, and a smallest data granularity base_granularity i  of the hardware acceleration instruction. 
     Further, the apparatus for allocating a hardware acceleration instruction to a memory controller in this embodiment may be configured to execute the technical solution in the method embodiment shown in  FIG. 3A  and  FIG. 3B . Implementation rules and technical effects of the apparatus are similar to those of the method, and details are not described herein. 
     Persons of ordinary skill in the art may understand that all or some of the steps of the method embodiments may be implemented by a program instructing relevant hardware. The program may be stored in a computer-readable storage medium. When the program runs, the steps of the method embodiments are performed. The foregoing storage medium includes any medium that can store program code, such as a read only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disc. 
     Finally, it should be noted that the foregoing embodiments are merely intended for describing the technical solutions of the present disclosure, rather than limiting the present disclosure. The embodiments provided in this specification are merely examples. Persons skilled in the art may clearly know that, for convenience and conciseness of description, in the foregoing embodiments, the embodiments emphasize different aspects, and for a part not described in detail in one embodiment, reference may be made to relevant description of another embodiment. The embodiments of the present disclosure, claims, and features disclosed in the accompanying drawings may exist independently, or exist in a combination. Features described in a hardware form in the embodiments of the present disclosure may be executed by software, and vice versa. This is not limited herein.