Method and device for executing program and storage medium

By replacing and inserting APIs with asynchronous execution mechanisms in program execution in data centers, the problem of waste of computing resources is solved and resource utilization is improved.

CN120234062APending Publication Date: 2025-07-01HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311863856.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-12-29
Publication Date
2025-07-01

AI Technical Summary

Technical Problem

When a data center executes an API with blocking characteristics, computing resources are idle, resulting in waste of resources.

Method used

Asynchronous execution is achieved by replacing API calls with blocking features with APIs that are executed asynchronously, and inserting APIs that are waiting for results between basic statement blocks with execution order earlier than that of the API, asynchronous execution is achieved to avoid idle computing resources.

Benefits of technology

Effectively avoid or reduce the idle state of computing power resources, improve resource utilization, and reduce resource waste.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120234062A_ABST
    Figure CN120234062A_ABST
Patent Text Reader

Abstract

The invention discloses a method and device for executing a program and a storage medium, and belongs to the field of communication. The method is applied to the data center, the data center comprises a first program, the first program comprises a first API, at least one first basic statement block, a second API and a second basic statement block, the first API is used for calling a third API and indicating asynchronous execution, the third API has a blocking characteristic, the second API is used for waiting for receiving an execution result returned by the third API, and the second API is used for receiving the execution result returned by the second API. The second basic statement block needs to execute the result. The method comprises the following steps: executing a first API (Application Program Interface) to call a third API; in response to asynchronous execution indicated by the first API, executing the at least one first basic statement block; after the at least one first basic statement block is executed, executing the second API to receive an execution result returned by the third API; and executing the second basic statement block based on the execution result. The method and the device can avoid or reduce computing power waste.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of communications, and in particular, to a method, apparatus, and storage medium for executing a program. Background Art

[0002] A program often includes multiple basic statement blocks. When a data center executes a program, it executes the multiple basic statement blocks in the execution order among the multiple basic statement blocks.

[0003] Among the multiple basic statement blocks, there may be a target basic statement block with a function call having a blocking semantics. The target basic statement block needs to call an application programming interface (API) with a blocking feature. After the API with a blocking feature is called, the API needs to execute for a period of time before returning an execution result to the target basic statement block. Therefore, when the data center executes the target basic statement block, it first calls the API, then waits for a period of time to receive the execution result returned by the API, and then executes the next basic statement block after the target basic statement block.

[0004] During the period when the data center waits for the API to return the execution result, the computing power resources used to execute the program in the data center are in an idle state, wasting computing power. Summary of the Invention

[0005] This application provides a method, apparatus, and storage medium for executing a program to avoid or reduce waste of computing power. The technical solutions are as follows:

[0006] In a first aspect, this application provides a method for executing a program. The method is applied to a data center. The data center includes a first program. The first program includes a first application programming interface API, at least one first basic statement block, a second API, and a second basic statement block. The execution order of the first API is earlier than that of at least one first basic statement block. The execution order of at least one first basic statement block is earlier than that of the second API. The execution order of the second API is earlier than that of the second basic statement block. The first API is used to call a third API and indicate asynchronous execution. The third API is an API with a blocking feature. The second API is used to wait to receive the execution result returned by the third API. The second basic statement block requires the execution result. In the method, the first API is executed to call the third API. In response to the asynchronous execution indicated by the first API, at least one first basic statement block is executed. After executing at least one first basic statement block, the second API is executed to receive the execution result returned by the third API. The second basic statement block is executed based on the execution result.

[0007] Since executing the first API can call the third API and, in response to the asynchronous execution indicated by the first API, execute at least one first basic statement block, and after executing the at least one first basic statement block, execute the second API to receive the execution result returned by the third API. In this way, during the period of waiting to receive the execution result, the at least one first basic statement block can be executed, thereby avoiding the computing power resources for executing the first program from being idle and avoiding waste of computing power; or reducing the time during which the computing power resources for executing the first program are idle and reducing waste of computing power.

[0008] In a possible implementation, the data center includes a second program to be executed. The second program includes a third basic statement block, at least one first basic statement block, and a second basic statement block. The execution order of the third basic statement block is earlier than that of the at least one first basic statement block, and the execution order of the at least one first basic statement block is earlier than that of the second basic statement block. The third basic statement block is used to call the third API and wait to receive the execution result returned by the third API. Replace the third basic statement block included in the second program with the first API, and insert the second API between the at least one first basic statement block and the second basic statement block to obtain the first program. This ensures that when executing the first program, the at least one first basic statement block can be executed during the period of waiting to receive the execution result.

[0009] In another possible implementation, obtain the logical structure of the second program, which is used to describe the multiple basic statement blocks included in the second program and the relationships between the multiple basic statement blocks. Obtain the configuration file of the second program, which is used to describe the target basic statement block of the function call with blocking semantics in the second program. The target basic statement block is used to call the API with blocking characteristics and wait to receive the execution result returned by the API. Based on the configuration file, use the target basic statement block in the second program as the third basic statement block. Based on the logical structure, obtain the basic statement block that has a dependency relationship with the third basic statement block as the second basic statement block. Thus, the target basic statement block can be accurately identified through the configuration file, and the second basic statement block that requires the execution result can be accurately identified through the logical structure.

