Resource management method, electronic device and storage medium

By dividing the intermediate representation into basic blocks and determining the resource state based on boundary information, automated resource management of intermediate representation is realized, and the problems of automation and overall state analysis of artificial intelligence computing graph resource management in the prior art are solved, and resource utilization efficiency and computing task execution are optimized.

CN118963994BActive Publication Date: 2025-08-12SHANGHAI BIREN TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410947523.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-15
Publication Date
2025-08-12
Estimated Expiration
2044-07-15

AI Technical Summary

Technical Problem

The existing technology is difficult to achieve automation and generalization in the resource management of artificial intelligence computing graphs, and it is impossible to directly analyze the overall resource status at any time, resulting in high labor and time costs and difficult to guarantee the correctness of the resource list.

Method used

By dividing the intermediate representation into basic blocks, resource state information is determined based on the type of the intermediate representation and the boundary information of the basic block, and using a process-oriented programming language to process the expressions of the intermediate representation to realize the automated allocation and release of resources and reduce manual operations.

Benefits of technology

It realizes efficient resource management, optimizes resource utilization efficiency, avoids resource waste, supports the allocation and release of instantaneous resources represented by any intermediate at different processing stages, and ensures the smooth execution of computing tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118963994B_ABST
    Figure CN118963994B_ABST
Patent Text Reader

Abstract

The embodiments of the present disclosure provide a resource management method, electronic device and storage medium. The method includes: dividing the multiple intermediate representations into at least one basic block according to the attributes of each intermediate representation in the multiple intermediate representations; determining resource status information based on the type of each intermediate representation in the multiple intermediate representations and the boundary information of at least one basic block, the resource status information records the resource requirements of the multiple intermediate representations; and allocating and releasing resources for the multiple intermediate representations based on the resource status information. The method uses a syntax similar to a process-oriented computer programming language to process the expression of the intermediate representation, which reduces manual operations and is conducive to automation and generalization implementation. In addition, the method does not need to explicitly specify a resource list, supports automatic judgment of the resource life cycle, and can directly allocate and perform other operations on the instantaneous resources of any intermediate representation at different processing stages, which is conducive to efficient resource management.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present disclosure relate to a resource management method, an electronic device, and a storage medium. Background Art

[0002] In the field of artificial intelligence, computational graphs are commonly expressed using an intermediate representation (IR). This IR is an abstract representation of a program. After completing front-end work (such as computational graph construction), the compiler first generates its own customized IR, then performs various analysis and optimization algorithms on this IR before generating the target code. Resource management is a key function of computational graph analysis, and computational graph resource analysis and management can be implemented based on the IR. Summary of the Invention

[0003] At least one embodiment of the present disclosure provides a resource management method, which includes: dividing the multiple intermediate representations into at least one basic block according to the attributes of each intermediate representation; determining resource status information based on the type of each intermediate representation in the multiple intermediate representations and the boundary information of the at least one basic block, wherein the resource status information records the resource requirements of the multiple intermediate representations; and allocating and releasing resources for the multiple intermediate representations based on the resource status information.

[0004] In the resource management method provided in at least one embodiment of the present disclosure, the multiple intermediate representations are divided into at least one basic block according to the attributes of each intermediate representation in the multiple intermediate representations, including: dividing the intermediate representations with related attributes into the same basic block, wherein the attributes of the intermediate representation include at least one of the scope of the intermediate representation, the operation type or the dependency relationship.

[0005] In the resource management method provided in at least one embodiment of the present disclosure, the basic block includes a global basic block and at least one local basic block, and the dividing of attribute-related intermediate representations into the same basic block includes: dividing the intermediate representation of the global scope into the global basic block, the intermediate representation of the global scope is valid for the multiple intermediate representations; and dividing the intermediate representation of the local scope into the corresponding local basic block, the intermediate representation of the local scope is only valid within the corresponding local basic block.

[0006] The resource management method provided in at least one embodiment of the present disclosure further includes: for a local basic block with a branch, inserting an intermediate representation representing a terminator at the end position of the branch.

[0007] In the resource management method provided in at least one embodiment of the present disclosure, the intermediate representation includes a resource-class intermediate representation and a non-resource-class intermediate representation, and the resource management method further includes: establishing a first resource space and initializing it to empty; for each resource-class intermediate representation, setting a resource counter for the resource-class intermediate representation and initializing it to 0, placing the identifier of the resource-class intermediate representation and the resource counter corresponding to the resource-class intermediate representation into the first resource space; and establishing a second resource space and initializing it to empty.

[0008] In the resource management method provided in at least one embodiment of the present disclosure, the resource status information is determined based on the type of each intermediate representation in the multiple intermediate representations and the boundary information of the at least one basic block, including: for each intermediate representation, if the intermediate representation is the start of a basic block, setting a block counter for the basic block and initializing it to 0; if the intermediate representation is the resource-class intermediate representation, placing the identifier of the intermediate representation in the second resource space, and adding 1 to the block counter corresponding to the basic block where the intermediate representation is located; if the intermediate representation is the non-resource-class intermediate representation, saving all identifiers in the second resource space to the resource set corresponding to the intermediate representation, and adding 1 to the resource counters corresponding to all resource-class intermediate representations that exist in both the first resource space and the second resource space; and if the intermediate representation is the end of a basic block, removing N identifiers from the second resource space, where N is the count value of the block counter corresponding to the basic block where the intermediate representation is located, N is an integer and N≥0.

[0009] The resource management method provided in at least one embodiment of the present disclosure further includes: sorting all non-resource intermediate representations.

[0010] In the resource management method provided in at least one embodiment of the present disclosure, the resource allocation and release of the multiple intermediate representations based on the resource status information includes: sequentially processing each sorted non-resource intermediate representation based on the information stored in the first resource space.

[0011] In the resource management method provided by at least one embodiment of the present disclosure, the sequential processing of each sorted non-resource class intermediate representation includes: for each resource class intermediate representation corresponding to an identifier in the resource set corresponding to each sorted non-resource class intermediate representation, if the resource class intermediate representation has not been allocated resources, allocating the corresponding resources to the resource class intermediate representation; if the resource class intermediate representation has been allocated resources, reducing the resource counter corresponding to the resource class intermediate representation by 1; and if the resource counter corresponding to the resource class intermediate representation has a value of 0, releasing the resources held by the resource class intermediate representation.

[0012] In the resource management method provided in at least one embodiment of the present disclosure, the resource management method is executed by a compiler.

