Resource allocation method, device, electronic device and storage medium
By evaluating and optimizing the compilation method, combining the allocation method of basic resource blocks and genetic algorithms, the problem of low resource allocation efficiency of existing compilers is solved, and a more efficient resource allocation effect is achieved.
Patent Information
- Application Number
- CN202210130544.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-11
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2042-02-11
AI Technical Summary
Existing compilers are inefficient in resource allocation, resulting in inability to flexibly adjust parameters and algorithms, which leads to poor resource allocation results.
By evaluating different compilation methods, selecting compilation methods that meet the requirements, completing resource allocation for multi-objective optimization problems given resource limitations, and generating better allocation effects. The specific method includes generating parameters according to the allocation method of the basic resource blocks, compiling the object code to obtain evaluation results, and optimizing resource allocation using objective functions and genetic algorithms.
It improves the resource allocation efficiency during the compilation process, and can obtain better resource allocation results in different scenarios, solving the problem of insufficient resource allocation flexibility in traditional methods.
Smart Images

Figure CN114461398B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computers, and in particular to a method, device, electronic device and storage medium for resource allocation. Background Art
[0002] With the widespread application of Domain-Specific Architecture (DSA) in proprietary fields, compiler technology has also developed significantly.
[0003] Compilation resource allocation itself is a multi-objective optimization problem. Each resource has its own constraints and specifications. Resources are also related due to target hardware constraints. In order to allocate resources in the compiler, a heuristic method is usually adopted, focusing on certain key resources and using a greedy algorithm to complete all resource allocation.
[0004] Since the above method adopts a single-point algorithm, the resource allocation efficiency is low during the compilation process. Summary of the invention
[0005] The embodiments of the present application disclose a method, device, electronic device and storage medium for resource allocation. By evaluating different compilation methods and selecting a compilation method whose evaluation results meet the requirements, resource allocation for a multi-objective optimization problem is completed under given resource constraints, thereby obtaining a better allocation effect.
[0006] In a first aspect, the present application provides a method, device, electronic device and storage medium for resource allocation, the method comprising: generating at least one first parameter according to an allocation method of at least one resource basic block, the first parameter being used to represent an initial allocation method of the resource basic block, the resource basic block comprising at least one associated resource; compiling a target code according to the at least one first parameter and the resource basic block to obtain a ratio corresponding to the at least one first parameter, the ratio being used to represent a ratio of remaining resources in the resource basic block to total resources occupied by the terminal after the terminal compiles using the resource basic block, the target code being a code loaded onto a target chip by the terminal; determining a target evaluation result according to the ratio corresponding to the at least one first parameter, a target function and a first numerical value, the target evaluation result being greater than or equal to the first numerical value, the first parameter corresponding to the target evaluation result being a target parameter, the target parameter representing an updated allocation relationship of the resource basic block, the target function being obtained based on a weight of the resource basic block and a first function used by the resource basic block, the first function being used to obtain a dynamic weight of the resource basic block.
[0007] The embodiment of the present application generates at least one first parameter according to the allocation method of resource basic blocks, and can comprehensively consider the combination of different allocation methods of different resource basic blocks. By compiling the first parameter and calculating the compilation evaluation result, the compilation evaluation result can represent the resource allocation efficiency when the resource basic block allocation method of the first parameter is adopted. Therefore, based on the screened excellent compilation results, an allocation method of resource basic blocks with higher allocation efficiency can be obtained, thereby effectively improving the resource allocation efficiency in the compilation process.
[0008] In a possible implementation manner of the first aspect, the objective function satisfies the following conditions:
[0009]
[0010] The RBB0 represents the first resource basic block. n-1 represents the nth resource basic block, the F(RBB0…RBB n-1 ) represents the objective function, the W i represents the weight of the i+1th resource basic block in the resource basic block, the AF i represents the first function used by the i+1th resource basic block in the resource basic block, the RP i It represents the ratio corresponding to the i+1th resource basic block corresponding to the first parameter, where n is a positive integer, i∈[0,n-1].
[0011] In a possible implementation of the first aspect, the W i The following conditions must be met:
[0012] W i ∈(0,1];
[0013]
[0014] The W i represents the weight of the i+1th resource basic block, and n represents the number of resource basic blocks.
[0015] In a possible implementation of the first aspect, determining the target evaluation result according to the ratio, objective function and first numerical value corresponding to the at least one first parameter includes: determining the first evaluation result according to the ratio and the objective function corresponding to one of the at least one first parameter, the first evaluation result being the evaluation result corresponding to one of the at least one first parameter; when the first evaluation result is greater than or equal to the first numerical value, determining that the first evaluation result is the target evaluation result, one of the at least one first parameter is the target parameter, and stopping determining the target evaluation result according to the ratio, the objective function and the first numerical value corresponding to the at least one first parameter.
[0016] In a possible implementation of the first aspect, after determining the first evaluation result based on the ratio corresponding to one of the at least one first parameters and the objective function, the method further includes: when the evaluation result of each of the at least one first parameter is less than the first numerical value, processing the at least one parameter according to a genetic algorithm.
[0017] In a possible implementation of the first aspect, the processing of the at least one parameter according to the genetic algorithm includes: determining at least one second parameter from the at least one first parameter, the evaluation result corresponding to the second parameter is greater than or equal to a second value and less than the first value, and the second value is less than the first value; crossing every two of the at least one second parameter as a group to generate at least one third parameter; randomly modifying at least one value of the at least one third parameter to obtain at least one fourth parameter; compiling the target code according to the at least one fourth parameter to obtain a ratio corresponding to the at least one fourth parameter; and determining the target evaluation result according to the ratio corresponding to the at least one fourth parameter, the target function and the first value.
[0018] In a possible implementation manner of the first aspect, when the number of the resource basic blocks is n, one first parameter corresponds to an allocation method of n resource basic blocks, and one first parameter corresponds to n ratios.
[0019] In a second aspect, an embodiment of the present application provides a resource allocation device, comprising: a generation unit, configured to generate at least one first parameter according to an allocation method of at least one resource basic block, wherein the first parameter is used to represent the initial allocation method of the resource basic block, and the resource basic block includes at least one associated resource; a compilation unit, configured to compile a target code according to the at least one first parameter and the resource basic block, and obtain a ratio corresponding to the at least one first parameter, wherein the ratio is used to represent the ratio of the remaining resources in the resource basic block to the total resources occupied by the terminal after the terminal compiles using the resource basic block, and the target code is the code loaded onto the target chip by the terminal; a determination unit, configured to determine a target evaluation result according to the ratio corresponding to the at least one first parameter, a target function, and a first numerical value, wherein the target evaluation result is greater than or equal to the first numerical value, and the first parameter corresponding to the target evaluation result is a target parameter, and the target parameter represents an updated allocation relationship of the resource basic block, and the target function is obtained based on the weight of the resource basic block and the first function used by the resource basic block, and the first function is used to obtain the dynamic weight of the resource basic block.
[0020] In a possible implementation of the second aspect, the determination unit is specifically used to determine a first evaluation result based on a ratio corresponding to one of the at least one first parameters and the objective function, the first evaluation result being an evaluation result corresponding to one of the at least one first parameters; when the first evaluation result is greater than or equal to the first numerical value, determine that the first evaluation result is the target evaluation result, one of the at least one first parameters is the target parameter, and stop determining the target evaluation result based on the ratio corresponding to the at least one first parameter, the objective function and the first numerical value.
[0021] In a possible implementation manner of the second aspect, the determination unit is specifically configured to process the at least one parameter according to a genetic algorithm when an evaluation result of each of the at least one first parameter is less than the first value.
[0022] In a possible implementation of the second aspect, the determination unit is specifically used to determine at least one second parameter from the at least one first parameter, the evaluation result corresponding to the second parameter is greater than or equal to a second numerical value and less than the first numerical value, and the second numerical value is less than the first numerical value; cross every two of the at least one second parameter as a group to generate at least one third parameter; randomly modify at least one numerical value of the at least one third parameter to obtain at least one fourth parameter; compile the target code according to the at least one fourth parameter to obtain a ratio corresponding to the at least one fourth parameter; determine the target evaluation result according to the ratio corresponding to the at least one fourth parameter, the target function and the first numerical value.
[0023] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a memory for storing instructions; a processor for executing the instructions stored in the memory, wherein when the instructions are executed, the method in the first aspect or any possible implementation manner of the first aspect is implemented.
[0024] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer storage medium stores a computer program. When the computer program is executed, the method in the first aspect or any possible implementation manner of the first aspect is implemented.
[0025] In a fifth aspect, an embodiment of the present application provides a computer program, which, when executed on a computer, enables the computer to execute a method according to the first aspect or any possible implementation of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the background technology, the following is a brief introduction to the drawings required for use in the embodiments of the present application or the background technology.
[0027] Figure 1 A flowchart of a resource allocation method provided in an embodiment of the present application;
[0028] Figure 2 A flowchart of another resource allocation method provided in an embodiment of the present application;
[0029] Figure 3 A schematic diagram of resource dependency provided in an embodiment of the present application;
[0030] Figure 4 A resource basic block partition diagram provided in an embodiment of the present application;
[0031] Figure 5A flowchart of a resource allocation method provided in an embodiment of the present application;
[0032] Figure 6 A schematic diagram of a resource allocation device provided in an embodiment of the present application;
[0033] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0034] In order to make the objectives, technical solutions and advantages of the present application clearer, the present application will be further described below in conjunction with the accompanying drawings.
[0035] The terms "first" and "second" in the specification, claims and drawings of this application are only used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units that are not listed, or may optionally include other steps or units that are inherent to these processes, methods, products or devices.
[0036] The "embodiment" mentioned in this article means that the specific features, structures or characteristics described in conjunction with the embodiment can be included in at least one embodiment of the present application. The appearance of this phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It can be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0037] In the present application, "at least one (item)" means one or more, "more than one" means two or more, "at least two (items)" means two or three and more than three, and "and / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c".
[0038] With the widespread application of domain-specific architectures in proprietary fields, compiler technology has also made significant progress. Using compilers to maximize the capabilities of DSA chips (such as resources, performance, etc.) is the goal pursued by all DSA compiler developers. Due to its strong domain-related characteristics, DSA chips are often inclined towards typical domain applications in terms of resource allocation. In addition, since various resources of the processor architecture, such as instruction allocation and register allocation, are often related in domainization, the quality of the compiler's resource allocation strategy also largely determines the size and complexity of the business scope supported by the DSA chip processor.
[0039] Currently, compilers usually use heuristic methods to complete all resource allocation based on certain key resources.
[0040] Due to the above method, the initial weights of various resources have been limited during the initialization of the strategy, making it difficult to adjust during the allocation process. Different algorithms have different parameters, and different parameters correspond to different allocation effects. For example, the resource allocation effects obtained under different allocation alignment granularities and different allocation priorities are different. Once the allocation strategy is determined, the flexibility of the algorithm / parameters is lost, which leads to the inability to obtain a good resource allocation effect for a strategy specified in one scenario in another scenario. Therefore, the above method cannot flexibly adjust the parameters and algorithms, nor can it obtain reasonable allocation results, and the allocation effect is poor.
[0041] In view of the above problems, the present application embodiment proposes a method for resource allocation, such as Figure 1 As shown, the method includes:
[0042] 101. Generate at least one first parameter according to an allocation method of at least one resource basic block.
[0043] The first parameter is used to indicate the initial allocation method of the resource basic block. The resource basic block includes at least one associated resource. The first parameter can be embodied in a vector.
[0044] Specifically, the division of the resource basic block (RBB) is based on the principle of "high cohesion and low coupling", and resources with high interdependence, i.e., resources with high correlation, are divided into the same resource basic block. The size of the resource basic block should be divided according to the characteristics of the DSA chip. The resource basic block includes at least one resource basic block, and the resources include but are not limited to instruction allocation and register allocation.
[0045] Optionally, the division method of the above resource basic blocks can be determined by professionals based on their professional knowledge, and the dependency graph of the resources involved in the multi-objective optimization can be constructed. According to the dependency graph of the above resources, the resource basic blocks are divided, and a model is established based on the resource basic blocks. When a single resource has a low correlation with other resources, the single resource itself constitutes a resource basic block. After obtaining the above model, the terminal establishes parameters according to the model and randomly generates a first parameter. The above first parameter represents the initial allocation method of all resource basic blocks.
[0046] The above-mentioned resource basic block division method can also be carried out by the terminal constructing a graph according to the correlation of the resources. The nodes of the above-mentioned graph are the above-mentioned resources, and the weights of the above-mentioned graph are the degree of correlation between the nodes. The terminal calculates the correlation between the nodes according to the nodes and weights of the graph. When the correlation between the above-mentioned nodes is greater than the preset value, the resources corresponding to the nodes are divided into the same resource basic block.
[0047] It is understandable that after acquiring the model, the terminal parameterizes the resource basic block, and the parameters of the resource basic block are used to represent the allocation method of the resource, and the parameters of the resource include but are not limited to: resource allocation algorithm, algorithm public parameters, and algorithm private parameters. After acquiring the target code, the terminal generates at least one first parameter.
[0048] Optionally, the at least one first parameter generated by heuristic method may be randomly assigned by the terminal, or the terminal may directly obtain specific initial parameters given by engineers based on their understanding of the currently compiled program.
[0049] 102. Compile the target code according to the at least one first parameter and the resource basic block to obtain a ratio corresponding to the at least one first parameter.
[0050] The above ratio is used to indicate the ratio of the remaining resources in the resource basic block to the total resources after the terminal compiles using the resource basic block, and the above target code is the code loaded onto the target chip through the terminal.
[0051] Specifically, the terminal can determine the allocation method of resources in the resource basic block according to the first parameter, and then compile the target code obtained by the terminal according to the allocation method of the resource basic block to obtain the ratio corresponding to the at least one first parameter, and the target code is a full program.
[0052] 103. Determine a target evaluation result according to the ratio corresponding to the at least one first parameter, the target function and the first numerical value.
[0053] The first parameter corresponding to the above target evaluation result is the target parameter. The above target parameter represents the allocation relationship of the above resource basic block update. The above target function is obtained based on the weight of the above resource basic block and the first function used by the above resource basic block. The above first function is used to obtain the dynamic weight (also called dynamic penalty value) of the above resource basic block. Since the number and distribution of resources of different resource basic blocks are different, the penalty values under different utilization rates are different. Therefore, the remaining amount of resources of the resource basic block is used as a parameter variable. The dynamic weight after the current allocation result is calculated by the first function. The above first function can be the activation function of the deep neural network. Exemplarily, when the amount of resources in a resource basic block is insufficient and has many dependencies, the above activation function is a relatively stable curve.
[0054] In a possible implementation provided in an embodiment of the present application, the above objective function satisfies the following conditions:
[0055]
[0056] The above RBB0 represents the first resource basic block. n-1 represents the nth resource basic block, the above F(RBB0…RBB n-1 ) represents the above objective function, and the above W i represents the weight of the i+1th resource basic block in the above resource basic block. i represents the first function used by the i+1th resource basic block in the above resource basic block. i Represents the ratio corresponding to the i+1th resource basic block in the parameter, where n is a positive integer, i∈[0,n-1].
[0057] In a possible implementation method provided in the embodiment of the present application, the above W i The following conditions must be met:
[0058] W i ∈(0,1];
[0059]
[0060] The above W i represents the weight of the i+1th resource basic block, and n represents the number of resource basic blocks.
[0061] It can be understood that the weight of the above-mentioned resource basic block is pre-set by professionals according to the scarcity of resources, and it reflects the global scarcity of the resource basic block. The higher the scarcity of resources, the higher the weight. The first function of the above-mentioned resource basic block is pre-set by professionals and included in the parameters of the above-mentioned resource basic block. It reflects the dynamic scarcity of the resource basic block. Different resource basic blocks can select different first functions according to the characteristics of the resources.
[0062] Optionally, the target evaluation result determined according to the ratio corresponding to the at least one first parameter, the objective function and the first numerical value can be determined according to the ratio corresponding to the at least one first parameter and the objective function; and the evaluation result corresponding to each first parameter of the at least one first parameter is selected from the evaluation results corresponding to each parameter of the at least one first parameter, which is greater than or equal to the first numerical value, as the target evaluation result.
[0063] The terminal calculates the evaluation results of all the above-mentioned first parameters. When there is an evaluation result greater than the first numerical value among the above-mentioned evaluation results, the optimal evaluation result is selected as the target evaluation result. When there is no evaluation result greater than the first numerical value among the above-mentioned evaluation results, the first parameters are processed according to the genetic algorithm to obtain offspring parameters, and the offspring parameters are recompiled and evaluated. The above-mentioned operation is repeated until there is an evaluation result greater than the first numerical value among the above-mentioned evaluation results, and the optimal evaluation result is selected as the target evaluation result.
[0064] The first evaluation result can also be determined based on the ratio corresponding to one of the at least one first parameter and the objective function, where the first evaluation result is the evaluation result corresponding to one of the at least one first parameter; when the first evaluation result is greater than or equal to the first numerical value, the first evaluation result is determined to be the target evaluation result, one of the at least one first parameter is the target parameter, and the determination of the target evaluation result based on the ratio corresponding to the at least one parameter, the objective function and the first numerical value is stopped.
[0065] The first parameter corresponding to the above target evaluation result is a resource allocation parameter. The above resource allocation parameter can be used for compiling the current application, or as a compilation configuration parameter for such applications, skipping the genetic algorithm stage to directly obtain a more efficient allocation result.
[0066] The embodiment of the present application comprehensively considers all allocation methods of all the above resource basic blocks, evaluates the compilation results, and selects the first parameter corresponding to the excellent evaluation result according to the evaluation result, and the above first parameter represents the corresponding allocation method under the resource allocation efficiency load requirement. The resource allocation of the multi-objective optimization problem, i.e., the resource allocation optimization problem of multiple allocation resources, is completed to achieve a better allocation effect.
[0067] Shown Figure 1 A resource allocation method is provided when the first evaluation result is greater than the first value. When the first evaluation result is less than the first value, the embodiment of the present application provides another resource allocation method, such as Figure 2 As shown, the above method comprises the following steps:
[0068] 201. Generate at least one first parameter according to an allocation method of at least one resource basic block.
[0069] The first parameter is used to indicate the initial allocation mode of all the resource basic blocks, and the resource basic blocks include at least one associated resource.
[0070] Specifically, the division of the resource basic block (RBB) is based on the principle of "high cohesion and low coupling", and resources with high interdependence, i.e., resources with high correlation, are divided into the same resource basic block. The size of the resource basic block should be divided according to the characteristics of the DSA chip. The resource basic block includes at least one resource basic block, and the resources include but are not limited to instruction allocation and register allocation.
[0071] In the above-mentioned method of generating at least one first parameter by heuristic means, the terminal randomly assigns values to the parameters to generate at least one first parameter.
[0072] It is understood that the specific description of step 201 can also refer to Figure 1 The step 101 shown is not repeated here.
[0073] 202. Compile the target code according to the at least one first parameter and the resource basic block to obtain a ratio corresponding to the at least one first parameter.
[0074] The above ratio is used to indicate the ratio of the remaining resources in the resource basic block to the total resources after the terminal compiles using the resource basic block. The above target code is the code acquired by the terminal and needs to be loaded onto the target chip.
[0075] Specifically, the above compilation is to compile the target code, that is, the full program, into a binary file that can run on the DSA chip. The terminal reasonably determines the allocation method of resources in the resource basic block based on the first parameter, and then compiles the target code obtained by the terminal according to the allocation method of the above resource basic block to obtain the ratio corresponding to at least one of the above first parameters. The above target code is the full program.
[0076] 203. Determine a first evaluation result according to a ratio corresponding to one of the at least one first parameter and an objective function.
[0077] The above-mentioned first evaluation result is an evaluation result corresponding to one of the above-mentioned at least one first parameter, the above-mentioned target parameter represents the allocation relationship of the above-mentioned resource basic block update, and the above-mentioned target function is obtained based on the weight of the above-mentioned resource basic block and the first function used by the above-mentioned resource basic block.
[0078] In a possible implementation provided in an embodiment of the present application, the above objective function may be:
[0079]
[0080] The above RBB0 represents the first resource basic block. n-1 represents the nth resource basic block, the above F(RBB0…RBB n-1 ) represents the above objective function, and the above W i represents the weight of the i+1th resource basic block in the above resource basic block. i represents the first function used by the i+1th resource basic block in the above resource basic block. i It represents the ratio corresponding to the i+1th resource basic block in the parameter. The value range of n is all natural numbers, and the value range of i is i∈[0,n-1].
[0081] In a possible implementation method provided in the embodiment of the present application, the above W i The following conditions are met:
[0082] W i ∈(0,1];
[0083]
[0084] The above W i represents the weight of the i+1th resource basic block, and n represents the number of resource basic blocks.
[0085] 204. Process the at least one first parameter according to a genetic algorithm.
[0086] It is understandable that the above-mentioned first value is preset by professionals, and when the evaluation results of all parameters in the above-mentioned at least one first parameter are less than the above-mentioned first value, the above-mentioned at least one first parameter is processed according to the genetic algorithm.
[0087] In a possible implementation method provided in an embodiment of the present application, the processing of the at least one first parameter according to the genetic algorithm includes: selecting the parameter corresponding to the evaluation result greater than or equal to the second numerical value in the evaluation result corresponding to each parameter in the at least one parameter as the second parameter; crossing every two second parameters in the second parameters as a group to generate a third parameter; randomly modifying at least one numerical value in the third parameter to obtain the fourth parameter; compiling the target code according to the fourth parameter to obtain the ratio corresponding to the fourth parameter; determining the target evaluation result according to the ratio corresponding to the fourth parameter, the target function and the first numerical value.
[0088] It can be understood that the second parameter, the third parameter and the fourth parameter can be embodied in the form of vectors. The second value is preset by professionals, the second value is less than the first value, the first parameter is selected, and the parameter greater than or equal to the second value of the evaluation result is selected to form a new population, that is, the second parameter, and the second parameter is crossed to generate a new excellent individual, that is, the third parameter. The crossover operator includes any one of double-point crossover, multi-point crossover, uniform crossover and arithmetic crossover, and then at least one value of the third parameter is randomly modified by a mutation algorithm to obtain the fourth parameter. The mutation algorithm includes one of basic bit mutation, uniform mutation, boundary mutation, non-uniform mutation, and Gaussian approximate mutation. According to the fourth parameter, the resource allocation method in the resource basic block is determined, and then the target code obtained by the terminal is compiled according to the allocation method of the resource basic block, and the corresponding evaluation result is obtained. When the evaluation result is greater than or equal to the first value, the evaluation result is determined to be the target evaluation result, and the mutation is stopped. When the evaluation result is less than the first value, the method is repeated until the compiled evaluation result is greater than or equal to the first value.
[0089] The embodiments of the present application utilize genetic algorithms and heuristic methods to comprehensively consider all combinations of all modes of all resource basic blocks. Different algorithms and parameters can be used for different resource basic blocks, so that resource allocation for various resource allocation optimization problems can be completed under the condition that the above-mentioned resources are restricted, thereby achieving a better allocation effect.
[0090] like Figure 3As shown, an embodiment of the present application provides a schematic diagram of resource dependencies, and the resources to be allocated include: instruction allocation, register allocation, instruction mapping and destination address allocation of extractors at each level (or source address allocation of extractors at each level). Taking the three-level extractor source address allocation as an example, it includes main extractor source address allocation, main extractor destination address allocation, sub-extractor source address allocation, sub-extractor destination address allocation, final extractor source address allocation and final extractor destination address allocation. Among them, the above-mentioned final extractor destination address allocation depends on the above-mentioned final extractor source address allocation, and the above-mentioned final extractor source address allocation depends on the above-mentioned sub-extractor source address allocation, the above-mentioned final extractor destination address allocation depends on the above-mentioned sub-extractor destination address allocation, the above-mentioned sub-extractor destination address allocation depends on the above-mentioned sub-extractor source address allocation, and the above-mentioned sub-extractor source address allocation depends on the above-mentioned main extractor source address allocation, the above-mentioned sub-extractor destination address allocation depends on the above-mentioned main extractor destination address allocation, the above-mentioned main extractor source address allocation, the main extractor destination address allocation, the sub-extractor source address allocation, the sub-extractor destination address allocation, the final extractor source address allocation and the final extractor destination address allocation all depend on the above-mentioned register allocation, the above-mentioned instruction mapping depends on the above-mentioned register allocation and the above-mentioned instruction allocation, the above-mentioned register allocation depends on the above-mentioned instruction allocation, therefore, according to the strategy of "high cohesion, low coupling", the above-mentioned resources are divided into the following 4 RBBs (i.e., the above-mentioned resource basic blocks).
[0091] Based on the above Figure 3 , a resource basic block partition diagram provided in an embodiment of the present application, such as Figure 4 As shown, the RBB0 includes the instruction allocation, the RBB1 includes the register allocation, the RBB2 includes the instruction mapping, and the RBB3 includes the main extractor source address allocation, the sub-extractor source address allocation, and the final extractor source address allocation. Therefore, the resource basic blocks have different characteristics, different allocation methods, and different parameters. Exemplarily, the parameters include:
[0092] class InstAlloc:RBB0
[0093] dependency:None
[0094] main_algm: {0:greedy}
[0095] weight: int
[0096] activation_function: function
[0097] strategy: {0: non-branch, 1: logical_inst_first} ...
[0098] class RegAlloc:RBB1
[0099] dependency:[InstAlloc]
[0100] main_algm: {0: graph_coloring, 1: linear_scan, 2: greedy_scan}
[0101] weight: int
[0102] activation_function: function
[0103] align: {0: 1B, 1: 2B, 2: 4B}
[0104] strategy: {0: sparse_alloc, 1: dense_alloc} ...
[0105] class...
[0106] It can be understood that the above-mentioned dependency represents the dependency relationship of the resource basic block, the above-mentioned main_algm represents the available allocation algorithm, the above-mentioned activation_function represents the first function that can be used, the above-mentioned strategy represents the allocation strategy, the above-mentioned weight represents the weight, the above-mentioned align represents the minimum unit granularity, the above-mentioned InstAlloc represents the instruction allocation module, the above-mentioned RegAlloc represents the register allocation module, the above-mentioned None represents no dependency, the above-mentioned int represents that the data type of the weight is an integer type, the above-mentioned greedy represents a greedy algorithm, the above-mentioned non-branch represents the strategy of not using jump instructions first, the above-mentioned logical_inst_first represents the strategy of using logical operation instructions first, the above-mentioned graph_coloring represents a graph coloring algorithm, the above-mentioned linear_scan represents a linear scanning algorithm, the above-mentioned greedy_scan represents a greedy algorithm, the above-mentioned 1B represents 1 byte, the above-mentioned 2B represents 2 bytes, the above-mentioned 4B represents 4 bytes, the above-mentioned sparse_alloc represents a dispersed allocation strategy, and the above-mentioned dense_alloc represents a compact allocation strategy.
[0107] After the terminal obtains the target code, Figure 5As shown, resource allocation starts (i.e., step 501), the terminal randomly generates at least one initial parameter (i.e., the first parameter) as the initial population in the genetic algorithm through heuristics according to the above parameters (i.e., step 502), compiles each initial parameter in the above initial population (i.e., step 503) and evaluates it through the objective function (i.e., step 504), obtains the first evaluation result as the result (i.e., step 505), and when the first evaluation result is greater than or equal to the first value (i.e., step 506), ends (i.e., step 507), stops compiling, and obtains the resource allocation parameter (i.e., the parameter corresponding to the target evaluation result). In the case where the evaluation result is less than the first value, the offspring population (i.e., step 511) is obtained as the fourth parameter through the selection (i.e., step 508), crossover (i.e., step 509) and mutation (i.e., step 510) of the genetic algorithm, and repeats steps 503 and 504. If the evaluation result is greater than or equal to the first value, the compilation ends, otherwise, the next cycle continues until the first evaluation result is greater than or equal to the first value, and the resource allocation parameter is obtained. The resource allocation parameters obtained can be used for compiling the current application, or as compilation configuration parameters for such applications, skipping the genetic algorithm stage and directly obtaining the allocation result. Exemplarily, when the first value is 98 and the second value is 90, the 100 randomly generated first parameters are compiled respectively. After compiling the first parameters each time, the terminal obtains the remaining resources in each resource basic block (i.e., the above ratio), and evaluates the resource allocation efficiency according to the objective function and the remaining resources to obtain the first evaluation result. When the above 100 first evaluation results are less than 98, the first parameter corresponding to the first evaluation result greater than or equal to 90 is selected as the second parameter, and the fourth parameter is obtained through the selection, crossover and mutation actions of the genetic algorithm. The above fourth parameter is compiled, and there is a target parameter in the above fourth parameter. The weight of RBB0 in the above target parameter is 0.5, the allocation algorithm used by RBB0 is the greedy algorithm, the weight of RBB1 is 0.2, the allocation algorithm used by RBB1 is the graph coloring algorithm, and the weight of RBB2 is 0.3. After the compilation of the above target parameter is completed, the evaluation result corresponding to the above target parameter is 98, and the evaluation result corresponding to the above target parameter is equal to the first value, and the compilation of other fourth variables is stopped. The above target parameter is the resource allocation parameter.
[0108] It can be understood that the above method can be applied on the DSA chip compiler, and the resource allocation results have a 5% to 10% allocation efficiency improvement compared with the traditional compilation process. In some extreme scenarios, it can solve the problem of resource allocation failure due to overload of key resources.
[0109] For detailed description of the embodiments of the present application, please refer to Figure 1 and Figure 2The embodiments shown will not be described in detail here.
[0110] Based on the above method, the embodiment of the present application provides a device for resource allocation, such as Figure 6 As shown, the device comprises:
[0111] A generating unit 601 is used to generate at least one first parameter according to an allocation mode of at least one resource basic block, wherein the first parameter is used to represent an initial allocation mode of the resource basic block, and the resource basic block includes at least one associated resource;
[0112] A compiling unit 602 is used to compile the target code according to the at least one first parameter and the resource basic block, and obtain a ratio corresponding to the at least one first parameter, wherein the ratio is used to represent the ratio of the remaining resources in the resource basic block to the total resources occupied by the resource basic block after the terminal compiles the resource basic block, and the target code is the code loaded onto the target chip by the terminal;
[0113] A determination unit 603 is used to determine a target evaluation result based on a ratio corresponding to the at least one first parameter, a target function and a first numerical value, wherein the target evaluation result is greater than or equal to the first numerical value, the first parameter corresponding to the target evaluation result is a target parameter, and the target parameter represents an allocation relationship for updating the resource basic block, and the target function is obtained based on a weight of the resource basic block and a first function used by the resource basic block.
[0114] In an optional implementation, the above-mentioned determination unit 603 is specifically used to determine a first evaluation result based on the ratio corresponding to one of the at least one first parameters and the objective function, the first evaluation result being the evaluation result corresponding to one of the at least one first parameters; when the first evaluation result is greater than or equal to the first numerical value, determine that the first evaluation result is the target evaluation result, one of the at least one first parameters is the target parameter, and stop determining the target evaluation result based on the ratio corresponding to the at least one first parameter, the objective function and the first numerical value.
[0115] In an optional implementation, the determination unit 603 is specifically configured to process the at least one parameter according to a genetic algorithm when an evaluation result of each of the at least one first parameter is less than the first value.
[0116] In an optional implementation, the above-mentioned determination unit 603 is specifically used to determine at least one second parameter from the at least one first parameter, the evaluation result corresponding to the second parameter is greater than or equal to the second numerical value and less than the first numerical value, and the second numerical value is less than the first numerical value; cross every two of the at least one second parameter as a group to generate at least one third parameter; randomly modify at least one numerical value of the at least one third parameter to obtain at least one fourth parameter; compile the target code according to the at least one fourth parameter to obtain the ratio corresponding to the at least one fourth parameter; determine the target evaluation result according to the ratio corresponding to the at least one fourth parameter, the target function and the first numerical value.
[0117] It can be understood that the description of each unit shown above is only an example, and the specific steps performed or functions implemented by each unit can also refer to the embodiments shown above, which will not be described in detail here.
[0118] Figure 6 The beneficial effects of the device can refer to the beneficial effects of the resource allocation method mentioned above, which will not be described in detail here.
[0119] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 7 As shown, the electronic device 70 includes a processor 701, a memory 702 and a communication interface 703; the processor 701, the memory 702 and the communication interface 703 are interconnected via a bus. Figure 7 The electronic device in is used to execute the data processing method in the aforementioned embodiment.
[0120] The memory 702 includes, but is not limited to, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), or a portable read-only memory (CDROM), and is used for related instructions and data. The communication interface 703 is used to receive and send data.
[0121] The processor 701 may be one or more CPUs. When the processor 701 is a CPU, the CPU may be a single-core CPU or a multi-core CPU.
[0122] Exemplarily, the processor 701 may implement Figure 6The functions or steps performed by the generation unit, compilation unit and determination unit shown.
[0123] It is understood that the specific description of the processor can refer to Figure 6 Alternatively, you may refer to the device shown in Figures 1 to 5 The embodiments shown will not be described in detail here.
[0124] In an embodiment of the present application, a computer-readable storage medium is provided, which stores a computer program. When the computer program is executed, the data processing method provided in the above-mentioned embodiment is implemented.
[0125] An embodiment of the present application provides a computer program product including instructions, which, when executed on a computer, enables the computer to execute the data processing method provided by the aforementioned embodiment.
[0126] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the division of the unit is only a logical function division, and there may be other division methods in actual implementation, for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. The mutual coupling, 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.
Claims
1. A method for resource allocation, characterized in that: Applied to a terminal, the method comprises: Generate at least one first parameter according to an allocation mode of at least one resource basic block, wherein the first parameter is used to represent an initial allocation mode of all resource basic blocks, wherein the resource basic block includes at least one associated resource, and the associated resource includes but is not limited to instruction allocation and register allocation; Compile the target code according to the at least one first parameter and the resource basic block to obtain a ratio corresponding to the at least one first parameter, the ratio being used to represent the ratio of the remaining resources in the resource basic block to the total resources in the same resource basic block after the terminal compiles using the resource basic block, the target code being the code loaded onto the target chip by the terminal; Determine a target evaluation result according to the ratio corresponding to the at least one first parameter, the target function and the first value, the target evaluation result is greater than or equal to the first value, the first parameter corresponding to the target evaluation result is the target parameter, the target parameter represents the allocation relationship of the resource basic block update, the target function is obtained based on the weight of the resource basic block and the first function used by the resource basic block, and the first function is used to obtain the dynamic weight of the resource basic block; The step of determining the target evaluation result according to the ratio, the target function and the first value corresponding to the at least one first parameter includes: Determine a first evaluation result according to a ratio corresponding to one of the at least one first parameter and the objective function, the first evaluation result being an evaluation result corresponding to one of the at least one first parameter; In the case where the first evaluation result is greater than or equal to the first value, determining that the first evaluation result is the target evaluation result, one of the at least one first parameter is the target parameter, and stopping determining the target evaluation result according to the ratio corresponding to the at least one first parameter, the objective function, and the first value; In a case where an evaluation result of each of the at least one first parameter is smaller than the first value, the at least one first parameter is processed according to a genetic algorithm.
2. The method according to claim 1, characterized in that The objective function satisfies the following conditions: ; Said Indicates the first resource basic block, the Indicates The resource basic blocks, the represents the objective function, the Indicates the first The weight of the resource basic block, Indicates the first The first function used by the resource basic block, the Indicates the first parameter corresponding to the The ratio corresponding to the resource basic blocks, is a positive integer, .
3. The method according to claim 2, characterized in that Said The following conditions must be met: ; ; Said Indicates The weight of the resource basic block, Indicates the number of resource basic blocks.
4. The method according to claim 3, characterized in that The processing of the at least one first parameter according to the genetic algorithm includes: selecting at least one second parameter from the at least one first parameter, the evaluation result corresponding to the second parameter is greater than or equal to a second value and less than the first value, and the second value is less than the first value; Cross each two of the at least one second parameter as a group to generate at least one third parameter; randomly modifying at least one value of the at least one third parameter by a mutation algorithm to obtain at least one fourth parameter; Recompile the target code according to the at least one fourth parameter to obtain a ratio corresponding to the at least one fourth parameter; The target evaluation result is determined according to the ratio corresponding to the at least one fourth parameter, the target function and the first numerical value.
5. The method according to claim 4, characterized in that When the number of the resource basic blocks is n, one first parameter corresponds to an allocation method of n resource basic blocks, and one first parameter corresponds to n ratios.
6. A resource allocation device, characterized in that: Applied to a terminal, the device comprises: A generating unit, configured to generate at least one first parameter according to an allocation mode of at least one resource basic block, wherein the first parameter is used to represent an initial allocation mode of all resource basic blocks, wherein the resource basic block includes at least one associated resource, and the associated resource includes but is not limited to instruction allocation and register allocation; a compiling unit, configured to compile a target code according to the at least one first parameter and the resource basic block, and obtain a ratio corresponding to the at least one first parameter, wherein the ratio is used to indicate a ratio of the remaining resources in the resource basic block to the total resources in the same resource basic block after the terminal compiles using the resource basic block, wherein the target code is a code loaded onto a target chip by the terminal; A determination unit, configured to determine a target evaluation result according to a ratio corresponding to the at least one first parameter, a target function, and a first numerical value, wherein the target evaluation result is greater than or equal to the first numerical value, the first parameter corresponding to the target evaluation result is a target parameter, the target parameter represents an allocation relationship of an update of the resource basic block, the target function is obtained based on a weight of the resource basic block and a first function used by the resource basic block, and the first function is used to obtain a dynamic weight of the resource basic block; The step of determining the target evaluation result according to the ratio, the target function and the first value corresponding to the at least one first parameter includes: Determine a first evaluation result according to a ratio corresponding to one of the at least one first parameter and the objective function, the first evaluation result being an evaluation result corresponding to one of the at least one first parameter; In the case where the first evaluation result is greater than or equal to the first value, determining that the first evaluation result is the target evaluation result, one of the at least one first parameter is the target parameter, and stopping determining the target evaluation result according to the ratio corresponding to the at least one first parameter, the objective function, and the first value; In a case where an evaluation result of each of the at least one first parameter is less than the first value, the at least one first parameter is processed according to a genetic algorithm.
7. An electronic device, characterized in that: include: A memory for storing instructions; A processor is used to execute the instructions stored in the memory, and when the instructions are executed, the method according to any one of claims 1 to 5 is implemented.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed, the method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
GPGPU register file dynamic extension method
CN108595258A
Method and device for obtaining resource allocation strategy, equipment and storage medium
CN113138848A