[0010] In another possible implementation, the logical structure is the abstract syntax tree AST of the second program or the low-level virtual machine intermediate representation LLVM IR of the second program.

[0011] In another possible implementation, during the compilation of the second program, replace the third basic statement block included in the second program with the first API, and insert the second API between the at least one first basic statement block and the second basic statement block to obtain the first program.

[0012] In another possible implementation, the first program is machine code in binary format.

[0013] In a second aspect, the present application provides an apparatus for executing a program, which is used to execute the method in the first aspect or any possible implementation manner of the first aspect. Specifically, the apparatus includes units for executing the method in the first aspect or any possible implementation manner of the first aspect.

[0014] In a third aspect, the present application provides a cluster of computing devices, where the cluster of computing devices includes at least one computing device, each device in the at least one computing device includes at least one processor and at least one memory, and computer-readable instructions are stored in the at least one memory; the at least one processor executes the computer-readable instructions so that the cluster of computing devices executes the method in the first aspect or any possible implementation manner of the first aspect.

[0015] In a fourth aspect, the present application provides a computer program product, where the computer program product includes a computer program stored in a computer-readable storage medium, and the computer program is loaded by a processor to implement the method in the first aspect or any possible implementation manner of the first aspect.

[0016] In a fifth aspect, the present application provides a computer-readable storage medium for storing a computer program, and the computer program is loaded by a processor to execute the method in the first aspect or any possible implementation manner of the first aspect.

[0017] In a sixth aspect, the present application provides a chip, which includes a memory and a processor. The memory is used to store computer instructions, and the processor is used to call and run the computer instructions from the memory to execute the method in the first aspect or any possible implementation manner of the first aspect. Description of the Drawings

[0018] Figure 1 is a schematic diagram of a network architecture provided by an embodiment of the present application;

[0019] Figure 2 is a schematic diagram of a program provided by an embodiment of the present application;

[0020] Figure 3 is a schematic diagram of a serial execution program provided by an embodiment of the present application;

[0021] Figure 4 is a schematic diagram of a parallel execution program provided by an embodiment of the present application;

[0022] Figure 5 is a flowchart of a method for executing a program provided by an embodiment of the present application;

[0023] Figure 6 is another program schematic diagram provided by an embodiment of the present application;

[0024] Figure 7 is a schematic diagram of a logical structure for obtaining a second program provided by an embodiment of the present application;

[0025] Figure 8 is another program schematic diagram provided by an embodiment of the present application;

[0026] Figure 9 is a schematic diagram of a device structure for executing a program provided by an embodiment of the present application;

[0027] Figure 10 is a schematic diagram of a computing device provided by an embodiment of the present application;

[0028] Figure 11 is a schematic diagram of a computing device cluster provided by an embodiment of the present application;

[0029] Figure 12 is another schematic diagram of a computing device cluster provided by an embodiment of the present application. Detailed implementation manners

[0030] The following concepts appearing in the present application are introduced:

[0031] A first program and a second program. The second program is a program written by a user, and the first program is a program obtained by compiling the second program.

[0032] A first basic statement block, a second basic statement block, and a third basic statement block are three basic statement blocks in the second program. The execution order of the third basic statement block is earlier than that of the first basic statement block, and the execution order of the first basic statement block is earlier than that of the second basic statement block. The third basic statement block is the target basic statement block of a function call with a blocking semantics in the second program. The second basic statement block is a basic statement block that has a dependency relationship with the third basic statement block, and there is no dependency relationship between the third basic statement block and the first basic statement block.

[0033] A first API, a second API, and a third API. The third API is an API with a blocking feature. The first API is an API for calling the third API and indicating asynchronous execution. The second API is an API for waiting to receive the execution result returned by the third API.

[0034] See Figure 1, an embodiment of the present application provides a network architecture 100. The network architecture 100 includes a data center 101 and a terminal device 102, and the data center 101 communicates with the terminal device 102.

[0035] A user can write a second program on the terminal device 102 using a programming language. The terminal device 102 obtains the second program and sends the second program to the data center 101. The data center 101 receives the second program, compiles the second program to obtain a first program. The first program is machine code in binary format, and then the first program can be executed.

[0036] The format of the first program is different from that of the second program. The second program is a user-oriented program, and the format of the second program is a format that can be recognized by the user. The first program is a machine-oriented program, and the format of the first program is a binary format that can be recognized by the machine.

[0037] The first program (or the second program) includes multiple basic statement blocks. The data center 101 executing the first program means that the data center 101 executes the multiple basic statement blocks based on the execution order between the multiple basic statement blocks.

[0038] For example, referring to Figure 2 the first program shown, the first program includes basic statement block 1, basic statement block 2, basic statement block 3, basic statement block 4, basic statement block 5, and basic statement block 6. Basic statement block 1 is a judgment basic statement block. When the data center 101 executes basic statement block 1, it makes a judgment and executes basic statement block 2 or basic statement block 3 based on the judgment result.