[0013] At least one embodiment of the present disclosure provides a resource management device, comprising: a partitioning module configured to partition the multiple intermediate representations into at least one basic block according to the attributes of each of the multiple intermediate representations; a determination module configured to determine resource status information based on the type of each of the multiple intermediate representations and boundary information of the at least one basic block, wherein the resource status information records the resource requirements of the multiple intermediate representations; and an allocation module configured to allocate and release resources for the multiple intermediate representations based on the resource status information.

[0014] At least one embodiment of the present disclosure provides an electronic device, comprising: at least one processor; at least one memory storing one or more computer program modules; wherein the one or more computer program modules are configured to be executed by the at least one processor to execute instructions of the resource management method provided in at least one embodiment above.

[0015] At least one embodiment of the present disclosure provides a non-transitory computer-readable storage medium having computer-readable instructions stored thereon, wherein the computer-readable instructions, when executed by at least one processor, implement the resource management method provided by at least one embodiment above. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the drawings of the embodiments will be briefly introduced below. Obviously, the drawings in the following description only relate to some embodiments of the present disclosure, rather than limiting the present disclosure.

[0017] Figure 1 A flowchart of a resource management method provided by at least one embodiment of the present disclosure;

[0018] Figure 2 A schematic diagram of an intermediate representation of a computation graph provided for at least one embodiment of the present disclosure;

[0019] Figure 3A A schematic diagram of a tree representation of an intermediate representation of a computation graph provided in at least one embodiment of the present disclosure;

[0020] Figure 3B A schematic diagram of a tree representation of an intermediate representation of a computation graph provided in at least one embodiment of the present disclosure;

[0021] Figure 4 A schematic diagram of an example of a resource management method provided by at least one embodiment of the present disclosure;

[0022] Figure 5 A schematic diagram of an example of a resource management method provided by at least one embodiment of the present disclosure;

[0023] Figure 6 A schematic block diagram of a resource management device provided in at least one embodiment of the present disclosure;

[0024] Figure 7 A schematic block diagram of an electronic device provided in at least one embodiment of the present disclosure;

[0025] Figure 8 A schematic block diagram of another electronic device provided for at least one embodiment of the present disclosure; and

[0026] Figure 9 A schematic block diagram of a non-transitory computer-readable storage medium is provided for at least one embodiment of the present disclosure. DETAILED DESCRIPTION

[0027] In order to make the purpose, technical solutions and advantages of the embodiments of the present disclosure more clear, the technical solutions of the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings of the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, not all of the embodiments. Based on the described embodiments of the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present disclosure.

[0028] Unless otherwise defined, the technical or scientific terms used in this disclosure should have the usual meanings understood by persons of ordinary skill in the field to which this disclosure belongs. The words "first", "second" and similar terms used in this disclosure do not indicate any order, quantity or importance, but are only used to distinguish different components. Words such as "include" or "comprise" mean that the elements or objects appearing before the word include the elements or objects listed after the word and their equivalents, without excluding other elements or objects. Words such as "connect" or "connected" are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the object being described changes, the relative positional relationship may also change accordingly.

[0029] The present disclosure is described below using several specific embodiments. To keep the following description of the embodiments of the present disclosure clear and concise, detailed descriptions of known functions and components may be omitted. When any component of an embodiment of the present disclosure appears in more than one drawing, the component is represented by the same or similar reference numeral in each drawing.

[0030] In related technologies, there are two common ways to implement computational graph resource analysis and management based on intermediate representation.

[0031] Method 1: Case-by-case manual analysis and allocation management. Specifically, professionals check each node in the computational graph one by one, analyze its resource requirements, and allocate resources accordingly.

[0032] Method 2: Explicitly specify the resource list. Specifically, each intermediate representation explicitly specifies the required resource list, and then resource allocation management is performed based on the resource list.

[0033] The inventors of the present disclosure have noticed that both the above-mentioned method 1 and method 2 have certain limitations. Method 1 is difficult to apply to complex or constantly changing computational graphs, is not conducive to automation and generalization, and has high requirements for manpower and time costs. In method 2, it is impossible to directly analyze the overall resource status at any time, and an additional mechanism is required to ensure the correctness of the resource list. In the process of generating target code through intermediate representation, obtaining the overall resource status at any time is a common requirement, so there is an urgent need for a resource management method based on intermediate representation to overcome the above limitations.

[0034] At least one embodiment of the present disclosure provides a resource management method, which includes: dividing the multiple intermediate representations into at least one basic block according to the attributes of each intermediate representation; determining resource status information based on the type of each intermediate representation in the multiple intermediate representations and the boundary information of at least one basic block, wherein the resource status information records the resource requirements of the multiple intermediate representations; and allocating and releasing resources for the multiple intermediate representations based on the resource status information.

[0035] At least one embodiment of the present disclosure provides a resource management method that utilizes syntax similar to that of a process-oriented computer programming language (e.g., C) to process intermediate representation expressions, reducing manual operations and facilitating automation and generalization. Furthermore, the method eliminates the need for explicit resource lists and, by maintaining resource status information, supports automatic determination of resource lifecycles. It can directly allocate and perform other operations on transient resources in any intermediate representation at different processing stages, facilitating efficient resource management.

[0036] Figure 1 A flowchart of a resource management method provided by at least one embodiment of the present disclosure. Figure 1 As shown, the resource management method provided by at least one embodiment of the present disclosure includes the following steps S101 to S103.

[0037] Step S101: Divide the multiple intermediate representations into at least one basic block according to the attribute of each of the multiple intermediate representations.

[0038] For example, in step S101, the intermediate representation is an abstract program representation. After completing front-end work (such as building a computational graph), the compiler first generates its own customized intermediate representation, executes various analysis and optimization algorithms on this representation, and finally generates the target code. In other words, the intermediate representation is an abstract and simplified form of the source code during the compilation process.

[0039] For example, a basic block is a discrete structure that makes up a program. The instructions within it are executed linearly, without conditional branches or loop control structures, and have only one entry and one exit point. A basic block is the fundamental unit of control flow analysis, optimization, and compilation, facilitating the understanding and manipulation of a program's control structure. For example, a basic block is similar to the {} in C programming language; each basic block is independent of the others.

[0040] For example, the properties of the intermediate representation may include the scope of the intermediate representation, the operation type, or the dependency relationship, and the intermediate representations related to the properties are divided into the same basic block.

[0041] Step S102: determining resource status information based on the type of each intermediate representation in the plurality of intermediate representations and boundary information of at least one basic block, where the resource status information records resource requirements of the plurality of intermediate representations.

