Parameter transfer method and electronic device
By establishing the mapping relationship and storage mapping between the caller and the callee, the target storage unit is directly allocated, which solves the problem of data duplication and resource waste caused by parameter transfer in multi-layer function calls, and improves parameter transfer efficiency and resource utilization. .
Patent Information
- Application Number
- CN202410865606.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-01
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2044-07-01
AI Technical Summary
In the existing technology, there is frequent data copying and unnecessary resource consumption when passing parameters in multi-layer function calls. Especially when passing aggregate type parameters, the entire aggregate needs to be passed rather than just some of the members used, resulting in a waste of resources.
By establishing a mapping relationship between the caller and the callee, including parameter mapping and storage mapping, the callee is assigned a target storage unit based on these mapping relationships, and parameter values are obtained directly from the target storage unit, reducing data copying and resource usage.
It simplifies the parameter transfer process, reduces the copying of data between different storage units, improves efficiency, avoids unnecessary resource consumption, and significantly improves performance, especially when processing large aggregates.
Smart Images

Figure CN118467064B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present disclosure relate to a parameter transfer method and an electronic device. Background Art
[0002] Parameter passing is a basic and important concept in programming, which refers to the way of passing data from the caller to the callee when calling a function, procedure, method or other subroutine. This mechanism enables the callee to access and operate external data, perform required calculations, and possibly return results. Summary of the invention
[0003] At least one embodiment of the present disclosure provides a parameter passing method, which includes: establishing a mapping relationship between a caller and a callee, wherein the mapping relationship includes a parameter mapping and a storage mapping; and allocating a target storage unit for the callee parameter based on the mapping relationship.
[0004] In the parameter passing method provided by at least one embodiment of the present disclosure, establishing a mapping relationship between a caller and a callee includes: establishing a first mapping relationship between caller parameters and the callee parameters, wherein the first mapping relationship represents a parameter correspondence relationship between the caller parameters and the callee parameters.
[0005] In the parameter passing method provided by at least one embodiment of the present disclosure, establishing the first mapping relationship between the caller parameter and the callee parameter includes: analyzing and recording the first mapping relationship between the caller parameter and the callee parameter based on data flow analysis technology.
[0006] In the parameter passing method provided in at least one embodiment of the present disclosure, the data flow analysis technology includes forward data flow analysis and reverse data flow analysis. The forward data flow analysis represents the data flow analysis from the caller parameter to the corresponding callee parameter, and the reverse data flow analysis represents the data flow analysis from the callee parameter to the corresponding caller parameter.
[0007] In the parameter passing method provided by at least one embodiment of the present disclosure, the reverse data flow analysis includes: tracing the data source path of the callee parameter to obtain the corresponding caller parameter.
[0008] In the parameter transfer method provided by at least one embodiment of the present disclosure, the forward data flow analysis includes: tracing the data transfer path of the caller parameter to obtain the corresponding callee parameter.
[0009] In the parameter passing method provided by at least one embodiment of the present disclosure, the first mapping relationship includes a complete mapping relationship and a partial mapping relationship, the complete mapping relationship represents the correspondence between the complete caller parameters and the callee parameters, and the partial mapping relationship represents the correspondence between a part of the caller parameters and the callee parameters.
[0010] In the parameter passing method provided by at least one embodiment of the present disclosure, the establishing of a mapping relationship between a caller and a callee further includes: establishing a second mapping relationship between a caller parameter and a storage unit, wherein the second mapping relationship represents a storage correspondence relationship between the caller parameter and the storage unit.
[0011] In the parameter passing method provided by at least one embodiment of the present disclosure, establishing the second mapping relationship between the caller parameter and the storage unit includes: obtaining the storage unit where the caller parameter is stored; and recording the second mapping relationship between the caller parameter and the storage unit.
[0012] In the parameter transfer method provided in at least one embodiment of the present disclosure, it also includes: updating the second mapping relationship.
[0013] In the parameter passing method provided by at least one embodiment of the present disclosure, the updating of the second mapping relationship includes: analyzing each instruction between the caller entry and the calling point, checking whether the storage unit recorded in the second mapping relationship has been rewritten with data; and in response to the existence of a storage unit with data rewritten, deleting the record in the second mapping relationship corresponding to the storage unit with the data rewritten.
[0014] In the parameter passing method provided by at least one embodiment of the present disclosure, allocating a target storage unit to the callee parameter based on the mapping relationship includes: determining the target caller parameter corresponding to the callee parameter based on a first mapping relationship; and determining the target storage unit corresponding to the target caller parameter based on a second mapping relationship.
[0015] In the parameter passing method provided by at least one embodiment of the present disclosure, the allocating a target storage unit to the callee parameter based on the mapping relationship further includes: acquiring a parameter value corresponding to the callee parameter from the target storage unit.
[0016] In the parameter passing method provided by at least one embodiment of the present disclosure, the caller and the callee have the same parameters.
[0017] In the parameter transfer method provided in at least one embodiment of the present disclosure, the parameter transfer method is applied to a central processing unit, a graphics processing unit, a general-purpose graphics processing unit or a neural network processor.
[0018] At least one embodiment of the present disclosure provides a parameter passing method, which is applied to a parameter transmitting party, comprising: transmitting parameters based on preset rules, wherein the preset rules include: determining a target storage unit corresponding to the callee parameter based on a mapping relationship between a caller and a callee, thereby obtaining a parameter value corresponding to the callee parameter from the target storage unit.
[0019] At least one embodiment of the present disclosure provides a parameter passing method, which is applied to a parameter receiver, comprising: receiving parameters based on preset rules, wherein the preset rules include: determining a target storage unit corresponding to the callee parameter based on a mapping relationship between a caller and a callee, thereby obtaining a parameter value corresponding to the callee parameter from the target storage unit.
[0020] At least one embodiment of the present disclosure provides a parameter passing device, which includes: a mapping module, configured to establish a mapping relationship between a caller and a callee, wherein the mapping relationship includes a parameter mapping and a storage mapping; and an allocation module, configured to allocate a target storage unit to the callee parameter based on the mapping relationship.
[0021] At least one embodiment of the present disclosure provides a processor, including the parameter transfer device provided by at least one embodiment above.
[0022] At least one embodiment of the present disclosure provides an electronic device, comprising at least one processor; and 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 parameter transfer method provided in at least one embodiment above. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] 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, but are not intended to limit the present disclosure.
[0024] Figure 1A It is a schematic diagram of a parameter passing method;
[0025] Figure 1B A flow chart of a parameter transfer method provided for at least one embodiment of the present disclosure;
[0026] Figure 2A A flowchart of an example of a parameter transfer method provided by at least one embodiment of the present disclosure;
[0027] Figure 2B A schematic diagram of an example of a parameter transfer method provided by at least one embodiment of the present disclosure;
[0028] Figure 2C A schematic diagram of an example of a parameter transfer method provided by at least one embodiment of the present disclosure;
[0029] Figure 2D A flowchart of an example of a parameter transfer method provided by at least one embodiment of the present disclosure;
[0030] Figure 2E A schematic diagram of an example of a parameter transfer method provided by at least one embodiment of the present disclosure;
[0031] Figure 3A A schematic diagram of an example of a parameter transfer method provided by at least one embodiment of the present disclosure;
[0032] Figure 3B A schematic diagram of an example of a parameter passing method;
[0033] Figure 4A A schematic diagram of an example of a parameter transfer method provided by at least one embodiment of the present disclosure;
[0034] Figure 4B A schematic diagram of an example of a parameter passing method;
[0035] Figure 5 A flowchart of another parameter transfer method provided for at least one embodiment of the present disclosure
[0036] Figure 6 A flowchart of another parameter transfer method provided for at least one embodiment of the present disclosure;
[0037] Figure 7 A schematic block diagram of a parameter transfer device provided for at least one embodiment of the present disclosure;
[0038] Figure 8 A schematic block diagram of a processor provided for at least one embodiment of the present disclosure;
[0039] Fig. 9 A schematic block diagram of an electronic device provided for at least one embodiment of the present disclosure; and
[0040] Fig.10 A schematic block diagram of another electronic device provided for at least one embodiment of the present disclosure. DETAILED DESCRIPTION
[0041] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution 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.
[0042] Unless otherwise defined, the technical terms or scientific terms used in the present disclosure should be understood by people with ordinary skills in the field to which the present disclosure belongs. The "first", "second" and similar words used in the present disclosure do not indicate any order, quantity or importance, but are only used to distinguish different components. "Include" or "comprise" and similar words mean that the elements or objects appearing before the word cover the elements or objects listed after the word and their equivalents, without excluding other elements or objects. "Connect" or "connected" and similar words are not limited to physical or mechanical connections, but can 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 described object changes, the relative positional relationship may also change accordingly.
[0043] The present disclosure is described below through several specific embodiments. In order to keep the following description of the embodiments of the present disclosure clear and concise, detailed descriptions of known functions and known components (elements) may be omitted. When any component (component) of the embodiments of the present disclosure appears in more than one drawing, the component (component) is represented by the same or similar reference numeral in each drawing.
[0044] Figure 1A This is a schematic diagram of a parameter passing method. Figure 1A As shown, the caller and the callee are both functions, and the caller passes parameters Arg0~Arg5 to the callee.
[0045] In order to support data transfer between functions, the hardware architecture needs to agree on fixed storage units for transferring data, such as registers or stacks. For example, registers can be used to pass parameters of basic types or simple aggregate types; stacks can be used to pass the remaining parameters that exceed the register size, or parameters of larger aggregate types. For example, in a 32-bit system, the stack is used to pass parameters; in a 64-bit system, when the number of parameters is small (usually less than or equal to 6), registers are used to pass parameters, and when the number of parameters exceeds the number of available registers (that is, more than 6), the excess is passed through the stack.
[0046] like Figure 1A As shown, in the caller, the parameters Arg0~Arg2 are stored in registers R0~R2 in sequence, and the parameters Arg3~Arg5 are stored in the stack in sequence. The stack also stores the local variables of the caller and the callee. When the callee function uses the parameters arg0~arg5, the data is read from registers R0~R2 and assigned to the parameters arg0~arg2 respectively, and the data is read from the corresponding position of the stack and assigned to the parameters arg3~arg5 respectively. After the parameter transfer is completed, the parameters arg0~arg5 can be used in the callee for subsequent data processing and other operations.
[0047] The inventors of the present disclosure have noticed that the above method has two drawbacks.
[0048] First, in multi-layer function calls, parameter passing will lead to frequent data copying and increase the usage of additional storage space resources.
[0049] For example, an example of a caller function and a callee function is represented by the following code, where the caller function is the caller and the callee function is the callee:
[0050] void caller(Arg0, Arg1, Arg2, Arg3) {
[0051] callee(Arg3, Arg2, Arg1, Arg0);
[0052] }
[0053] void callee(arg0, arg1, arg2, arg3) {
[0054] / / Use parameters arg0~arg3
[0055] }
[0056] For example, the caller parameters Arg0, Arg1, Arg2 and Arg3 are stored in registers R0, R1, R2 and the stack respectively. In the process of passing parameters from the caller to the callee, the following steps A1 to A5 are required.
[0057] Step A1: Read the value of Arg0 from register R0 and copy it to the stack.
[0058] Step A2: Read the value of Arg1 from register R1 and copy it into register R4.
[0059] Step A3: Read the value of Arg2 from register R2 and copy it into register R1.
[0060] Step A4: Read the value of Arg3 from the stack and copy it to register R0.
[0061] Step A5: Read the value of Arg1 from register R4 and copy it to register R2.
[0062] When the callee uses parameters arg0~arg3, data is read from registers R0, R1, R2 and the stack and assigned to parameters arg0~arg3 respectively. Therefore, taking the process of passing the caller parameter Arg0 to the callee parameter arg3 as an example, it goes through the complex process of reading register R0, storing on the stack, and retrieving from the stack. Multiple read and write operations consume additional computing resources. Taking the process of passing the caller parameter Arg1 to the callee parameter arg2 as an example, it goes through the complex process of reading register R1, writing register R4, reading register R4, and writing register R2. Register R4 is introduced to assist in the reallocation of parameters, which increases the occupancy of additional storage space resources.
[0063] Second, when passing aggregate type parameters, even if the callee only uses some members of the aggregate later, data of all members of the aggregate needs to be copied, resulting in unnecessary resource consumption.
[0064] Another example of caller function and callee function is shown in the following code, where caller function is the caller and callee function is the callee:
[0065] struct AggT{
[0066] f0;
[0067] f1;
[0068] };
[0069] void caller(AggT Agg) {
[0070] callee(Arg0, Agg);
[0071] }
[0072] void callee(arg0, AggT agg) {
[0073] / / Only use agg.f0
[0074] }
[0075] For example, the caller parameter Agg of the aggregate type is stored in registers R0~R1, register R0 contains the value of Agg.f0, and register R1 contains the value of Agg.f1. In the process of passing parameters from the caller to the callee, the following steps B1~B3 are required.
[0076] Step B1: Read the value of Agg.f1 from register R1 and copy it to register R2.
[0077] Step B2: Read the value of Agg.f0 from register R0 and copy it to register R1.
[0078] Step B3: Read the value of the global variable Arg0 from the static storage area and copy it to register R0.
[0079] In the above transfer process, even if the called function only uses the agg.f0 member later, the instance Agg of the entire aggregate AggT (including Agg.f1) still needs to participate in the copy process, which leads to unnecessary resource consumption. Especially for large aggregates, this full copy will significantly increase the burden on memory and processors, affecting program efficiency.
[0080] At least one embodiment of the present disclosure provides a parameter passing method, which includes: establishing a mapping relationship between a caller and a callee, the mapping relationship including parameter mapping and storage mapping; and allocating a target storage unit for the callee parameter based on the mapping relationship.
[0081] At least one embodiment of the present disclosure provides a parameter transfer method that simplifies the parameter transfer process by establishing a mapping relationship between the caller and the callee, and assigning a target storage unit to the callee parameter based on the mapping relationship, thereby reducing the copying of data between different storage units and the occupation of additional storage resources. For parameters of the aggregate type, only some members of the aggregate that need to be used can be transferred without transferring the entire aggregate, thereby improving efficiency and reducing resource waste.
[0082] Figure 1B A flow chart of a parameter transfer method provided by at least one embodiment of the present disclosure. Figure 1B As shown, the parameter transfer method provided by at least one embodiment of the present disclosure includes the following steps S110-S120.
[0083] Step S110: establishing a mapping relationship between the caller and the callee, the mapping relationship including parameter mapping and storage mapping.
[0084] For example, in step S110, the caller may be a function that actively calls another function (i.e., the callee) during execution, requests the callee to perform a specific task by passing the function name and necessary parameters, and then waits for the callee to complete the execution and possibly return a result, and then continues to execute its subsequent code. The callee may be a function that is requested by other functions (callers) to perform a specific function. The callee receives parameters from the caller, executes its own internally defined tasks, and may return a result to the caller.
[0085] For example, the parameter transfer method proposed in at least one embodiment of the present disclosure can support a parameter transfer method across multiple layers of functions. For example, the caller and the callee have the same parameters.
[0086] For example, parameter mapping can be a mapping of caller parameters to callee parameters, or a mapping of callee parameters to caller parameters. Parameter mapping can also be a mapping of part of caller parameters to callee parameters. For example, when the type of the caller parameter is an aggregate type (such as a structure or a class object), the parameter mapping can be a mapping of some members in the aggregate to the callee parameters. For example, a parameter mapping table can be established to record, for each caller parameter, the identifier of the caller parameter and the identifier of its corresponding callee parameter. This parameter mapping table can be dynamically generated or statically defined, depending on specific needs and environment. The identifier can be an address, index, name, type tag, or any other unique identifier, as long as the corresponding parameter can be found based on the identifier.
[0087] For example, the storage mapping may be a mapping of the caller parameters to the storage units where they are stored. For example, a storage mapping table may be established, and for each caller parameter, the identifier of the caller parameter and the identifier of the storage unit where it is stored are recorded. Such a storage mapping table may be dynamically generated or statically defined, depending on specific needs and circumstances. The identifier may be an address, an index, a name, a type tag, or any other unique identifier, as long as the corresponding parameter and storage unit can be found according to the identifier.
[0088] Step S120: allocating a target storage unit for the callee parameter based on the mapping relationship.
[0089] For example, in step S120, a target storage unit is directly allocated for the callee parameter according to the parameter mapping and the storage mapping, so that the parameter value or corresponding data of the callee parameter can be directly obtained from the target storage unit, reducing the copying of data between storage units.
[0090] For example, the storage unit can be a register, a stack, a heap, a global memory, a shared memory, a constant memory, etc., depending on specific needs and environments, and the embodiments of the present disclosure do not limit this. The target storage unit is the storage unit to which the callee parameter should ultimately be allocated, and data can be directly read from the target storage unit and assigned to the callee parameter.
[0091] For example, the parameter transfer method provided by at least one embodiment of the present disclosure can be applied to a central processing unit (CPU), a graphics processing unit (GPU), a general-purpose graphics processing unit (GPGPU), or a neural-network processing unit (NPU).
[0092] For example, the execution subject of the parameter transfer method provided in at least one embodiment of the present disclosure may be a compiler. The compiler may be integrated into a variety of electronic devices, including but not limited to personal computers, workstations, servers, and even embedded systems and mobile devices. Through this intelligent compiler technology integrated into electronic devices, developers do not need to manually adjust the code to optimize parameter transfer, which significantly improves development efficiency and the running performance of the final application, especially in scenarios that rely on large amounts of data processing and parallel computing.
[0093] In at least one embodiment of the present disclosure, an example of step S110 includes the following step S210.
[0094] Step S210: establishing a first mapping relationship between caller parameters and callee parameters.
[0095] For example, the first mapping relationship represents the parameter correspondence relationship between the caller parameters and the callee parameters.
[0096] In at least one embodiment of the present disclosure, an example of step S210 includes the following step S211.
[0097] Step S211: Based on the data flow analysis technology, analyze and record the first mapping relationship between the caller parameters and the callee parameters.
[0098] For example, the first mapping relationship represents parameter mapping. The concept of parameter mapping can be referred to the above description, which will not be repeated here.
[0099] For example, data flow analysis technology includes forward data flow analysis and reverse data flow analysis. Forward data flow analysis refers to data flow analysis from caller parameters to corresponding callee parameters, and reverse data flow analysis refers to data flow analysis from callee parameters to corresponding caller parameters.
[0100] For example, the reverse data flow analysis includes: tracing the data source path of the callee parameter to obtain the corresponding caller parameter. For example, for each parameter in the callee parameter, tracing its data source path until finding its corresponding caller parameter.
[0101] For example, the forward data flow analysis includes: tracing the data transfer path of the caller parameters to obtain the corresponding callee parameters. For example, for each parameter in the caller parameters, tracing its data transfer path until finding its corresponding callee parameter.
[0102] It should be noted that the above-mentioned forward data flow analysis and reverse data flow analysis can be used independently or in combination, and the embodiments of the present disclosure do not limit this.
[0103] For example, the first mapping relationship includes a complete mapping relationship and a partial mapping relationship.
[0104] For example, a complete mapping relationship indicates a correspondence relationship between complete caller parameters and callee parameters, and a partial mapping relationship indicates a correspondence relationship between a portion of caller parameters and callee parameters.
[0105] For example, the scenario corresponding to the complete mapping relationship is that the caller passes a certain caller parameter completely to the callee, and the scenario corresponding to the partial mapping relationship is that the caller passes part of a certain caller parameter to the callee. For example, when the type of the caller parameter is an aggregate type (such as a structure or class object), the partial mapping relationship can refer to the mapping of some members in the aggregate to the callee parameter.
[0106] For example, based on the result of the data flow analysis, for each callee parameter, it can be determined whether the callee parameter is derived from a complete caller parameter or from a part of a caller parameter.
[0107] Figure 2A A flowchart of an example of a parameter transfer method provided by at least one embodiment of the present disclosure. For example, Figure 2A This is a specific example of step S211 provided in at least one of the above embodiments.
[0108] For example, Figure 2A As shown, for each callee parameter, the following steps S2101 to S2105 are executed.
[0109] Step S2101: Based on the result of data flow analysis, determine whether the callee parameter is derived from a complete caller parameter. If so, execute step S2102; if not, execute step S2103.
[0110] Step S2102: Record the complete mapping relationship between the callee parameters and the corresponding caller parameters.
[0111] For example, the complete mapping relationship can be in the form of<CalleeArg,CallerArg> , CalleeArg is the identifier of the callee parameter, CallerArg is the identifier of the caller parameter, and the identifier can be an address, index, name, type tag or any other unique identifier. It should be noted that the above complete mapping relationship is only an example, and it can also be other forms that can reflect the parameter correspondence relationship, and the embodiments of the present disclosure are not limited to this.
[0112] Step S2103: Based on the result of data flow analysis, determine whether the callee parameter is derived from a part of a caller parameter. If so, execute step S2104; if not, execute step S2105.
[0113] Step S2104: Record a partial mapping relationship between the callee parameters and the corresponding caller parameters.
[0114] For example, the form of some mapping relations can be<CalleeArg,CallerArg+Offset> , where Offset represents the offset from the starting position of the caller parameter to the corresponding part of the callee parameter, and the offset may vary due to the parameter size and the alignment rules of a specific compiler or compilation platform. It should be noted that the form of the above partial mapping relationship is only an example, and it can also be other forms that can reflect the parameter correspondence relationship, and the embodiments of the present disclosure are not limited to this.
[0115] Step S2105: confirm that there is no mapping relationship between the callee parameter and the caller parameter, and do not record it.
[0116] Figure 2B A schematic diagram of an example of a parameter transfer method provided by at least one embodiment of the present disclosure. For example, Figure 2B for Figure 2A A specific example of steps S2101~S2105 shown.
[0117] like Figure 2B As shown, it is assumed that according to data flow analysis, it has been obtained that the callee parameter arg0 comes from the caller parameter Agg.f1, the callee parameter arg1 comes from the caller parameter Agg.f0, the callee parameter arg2 comes from the caller parameter Arg0, and the callee parameter arg3 comes from a part of the caller parameter Agg2.
[0118] For example, Figure 2BAs shown, for the callee parameter arg2, step S2101 is executed to determine that the callee parameter arg2 is derived from the complete caller parameter Arg0 according to the result of data flow analysis. Step S2102 is executed to record the complete mapping relationship<arg2,Arg0> The same is true for the callee parameters arg0 and arg1, and the complete mapping relationship can be obtained respectively.<arg0,Agg.f1> and<arg1,Agg.f0> .
[0119] For example, Figure 2B As shown, for the callee parameter arg3, step S2101 is executed. According to the result of data flow analysis, it is determined that the callee parameter arg3 does not come from a complete caller parameter, so step S2103 is executed. According to the result of data flow analysis, it is determined that the callee parameter arg3 comes from a part of the caller parameter Agg2. Step S2104 is executed to record the partial mapping relationship<arg3,Agg2+offset> .
[0120] In the parameter passing method provided in the embodiment of the present disclosure, through data flow analysis, the compiler can determine which parameter values will be actually used in the function call, thereby avoiding copying and passing parameters that are not needed inside the called function, effectively reducing the consumption of storage space and processor resources.
[0121] In at least one embodiment of the present disclosure, an example of step S110 further includes the following step S220.
[0122] Step S220: Establish a second mapping relationship between the caller parameter and the storage unit.
[0123] For example, the second mapping relationship represents a storage correspondence relationship between the caller parameter and the storage unit.
[0124] In at least one embodiment of the present disclosure, an example of step S220 includes the following steps S221 to S222.
[0125] Step S221: Obtain the storage unit where the caller parameters are stored.
[0126] Step S222: Record the second mapping relationship between the caller parameter and the storage unit.
[0127] For example, for each caller parameter, steps S221 to S222 are executed to query the storage unit where the caller parameter is stored, and the corresponding relationship between the caller parameter and the storage unit is recorded.
[0128] For example, the second mapping relationship represents storage mapping. The concept of storage mapping can be referred to the above description, which will not be repeated here.
[0129] For example, the second mapping relationship can be in the form of<CallerArg,Regs / Stack> , CalleeArg is the identifier of the callee parameter, Regs / Stack is the identifier of the storage unit where the caller parameter is stored, and the identifier can be an address, index, name, type tag or any other unique identifier. It should be noted that the form of the above second mapping relationship is only an example, and it can also be other forms that can reflect the storage correspondence relationship, and the embodiments of the present disclosure are not limited to this.
[0130] Figure 2C A schematic diagram of an example of a parameter transfer method provided by at least one embodiment of the present disclosure. For example, Figure 2C This is a specific example of the above steps S221~S222.
[0131] like Figure 2C As shown, the caller parameters include Arg0, Agg.f0, Agg.f1, Agg2.f0, Agg2.f1, and Agg2.f2.
[0132] For example, for the caller parameter Arg0, execute step S221 to obtain the storage unit where the caller parameter Arg0 is stored as register R0, and execute step S222 to record the second mapping relationship between the caller parameter Arg0 and register R0.<Arg0,R0> .
[0133] For example, for the caller parameter Agg2.f2, execute step S221 to obtain the storage unit where the caller parameter Agg.f2 is stored as stack frame Stack Frame 2, and execute step S222 to record the second mapping relationship between the caller parameter Agg.f2 and the stack frame Stack Frame2.<Agg.f2,Stack Frame 2> .
[0134] The above are just two examples. The other caller parameters Agg.f0, Agg.f1, Agg2.f0 and Agg2.f1 are similarly processed through the above steps S221 to S222 to obtain the second mapping relationship.<Agg.f0,R1> ,<Agg.f1,R2> ,<Agg2.f0,Stack Frame 0> and<Agg2.f1,Stack Frame 1> .
[0135] In at least one embodiment of the present disclosure, an example of step S110 further includes the following step S230.
[0136] Step S230: Update the second mapping relationship.
[0137] In step S220, a second mapping relationship is established. However, as the instructions in the caller are executed, the storage unit recorded in the second mapping relationship may be modified. In order to avoid the possible mapping relationship inconsistency problem, the second mapping relationship can be dynamically updated. It should be noted that different hardware architectures have different access rights (such as read-only, read-write) to the storage unit. For example, when the storage unit is a read-only unit, it will not be modified, and step S230 does not need to be executed.
[0138] In at least one embodiment of the present disclosure, an example of step S230 includes the following steps S231 - S232 .
[0139] Step S231: Analyze each instruction from the caller entry to the call point, and check whether the storage unit recorded in the second mapping relationship has been rewritten with data.
[0140] Step S232: In response to the existence of a storage unit in which data is rewritten, deleting the record corresponding to the storage unit in which the data is rewritten in the second mapping relationship.
[0141] For example, caller entry refers to the location where the caller begins execution, and call site refers to the location in the caller where the call to the callee function occurs.
[0142] For example, in step S231, starting from the first instruction of the caller, it is determined whether the storage unit operated by the instruction is rewritten with data until the location where the callee function is called occurs.
[0143] For example, in step S232, if the instruction is a write operation or a read-write operation on a storage unit, it is determined that data is rewritten to the storage unit, and the record corresponding to the storage unit in the second mapping relationship is deleted.
[0144] Figure 2D A flowchart of an example of a parameter transfer method provided by at least one embodiment of the present disclosure. For example, Figure 2D This is a specific example of steps S231 - S232 provided in at least one of the above embodiments.
[0145] For example, Figure 2D As shown, the example includes the following steps S2301~S2305.
[0146] Step S2301: Get the first instruction of the caller.
[0147] Step S2302: Determine whether the storage unit operated by the instruction has been rewritten with data, if so, execute step S2303, if not, execute step S2404.
[0148] Step S2303: Delete the record corresponding to the storage unit in the second mapping relationship.
[0149] Step S2304: Get the next instruction.
[0150] Step S2305: Determine whether the instruction is a call point, if so, end the operation, if not, return to execute step S2302.
[0151] For example, the following is an example of a parameter transfer method provided by at least one embodiment of the present disclosure, that is, a specific example of the above steps S2301 to S2305.
[0152] For example, an example of the caller function is represented by the following code, where the caller function is the caller and the callee function is the callee. First, registers R0 and R1 are read and modified respectively, and then the callee function is called:
[0153] void caller(Arg0, Agg, Agg2) {
[0154] / / Instruction 1: Read register R0
[0155] / / Instruction 2: Modify register R1
[0156] / / ......
[0157] callee (Agg.f1, Agg.f0, Arg0, Agg2.f1);
[0158] }
[0159] For the above caller, it is assumed that the second mapping relationship established in step S220 is as follows:
[0160] <Arg0,R0>
[0161] <Agg.f0,R1>
[0162] <Agg.f1,R2>
[0163] <Agg2.f0,Stack Frame 0>
[0164] <Agg2.f1,Stack Frame 1>
[0165] <Agg2.f2,Stack Frame 2>
[0166] For example, execute step S2301 to obtain the first instruction of the caller function (instruction 1). Execute step S2302 to determine whether the register R0 operated by instruction 1 has been rewritten. Since instruction 1 only involves a read operation, the register R0 has not been rewritten. Execute step S2304 to obtain the next instruction (instruction 2). Execute step S2305 to determine whether instruction 2 is a call point. Since the call point, that is, the callee (Agg.f1, Agg.f0, Arg0, Agg2.f0) instruction, has not been reached, return to execute step S2302 to determine whether the register R1 operated by instruction 2 has been rewritten. Since instruction 2 involves a modification operation, the register R1 has been rewritten. Execute step S2303 to delete the record corresponding to register R1 in the second mapping relationship, that is<Agg.f0,R1> . Execute step S2304 to continue to obtain the next instruction. Repeat the above operation until the call point is reached and the operation ends.
[0167] If in the above example, only the storage unit operated by instruction 2 is rewritten with data, the updated second mapping relationship is as follows:
[0168] <Arg0,R0>
[0169] <Agg.f1,R2>
[0170] <Agg2.f0,Stack Frame 0>
[0171] <Agg2.f1,Stack Frame 1>
[0172] <Agg2.f2,Stack Frame 2>
[0173] The parameter transfer method provided by at least one embodiment of the present disclosure implements dynamic management of the second mapping relationship by updating the second mapping relationship, thereby ensuring the accuracy of parameter transfer.
[0174] In at least one embodiment of the present disclosure, an example of step S120 includes the following steps S310 to S320.
[0175] Step S310: Based on the first mapping relationship, determine the target caller parameter corresponding to the callee parameter.
[0176] Step S320: Based on the second mapping relationship, determine the target storage unit corresponding to the target caller parameter.
[0177] For example, for each callee parameter, firstly, according to the first mapping relationship, the corresponding caller parameter or part of the caller parameter is queried and obtained, and then according to the second mapping relationship, the storage unit that the callee should eventually allocate is queried and obtained.
[0178] In at least one embodiment of the present disclosure, an example of step S120 further includes the following step S330.
[0179] Step S330: Obtain parameter values corresponding to the callee parameters from the target storage unit.
[0180] For example, when the caller parameter is needed, the target storage unit can be directly accessed.
[0181] Figure 2E A schematic diagram of an example of a parameter transfer method provided by at least one embodiment of the present disclosure. For example, Figure 2E This is a specific example of the above steps S310 to S330.
[0182] For example, Figure 2E As shown, a first mapping relationship between caller parameters and callee parameters, and a second mapping relationship between caller parameters and storage units are shown.
[0183] For example, taking the callee parameter arg0 as an example, step S310 is executed, based on the first mapping relationship<arg0,Agg.f1> , determine that the target caller parameter corresponding to the callee parameter arg0 is Agg.f1. Execute step S320, based on the second mapping relationship<Agg.f1,R2> , determine that the target storage unit corresponding to the target caller parameter Agg.f1 is register R2. When the caller parameter arg0 needs to be used, execute step S330 to obtain the parameter value corresponding to the callee parameter arg0 from register R2.
[0184] For example, taking the callee parameter arg3 as an example, step S310 is executed based on the first mapping relationship<arg3,Agg2+offset> , determine that the target caller parameter corresponding to the callee parameter arg3 is Agg2.f1. Execute step S320, based on the second mapping relationship<Agg2.f1,Stack Frame 2> , determine that the target storage unit corresponding to the target caller parameter Agg2.f1 is stack frame 2. When the caller parameter arg3 needs to be used, execute step S330 to obtain the parameter value corresponding to the callee parameter arg3 from stack frame 2. The above are only two examples, and the same operation is performed for other callee parameters, which will not be repeated here.
[0185] Figure 3A A schematic diagram showing an example of a parameter transfer method provided by at least one embodiment of the present disclosure is shown. Figure 3B A schematic diagram showing an example of a parameter transfer method provided by the related art.
[0186] For example, in a heterogeneous computing architecture, the host function on the CPU side can use the API to request the GPU to execute a specific kernel function. The host function prepares the data to be passed to the kernel function and stores it in read-only memory. The kernel function is executed on the GPU's stream processor and can call the device function to perform more fine-grained operations or calculations.
[0187] An example of kernel function and device function is shown in the following code, where kernel function is the caller and device function is the callee.
[0188] void kernel(float *Arg0, float Arg1, int Arg2, char Arg3) {
[0189] device(Arg3, Arg2, Arg1, Arg0);
[0190] }
[0191] void device(char arg0, int arg1, float arg2, float *arg3) {
[0192] *arg3 = arg0 + arg1 + arg2;
[0193] }
[0194] For example, in the data preparation phase, the Host function stores the value of the caller parameter Arg0 in the read-only registers ror0-ror1, and the values of the caller parameters Arg1-Arg3 are stored in the read-only registers ror2-ror4. Based on this, the parameter transfer method provided by at least one embodiment of the present disclosure is described below.
[0195] For example, executing step S210, a first mapping relationship between caller parameters Arg0~Arg3 and callee parameters arg0~arg3 is established. Specifically, executing step S211, based on data flow analysis technology, the first mapping relationship between caller parameters Arg0~Arg3 and callee parameters arg0~arg3 is analyzed and recorded, as follows:
[0196] <arg0,Arg3>
[0197] <arg1,Arg2>
[0198] <arg2,Arg1>
[0199] <arg3,Arg0>
[0200] For example, execute step S221 to obtain the storage unit where the caller parameters Arg0-Arg3 are stored, and execute step S222 to record the second mapping relationship between the caller parameters Arg0-Arg3 and the storage unit, which is as follows:
[0201] <Arg0,ror0~ror1>
[0202] <Arg1,ror2>
[0203] <Arg2,ror3>
[0204] <Arg3,ror4>
[0205] For example, for the callee parameter arg1, step S310 is executed, based on the first mapping relationship<arg1,Arg2> , determine that the target caller parameter corresponding to the callee parameter arg1 is Arg2, execute step S320, based on the second mapping relationship<Arg2,ror3> , determine that the target storage unit corresponding to the target caller parameter Arg2 is the read-only register ror3. For example, execute step S330 to obtain the parameter value corresponding to the callee parameter arg1 from the read-only register ror3. For other callee parameters, the same steps are also adopted, which will not be repeated here.
[0206] like Figure 3A As shown in the figure, when the callee uses parameter arg1, it only needs to read data directly from the read-only register ror3 and assign it to parameter arg1. The caller does not need to be responsible for passing parameters. This method effectively avoids Figure 3B The related technology shown in the figure solves the problem of additional overhead caused by frequent data replication and improves operating efficiency.
[0207] For example, Figure 3B As shown, in the related art, taking the process of passing the caller parameter Arg2 to the callee parameter arg1 as an example, the specific process includes: reading the value of Arg2 from the read-only register ror3 and storing it in the temporary register tr0 (not shown), and then reading the value of Arg2 from the temporary register tr0 and storing it in the parameter register ar1. When the callee uses the parameter arg1, it is necessary to read the data from the parameter register ar1 and assign it to the parameter arg1. Not only does this increase the copying of data between different storage units, but it also occupies additional storage resources (such as the temporary register tr0).
[0208] Figure 4A A schematic diagram showing an example of a parameter transfer method provided by at least one embodiment of the present disclosure is shown. Figure 4BA schematic diagram showing an example of a parameter transfer method provided by the related art.
[0209] Another example of kernel function and device function is shown in the following code, where kernel function is the caller and device function is the callee.
[0210] struct SmallAgg {
[0211] float f0;
[0212] int f1;
[0213] };
[0214] struct BigAgg {
[0215] float f0;
[0216] int f1;
[0217] SmallAgg f2;
[0218] };
[0219] void kernel(float *Arg0, SmallAgg SAgg, BigAgg BAgg) {
[0220] device(Arg0, SAgg, BAgg);
[0221] }
[0222] void device(float *arg0, SmallAgg sagg, BigAgg bagg) {
[0223] *arg0 = sagg.f0 + bagg.f0 + bagg.f2.f0;
[0224] }
[0225] For example, in the data preparation stage, the Host function stores the value of the caller parameter Arg0 in the read-only registers ror0~ror1, the value of the caller parameter Agg in the read-only registers ror2~ror3, and the value of the caller parameter BAgg in the read-only registers ror4~ror7. Based on this, the parameter transfer method provided by at least one embodiment of the present disclosure is described below.
[0226] For example, execute step S210 to establish a first mapping relationship between the caller parameters Arg0~Arg3 and the callee parameters arg0~arg3. Specifically, execute step S211 to analyze and record the first mapping relationship between the caller parameters arg0, sagg.f0, bagg.f0 and bagg.f2.f0 and the callee parameters Arg0, SAgg and BAgg based on the data flow analysis technology, as follows:
[0227] <arg0,Arg0>
[0228] <sagg.f0,SAgg+offset1>
[0229] <bagg.f0,BAgg+offset2>
[0230] <bagg.f2.f0,BAgg+offset3>
[0231] For example, execute step S221 to obtain the storage unit where the caller parameters Arg0, SAgg and BAgg are stored, and execute step S222 to record the second mapping relationship between the caller parameters Arg0, SAgg and BAgg and the storage unit, which is as follows:
[0232] <Arg0,ror0~ror1>
[0233] <SAgg.f0,ror2>
[0234] <SAgg.f1,ror3>
[0235] <BAgg.f0,ror4>
[0236] <BAgg.f1,ror5>
[0237] <BAgg.f2.f0,ror6>
[0238] <BAgg.f2.f1,ror7>
[0239] For example, for the callee parameter bagg.f0, step S310 is executed, based on the first mapping relationship<bagg.f0,BAgg+offset2> , determine that the target caller parameter corresponding to the callee parameter bagg.f0 is BAgg.f0, execute step S320, based on the second mapping relationship<BAgg.f0,ror4> , determine that the target storage unit corresponding to the target caller parameter BAgg.f0 is the read-only register ror4. For example, execute step S330 to obtain the parameter value corresponding to the callee parameter bagg.f0 from the read-only register ror4. For other callee parameters, the same steps are also adopted, which will not be repeated here.
[0240] like Figure 4A As shown in the figure, when the callee uses parameter bAgg.f0, it only needs to read data directly from the read-only register ror4 and assign it to parameter bAgg.f0. This method effectively avoids Figure 4B The related technology shown needs to transfer and copy the entire aggregate BAgg, resulting in a waste of resources.
[0241] For example, Figure 4B As shown, in the related art, taking the process of passing the caller parameter BAgg to the callee parameter bAgg.f0 as an example, the specific process includes: reading the values of each member of BAgg from the read-only registers ror4~ror7 and storing them in the temporary register, and then reading the values of each member of BAgg from the temporary register and storing them in the parameter registers ar4~ar7. When the callee uses the parameter bAgg.f0, it is necessary to read the data from the parameter register ar4 and assign it to the parameter bAgg.f0. However, the data copied to ar5~ar7 does not need to be used, resulting in unnecessary resource consumption.
[0242] Figure 5 A flowchart of another parameter transfer method provided by at least one embodiment of the present disclosure, wherein the parameter transfer method is applied to a parameter transmission party. Figure 5 As shown, the parameter transfer method provided by at least one embodiment of the present disclosure includes the following step S501.
[0243] Step S501: transmitting parameters based on preset rules, the preset rules including: determining a target storage unit corresponding to the callee parameter based on a mapping relationship between the caller and the callee, thereby obtaining a parameter value corresponding to the callee parameter from the target storage unit.
[0244] For example, the specific description of the caller, the callee, the mapping relationship, and the target storage unit can refer to the content in the above embodiments, which will not be repeated here.
[0245] For example, the parameter transmission party may be the party responsible for initiating and executing the parameter transmission action during the function call, message transmission or data interaction process. For example, the parameter transmission party may be a function, a process, a hardware execution environment such as a CPU or a GPU, etc.
[0246] Figure 6 A flowchart of another parameter transfer method provided by at least one embodiment of the present disclosure, the parameter transfer method is applied to a parameter receiver. Figure 6 As shown, the parameter transfer method provided by at least one embodiment of the present disclosure includes the following step S601.
[0247] Step S601: receiving parameters based on preset rules, the preset rules including: determining a target storage unit corresponding to the callee parameter based on a mapping relationship between the caller and the callee, thereby obtaining a parameter value corresponding to the callee parameter from the target storage unit.
[0248] For example, the specific description of the caller, the callee, the mapping relationship, and the target storage unit can refer to the content in the above embodiments, which will not be repeated here.
[0249] For example, the parameter receiver may be the party that receives the parameters sent by the parameter transmitter (which may be another function, process, hardware execution environment such as CPU or GPU, etc.) during a function call, message passing, or data interaction.
[0250] Figure 7 A schematic block diagram of a parameter transfer device provided for at least one embodiment of the present disclosure.
[0251] For example, Figure 7 As shown, the parameter transfer device 700 provided by the embodiment of the present disclosure includes a mapping module 710 and an allocation module 720 .
[0252] For example, the mapping module 710 is configured to establish a mapping relationship between the caller and the callee, wherein the mapping relationship includes parameter mapping and storage mapping. Figure 1B The relevant description of step S110 is not repeated here.
[0253] For example, the allocation module 720 is configured to allocate a target storage unit for the callee parameter based on the mapping relationship. For the relevant content of the allocation module 720, reference can be made to the embodiment of the above parameter transfer method. Figure 1B The relevant description of step S120 shown is not repeated here.
[0254] For example, in at least one embodiment of the present disclosure, the mapping module 710 includes a first mapping module, which is configured to establish a first mapping relationship between caller parameters and callee parameters, wherein the first mapping relationship represents a parameter correspondence relationship between the caller parameters and the callee parameters.
[0255] For example, in at least one embodiment of the present disclosure, the first mapping module is further configured to analyze and record a first mapping relationship between caller parameters and callee parameters based on a data flow analysis technique.
[0256] For example, in at least one embodiment of the present disclosure, the data flow analysis technology includes forward data flow analysis and reverse data flow analysis. The forward data flow analysis represents data flow analysis from caller parameters to corresponding callee parameters, and the reverse data flow analysis represents data flow analysis from callee parameters to corresponding caller parameters.
[0257] For example, in at least one embodiment of the present disclosure, the reverse data flow analysis includes: tracing the data source path of the callee parameter to obtain the corresponding caller parameter.
[0258] For example, in at least one embodiment of the present disclosure, the forward data flow analysis includes: tracing the data transfer path of the caller parameters to obtain the corresponding callee parameters.
[0259] For example, in at least one embodiment of the present disclosure, the first mapping relationship includes a complete mapping relationship and a partial mapping relationship, the complete mapping relationship represents the correspondence between the complete caller parameters and the callee parameters, and the partial mapping relationship represents the correspondence between a part of the caller parameters and the callee parameters.
[0260] For example, in at least one embodiment of the present disclosure, the mapping module 710 also includes a second mapping module, which is configured to establish a second mapping relationship between the caller parameters and the storage unit, wherein the second mapping relationship represents a storage correspondence relationship between the caller parameters and the storage unit.
[0261] For example, in at least one embodiment of the present disclosure, the second mapping module includes: an acquisition unit configured to acquire a storage unit where the caller parameter is stored; and a recording unit configured to record a second mapping relationship between the caller parameter and the storage unit.
[0262] For example, in at least one embodiment of the present disclosure, the second mapping module further includes an updating unit configured to update the second mapping relationship.
[0263] For example, in at least one embodiment of the present disclosure, the update unit is further configured to analyze each instruction between the caller entry and the call point, check whether the storage unit recorded in the second mapping relationship has been rewritten with data; and in response to the existence of a storage unit with data rewritten, delete the record in the second mapping relationship corresponding to the storage unit with the data rewritten.
[0264] For example, in at least one embodiment of the present disclosure, the allocation module 720 includes: a first determination unit, configured to determine the target caller parameter corresponding to the callee parameter based on the first mapping relationship; and a second determination unit, configured to determine the target storage unit corresponding to the target caller parameter based on the second mapping relationship.
[0265] For example, in at least one embodiment of the present disclosure, the allocation module 720 further includes an assignment unit configured to obtain a parameter value corresponding to the callee parameter from the target storage unit.
[0266] For example, in at least one embodiment of the present disclosure, the caller and the callee have the same parameters.
[0267] For example, in at least one embodiment of the present disclosure, the parameter transfer device is implemented by a central processing unit, a graphics processing unit, a general-purpose graphics processing unit, or a neural network processor.
[0268] It should be noted that the above Figure 7 The various modules shown may be implemented by software, hardware, firmware or any combination thereof. For example, they may be implemented as a mapping circuit and a distribution circuit respectively. The embodiments of the present disclosure do not limit their specific implementations.
[0269] It should be understood that the parameter transfer device 700 provided in at least one embodiment of the present disclosure can be used to implement the aforementioned visual parameter transfer method, and can also achieve technical effects similar to the aforementioned parameter transfer method, which will not be elaborated herein.
[0270] It should be noted that in the embodiment of the present disclosure, the parameter transfer device 700 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 can be composed in other applicable ways.
[0271] Figure 8 A schematic block diagram of a processor provided for at least one embodiment of the present disclosure.
[0272] For example, Figure 8As shown, the processor 800 provided in the embodiment of the present disclosure includes a parameter transfer device 810. The parameter transfer device 810 may be a parameter transfer device provided in any embodiment of the present disclosure. The structure, function, and technical effect of the parameter transfer device 810 may refer to the relevant content of the parameter transfer device 700, which will not be repeated here. For example, the processor may be a single-core or multi-core central processing unit (CPU), a graphics processing unit (GPU), a general-purpose graphics processing unit (GPGPU), an artificial intelligence (AI) accelerator, etc., and the present disclosure does not limit this.
[0273] Fig. 9 A schematic block diagram of an electronic device provided for at least one embodiment of the present disclosure.
[0274] For example, Fig. 9 As shown, the electronic device 900 includes at least one processor 901 and at least one memory 902, and the memory 902 stores one or more computer program modules. The one or more computer program modules are configured to be executed by the at least one processor 901, and are used to execute the instructions of the parameter transfer method provided by at least one embodiment above. The memory 902 and the processor 901 can be interconnected through a bus system and / or other forms of connection mechanisms (not shown).
[0275] For example, the processor 901 may be a central processing unit (CPU), a digital signal processor (DSP), or other forms of processing units with data processing capabilities and / or program execution capabilities, such as a field programmable gate array (FPGA), etc.; for example, the central processing unit (CPU) may be an X86, ARM, RISC-V architecture, etc. The processor 901 may be a general-purpose processor or a dedicated processor, and may control other components in the electronic device 900 to perform desired functions.
[0276] For example, the memory 902 may include any combination of one or more computer program products, and the computer program product 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 (Cache), etc. Non-volatile memory may include, for example, read-only memory (ROM), hard disk, erasable programmable read-only memory (EPROM), portable compact disk read-only memory (CD-ROM), USB memory, flash memory, etc.
[0277] Fig.10 A schematic block diagram of another electronic device provided by at least one embodiment of the present disclosure. Fig.10As shown, the electronic device 1000 includes a processor provided by any of the above embodiments of the present disclosure, and the electronic device 1000 is suitable for implementing the parameter transfer method provided by the embodiment of the present disclosure. The electronic device 1000 may be a terminal device or a server, etc. It should be noted that, Fig.10 The electronic device 1000 shown is only an example and does not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0278] like Fig.10 As shown, the electronic device 1000 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 1001, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1002 or a program loaded from a storage device 1008 into a random access memory (RAM) 1003. For example, the processing device 1001 can be a processor provided by any of the above embodiments of the present disclosure. In the RAM 1003, various programs and data required for the operation of the electronic device 1000 are also stored. The processing device 1001, the ROM 1002, and the RAM 1003 are connected to each other via a bus 1004. An input / output (I / O) interface 1005 is also connected to the bus 1004.
[0279] Typically, the following devices may be connected to the I / O interface 1005: an input device 1006 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 1007 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 1008 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 may allow the electronic device 1000 to communicate with other electronic devices wirelessly or by wire to exchange data. Although Fig.10 The electronic device 1000 is shown to have various devices, but it should be understood that it is not required to implement or possess all the devices shown, and the electronic device 1000 may alternatively implement or possess more or fewer devices.
[0280] For the detailed description and technical effects of the electronic device 900 / 1000, please refer to the above description of the processor and parameter transfer method, which will not be repeated here.
[0281] Although the disclosure has been described in detail above with general descriptions and specific implementation methods, it is obvious to those skilled in the art that some modifications or improvements may be made to the embodiments of the disclosure. Therefore, these modifications or improvements made without departing from the spirit of the disclosure are within the scope of protection claimed by the disclosure.
[0282] There are a few points to note about this disclosure:
[0283] (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 the general design.
[0284] (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 enlarged or reduced, that is, these drawings are not drawn according to the actual scale.
[0285] (3) In the absence of conflict, the embodiments of the present disclosure and the features therein may be combined with each other to obtain new embodiments.
[0286] The above description is only a specific implementation 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 parameter passing method, performed by the compiler and applied to function calls, comprising: Establishing a mapping relationship between the caller and the callee, wherein the mapping relationship includes parameter mapping and storage mapping; and Based on the mapping relationship, a target storage unit is allocated for the callee parameter. The step of establishing a mapping relationship between the caller and the callee includes: Establishing a first mapping relationship between the caller parameter and the callee parameter, wherein the first mapping relationship represents a parameter correspondence relationship between the caller parameter and the callee parameter; and Establishing a second mapping relationship between the caller parameter and the storage unit, wherein the second mapping relationship represents a storage correspondence relationship between the caller parameter and the storage unit, The first mapping relationship includes a partial mapping relationship, and the partial mapping relationship represents a corresponding relationship between a part of the caller parameter and the callee parameter.
2. The parameter transfer method according to claim 1, wherein: The establishing of a first mapping relationship between the caller parameter and the callee parameter includes: Based on the data flow analysis technology, a first mapping relationship between the caller parameters and the callee parameters is analyzed and recorded.
3. The parameter transfer method according to claim 2, wherein: The data flow analysis technology includes forward data flow analysis and reverse data flow analysis. The forward data flow analysis refers to data flow analysis from the caller parameter to the corresponding callee parameter, and the reverse data flow analysis refers to data flow analysis from the callee parameter to the corresponding caller parameter.
4. The parameter transfer method according to claim 3, wherein: The reverse data flow analysis includes: The data source path of the callee parameter is traced to obtain the corresponding caller parameter.
5. The parameter transfer method according to claim 3, wherein: The forward data flow analysis includes: The data transfer path of the caller parameter is traced to obtain the corresponding callee parameter.
6. The parameter transfer method according to claim 1, wherein: The first mapping relationship also includes a complete mapping relationship, and the complete mapping relationship represents the corresponding relationship between the complete caller parameters and the callee parameters.
7. The parameter transfer method according to claim 1, wherein: The establishing of a second mapping relationship between the caller parameter and the storage unit includes: Obtaining the storage unit where the caller parameter is stored; A second mapping relationship between the caller parameter and the storage unit is recorded.
8. The parameter transfer method according to claim 1, wherein: The establishing of a second mapping relationship between the caller parameter and the storage unit also includes: The second mapping relationship is updated.
9. The parameter transfer method according to claim 8, wherein: The updating of the second mapping relationship includes: Analyze each instruction from the caller entry to the call point, and check whether the storage unit recorded in the second mapping relationship has been rewritten with data; and In response to a storage unit having data rewritten therein, a record in the second mapping relationship corresponding to the storage unit having data rewritten therein is deleted.
10. The parameter transfer method according to claim 1, wherein: The allocating a target storage unit for the callee parameter based on the mapping relationship includes: Based on the first mapping relationship, determining a target caller parameter corresponding to the callee parameter; and Based on the second mapping relationship, a target storage unit corresponding to the target caller parameter is determined.
11. The parameter transfer method according to claim 10, wherein: The allocating a target storage unit for the callee parameter based on the mapping relationship also includes: A parameter value corresponding to the callee parameter is obtained from the target storage unit.
12. The parameter transfer method according to any one of claims 1 to 11, wherein: The caller and the callee have the same parameters.
13. The parameter transfer method according to any one of claims 1 to 11, wherein: The parameter transfer method is applied to a central processing unit, a graphics processing unit, a general-purpose graphics processing unit or a neural network processor.
14. A parameter transfer method, applied to parameter transmission and function calling, comprising: Transmit parameters based on preset rules, The preset rules include: Determine the target storage unit corresponding to the callee parameter based on the mapping relationship between the caller and the callee, thereby obtaining the parameter value corresponding to the callee parameter from the target storage unit, The mapping relationship between the caller and the callee includes: a first mapping relationship between a caller parameter and the callee parameter, wherein the first mapping relationship represents a parameter correspondence relationship between the caller parameter and the callee parameter; and a second mapping relationship between the caller parameter and the storage unit, wherein the second mapping relationship represents a storage correspondence relationship between the caller parameter and the storage unit, The first mapping relationship includes a partial mapping relationship, and the partial mapping relationship represents a corresponding relationship between a part of the caller parameter and the callee parameter.
15. A parameter passing method, applied to a parameter receiver and a function call, comprising: Receive parameters based on preset rules, The preset rules include: Determine a target storage unit corresponding to the callee parameter based on a mapping relationship between the caller and the callee, thereby obtaining a parameter value corresponding to the callee parameter from the target storage unit, wherein the mapping relationship between the caller and the callee includes: a first mapping relationship between a caller parameter and the callee parameter, wherein the first mapping relationship represents a parameter correspondence relationship between the caller parameter and the callee parameter; and a second mapping relationship between the caller parameter and the storage unit, wherein the second mapping relationship represents a storage correspondence relationship between the caller parameter and the storage unit, The first mapping relationship includes a partial mapping relationship, and the partial mapping relationship represents a corresponding relationship between a part of the caller parameter and the callee parameter.
16. 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 parameter transfer method according to any one of claims 1 to 15.
Citation Information
Patent Citations
Parameter transmission method and device based on tree structure, equipment and medium
CN113590348A
Method and system for inter-process communication
WO2021217529A1