[0039] Suppose the data center 101 executes basic statement block 2 and ends the execution after executing basic statement block 2. Suppose the data center 101 executes basic statement block 3. After executing basic statement block 3, it executes basic statement block 4. After executing basic statement block 4, it executes basic statement block 5. After executing basic statement block 5, it executes basic statement block 6. After executing basic statement block 6, it ends the execution.

[0040] In some embodiments, among the multiple basic statement blocks included in the first program, there may be a target basic statement block with a function call having a blocking semantics. The target basic statement block is used to call an API with a blocking feature and wait for the API to return an execution result.

[0041] A so-called API with blocking characteristics means that after the API is called in the target basic statement block, it takes some time for the API to produce an execution result and return the execution result to the target basic statement block. Therefore, after the target basic statement block calls an API with blocking characteristics, it will not immediately receive the execution result returned by the API, but will wait for some time before receiving the execution result returned by the API.

[0042] Among them, the period of time during which the API executes is called the blocking time, and the computing power resources used to execute the API are different from the computing power resources used to execute the first program. For example, the device used to execute the API and the device used to execute the first program are two different devices, and these two devices may be devices in data center 101.

[0043] For example, network communication APIs usually have blocking characteristics. After the target basic statement block calls a network communication API, the network communication API starts to transmit data. The process of transmitting data is as follows: the network communication API sends a request for transmitting data to the communication peer, waits for the communication peer to respond after sending the request for transmitting data, and only returns the execution result to the target basic statement block after the communication peer responds. Among them, it may take a long time from when the target basic statement block calls the network communication API to when the target basic statement block receives the execution result returned by the network communication API. That is to say, after the target basic statement block calls the network communication API, it needs to wait for a long time before receiving the execution result returned by the network communication API, that is, the blocking time is a long time.

[0044] After data center 101 finishes executing the target basic statement block, it will execute the next basic statement block whose execution order is later than that of the target basic statement block. When data center 101 executes the target basic statement block, the target basic statement block starts to call an API with blocking characteristics and then waits for the API to return the execution result. Therefore, during the period when the target basic statement block waits for the API to return the execution result, the computing power resources used to execute the first program included in data center 101 are in an idle state, wasting the computing power of data center 101.

[0045] For example, as Figure 2 shown, assume that basic statement block 3 is used to call an API with blocking characteristics and wait for the API to return the execution result. Refer to Figure 3 , the judgment result obtained by data center 101 when executing basic statement block 1 is that basic statement block 3 needs to be executed. When data center 101 executes basic statement block 3, basic statement block 3 calls the API and then waits for the API to return the execution result, and this waiting time is called the blocking time.

[0046] After receiving the execution result returned by the API based on statement block 3, data center 101 executes basic statement block 4. After executing basic statement block 4, data center 101 executes basic statement block 5. After executing basic statement block 5, data center 101 executes basic statement block 6. After executing basic statement block 6, the execution ends. Therefore, within this blocking time, the computing power resources included in data center 101 for executing the first program do not execute any basic statement blocks and are in an idle state, wasting precious computing power.

[0047] For the next basic statement block in the first program whose execution order is later than the target basic statement block, there may be no dependency relationship between the next basic statement block and the target basic statement block. That is to say, executing the next basic statement block may not require the execution result received by the target basic statement block.

[0048] For other basic statement blocks that have a dependency relationship with the target basic statement block, executing the other basic statement block requires the execution result received by the target basic statement block. The other basic statement block is the nth basic statement block after the target basic statement block in terms of execution order, where n is an integer greater than 1. That is to say, there are n - 1 basic statement blocks between the target basic statement block and the other basic statement block. There is no dependency relationship between these n - 1 statement blocks and the target basic statement block, and executing each of these n - 1 basic statement blocks does not require the execution result received by the target basic statement block.

[0049] To avoid or reduce waste of computing power resources, data center 101 executes the target basic statement block. During the blocking time when the target basic statement block calls the API and waits for the API to return the execution result, data center 101 can execute these n - 1 basic statement blocks. When these n - 1 basic statement blocks are executed, the API may return the execution result. At this time, the execution result is received, and then data center 101 executes the other basic statement block based on the execution result. Or, when these n - 1 basic statement blocks are executed, the API may not have returned the execution result yet, but at this time, it may only need to wait a little while to receive the execution result, and then data center 101 executes the other basic statement block based on the execution result.

[0050] For example, as Figure 2As shown, it is assumed that the basic statement block 3 is used to call an API with a blocking feature and wait for the API to return an execution result. There is no dependency between the basic statement block 4 and the basic statement block 5 and the basic statement block 3. That is to say, the execution of the basic statement block 3 and the basic statement block 4 does not require this execution result. There is a dependency between the basic statement block 6 and the basic statement block 3. That is to say, the execution result is required when the basic statement block 6 is executed.

[0051] See Figure 4 , the judgment result obtained by the data center 101 executing the basic statement block 1 is that the basic statement block 3 needs to be executed. When the data center 101 executes the basic statement block 3, the basic statement block 3 calls this API. During the blocking time waiting for the API to return the execution result, the data center 101 executes the basic statement block 4. After executing the basic statement block 4, the data center 101 executes the basic statement block 5.