[0042] For example, in step S102, the boundary information between basic blocks can help determine the life cycle of resources, that is, which resources need to be retained when crossing basic blocks and which can be released. Combining the type of intermediate representation and the boundary information of the basic block, it can be determined which basic blocks need to be allocated resources, thereby determining the resource status information. It should be noted that after the execution of step S101 is completed, each intermediate representation will be divided into a corresponding basic block. Therefore, in step S102, the resource status information will be determined based on the boundary information of each basic block and the type of intermediate representation contained in the basic block. The resource status information records the resource requirements of the intermediate representation, for example, the type and amount of resources that need to be allocated to the intermediate representation. Based on the resource status information, the overall resource status at any time can be directly analyzed to achieve dynamic resource management.

[0043] For example, intermediate representations can be divided into different types according to the functions they implement. In the resource management method provided in at least one embodiment of the present disclosure, intermediate representations include resource-class intermediate representations and non-resource-class intermediate representations. Resource-class intermediate representations refer to intermediate representations related to the consumption and allocation of resources (such as memory resources, computing resources, input / output resources, etc.). Non-resource-class intermediate representations refer to intermediate representations that are not directly related to resource management, but are more related to computing logic, data flow, control flow, etc.

[0044] Step S103: Allocate and release resources for multiple intermediate representations based on the resource status information.

[0045] For example, in step S103, based on the resource status information obtained in step S102, it is possible to determine which intermediate representations need to be allocated resources, and also to determine which resources have been fully used and released. The released resources can then be reallocated to other required resource-class intermediate representations, thereby achieving resource reuse and management. In the resource management method provided in the embodiment of the present disclosure, through the resource allocation and release mechanism, it is possible to optimize resource utilization efficiency, avoid unnecessary resource waste, and ensure the smooth execution of computing tasks.

[0046] In the resource management method provided in at least one embodiment of the present disclosure, the basic blocks include a global basic block and at least one local basic block. An example of step S101 may include the following steps S1011 to S1012.

[0047] Step S1011: Divide the intermediate representation of the global scope into global basic blocks.

[0048] For example, an intermediate representation with a global scope is valid for all intermediate representations. For example, an intermediate representation with a global scope can be understood as an intermediate representation at the main function level, which can be applied to all intermediate representations after the intermediate representation is defined.

[0049] Step S1012: Divide the intermediate representation of the local scope into corresponding local basic blocks.

[0050] For example, the intermediate representation of a local scope is only valid within the corresponding local basic block. For example, the intermediate representation within each local basic block does not apply to other local basic blocks.

[0051] Figure 2 A schematic diagram of an intermediate representation of a computational graph provided for at least one embodiment of the present disclosure. Figure 3A A schematic diagram of a tree representation of an intermediate representation of a computation graph provided in at least one embodiment of the present disclosure. Figure 2 and Figure 3A The logical structures shown are equivalent.

[0052] For example, Figure 2 As shown in , T_a~T_f are all intermediate representations of resource classes, mapped to intermediate representations IR_1, IR_3, IR_5, IR_13, IR_17 and IR_23 respectively. Figure 2 and Figure 3A As shown in the figure, IR_1, IR_3, IR_5, IR_13, IR_17 and IR_23 are resource-type intermediate representations, and the remaining intermediate representations are non-resource-type intermediate representations.

[0053] For example, Figure 3A As shown, steps S1011 to S1012 are executed to divide the intermediate representation of the global scope into global basic blocks, and to divide the intermediate representation of the local scope into corresponding local basic blocks.

[0054] For example, Figure 3A As shown in the figure, IR_0, IR_1, IR_13, and IR_14 are global intermediate representations, while the remaining intermediate representations are local intermediate representations. For example, the global intermediate representation IR_1 can be applied to all subsequent intermediate representations IR_2 to IR_24, while the local intermediate representation IR_5 can only be applied to intermediate representations IR_6 to IR_7 in the same local basic block.

[0055] For example, Figure 3A As shown, the intermediate representations IR_2, IR_3, IR_4, IR_11 and IR_12 are divided into the local basic block bb_a, IR_2 is the start of bb_a, and IR_12 is the end of bb_a; the intermediate representations IR_5, IR_6 and IR_7 are divided into the local basic block bb_a1, IR_5 is the start of bb_a1, and IR_7 is the end of bb_a1; the intermediate representations IR_8 and IR_9 are divided into the local basic block bb_a2, IR_8 is the start of bb_a2, and IR_9 is the end of bb_a 2; the intermediate representation IR_15 is divided into the local basic block bb_b, and IR_15 is the start and end of bb_b; the intermediate representations IR_16, IR_17, IR_18 and IR_19 are divided into the local basic block bb_b1, IR_16 is the start of bb_b1, and IR_19 is the end of bb_b1; the intermediate representations IR_21, IR_22, IR_23 and IR_24 are divided into the local basic block bb_c, IR_21 is the start of bb_c, and IR_24 is the end of bb_c.

[0056] The resource management method provided by at least one embodiment of the present disclosure may further include step S201 . Step S201 may be performed after steps S1011 to S1012 .

[0057] Step S201: For a local basic block with a branch, an intermediate representation representing the end symbol is inserted at the end position of the branch.

[0058] For example, a branching local basic block can include a basic block with a branching structure (e.g., if-else statements, for / while statements). For example, the intermediate representation representing the terminator does not change the semantics of the program; it merely serves as a sequential marker, signaling the completion of the basic block and potentially requiring sequential information. For algorithms that subsequently need to sort or edit the intermediate representation, this ensures that the original execution order logic is maintained during the transformation process.

[0059] Figure 3B A schematic diagram of a tree representation of an intermediate representation of a computational graph provided in at least one embodiment of the present disclosure. For example, Figure 3B is Figure 3A The example provided is based on the result of executing step S201.

[0060] For example, Figure 3B As shown, basic blocks bb_a and bb_b are branched local basic blocks. For basic block bb_a, intermediate representation IR_10 is inserted between intermediate representations IR_4 and IR_11. For basic block bb_b, intermediate representation IR_20 is inserted after intermediate representation IR_15. IR_10 and IR_20 are intermediate representations representing terminators and are non-resource intermediate representations. Figure 3B The rest of the content can be referred to Figure 3A The relevant description is not repeated here.

[0061] The resource management method provided by at least one embodiment of the present disclosure may further include steps S301 to S303 , and steps S301 to S303 may be performed after step S101 .

[0062] Step S301: Create a first resource space and initialize it to empty.

[0063] For example, in step S301, establishing the first resource space may mean defining a data structure or container for subsequent resource management. For example, the first resource space may be a resource pool, which may be implemented by a list, array, hash table, or other data structure, which is not limited in the present embodiment.

[0064] Step S302: For each resource class intermediate representation, set a resource counter for the resource class intermediate representation and initialize it to 0, and put the resource class intermediate representation identifier and the resource counter corresponding to the resource class intermediate representation into the first resource space.

