Register resource allocation method, computer device, readable storage medium and program product

By constructing function groups and resource record tables, the isolation and consistency issues of register allocation in coroutine mode are solved, and efficient parallel computing in cooperative mode is achieved.

CN121070435BActive Publication Date: 2026-02-27SHANGHAI BIREN TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511596722.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-11-04
Publication Date
2026-02-27
Estimated Expiration
2045-11-04

Smart Images

  • Figure CN121070435B_ABST
    Figure CN121070435B_ABST
Patent Text Reader

Abstract

The application relates to a register resource allocation method, computer equipment, a readable storage medium and a program product. The method comprises the following steps: constructing a function group through a calling relationship between functions, the function group comprising a coroutine kernel function and at least one coroutine sub-function; creating a resource record table corresponding to the function group, the resource record table being used for recording register resources allocated for the coroutine kernel function and / or the coroutine sub-function in the function group; and performing register allocation for the coroutine kernel function and the coroutine sub-function in the function group based on the resource record table. The method can meet the demand that local variable register resources are isolated and shared variable register resources are consistent in a cooperative mode, thereby improving parallel computing efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of artificial intelligence chip technology, and in particular to a register resource allocation method, computer device, readable storage medium, and program product. Background Technology

[0002] In the fields of parallel and heterogeneous computing, the collaborative optimization of hardware architecture and programming models is the core direction for improving computing efficiency. Coroutine functions, by initiating coroutines, can efficiently realize collaborative work in patterns such as consumer-producer, adding a concurrent dimension to device programming in addition to SIMT (Single Instruction Multiple Threads) parallelism, significantly expanding the application scenarios of parallel computing.

[0003] However, hardware execution in coroutine mode faces the following constraints: the compiler must ensure that local code in different kernel functions uses isolated physical register blocks to avoid interference from local variables; at the same time, shared variables between different kernel functions must be mapped to the same physical registers to guarantee effective data exchange and consistency. This dual requirement of both isolation and sharing poses a severe challenge to register allocation.

[0004] Traditional register allocation algorithms are all based on a single function design. Their core logic is to allocate register resources for variables inside the function. They cannot meet the requirements of local variable isolation and shared variable consistency in the coroutine mode, which has become a technical bottleneck restricting the efficient operation of kernel function coroutines. Summary of the Invention

[0005] Based on this, it is necessary to provide a register resource allocation method, computer device, readable storage medium, and program product that can meet the requirements of cooperative mode to ensure that local variables of different coroutine functions are isolated through different blocks, and to ensure the address consistency of shared variables.

[0006] Firstly, this application provides a register resource allocation method, including:

[0007] Function groups are constructed by means of function call relationships, wherein the function group includes a coroutine kernel function and at least one coroutine subfunction;

[0008] Create a resource record table corresponding to the function group, the resource record table being used to record the register resources allocated to the coroutine kernel function and / or coroutine subfunction in the function group;

[0009] Register allocation is performed for the coroutine kernel function and coroutine subfunction in the function group based on the resource record table.

[0010] In one of the embodiments, the function group is constructed through the calling relationship between functions, including:

[0011] The calling relationship between functions is obtained by traversing the compiled file, and at least one function group is constructed based on the calling relationship between functions, for any function group, the coroutine kernel function in the function group is not called by other functions, and the coroutine sub-function is only called by the coroutine kernel function.

[0012] In one of the embodiments, the resource record table corresponding to the function group is created, including:

[0013] A first resource record table is created for each function group, and the first resource record table is used to record the register resources allocated for the coroutine function, which is the coroutine kernel function or the coroutine sub-function in the function group.

[0014] In one of the embodiments, the register allocation is performed for the coroutine kernel function and the coroutine sub-function in the function group based on the resource record table, including:

[0015] The coroutine kernel function in each function group is adjusted to the head of the compiled file;

[0016] The compiled file is traversed, and for each coroutine function traversed, register resource allocation is performed for the coroutine function based on the first resource record table.

[0017] In one of the embodiments, the register resource allocation is performed for the coroutine function based on the first resource record table, including:

[0018] The register resources recorded in the resource record table are reserved in a resource pool, and register allocation is performed for the coroutine function from the remaining register resources in the resource pool;

[0019] The register resources allocated to the coroutine function are added to the resource record table.

[0020] In one of the embodiments, the resource record table corresponding to the function group is created, including:

[0021] Reserve corresponding register resources for each function group;

[0022] For any function group, a second resource record table corresponding to the function group is created based on the register resources allocated for the function group, and the second resource record table is used to record the register resources reserved for the function group.

[0023] In one of the embodiments, the register allocation is performed for the coroutine kernel function and the coroutine sub-function in the function group based on the resource record table, including:

[0024] adjusting a coroutine kernel function in each of the function groups to a header of a compiled file;

[0025] traversing the compiled file, and for each coroutine function in the traversal, performing register allocation for the coroutine function based on a second resource record table corresponding to a function group to which the coroutine function belongs, the coroutine function being a coroutine kernel function or a coroutine sub-function.

[0026] In one embodiment, the performing register resource allocation for the coroutine function based on the second resource record table corresponding to the function group to which the coroutine function belongs comprises:

[0027] obtaining the second resource record table corresponding to the function group to which the coroutine function belongs;

[0028] performing register allocation for the coroutine function from register resources recorded in the second resource record table;

[0029] deleting the register resources allocated for the coroutine function from the second resource record table.

[0030] In a second aspect, the present application further provides a register resource allocation apparatus, comprising:

[0031] a construction module configured to construct a function group through an inter-function calling relationship, the function group comprising a coroutine kernel function and at least one coroutine sub-function;

[0032] a creation module configured to create a resource record table corresponding to the function group, the resource record table being configured to record register resources allocated for the coroutine kernel function and / or the coroutine sub-function in the function group;

[0033] an allocation module configured to perform register allocation for the coroutine kernel function and the at least one coroutine sub-function in the function group based on the resource record table.

[0034] In one embodiment, the constructing the function group through the inter-function calling relationship comprises:

[0035] traversing a compiled file to obtain an inter-function calling relationship, and constructing a function group based on the inter-function calling relationship, for any of the function groups, a coroutine kernel function in the function group not being called by other functions, and a coroutine sub-function only being called by the coroutine kernel function.

[0036] In one embodiment, the creating the resource record table corresponding to the function group comprises:

[0037] A first resource record table is created for each of the function groups, and the first resource record table is used to record the register resources allocated for the coroutine functions, which are the coroutine kernel functions or the coroutine sub-functions in the function groups.

[0038] In one of the embodiments, the register allocation for the coroutine kernel functions and the coroutine sub-functions in the function groups based on the resource record table comprises:

[0039] The coroutine kernel functions in each of the function groups are adjusted to the header of the compilation file.

[0040] The compilation file is traversed, and for each coroutine function traversed, the register resource allocation is performed for the coroutine function based on the first resource record table.

[0041] In one of the embodiments, the register resource allocation for the coroutine function based on the first resource record table comprises:

[0042] The register resources recorded in the resource record table are reserved in a resource pool, and the register allocation is performed for the coroutine function from the remaining register resources in the resource pool.

[0043] The register resources allocated to the coroutine function are added to the resource record table.

[0044] In one of the embodiments, the creation of the resource record table corresponding to the function groups comprises:

[0045] The corresponding register resources are reserved for each of the function groups.

[0046] For any of the function groups, a second resource record table corresponding to the function group is created based on the register resources allocated for the function group, and the second resource record table is used to record the register resources reserved for the function group.

[0047] In one of the embodiments, the register allocation for the coroutine kernel functions and the coroutine sub-functions in the function groups based on the resource record table comprises:

[0048] The coroutine kernel functions in each of the function groups are adjusted to the header of the compilation file.

[0049] The compilation file is traversed, and for each coroutine function traversed, the register allocation is performed for the coroutine function based on the second resource record table corresponding to the function group to which the coroutine function belongs, and the coroutine function is the coroutine kernel function or the coroutine sub-function.

[0050] In one of the embodiments, the register resource allocation for the coroutine function based on the second resource record table corresponding to the function group to which the coroutine function belongs comprises:

[0051] obtaining a second resource record table corresponding to a function group to which the coroutine function belongs;

[0052] allocating registers for the coroutine function from register resources recorded in the second resource record table;

[0053] deleting the register resources allocated for the coroutine function from the second resource record table.

[0054] In a third aspect, the present application also provides a computer device, comprising a memory and a processor, the memory stores a computer program, and the processor implements the register resource allocation method of any one of the above when executing the computer program.

[0055] In a fourth aspect, the present application also provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the register resource allocation method of any one of the above.

[0056] In a fifth aspect, the present application also provides a computer program product, comprising a computer program, and the computer program is executed by a processor to implement the register resource allocation method of any one of the above.

[0057] The register resource allocation method, computer device, readable storage medium and program product provided by the above embodiments, the function group is constructed through the calling relationship between functions, the function group includes a coroutine kernel function and at least one coroutine sub-function, a resource record table corresponding to the function group is created, the resource record table is used to record the register resources allocated for the coroutine kernel function and the coroutine sub-function in the function group, and register allocation is performed for the coroutine kernel function and the coroutine sub-function in the function group based on the resource record table. By using the register resource allocation method, computer device, readable storage medium and program product provided by the embodiments of the present application, the function group containing the coroutine kernel function and the coroutine sub-function is constructed through the calling relationship between functions, the extension of the register allocation perspective from a single function to an associated function cluster is realized, the introduction of the resource record table provides a global perspective for the register resource allocation in the function group, register conflicts or resource waste caused by independent allocation of a single function can be avoided, cross-coroutine register collaborative planning is realized, and the demand for both local variable register resource isolation and shared variable register resource consistency in the collaborative mode is met, so that the expansion of the coroutine function in the concurrency dimension can be fully utilized, and the parallel computing efficiency is improved. BRIEF DESCRIPTION OF DRAWINGS

[0058] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related art, the drawings needed to be used in the description of the embodiments of the present application or the related art will be briefly introduced. Obviously, the drawings in the following description only some embodiments of the present application, and for those skilled in the art, other related drawings can be obtained without creative labor.

[0059] Figure 1 For an embodiment, the schematic diagram of the coroutine dimension parallel computing is shown in FIG. 1.

[0060] Figure 2 For an embodiment, the flowchart of the register resource allocation method is shown in FIG. 2.

[0061] Figure 3 For an embodiment, the structural schematic diagram of the artificial intelligence processor is shown in FIG. 3.

[0062] Figure 4 For an embodiment, the schematic diagram of the function group is shown in FIG. 4.

[0063] Figure 5 For an embodiment, the flowchart of step 206 is shown in FIG. 5.

[0064] Figure 6 For an embodiment, the flowchart of step 504 is shown in FIG. 6.

[0065] Figure 7 For an embodiment, the schematic diagram of the coroutine function register resource allocation is shown in FIG. 7.

[0066] Figure 8 For an embodiment, the flowchart of step 204 is shown in FIG. 8.