[0052] After executing the basic statement block 5, the execution result returned by the API may have been received, and the data center 101 executes the basic statement block 6 based on this execution result. Or, after executing the basic statement block 5, the execution result returned by the API may not have been received yet, but the execution result returned by the API may be received after waiting for a while, and the data center 101 executes the basic statement block 6 based on this execution result. After executing the basic statement block 6, the execution ends. In this way, it is possible to avoid the computing power resources of the data center 101 for executing the first program from being idle, thereby avoiding waste of computing power; or, reducing the time when the computing power resources of the data center 101 for executing the first program are idle and reducing waste of computing power.

[0053] See Figure 5 , an embodiment of the present application provides a method 500 for executing a program. The method 500 can be applied to Figure 1 the data center 101 included in the network architecture 100 shown, and includes the following processes.

[0054] Step 501: Obtain a second program and a configuration file of the second program. The second program is a program written by a user. The configuration file is used to describe the target basic statement block of the function call with blocking semantics in the second program. The target basic statement block is used to call a third API with a blocking feature and wait to receive the execution result returned by the third API.

[0055] The user can write a second program and set a configuration file on the terminal device. Since the second program is written by the user, the user can know which basic statement blocks in the second program are the target basic statement blocks of function calls with blocking semantics. Therefore, the user can set the configuration file on the terminal device. The terminal device obtains the second program and the configuration file, and sends the second program and the configuration file to the data center. The data center receives the second program and the configuration file.

[0056] Optionally, the user knows that the third API has blocking characteristics and knows which code statements in the second program are used to call the third API. Then, the basic statement block where the code statements for calling the third API are located is analyzed, and this basic statement block is used as the target basic statement block of function calls with blocking semantics in the second program.

[0057] Optionally, the configuration file may include the identification information of the target basic statement block and the identification information of the third API that the target basic statement block needs to call. Optionally, the identification information of the target basic statement block may be the name of the target basic statement block, etc., and the identification information of the third API may be the name of the third API, etc.

[0058] See Figure 6 the second program shown. The second program includes a third basic statement block, at least one first basic statement block, and a second basic statement block. The execution order of the third basic statement block is earlier than the execution order of the at least one first basic statement block, and the execution order of the at least one first basic statement block is earlier than the second basic statement block.

[0059] There is no dependency between the third basic statement block and each first basic statement block in the at least one first basic statement block. There is no dependency between each first basic statement block in the at least one first basic statement block and the second basic statement block. However, there is a dependency between the third basic statement block and the second basic statement block.

[0060] Step 502: Replace the third basic statement block included in the second program with the first API, and insert the second API between the at least one first basic statement block and the second basic statement block to obtain a first program. The first API is used to call the third API and indicate asynchronous execution, and the second API is used to wait for the execution result returned by the third API.

[0061] In step 502, the first program can be obtained through the operations of steps 5021 to 5024 as follows.

[0062] Optionally, the operations of 5021 - 5024 are executed during the compilation of the second program, and the first program is the machine code in binary format obtained by compiling the second program.

[0063] Optionally, the data center includes a compiler, and the second program can be compiled using the compiler.

[0064] 5021: Obtain the logical structure of the second program. The logical structure of the second program is used to describe multiple basic statement blocks included in the second program and the relationships between the multiple basic statement blocks. The multiple basic statement blocks include a third basic statement block, at least one first basic statement block, and a second basic statement block.

[0065] Optionally, the logical structure of the second program is the abstract syntax tree (AST) of the second program or the low level virtual machine intermediate representation (LLVM IR) of the second program.

[0066] See Figure 7 , use a preprocessor to process the second program to obtain the AST of the second program, and use the AST as the logical structure of the second program. Alternatively, perform semantic analysis on the AST of the second program to obtain the LLVM IR of the second program, and use the LLVM IR as the logical structure of the second program.

[0067] 5022: Based on the configuration file of the second program, use the target basic statement block in the second program as the third basic statement block.

[0068] In 5022, based on the configuration file of the second program, identify the target basic statement block in the second program, and use the identified target basic statement block as the third basic statement block.

[0069] Optionally, the configuration file of the second program includes identification information of the target basic statement block. Based on the identification information of the target basic statement block, identify the target basic statement block in the second program.

[0070] 5023: Based on the logical structure of the second program, obtain the basic statement blocks that have a dependency relationship with the third basic statement block as the second basic statement block, and at least one first basic statement block located between the third basic statement block and the second basic statement block.

[0071] The logical structure of the second program is used to describe the relationships between multiple basic statement blocks included in the second program. Therefore, based on the logical structure of the second program used to describe the relationships between the multiple basic statement blocks, identify the basic statement blocks that have a dependency relationship with the third basic statement block from the multiple basic statement blocks as the second basic statement block. Identify at least one first basic statement block located between the third basic statement block and the second basic statement block based on the logical structure of the second program.

[0072] 5024: Replace the third basic statement block included in the second program with the first API, and insert the second API between at least one first basic statement block and the second basic statement block to obtain the first program.