[0065] For example, in step S302, the identifier of the intermediate representation can be an index, name, type tag, or any other unique identifier of the intermediate representation. As long as the corresponding intermediate representation can be determined based on the identifier, this is not a limitation of the present embodiment. For example, assuming there is a resource-class intermediate representation IR_t1, the identifier of IR_t1 can be "t1".

[0066] For example, resource counters are used to record resource usage related to the corresponding resource class intermediate representation. At the initialization time, the resource counters corresponding to all resource class intermediate representations are initialized to 0, indicating that no resources have been allocated to these resource class intermediate representations.

[0067] For example, in order to better organize and manage the intermediate representation information of the above resource class, a class named PIR can be defined. This class includes two members: name represents the identifier of the intermediate representation, and cnt represents the resource counter corresponding to the intermediate representation.

[0068] class PIR{

[0069] name; / / Intermediate representation identifier

[0070] cnt; / / The middle represents the corresponding resource counter

[0071] }

[0072] For example, for each resource class intermediate representation, the aforementioned PIR class can be instantiated, and all PIR class instances are collected and placed in the first resource space. For example, assuming a computation graph includes three resource class intermediate representations: IR_t1, IR_t2, and IR_t3, then at the initialization time, the PIR class instances created to create resource class intermediate representations IR_t1, IR_t2, and IR_t3 can be abstractly represented as: PIR IR_t1 (name = "t1", cnt = 0); PIR IR_t2 (name = "t2", cnt = 0); PIR IR_t3 (name = "t3", cnt = 0). The aforementioned instances are all stored in the first resource space, and the overall resource status can be viewed in real time in the first resource space. For example, the resource counter corresponding to IR_t2 can be viewed through IR_t2.cnt.

[0073] Step S303: Create a second resource space and initialize it to empty.

[0074] For example, in step S303, establishing the second resource space may mean defining a first-in-first-out data structure or container. For example, the second resource space may be a resource stack, which is subsequently used to store identifiers of intermediate representations of resource classes.

[0075] In the resource management method provided in the embodiment of the present disclosure, through the first resource space, it is possible to search and update the corresponding resource counter according to the identifier of the intermediate representation of the resource class, and then obtain the overall resource status at any time, which is convenient for monitoring, managing and updating resource usage.

[0076] In the resource management method provided by at least one embodiment of the present disclosure, an example of step S102 may include: executing the following steps S401 to S404 for each intermediate representation.

[0077] Step S401: If the intermediate representation is the start of a basic block, set a block counter for the basic block and initialize it to 0.

[0078] For example, the start of a basic block has been described in the previous embodiment and will not be repeated here. For example, a block counter may not be set for a global basic block. For example, in step S401, assuming that an intermediate representation IR_p1 is the start of a basic block bb_y1, a block counter is set for the basic block bb_y1, for example, bb_y1.cnt, and the initial value of the block counter bb_y1.cnt is set to 0.

[0079] Step S402: If the intermediate representation is a resource-type intermediate representation, the identifier of the intermediate representation is placed in the second resource space, and the block counter corresponding to the basic block where the intermediate representation is located is increased by 1.

[0080] For example, if the second resource space is a resource stack, assuming an intermediate representation IR_p2 is a resource-class intermediate representation, the identifier "p2" of IR_p2 is pushed into the stack, and the block counter corresponding to the basic block where the intermediate representation IR_p2 is located is increased by 1.

[0081] Step S403: If the intermediate representation is a non-resource intermediate representation, save all identifiers in the second resource space to the resource set corresponding to the intermediate representation, and increase the resource counters corresponding to all resource-class intermediate representations that exist in both the first resource space and the second resource space by 1.

[0082] For example, in step S403, in order to better organize and manage non-resource intermediate representation information, a class named OIR can be defined. This class includes two members: name represents the identifier of the intermediate representation, and Tset represents the resource set corresponding to the intermediate representation.

[0083] class OIR{

[0084] name; / / Intermediate representation identifier

[0085] Tset; / / The intermediate representation corresponds to the resource set

[0086] }

[0087] For example, for non-resource intermediate representations, the aforementioned OIR class can be instantiated. For example, assuming there exists a non-resource intermediate representation IR_p3, whose corresponding resource set contains the identifiers of resource intermediate representations IR_t1, IR_t2, and IR_t3, then the OIR class instance created to create the non-resource intermediate representation IR_p3 can be abstractly represented as: OIR IR_p3(name="p3", Tset="t1","t2","t3"}). The contents stored in this resource set will be used for subsequent resource allocation.

[0088] Step S404: If the intermediate representation is the end of a basic block, remove N identifiers from the second resource space, where N is the count value of the block counter corresponding to the basic block where the intermediate representation is located, and N is an integer and N≥0.

[0089] For example, the end of a basic block has been described in the previous embodiment and will not be repeated here. For example, in step S404, if the second resource space is a resource stack, assuming that an intermediate representation IR_p4 is the end of a basic block bb_y2, and the block counter bb_y2.cnt corresponding to the basic block bb_y2 is N1, then N1 identifiers are popped from the stack.

[0090] The resource management method provided by at least one embodiment of the present disclosure may further include step S202 . Step S202 may be performed after steps S401 to S404 .

[0091] Step S202: sort all non-resource intermediate representations.

[0092] For example, the OIR class instances of the non-resource intermediate representation created above may be directly sorted.

[0093] An example of step S103 may include sequentially processing each sorted non-resource intermediate representation based on the information stored in the first resource space. For example, for each resource intermediate representation corresponding to each identifier in the resource set corresponding to each sorted non-resource intermediate representation, the following steps S501 to S503 may be executed.

[0094] Step S501: If the resource class intermediate representation has not been allocated resources, allocate the corresponding resources to the resource class intermediate representation.

[0095] For example, suppose there is a non-resource intermediate representation IR_p3, and its corresponding resource set contains the identifiers of resource intermediate representations IR_t1, IR_t2, and IR_t3. If a resource intermediate representation (such as IR_t1) does not currently hold any resources, a resource allocation operation will be performed to allocate the required resources to IR_t1.

[0096] Step S502: If the resource class intermediate representation has been allocated resources, the resource counter corresponding to the resource class intermediate representation is reduced by 1.

[0097] For example, in the above example, if a resource class intermediate representation (e.g., IR_t2) has already been allocated resources, then instead of allocating resources to it, the resource counter value of the resource class intermediate representation is decremented to monitor and track resource usage. Each time this operation is performed, the resource counter of IR_t2 is decremented by 1.

[0098] Step S503: If the resource counter value corresponding to the resource class intermediate representation is 0, release the resources held by the resource class intermediate representation.