[0067] Figure 9 For another embodiment, the flowchart of step 206 is shown in FIG. 9.

[0068] Figure 10 For an embodiment, the flowchart of step 904 is shown in FIG. 10.

[0069] Figure 11 For an embodiment, the structural block diagram of the register resource allocation device is shown in FIG. 11.

[0070] Figure 12 For an embodiment, the internal structure diagram of the computer device is shown in FIG. 12. DETAILED DESCRIPTION

[0071] In order to make the purpose, technical solutions and advantages of the present application more clear, the present application will be further described in detail below with reference to the drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application, and not to limit the present application.

[0072] It should be noted that the terms "first", "second", etc. used in the present application can be used to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish the first element from the second element. The terms "include" and "have" and any variations thereof used in the present application are intended to cover non-exclusive inclusion. The term "a plurality of" used in the present application refers to two or more. The term "and / or" used in the present application refers to one of the options or any combination of the options.

[0073] In the field of parallel computing and heterogeneous computing, the coroutine kernel function technology adds a new concurrency dimension to device programming beyond SIMT parallelism by introducing an asynchronous execution model. With the support of a specific hardware architecture, the threads of a kernel function can start a coroutine through an asynchronous function and achieve synchronization control with the help of a coroutine semaphore. Typical application scenarios include the consumer-producer mode. Referring to Figure 1 As shown, the coroutines can be executed alternately (for example, the first coroutine (coroutine#0) and the second coroutine (coroutine#1) can be executed alternately), and the threads within the coroutines can be executed in parallel (the threads in parallel are represented by arrows that are parallel and downward). Figure 1 Figure 1 As shown, the coroutines can be executed alternately (for example, the first coroutine (coroutine#0) and the second coroutine (coroutine#1) can be executed alternately), and the threads within the coroutines can be executed in parallel (the threads in parallel are represented by arrows that are parallel and downward). Figure 1

[0074] This programming paradigm allows developers to define coroutine functions through lambda expressions and capture shared resources (such as the integer variable v for data exchange and the coroutine signal s for synchronization control), while passing kernel function parameters (such as the input parameter in and the output parameter out) to the capture list of the coroutine function to support data sharing and state synchronization.

[0075] However, there are certain constraints on the current coroutine semantics: asynchronously started coroutines can only be executed in one direction to the program end, so the coroutine function does not support return values. At the hardware execution level, the coroutine mode requires the compiler to satisfy double constraints when allocating registers: not only to ensure that the local variables of different kernel functions use isolated physical register blocks, but also to ensure that shared variables are mapped to the same physical register address.

[0076] Traditional single-function-based register allocation algorithms cannot meet this challenge: on the one hand, they lack global planning capabilities across functions and are difficult to pre-allocate exclusive register blocks to different coroutine functions; on the other hand, they cannot guarantee that the local variables of different coroutines use completely non-overlapping registers, making it difficult to achieve both local isolation and shared consistency, which becomes a bottleneck restricting the performance of coroutine kernel function technology.

[0077] ​​The embodiment of the application provides a register resource allocation method, a function group containing a coroutine kernel function and a coroutine sub-function is constructed through an inter-function call relationship, register resource allocation is performed based on the function group, register allocation perspective is expanded from a single function to an associated function cluster, register conflict or resource waste caused by independent allocation of a single function can be avoided, register collaborative planning across coroutines is realized, and the demand that local variable register resources should be isolated and shared variable register resources should be consistent in a collaborative mode is met.

[0078] In one exemplary embodiment, as shown in Figure 2 A register resource allocation method is provided, applied to an artificial intelligence processor. In the embodiment of the application, the artificial intelligence processor is any one of a GPU (Graphics Processing Unit, graphics processor), a TPU (Tensor Processing Unit, tensor processor), an NPU (Neural network Processing Unit, neural network processor), a DPU (Deep learning Processing Unit, deep learning processor), an APU (Accelerated Processing Unit, acceleration processor), and a GPGPU (General-Purpose Graphics Processing Unit, general-purpose graphics processor). In the embodiment of the application, this is not specifically limited, and the following is described by taking the GPGPU as an example.

[0079] Referring to Figure 3 A structural diagram of the GPGPU is shown. The GPGPU is actually an array of streaming processor clusters (SPC), for example, including a streaming processor cluster 1,..., a streaming processor cluster M, as shown in Figure 3 M is a positive integer greater than 1. In the graphics processor, one streaming processor cluster processes one computing task, or multiple streaming processor clusters process one computing task. Multiple streaming processor clusters share data through a global cache or a global memory.

[0080] As shown in Figure 3 Taking the streaming processor cluster 1 as an example, one streaming processor cluster includes multiple computing units, for example Figure 3The compute units 1, 2, …, N in the stream processor cluster 1 are configured to perform arithmetic logic operations other than matrix computation, such as accumulation, reduction, regular addition, subtraction, multiplication, division, etc. Each compute unit includes a plurality of cores, each of which includes an arithmetic logic unit (ALU), a floating point compute unit, etc. The cores are configured to perform specific compute tasks. In addition, each compute unit includes a register file (e.g. Figure 3

[0081] In parallel computing, a compute task is generally executed by a plurality of threads. The threads are divided into a plurality of thread blocks before being executed in the general purpose graphics processor (or parallel computing processor), and then the plurality of thread blocks are distributed to the compute units via a thread block distribution module (not shown in Figure 3 All threads in a thread block must be assigned to the same compute unit for execution. Meanwhile, the thread blocks are split into the smallest execution thread bundle (or simply referred to as a thread bundle, warp), each of which includes a fixed number (or less than the fixed number) of threads, for example, 32 threads. The plurality of thread blocks can be executed in the same compute unit or in different compute units.

[0082] In each compute unit, a thread bundle scheduling / distribution module (not shown in Figure 3 ) schedules and assigns the thread bundles so that the plurality of compute cores of the compute unit execute the thread bundles. According to the number of compute cores in the compute unit, the plurality of thread bundles in a thread block can be executed simultaneously or in time division. The plurality of threads in each thread bundle execute the same instruction. Memory execution instructions are transmitted to the shared cache in the compute unit or further transmitted to the L2 cache or the global cache or the global memory for read / write operations, etc.

[0083] As shown in Figure 3 , the stream processor cluster 1 further includes a tensor operation unit configured to perform tensor computation, for example, the tensor computation can include matrix multiplication, convolution operation, etc.

[0084] Referring to Figure 2 , the register resource allocation method provided by the embodiments of the present application can include the following steps 202, 204 and 206, wherein:

[0085] ​In step 202, a function group is constructed through the calling relationship between functions, and the function group includes the coroutine kernel function and at least one coroutine sub-function.

[0086] In the embodiment of the present application, the calling relationship between functions can be obtained by traversing the compilation file. The calling relationship between functions includes direct calling and / or indirect calling relationship between functions. A function group can be constructed for a group of coroutine functions having direct calling relationship and / or indirect calling relationship. For example, the calling relationship between functions can refer to FIG. 1. Figure 4 As shown in FIG. 1, the coroutine function coroutine kernel A calls the coroutine functions coroutine 0, coroutine 1 and coroutine 2 respectively, and the function group is constructed by the coroutine kernel A, the coroutine 0, the coroutine 1 and the coroutine 2.

[0087] In an exemplary embodiment, the function group is constructed through the calling relationship between functions, which can include:

[0088] The calling relationship between functions is obtained by traversing the compilation file, and at least one function group is constructed based on the calling relationship between functions. For any function group, the coroutine kernel function in the function group is not called by other functions, and the coroutine sub-function is only called by the coroutine kernel function.

[0089] In the embodiment of the present application, for a group of coroutine functions having calling relationship, the function in the group of coroutine functions which is not called by other functions is taken as the coroutine kernel function, and the coroutine function which is directly or indirectly called by the coroutine kernel function is taken as the coroutine sub-function. The coroutine kernel function and the coroutine sub-function in the group of functions can construct the corresponding function group.

[0090] In step 204, a resource record table corresponding to the function group is created, and the resource record table is used to record the register resources allocated for the coroutine kernel function and / or the coroutine sub-function in the function group.

[0091] In the embodiment of the present application, after at least one function group is constructed, a corresponding resource record table can be created for each function group, and the resource record table is used to record the register resources allocated for the coroutine functions in the function group. For example, the resource record table can include a first resource record table and a second resource record table. For example, a first resource record table is created for at least one function group, or a corresponding second resource record table is created for each function group. The first resource record table is used to record the register resources allocated to each function in the function group, and the second resource record table is used to record the register resources reserved for each function in the function group, etc.

[0092] In step 206, register allocation is performed for the coroutine kernel function and the coroutine sub-function in the function group based on the resource record table.

[0093] In the embodiments of the present application, the allocation of register resources can be determined based on the resource record table, and then the available register resources can be determined, and the register allocation can be performed for the coroutine functions (including the coroutine kernel function and the coroutine sub-function) in the function group based on the available register resources.

[0094] The above register resource allocation method constructs a function group through the calling relationship between functions, the function group includes a coroutine kernel function and at least one coroutine sub-function, a resource record table corresponding to the function group is created, the resource record table is used to record the register resources allocated for the coroutine kernel function and / or the coroutine sub-function in the function group, and the register allocation is performed for the coroutine kernel function and the coroutine sub-function in the function group based on the resource record table. The register resource allocation method provided in the embodiments of the present application constructs a function group including a coroutine kernel function and a coroutine sub-function through the calling relationship between functions, realizes the expansion of the register allocation perspective from a single function to an associated function cluster, the introduction of the resource record table provides a global perspective for the register resource allocation in the function group, can avoid the register conflict or resource waste caused by the independent allocation of a single function, realizes the register collaborative planning across coroutines, and then meets the demand that both the local variable register resources are isolated and the shared variable register resources are consistent in the collaborative mode, so that the expansion of the coroutine function in the concurrency dimension can be fully utilized, and the parallel computing efficiency is improved.

[0095] In an exemplary embodiment, creating the resource record table corresponding to the function group can include:

[0096] A first resource record table is created for each function group, and the first resource record table is used to record the register resources that have been allocated for the coroutine function, and the coroutine function is the coroutine kernel function or the coroutine sub-function in the function group.

[0097] In the embodiments of the present application, a first resource record table can be created, the first resource record table is initially empty, and each time the register resource is allocated for the coroutine function, the register resource allocated for the coroutine function can be recorded in the first resource record table, and when the register resource is allocated for the coroutine function, the register resource recorded in the first resource record table is removed from the resource pool, and the corresponding register resource is allocated for the coroutine function from the remaining register.

[0098] In an exemplary embodiment, step 206, the register allocation is performed for the coroutine kernel function and the coroutine sub-function in the function group based on the resource record table, can include the following steps 502 and 504, refer to Figure 5

[0099] Step 502, adjusting the coroutine kernel function in each function group to the header of the compilation file;

[0100] ​At step 504, the compiling file is traversed, and for each coroutine function traversed, register resource allocation is performed for the coroutine function based on the first resource record table.

[0101] In the embodiment of the present application, since the coroutine kernel function is the core of the logic in the group, it is necessary to ensure that the resource requirement is processed preferentially during compiling, that is, register resource allocation is performed preferentially for the coroutine kernel function in each function group. For example, the coroutine kernel function can be adjusted to the head of the compiling file, and the coroutine functions in the compiling file are traversed, and for each coroutine function traversed, register resource allocation is performed for the coroutine function based on the first resource record table. Since the coroutine kernel function has been adjusted to the head of the compiling file, the coroutine kernel function will be traversed preferentially when the coroutine file is traversed, and the register resource allocation of the coroutine kernel function can be ensured.

[0102] In an exemplary embodiment, at step 504, the register resource allocation is performed for the coroutine function based on the first resource record table, which can include the following steps 602 and 604, as shown in Figure 6

[0103] At step 602, the register resources recorded in the resource record table are reserved in the resource pool, and register allocation is performed for the coroutine function from the remaining register resources in the resource pool.

[0104] At step 604, the register resources allocated to the coroutine function are added to the resource record table.

[0105] In the embodiment of the present application, after the coroutine kernel function is adjusted to the head of the compiling file, the coroutine functions in the compiling file can be traversed. The traversal process is shown in Figure 7

[0106] The compiling file is traversed, and the coroutine kernel function is traversed first. The register can be allocated to the coroutine kernel function from the resource pool, and the register resources allocated to the coroutine kernel function are recorded in the first resource record table. The compiling file is continuously traversed, and if there are still coroutine functions (including coroutine kernel functions and coroutine sub-functions) that have not been allocated registers, the register resources recorded in the first resource record table are reserved (for example, the Reserve mechanism is used to process the register resources recorded in the first resource record table), and then the remaining register resources in the resource pool are used to allocate registers for the traversed coroutine functions, and the allocated register resources are recorded in the first resource record table. Then, the step of traversing the compiling file is jumped to, and the process is repeated until all coroutine functions are allocated registers.

[0107] ​​In this way, the register resources that have been occupied can be known through the first resource record table, and thus the allocation of register resources for each coroutine function from the register resources that have not been occupied can avoid register conflicts or resource waste caused by independent allocation of a single function, realize register collaborative planning across coroutines, and thus meet the demand that both local variable register resources are isolated and shared variable register resources are consistent in the collaborative mode, so that the expansion of coroutine functions in the concurrency dimension can be fully utilized, and the parallel computing efficiency is improved.

[0108] In an exemplary embodiment, step 204 of creating the resource record table corresponding to the function group can include the following steps 802 and 804, as shown in the table. Figure 8

[0109] Step 802 of reserving corresponding register resources for each function group;

[0110] Step 804 of creating, for any function group, a second resource record table corresponding to the function group based on the register resources allocated to the function group, the second resource record table being used to record the register resources reserved for the function group.

[0111] In the embodiment of the application, the physical register resources are shared by all function groups, and there is no register conflict between different function groups. The core constraint of register allocation is the coroutine functions in the same function group, that is, each coroutine function in the group needs to be allocated a non-overlapping register block, while ensuring that the shared variables in the group use fixed physical registers.

[0112] For the same function group, the number and type of register allocation for each coroutine function can be determined according to the number of coroutine functions in the group, the functional complexity (such as the amount of calculation, the size of data processing), and the historical resource demand, etc. For example, if there are 60 physical register resources, 20 of which are reserved for shared variables (for all function groups), and the remaining 40 are for local variable resources of coroutine functions; then for a function group containing 4 coroutine functions, each coroutine function can be allocated 10 registers; for a function group containing 2 coroutine functions, each coroutine function can also be allocated 10 registers.

[0113] After allocating registers for the coroutine functions in the same function group, a second resource record table can be created for the function group to record the register allocation information of each coroutine function in the group. For example, the second resource record table can include the following information: function group identifier, identifier of each coroutine function in the group, register number range of each coroutine function (such as coroutine 1: R20-R29, coroutine 2: R30-R39), register type (general register / floating point register, etc.), and the like.

[0114] ​In this way, register isolation management of the coroutine functions in the same function group can be realized through the second resource record table, local variable register conflicts of different coroutine functions in the group are avoided, and meanwhile, the shared use of the physical register resources by different function groups is not affected.

[0115] In an exemplary embodiment, in step 206, register allocation is performed for the coroutine kernel functions and the coroutine sub-functions in the function groups based on the resource record tables, referring to Figure 9 As shown in the figure, the following steps 902 and 904 are included, wherein:

[0116] In step 902, the coroutine kernel functions in each function group are adjusted to the header of the compilation file.

[0117] In step 904, the compilation file is traversed, and for each coroutine function in the traversal, register allocation is performed for the coroutine function based on the second resource record table corresponding to the function group to which the coroutine function belongs, the coroutine function being a coroutine kernel function or a coroutine sub-function.

[0118] In the embodiments of the present application, the coroutine kernel functions of each function group can be respectively moved to the header region of the compilation file. Since the coroutine kernel functions are the core of the logic in the group, being placed in the header can ensure that their resource requirements are processed preferentially during compilation.

[0119] According to the adjusted order of the compilation file (after adjustment, the header coroutine kernel functions are traversed preferentially), all coroutine functions (including coroutine kernel functions and coroutine sub-functions) are traversed one by one, and register allocation is performed for each coroutine according to the second resource record table of the function group to which the coroutine belongs. In this way, each coroutine function only obtains register resources from the second resource record table of the function group to which it belongs, which can ensure that register resources are isolated between different coroutine functions.

[0120] In an exemplary embodiment, in step 904, register resource allocation is performed for the coroutine function based on the second resource record table corresponding to the function group to which the coroutine function belongs, referring to Figure 10 As shown in the figure, the following steps 1002, 1004 and 1006 are included, wherein:

[0121] In step 1002, the second resource record table corresponding to the function group to which the coroutine function belongs is obtained.

[0122] In step 1004, register allocation is performed for the coroutine function from the register resources recorded in the second resource record table.

[0123] In step 1006, the register resources allocated for the coroutine function are deleted from the second resource record table.

[0124] In the embodiments of the present application, for the currently traversed coroutine function, the function group to which the coroutine function belongs can be found through the function group identifier (such as the group name or unique ID), and a suitable register can be selected from the reserved registers recorded in the second resource record table of the function group for allocation. For example, an unused register can be preferentially allocated, and if there are multiple selectable registers, the registers can be selected according to the access efficiency (such as general-purpose registers are preferred over special-purpose registers).

[0125] After completing the register allocation, the register can be removed from the second resource record table of the function group to which the register belongs. In this way, the same register can be prevented from being repeatedly allocated to other functions in the group, ensuring the isolation of register resources among different coroutines, while reflecting the remaining situation of the reserved resources in real time, thereby providing an accurate basis for subsequent function allocation.

[0126] In the embodiments of the present application, the second resource record table is used to plan exclusive register resources for different coroutine functions in the same function group in advance, and the coroutine function only allocates registers from the reserved register resources in the second resource record table of the function group to which the coroutine function belongs, so that the isolation of register resources among coroutine functions can be achieved.

[0127] In order for those skilled in the art to better understand the embodiments of the present application, the embodiments of the present application are described below through specific examples.

[0128] The embodiments of the present application propose a function group-based coroutine register allocation method, wherein the function group is characterized by a coroutine kernel function and all coroutine sub-functions called by the coroutine kernel function, and the coroutine sub-functions can only be called by the current kernel function. The register allocation method includes the following four main steps:

[0129] Step 1: Analyze the compilation file, and construct a function group according to the mapping relationship between the coroutine kernel function and all coroutine sub-functions called by the coroutine kernel function;

[0130] Step 2: Modify the function order in the compilation file to ensure that the coroutine kernel function is allocated registers before the coroutine sub-functions;

[0131] Step 3: Allocate registers for the coroutine kernel function;

[0132] Step 4: Allocate registers for the coroutine sub-functions.

[0133] The aforementioned step 2 can include: traversing the functions of the entire compilation file, and adjusting the definition of the coroutine kernel function to the head of the compilation module. For example, the example before the compilation file is adjusted as follows:

[0134] / / Translation Unit

[0135] Coroutine Kernel1:

[0136]

[0137] Coroutine 1:

[0138]

[0139] Coroutine 2:

[0140]

[0141] Coroutine Kernel2:

[0142]

[0143] Coroutine 3:

[0144]

[0145] Coroutine 4:

[0146]

[0147] Coroutine 5:

[0148]

[0149] The compiled file in the above example can be divided into two function groups, the first function group {Coroutine Kernel1, (Coroutine 1, Coroutine 2)} and the second function group {Coroutine Kernel2, (Coroutine 3, Coroutine 4, Coroutine 5)}.

[0150] After adjusting the compiled file, Coroutine Kernel1 and Coroutine Kernel2 are adjusted to the head of the compiled file, and the compiled example is as follows:

[0151] / / Translation Unit

[0152] Coroutine Kernel1:

[0153]

[0154] Coroutine Kernel2:

[0155]

[0156] Coroutine 1:

[0157]

[0158] Coroutine 2:

[0159]

[0160] Coroutine 3:

[0161]

[0162] Coroutine 4:

[0163]

[0164] Coroutine 5:

[0165]

[0166] The implementation process of the foregoing Step 3 and Step 4 is shown in FIG. 6, and the implementation process of the foregoing Step 4 is shown in FIG. 7. Figure 7 The implementation process of the foregoing Step 3 and Step 4 is shown in FIG. 6, and the implementation process of the foregoing Step 4 is shown in FIG. 7. Figure 7 The algorithm for performing register allocation on each function is a function-level general register allocation algorithm, and the Reserve mechanism refers to excluding the physical registers that have been used from the entire resource pool before register allocation. For example, the general registers are R0-R255, so the entire allocation resource pool is R0-R255 at the beginning, and it is assumed that the coroutine kernel function (i.e., a shared variable) allocates R0-R11, so that when the coroutine sub-function is allocated, the resource pool becomes R12-R255. The RegUsedList represents a resource record table.

[0167] Based on the existing function-level general register allocation algorithm, the embodiment of the present application meets the demand of register allocation of the coroutine kernel function by regarding the coroutine kernel function group as a whole and combining the Reserve mechanism, and the technical implementation is relatively simple and does not need to modify the existing register allocation framework of the llvm (Low Level Virtual Machine, bottom layer virtual machine) backend.

[0168] It should be understood that, although each step in the flowchart involved in each embodiment as described above is displayed in sequence according to the arrow, these steps are not necessarily executed in sequence according to the arrow. Unless explicitly stated in this document, the execution of these steps has no strict sequence limitation, and these steps can be executed in other sequences. Moreover, at least part of the steps in the flowchart involved in each embodiment as described above can include multiple steps or multiple stages, which are not necessarily executed at the same time, but can be executed at different times, and the execution sequence of these steps or stages is not necessarily sequential, but can be executed in rotation or alternation with at least part of other steps or steps or stages in other steps. It can be understood that the steps in different embodiments can be freely combined as needed, and various non-contradictory schemes formed by the combination are within the scope of protection of the present application.

[0169] Based on the same inventive concept, the embodiments of the present application also provide a register resource allocation device for implementing the register resource allocation method described above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme described in the above method, so the specific limitations in one or more register resource allocation device embodiments provided below can refer to the limitations of the register resource allocation method described above, which will not be repeated here.

[0170] In one exemplary embodiment, as shown in Figure 11 A register resource allocation device 1100 is provided, comprising a construction module 1102, a creation module 1104 and an allocation module 1106, wherein:

[0171] The construction module 1102 is configured to construct a function group through an inter-function calling relationship, the function group comprising a coroutine kernel function and at least one coroutine sub-function;

[0172] The creation module 1104 is configured to create a resource record table corresponding to the function group, the resource record table being configured to record register resources allocated for the coroutine kernel function and / or the coroutine sub-function in the function group;

[0173] The allocation module 1106 is configured to perform register allocation for the coroutine kernel function and the coroutine sub-function in the function group based on the resource record table.

[0174] The register resource allocation device described above constructs a function group through an inter-function calling relationship, the function group comprising a coroutine kernel function and at least one coroutine sub-function, creates a resource record table corresponding to the function group, the resource record table being configured to record register resources allocated for the coroutine kernel function and / or the coroutine sub-function in the function group, and performs register allocation for the coroutine kernel function and the coroutine sub-function in the function group based on the resource record table. By using the register resource allocation device provided in the embodiments of the present application, the function group comprising the coroutine kernel function and the coroutine sub-function is constructed through the inter-function calling relationship, the extension of the register allocation perspective from a single function to an associated function cluster is realized, the introduction of the resource record table provides a global perspective for the register resource allocation within the function group, which can avoid register conflicts or resource waste caused by independent allocation of a single function, realize cross-coroutine register collaborative planning, and thus meet the demand for both local variable register resource isolation and shared variable register resource consistency in the collaborative mode, so that the extension of the coroutine function in the concurrency dimension can be fully utilized, and the parallel computing efficiency is improved.

[0175] In one embodiment, the construction of the function group through the inter-function calling relationship comprises:

[0176] Traverse the compiled file to obtain a call relationship between functions, and build at least one function group based on the call relationship between the functions, for any function group, a coroutine kernel function in the function group is not called by other functions, and a coroutine sub-function is only called by the coroutine kernel function.

[0177] In one of the embodiments, the creating the resource record table corresponding to the function group comprises:

[0178] A first resource record table is created for each function group, and the first resource record table is used to record register resources allocated for a coroutine function, which is a coroutine kernel function or a coroutine sub-function in the function group.

[0179] In one of the embodiments, the performing register allocation for the coroutine kernel function and the coroutine sub-function in the function group based on the resource record table comprises:

[0180] The coroutine kernel function in each function group is adjusted to the head of the compiled file.

[0181] The compiled file is traversed, and for each coroutine function traversed, register resource allocation is performed for the coroutine function based on the first resource record table.

[0182] In one of the embodiments, the performing register resource allocation for the coroutine function based on the first resource record table comprises:

[0183] The register resources recorded in the resource record table are reserved in a resource pool, and register allocation is performed for the coroutine function from the remaining register resources in the resource pool.

[0184] The register resources allocated to the coroutine function are added to the resource record table.

[0185] In one of the embodiments, the creating the resource record table corresponding to the function group comprises:

[0186] Respective register resources are reserved for each function group.

[0187] For any function group, a second resource record table corresponding to the function group is created based on the register resources allocated for the function group, and the second resource record table is used to record the register resources reserved for the function group.

[0188] In one of the embodiments, the performing register allocation for the coroutine kernel function and the coroutine sub-function in the function group based on the resource record table comprises:

[0189] The coroutine kernel function in each function group is adjusted to the head of the compiled file.

[0190] traversing the compiled file, for each coroutine function traversed, performing register allocation for the coroutine function based on a second resource record table corresponding to a function group to which the coroutine function belongs, the coroutine function being a coroutine kernel function or a coroutine sub-function.

[0191] In one of the embodiments, the performing register resource allocation for the coroutine function based on the second resource record table corresponding to the function group to which the coroutine function belongs comprises:

[0192] obtaining the second resource record table corresponding to the function group to which the coroutine function belongs;

[0193] performing register allocation for the coroutine function from the register resources recorded in the second resource record table;

[0194] deleting the register resources allocated for the coroutine function from the second resource record table.

[0195] Each of the modules in the register resource allocation apparatus can be realized by software, hardware, and combinations thereof, in whole or in part. Each of the modules can be embedded in or independent of a processor in a computer device in hardware form, or stored in a memory in the computer device in software form, so as to be called and executed by a processor to perform operations corresponding to each of the modules.

[0196] In an exemplary embodiment, a computer device, which can be a terminal, is provided, and an internal structure diagram of the computer device can be as shown in Figure 12The computer device shown in the figure includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capability. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operating system and the computer program in the non-volatile storage medium to run. The input / output interface of the computer device is used to exchange information between the processor and external devices. The communication interface of the computer device is used to communicate with external terminals in a wired or wireless manner. The wireless manner can be realized through WIFI, mobile cellular network, near field communication (NFC) or other technologies. The computer program is executed by the processor to realize a register resource allocation method. The display unit of the computer device is used to form a visually visible picture, which can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen. The input device of the computer device can be a touch layer overlaid on the display screen, or a key, trackball or touchpad arranged on the shell of the computer device, or an external keyboard, touchpad or mouse, etc.

[0197] Those skilled in the art can understand that, Figure 12 The structure shown in the figure is only a block diagram of part of the structure related to the scheme of the present application, and does not constitute a limitation on the computer device to which the scheme of the present application is applied. The specific computer device can include more or fewer components than those shown in the figure, or combine certain components, or have a different component arrangement.

[0198] In one embodiment, a computer device is also provided, including a memory and a processor, the memory storing a computer program, and the processor executing the computer program to realize the steps in each of the above method embodiments.

[0199] In one embodiment, a computer readable storage medium is provided, which stores a computer program, and the computer program is executed by a processor to realize the steps in each of the above method embodiments.

[0200] In one embodiment, a computer program product is provided, including a computer program, and the computer program is executed by a processor to realize the steps in each of the above method embodiments.

[0201] It should be noted that the user information (including but not limited to user equipment information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the present application are all information and data authorized by the user or authorized by all parties, and the collection, use and processing of related data need to comply with relevant regulations.

[0202] It can be understood by those skilled in the art that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing related hardware through a computer program. The computer program can be stored in a non-volatile computer readable storage medium. When the computer program is executed, it can include the processes of the above-mentioned embodiments of each method. In the embodiments provided in the present application, any reference to memory, database or other medium can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical storage, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration but not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc. The database involved in the embodiments provided in the present application can include at least one of a relational database and a non-relational database. The non-relational database can include a distributed database based on a block chain, etc., without being limited thereto. The processor involved in the embodiments provided in the present application can be a general-purpose processor, a central processing unit, a graphics processing unit, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., without being limited thereto.

[0203] Any technical features in the above embodiments can be combined, and for the sake of brevity, not all possible combinations are described above, however, any combination of these technical features is deemed to be within the scope of the present application.

[0204] The above embodiments only express several implementation manners of the present application, and the description is relatively specific and detailed, but it should not be understood as a limitation on the patent scope of the present application. It should be pointed out that, for ordinary skilled persons in the art, several modifications and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the appended claims.

Claims

1. A method of allocating register resources, characterized by, The method comprises: constructing a function group through a calling relationship between functions, the function group comprising a coroutine kernel function and at least one coroutine sub-function; creating a resource record table corresponding to the function group, the resource record table being used to record register resources that have been allocated to the coroutine kernel function and / or the coroutine sub-function in the function group, or the resource record table being used to record register resources that are currently reserved for the coroutine kernel function and / or the coroutine sub-function in the function group; performing register allocation for the coroutine kernel function and the coroutine sub-function in the function group based on the resource record table.

2. The method of claim 1, wherein, The function group is constructed through a calling relationship between functions, comprising: traversing a compilation file to obtain a calling relationship between functions, and constructing a function group based on the calling relationship between functions, for any function group, the coroutine kernel function in the function group is not called by other functions, and the coroutine sub-function is only called by the coroutine kernel function.

3. The method according to claim 1 or 2, characterized in that, The resource record table corresponding to the function group is created, comprising: a first resource record table is created for each function group, the first resource record table being used to record register resources that have been allocated to a coroutine function, the coroutine function being the coroutine kernel function or the coroutine sub-function in the function group.

4. The method of claim 3, wherein, The register allocation is performed for the coroutine kernel function and the coroutine sub-function in the function group based on the resource record table, comprising: adjusting the coroutine kernel function in each function group to the head of a compilation file; traversing the compilation file, and performing register resource allocation for each coroutine function based on the first resource record table.

5. The method of claim 4, wherein, The register resource allocation is performed for the coroutine function based on the first resource record table, comprising: reserving the register resources recorded in the resource record table in a resource pool, and performing register allocation for the coroutine function from the remaining register resources in the resource pool; adding the register resources allocated to the coroutine function to the resource record table.

6. The method of claim 1 or 2, wherein, The resource record table corresponding to the function group is created, comprising: reserving corresponding register resources for each function group respectively; for any function group, a second resource record table corresponding to the function group is created based on the register resources allocated to the function group, the second resource record table being used to record the register resources reserved for the function group.

7. The method of claim 6, wherein, The register allocation is performed for the coroutine kernel function and the coroutine sub-function in the function group based on the resource record table, comprising: adjusting the coroutine kernel function in each function group to the head of a compilation file; traversing the compilation file, and performing register allocation for each coroutine function based on the second resource record table corresponding to the function group to which the coroutine function belongs, the coroutine function being the coroutine kernel function or the coroutine sub-function.

8. The method of claim 7, wherein, The register resource allocation is performed for the coroutine function based on the second resource record table corresponding to the function group to which the coroutine function belongs, comprising: obtaining the second resource record table corresponding to the function group to which the coroutine function belongs; performing register allocation for the coroutine function from the register resources recorded in the second resource record table; deleting a register resource allocated for the coroutine function from the second resource record table. 9.A computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the computer device is configured to perform the method according to any one of claims 1-8 when the computer program is executed by the processor. The computer program, when executed by the processor, implements the steps of the method of any one of claims 1 to 8.

10. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program, when executed by the processor, implements the steps of the method of any one of claims 1 to 8.

11. A computer program product comprising a computer program, characterized in that, The computer program, when executed by the processor, implements the steps of the method of any one of claims 1 to 8. The computer program, when executed by the processor, implements the steps of the method of any one of claims 1 to 8.

Citation Information

Patent Citations

  • Coroutine execution method and device

    CN114063894A

  • Performance optimization method and device for OpenMP Offload and electronic equipment

    CN117407169A