[0073] In 5024, the configuration file of the second program includes the identification information of the third API that the third basic statement block needs to call. Therefore, the first API and the second API can be obtained based on the identification information of the third API. The first API is used to call the third API, and the second API is used to wait for receiving the execution result returned by the third API. Then, replace the third basic statement block included in the second program with the first API, and insert the second API between at least one first basic statement block and the second basic statement block. Then compile the second program into the first program in binary format.

[0074] For example, for Figure 6 the second program shown, replace the third basic statement block included in the second program with the first API, and insert the second API between at least one first basic statement block and the second basic statement block to obtain the first program as shown in Figure 8 shown.

[0075] After obtaining the first program, next the data center can execute the first program, and the detailed execution process is as follows.

[0076] Step 503: Execute the first API included in the first program to call the third API.

[0077] For the first API, at least one first basic statement block, the second API, and the second basic statement block included in the first program, the execution order of the first API is earlier than that of at least one first basic statement block, the execution order of at least one first basic statement block is earlier than that of the second API, and the execution order of the second API is earlier than that of the second basic statement block. Therefore, when the data center executes the first program, it will first execute the first API. Since the first API is used to call the third API, the third API will be automatically called when the first API is executed.

[0078] After the third API is called, the third API starts to be executed. Since the third API is an API with blocking characteristics, the third API is not immediately executed after being called. That is to say, it takes a relatively long time to execute the third API. After a period of time, the third API can be executed completely and the execution result can be obtained, and then the third API returns the execution result.

[0079] In some embodiments, the computing power resources for executing the first program and the computing power resources for executing the third API are different.

[0080] Step 504: In response to the asynchronous execution indicated by the first API, execute at least one first basic statement block included in the first program.

[0081] Since the first API is also used to indicate asynchronous execution, when the first API is executed, triggered by the asynchronous execution indicated by the first API, the next API whose execution order is after the first API is automatically executed. This next API is the first basic statement block among the at least one first basic statement block.

[0082] When executing the at least one first basic statement block, the at least one first basic statement block will be executed based on the execution order among the at least one first basic statement block.

[0083] Step 505: After executing the at least one first basic statement block, execute the second API included in the first program to receive the execution result returned by the third API.

[0084] Since the execution order of the second API is later than the last first basic statement block among the at least one first basic statement block, the second API is automatically executed after the last first basic statement block is executed. Since the second API is used to wait for receiving the execution result returned by the third API, when the second API is executed, if the third API has been executed and produced an execution result, the execution result returned by the third API is automatically received when the second API is executed. This avoids the computing power resources used to execute the first program being in an idle state and avoids the waste of such computing power resources.

[0085] When the second API is executed, if the third API has not been executed yet, that is, the third API has not produced an execution result, after the second API is executed, wait for the third API to be executed and produce the execution result. When the third API produces the execution result and returns the execution result, the execution result returned by the third API is automatically received. This reduces the time when the computing power resources used to execute the first program are in an idle state and reduces the waste of such computing power resources.

[0086] Step 506: Execute the second basic statement block based on the execution result.

[0087] Since the execution order of the second basic statement block is later than the second API, after the second API is executed, it is considered that the second API is executed after receiving the execution result returned by the third API, and then the second basic statement block whose execution order is after the second API is executed based on the execution result.

[0088] In an embodiment of the present application, the second program includes a third basic statement block, at least one first basic statement block, and a second basic statement block. The execution order of the third basic statement block is earlier than that of the at least one first basic statement block, and the execution order of the at least one first basic statement block is earlier than that of the second basic statement block. Replace the third basic statement block included in the second program with a first API, and insert a second API between the at least one first basic statement block and the second basic statement block included in the second program. Since the first API is used to call a third API and indicate asynchronous execution, and the second API is used to wait for receiving the execution result returned by the third API, when the first program is executed, the first API is executed first to call the third API, and in response to the asynchronous execution indicated by the first API, the at least one first basic statement block is executed. After the at least one first basic statement block is executed, the second API is executed to receive the execution result returned by the third API. Then, the second basic statement block is executed based on the execution result. This avoids the computing power resources for executing the first program being in an idle state and wastes of such computing power resources; or, reduces the time during which the computing power resources for executing the first program are in an idle state and reduces the waste of such computing power resources.

[0089] See Figure 9 , an embodiment of the present application provides an apparatus 900 for executing a program. The apparatus 900 may be deployed on Figure 1 the data center 101 in the network architecture 100 shown in Figure 5 or the apparatus 900 may be deployed on

[0090] the data center 101 of the method 500 shown in

[0091] The apparatus 900 includes a first program. The first program includes a first application programming interface (API), at least one first basic statement block, a second API, and a second basic statement block. The execution order of the first API is earlier than that of the at least one first basic statement block, the execution order of the at least one first basic statement block is earlier than that of the second API, and the execution order of the second API is earlier than that of the second basic statement block. The first API is used to call a third API and indicate asynchronous execution. The third API is an API with a blocking feature. The second API is used to wait for receiving the execution result returned by the third API. The second basic statement block requires the execution result. The apparatus 900 includes: a processing unit 901 and a receiving unit 902;

[0091] The processing unit 901 is configured to execute the first API to call the third API;

[0092] The processing unit 901 is further configured to execute at least one first basic statement block in response to the asynchronous execution indicated by the first API;