[0099] For example, if the resource counter corresponding to IR_t2 drops to 0 after multiple resource counter decrement operations, this indicates that IR_t2 no longer uses any resources. At this point, a resource release operation is triggered, reclaiming all resources held by IR_t2. After IR_t2's resources are released, they can be reallocated to other resource intermediate representations in need, thus achieving resource reuse and management.

[0100] In the resource management method provided in the embodiment of the present disclosure, through the above-mentioned resource allocation and release mechanism, it is possible to optimize resource utilization efficiency, avoid unnecessary resource waste, and ensure the smooth execution of computing tasks.

[0101] Figure 4 This is a schematic diagram of an example of a resource management method provided by at least one embodiment of the present disclosure. For example, Figure 4 This is an example of the above steps S301 to S303 and steps S401 to S404.

[0102] For example, Figure 4 As shown above Figure 3B The example is the same as that of IR_0 to IR_24. Among the intermediate representations IR_1, IR_3, IR_5, IR_13, IR_17 and IR_23 are resource-type intermediate representations, and the rest are non-resource-type intermediate representations. The relationship between each intermediate representation and the basic block can also refer to the above Figure 3B The relevant description will not be repeated here.

[0103] For example, Figure 4As shown, at the initialization moment, execute step S301, establish a resource pool Tpool and initialize it to empty; execute step S302, set a resource counter for each resource class intermediate representation and initialize it to 0, and put the identifier of the resource class intermediate representation and the resource counter corresponding to the resource class intermediate representation into the resource pool Tpool; execute step S303, establish a resource stack Tstack and initialize it to empty.

[0104] For example, Figure 4 As shown, the relevant descriptions of the PIR class and the OIR class can refer to the descriptions in the above embodiments and will not be repeated here. For the convenience of description, the identifier of the intermediate representation IR_x is denoted as IR_x.name, the resource counter corresponding to IR_x is denoted as IR_x.cnt, and the resource set corresponding to IR_x is denoted as IR_x.Tset. In this example, x can be 0 to 24. At the initialization moment, the resource stack Tstack is empty (Null), and the identifiers and corresponding resource counters of the intermediate representations IR_1, IR_3, IR_5, IR_13, IR_17, and IR_23 of the resource class are stored in the resource pool, and the values of the resource counters IR_1.cnt, IR_3.cnt, IR_5.cnt, IR_13.cnt, IR_17.cnt, and IR_23.cnt are all 0.

[0105] For example, Figure 4 As shown, the intermediate representations IR_0 to IR_24 are processed in sequence.

[0106] For example, refer to Figure 3B and Figure 4 IR_0 is a non-resource intermediate representation. Step S403 is executed to store all identifiers in the resource stack Tstack into the resource set IR_0.Tset corresponding to IR_0. Since the resource stack Tstack is empty at this time, the resource set IR_0.Tset corresponding to IR_0 is also empty.

[0107] The intermediate representation IR_1 is a resource-class intermediate representation. Step S402 is executed to put the identifier of IR_1 into the resource stack Tstack.

[0108] The intermediate representation IR_2 is the beginning of the basic block bb_a. Step S401 is executed to create a block counter bb_a.ten_cnt for the basic block bb_a and initialize it to 0.

[0109] The intermediate representation IR_3 is a resource-class intermediate representation. Step S402 is executed to put the identifier of IR_3 into the resource stack Tstack and increase the corresponding block counter bb_a.ten_cnt by 1.

[0110] The intermediate representation IR_4 is a non-resource class intermediate representation. Step S403 is executed to store all identifiers in the resource stack Tstack into the resource set IR_4.Tset corresponding to IR_4. At this time, all resource class intermediate representations that exist in the resource stack Tstack and the resource pool Tpool are IR_1 and IR_3, and their corresponding resource counters IR_1.cnt and IR_3.cnt are both increased by 1.

[0111] Intermediate representation IR_5 is the start of basic block bb_a1. Step S401 is executed to create a block counter bb_a1.ten_cnt for basic block bb_a1 and initialize it to 0. Intermediate representation IR_5 is a resource IR. Step S402 is executed to place the identifier of IR_5 into the resource stack Tstack and increment the corresponding block counter bb_a.ten_cnt by 1.

[0112] The intermediate representation IR_6 is a non-resource class intermediate representation. Step S403 is executed to store all identifiers in the resource stack Tstack into the resource set IR_6.Tset corresponding to IR_6. At this time, all resource class intermediate representations that exist in the resource stack Tstack and the resource pool Tpool are IR_1, IR_3 and IR_5, and their corresponding resource counters IR_1.cnt, IR_3.cnt and IR_5.cnt are all increased by 1.

[0113] Intermediate representation IR_7 is a non-resource intermediate representation. Step S403 is executed to store all identifiers in the resource stack into the resource set IR_7.Tset corresponding to IR_7. At this point, all resource-class intermediate representations existing in both the resource stack Tstack and the resource pool Tpool are designated IR_1, IR_3, and IR_5. Their corresponding resource counters IR_1.cnt, IR_3.cnt, and IR_5.cnt are incremented by 1. Intermediate representation IR_7 represents the end of basic block bb_a1. Step S404 is executed to set the block counter bb_a1.ten_cnt of basic block bb_a1 to 1, and one identifier is removed from resource stack Tstack. Resource stack Tstack now stores the identifiers of IR_1 and IR_3.

[0114] Intermediate representation IR_8 is the starting point of basic block bb_a2. Step S401 is executed to establish a block counter bb_a2.ten_cnt for basic block bb_a2 and initialize it to 0. Intermediate representation IR_8 is a non-resource intermediate representation. Step S403 is executed to store all identifiers in the resource stack into the resource set Tset corresponding to IR_8. At this point, all resource intermediate representations in both the resource stack Tstack and the resource pool Tpool are designated IR_1 and IR_3, and their corresponding resource counters IR_1.cnt and IR_3.cnt are incremented by 1.

[0115] Intermediate representation IR_9 is a non-resource intermediate representation. Step S403 is executed, and all identifiers in the resource stack are stored in the resource set IR_9.Tset corresponding to IR_9. At this point, all resource-class intermediate representations existing in both the resource stack Tstack and the resource pool Tpool are designated IR_1 and IR_3, and their corresponding resource counters IR_1.cnt and IR_3.cnt are incremented by 1. Intermediate representation IR_9 represents the end of basic block bb_a2. Step S404 is executed, and the block counter bb_a2.ten_cnt of basic block bb_a2 is set to 0. Zero identifiers are removed from resource stack Tstack. Resource stack Tstack now stores the identifiers of IR_1 and IR_3.

