WO2012069010A1 - 静态存储的分配方法和装置 - Google Patents

静态存储的分配方法和装置 Download PDF

Info

Publication number
WO2012069010A1
WO2012069010A1 PCT/CN2011/082949 CN2011082949W WO2012069010A1 WO 2012069010 A1 WO2012069010 A1 WO 2012069010A1 CN 2011082949 W CN2011082949 W CN 2011082949W WO 2012069010 A1 WO2012069010 A1 WO 2012069010A1
Authority
WO
WIPO (PCT)
Prior art keywords
variable
variables
population
size
storage space
Prior art date
Application number
PCT/CN2011/082949
Other languages
English (en)
French (fr)
Inventor
厉正吉
Original Assignee
意法·爱立信半导体(北京)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 意法·爱立信半导体(北京)有限公司 filed Critical 意法·爱立信半导体(北京)有限公司
Publication of WO2012069010A1 publication Critical patent/WO2012069010A1/zh

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5016Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory

Definitions

  • the present invention relates to the field of data storage technology, and in particular to a static storage allocation method and apparatus.
  • Static storage allocation refers to the allocation of storage addresses that are completed at program compile time. The static storage allocation is different from the dynamic storage allocation that is completed when the program is run. Static allocation has no runtime overhead, has no effect on the performance of the program, and does not have problems such as allocation failures that may occur during dynamic allocation.
  • a certain degree of storage multiplexing is implemented in some C language compilers of the Intel 8051. For example, the following two functions fl, ⁇ 2, if they are not active at the same time (called state), then the statically allocated variables vl, v2 in fl, f2 can be multiplexed with the same 100 bytes of storage space. If multiplexing is not performed, 200 bytes of storage space is required.
  • the technical problem to be solved by the present invention is to provide a static storage allocation method and apparatus, which can reduce the demand for storage space.
  • a method for allocating static storage including:
  • Step 1 Obtain a module to be optimized, the module includes at least two functions coupled to each other;
  • Step 2 Generate a module model according to a coupling relationship between the functions;
  • the module model includes: a function name and a variable, the variable including an input variable and an output variable;
  • Step 3 Obtain all function scheduling orders of the module according to the module model.
  • Step 4 Acquire a lower bound of a required storage space of all variables corresponding to each module in the scheduling order of the function ;
  • Step 5 For each function scheduling order, optimize the address allocation information of all variables by genetic algorithm, so that the size of the storage space occupied by all variables approaches or reaches the minimum value of the lower bound; Step 6, select After optimizing, the function scheduling order of the smallest storage space occupied by all the variables is obtained; Step 7: compiling the module according to the selected function scheduling order and the address allocation information corresponding to the function scheduling order, the address allocation information Includes: the starting address of each variable.
  • the method further includes:
  • the step 5 is specifically: scheduling the sequence of each function selected, optimizing the address allocation of all variables by a genetic algorithm, so that the size of the storage space occupied by all variables approaches or reaches the minimum value of the lower bound. .
  • the step 5 includes:
  • Step A Set the current population Populating to the initial population FirstGen, set the minimum value of the minimum storage space of the current storage space of the current population to the maximum value of LastSize, and set the number of times the storage space does not change during the evolution SizeCounter The current value is 0, set the total number of evolutions TotalCounter current value is 0;
  • Step B Set the current mutation probability value P,,, ut and the current population size value S P . PU ;
  • Step C For each individual Candi in the current population, the mutation is subjected to mutation processing with the probability value P mut , and cross-processed with probability (i - P mut ) to generate each new individual NewCandi; Step D, Selecting individuals who meet the following formula from the new generation population NewGen, and selecting the selected population of selected individuals by the selected individual composition;
  • Step E removing unused storage space for each selected body of SelectedNewGen
  • Step F combining the current population Population with the selected population SelectedNewGen to obtain a set NewAl lPopu, sorting each body in the set NewAl lPopu from small to large according to the size of the required storage space, and selecting the second predetermined number before The individual forms a NewPopulation of the next generation population, and obtains a minimum value NewSize of the storage space required by each body of the current population; the second predetermined number is less than or equal to the current population size value S P . PU ;
  • Step G adding TotalCounter to 1, and updating the current population using the next generation population; when NewSize is less than LastSize, setting the current value of Si zeCounter to 0, and using NewSize The value of LastSize is updated; when NewSize is greater than or equal to LastSize, the current value of SizeCounter is incremented by 1;
  • Step H determining whether NewSize is equal to the minimum value in the lower bound, if the judgment result is yes, ending the evolution process; if the judgment result is no, then turning to step I; Step I, determining whether it is satisfied (SizeCounter ⁇ MAX— NO— IMPROVEMENT and (TotalCounter ⁇
  • the steps of performing the mutation processing include:
  • the Offset generation method is:
  • round means rounding out
  • the steps of performing the cross processing include: A set of elements is selected from the individual Candi with equal probability. ⁇ Vi , Addr selects a Candi2 different from Candi from the current population, and finds the starting address of Vi from Candi2.
  • the initial population FirstGen is generated by the following steps:
  • the variables of the population are sequentially allocated to the adjacent storage spaces in order, that is, the corresponding individuals are obtained.
  • the set of coexisting variable sets is obtained by the following steps:
  • a coexisting variable set corresponding to the scheduling sequence is generated according to a variable that exists in the module execution process
  • the module model in the step 2 is generated as follows:
  • Functions include function names, input variables, output variables, and large storage space for output variables. Small; the output variable of the function includes the temporary variables used in the execution of the function;
  • the module model includes an input variable, a size of a storage space occupied by the input variable, an output variable, an exception variable, and at least one set of alias variables, the output variable containing an output variable of a function within the module, the exception variable not being optimized
  • Each alias variable set contains multiple variables that are aliased to each other; when a variable has N writes, N new variables are introduced, so that any one variable is written only once; the new variable and the original variable are aliased to each other. , where N is a natural number of > 1.
  • a static storage distribution device including:
  • a module acquiring unit which acquires a module to be optimized, the module includes at least two functions coupled to each other;
  • the model generating unit generates a module model according to the coupling relationship between the functions;
  • the module model includes: a function name and a variable, and the variable includes an input variable and an output variable;
  • a function scheduling order obtaining unit which acquires, according to the module model, all function scheduling orders of the module
  • a lower bound acquisition unit obtains a lower bound of a storage space required by the module for each variable corresponding to each of the function scheduling sequences;
  • Optimization unit for each function scheduling order, optimize the address allocation information of all variables by genetic algorithm, so that the size of the storage space occupied by all variables approaches or reaches the minimum value of the lower bound; Select unit, select optimization a function scheduling order in which all variables occupy the smallest storage space; the compiling unit compiles the module according to the selected function scheduling order and the address allocation information corresponding to the function scheduling order, and the address allocation information includes: The starting address of the variable.
  • Embodiments of the present invention have the following beneficial effects:
  • the static allocation of variables is optimized from the global of the program, and the storage space can be reused as much as possible, thereby reducing the demand for the storage space.
  • FIG. 1 is a schematic flow chart of a method for allocating static storage according to the present invention
  • FIG. 2 is a schematic structural diagram of a static storage distribution device according to the present invention.
  • Figure 3 is a schematic diagram of a module to be optimized
  • FIG. 4 is a schematic flowchart of an application scenario of a static storage allocation method according to the present invention
  • FIG. 5 is a schematic flowchart of a genetic algorithm in a static storage allocation method according to the present invention
  • the present invention is an optimization method and apparatus suitable for static storage allocation, and is particularly suitable for static storage allocation in the field of embedded processors with limited storage resources.
  • the static allocation of static variables, global variables, etc. is optimized from the global, to multiplex the storage space as much as possible, and reduce the need for storage space.
  • vl is only used by functions f l and f2
  • v2 is only used by functions f3 and f4, and four functions are called sequentially.
  • vl and v2 can also reuse the same storage space.
  • a static storage allocation method includes: Step 11: Acquire a module to be optimized, the module includes at least two functions coupled to each other; Step 12, according to a coupling relationship between the functions, generating a module model; the module model includes: a function name and a variable, the variable including an input variable and an output variable;
  • Step 13 Obtain all function scheduling orders of the module according to the module model.
  • Step 14 Acquire a lower bound of a storage space required by the module for each variable corresponding to each function scheduling order ;
  • Step 15 for each function scheduling order, optimize the address allocation information of all variables by genetic algorithm, so that the size of the storage space occupied by all variables approaches or reaches the minimum value of the lower bound;
  • Step 16 select After the optimization, the function scheduling order of the smallest storage space occupied by all the variables is obtained;
  • Step 17 the module is compiled according to the selected function scheduling order and the address allocation information corresponding to the function scheduling order, and the address allocation information is compiled. Includes: Start address of each variable.
  • the method further includes:
  • the step 15 is specifically: scheduling the sequence of each function selected, and optimizing by the genetic algorithm
  • the address allocation of all variables is such that the size of the storage space occupied by all variables approaches or reaches the minimum value of the lower bound.
  • the step 15 includes:
  • Step A Set the current population Populating to the initial population FirstGen, set the minimum value of the minimum storage space of the current storage space of the current population to the maximum value of LastSize, and set the number of times the storage space does not change during the evolution SizeCounter The current value is 0, set the total number of evolutions TotalCounter current value is 0;
  • Step B Set the current mutation probability value P,,, ut and the current population size value S P . PU ;
  • Step C For each individual Candi in the current population, the mutation is subjected to mutation processing with the probability value P mut , and cross-processed with probability (i - P mut ) to generate each new individual NewCandi; Step D, Selecting individuals who meet the following formula from the new generation population NewGen, and selecting the selected population of selected individuals by the selected individual composition;
  • G represents an element in the set VarGroupi.
  • indicates the "belonging" relationship in the collection.
  • Step E removing unused storage space for each selected body of SelectedNewGen
  • Step F combining the current population Population with the selected population SelectedNewGen to obtain a set NewAl lPopu, sorting each body in the set NewAl lPopu from small to large according to the size of the required storage space, and selecting the second predetermined number before Individuals to form the next generation of population NewPopulation, the minimum value NewSize of the storage space required for each body of the current population; the second predetermined number is less than or equal to the current population size value S P . PU ;
  • Step G adding TotalCounter to 1, and updating the current population with the next generation population; when NewSize is less than LastSize, setting the current value of SizeCounter to 0, and updating LastSize with the value of NewSize; when NewSize is greater than or equal to LastSize , increment the current value of SizeCounter by 1 ;
  • Step H determining whether NewSize is equal to the minimum value in the lower bound, if the judgment result is yes, ending the evolution process; if the judgment result is no, then turning to step I;
  • step B the evolution process is ended, wherein the third predetermined value MAX_NO_IMPR0VEMENT and the fourth predetermined value MAX_TOTAL are preset values.
  • the steps of performing the mutation processing include:
  • the steps of performing the cross processing include:
  • a set of elements is selected from the individual Candi with equal probability.
  • ⁇ Vi Addr selects one Candi2 different from Candi from the current population Population, and finds the starting address Addr of Vi from Candi2.
  • the initial population FirstGen is generated by the following steps:
  • the variables of the population are sequentially allocated to the adjacent storage spaces in order, that is, the corresponding individuals are obtained.
  • the set of coexisting variable sets is obtained by the following steps:
  • a coexisting variable set corresponding to the scheduling sequence is generated according to a variable that exists in the module execution process
  • the lower bound is obtained by the following steps: Obtaining a maximum value of the storage space occupied by each of the coexisting variable sets of each function scheduling order, as a lower bound of the storage space required for all variables corresponding to the function scheduling order.
  • the module model in the step 12 is generated as follows:
  • the function includes the function name, the input variable, the output variable, and the size of the storage space occupied by the output variable; the output variable of the function includes the temporary variable used in the execution of the function;
  • the module model includes an input variable, a size of a storage space occupied by the input variable, an output variable, an exception variable, and at least one set of alias variables, the output variable containing an output variable of a function within the module, the exception variable not being optimized
  • Each alias variable set contains multiple variables that are aliased to each other; when a variable has N writes, N new variables are introduced, so that any one variable is written only once; the new variable and the original variable are aliased to each other. , where N is a natural number of > 1.
  • the static storage allocation device of the present invention includes:
  • a module acquiring unit 21 which acquires a module to be optimized, where the module includes at least two functions coupled to each other;
  • the model generating unit 22 generates a module model according to the coupling relationship between the functions; the module model includes: a function name and a variable, the variable includes an input variable and an output variable; and a function scheduling order acquiring unit 23 a module model, which acquires all function scheduling orders of the module;
  • the lower bound obtaining unit 24 obtains the lower bound of the required storage space of all the variables corresponding to the module in each of the function scheduling sequences;
  • the optimization unit 25 for each function scheduling order, optimizes the address allocation information of all variables by the genetic algorithm, so that the size of the storage space occupied by all the variables approaches or reaches the minimum value of the lower bound;
  • the selecting unit 26 selects a function scheduling order in which the storage space occupied by all the variables is optimized, and the compiling unit 27 compiles the module according to the selected function scheduling order and the address allocation information corresponding to the function scheduling order.
  • the address allocation information includes: a starting address of each variable.
  • the optimization unit 25 includes:
  • the first setting subunit sets the current population Population to the initial population FirstGen, and sets the current value of the minimum storage space of the current storage space of the current population to the minimum value of LastSize, and sets the number of times the storage space does not change during the evolution.
  • the current value of SizeCounter is 0, and the current value of TotalCounter is set to 0;
  • the second setting subunit sets the current mutation probability value P mut and the current population size value S P . PU ;
  • the first selection subunit selects an individual that satisfies the following formula from the new generation population NewGen, and selects the selected population by the selected individual composition;
  • the storage space removes the subunit, and removes unused storage space for each selected body of the selected population NewNews;
  • the second selection sub-unit merges the current population Population with the selected population SelectedNewGen to obtain a collection NewAl lPopu, which will be set in each of the NewAl lPopu Sorting the size of the required storage space from small to large, selecting a second predetermined number of individuals to form a next generation population NewPopulation, and obtaining a minimum value NewSize of the storage space required by each body of the current population; The number is less than or equal to the current population size value S p . Pu ;
  • Update the subunit add TotalCounter to 1, and update the current population with the next generation population; when NewSize is less than LastSize, set the current value of SizeCounter to 0, and update LastSize with the value of NewSize; when NewSize is greater than or equal to LastSize , increment the current value of SizeCounter by 1;
  • a first determining subunit determining whether the NewSize is equal to a minimum value in the lower bound; if the judgment result is yes, ending the evolution process; if the determination result is no, starting the second determining subunit; the second determining subunit , judging whether it is satisfied (SizeCounter ⁇ MAX - NO - IMPROVEMENT) and (TotalCounter ⁇ ⁇ _rO ⁇ L), if the judgment result is no, then proceed to the step B, otherwise, the evolution process is ended, wherein the third predetermined value MAX — NO— IMPROVEMENT
  • the fourth predetermined value MAX—TOTAL is a preset value.
  • the variation/cross subunit is subjected to mutation processing specifically as follows:
  • the Offset generation method is:
  • variation/cross subunits are cross processed specifically as follows:
  • a set of elements is selected from the individual Candi with equal probability.
  • ⁇ Vi Addr selects one Candi2 different from Candi from the current population Population, and finds the starting address Addr of Vi from Candi2.
  • FIG. 3 is a schematic diagram of an exemplary module to be optimized.
  • the application scenario of the static storage allocation method according to the present invention is described below with reference to FIG. 3. As shown in FIG. 4, the method includes:
  • Step 1 Determine which module to process.
  • the modules described in the present invention consist of a series of closely coupled functions with explicit inputs and outputs. In the example shown in Figure 3, the three functions are tightly coupled together to form a module with the input "variable 1" and the output "variable 4".
  • Step 2 generate a module model, the rules are as follows:
  • the function model includes the function name, input, and output.
  • the input to a function contains a series of variables (called a set of input variables for a function).
  • the output of a function contains a series of variables and their storage size (called the output variable set of the function).
  • the module model consists of an input (called the module's input variable set), an output (called the module's output variable set), and a set of variables called the exception variable set (denoted as ExcludeSet). Variables in a variable set will be treated as being allocated by other mechanisms outside the program and not in the scope of this method.
  • the input to the module contains a series of variables and their storage size.
  • the output of the module contains a series of variables that are output by functions within the module.
  • the model includes several sets of alias variables, each of which contains a number of variables that are aliased to each other.
  • the alias relationship between variables is characterized by the set of alias variables in the model.
  • variable name A unique variable name (hereinafter referred to as "alternative name") is defined for each alias variable set after the merge, and the mapping from the variable in the alias variable set to the newly defined variable name is saved.
  • alternative name For convenience of description, define a function (variable name): If the "variable name" is included in a merged alias variable set, the (variable name) returns the variable name defined for the alias variable set; otherwise, the "variable name” is directly returned. It can also be applied to a collection of variable names: / m ( ⁇ x
  • variable name is an alternate name defined for the alias variable set, return the maximum value of the storage size of each variable in the alias variable set; otherwise return "variable name” directly The size of the storage.
  • the input to the module is “variable 1” and the output is “variable 4", where "variable 1” is externally controlled, not in the optimization range, and "variable 1" belongs to the exception variable set;
  • the sizes of "variable 1", “variable 2", “variable 3", “variable 4", and “variable 5" are s 2 , s 3 , s 4 , and s 5 respectively .
  • Function 1 Input variable set ⁇ variable 1 ⁇ , output variable set ⁇ variable 2 (size S 2 ), Variable 5 (size S 5 ) ⁇ ;
  • variable 2 since function 2 rewrites variable 2, the new variable "variable 2 '" is introduced in the model to represent the updated variable 2, and they are written into an alias variable set.
  • Step 3 according to the module model, get all possible function scheduling paths.
  • ScheduleType - the item is the scheduling path Path, which is a list of function names; and one is the set of existing inputs corresponding to the path, ReadySet.
  • Step 30 Initialize the ScheduleType set, and the ScheduleSet contains only one ScheduleType data Schedule its Path. An empty list, its ReadySet. The set of input variables for the module.
  • Step 31 Initialize an empty set NewScheduleSet, and execute Step 311-313 for each Schedulei in the ScheduleSet, where the scheduled path in Schedulei is recorded as Pathi, and the set of existing inputs is recorded as ReadySeti
  • Step 311 if the output variables of the module are all included in ReadySeti, put Schedulei into NewScheduleSet, and then go to step 31 to process the next element in the ScheduleSet.
  • Step 312 selecting all candidate functions that can be called from the functions that have not been called yet, Into the collection FunCandidates.
  • the criterion for the candidate function is: The input variables are all included in ReadySeti o If FunCandidates is an empty set, the module model is incorrect and ends directly.
  • Step 313 For each candidate function Candidatej in FunCandidates, perform steps 3131-3132, where j represents the sequence number of the candidate function.
  • Step 3131 attach Candidatej to the end of Pat, denoted Path ⁇ , merge the output of Candidatej into the set ReadySeti, recorded as
  • Step 3132 using Pathiij, ReadySet ⁇ to form Schedule ⁇ , and put into the collection NewScheduleSet.
  • Step 32 Compare the collection NewScheduleSet with the ScheduleSet. If the two are different, replace the ScheduleSet with NewScheduleSet and go to step 31.
  • Step 33 Extract the Path in each Schedule in the ScheduleSet and form a set PathSet.
  • Step 4 Export a storage allocation scheme Al locPla for each Pathi in the PathSet, as described in steps 41-45.
  • Al locPla is a list of storage allocation and release commands.
  • the assignment command contains the variable name of the assigned variable
  • the release command contains the variable name of the variable to be released.
  • Step 41 Initialize the command list Al locPla to null, set the temporary variable Al located to the assigned variable set to be an empty set, and record a copy of Pat as ThisPath.
  • Step 42 Set a temporary variable NeedAl locSet representing the variable set to be allocated as (the input variable set of the module), and set a temporary variable CanFreeSet indicating the variable set to be released as an empty set.
  • Step 43 a release command is generated for each variable in the temporary variable CanFreeSet to be appended to the end of Al locPla, and the order in which the commands are generated may be arbitrarily selected.
  • Step 44 Append an allocation command to each variable in the NSet to append to the end of Al locPla.
  • the order in which the commands are generated can be arbitrarily selected.
  • NSet is given by:
  • NSet NeedAllocSet - f m (ExcludeSet), also in accordance with Set - NeedAllocSet - f m (ExcludeSet) and NSet - NeedAllocSet - / m (ExcludeSet) update NSet - NeedAllocSet - m (ExcludeSet).
  • Step 45 Update Al located as follows:
  • Step 46 If ThisPath is not empty, perform steps 461-463. Step 461. Calculate the set of variables that can not be released currently s d ⁇ as follows
  • Step 462 the first element in ThisPath is F. Update the NeedAl locSet as follows:
  • Step 463 remove the first element in ThisPath and go to step 43.
  • Step 5 a set of "coexistence variable sets" is derived for each path. Specifically, the storage allocation scheme Al locPla corresponding to each Pathi in the PathSet is analyzed, and each element in the collection VarGroup ⁇ VarGroupi is a non-empty set containing a plurality of variables, and the collections are called "total”. Save the variable set. The specific steps for getting VarGroupi are shown in step 51_53.
  • Step 51 Initialize VarGroupi to an empty set; create a temporary variable CurSet representing the set of coexisting variables, and initialize it to an empty set; create an AllocFlag indicating the last assigned command type as "Assignment".
  • Step 52 sequentially traversing AllocPla, and performing a step 521 for each command Cmd in AllocPla.
  • Step 53 If CurSet is not an empty set, put the CurSet into VarGroup ⁇
  • the genetic algorithm is used to optimize the storage allocation, where the individual contains all the variables that need to be allocated (that is, all variables that appear in each AllocPla) and their starting addresses.
  • the population is a collection of individuals. For the sake of clarity, the following describes the individual as a collection of a set of two-part groups containing the variable name and its starting address, and is written as " ⁇ variable name, starting address.”
  • Step 6 Obtain the lower bound Infi of the required storage space for each Pat in the PathSet, and the initial population FirstGe, where i represents the sequence number of each function scheduling order. Specific steps such as Shown 61-64.
  • Step 61 Find the union of each element in VarGroupi, and record it as AllVar:
  • Step 62 calculate the lower bound Infi as follows:
  • Step 63 Record the number of all elements in AllVar as N, and obtain at most INIT-POPU-SIZE arrangement of all elements in AllVar, which is recorded as Perms. The method is as follows:
  • Step 64 For each permutation in Perms, obtain corresponding individuals, and combine the individuals to obtain FirstGen.
  • the step of obtaining an individual corresponding to a certain arrangement P in Perms is 641.
  • Step 7 press Infi to arrange each Pat in the PathSet from small to large, select the smallest at most INIT-CANDI-SIZE item, constitute CandiPathSet, and call each Infi minimum as the lower bound of the required storage size of the module. , as Inf.
  • Step 8 Arranging each Pat in the CandiPathSet onto one or more processors or processor cores, and using a genetic algorithm to evolve the population corresponding to each Pathi to approach or reach the respective Infi, thereby approaching or reaching Inf .
  • Step 9 After the evolution process for each Pat is terminated, finally select the lowest-occupied individuals in all the Pats, and give the starting address of each variable, the corresponding Pathi, and the set of aliases from the alias variable set.
  • the information such as the correspondence between variables and alternative names is modified according to the above information to achieve the purpose of saving storage.
  • Step A set the Population Population to FirstGeni, and set the minimum value to be stored in each generation of the population.
  • LastSize is infinity. The storage size does not change when the evolution is performed. SizeCounter is 0, and the total number of evolutions is TotalCounter is 0.
  • Step B Set the mutation probability P mut and the population size S P for the current breeding. PU .
  • P mut S p .
  • Pu decreases as the evolution progresses.
  • Step C for each individual Candi in the Population, which is mutated with the probability P mut (also called “mutation”), with a probability (l - P mut ) crossing (also called mating), resulting in each new individual NewCandi ⁇ If a t ⁇ NewGeno
  • P mut also called “mutation”
  • l - P mut probability crossing
  • Step Cl select a set of ⁇ Vi from Candi with equal probability
  • Addr produces an integer Offset randomly distributed in the interval [i, the larger the value, the smaller the probability of occurrence.
  • [ ⁇ 1 means round up
  • Size is the size that the individual Candi needs to store, which is given by:
  • the generation method of the Offset can be arbitrarily constructed, for example, the method as shown in step C11.
  • Step C11, ⁇ [ 5 ⁇ £ ' 2 ⁇ ( ⁇ )
  • Offset M - round (a random number uniformly distributed between M * J[0, 1]) + 1 where round indicates rounding.
  • Step C2 select a group of Vi from Candi with equal probability, Addr selects a body Candi2 different from Candi from the medium probability of Population, and finds the starting address Addr of Vi from Candi2.
  • Step D use the set of "coexistence variable sets" to screen individuals and directly eliminate individuals who do not meet the conditions. Specifically: From the NewGen, select the individual that meets the VarGroupi requirements, that is, the individual that satisfies the following formula:
  • Step E for each body of SelectedNewGen, by removing unused storage space The size of the small required storage. Specifically, for a certain body Candi, if it is found that there is not any one
  • Step F combine the two populations of Population and SelectedNewGen to obtain the set NewAllPopu, and sort each body in NewAllPopu according to the size of the required storage (calculation formula see step C1) (the minimum value of the required storage is recorded as NewSize), size The same sort order can be arbitrarily selected, and then at most S P can be selected.
  • the PU individuals constitute the set NewP 0 pulati 0 n. (Note: Here the size of the required storage is used to characterize the individual's fitness. The smaller the required storage, the greater the fitness, and vice versa.)
  • Step G update the relevant state and counter of the genetic algorithm:
  • LastSize NewSize SizeCounter 0
  • NewSize ⁇ LastSize Compare ewSize with LastSize:
  • Step I if (SizeCounter ⁇ ⁇ MAX TOTAL), Bjj changes to B, otherwise the smallest individual stored in the Population is the result of the optimization, and the evolution process ends.
  • INIT_POPU_SIZE can be flexibly set according to the complexity of the module.
  • step 8 if the final required storage size is larger than Inf, MAX-NO-IMROVEMENT and MAX_TOTAL may be increased, ⁇ T-POPU-SIZE may be increased as appropriate, and the mutation probability P mut and population size S p may be fine-tuned. Adjustment The strategy is then re-executed in step 8, until the final required storage size is equal to Inf or it is considered that the optimization results obtained from the genetic algorithm are acceptable.
  • Step 9 Compile the program according to the optimization result.
  • the application scenario of the static storage allocation method according to the present invention will be described below with reference to FIG.
  • the method includes:
  • Step 1 Determine which module to process.
  • the module described in the present invention consists of a series of closely coupled functions with explicit inputs and outputs.
  • Step 2 generate a module model.
  • the input to the module is “variable 1" and the output is “variable 4", where "variable 1” is externally controlled and not in the optimization range; "variable 1", “variable 2", " The variables 3", “variable 4", and “variable 5" are S 2 , S 3 , S 4 , and S 5 respectively ; after function 2 is executed, the contents of variable 2 are updated, and function 3 is updated with variable 3 and The variable 2 is the input, and the model of the module can be obtained as follows:
  • Function 1 Input variable set ⁇ variable 1 ⁇ , output variable set ⁇ variable 2 (size S 2 ), variable 5 (size S 5 ) ⁇
  • Step 3 get all the scheduling methods. There is only one in Figure 3: fl-->f2->f3.
  • Step 4 Storage allocation scheme:
  • Step 5 get a collection of coexisting variable sets: ⁇ alias— v2, v5, v3 ⁇ , ⁇ alias— v2, v4, v3 ⁇
  • the scheduling path fl->f2-->f3 corresponds to a storage with a bound of 130, and the initial population is:
  • the minimum value of Inf of the lower bound of each scheduling method is also 130.
  • Step 7 Since there is only one scheduling path, this trick does not require special handling.
  • Step 8 The genetic algorithm enables the storage allocation to reach Inf, and the algorithm ends. During the process of genetic algorithm, several generations are intercepted as follows: (listing the individual storage space and the corresponding storage space size)
  • Step 9 The 46th generation is selected, and the program is compiled according to the 46th generation.
  • the means for implementing the above steps includes four units as shown in FIG.
  • the model generating unit which is equivalent to the module acquiring unit and the model generating unit, performs the above steps 1, 2, analyzes the source code of the module to be optimized, and generates a model of the module to be optimized;
  • the model processing unit is equivalent to the function scheduling order obtaining unit and the lower bound obtaining unit, and performs the above steps 3 to 7, and processes the module model to complete various preparations for performing step 8 and steps A to I.
  • the model processing module will also determine four parameters, such as INIT-C AND I-SIZE, MAX-NO-IMROVEMEN MAX-TOTAL, ⁇ T-POPU-SIZE, used in the genetic algorithm according to the size of the module to be optimized, etc. The calculation can be performed as shown in the following table:
  • the genetic algorithm unit which is equivalent to the above-mentioned optimization unit, performs steps A to I to optimize the storage size required for a specific scheduling method of the function in the module, the module is started by the algorithm control module, and the optimization result is transmitted to The algorithm control module; the genetic algorithm module, when performing step B, sets the mutation probability P mut and the population size S P applicable to the current breeding.
  • PU here P mut , S P .
  • the PU decreases as the evolution progresses, for example, according to the size of (TotalCmmter/MAX_TOTAL):
  • the algorithm control unit performs step 8 to optimize the storage size required by the various scheduling methods of the functions in the module by using the genetic algorithm module, and finally obtains the minimum variable allocation method and corresponding function scheduling method required by the module, and completes the static storage. Optimized processing of allocation;
  • the compilation unit compiles according to the above optimization processing result.
  • the algorithm control module can simultaneously run the algorithm control module for different scheduling methods on these processors or processor cores, Evolve different scheduling methods, make full use of computing resources, and improve optimization speed.
  • multiple threads may be created according to the number of processors or processor cores, and each thread runs a genetic algorithm module for a certain scheduling method, and usually these threads will be automatically assigned to different processors or processed by the operating system. Executed on the kernel.
  • the invention discloses an optimization method and device for applying static storage allocation.
  • the method utilizes a genetic algorithm to multiplex statically allocated storage as much as possible, thereby reducing the need for storage size and optimizing static storage allocation.
  • the invention generates a module model, analyzes the model to obtain different function calling paths, uses a genetic algorithm for each path to reduce the storage size requirement by using storage multiplexing as much as possible, and finally adopts a function calling path that needs to store the least, thereby realizing
  • the optimization of the storage size of the entire module reaches or approaches the lower bound of the storage size corresponding to the function call path.
  • the invention improves the utilization of the storage space, reduces the requirement for the storage space, and multiplexes the same storage space for variables that do not need to exist at the same time, thereby reducing the storage space, reducing the power consumption, and reducing the cost.
  • the method of the present invention has the following advantages:
  • the method of the present invention can be easily re-optimized to make the code easy to maintain.
  • the method of the present invention has at least the following advantages:
  • the modules described in the present invention refer to a number of functions, processes or methods that are closely related or coupled together in order to perform a certain function in programming, or independent processes that can be processed by a compiler, an assembly program, or the like.
  • Program unit or part of a large software system.
  • the method embodiment is corresponding to the device embodiment, and the portion not described in detail in the method embodiment may refer to the description of the relevant part in the device embodiment, and the partial reference method not described in detail in the device embodiment.
  • the description of the relevant parts in the embodiment can be.
  • the method includes the following steps, such as: a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (Random Access Memory, RAM) and so on.

Description

技术领域
本发明涉及数据存储技术领域, 特别是指一种静态存储的分配方法和装 置。
背景技术
静态存储分配是指在程序编译时完成的存储地址的分配, 静态存储分配 与在程序运行时完成的动态存储分配不同。 静态分配没有运行时的开销, 对 程序的性能没有影响, 不存在动态分配时可能出现的分配失败等问题。
静态存储分配的灵活性差比较差, 主要体现在: 一个变量往往在程序的 整个生存期都一直占据所分配的存储空间,降低了存储空间使用上的灵活性。
现有技术中, 在 Intel 8051的一些 C语言编译器里, 实现了一定程度的 存储复用。 例如下面的两个函数 fl、 Ϊ2, 如果它们不可能同时处于活动状态 (被调用状态), 那么可以将 fl、 f2里静态分配的变量 vl、 v2复用同一 100 字节的存储空间。 若不进行复用, 则需要 200个字节的存储空间。
void fl() static char vl [100];
}
void f2() static char v2 [100] 变量。
发明内容
本发明要解决的技术问题是提供一种静态存储的分配方法和装置, 能够 减少对存储空间的需求。
为解决上述技术问题, 本发明的实施例提供技术方案如下:
一方面, 提供一种静态存储的分配方法, 包括:
歩骤 1, 获取待优化的模块, 所述模块包括至少两个相互耦合的函数; 歩骤 2, 根据所述函数之间的耦合关系, 生成一模块模型; 所述模块模型 包括: 函数名称和变量, 所述变量包括输入变量和输出变量;
歩骤 3, 根据所述模块模型, 获取所述模块的所有的函数调度顺序; 歩骤 4, 获取所述模块在每个所述函数调度顺序下对应的所有变量所需存 储空间的下确界;
歩骤 5, 对每一种函数调度顺序, 通过遗传算法优化所有变量的地址分配 信息, 使所有变量占用的存储空间的大小趋近或到达所述下确界的最小值; 歩骤 6, 选择优化后所有变量占用的存储空间最小的函数调度顺序; 歩骤 7, 根据选择的所述函数调度顺序和所述函数调度顺序对应的地址分 配信息,对所述模块进行编译,所述地址分配信息包括:各变量的起始地址。
所述歩骤 4之后, 所述方法还包括:
将每个所述函数调度顺序按照其对应的所述下确界的大小从小到大排序, 选择前第一预定数量个所述函数调度顺序;
所述歩骤 5具体为: 对选择出的每一种函数调度顺序, 通过遗传算法优化 所有变量的地址分配, 使所有变量占用的存储空间的大小趋近或到达所述下 确界的最小值。 所述歩骤 5包括:
歩骤 A, 设置当前种群 Populat ion为初始种群 FirstGen, 设置当前种群 的上一代种群中的各个体所需存储空间的最小值 LastSize 的当前值为无穷 大, 设置演化时存储空间大小未变化的次数 SizeCounter 的当前值为 0, 设 置总演化次数 TotalCounter的当前值为 0;
歩骤 B, 设置当前变异概率值 P,,,ut和当前种群规模值 SPPU
歩骤 C, 对当前种群 Population里的每一个体 Candi , 使其以所述概率值 Pmut进行变异处理, 以概率 (i - Pmut)进行交叉处理, 产生各新个体 NewCandi ; 歩骤 D, 从新一代种群 NewGen 中选出满足以下公式的个体, 并用选择出 的个体组成选择出的种群 SelectedNewGen;
所述公式为: 对于每一个 G e VarGroupi里的任意两个不同的变量 v!、 vk
[Add Addrz + s (v;)— 1] n [Addrfe, Addrfe + s (vfe)— 1] = Φ ;
其中, [Addrx, Addrx + s(vx) - 1]表示变量^所用存储空间的起止位置所对应的 区间;
歩骤 E, 对选择出的种群 SelectedNewGen的各个体, 去除未使用的存储 空间;
歩骤 F, 将当前种群 Population和选择出的种群 SelectedNewGen合并, 得到集合 NewAl lPopu, 将集合 NewAl lPopu里的各个体按所需存储空间的大 小从小到大排序, 从中选出前第二预定数量个个体以构成下一代种群 NewPopulation, 获取当前种群的各个体所需存储空间的最小值 NewSize; 所 述第二预定数量小于或等于当前种群规模值 SPPU ;
歩骤 G, 将 TotalCounter加 1, 并使用所述下一代种群更新当前种群; 当 NewSize小于 LastSize时,将 Si zeCounter的当前值设置为 0,并使用 NewSize 的值更新 LastSize; 当 NewSize大于或等于 LastSize时, 将 SizeCounter 的当前值加 1 ;
歩骤 H, 判断 NewSize是否等于所述下确界中的最小值, 如果判断结果为 是, 则结束演化过程; 如果判断结果为否, 则转向歩骤 I; 歩骤 I, 判断是否满足 (SizeCounter < MAX— NO— IMPROVEMENT)且 (TotalCounter <
MAX TOTAL) , 如果判断结果为否, 则转向所述歩骤 B, 否则, 结束演化过程, 其中, 第三预定值 MAX— NO— IMPROVEMENT 第四预定值 MAX— TOTAL为预先设置 的值。
所述进行变异处理的歩骤包括:
从个体 Candi 中以等概率选出一组元素 Addr 产生一个随机分布于区 间 [i, 的整数 Offset, 其中 [·1表示向上取整运算, Size为个体 Candi 所需存储空间的大小, gPsize = maXi=1...N (Addri + /s (Vi)), 其中, 元素〈 , Addr 表示 变量〈Vi, Addi ^和所述变量的起始地址〈Vi, Addr
先以预定概率将 Offset 的当前值生成相反数, 并使用所述相反数更新
Offset , 然后使用〈v (Addr! + Offset) mod (Size - 代替〈 , Addr , 得到新个体
NewCandi , 其中, mod表示取余运算;
其中, Size = maxi=1...N (Addri +/s(V )表示: 如果变量名是为别名变量集定义的 替代名, 则返回该别名变量集中各变量所占存储空间大小的最大值; 否则返 回变量名所占存储空间的大小;
所述 Offset生成方法为:
变量 M = [size-A ( ) 1― 1, 贝 |Joffset = M - round + 1,
Figure imgf000006_0001
其中, round表示四舍五入运
所述进行交叉处理的歩骤包括: 从个体 Candi中以等概率选出一组元素〈Vi, Addr 从当前种群 Population 中以等概率选出异于 Candi 的一个体 Candi2, 从 Candi2找到 Vi的起始地址
Addr, 。
用〈 , Addr; >代替〈 , Addr 得到新个体 NewCandi。
所述初始种群 FirstGen通过以下歩骤生成:
求出共存变量集的集合 VarGroupi中各元素的并集, 记作 Al lVar;
将 Al lVar里的所有元素的个数记作 N, 得到 Al lVar里的所有元素的第五 预定数量种排列, 记作 Perms , 所述第五预定数量小于或者等于 INIT— POPU— SIZE, 所述 INIT— POPU— SIZE为预先设置值;
针对 Perms里的每一种排列,得到对应的各个个体,将这些个体组成集合, 生成所述初始种群 FirstGen;
所述个体为以下歩骤获取的:
将种群的各变量按照先后顺序依次分配相邻的存储空间,即得到对应的个 体。
所述共存变量集的集合是通过以下歩骤获取的:
获取所述模块按照所述函数调度顺序进行处理时,根据所述模块执行过程 中同时存在的变量的情况, 生成与该调度顺序对应的共存变量集;
组合所述共存变量集, 生成共存变量集的集合;
所述下确界是通过以下歩骤获取的:
获取每个函数调度顺序的各个所述共存变量集占用的存储空间的最大值, 作为所述函数调度顺序对应的所有变量所需存储空间的下确界。
所述歩骤 2中模块模型按照如下方式生成:
函数包括函数名称、输入变量、输出变量以及输出变量所占存储空间的大 小; 函数的输出变量包括函数执行过程中用到的临时变量;
同一函数被多次调用时, 使用不同的函数名称;
模块模型包括输入变量、 输入变量所占存储空间的大小、 输出变量、 例外 变量以及至少一个别名变量集, 所述输出变量包含所述模块内的函数的输出 变量, 所述例外变量不被优化处理, 每个别名变量集包含多个互为别名关系 的变量; 当一个变量出现 N次写入, 则引入 N个新变量, 使得任何一个变量 只被写入一次; 新变量与原变量互称别名, 其中, N为〉 1的自然数。
另一方面, 提供一种静态存储的分配装置, 包括:
模块获取单元, 获取待优化的模块, 所述模块包括至少两个相互耦合的函 数;
模型生成单元, 根据所述函数之间的耦合关系, 生成一模块模型; 所述模 块模型包括: 函数名称和变量, 所述变量包括输入变量和输出变量;
函数调度顺序获取单元, 根据所述模块模型, 获取所述模块的所有的函数 调度顺序;
下确界获取单元,获取所述模块在每个所述函数调度顺序下对应的所有变 量所需存储空间的下确界;
优化单元, 对每一种函数调度顺序, 通过遗传算法优化所有变量的地址分 配信息,使所有变量占用的存储空间的大小趋近或到达所述下确界的最小值; 选择单元, 选择优化后所有变量占用的存储空间最小的函数调度顺序; 编译单元,根据选择的所述函数调度顺序和所述函数调度顺序对应的地址 分配信息, 对所述模块进行编译, 所述地址分配信息包括: 各变量的起始地 址。
本发明的实施例具有以下有益效果: 上述方案中, 通过函数间的数据依赖关系, 从程序的全局出发, 对变量的 静态分配进行优化,能够尽可能多地复用存储空间,减少对存储空间的需求。 附图说明
图 1为本发明的所述的静态存储的分配方法的流程示意图;
图 2为本发明的所述的静态存储的分配装置的结构示意图;
图 3为一待优化模块的示意图;
图 4为本发明的所述的静态存储的分配方法的应用场景的流程示意图; 图 5为本发明的所述的静态存储的分配方法中遗传算法的流程示意图; 图 6为本发明的所述的静态存储的分配装置的应用场景的结构示意图。 具体实施方式
为使本发明的实施例要解决的技术问题、 技术方案和优点更加清楚, 下 面将结合附图及具体实施例进行详细描述。
本发明是一种适用于静态存储分配的优化方法和装置, 尤其适用于存储 资源有限的嵌入式处理器领域的静态存储分配。 通过一系列函数间的数据依 赖关系, 从全局出发, 对静态变量、 全局变量等的静态分配进行优化, 以尽 可能多地复用存储空间, 减少对存储空间的需求。
例如下面的例子中, vl仅被函数 f l、 f2使用, v2仅被函数 f3、 f4使用, 四个函数被顺次调用, 这时, vl、 v2也可复用相同的存储空间。
char vl [ 100];
char v2 [ 100];
void f l () { II 使用 vl }
void f2 () { II 使用 vl } void f3() { II使用 v2 } void f4() { II使用 v2 }
本发明中用到了集合的若干种运算, 为描述方便, 集中说明如下: 交集: AnB
Figure imgf000010_0001
并集: 4uB ^{x|xe^xeB}
差集: A-B
Figure imgf000010_0002
如图 1所示, 为本发明所述的一种静态存储的分配方法, 包括: 歩骤 11, 获取待优化的模块, 所述模块包括至少两个相互耦合的函数; 歩骤 12, 根据所述函数之间的耦合关系, 生成一模块模型; 所述模块模 型包括: 函数名称和变量, 所述变量包括输入变量和输出变量;
歩骤 13, 根据所述模块模型, 获取所述模块的所有的函数调度顺序; 歩骤 14, 获取所述模块在每个所述函数调度顺序下对应的所有变量所需 存储空间的下确界;
歩骤 15, 对每一种函数调度顺序, 通过遗传算法优化所有变量的地址分 配信息,使所有变量占用的存储空间的大小趋近或到达所述下确界的最小值; 歩骤 16, 选择优化后所有变量占用的存储空间最小的函数调度顺序; 歩骤 17, 根据选择的所述函数调度顺序和所述函数调度顺序对应的地址 分配信息, 对所述模块进行编译, 所述地址分配信息包括: 各变量的起始地 址。
所述歩骤 14之后, 所述方法还包括:
将每个所述函数调度顺序按照其对应的所述下确界的大小从小到大排序, 选择前第一预定数量个所述函数调度顺序;
所述歩骤 15具体为: 对选择出的每一种函数调度顺序, 通过遗传算法优 化所有变量的地址分配, 使所有变量占用的存储空间的大小趋近或到达所述 下确界的最小值。
所述歩骤 15包括:
歩骤 A, 设置当前种群 Populat ion为初始种群 FirstGen, 设置当前种群 的上一代种群中的各个体所需存储空间的最小值 LastSize 的当前值为无穷 大, 设置演化时存储空间大小未变化的次数 SizeCounter 的当前值为 0, 设 置总演化次数 TotalCounter的当前值为 0;
歩骤 B, 设置当前变异概率值 P,,,ut和当前种群规模值 SPPU
歩骤 C, 对当前种群 Population里的每一个体 Candi , 使其以所述概率值 Pmut进行变异处理, 以概率 (i - Pmut)进行交叉处理, 产生各新个体 NewCandi ; 歩骤 D, 从新一代种群 NewGen 中选出满足以下公式的个体, 并用选择出 的个体组成选择出的种群 SelectedNewGen;
所述公式为: 对于每一个 G e VarGroupi里的任意两个不同的变量 V!、 vk
[Addr!, Add + s (v;) - 1] Π [Addrfe, Addrfe + s (vfe)— 1] = Φ;
其中, G表示集合 VarGroupi里的一个元素。 "≡ "表示集合里的 "属于" 关系。
其中, [Addrx, Addrx + s(vx) - 1]表示变量^所用存储空间的起止位置所对应的 区间;
歩骤 E, 对选择出的种群 SelectedNewGen的各个体, 去除未使用的存储 空间;
歩骤 F, 将当前种群 Population和选择出的种群 SelectedNewGen合并, 得到集合 NewAl lPopu, 将集合 NewAl lPopu里的各个体按所需存储空间的大 小从小到大排序, 从中选出前第二预定数量个个体以构成下一代种群 NewPopulation, 获取当前种群的各个体所需存储空间的最小值 NewSize; 所 述第二预定数量小于或等于当前种群规模值 SPPU ;
歩骤 G, 将 TotalCounter加 1, 并使用所述下一代种群更新当前种群; 当 NewSize小于 LastSize时,将 SizeCounter的当前值设置为 0,并使用 NewSize 的值更新 LastSize; 当 NewSize大于或等于 LastSize时, 将 SizeCounter 的当前值加 1 ;
歩骤 H, 判断 NewSize是否等于所述下确界中的最小值, 如果判断结果为 是, 则结束演化过程; 如果判断结果为否, 则转向歩骤 I;
判断是否满足 (SizeCounter < MAX— NO— IMPROVEMENT)且 (TotalCounter <
MAX TOTAL) , 如果判断结果为否, 则转向所述歩骤 B, 否则, 结束演化过程, 其中, 第三预定值 MAX— NO— IMPR0VEMENT、 第四预定值 MAX— TOTAL为预先设置 的值。
所述进行变异处理的歩骤包括:
从个体 Candi 中以等概率选出一组元素 Addr 产生一个随机分布于区 间 [i, 的整数 Offset , 其中 [·1表示向上取整运算, Size为个体 Candi 所需存储空间的大小, gPsize = maXi=1...N (Addri + /s (Vi)), 其中, 元素〈 , Addr 表示 变量〈Vi, Addi ^和所述变量的起始地址〈Vi, Addr
先以预定概率将 Offset 的当前值生成相反数, 并使用所述相反数更新
Offset , 然后使用〈v (Addr! + Offset) mod (Size - /s (Vi) 代替〈 , Addr , 得到新个体
NewCandi , 其中, mod表示取余运算;
其中, Size = maxi=1...N (Addri + /s(V )表示: 如果变量名是为别名变量集定义的 替代名, 则返回该别名变量集中各变量所占存储空间大小的最大值; 否则返 回变量名所占存储空间的大小; 所述 Offset生成方法为:
令变量 M = [Size_n― 1, 贝 Ijoffset = M - round (M * J [0, 1]之间均匀分布的随机数) + 1, 其中, round表示四舍五入运算。
所述进行交叉处理的歩骤包括:
从个体 Candi中以等概率选出一组元素〈Vi,Addr 从当前种群 Population 中以等概率选出异于 Candi 的一个体 Candi2, 从 Candi2找到 Vi的起始地址 Addr, 。
用〈 , Addr; >代替〈 , Addr 得到新个体 NewCandi。
所述初始种群 FirstGen通过以下歩骤生成:
求出共存变量集的集合 VarGroupi中各元素的并集, 记作 Al lVar;
将 Al lVar里的所有元素的个数记作 N, 得到 Al lVar里的所有元素的第五 预定数量种排列, 记作 Perms , 所述第五预定数量小于或者等于 INIT— P0PU— SIZE, 所述 INIT— P0PU— SIZE为预先设置值;
针对 Perms里的每一种排列,得到对应的各个个体,将这些个体组成集合, 生成所述初始种群 FirstGen;
所述个体为以下歩骤获取的:
将种群的各变量按照先后顺序依次分配相邻的存储空间,即得到对应的个 体。
所述共存变量集的集合是通过以下歩骤获取的:
获取所述模块按照所述函数调度顺序进行处理时,根据所述模块执行过程 中同时存在的变量的情况, 生成与该调度顺序对应的共存变量集;
组合所述共存变量集, 生成共存变量集的集合;
所述下确界是通过以下歩骤获取的: 获取每个函数调度顺序的各个所述共存变量集占用的存储空间的最大值, 作为所述函数调度顺序对应的所有变量所需存储空间的下确界。
所述歩骤 12中模块模型按照如下方式生成:
函数包括函数名称、输入变量、输出变量以及输出变量所占存储空间的大 小; 函数的输出变量包括函数执行过程中用到的临时变量;
同一函数被多次调用时, 使用不同的函数名称;
模块模型包括输入变量、 输入变量所占存储空间的大小、 输出变量、 例外 变量以及至少一个别名变量集, 所述输出变量包含所述模块内的函数的输出 变量, 所述例外变量不被优化处理, 每个别名变量集包含多个互为别名关系 的变量; 当一个变量出现 N次写入, 则引入 N个新变量, 使得任何一个变量 只被写入一次; 新变量与原变量互称别名, 其中, N为〉 1的自然数。
如图 2所示, 为本发明所述的静态存储的分配装置, 包括:
模块获取单元 21, 获取待优化的模块, 所述模块包括至少两个相互耦合 的函数;
模型生成单元 22, 根据所述函数之间的耦合关系, 生成一模块模型; 所 述模块模型包括: 函数名称和变量, 所述变量包括输入变量和输出变量; 函数调度顺序获取单元 23, 根据所述模块模型, 获取所述模块的所有的 函数调度顺序;
下确界获取单元 24, 获取所述模块在每个所述函数调度顺序下对应的所 有变量所需存储空间的下确界;
优化单元 25, 对每一种函数调度顺序, 通过遗传算法优化所有变量的地 址分配信息, 使所有变量占用的存储空间的大小趋近或到达所述下确界的最 小值; 选择单元 26,选择优化后所有变量占用的存储空间最小的函数调度顺序; 编译单元 27, 根据选择的所述函数调度顺序和所述函数调度顺序对应的 地址分配信息, 对所述模块进行编译, 所述地址分配信息包括: 各变量的起 始地址。
所述优化单元 25包括:
第一设置子单元, 设置当前种群 Population为初始种群 FirstGen, 设置 当前种群的上一代种群中的各个体所需存储空间的最小值 LastSize 的当前 值为无穷大, 设置演化时存储空间大小未变化的次数 SizeCounter的当前值 为 0, 设置总演化次数 TotalCounter的当前值为 0;
第二设置子单元, 设置当前变异概率值 Pmut和当前种群规模值 SPPU ;
变异 /交叉子单元, 对当前种群 Population里的每一个体 Candi , 使其以 所述概率值 Pmut进行变异处理, 以概率 (i - Pmu 进行交叉处理, 产生各新个体 NewCandi;
第一选择子单元, 从新一代种群 NewGen中选出满足以下公式的个体, 并 用选择出的个体组成选择出的种群 SelectedNewGen;
所述公式为: 对于每一个 G e VarGroupi里的任意两个不同的变量 、 vfc
[Addr!, Add + s (v;) - 1] Π [Addrfe, Addrfe + s (vfe)— 1] = Φ;
其中, [Addrx, Addrx + s(vx) - 1]表示变量^所用存储空间的起止位置所对应的 区间;
存储空间去除子单元, 对选择出的种群 SelectedNewGen的各个体, 去除 未使用的存储空间;
第二选择子单元, 将当前种群 Population 和选择出的种群 SelectedNewGen合并, 得到集合 NewAl lPopu, 将集合 NewAl lPopu里的各个 体按所需存储空间的大小从小到大排序, 从中选出前第二预定数量个个体以 构成下一代种群 NewPopulation, 获取当前种群的各个体所需存储空间的最 小值 NewSize; 所述第二预定数量小于或等于当前种群规模值 Sppu ;
更新子单元, 将 TotalCounter加 1, 并使用所述下一代种群更新当前种 群; 当 NewSize小于 LastSize时, 将 SizeCounter的当前值设置为 0, 并使 用 NewSize 的值更新 LastSize; 当 NewSize大于或等于 LastSize 时, 将 SizeCounter的当前值加 1 ;
第一判断子单元, 判断 NewSize是否等于所述下确界中的最小值, 如果判 断结果为是,则结束演化过程;如果判断结果为否,则启动第二判断子单元; 第二判断子单元, 判断是否满足 (SizeCounter < MAX— NO— IMPROVEMENT)且 (TotalCounter < ^_rO^L) , 如果判断结果为否, 则转向所述歩骤 B, 否则, 结 束演化过程,其中,第三预定值 MAX— NO— IMPROVEMENT 第四预定值 MAX— TOTAL 为预先设置的值。
所述变异 /交叉子单元进行变异处理具体为:
从个体 Candi 中以等概率选出一组元素 Addr 产生一个随机分布于区 间 [i, ^¾的整数 Offset , 其中 [·1表示向上取整, Size为个体 Candi所需 存储空间的大小, gPsize = maXi=1...N (Addri + /s (Vi)), 其中, 元素〈 , Addi ^表示变量 和所述变量的起始地址;
先以预定概率将 Offset 的当前值生成相反数, 并使用所述相反数更新
Offset , 然后使用〈v (Addr! + Offset) mod (Size - /s (Vi) 代替〈 , Addr , 得到新个体
NewCandi , 其中, mod表示取余运算;
其中, Size = maxi=1...N (Addri + /s(V )表示: 如果变量名是为别名变量集定义的 替代名, 则返回该别名变量集中各变量所占存储空间大小的最大值; 否则返 回变量名所占存储空间的大小;
所述 Offset生成方法为:
令变量 M = [Size_n― 1, 贝 Ijoffset = M - round (M * J [0, 1]之间均匀分布的随机数) + 1, 其中, round表示四舍五入。
所述变异 /交叉子单元进行交叉处理具体为:
从个体 Candi中以等概率选出一组元素〈Vi,Addr 从当前种群 Population 中以等概率选出异于 Candi 的一个体 Candi2, 从 Candi2找到 Vi的起始地址 Addr, 。
用〈 , Addr; >代替〈 , Addr 得到新个体 NewCandi。
图 3为一示例性的待优化模块的示意图, 以下结合图 3说明本发明所述的 静态存储的分配方法的应用场景。 如图 4所示, 所述方法包括:
歩骤 1, 确定要处理的模块。 本发明中所述的模块由一系列紧密耦合在一 起的函数构成, 具备明确的输入和输出。 如图 3所示的例子中, 3个函数紧 密耦合在一起构成一个模块, 该模块的输入为 "变量 1 ", 输出为 "变量 4"。
歩骤 2, 生成模块模型, 规则如下:
( 1 ) 函数模型包括函数名、 输入以及输出。
( 2 ) 同一函数多次调用时, 使用不同的函数名称加以区分。
( 3 ) 函数的输入包含一系列变量 (称为函数的输入变量集)。
(4) 函数的输出包含一系列变量及其所占的存储大小 (称为函数的输出 变量集)。
( 5 ) 对于函数执行过程中用到的临时变量, 也归为函数的输出。
( 6)模块模型包括输入(称为模块的输入变量集)、 输出 (称为模块的输 出变量集) 和一个称为例外变量集 (记作 ExcludeSet ) 的变量集合, 该例外 变量集里的变量将被视为由程序外的其它机制分配而不在本方法所优化的范 围。
(7) 模块的输入包含一系列变量及其所占的存储大小。
( 8 ) 模块的输出包含一系列由模块内的函数输出的变量。
(9) 如果一个变量出现 N 麵 ) 次写入, 则分别引入 N个新的变量, 使 得任何一个变量只被写入一次; 这样的新变量与原变量互称 "别名"。
(10)模型中包括若干别名变量集, 每个别名变量集包含若干互为别名关 系的变量。 变量间的别名关系用模型里的别名变量集来表征。
将所有函数里出现的别名变量集加以归并, 具体为: 若含有相同的变量, 则并入同一集合。 为归并后的每一别名变量集定义一个唯一的变量名 (下称 "替代名"), 并保存从别名变量集里的变量到新定义的变量名的映射关系。 为描述方便, 定义函数 (变量名): 如果 "变量名 "包含于某归并后的别名 变量集中, 则 (变量名)返回为该别名变量集定义的变量名; 否则直接返回 "变量名"。 也可作用于变量名的集合: /m({x|x是变量名 返回 {/m(x)|x是变量名 }。
为描述方便, 定义函数/ (变量名): 如果 "变量名"是为别名变量集定义 的替代名, 则返回该别名变量集中各变量所占存储大小的最大值; 否则直接 返回 "变量名"所占存储的大小。
例如, 在图 3所示的例子中, 模块的输入为 "变量 1", 输出为 "变量 4", 其中 "变量 1" 由外部控制, 不在优化范围内, "变量 1"属于例外变量集; "变量 1"、 "变量 2"、 "变量 3"、 "变量 4"、 "变量 5"的大小分别为 s2、 s3、 s4、 s5, 函数 2执行后, 变量 2内的内容被更新, 函数 3用变量 3和更新过的 变量 2为输入, 据此可得到模块的模型如下:
(1) 函数 1: 输入变量集 {变量 1}, 输出变量集 {变量 2 (大小为 S2), 变量 5 (大小为 S5) };
( 2 ) 函数 2: 输入变量集 {变量 2, 变量 5}, 输出变量集 {变量 2 ' (大 小为 S2), 变量 3 (大小为 S3) };
( 3 )函数 3 : 输入变量集 {变量 2 ' , 变量 3}, 输出变量集 {变量 4 (大 小为 S4) };
(4)模块: 输入变量集 {变量 1 (大小为 }, 输出变量集 {变量 4}, 例外变量集 {变量 1}, 别名变量集 {变量 2, 变量 2 ' }。
其中, 由于函数 2改写了变量 2, 模型中引入了新的变量 "变量 2 ' "来表 示更新后的变量 2, 同时将它们写入了一个别名变量集里。
歩骤 3, 根据模块模型, 得到所有可能的函数调度路径。
为描述方便, 定义一个包含两项内容的数据结构 ScheduleType: —项为 调度路径 Path , 为函数名的列表; 一项为与该路径对应的已有输入的集合 ReadySet。
该歩骤得到包含若干 ScheduleType型数据的集合 ScheduleSet , 其中所 有的 Path即构成所有可能的函数调度方法, 具体包括:
歩骤 30,初始化 ScheduleType集, ScheduleSet为只含一个 ScheduleType 数据 Schedule 其 Path。为空列表, 其 ReadySet。为模块的输入变量集。
歩骤 31, 初始化一个空集 NewScheduleSet , 针对 ScheduleSet里的每一 项 Schedulei执行歩骤 311-313, 其中将 Schedulei里的调度路径记作 Pathi, 已有输入的集合记作 ReadySeti
歩骤 311, 如果模块的输出变量全部包含于 ReadySeti , 将 Schedulei放入 NewScheduleSet , 并转歩骤 31处理 ScheduleSet里的下一个元素。
歩骤 312, 从尚未调用的函数里选出当前可以被调用的所有候选函数, 记 入集合 FunCandidates。 候选函数的判断准则为: 其输入变量全部包含于 ReadySeti o 如果 FunCandidates为空集, 则提示模块模型有误, 直接结束。
歩骤 313, 对 FunCandidates 里的每一候选函数 Candidatej, 执行歩骤 3131-3132,其中, j表示候选函数的序号。
歩骤 3131, 将 Candidatej附加到 Pat 的末尾,记作 Path^,将 Candidatej 的输出合并到集合 ReadySeti , 记作
Figure imgf000020_0001
歩骤 3132, 用 Pathiij , ReadySet^构成 Schedule^, 并放入集合 NewScheduleSet。
歩骤 32, 比较集合 NewScheduleSet与 ScheduleSet , 如果两者不同, 则 以 NewScheduleSet代替 ScheduleSet并转歩骤 31.
歩骤 33, 将 ScheduleSet中的每一 Schedule里的 Path提取出来, 并组 成集合 PathSet。
为描述方便, 定义函数/^ s (函数名), 其返回 (该函数的输入变量集 : 1 出变量集), 并将 ^返回的集合称为函数的 "依赖集"。
例如, 在图 3所示的例子中, 函数所有的调度顺序为一种, §Ρ: 函数 1→ 函数 2→函数 3。
歩骤 4, 为 PathSet里的每一 Pathi导出存储分配方案 Al locPla , 具体 如歩骤 41-45。 这里 Al locPla 为一系列存储分配和释放命令的列表。 分配 命令包含所分配变量的变量名, 释放命令包含要释放变量的变量名。
歩骤 41, 将命令列表 Al locPla 初始化为空, 设置表示已分配变量集的 临时变量 Al located为空集, 将 Pat 复制一份记作 ThisPath。
歩骤 42, 设置表示待分配变量集的临时变量 NeedAl locSet为 (模块的 输入变量集), 设置表示待释放变量集的临时变量 CanFreeSet为空集。 歩骤 43, 为临时变量 CanFreeSet里的每一个变量产生一个释放命令追加 到 Al locPla 末尾, 这里产生命令的顺序可以任意选择。
歩骤 44, 为 NSet里的每一个变量产生一个分配命令追加到 Al locPla 末 尾, 这里产生命令的顺序可以任意选择, NSet由下式给出:
NSet NeedAllocSet - fm (ExcludeSet), 也京尤是根据 Set― NeedAllocSet - fm (ExcludeSet) 禾口 NSet— NeedAllocSet— /m (ExcludeSet) 之 间 的 差 集 来 更 新 NSet― NeedAllocSet - m (ExcludeSet)。 歩骤 45, 按下式更新 Al located:
Allocated― Allocated U NeedAllocSet, 也京尤是说: 根据 Al located 禾口 Allocated― Allocated U NeedAllocSet之间的并集来更新 Al located。 歩骤 46, 若 ThisPath不为空, 则执行歩骤 461-463。 歩骤 461.计算当前不能释放的变量的集合 sd ^如下
^deps ― (J /deps (F) U /m (模块的输出变量集)
\ThisPath里的每一函数 F / 按下式更新 CanFreeSet:
CanFreeSet Allocated― Sdeps。 歩骤 462,记 ThisPath里的第一个元素为 F。,按下式更新 NeedAl locSet:
NeedAllocSet deps (F0)― Allocated
歩骤 463, 去掉 ThisPath里的第一个元素并转歩骤 43。 歩骤 5, 对每一路径得出了 "共存变量集"的集合。具体为: 分析 PathSet 里的每一 Pathi所对应的存储分配方案 Al locPla , 得到集合 VarGroup^ VarGroupi里的每一个元素都是包含若干变量的非空集合, 称这些集合为 "共 存变量集"。 得到 VarGroupi的具体歩骤如歩骤 51_53所示。
歩骤 51, 将 VarGroupi初始化为空集; 创建表示共存变量集的临时变量 CurSet, 并初始化为空集; 创建标示上次分配命令类型的 AllocFlag为 "分 配"。
歩骤 52, 顺序遍历 AllocPla , 对 AllocPla 里的每一个命令 Cmd, 执行 歩骤 521。
歩骤 521, 由于 Cmd有 "分配"、 "释放"两种, AllocFlag亦有 "分配"、 "释放"两种, 分 4种组合方式如下:
(1) 如果 AllocFlag为 "分配"且 Cmd为分配变量 Var, 则将 Var加入 CurSet;
(2) 如果 AllocFlag为 "分配"且 Cmd为释放变量 Var, 则将 CurSet放 AVarGroupi, 然后将 CurSet清空, 并将 AllocFlag置为 "释放";
(3) 如果 AllocFlag为 "释放"且 Cmd为分配变量 Var, 则将 Var加入 CurSet, 并将 AllocFlag置为 "分配";
(4) 如果 AllocFlag为 "释放"且 Cmd为释放变量 Var, 则将 Var从集 合 CurSet中剔除。
歩骤 53.若 CurSet不为空集, 则将 CurSet放入 VarGroup^
后续歩骤中, 将利用遗传算法完成存储分配的优化, 其中个体包含所有需 要分配的变量 (即每一个 AllocPla 中出现的所有变量) 的变量名及其起始 地址, 种群是若干个体的集合。 明了起见, 以下将个体描述为一系列二元组 的集合, 二元组包含变量名及其起始地址, 并记作 "〈变量名, 起始地址 。
歩骤 6,为 PathSet里的每一 Pat 得到所需存储空间大小的下确界 Infi, 以及初始种群 FirstGe ,其中, i表示每个函数调度顺序的序号。 具体歩骤如 61-64所示。
歩骤 61, 求出 VarGroupi中各元素的并集, 记作 AllVar:
AllVar S
Figure imgf000023_0001
oupj
歩骤 62, 计算下确界 Infi如下:
Infi = max
GGVarGroupj
Figure imgf000023_0002
歩骤 63, 将 AllVar里的所有元素的个数记作 N, 得到 AllVar里的所有元 素的至多 INIT— POPU— SIZE种排列, 记作 Perms, 方法如下:
( 1 ) 如果 N! > INIT_POPU_SIZE (这里 N!表示 N 的阶乘), 则任意选出
INIT— POPU— SIZE种排列;
(2) 如果 Ν!≤【ΝΓΓ— POPU— SIZE, 则得到所有的 N!种排列。
歩骤 64, 针对 Perms里的每一种排列, 得到对应的各个个体, 将这些个 体组成集合即得 FirstGen。 得到 Perms里的某一排列 P对应的个体的歩骤为 641。 歩骤 641, 将 P中的各变量按先后顺序依次分配相邻的存储空间, 即得到 对应的个体。 具体地, 将 P中的各变量按先后顺序记作 Vl,v2nN, 则变量 的 起始地址 Addri为:
Figure imgf000023_0003
P对应的个体为:
{(ν;,Αάά );=1...Ν}
歩骤 7, 按 Infi将 PathSet里的每一 Pat 从小到大排列, 选出最小的至 多 INIT— CANDI— SIZE项, 构成 CandiPathSet , 并将各 Infi最小值称为模块所 需存储大小的下确界, 记作 Inf。
歩骤 8, 将 CandiPathSet里的各 Pat 布置到一个或多个处理器或处理器 内核上, 利用遗传算法对各 Pathi对应的种群进行演化以趋近或到达各自的 Infi , 从而趋近或到达 Inf。 当针对某一 Pathi的演化到达 Infi且 ΐη& = inf时, 模块存储优化过程即告完成, 其它尚在运行之中的演化过程可即行终止。
歩骤 9, 待针对各 Pat 的演化过程皆终止后, 最后选出所有 Pat 里所占 存储最小的个体, 给出关于各变量的起始地址、 与之对应的 Pathi、 从别名变 量集里的变量到替代名间的对应关系等信息, 根据上述信息修改原模块, 达 到在节省存储的目的。
这里遗传算法针对 CandiPathSet 里每一 Pat 所对应的 FirstGen^ VarGroupi进行演化, 具体歩骤如如图 5所示, 包括:
歩骤 A, 置种群 Population为 FirstGeni , 置上一代种群各个体所需存储 的最小值 LastSize为无穷大, 置演化时存储大小未变化的次数 SizeCounter 为 0, 置总演化次数 TotalCounter为 0。
歩骤 B, 设置适用于当前一次繁殖的变异概率 Pmut、 种群规模 SPPU。 这里 Pmut、 Sppu随着演化过程的进行而减少。
歩骤 C,对 Population里的每一个体 Candi ,使其以概率 Pmut发生变异(也 称 "突变"), 以概率 (l - Pmut)发生交叉 (也称交配), 产生各新个体 NewCandi 丰勾 If一 t禾中 NewGeno 这里的变异操作如歩骤 C1所示, 交叉操作如歩骤 C2所示。
歩骤 Cl, 从 Candi中以等概率选出一组〈Vi,Addr 产生一个随机分布于区 间 [i, 的整数 Offset,要求其值越大则出现的概率越小。这里的 [·1表示 向上取整, Size为个体 Candi所需存储的大小, 由下式给出:
Size = maxi=1...N(Addri + s(v )'
然后以 50%的概率将 Offset 的当前值生成相反数, 并使用所述相反数更 新 Offset, 然后使用〈 , (Addr; + Offset) mod (Size - /5;)) 弋替〈 , Addr , 得到新个体
NewCandi。 这里的 "mod"表示取余运算。
这里, Offset的产生方法可以任意构造, 例如如歩骤 C11所示的方法。 歩骤 C11, ^Μ = [5ίΖ£'2 Λ(νί)|-ι,贝 lj
Offset = M - round (M * J[0, 1]之间均匀分布的随机数) + 1 其中, round表示四舍五入。
歩骤 C2, 从 Candi中以等概率选出一组〈Vi,Addr 从 Population中等概率 选出异于 Candi的一个体 Candi2, 从 Candi2找到 Vi的起始地址 Addr; 。
用〈 , Addr; >代替〈 , Addr 得到新个体 NewCandi。
歩骤 D, 利用 "共存变量集" 的集合对个体进行筛选, 直接淘汰不符合条 件的个体。 具体为: 从 NewGen中选出满足 VarGroupi要求的个体, 即满足下 式的个体:
对于每一个 G ε VarGroupi里的任意两个不同的变量 、 vk,
[Αάά ,Αάά + s(v;) - 1] Π [Addrfe, Addrfe + s(vfe)— 1] = Φ 这里的 [Addrx,Addrx + s(vx) - 1]表示变量^所用存储起止位置所对应的区间。 用满足上述要求的所有个体组成种群 SelectedNewGen。
歩骤 E, 对 SelectedNewGen的各个体, 通过去除未使用的存储空间来减 小所需存储的大小。 具体地, 对于某个体 Candi , 如果发现有不被任何一个
[Addr;, Addri + s (v;) - l]i=1...N所覆盖的存储单元, 则将起始地址大于该存储单元地 址的所有变量前移, 然后重复上述过程, 直至所有的存储空间都得以利用。
歩骤 F , 将 Population 和 SelectedNewGen 两个种群合并得到集合 NewAllPopu, 将 NewAllPopu里的各个体按所需存储的大小(计算公式参见歩 骤 C1 )排序(所需存储的最小值记作 NewSize) , 大小相同的排列次序可任意 选择, 然后从中选出至多 SPPU个个体构成集合 NewP0pulati0n。 (说明: 这里 以所需存储的大小表征个体的适应度, 所需存储越小, 适应度越大, 反之则 越小。)
歩骤 G, 更新遗传算法的相关状态和计数器:
Population NewPopulation TotalCounter TotalCounter + 1
LastSize NewSize, SizeCounter 0, NewSize < LastSize 比较 ewSize与 LastSize:
SizeCounter SizeCounter + 1, NewSize > LastSize 歩骤 H, 若 NewSize = 演化过程结束, Population中所需存储最小的个体即 为优化所得的结果。
歩骤 I, 若(SizeCounter <
Figure imgf000026_0001
< MAX TOTAL), 贝 lj 转歩骤 B, 否则 Population中所需存储最小的个体即为优化所得的结果, 演化过 程结束。
上述歩骤中涉及常数 INIT— CANDI— SIZE、 MAX— NO— IMPROVEMEN MAX— TOTAL、
INIT_POPU_SIZE可根据模块的复杂度灵活设置。
歩骤 8中, 如果最终所需存储大小大于 Inf, 可增大 MAX— NO— IMPROVEMENT与 MAX— TOTAL , 酌情增大匪 T— POPU— SIZE , 并微调变异概率 Pmut、种群规模 Sp,的调整 策略, 然后重新执行歩骤 8, 直至最终所需存储大小等于 Inf 或者经考虑认 为从遗传算法中得到的优化结果已可接受。
歩骤 9, 根据优化结果进行程序编译。
以下结合图 3说明本发明所述的静态存储的分配方法的应用场景。所述方 法包括:
歩骤 1, 确定要处理的模块。 本发明中所述的模块由一系列紧密耦合在一 起的函数构成, 具备明确的输入、 输出。
歩骤 2, 生成模块模型。
在图 3所示的例子中, 模块的输入为 "变量 1", 输出为 "变量 4", 其中 "变量 1" 由外部控制, 不在优化范围内; "变量 1"、 "变量 2" 、 "变量 3"、 "变量 4" 、 "变量 5"的大小分别为 S2、 S3、 S4、 S5; 函数 2执行后, 变 量 2内的内容被更新, 函数 3用变量 3和更新过的变量 2为输入, 据此可得 到模块的模型如下:
(1) 函数 1: 输入变量集 {变量 1}, 输出变量集 {变量 2 (大小为 S2), 变量 5 (大小为 S5) }
(2) 函数 2: 输入变量集 {变量 2, 变量 5}, 输出变量集 {变量 2' (大 小为 S2), 变量 3 (大小为 S3) }
(3) 函数 3: 输入变量集 {变量 2' , 变量 3}, 输出变量集 {变量 4 (大 小为 S4) }
(4) 模块: 输入变量集 {变量 1 (大小为 }, 输出变量集 {变量 4}, 例外变量集 {变量 1}, 别名变量集 {变量 2, 变量 2' }。
简明起见, 将函数 1、 2、 3分别写作 fl、 f2、 f3; "变量 1"、 "变量 2"、 "变量 3"、 "变量 4"、 "变量 5"分别写作 vl、 v2、 v3、 v4、 v5。 由于后续歩 骤需要实际数据, 所以给 S2、 S3、 S4、 S5分别赋值为 100、 10、 20、 100、 100. (单位可以是 "字节"、 "比特"等)
这样上述模型变为:
(Dfl:输入变量集 {vl},输出变量集 {v2(大小为 10), v5(大小为 100)} (2) f2: 输入变量集 {v2, v5}, 输出变量集 {ν2' (大小为 10), ν3 (大 小为 20) }
(3) f3: 输入变量集 {ν2' , ν3}, 输出变量集 {v4 (大小为 100) }
(4) 模块: 输入变量集 {vl (大小为 100) }, 输出变量集 {v4}, 例外变 量集 { , 别名变量集 2, ν2' }。
为别名变量集 {v2, ν2' }构造一个 "替代名 " "alias— v2"。
歩骤 3, 得到所有的调度方法。 图 3中只有一种: fl-->f2->f3。
歩骤 4, 存储分配方案:
分配 alias— v2;
分酉己 v5;
分配 v3;
释放 v5;
分配 v4。
歩骤 5, 得到共存变量集的集合: {{alias— v2, v5, v3}, { alias— v2, v4, v3}}
歩骤 6,共存变量集 { alias— v2, v5, v3}需要的存储大小为 10+100+20=130; 共存变量集 { alias— v2, v4, v3}需要的存储大小为 10+100+20=130。
调度路径 fl->f2-->f3 对应的存储下确界为 130, 初始种群为:
{〈v3, 0>,〈v4, 20>, <v5, 120>,〈alias— v2, 220>},
{<v5, 0>,〈v4, 100>,〈v3, 200>,〈alias— v2, 220>}, 等等
各调度方法的下确界的最小值 Inf 也是 130。
歩骤 7, 由于只有一种调度路径, 所以这一歩不需要特别处理。
歩骤 8, 遗传算法能使存储分配达到 Inf, 算法结束。 遗传算法进行过程 中截取若干代如下:(列出了里面所需存储空间最小的一个个体及对应的存储 空间大小)
初始: Kv3, 0>,〈v4, 20>,〈v5, 120>,〈alias— v2, 220>}, 存储空间大小为 230;
第 10代: {〈v3, 0>,〈v4, 30>, <v5, 101>,〈alias— v2, 20>}, 存储空间大小为 201;
31代: {〈v3, 0>,〈v4, 66>, <v5, 30>,〈alias— v2, 20>}, 存储空间大小为
166;
第 46代: {〈v3, 10>,〈v4, 30>, <v5, 30>,〈alias— v2, 0>}, 存储空间:
Figure imgf000029_0001
130, 到达 Inf。
歩骤 9, 选出第 46代, 根据所述第 46代进行程序编译。
相应的, 实现执行上述各歩骤的装置包括如图 6所示的四个单元。
模型生成单元, 相当于上述的模块获取单元和模型生成单元, 执行上述歩 骤 1、 2, 分析待优化模块的源代码, 生成所要优化的模块的模型;
模型处理单元, 相当于上述的函数调度顺序获取单元、 下确界获取单元, 执行上述歩骤 3到 7, 对模块模型进行处理, 为执行歩骤 8及歩骤 A到 I完 成各种准备工作; 模型处理模块还将根据待优化模块的规模等信息确定遗传 算法中用到的 INIT— C AND I— SIZE、 MAX— NO— IMPROVEMEN MAX— TOTAL、 匪 T— POPU— SIZE 等四个参数, 具体可如下表所示进行计算:
Figure imgf000029_0002
遗传算法单元, 相当于上述的优化单元, 执行歩骤 A到 I, 对模块内函数 一种特定调度方法所需的存储大小进行优化, 该模块由算法控制模块启动, 并将优化结果传递给算法控制模块; 遗传算法模块在执行歩骤 B时, 设置适 用于当前一次繁殖的变异概率 Pmut、 种群规模 SPPU, 这里 Pmut、 SPPU随着演化过 程的进行而减少, 例如可根据 (TotalCmmter/MAX— TOTAL)的大小设置如下:
TotalCounter
如果 MAX— TOTAL ≤ 0.05 , 贝1 JPMUT = 0.9 , SD0DU = INIT— POPU— SIZE; 如果 0.05 < C 'r≤ 0.10
MAX—二 e
TOTAL , 则 P t = Q.9, S u = Q.9 x INIT— POPU— SIZE; 如果 < TotalCounter
0.10
MAX— TOTAL ≤ 0.25 , 贝1 JPmut = 0.8 , S u = 0.8 x匪 T— POPU— SIZE; 如果 TotalCounter
0.2S < ≤ 0.50 , Jpmut = 0.8, SD0DU = 0.5 x INIT— POPU— SIZE;
MAX— TOTAL 贝1
TotalCounter
如果 > 0.50 , SD0DU = 0.1 x INIT— POPU— SIZE
MAX— TOTAL 贝1 Jpmut = 0.6,
算法控制单元, 执行歩骤 8, 利用遗传算法模块对模块内函数各种调度方 法所需的存储大小进行优化, 最终得到模块所需存储最小的变量分配方法及 对应的函数调度方法, 完成静态存储分配的优化处理;
编译单元, 根据上述优化处理结果进行编译。
由于对不同的调度方法的优化互不干扰, 所以, 如果有多个处理器或处理 器内核, 算法控制模块可在这些处理器或处理器内核上同时针对不同的调度 方法运行算法控制模块, 同时对不同的调度方法进行演化, 充分利用计算资 源, 提高优化速度。 具体地, 可以依照处理器或处理器内核的个数创建多个 线程, 每个线程上运行一个针对某一调度方法的遗传算法模块, 通常这些线 程将由操作系统自动分配到不同的处理器或处理器内核上执行。
本发明公开了一种应用于静态存储分配的优化方法及其装置。该方法利用 遗传算法使静态分配的存储尽可能地得到复用,从而减少对存储大小的需求, 实现静态存储分配的优化。
本发明通过生成模块模型, 分析模型得到不同的函数调用路径, 针对每一 路径利用遗传算法尽可能地通过存储复用来减少对存储大小的需求, 最后采 用需要存储最少的函数调用路径,从而实现对整个模块占用存储大小的优化, 达到或趋近于函数调用路径所对应的存储大小的下确界。
本发明提高了存储空间的利用率, 减少了对存储空间的需求, 对于不需要 同时存在的变量, 令其复用相同的存储空间, 从而缩减了存储空间、 降低了 功耗、 降低了成本。
与人工实现的存储复用相对比, 本发明中的方法具有如下优点:
( 1 ) 可以达到或尽可能接近整个模块所需存储的理论上的下确界, 存储 复用程度更高, 能更好地减少对存储大小的需求; (2) 可以保证存储分配结 果的正确性;(3 )代码修改后,用本发明中的方法可以方便地重新进行优化, 使代码易于维护。
与编译器实现的存储复用相对比, 本发明中的方法至少具有如下优点:
( 1 ) 全盘考虑模块内的所有函数, 可以达到或尽可能接近整个模块所需 存储的下确界, 存储复用程度更高, 能更好地减少对存储大小的需求; (2 ) 不依赖于编译器, 对不同的编译器都能实现相同的节省存储空间的效果。
本发明中所述的模块, 是指在程序设计中, 为完成某一功能所需的紧密相 关或耦合在一起的若干函数、 过程或者方法; 或指能由编译程序、 装配程序 等处理的独立程序单位; 或指大型软件系统的一部分。
所述方法实施例是与所述装置实施例相对应的, 在方法实施例中未详细 描述的部分参照装置实施例中相关部分的描述即可, 在装置实施例中未详细 描述的部分参照方法实施例中相关部分的描述即可。
本领域普通技术人员可以理解, 实现上述实施例方法中的全部或部分歩 骤是可以通过程序来指令相关的硬件来完成, 所述的程序可以存储于一计算 机可读取存储介质中, 该程序在执行时, 包括如上述方法实施例的歩骤, 所 述的存储介质, 如: 磁碟、光盘、只读存储记忆体 ( Read-Only Memory, ROM) 或随机存储记忆体 (Random Access Memory, RAM) 等。
在本发明各方法实施例中, 所述各歩骤的序号并不能用于限定各歩骤的 先后顺序, 对于本领域普通技术人员来讲, 在不付出创造性劳动的前提下, 对各歩骤的先后变化也在本发明的保护范围之内。
以上所述是本发明的优选实施方式, 应当指出, 对于本技术领域的普通 技术人员来说, 在不脱离本发明所述原理的前提下, 还可以作出若干改进和 润饰, 这些改进和润饰也应视为本发明的保护范围。

Claims

权利 要求 书
1. 一种静态存储的分配方法, 其特征在于, 包括:
歩骤 1, 获取待优化的模块, 所述模块包括至少两个相互耦合的函数; 歩骤 2, 根据所述函数之间的耦合关系, 生成一模块模型; 所述模块模型 包括: 函数名称和变量, 所述变量包括输入变量和输出变量;
歩骤 3, 根据所述模块模型, 获取所述模块的所有的函数调度顺序; 歩骤 4, 获取所述模块在每个所述函数调度顺序下对应的所有变量所需存 储空间的下确界;
歩骤 5, 对每一种函数调度顺序, 通过遗传算法优化所有变量的地址分配 信息, 使所有变量占用的存储空间的大小趋近或到达所述下确界的最小值; 歩骤 6, 选择优化后所有变量占用的存储空间最小的函数调度顺序; 歩骤 7, 根据选择的所述函数调度顺序和所述函数调度顺序对应的地址分 配信息,对所述模块进行编译,所述地址分配信息包括:各变量的起始地址。
2. 根据权利要求 1所述的静态存储的分配方法, 其特征在于, 所述歩骤 4之后, 所述方法还包括:
将每个所述函数调度顺序按照其对应的所述下确界的大小从小到大排序, 选择前第一预定数量个所述函数调度顺序;
所述歩骤 5具体为: 对选择出的每一种函数调度顺序, 通过遗传算法优化 所有变量的地址分配, 使所有变量占用的存储空间的大小趋近或到达所述下 确界的最小值。
3. 根据权利要求 1所述的静态存储的分配方法, 其特征在于, 所述歩骤 5包括:
歩骤 A, 设置当前种群 Population为初始种群 FirstGen, 设置当前种群 的上一代种群中的各个体所需存储空间的最小值 LastSize 的当前值为无穷 大, 设置演化时存储空间大小未变化的次数 SizeCounter 的当前值为 0, 设 置总演化次数 TotalCounter的当前值为 0;
歩骤 B, 设置当前变异概率值 Pmut和当前种群规模值 SPPU ;
歩骤 C, 对当前种群 Population里的每一个体 Candi , 使其以所述概率值 Pmut进行变异处理, 以概率 (i - Pmut)进行交叉处理, 产生各新个体 NewCandi ; 歩骤 D, 从新一代种群 NewGen 中选出满足以下公式的个体, 并用选择出 的个体组成选择出的种群 SelectedNewGen;
所述公式为: 对于每一个 G e VarGroupi里的任意两个不同的变量 、 vfc
[Addr!, Add + s (v;) - 1] Π [Addrfe, Addrfe + s (vfe)— 1] = Φ;
其中, [Addrx, Addrx + s(vx) - 1]表示变量^所用存储空间的起止位置所对应的 区间;
歩骤 E, 对选择出的种群 SelectedNewGen的各个体, 去除未使用的存储 空间;
歩骤 F, 将当前种群 Population和选择出的种群 SelectedNewGen合并, 得到集合 NewAl lPopu, 将集合 NewAl lPopu里的各个体按所需存储空间的大 小从小到大排序, 从中选出前第二预定数量个个体以构成下一代种群 NewPopulation, 获取当前种群的各个体所需存储空间的最小值 NewSize; 所 述第二预定数量小于或等于当前种群规模值 SPPU ;
歩骤 G, 将 TotalCounter加 1, 并使用所述下一代种群更新当前种群; 当 NewSize小于 LastSize时,将 SizeCounter的当前值设置为 0,并使用 NewSize 的值更新 LastSize; 当 NewSize大于或等于 LastSize时, 将 SizeCounter 的当前值加 1 ; 歩骤 H, 判断 NewSize是否等于所述下确界中的最小值, 如果判断结果为 是, 则结束演化过程; 如果判断结果为否, 则转向歩骤 I; 判断是否满足 (SizeCounter < MAX— NO— IMPROVEMENT)且 (TotalCounter <
MAX TOTAL) , 如果判断结果为否, 则转向所述歩骤 B, 否则, 结束演化过程, 其中, 第三预定值 MAX— NO— IMPROVEMENT 第四预定值 MAX— TOTAL为预先设置 的值。
4. 根据权利要求 3所述的静态存储的分配方法, 其特征在于, 所述进行 变异处理的歩骤包括:
从个体 Candi 中以等概率选出一组元素 Addr 产生一个随机分布于区 间 [i, 的整数 Offset, 其中 [·1表示向上取整运算, Size为个体 Candi 所需存储空间的大小, gPsize = maXi=1...N (Addri + /s (Vi)), 其中, 元素〈 , Addr 表示 变量〈Vi, Addi ^和所述变量的起始地址〈Vi, Addr
先以预定概率将 Offset 的当前值生成相反数, 并使用所述相反数更新
Offset , 然后使用〈v (Addr! + Offset) mod (Size - 代替〈 , Addr , 得到新个体
NewCandi , 其中, mod表示取余运算;
其中, Size = maxi=1...N (Addri +/s(V )表示: 如果变量名是为别名变量集定义的 替代名, 则返回该别名变量集中各变量所占存储空间大小的最大值; 否则返 回变量名所占存储空间的大小;
所述 Offset生成方法为:
变量 M = [size-A ( ) 1― 1, 贝 |Joffset = M - round + 1,
Figure imgf000034_0001
其中, round表示四舍五入运算。
5. 根据权利要求 3所述的静态存储的分配方法, 其特征在于, 所述进行 交叉处理的歩骤包括: 从个体 Candi中以等概率选出一组元素〈Vi, Addr 从当前种群 Population 中以等概率选出异于 Candi 的一个体 Candi2, 从 Candi2找到 Vi的起始地址
Addr, 。
用〈 , Addr; >代替〈 , Addr 得到新个体 NewCandi。
6. 根据权利要求 3所述的静态存储的分配方法, 其特征在于,
所述初始种群 FirstGen通过以下歩骤生成:
求出共存变量集的集合 VarGroupi中各元素的并集, 记作 Al lVar;
将 Al lVar里的所有元素的个数记作 N, 得到 Al lVar里的所有元素的第五 预定数量种排列, 记作 Perms , 所述第五预定数量小于或者等于 INIT— POPU— SIZE, 所述 INIT— POPU— SIZE为预先设置值;
针对 Perms里的每一种排列,得到对应的各个个体,将这些个体组成集合, 生成所述初始种群 FirstGen;
所述个体为以下歩骤获取的:
将种群的各变量按照先后顺序依次分配相邻的存储空间,即得到对应的个 体。
7. 根据权利要求 6所述的静态存储的分配方法, 其特征在于,
所述共存变量集的集合是通过以下歩骤获取的:
获取所述模块按照所述函数调度顺序进行处理时,根据所述模块执行过程 中同时存在的变量的情况, 生成与该调度顺序对应的共存变量集;
组合所述共存变量集, 生成共存变量集的集合;
所述下确界是通过以下歩骤获取的:
获取每个函数调度顺序的各个所述共存变量集占用的存储空间的最大值, 作为所述函数调度顺序对应的所有变量所需存储空间的下确界。
8. 根据权利要求 1所述的静态存储的分配方法, 其特征在于, 所述歩骤 2中模块模型按照如下方式生成:
函数包括函数名称、输入变量、输出变量以及输出变量所占存储空间的大 小; 函数的输出变量包括函数执行过程中用到的临时变量;
同一函数被多次调用时, 使用不同的函数名称;
模块模型包括输入变量、 输入变量所占存储空间的大小、 输出变量、 例外 变量以及至少一个别名变量集, 所述输出变量包含所述模块内的函数的输出 变量, 所述例外变量不被优化处理, 每个别名变量集包含多个互为别名关系 的变量; 当一个变量出现 N次写入, 则引入 N个新变量, 使得任何一个变量 只被写入一次; 新变量与原变量互称别名, 其中, N为大于 1的自然数。
9. 一种静态存储的分配装置, 其特征在于, 包括:
模块获取单元, 获取待优化的模块, 所述模块包括至少两个相互耦合的函 数;
模型生成单元, 根据所述函数之间的耦合关系, 生成一模块模型; 所述模 块模型包括: 函数名称和变量, 所述变量包括输入变量和输出变量;
函数调度顺序获取单元, 根据所述模块模型, 获取所述模块的所有的函数 调度顺序;
下确界获取单元,获取所述模块在每个所述函数调度顺序下对应的所有变 量所需存储空间的下确界;
优化单元, 对每一种函数调度顺序, 通过遗传算法优化所有变量的地址分 配信息,使所有变量占用的存储空间的大小趋近或到达所述下确界的最小值; 选择单元, 选择优化后所有变量占用的存储空间最小的函数调度顺序; 编译单元,根据选择的所述函数调度顺序和所述函数调度顺序对应的地址 分配信息, 对所述模块进行编译, 所述地址分配信息包括: 各变量的起始地 址。
10. 根据权利要求 9所述的静态存储的分配装置, 其特征在于, 所述优化 单元包括:
第一设置子单元, 设置当前种群 Population为初始种群 FirstGen, 设置 当前种群的上一代种群中的各个体所需存储空间的最小值 LastSize 的当前 值为无穷大, 设置演化时存储空间大小未变化的次数 SizeCounter的当前值 为 0, 设置总演化次数 TotalCounter的当前值为 0;
第二设置子单元, 设置当前变异概率值 Pmut和当前种群规模值 SPPU ;
变异 /交叉子单元, 对当前种群 Population里的每一个体 Candi , 使其以 所述概率值 Pmut进行变异处理, 以概率 (i - Pmu 进行交叉处理, 产生各新个体 NewCandi;
第一选择子单元, 从新一代种群 NewGen中选出满足以下公式的个体, 并 用选择出的个体组成选择出的种群 SelectedNewGen;
所述公式为: 对于每一个 G e VarGroupi里的任意两个不同的变量 、 vfc
[Addr!, Add + s (v;) - 1] Π [Addrfe, Addrfe + s (vfe)— 1] = Φ;
其中, [Addrx, Addrx + s(vx) - 1]表示变量^所用存储空间的起止位置所对应的 区间;
存储空间去除子单元, 对选择出的种群 SelectedNewGen的各个体, 去除 未使用的存储空间;
第二选择子单元, 将当前种群 Population 和选择出的种群 SelectedNewGen合并, 得到集合 NewAl lPopu, 将集合 NewAl lPopu里的各个 体按所需存储空间的大小从小到大排序, 从中选出前第二预定数量个个体以 构成下一代种群 NewPopulation, 获取当前种群的各个体所需存储空间的最 小值 NewSize; 所述第二预定数量小于或等于当前种群规模值 Sppu ;
更新子单元, 将 TotalCounter加 1, 并使用所述下一代种群更新当前种 群; 当 NewSize小于 LastSize时, 将 SizeCounter的当前值设置为 0, 并使 用 NewSize 的值更新 LastSize; 当 NewSize大于或等于 LastSize 时, 将 SizeCounter的当前值加 1 ;
第一判断子单元, 判断 NewSize是否等于所述下确界中的最小值, 如果判 断结果为是,则结束演化过程;如果判断结果为否,则启动第二判断子单元; 第二判断子单元, 判断是否满足 (SizeCounter < MAX— NO— IMPROVEMENT)且 (TotalCounter < ^_rO^L) , 如果判断结果为否, 则转向所述歩骤 B, 否则, 结 束演化过程,其中,第三预定值 MAX— NO— IMPROVEMENT 第四预定值 MAX— TOTAL 为预先设置的值。
11. 根据权利要求 10所述的静态存储的分配装置, 其特征在于, 所述变 异 /交叉子单元进行变异处理具体为:
从个体 Candi 中以等概率选出一组元素 Addr 产生一个随机分布于区 间 [i, ^¾的整数 Offset , 其中 [·1表示向上取整, Size为个体 Candi所需 存储空间的大小, gPsize = maXi=1...N (Addri + /s (Vi)), 其中, 元素〈 , Addi ^表示变量 和所述变量的起始地址;
先以预定概率将 Offset 的当前值生成相反数, 并使用所述相反数更新
Offset , 然后使用〈v (Addr! + Offset) mod (Size - /s (Vi) 代替〈 , Addr , 得到新个体
NewCandi , 其中, mod表示取余运算;
其中, Size = maxi=1...N (Addri + /s(V )表示: 如果变量名是为别名变量集定义的 替代名, 则返回该别名变量集中各变量所占存储空间大小的最大值; 否则返 回变量名所占存储空间的大小;
所述 Offset生成方法为:
令变量 M = [Size_n― 1, 贝 Ijoffset = M - round (M * J [0, 1]之间均匀分布的随机数) + 1, 其中, round表示四舍五入。
12. 根据权利要求 10所述的静态存储的分配装置, 其特征在于, 所述变 异 /交叉子单元进行交叉处理具体为:
从个体 Candi中以等概率选出一组元素〈Vi,Addr 从当前种群 Population 中以等概率选出异于 Candi 的一个体 Candi2, 从 Candi2找到 Vi的起始地址 Addr, 。
用〈 , Addr; >代替〈 , Addr 得到新个体 NewCandi。
PCT/CN2011/082949 2010-11-25 2011-11-25 静态存储的分配方法和装置 WO2012069010A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN 201010567232 CN102096638B (zh) 2010-11-25 2010-11-25 静态存储的分配方法和装置
CN201010567232.7 2010-11-25

Publications (1)

Publication Number Publication Date
WO2012069010A1 true WO2012069010A1 (zh) 2012-05-31

Family

ID=44129740

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2011/082949 WO2012069010A1 (zh) 2010-11-25 2011-11-25 静态存储的分配方法和装置

Country Status (2)

Country Link
CN (1) CN102096638B (zh)
WO (1) WO2012069010A1 (zh)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102096638B (zh) * 2010-11-25 2013-05-29 意法·爱立信半导体(北京)有限公司 静态存储的分配方法和装置
CN106775893B (zh) * 2016-12-30 2020-03-17 北京小米移动软件有限公司 对程序预编译的方法及装置
CN110119636B (zh) * 2019-05-21 2020-12-08 浙江齐治科技股份有限公司 一种数字电路、数据存储方法及装置
CN112965663A (zh) * 2021-03-05 2021-06-15 上海寒武纪信息科技有限公司 对数据块的存储空间进行复用的方法和相关产品

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH0370038A (ja) * 1989-08-08 1991-03-26 Nec Corp 高級言語プログラムの変数割付け方式
JPH0381829A (ja) * 1989-08-24 1991-04-08 Nec Corp 高級言語プログラムの初期値を有したスタティック変数参照方式
CN1489334A (zh) * 2002-10-11 2004-04-14 深圳市中兴通讯股份有限公司 一种静态动态结合的存储区管理的方法
US6826681B2 (en) * 2001-06-18 2004-11-30 Mips Technologies, Inc. Instruction specified register value saving in allocated caller stack or not yet allocated callee stack
US6829761B1 (en) * 1999-10-21 2004-12-07 Oracle International Corporation Method and apparatus for managing shared memory in a run-time environment
CN101901192A (zh) * 2010-07-27 2010-12-01 杭州电子科技大学 一种片上和片外数据对象静态分配方法
CN102096638A (zh) * 2010-11-25 2011-06-15 意法·爱立信半导体(北京)有限公司 静态存储的分配方法和装置

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050071595A1 (en) * 2003-09-25 2005-03-31 International Business Machines Corporation Methods and apparatus for allocating memory
US7793058B2 (en) * 2005-04-19 2010-09-07 International Business Machines Corporation Method and apparatus for negotiating revised service level agreements
CN101551749B (zh) * 2009-05-11 2012-08-22 中国科学院计算技术研究所 随机测试程序生成方法和系统以及设计验证方法

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH0370038A (ja) * 1989-08-08 1991-03-26 Nec Corp 高級言語プログラムの変数割付け方式
JPH0381829A (ja) * 1989-08-24 1991-04-08 Nec Corp 高級言語プログラムの初期値を有したスタティック変数参照方式
US6829761B1 (en) * 1999-10-21 2004-12-07 Oracle International Corporation Method and apparatus for managing shared memory in a run-time environment
US6826681B2 (en) * 2001-06-18 2004-11-30 Mips Technologies, Inc. Instruction specified register value saving in allocated caller stack or not yet allocated callee stack
CN1489334A (zh) * 2002-10-11 2004-04-14 深圳市中兴通讯股份有限公司 一种静态动态结合的存储区管理的方法
CN101901192A (zh) * 2010-07-27 2010-12-01 杭州电子科技大学 一种片上和片外数据对象静态分配方法
CN102096638A (zh) * 2010-11-25 2011-06-15 意法·爱立信半导体(北京)有限公司 静态存储的分配方法和装置

Also Published As

Publication number Publication date
CN102096638A (zh) 2011-06-15
CN102096638B (zh) 2013-05-29

Similar Documents

Publication Publication Date Title
TWI406176B (zh) 準備用於具有多個發送埠之處理器的指令群
WO2019237811A1 (zh) 一种神经网络的内存分配方法及装置
US20060005176A1 (en) Program parallelizing apparatus, program parallelizing method, and program parallelizing program
CN102132249A (zh) 批量同步图形处理单元编程
US20060005179A1 (en) Program parallelizing apparatus, program parallelizing method, and program parallelizing program
US20060005194A1 (en) Program parallelizing apparatus, program parallelizing method, and program parallelizing program
US7386843B2 (en) Method and system for register allocation
JP2011527788A5 (zh)
JP2001147819A (ja) 最適化装置および記録媒体
JPH1139167A (ja) 機械語命令列またはアセンブリ言語命令列を最適化する最適化装置、及び、高級言語で記載されたソースプログラムを機械語またはアセンブリ言語の命令列に変換するコンパイラ
CN1516003A (zh) 一种机器可读介质
JPH1173325A (ja) プログラム変換装置及び記録媒体
US8448157B2 (en) Eliminating redundant operations for common properties using shared real registers
WO2012069010A1 (zh) 静态存储的分配方法和装置
CN113568599A (zh) 用于处理计算作业的方法、电子设备和计算机程序产品
CN109934507A (zh) 一种业务流程调度的方法及装置
CN102265257B (zh) 程序变换装置及程序变换方法
EP0427391B1 (en) Operation assignment method and apparatus therefor
JP2006268168A (ja) ベクトル命令管理回路、ベクトル処理装置、ベクトル命令管理方法、ベクトル処理方法、ベクトル命令管理プログラム、および、ベクトル処理プログラム
CN113791770B (zh) 代码编译器、代码编译方法、代码编译系统和计算机介质
JP3871312B2 (ja) プログラム変換方法、これを用いたデータ処理装置及びプログラム
CN100342328C (zh) 带有复制寄存器文件的vliw处理器
JP4293223B2 (ja) プログラム並列化装置及びその方法並びにプログラム
JP2729795B2 (ja) 並列計算機及びその制御方法
CN117591122A (zh) 一种针对申威平台.net运行时的结构体提升优化编译方法、装置、存储介质及设备

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 11843537

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 11843537

Country of ref document: EP

Kind code of ref document: A1