[0093] The receiving unit 902 is configured to execute a second API after executing at least one first basic statement block, so that the receiving unit 902 receives the execution result returned by the third API;

[0094] The processing unit 901 is further configured to execute a second basic statement block based on the execution result.

[0095] Optionally, for the processing unit 901 to execute the first API to call the third API, the detailed implementation process is as described in Figure 5 the relevant content of step 503 of the method 500 shown, which will not be elaborated here.

[0096] Optionally, for the detailed implementation process of the processing unit 901 to execute at least one first basic statement block, see Figure 5 the relevant content of step 504 of the method 500 shown, which will not be elaborated here.

[0097] Optionally, for the detailed implementation process of the processing unit 901 to execute the second API, see Figure 5 the relevant content of step 505 of the method 500 shown, which will not be elaborated here.

[0098] Optionally, for the detailed implementation process of the processing unit 901 to execute the second basic statement block based on the execution result, see Figure 5 the relevant content of step 506 of the method 500 shown, which will not be elaborated here.

[0099] Optionally, the device 900 includes a second program to be executed. The second program includes a third basic statement block, at least one first basic statement block, and a second basic statement block. The execution order of the third basic statement block is earlier than that of at least one first basic statement block, and the execution order of at least one first basic statement block is earlier than that of the second basic statement block. The third basic statement block is used to call the third API and wait for receiving the execution result returned by the third API. The processing unit 901 is further configured to replace the third basic statement block included in the second program with the first API, and insert the second API between at least one first basic statement block and the second basic statement block to obtain a first program.

[0100] Optionally, for the detailed implementation process of the processing unit 901 to replace the third basic statement block included in the second program with the first API and insert the second API between at least one first basic statement block and the second basic statement block to obtain a first program, see Figure 5 the relevant content of step 502 of the method 500 shown, which will not be elaborated here.

[0101] Optionally, the processing unit 901 is further configured to:

[0102] Obtain the logical structure of the second program, where the logical structure is used to describe multiple basic statement blocks included in the second program and the relationships between the multiple basic statement blocks;

[0103] Obtain the configuration file of the second program, where the configuration file is used to describe the target basic statement blocks of function calls with blocking semantics in the second program, and the target basic statement blocks are used to call APIs with blocking characteristics and wait to receive the execution results returned by the APIs;

[0104] Based on the configuration file, use the target basic statement blocks in the second program as the third basic statement blocks;

[0105] Based on the logical structure, obtain the basic statement blocks that have a dependency relationship with the third basic statement blocks as the second basic statement blocks.

[0106] Optionally, for the detailed implementation process of the processing unit 901 to obtain the logical structure of the second program, refer to Figure 5 the relevant content of step 5021 of the method 500 shown in the figure, which will not be elaborated here.

[0107] Optionally, for the detailed implementation process of the processing unit 901 to obtain the configuration file of the second program, refer to Figure 5 the relevant content of step 501 of the method 500 shown in the figure, which will not be elaborated here.

[0108] Optionally, for the detailed implementation process of the processing unit 901 to use the target basic statement blocks in the second program as the third basic statement blocks, refer to Figure 5 the relevant content of step 5022 of the method 500 shown in the figure, which will not be elaborated here.

[0109] Optionally, for the detailed implementation process of the processing unit 901 to obtain the basic statement blocks that have a dependency relationship with the third basic statement blocks as the second basic statement blocks, refer to Figure 5 the relevant content of step 5023 of the method 500 shown in the figure, which will not be elaborated here.

[0110] Optionally, the logical structure is the Abstract Syntax Tree (AST) of the second program or the Low-Level Virtual Machine Intermediate Representation (LLVM IR) of the second program.

[0111] Optionally, the processing unit 901 is used to replace the third basic statement blocks included in the second program with the first API during the compilation of the second program, and insert the second API between at least one first basic statement block and the second basic statement block to obtain the first program.

[0112] Optionally, during the compilation of the second program, the processing unit 901 replaces the third basic statement block included in the second program with the first API, and inserts the second API between at least one first basic statement block and the second basic statement block. For the detailed implementation process of the first program, refer to Figure 5 the relevant content of step 5024 of the method 500 shown in the figure, which will not be elaborated here.

[0113] Optionally, the first program is machine code in binary format.

[0114] In the embodiments of the present application, since the first API is used to call the third API and indicate asynchronous execution, and the second API is used to wait for receiving the execution result returned by the third API, when the processing unit executes the first program, it first executes the first API to call the third API, and in response to the asynchronous execution indicated by the first API, executes the at least one first basic statement block. After executing the at least one first basic statement block, it executes the second API to receive the execution result returned by the third API. That is to say, during the period of waiting for receiving the execution result, the processing unit executes the at least one first basic statement block, avoiding the computing power resources for executing the first program from being idle and avoiding waste of computing power; or, reducing the time when the computing power resources for executing the first program are idle and reducing waste of computing power.

[0115] Refer to Figure 10 , the embodiments of the present application provide a computing device 1000. For example, the computing device 1000 may be Figure 1 a device included in the data center 101 included in the network architecture 100 shown in the figure, or may be Figure 5 a device included in the data center in the method 500 shown in the figure.