[0116] The intermediate representation IR_10 is a non-resource intermediate representation. Step S403 is executed to store all identifiers in the resource stack Tstack into the resource set IR_10.Tset corresponding to IR_10. At this time, all resource class intermediate representations that exist in the resource stack Tstack and the resource pool Tpool are IR_1 and IR_3, and their corresponding resource counters IR_1.cnt and IR_3.cnt are both increased by 1.

[0117] The operations on the remaining intermediate representations are similar to those described above. The complete process is omitted here, and only a part of the intermediate representations is used as an example.

[0118] Figure 5 This is a schematic diagram of an example of a resource management method provided by at least one embodiment of the present disclosure. For example, Figure 5 is Figure 4 Based on the example provided, the result of executing step S202 is Figure 5 This is an example of the above steps S501 to S503.

[0119] For example, Figure 5 As shown, each sorted non-resource intermediate representation is processed sequentially.

[0120] For example, Figure 5As shown, the resource set IR_0.Tset corresponding to the non-resource intermediate representation IR_0 is empty, so no operation is performed.

[0121] For example, Figure 5 As shown, the resource set IR_2.Tset corresponding to the non-resource intermediate representation IR_2 is {1}, which corresponds to the resource intermediate representation IR_1. Since no resources have been allocated to the resource intermediate representation IR_1, step S501 is executed to allocate resources to the resource intermediate representation IR_1. Furthermore, step S502 is executed to decrement the resource counter IR_1.cnt corresponding to the resource intermediate representation IR_1 by 1, resulting in IR_1.cnt = 17.

[0122] For example, Figure 5 As shown, the resource set IR_4.Tset = {1, 3} corresponding to the non-resource intermediate representation IR_4 corresponds to the resource intermediate representations IR_1 and IR_3. Resource intermediate representation IR_1 has been allocated resources, so step S502 is executed to decrement the resource counter IR_1.cnt corresponding to resource intermediate representation IR_1, resulting in IR_1.cnt = 16. Resource intermediate representation IR_3 has not been allocated resources, so step S501 is executed to allocate resources to resource intermediate representation IR_3. Furthermore, step S502 is executed to decrement the resource counter IR_3.cnt corresponding to resource intermediate representation IR_3, resulting in IR_3.cnt = 7.

[0123] For example, Figure 5 As shown, the resource set IR_8.Tset corresponding to the non-resource intermediate representation IR_8 is {1, 3}, corresponding to the resource intermediate representations IR_1 and IR_3. For the resource intermediate representation IR_1, resources have already been allocated. Therefore, step S502 is executed to decrement the resource counter IR_1.cnt corresponding to the resource intermediate representation IR_1, IR_1.cnt = 15. For the resource intermediate representation IR_3, resources have already been allocated. Therefore, step S502 is executed to decrement the resource counter IR_3.cnt corresponding to the resource intermediate representation IR_3, IR_3.cnt = 6.

[0124] The operations for other non-resource intermediate representations are similar to those described above. The complete process is omitted here, and only a part of the non-resource intermediate representations is used as an example.

[0125] For example, Figure 5As shown, the resource set IR_22.Tset corresponding to the non-resource intermediate representation IR_22 is {1, 13}, corresponding to the resource intermediate representations IR_1 and IR_13. For the resource intermediate representation IR_1, resources have been allocated. Therefore, step S502 is executed to decrement the resource counter IR_1.cnt corresponding to the resource intermediate representation IR_1, IR_1.cnt = 1. For the resource intermediate representation IR_13, resources have been allocated. Therefore, step S502 is executed to decrement the resource counter IR_13.cnt corresponding to the resource intermediate representation IR_13, IR_13.cnt = 1.

[0126] For example, Figure 5 As shown, the resource set IR_24.Tset corresponding to the non-resource intermediate representation IR_24 is {1, 13, 23}, corresponding to the resource intermediate representations IR_1, IR_13, and IR_23. For the resource intermediate representation IR_1, resources have already been allocated. Therefore, step S502 is executed to decrement the resource counter IR_1.cnt corresponding to the resource intermediate representation IR_1, so that IR_1.cnt = 0. Since IR_1.cnt = 0, step S503 is executed to release the resources held by the resource intermediate representation IR_1. For the resource intermediate representation IR_13, resources have already been allocated. Therefore, step S502 is executed to decrement the resource counter IR_13.cnt corresponding to the resource intermediate representation IR_13, so that IR_13.cnt = 0. Since IR_13.cnt = 0, step S503 is executed to release the resources held by the resource intermediate representation IR_13. Since no resources have been allocated to the resource intermediate representation IR_23, step S501 is executed to allocate resources to the resource intermediate representation IR_23. Furthermore, step S502 is executed to decrement the resource counter IR_23.cnt corresponding to the resource intermediate representation IR_23 by 1, so that IR_23.cnt = 0. Since IR_23.cnt = 0, step S503 is executed to release the resources held by the resource intermediate representation IR_23.

[0127] Figure 6 A schematic block diagram of a resource management device provided in at least one embodiment of the present disclosure.

[0128] For example, Figure 6 As shown, the resource management device 600 provided by the embodiment of the present disclosure includes a partitioning module 601 , a determination module 602 and an allocation module 603 .

[0129] For example, the partitioning module 601 is configured to partition the plurality of intermediate representations into at least one basic block according to the attributes of each of the plurality of intermediate representations. For details about the partitioning module 601, reference may be made to the description of step S101 in the embodiment of the resource management method, and will not be repeated here.

[0130] For example, determination module 602 is configured to determine resource status information based on the type of each intermediate representation in the plurality of intermediate representations and boundary information of at least one basic block, where the resource status information records resource requirements for the plurality of intermediate representations. For details regarding determination module 602, reference may be made to the description of step S102 in the embodiment of the resource management method described above and will not be repeated here.

[0131] For example, the allocation module 603 is configured to allocate and release resources for multiple intermediate representations based on resource status information. For details about the allocation module 603, please refer to the description of step S103 in the above resource management method embodiment, which will not be repeated here.

[0132] For example, in at least one embodiment of the present disclosure, the partitioning module 601 is further configured to partition attribute-related intermediate representations into the same basic block, wherein the attributes of the intermediate representation include at least one of the scope of the intermediate representation, the operation type, or the dependency relationship.

[0133] For example, in at least one embodiment of the present disclosure, a basic block includes a global basic block and at least one local basic block, and the partitioning module 601 includes a first partitioning unit and a second partitioning unit. The first partitioning unit is configured to partition an intermediate representation of a global scope into the global basic block, where the intermediate representation of the global scope is valid for all of the multiple intermediate representations. The second partitioning unit is configured to partition an intermediate representation of a local scope into corresponding local basic blocks, where the intermediate representation of the local scope is valid only within the corresponding local basic block.

[0134] For example, in at least one embodiment of the present disclosure, the resource management device 600 further includes an insertion module, which is configured to insert an intermediate representation representing a terminator at a branch end position for a local basic block with a branch.

[0135] For example, in at least one embodiment of the present disclosure, the intermediate representation includes a resource-class intermediate representation and a non-resource-class intermediate representation, and the resource management apparatus 600 further includes a first initialization unit and a second initialization unit. The first initialization unit is configured to establish a first resource space and initialize it to empty; and for each resource-class intermediate representation, set a resource counter for the resource-class intermediate representation and initialize it to 0, and place the identifier of the resource-class intermediate representation and the resource counter corresponding to the resource-class intermediate representation into the first resource space. The second initialization unit is configured to establish a second resource space and initialize it to empty.

[0136] For example, in at least one embodiment of the present disclosure, the determination module 602 is further configured to, for each intermediate representation, if the intermediate representation is the start of a basic block, set a block counter for the basic block and initialize it to 0; if the intermediate representation is a resource-class intermediate representation, put the identifier of the intermediate representation into the second resource space, and add 1 to the block counter corresponding to the basic block where the intermediate representation is located; if the intermediate representation is a non-resource-class intermediate representation, save all identifiers in the second resource space to the resource set corresponding to the intermediate representation, and add 1 to the resource counters corresponding to all resource-class intermediate representations that exist in both the first resource space and the second resource space; and if the intermediate representation is the end of a basic block, remove N identifiers from the second resource space, where N is the count value of the block counter corresponding to the basic block where the intermediate representation is located, N is an integer and N≥0.

[0137] For example, in at least one embodiment of the present disclosure, the resource management apparatus 600 further includes a sorting module, which is configured to sort all non-resource intermediate representations.

[0138] For example, in at least one embodiment of the present disclosure, the allocation module 603 is further configured to sequentially process each sorted non-resource intermediate representation based on the information stored in the first resource space.

[0139] For example, in at least one embodiment of the present disclosure, the allocation module 603 is further configured to allocate the corresponding resource class intermediate representation to the resource class intermediate representation for each identifier in the resource set corresponding to each sorted non-resource class intermediate representation if the resource class intermediate representation has not been allocated resources; if the resource class intermediate representation has been allocated resources, reduce the resource counter corresponding to the resource class intermediate representation by 1; and if the resource counter corresponding to the resource class intermediate representation has a value of 0, release the resources held by the resource class intermediate representation.

[0140] For example, in at least one embodiment of the present disclosure, the resource management device 600 may be a compiler, or a component provided in the compiler.

[0141] It should be noted that the above Figure 6 The various modules shown can be implemented by software, hardware, firmware or any combination thereof. For example, they can be implemented as a division circuit, a determination circuit and an allocation circuit respectively. The embodiments of the present disclosure do not limit their specific implementation methods.

[0142] It should be understood that the resource management device 600 provided in at least one embodiment of the present disclosure can be used to implement the aforementioned resource management method, and can also achieve technical effects similar to those of the aforementioned resource management method, which will not be elaborated here.

[0143] It should be noted that in the embodiments of the present disclosure, the resource management device 600 may include more or fewer modules or units, and the connection relationship between the modules or units is not limited and can be determined according to actual needs. The specific configuration of each module is not limited and can be composed of analog devices according to circuit principles, or can be composed of digital chips, or constructed in other applicable ways.

[0144] Figure 7 A schematic block diagram of an electronic device provided in accordance with at least one embodiment of the present disclosure.

[0145] For example, Figure 7 As shown, the electronic device 700 includes at least one processor 701 and at least one memory 702. The at least one memory 702 includes one or more computer program modules. The one or more computer program modules are stored in the memory 702 and are configured to be executed by the at least one processor 701. The one or more computer program modules include instructions for executing the above-mentioned resource management method. When executed by the at least one processor 701, one or more steps in the resource management method provided in at least one embodiment of the present disclosure can be executed. The memory 702 and the processor 701 can be interconnected via a bus system and / or other forms of connection mechanisms (not shown).

[0146] For example, the processor 701 may be a central processing unit (CPU), a digital signal processor (DSP), a graphics processing unit (GPU), a general-purpose graphics processing unit (GPGPU), an artificial intelligence (AI) accelerator, or other processing units with data processing capabilities and / or program execution capabilities, such as a field programmable gate array (FPGA). For example, the central processing unit (CPU) may be an X86, ARM, or RISC-V architecture. The processor 701 may be a general-purpose processor or a dedicated processor, and may control other components in the electronic device 700 to perform desired functions.

[0147] For example, the memory 702 may include any combination of one or more computer program products, which may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. Volatile memory may include, for example, random access memory (RAM) and / or cache memory. Non-volatile memory may include, for example, read-only memory (ROM), a hard disk, an erasable programmable read-only memory (EPROM), a portable compact disk read-only memory (CD-ROM), a USB memory, a flash memory, etc.

[0148] Figure 8A schematic block diagram of another electronic device provided for at least one embodiment of the present disclosure.

[0149] The electronic devices in at least one embodiment of the present disclosure may include but are not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), wearable electronic devices, etc., as well as fixed terminals such as digital TVs, desktop computers, etc. Figure 8 The electronic device shown is only an example and should not limit the functions and scope of use of the embodiments of the present disclosure.

[0150] The electronic device includes at least one processor and a memory. The processor here can be referred to as the processing device 801 described below, and the memory can include at least one of the read-only memory (ROM) 802, the random access memory (RAM) 803, and the storage device 808 described below. The memory is used to store programs for executing the methods described in the above-mentioned various method embodiments; the processor is configured to execute the programs stored in the memory. The processor can be a central processing unit (CPU) or other form of processing unit with data processing capability and / or instruction execution capability, and can control other components in the electronic device to perform the desired functions.

[0151] like Figure 8 As shown, the electronic device 800 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 801, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 802 or a program loaded from a storage device 808 into a random access memory (RAM) 803. Various programs and data required for the operation of the electronic device 800 are also stored in the RAM 803. The processing device 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.

[0152] Typically, the following devices may be connected to the I / O interface 805: an input device 806 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 807 including, for example, a display (e.g., a liquid crystal display (LCD) or an organic light emitting diode display (OLED)), a speaker, a vibrator, etc.; a storage device 808 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 809. The communication device 809 may allow the electronic device 800 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 8The electronic device 800 is shown with various devices, but it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed instead.