[0116] As Figure 10 shown, the computing device 1000 includes: a bus 1002, a processor 1004, a memory 1006, and a communication interface 1008. The processor 1004, the memory 1006, and the communication interface 1008 communicate with each other through the bus 1002. The computing device 1000 may be a server or a terminal device. It should be understood that the present application does not limit the number of processors and memories in the computing device 1000.

[0117] The bus 1002 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For the sake of convenience of representation, Figure 10It is represented by only one line, but it does not mean that there is only one bus or one type of bus. Bus 1002 may include a path for transmitting information between various components of computing device 1000 (e.g., processor 1004, memory 1006, communication interface 1008).

[0118] Processor 1004 may include any one or more of processors such as a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).

[0119] Memory 1006 may include volatile memory, such as random access memory (RAM). Memory 1006 may also include non-volatile memory, such as read-only memory (ROM), flash memory, a hard disk drive (HDD), or a solid state drive (SSD).

[0120] See Figure 10 , executable program code is stored in memory 1006, and processor 1004 executes the executable program code to respectively implement the functions of processing unit 901 and receiving unit 902 in device 900 shown in Figure 9 , thereby implementing the method provided in any of the above embodiments. That is, instructions for executing the method provided in any of the above embodiments are stored on memory 1006. Or,

[0121] Communication interface 1008 uses a transceiver module such as, but not limited to, a network interface card or a transceiver to implement communication between computing device 1000 and other devices or a communication network.

[0122] An embodiment of the present application also provides a cluster for executing a program. The cluster for executing the program includes at least one computing device. The computing device may be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device may also be a terminal device such as a desktop computer, a laptop computer, or a smart phone.

[0123] As Figure 11As shown, the cluster for executing the program includes at least one computing device 1000. The memory 1006 in one or more computing devices 1000 in the cluster for executing the program may store the same instructions for executing the method provided in any of the above embodiments.

[0124] In some possible implementations, the memory 1006 of one or more computing devices 1000 in the cluster for executing the program may also store partial instructions for executing the method for executing the program. In other words, the combination of one or more computing devices 1000 may jointly execute instructions for executing the method provided in any of the above embodiments.

[0125] In some possible implementations, one or more computing devices in the cluster that executes the program may be connected via a network, which may be a wide area network or a local area network. Figure 12 A possible implementation is shown. Figure 12 As shown, two computing devices 1000A and 1000B are connected via a network. Specifically, they are connected to the network via a communication interface in each computing device.

[0126] In this type of possible implementation, the memory 1006 in the computing device 1000A stores the execution Figure 9 Instructions for the functions of the processing unit 901 in the illustrated embodiment. Meanwhile, the memory 1006 in the computing device 1000B stores instructions for executing the functions of the processing unit 901 in the illustrated embodiment. Figure 9 Instructions for the functionality of the receiving unit 902 in the illustrated embodiment.

[0127] It should be understood that Figure 12 The functions of the computing device 1000A shown in FIG. 1000A may also be completed by multiple computing devices 1000. Similarly, the functions of the computing device 1000B may also be completed by multiple computing devices 1000.

[0128] The present application embodiment also provides another cluster for executing programs. The connection relationship between the computing devices in the cluster for executing programs can be similarly referred to as Figure 12 The connection mode of the cluster for executing the program. The difference is that the memory 1006 in one or more computing devices 1000 in the cluster for executing the program may store the same instructions for executing the method provided by any of the above embodiments.

[0129] In some possible implementations, the memory 1006 of one or more computing devices 1000 in the cluster for executing the program may also store partial instructions for executing the method provided in any of the above embodiments. In other words, a combination of one or more computing devices 1000 may jointly execute instructions for executing the method provided in any of the above embodiments.

[0130] The embodiments of the present application also provide a computer program product containing instructions. The computer program product may be software or a program product containing instructions that can run on a computing device or be stored in any available medium. When the computer program product runs on at least one computing device, at least one computing device is caused to execute the method provided in any of the above embodiments.

[0131] The embodiments of the present application also provide a computer-readable storage medium. The computer-readable storage medium may be any available medium that a computing device can store or a data storage device such as a data center containing one or more available media. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a magnetic tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive), etc. The computer-readable storage medium includes instructions that direct the computing device to execute the method provided in any of the above embodiments.

[0132] Those of ordinary skill in the art can understand that all or part of the steps of implementing the above embodiments can be completed by hardware or by a program instructing relevant hardware. The program can be stored in a computer-readable storage medium. The storage medium mentioned above can be a read-only memory, a magnetic disk, an optical disc, etc.

[0133] The above are only optional embodiments of the present application and are not intended to limit the present application. Any modifications, equivalent replacements, improvements, etc. made within the principles of the present application shall be included within the protection scope of the present application.

Claims