[0153] In particular, according to at least one embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, at least one embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program includes program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device 809, or installed from the storage device 808, or installed from the ROM 802. When the computer program is executed by the processing device 801, the above-mentioned functions defined in the method of at least one embodiment of the present disclosure are performed.

[0154] It should be noted that the computer-readable medium described above in the present disclosure may be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. Computer-readable storage media may be, for example, but not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or components, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to, an electrical connection having one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In at least one embodiment of the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, device, or component. Furthermore, in at least one embodiment of the present disclosure, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium may be transmitted using any suitable medium, including but not limited to wires, optical cables, RF (radio frequency), etc., or any suitable combination thereof.

[0155] The computer-readable medium may be included in the electronic device 800 , or may exist independently without being incorporated into the electronic device 800 .

[0156] Figure 9 A schematic block diagram of a non-transitory computer-readable storage medium is provided for at least one embodiment of the present disclosure.

[0157] For example, Figure 9 As shown, a non-transitory computer-readable storage medium 900 stores computer-readable instructions 901 , which, when executed by at least one processor, perform one or more steps of the above-mentioned resource management method.

[0158] For example, the storage medium may include a memory card of a smart phone, a storage component of a tablet computer, a hard disk of a personal computer, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a portable compact disk read-only memory (CD-ROM), a flash memory, or any combination of the above storage media, or other suitable storage media. For example, the readable storage medium may also be Figure 7 For the memory 702 in the embodiment, the related description can be referred to the aforementioned content and will not be repeated here.

[0159] Although the present disclosure has been described in detail above using general descriptions and specific embodiments, it will be apparent to those skilled in the art that modifications or improvements may be made based on the embodiments of the present disclosure. Therefore, such modifications or improvements, as long as they do not depart from the spirit of the present disclosure, are within the scope of protection claimed by the present disclosure.

[0160] Regarding this disclosure, the following points need to be explained:

[0161] (1) The drawings of the embodiments of the present disclosure only relate to the structures related to the embodiments of the present disclosure. Other structures may refer to conventional designs.

[0162] (2) For the sake of clarity, in the drawings used to describe the embodiments of the present disclosure, the thickness of layers or regions is exaggerated or reduced, that is, these drawings are not drawn according to the actual scale.

[0163] (3) In the absence of conflict, the embodiments of the present disclosure and the features therein may be combined with each other to form new embodiments.

[0164] The above description is only a specific embodiment of the present disclosure, but the protection scope of the present disclosure is not limited thereto. The protection scope of the present disclosure shall be based on the protection scope of the claims.

Claims

1. A resource management method, comprising: Dividing the plurality of intermediate representations into at least one basic block according to an attribute of each intermediate representation in the plurality of intermediate representations, wherein the plurality of intermediate representations are simplified program representations of source code during a compilation process, the basic block is a discrete structure constituting a program, and instructions within the basic block are executed linearly; determining resource status information based on a type of each intermediate representation in the plurality of intermediate representations and boundary information of the at least one basic block, wherein the resource status information records resource requirements of the plurality of intermediate representations; and Allocate and release resources for the multiple intermediate representations based on the resource status information; The basic block includes a global basic block and at least one local basic block, and dividing the multiple intermediate representations into at least one basic block according to the attribute of each intermediate representation in the multiple intermediate representations includes: Dividing an intermediate representation of a global scope into the global basic block, the intermediate representation of the global scope being valid for the plurality of intermediate representations; and The intermediate representation of the local scope is divided into corresponding local basic blocks, and the intermediate representation of the local scope is only valid within the corresponding local basic block.

2. The resource management method according to claim 1, wherein: The properties of the intermediate representation include the scope of the intermediate representation, and at least one of an operation type or a dependency relationship.

3. The resource management method according to claim 1, further comprising: For a local basic block with branches, an intermediate representation representing the terminator is inserted at the end of the branch.

4. The resource management method according to claim 1, wherein: The intermediate representation includes a resource-type intermediate representation and a non-resource-type intermediate representation, and the resource management method further includes: Create a first resource space and initialize it to empty; For each resource class intermediate representation, setting a resource counter for the resource class intermediate representation and initializing it to 0, and placing the identifier of the resource class intermediate representation and the resource counter corresponding to the resource class intermediate representation into the first resource space; and Create a second resource space and initialize it to empty.

5. The resource management method according to claim 4, wherein: The determining of resource status information based on the type of each intermediate representation in the plurality of intermediate representations and boundary information of the at least one basic block includes: For each intermediate representation, If the intermediate representation is the start of a basic block, set a block counter for the basic block and initialize it to 0; If the intermediate representation is the resource-class intermediate representation, placing the identifier of the intermediate representation into the second resource space, and increasing the block counter corresponding to the basic block where the intermediate representation is located by 1; If the intermediate representation is the non-resource intermediate representation, save all identifiers in the second resource space to the resource set corresponding to the intermediate representation, and increment the resource counters corresponding to all resource intermediate representations that exist in both the first resource space and the second resource space by 1; and If the intermediate representation is the end of a basic block, N identifiers are removed from the second resource space, where N is the count value of the block counter corresponding to the basic block where the intermediate representation is located, and N is an integer and N≥0.

6. The resource management method according to claim 4, further comprising: Sort all non-resource intermediate representations.

7. The resource management method according to claim 6, wherein: The allocating and releasing resources for the plurality of intermediate representations based on the resource status information includes: Based on the information stored in the first resource space, each sorted non-resource intermediate representation is sequentially processed.

8. The resource management method according to claim 7, wherein: The sequential processing of each sorted non-resource intermediate representation includes: For each resource-class intermediate representation corresponding to each identifier in the resource set corresponding to each sorted non-resource-class intermediate representation, If the resource class intermediate representation has no resources allocated to it, allocate the corresponding resources to the resource class intermediate representation; If the resource class intermediate representation has been allocated resources, decrement the resource counter corresponding to the resource class intermediate representation by 1; and If the resource counter value corresponding to the resource class intermediate representation is 0, the resources held by the resource class intermediate representation are released.

9. The resource management method according to any one of claims 1 to 8, wherein: The resource management method is executed by a compiler.

10. An electronic device comprising: at least one processor; at least one memory storing one or more computer program modules; The one or more computer program modules are configured to be executed by the at least one processor to execute instructions of the resource management method according to any one of claims 1 to 9.

11. A non-transitory computer-readable storage medium having computer-readable instructions stored thereon, wherein: When the computer-readable instructions are executed by at least one processor, the resource management method according to any one of claims 1 to 9 is implemented.

Citation Information

Patent Citations

  • Task processing method and device, electronic equipment and storage medium

    CN114968594A

  • Method, a device, and a computer program product for determining a resource required for executing a code segment

    US20200334083A1