1. A method for executing a program, characterized in that, The method is applied to a data center, which includes a first program. The first program includes a first application programming interface (API), at least one first basic statement block, a second API, and a second basic statement block. The execution order of the first API is earlier than that of the at least one first basic statement block. The execution order of the at least one first basic statement block is earlier than that of the second API. The execution order of the second API is earlier than that of the second basic statement block. The first API is used to call a third API and indicate asynchronous execution. The third API is an API with a blocking feature. The second API is used to wait for receiving the execution result returned by the third API. The second basic statement block requires the execution result. The method includes: Execute the first API to call the third API; In response to the asynchronous execution indicated by the first API, execute the at least one first basic statement block; After executing the at least one first basic statement block, execute the second API to receive the execution result returned by the third API; Execute the second basic statement block based on the execution result.

2. The method according to claim 1, characterized in that The data center includes a second program to be executed. The second program includes a third basic statement block, at least one first basic statement block, and a second basic statement block. The execution order of the third basic statement block is earlier than that of the at least one first basic statement block. The execution order of the at least one first basic statement block is earlier than that of the second basic statement block. The third basic statement block is used to call the third API and wait for receiving the execution result returned by the third API. The method further includes: Replace the third basic statement block included in the second program with the first API, and insert the second API between the at least one first basic statement block and the second basic statement block to obtain the first program.

3. The method according to claim 2, wherein The method further includes: Obtain the logical structure of the second program, which is used to describe multiple basic statement blocks included in the second program and the relationships between the multiple basic statement blocks; Obtain the configuration file of the second program, which is used to describe the target basic statement block of the function call with a blocking semantics in the second program. The target basic statement block is used to call an API with a blocking feature and wait for receiving the execution result returned by the API; Based on the configuration file, use the target basic statement block in the second program as the third basic statement block; Based on the logical structure, obtain the basic statement block that has a dependency relationship with the third basic statement block as the second basic statement block.

4. The method according to claim 3, wherein The logical structure is the abstract syntax tree (AST) of the second program or the low-level virtual machine intermediate representation (LLVM IR) of the second program.

5. The method according to any one of claims 2-4, characterized in that, The step of replacing the third basic statement block included in the second program with the first API and inserting the second API before the second basic statement block to obtain the first program includes: During the compilation of the second program, replace the third basic statement block included in the second program with the first API, and insert the second API between the at least one first basic statement block and the second basic statement block to obtain the first program.

6. The method according to any one of claims 1-5, characterized in that, The first program is machine code in binary format.

7. An apparatus for executing a program, characterized in that, The device includes a first program, the first program includes a first application programming interface (API), at least one first basic statement block, a second API, and a second basic statement block. The execution order of the first API is earlier than that of the at least one first basic statement block. The execution order of the at least one first basic statement block is earlier than that of the second API. The execution order of the second API is earlier than that of the second basic statement block. The first API is used to call a third API and indicate asynchronous execution. The third API is an API with a blocking feature. The second API is used to wait for the execution result returned by the third API. The second basic statement block requires the execution result. The device includes a processing unit and a receiving unit; The processing unit is configured to execute the first API to call the third API; The processing unit is further configured to execute the at least one first basic statement block in response to the asynchronous execution indicated by the first API; The processing unit is further configured to execute the second API after executing the at least one first basic statement block, so that the receiving unit receives the execution result returned by the third API; The processing unit is further configured to execute the second basic statement block based on the execution result.

8. The device according to claim 7, wherein The device includes a second program to be executed. The second program includes a third basic statement block, at least one first basic statement block, and a second basic statement block. The execution order of the third basic statement block is earlier than that of the at least one first basic statement block. The execution order of the at least one first basic statement block is earlier than that of the second basic statement block. The third basic statement block is used to call the third API and wait for the execution result returned by the third API. The processing unit is further configured to replace the third basic statement block included in the second program with the first API, and insert the second API between the at least one first basic statement block and the second basic statement block to obtain the first program.

9. The device according to claim 8, characterized in that, The processing unit is further configured to: Obtain the logical structure of the second program, where the logical structure is used to describe multiple basic statement blocks included in the second program and the relationships between the multiple basic statement blocks; Obtain the configuration file of the second program, where the configuration file is used to describe the target basic statement block of the function call with blocking semantics in the second program, and the target basic statement block is used to call an API with a blocking feature and wait for the execution result returned by the API; Based on the configuration file, use the target basic statement block in the second program as the third basic statement block; Based on the logical structure, obtain the basic statement block that has a dependency relationship with the third basic statement block as the second basic statement block.

10. The device according to claim 9, characterized in that, The logical structure is the abstract syntax tree (AST) of the second program or the low-level virtual machine intermediate representation (LLVM IR) of the second program.

11. The device according to any one of claims 8-10, characterized in that, The processing unit is configured to, during the compilation of the second program, replace the third basic statement block included in the second program with the first API, and insert the second API between the at least one first basic statement block and the second basic statement block, to obtain the first program.

12. The device according to any one of claims 7-11, characterized in that, The first program is machine code in binary format.

13. A cluster of computing devices, characterized in that, Comprising at least one computing device, each computing device including a processor and a memory; The processor of the at least one computing device is configured to execute instructions stored in the memory of the at least one computing device, so that the computing device cluster executes the method according to any one of claims 1-6.

14. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a computer, the method according to any one of claims 1-6 is implemented.

15. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, the method according to any one of claims 1-6 is implemented.