An API call method and device

By selecting the appropriate processing engine to call the target API in a heterogeneous system, the problem of inappropriate processing engine configuration in a heterogeneous system is solved, and efficient API calls and processing efficiency are improved.

CN113918290BActive Publication Date: 2025-08-05HUAWEI TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202010656379.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-07-09
Publication Date
2025-08-05
Estimated Expiration
2040-07-09

AI Technical Summary

Technical Problem

In heterogeneous systems, the prior art cannot guarantee whether the configuration of the processing engine is appropriate, resulting in the inability to efficiently execute program instructions.

Method used

The target API is determined by the CPU in the heterogeneous system, and the most suitable processing engine calls the target API based on the API call information. The pre-configured API signature collection, function library and intermediate representation are used to dynamically compile program instructions.

Benefits of technology

It realizes efficient calling of APIs in heterogeneous systems, improves processing efficiency and expands the scope of application.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113918290B_ABST
    Figure CN113918290B_ABST
Patent Text Reader

Abstract

An API call method and device. In the present application, the method is applied to a heterogeneous system, which may include multiple processing engines. The multiple processing engines include a first processing engine and a second processing engine. The method can be executed by a CPU in the heterogeneous system. The CPU can be one of the first processing engine and the second processing engine, or a processing engine other than the first processing engine and the second processing engine in the heterogeneous system. The CPU determines the target API to be called; then, based on the API call information, it selects the first processing engine to call the target API, and the API call information is used to indicate the efficiency of the first processing engine and the second processing engine in calling the target API respectively. The CPU in the heterogeneous system can select a suitable processing engine to call the target API according to the efficiency of different processing engines in calling the target API, so as to achieve efficient API calls.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of communication technologies, and in particular, to an API call method and apparatus. Background Art

[0002] With the in-depth promotion of computers and intelligent devices in different application fields, in order to meet the data processing requirements in different fields, in addition to the central processing unit (CPU), many different processing engines have emerged, such as graphics processing unit (GPU), image processor (IP), digital signal processor (DSP), neural network processing unit (NPU), field programmable gate array (FPGA), etc. For different data processing scenarios, different types of processing engines will have better data processing capabilities in corresponding scenarios.

[0003] To improve the overall data processing ability of a computing system, in addition to the central processing unit (CPU), the computing system may also include processing engines such as GPU, IP, DSP, and NPU. Such a computing system with two or more types of processors may also be referred to as a heterogeneous system.

[0004] In such a heterogeneous system, the CPU can act as a scheduler, interact with other processing engines for data, and assist other processing engines in data processing.

[0005] Currently, since the types of program instructions used by different processing engines in a heterogeneous system are different, the compiler needs to pre-send the program instructions required to be executed by each processing engine (including the CPU), such as application programming interface (API) functions, etc., to the CPU. Then, the CPU sends the program instructions required to be executed by other processing engines to the corresponding processing engines.

[0006] Before sending these program instructions to the CPU, during the development of the program instructions, the compiler needs to configure in advance which program instructions are to be executed by which processing engine.

[0007] The way of configuring the processing engine for executing program instructions depends on the developer, and it cannot be guaranteed whether the configured processing engine for executing program instructions is appropriate or can execute program instructions more efficiently than other processing engines. Summary of the Invention

[0008] This application provides an API calling method and device for determining a processing engine that can efficiently call an API.

[0009] In a first aspect, an embodiment of this application provides an application programming interface (API) calling method. This method is applied to a heterogeneous system, which may include multiple processing engines. The multiple processing engines include a first processing engine and a second processing engine. This method can be executed by a CPU in the heterogeneous system. The CPU can be one of the first processing engine and the second processing engine, or a processing engine in the heterogeneous system other than the first processing engine and the second processing engine. The CPU first determines a target API to be called; then, based on API call information, it selects the first processing engine to call the target API, where the API call information is used to indicate the efficiency of the first processing engine and the second processing engine in calling the target API respectively. The target API can be a heterogeneous API or other types of APIs.

[0010] Through the above method, the CPU in the heterogeneous system can select a suitable processing engine to call the target API according to the efficiency of different processing engines in calling the target API, realizing the efficient call of the API.

[0011] In a possible implementation, when the CPU selects the first processing engine to call the target API based on the API call information, it can first determine the target parameter scale of the target API. For example, the CPU can first obtain the signature of the target API, and the signature of the target API is used to indicate the target parameter scale of the target API. Then, according to the API call information and the target parameter scale of the target API, it selects the first processing engine, where the API call information indicates the efficiency of the first processing engine and the second processing engine in calling the target API with candidate parameter scales, and the candidate parameter scales include the target parameter scale.

[0012] Through the above method, the CPU in the heterogeneous system can select a suitable processing engine to call the target API with the target parameter scale according to the efficiency of different processing engines in calling the target API with different candidate parameter scales.

[0013] In a possible implementation, the embodiments of the present application do not limit the manner in which the CPU obtains the signature of the target API. For example, the CPU may first obtain the identifier of the target API; then, determine the signature of the target API from a pre-configured API signature set according to the identifier of the target API, where the target API signature includes the identifier of the target API.

[0014] Through the above method, the CPU can conveniently determine the signature of the target API through a pre-configured API signature set.

[0015] In a possible implementation, after the CPU selects the first processing engine to call the target API, it can obtain the program instructions required for the first processing engine to call the target API from a pre-configured API function library of the first processing engine. The API function library of the first processing engine includes the program instructions required for the first processing engine to call one or more APIs respectively, and one or more APIs include the target API; then, send the program instructions required for the first processing engine to call the target API to the first processing engine.

[0016] Through the above method, the pre-configured API function library of the first processing engine includes the program instructions required for the first processing engine to call one or more APIs respectively. The CPU can quickly obtain the program instructions required for the first processing engine to call the target API through the API function library of the first processing engine, which can improve the efficiency of the first processing engine calling the target API.

[0017] In a possible implementation, after the CPU selects the first processing engine to call the target API, it can also obtain the intermediate representation of the target API stored in advance; compile the intermediate representation of the target API into the program instructions required for the first processing engine to call the target API; then, send the program instructions required for the first processing engine to call the target API to the first processing engine.

[0018] Through the above method, the CPU can quickly compile and generate the program instructions required for the first processing engine to call the target API through the intermediate representation of the target API, which improves the efficiency of the first processing engine calling the target API. In addition, this method can be applied to a variety of different heterogeneous systems, and these heterogeneous systems only need to include a processing engine that can compile the intermediate representation of the target API, effectively expanding the application scope.

[0019] In a possible implementation, the API call information can also indicate the storage address of the intermediate representation of the target API. When the CPU obtains the intermediate representation of the target API stored in advance, it can determine the storage address of the intermediate representation of the target API from the API call information, and then obtain the intermediate representation of the target API according to the storage address of the intermediate representation of the target API.

[0020] Through the above method, the CPU can also conveniently obtain the intermediate representation of the target API through the API call information. Further, the time required to generate the program instructions for the first processing engine to call the target API can be shortened, and the efficiency of the first processing engine calling the target API can be improved.

[0021] In a possible implementation, the API call information is stored in the form of a table, and the form of the table is more intuitive, which is convenient for the CPU to obtain relevant information from the API call information.

[0022] In a possible implementation, the API call information can also indicate the cache addresses of the program instructions required for the first processing engine and the second processing engine to call the target API respectively. After the CPU selects the first processing engine to call the target API, it can obtain the program instructions required for the first processing engine to call the target API according to the cache address of the program instructions required for the first processing engine to call the target API in the API call information; then, send the program instructions to the first processing engine.

[0023] Through the above method, the CPU can also conveniently obtain the cache address of the program instructions required for the first processing engine to call the target API through the API call information, and can obtain the program instructions required for the first processing engine to call the target API relatively quickly, so that the first processing engine can efficiently call the target API.

[0024] In a possible implementation, the cache address of the program instructions required for the first processing engine to call the target API includes the cache address of the program instructions required for the first processing engine to call the target API with the candidate parameter scale, and the candidate parameter scale includes the target parameter scale.

[0025] When the CPU obtains the program instructions required for the first processing engine to call the target API according to the cache address of the program instructions required for the first processing engine to call the target API in the API call information, it can obtain the cache address of the program instructions required for the first processing engine to call the target API with the target parameter scale from the API call information according to the target parameter scale of the target API, and then obtain the program instructions required for the first processing engine to call the target API with the target reference scale according to the cache address of the program instructions required for the first processing engine to call the target API with the target parameter scale.

[0026] Through the above method, the API call information can indicate the cache addresses of the program instructions required for the first processing engine to call the target APIs with different candidate parameter scales respectively. It is convenient for the CPU to select the program instructions required for the first processing engine to call the target API with the target reference scale.

[0027] Second aspect, the embodiments of the present application further provide an API call device. For the beneficial effects, reference can be made to the description in the first aspect and will not be elaborated here. This device has the functions to implement the behaviors in the method examples of the first aspect. The functions can be implemented by hardware or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above functions. In a possible design, the structure of the device includes a determination unit and a selection unit. Optionally, it further includes an instruction determination unit and a sending unit. These units can execute the corresponding functions in the method examples of the first aspect. For specific details, reference can be made to the detailed description in the method examples and will not be elaborated here.

[0028] Third aspect, the embodiments of the present application further provide a computing device. For the beneficial effects, reference can be made to the description in the first aspect and will not be elaborated here. The structure of the computing device includes a processor and a memory. The processor is configured to support the device to execute the corresponding functions in the method of the first aspect. The memory is coupled with the processor and stores the necessary program instructions and data of the computing device. The structure of the computing device further includes a communication interface for communicating with other devices.

[0029] Fourth aspect, the present application further provides a computer-readable storage medium. Instructions are stored in the computer-readable storage medium. When it runs on a computer, it enables the computer to execute the method of the first aspect.

[0030] Fifth aspect, the present application further provides a computer program product containing instructions. When it runs on a computer, it enables the computer to execute the method of the first aspect.

[0031] Sixth aspect, the present application further provides a computer chip. The chip is connected to the memory. The chip is used to read and execute the software program stored in the memory and execute the method of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] Figure 1A It is a schematic diagram of the architecture of a system provided by the present application;

[0033] Figure 1B It is a schematic diagram of the architecture of a system provided by the present application;

[0034] Figure 1C It is a schematic diagram of the architecture of a system provided by the present application;

[0035] Figure 1D It is a schematic diagram of the architecture of a system provided by the present application;

[0036] Figure 2 It is a schematic diagram of a heterogeneous API call method provided by the present application;

[0037] Figure 3A schematic structural diagram of a heterogeneous system provided by this application;

[0038] Figure 4 A schematic structural diagram of a heterogeneous system provided by this application;

[0039] Figure 5 A schematic structural diagram of a heterogeneous API call device provided by this application;

[0040] Figure 6 A schematic structural diagram of a device provided by this application. Detailed implementation manners

[0041] As Figure 1A shown, it is a schematic structural diagram of a system applicable to an embodiment of this application. The system includes a compiler 100 and a heterogeneous system 200. The heterogeneous system 200 includes multiple processing engines 210. In the embodiment of this application, the processing engine 210 is a unit capable of performing data processing operations. The embodiment of this application does not limit the specific type and form of the processing engine 210. Any unit capable of performing data processing operations can be used as the processing engine 210.

[0042] The multiple processing engines 210 may include at least one CPU, and the remaining processing engines 210 may be processing engines 210 of a different type from the CPU. For example, the remaining processing engines 210 may include some or all of the following:

[0043] CPU, GPU, IP, DSP, NPU, or FPGA.

[0044] One of the multiple processing engines 210 may be used as a scheduler for data interaction with the remaining processing engines 210 to assist the remaining processing engines 210 in data processing. In the embodiment of this application, taking the scheduler as the CPU as an example, for the convenience of description, the CPU serving as the scheduler is referred to as the scheduling CPU, or the main CPU (host CPU) in the embodiment of this application.

[0045] The embodiment of this application does not limit the deployment manner of the heterogeneous system 200. For example, the heterogeneous system 200 may be deployed in a centralized manner on a computing node, or may be deployed in a distributed manner on multiple computing nodes.

[0046] Compiler 100 can compile a source program including heterogeneous APIs into program instructions that can run in a heterogeneous system 200 (such as a host CPU) or into an intermediate representation (IR) of the heterogeneous APIs. Compiler 100 can be independently deployed from heterogeneous system 200, located on different computing nodes, or can be co-deployed with heterogeneous system 200, located on the same computing node.

[0047] Specifically, after obtaining the prototype declaration files of one or more heterogeneous APIs, compiler 100 can identify the prototype declaration files of the one or more heterogeneous APIs and edit the heterogeneous API header files, which include the signatures of each heterogeneous API. For ease of explanation, the set composed of the signatures of one or more heterogeneous APIs is called a heterogeneous API signature set.

[0048] The prototype declaration file of each heterogeneous API can indicate the parameter scale of the heterogeneous API, and the parameter scale can describe the scale of the parameters required for calling the heterogeneous API (such as the types, quantities, etc. of the parameters).

[0049] The prototype declaration file of each heterogeneous API can also indicate the relevant information of the heterogeneous API, such as some information other than the function body of the heterogeneous API, such as the number of parameters required for calling the heterogeneous API, the types of the parameters, and the parameter names.

[0050] It should be noted that in the embodiments of the present application, the size of the parameter does not refer to the numerical size of the parameter, but refers to the number of bytes occupied by the parameter in memory or in the processing engine 210.

[0051] The embodiments of the present application do not limit the manner in which the prototype declaration file of the heterogeneous API indicates the parameter scale of the heterogeneous API. For example, identifiers corresponding to different parameter scales can be preset, and different identifiers indicate different parameter scales of the heterogeneous API. For example, identifier A can correspond to 2 to 4 parameters and the parameter size is 2 to 4 bits, and identifier B can correspond to 5 to 7 parameters and the parameter size is 5 to 10 bits. Compiler 100 determines the parameter scale of the heterogeneous API by identifying the identifier corresponding to the parameter scale in the prototype declaration file of the heterogeneous API.

[0052] For another example, an expression for calculating the parameter scale can be predefined. The parameter information required for calling the heterogeneous API needs to be brought into the expression to obtain the expression of the parameter scale of the heterogeneous API. Compiler 100 determines the parameter scale of the heterogeneous API by identifying the expression of the parameter scale in the prototype declaration file of the heterogeneous API.

[0053] Illustrated by way of example, the following statement can be added to the prototype declaration file of the heterogeneous API:

[0054] #pragma HAPI_PARA_SIZE(hapi_para_size_expr)

[0055] The #pragma HAPI_PARA_SIZE is used to characterize the parameter scale of the heterogeneous API declared here, and hapi_para_size_expr is an expression of the parameter scale.

[0056] For example, the expression of the parameter scale can be max(max(A.Size(), B.Size()), C.Size())), where max(max(A.Size(), B.Size()), C.Size()) means to take the maximum value of Size among the three parameters A, B, and C as the parameter scale.

[0057] The embodiments of the present application do not limit the specific content of the expression of the parameter scale. Generally, the operands appearing in the expression can be positive integer constants, positive integer parameters in the corresponding heterogeneous API prototype declaration file, positive integer member variables of the parameters, or member functions with a positive integer return value.

[0058] The compiler 100 can generate the signature of the heterogeneous API. In the embodiments of the present application, the signature of the heterogeneous API includes the identifier of the heterogeneous API (used to uniquely identify the heterogeneous API), and can also include the relevant content of the prototype declaration of the heterogeneous API, such as the number of parameters required to call the heterogeneous API, the type of each parameter, and the size of the parameter, the type of the return value of the heterogeneous API (that is, the result value generated after calling the heterogeneous API), and the number of bytes occupied by the return value of the heterogeneous API in the host CPU. The signature of the heterogeneous API can also indicate the parameter scale of the heterogeneous API.

[0059] The way to indicate the parameter scale of the heterogeneous API in the signature of the heterogeneous API is similar to the way the prototype declaration file of the heterogeneous API indicates the parameter scale of the heterogeneous API. For specific details, please refer to the foregoing content and will not be described here. In the signature of the heterogeneous API, the parameter scale of the heterogeneous API can be indicated in the same way as the prototype declaration file of the heterogeneous API, or in a different way. The embodiments of the present application do not limit this.

[0060] The heterogeneous API signature set can be pre-deployed in the heterogeneous system 200, such as pre-loaded in the host CPU. In addition to the heterogeneous API signature set, in the embodiments of the present application, the heterogeneous API function libraries of each processing engine 210 in the heterogeneous system 200 can also be pre-deployed in the heterogeneous system 200, such as pre-loaded in the host CPU.

[0061] The heterogeneous API library of any processing engine 210 includes the program instructions required for the processing engine 210 to call the heterogeneous API. The types of program instructions used by different processing engines 210 may be different. The program instructions in the heterogeneous API library of any processing engine 210 are to convert the source program including the heterogeneous API into the program instructions that can be directly called by the processing engine 210. The heterogeneous API libraries of different types of processing engines 210 may be different.

[0062] Among them, the source program including the heterogeneous API is the original code of the heterogeneous API, which is the most original program instructions when writing the heterogeneous API and usually cannot be directly called by the processor engine.

[0063] If the heterogeneous API libraries of each processing engine 210 are not pre-deployed in the heterogeneous system 200, the heterogeneous system 200 can have a dynamic compilation function. For example, the host CPU has a dynamic compilation function. The host CPU can compile the intermediate representation of one or more heterogeneous APIs obtained from the compiler 100 into the program instructions required for different processing engines 210 to call the heterogeneous API.

[0064] Among them, the intermediate representation of the heterogeneous API is the program instructions compiled by the compiler 100 based on the heterogeneous API source program and can be recognized by different heterogeneous systems 200 (such as the host CPU in the heterogeneous system 200).

[0065] In the embodiment of the present application, the code generated by the compiler 100 triggers the host CPU in the heterogeneous system 200 to call the heterogeneous API. For example, the statement calling the heterogeneous API in the code generated by the compiler 100 is changed to call the host CPU, and the host CPU calls the heterogeneous API to determine the processing engine that executes the API in the heterogeneous system. This heterogeneous API can be called the target heterogeneous API.

[0066] After determining that it needs to call the target heterogeneous API, the host CPU in the heterogeneous system 200 can select the processing engine 210 corresponding to the target heterogeneous API (this processing engine 210 can also be called the target processing engine) from multiple processing engines 210 in the heterogeneous system 200 to call the target heterogeneous API.

[0067] In the embodiment of the present application, the host CPU in the heterogeneous system 200 can decide by itself the target processing engine for calling the target heterogeneous API without human participation, which can improve the efficiency of heterogeneous API calls in the heterogeneous system 200.

[0068] The following lists two possible deployment methods of the system in actual scenarios.

[0069] Such as Figure 1BAs shown in the figure, it is a schematic structural diagram of another system applicable to the embodiments of the present application. In this system, the compiler 100 can run on a development machine and on a computing node where the heterogeneous system 200 is deployed. The heterogeneous system 200 includes multiple processing engines 210, such as CPUs, GPUs, DSPs, etc. Among them, the CPU is the host CPU.

[0070] The compiler 100 is capable of compiling a source program including heterogeneous APIs to generate program instructions that can run on the host CPU, which is identified here as "application executable code". The application executable code is deployed in the heterogeneous system 200. The host CPU in the heterogeneous system can determine the processing engine (i.e., the target processing engine) that calls the heterogeneous API according to the application executable code.

[0071] It should be noted that the host CPU may include a module for determining the operation of the target processing engine that calls the heterogeneous API. For example, this module can be a heterogeneous runtime (HRT). The heterogeneous runtime can be a module in the host CPU responsible for executing heterogeneous programs (heterogeneous programs are programs executed by one or more of the multiple processing engines in the heterogeneous system, such as heterogeneous APIs), and for implementing heterogeneous program scheduling (such as determining the processing engine that executes the heterogeneous program, sending the heterogeneous program to the corresponding processing engine to trigger the execution of the heterogeneous program, etc.). The name of this module is not limited here, and "heterogeneous runtime" is only an example.

[0072] As Figure 1C As shown in the figure, it is a schematic structural diagram of another system applicable to the embodiments of the present application. In this system, the compiler 100 can run on a development machine and on a computing node where the heterogeneous system 200 is deployed. The heterogeneous system 200 includes multiple processing engines 210, such as CPUs, GPUs, DSPs, etc. Among them, the CPU is the host CPU.

[0073] The compiler 100 is capable of compiling a source program including heterogeneous APIs to generate an intermediate representation of the heterogeneous API. The intermediate representation of the heterogeneous API is deployed (or stored) in the heterogeneous system 200 (such as the host CPU). When the host CPU in the heterogeneous system 200 determines that it needs to call the heterogeneous API, it can first determine the processing engine (i.e., the target processing engine) that calls the heterogeneous API, and then compile the intermediate representation of the heterogeneous API into the program instructions required for the target processing engine to call the heterogeneous API.

[0074] Differentiating from the function of the host CPU in the system as Figure 1B shown, in Figure 1CIn the system shown, the host CPU (or the heterogeneous runtime in the host CPU) can not only execute heterogeneous programs and implement heterogeneous program scheduling, but also has a dynamic compilation function, which can compile the intermediate representation of a heterogeneous API into program instructions required for different processing engines to call the heterogeneous API in real time.

[0075] As Figure 1D shown, it is a schematic structural diagram of another system applicable to the embodiments of the present application. The system includes a compiler 100 and a heterogeneous cluster 20. The heterogeneous cluster 20 includes multiple heterogeneous systems 200. The specific structure of the heterogeneous system 200 can be referred to the structure of the heterogeneous system 200 shown in FIG. 1, which will not be elaborated here.

[0076] One heterogeneous system 200 or the processing engine 210 in one heterogeneous system 200 in the heterogeneous cluster 20 can be used as a scheduler to interact with the processing engines 210 in the remaining heterogeneous systems 200 (and the remaining processing engines 210 in the heterogeneous systems 200 where they are located), and assist the processing engines 210 in the remaining heterogeneous systems 200 (and the remaining processing engines 210 in the heterogeneous systems 200 where they are located) in data processing.

[0077] The functions of the compiler 100 can be referred to the foregoing content, which will not be elaborated here. The operations performed by the heterogeneous system 200 or the processing engine 210 in the heterogeneous system 200 as the scheduler can be referred to the operations performed by the host CPU as Figure 1B shown. Specifically, it can be referred to the foregoing content, which will not be elaborated here.

[0078] Next, taking the system as Figures 1A - 1C shown as an example, in combination with Figure 2 the heterogeneous API call method provided by the embodiments of the present application will be described. When the processing engine 210 acting as the scheduler in the heterogeneous system 200 is other processing engines 210, the method of the embodiments of the present application is also applicable, and the difference lies in the different execution entities. The method includes:

[0079] Step 201: The host CPU determines the target heterogeneous API to be called.

[0080] In the embodiments of the present application, there is no limitation on the manner in which the host CPU determines the target heterogeneous API to be called. For example, the compiler 100 can hand over the call right of the target heterogeneous API to the host CPU. Specifically, the compiler 100 can change the call statement of the target heterogeneous API and change the caller of the target heterogeneous API to the host CPU (the call statement can be invokeHRT(...)). The compiler 100 can change the caller of the target heterogeneous API to a module in the host CPU. For example, the module can be a heterogeneous runtime or other modules.

[0081] Optionally, the host CPU can also determine the information of the target heterogeneous API, and the information of the target heterogeneous API can be notified to the host CPU by the compiler 100. The information of the target heterogeneous API can include the identifier of the target heterogeneous API, and can also include the cache address of the parameters required to call the target heterogeneous API and the storage address of the return value of the heterogeneous API.

[0082] Among them, the cache address of the parameters required to call the target heterogeneous API can be used to point to the buffer pointer representation of the parameters required to call the target heterogeneous API. If the heterogeneous API has no return value, the storage address of the return value of the heterogeneous API can be represented by a null address.

[0083] Step 202: The host CPU selects a target processing engine from multiple processing engines 210 based on the heterogeneous API call information to call the target heterogeneous API.

[0084] The heterogeneous API call information can indicate the efficiency of each of the multiple processing engines 210 in the heterogeneous system to call the target heterogeneous API, and there are multiple ways to characterize the efficiency of calling the target heterogeneous API.

[0085] For example, the heterogeneous API call information can characterize the efficiency of the processing engine 210 for the target heterogeneous API through the call time (this time can be relative time or absolute time).

[0086] For another example, the heterogeneous API call information can also characterize the efficiency of the processing engine 210 for the target heterogeneous API through the serial numbers of the multiple processing engines 210. The serial numbers of the processing engines 210 can be determined according to the time when the multiple processing engines 210 call the target heterogeneous API, or can be determined according to the preset call order of the multiple processing engines 210, or can be determined according to the performance of the multiple processing engines 210. The setting method of the serial numbers of the processing engines 210 is not limited here.

[0087] For another example, the heterogeneous API call information can also characterize the efficiency of the processing engine 210 for the target heterogeneous API through the call speed.

[0088] Any way that can characterize the efficiency of each of the multiple processing engines 210 to call the target heterogeneous API is applicable to the embodiments of the present application, and the present application does not limit the way to characterize the efficiency of the processing engine to call the target heterogeneous API.

[0089] It should be noted that, in the embodiments of the present application, the heterogeneous API call information indicating the efficiency of all the processing engines 210 in the heterogeneous system to call the target heterogeneous API is taken as an example for illustration. In some application scenarios, the heterogeneous API call information may also only indicate the efficiency of some of the multiple processing engines 210 in the heterogeneous system to call the target heterogeneous API.

[0090] In the embodiments of the present application, the heterogeneous API call information characterizing the efficiency of the processing engine 210 for the target heterogeneous API by the call time is taken as an example for illustration. Other ways of characterizing the efficiency can be referred to this way. The difference is that in the embodiments of the present application, the time value is used in the heterogeneous API call information to characterize the efficiency of the processing engine 210 for the target heterogeneous API, and when other ways of characterizing the efficiency are adopted, the time value can be replaced with other parameters characterizing the efficiency.

[0091] The heterogeneous API call information includes the time required for each of the multiple processing engines 210 to call one or more heterogeneous APIs respectively. The time required for the processing engine 210 to call a heterogeneous API can also be understood as the time for the processing engine 210 to execute the heterogeneous API. The one or more heterogeneous APIs include the target heterogeneous API.

[0092] The host CPU can select, based on the heterogeneous API call information, the processing engine 210 with the shortest time required to call the target heterogeneous API and currently available among the multiple processing engines 210 as the target processing engine. The host CPU can also determine, based on the heterogeneous API call information, one or more processing engines 210 among the multiple processing engines 210 whose time required to call the target heterogeneous API is less than the time threshold and currently available, and determine the target processing engine from the one or more processing engines 210. The currently available processing engine 210 refers to the processing engine 210 that is currently in an idle state and can execute the target heterogeneous API.

[0093] The heterogeneous API call information can be pre-configured in the heterogeneous system 200. The time required for each processing engine 210 included in the heterogeneous API call information to call one or more heterogeneous APIs can be determined according to empirical values or by means such as test statistics. In the embodiments of the present application, the specific information included in the heterogeneous API call information is not limited, and any information that can indicate the time required for each of the multiple processing engines 210 to call one or more heterogeneous APIs can be used as the heterogeneous API call information.

[0094] When the specific information included in the heterogeneous API call information is different, the way for the host CPU to select the target processing engine is different. The following are several ways:

[0095] (1). The heterogeneous API call information includes the identifier of the heterogeneous API and the time required for each processing engine 210 in the multiple processing engines 210 to call one or more heterogeneous APIs respectively.

[0096] The information included in the heterogeneous API call information can be seen in Table 1:

[0097] Table 1

[0098]

[0099] As can be seen from Table 1, the heterogeneous API call information includes the time required for each processing engine 210 to call M heterogeneous APIs respectively. Taking processing engine 1 as an example, the heterogeneous API call information includes the time required for processing engine 1 to call M heterogeneous APIs respectively. The required times are T11, T12,..., T1M respectively.

[0100] For different types of heterogeneous APIs, the time required for the processing engine 210 to call the heterogeneous API may also be different. For example, for a heterogeneous API used to implement convolution operations, the time for the GPU to call this heterogeneous API is shorter, and the time for the CPU to call this heterogeneous API is longer. For a heterogeneous API used to implement logical operations, the time for the GPU to call this heterogeneous API is longer, and the time for the CPU to call this heterogeneous API is shorter.

[0101] As can be seen from Table 1, the heterogeneous API call information can also include the parameter scale of each heterogeneous API. In this way, the parameter scale of each heterogeneous API can only be for reference and not used as the basis for selecting the target processing engine. For example, the parameter scales of each heterogeneous API in Table 1 can be set to the same value, that is, the time difference for the processing engine 210 to call the same heterogeneous API under different parameter scales is not considered.

[0102] Based on the heterogeneous API call information as shown in Table 1, the host CPU can determine the corresponding time information of the target heterogeneous API in the heterogeneous API call information according to the identifier of the target heterogeneous API, such as locating the row where the identifier of the target heterogeneous API in this Table 1 is located.

[0103] After the host CPU determines the time information corresponding to the target heterogeneous API in the heterogeneous API call information, it selects a target processing engine according to the time information. For example, it can select the processing engine 210 with the shortest time required to call the target heterogeneous API as the target processing engine. For example, if the target heterogeneous API is used to implement convolution operations, the host CPU can select a GPU with a shorter time required to call the target heterogeneous API as the target processing engine. If the target heterogeneous API is used to implement logical operations, the host CPU can select a CPU with a shorter time required to call the target heterogeneous API as the target processing engine.

[0104] The host CPU can also select a target processing engine based on the time information according to other selection strategies (such as a load balancing strategy, which ensures that the number of times or time of heterogeneous API call operations executed by each processing engine 210 is consistent).

[0105] (2) The heterogeneous API call information includes the identifier of the heterogeneous API, and the time required for each of the multiple processing engines 210 to call one or more heterogeneous APIs respectively. The time required for each processing engine 210 to call any heterogeneous API includes the time required for each processing engine 210 to call the heterogeneous API with one or more parameter scales (this parameter scale can also be understood as a candidate parameter scale). This parameter scale can also be understood as a candidate parameter scale. There is no limit to the number of parameter scales here, which can be one or more. The parameter scale includes the target parameter scale of the target heterogeneous API.

[0106] For the information included in the heterogeneous API call information, please refer to Table 2:

[0107] Table 2

[0108]

[0109] It can be seen from Table 2 that the heterogeneous API call information includes the time required for each processing engine 210 to call M heterogeneous APIs respectively. Taking processing engine 1 as an example, the heterogeneous API call information includes the time required for processing engine 1 to call M heterogeneous APIs respectively. The time required for processing engine 1 to call any heterogeneous API includes the time required to call the heterogeneous API with one or more parameter scales. The required times are T111, T122,..., T1M respectively. S .

[0110] As can be seen from Table 2, one or more parameter scales of each heterogeneous API are marked in the heterogeneous API call information. In this way, the parameter scale of each heterogeneous API can be used as a basis for selecting the target processing engine. The time shown in Table 2 is determined by combining the time differences of the processing engine 210 calling the same heterogeneous API under different parameter scales.

[0111] In Table 2, the parameter scale corresponding to a heterogeneous API can be all possible values or some possible values of the parameter scale of the heterogeneous API when actually calling the heterogeneous API. For example, there may be S values for the parameter scale corresponding to the heterogeneous API in Table 2. The time when the processing engine 2101 calls the heterogeneous API is marked for each value in Table 2. Taking the example that all possible values of the parameter scale of each heterogeneous API are S, in fact, the number of possible values of the parameter scale of each heterogeneous API can also be different.

[0112] Based on the heterogeneous API call information shown in Table 2, the host CPU can obtain the signature of the target heterogeneous API according to the identifier of the target heterogeneous API, and determine the target parameter scale of the target heterogeneous API from the signature of the target heterogeneous API. According to the identifier of the target heterogeneous API and the target parameter scale, determine the corresponding time information of the target heterogeneous API in the heterogeneous API call information, such as locating the row in Table 2 where the identifier of the target heterogeneous API and the target parameter scale are located. After the host CPU determines the corresponding time information of the target heterogeneous API in the heterogeneous API call information, the method of selecting the target processing engine according to the time information can refer to the relevant description in method (1) and will not be elaborated here.

[0113] Among them, when the host CPU obtains the signature of the target heterogeneous API, it can determine the signature of the target heterogeneous API from the pre-configured heterogeneous API signature set according to the identifier of the target heterogeneous API.

[0114] In Table 2, the parameter scale corresponding to a heterogeneous API can also be classifying all possible values of the parameter scale when actually calling the heterogeneous API into S categories, and each category corresponds to a value range of the parameter scale. For example, the possible values of the parameter scale corresponding to the heterogeneous API in Table 2 may be divided into S categories. The time when the processing engine 2101 calls the heterogeneous API is marked for each value range of the parameter scale in Table 2. Taking the example that all possible values of the parameter scale of each heterogeneous API can be divided into S categories, in fact, the possible values of the parameter scale of each heterogeneous API can be divided into different numbers of categories according to the specific scenario.

[0115] Based on the heterogeneous API call information shown in Table 2, the host CPU can obtain the signature of the target heterogeneous API according to the identifier of the target heterogeneous API, and determine the target parameter scale of the target heterogeneous API from the signature of the target heterogeneous API. According to the identifier of the target heterogeneous API and the target parameter scale, determine the corresponding time information of the target heterogeneous API in the heterogeneous API call information, such as locating the row where the class of the identifier and target parameter scale of the target heterogeneous API in Table 2 is located. After the host CPU determines the corresponding time information of the target heterogeneous API in the heterogeneous API call information, the method of selecting the target processing engine according to this time information can refer to the relevant description in method (1), which will not be elaborated here.

[0116] Among them, the method for the host CPU to obtain the signature of the target heterogeneous API can refer to the foregoing description and will not be elaborated here.

[0117] (3). The heterogeneous API call information includes the time required for each processing engine 210 in multiple processing engines 210 to call the heterogeneous API, and the time required for each processing engine 210 to call the heterogeneous API is a time value.

[0118] The information included in the heterogeneous API call information can be seen in Table 3:

[0119] Table 3

[0120]

[0121] It can be seen from Table 3 that the heterogeneous API call information includes the time required for each processing engine 210 to call the heterogeneous API respectively. Taking processing engine 1 as an example, the time required for processing engine 1 to call any heterogeneous API is T1. T1 can be an average value or an empirical value.

[0122] It can be seen from Table 3 that the heterogeneous API call information may not include the parameter scale of each heterogeneous API and the identifier of the heterogeneous API. In this case, the parameter scale of each heterogeneous API and the identifier of the heterogeneous API are not used as the basis for selecting the target processing engine. That is to say, the various times shown in Table 3 do not consider the time difference of the processing engine 210 calling the heterogeneous API under different heterogeneous APIs and different parameter scales.

[0123] Based on the heterogeneous API call information shown in Table 3, the host CPU can select the processing engine 210 with the shortest time required to call the heterogeneous API as the target processing engine based on the heterogeneous API call information. The host CPU can also select the target processing engine based on other selection strategies and heterogeneous API call information (such as a load balancing strategy, which is to ensure that the number of times or time of the heterogeneous API call operations executed by each processing engine 210 is the same).

[0124] It should be noted that the time required for each processing engine 210 included in the heterogeneous API call information to call one or more heterogeneous APIs can be absolute time or relative time. For example, taking the absolute time required for a certain processing engine 210 to call a heterogeneous API as a reference, the relative time required for other processing engines 210 to call one or more heterogeneous APIs is determined. The time required for each processing engine 210 to call one or more heterogeneous APIs is essentially used to characterize the efficiency of this processing engine 210 in calling heterogeneous APIs. Any time value that can characterize the efficiency of this processing engine 210 in calling heterogeneous APIs can be used as the time required for the processing engine 210 to call heterogeneous APIs, and then the heterogeneous API call information is constructed.

[0125] After the host CPU selects the target processing engine, it can execute step 203.

[0126] Optionally, after the host CPU selects the target processing engine, it can mark the status of this target processing engine as unavailable to avoid subsequently continuing to select this target processing engine to call other heterogeneous APIs. Until the target processing engine finishes calling the target heterogeneous API, the host CPU marks the status of this target processing engine as available.

[0127] Step 203: The host CPU triggers the target processing engine to call the target heterogeneous API.

[0128] When the host CPU executes step 203, it can execute the processing operations required for this target processing engine to call the target heterogeneous API. The host CPU can send the program instructions required for the target processing engine to call the target heterogeneous API to the target processing engine. It can also notify the cache address of the parameters required to call the heterogeneous API and the storage address of the return value of this heterogeneous API to the target processing engine, so that the target processing engine can obtain the parameters required to call the heterogeneous API from the cache address and store the return value of this target heterogeneous API in the corresponding storage address.

[0129] Before the host CPU can send the program instructions required for the target processing engine to call the target heterogeneous API to the target processing engine, the host CPU needs to first determine the program instructions required for the target processing engine to call the target heterogeneous API. Embodiments of this application provide two ways to determine the program instructions required for the target processing engine to call the target heterogeneous API:

[0130] Method 1: Heterogeneous API libraries of each processing engine 210 are pre-configured in the heterogeneous system 200.

[0131] As Figure 3 shown, a signature set of the heterogeneous API and heterogeneous API libraries of each processing engine 210 are pre-configured in the heterogeneous system 200.

[0132] The host CPU can select the program instructions required for the target processing engine to call the target heterogeneous API from the heterogeneous API library of the target processing engine.

[0133] The heterogeneous API library of the processing engine 210 includes the identifier of the heterogeneous API and the program instructions required for the processing engine 210 to call the target heterogeneous API. The host CPU selects the program instructions required for the target processing engine to call the target heterogeneous API from the heterogeneous API library of the target processing engine according to the identifier of the target heterogeneous API.

[0134] Method 2: Heterogeneous API libraries of each processing engine 210 are not configured in the heterogeneous system 200, and the host CPU pre-stores the intermediate representation of the target heterogeneous API.

[0135] As Figure 4 shown, the compiler 100 can pre-compile the source program including the target heterogeneous API to generate the intermediate representation of the target heterogeneous API. The host CPU in the heterogeneous system 200 can pre-store the intermediate representation of the target heterogeneous API. Embodiments of this application do not limit the way in which the host CPU in the heterogeneous system 200 can pre-configure the intermediate representation of the target heterogeneous API. For example, the host CPU in the heterogeneous system 200 pre-stores the intermediate representations of one or more heterogeneous APIs, where the intermediate representations of the one or more heterogeneous APIs include the intermediate representation of the target heterogeneous API. Another example is that the host CPU in the heterogeneous system 200 configures the intermediate representations of one or more heterogeneous APIs under the trigger of the user, where the intermediate representations of the one or more heterogeneous APIs include the intermediate representation of the target heterogeneous API.

[0136] When the host CPU determines that the target heterogeneous API needs to be called, it can compile the intermediate representation of the target heterogeneous API into program instructions required for the target processing engine to call the target heterogeneous API, and send them to the target processing engine.

[0137] In this method, the host CPU (which can also be understood as the heterogeneous runtime) has the dynamic compilation function. In the embodiments of the present application, the heterogeneous API call information may also indicate the storage address of the intermediate representation of the target heterogeneous API. Taking the first representation method of the heterogeneous API call information in the foregoing description as an example.

[0138] Referring to Table 4, the heterogeneous API call information also includes the storage addresses of the intermediate representations of one or more heterogeneous APIs.

[0139] Table 4

[0140]

[0141]

[0142] As can be seen from Table 4, the heterogeneous API call information includes the time required for each processing engine 210 to call M heterogeneous APIs respectively, and the storage addresses of the intermediate representations of the M heterogeneous APIs. The storage addresses of the intermediate representations of the M heterogeneous APIs are storage address 1, storage address 2,..., storage address M respectively.

[0143] After the host CPU determines the target processing engine that needs to call the target heterogeneous API, it can obtain the storage address of the intermediate representation of the target heterogeneous API from the heterogeneous API call information, and then obtain the intermediate representation of the target heterogeneous API according to the storage address of the intermediate representation of the target heterogeneous API.

[0144] It should be noted that the above method of indicating the storage address of the intermediate representation of the heterogeneous API in the heterogeneous API call information is only an example, and the embodiments of the present application do not limit the method of indicating the storage address of the intermediate representation of the heterogeneous API in the heterogeneous API call information.

[0145] Generally, for the same heterogeneous API, the program instructions for the same processing engine to call the heterogeneous API with different parameter scales may also be different. This is because when the host CPU compiles the intermediate representation of the heterogeneous API, it will make adjustments according to the parameter scale, and perform different memory layouts and loop optimizations on the program instructions, resulting in differences in the program instructions for the same processing engine to call the heterogeneous API with different parameter scales.

[0146] In an embodiment of the present application, after the host CPU compiles the intermediate representation of the target heterogeneous API into program instructions required for the target processing engine to call the target heterogeneous API, the host CPU may also cache the program instructions required for the target processing engine to call the target heterogeneous API. So that when the host CPU determines again that the target processing engine needs to call the target heterogeneous API, the host CPU can directly obtain the cached program instructions required for the target processing engine to call the target heterogeneous API.

[0147] After each time the host CPU compiles the intermediate representation of a heterogeneous API into program instructions required for a processing engine to call the heterogeneous API, the host CPU may store the compiled program instructions required for the processing engine to call the heterogeneous API. Optionally, when the host CPU stores the compiled program instructions required for the processing engine to call the heterogeneous API, it may also identify the identifier of the heterogeneous API and the parameter scale.

[0148] Optionally, the host CPU may store the program instructions required for different processing engines 210 to call a heterogeneous API that have been compiled into the heterogeneous API call information. That is, the heterogeneous API call information may indicate the cache addresses of the program instructions required for multiple processing engines to call the heterogeneous API, and the heterogeneous API includes the target heterogeneous API. For different parameter scales, the cache address of the program instructions required for each processing engine to call the heterogeneous API includes the cache addresses of the program instructions required for the processing engine to call the heterogeneous API with different parameter scales.

[0149] Taking the second representation method of the heterogeneous API call information in the foregoing description as an example, referring to Table 5, the heterogeneous API call information also includes the cache addresses of the program instructions required for multiple processing engines to call the heterogeneous API.

[0150] Table 5

[0151]

[0152]

[0153] As can be seen from Table 5, the heterogeneous API call information includes the time required for each processing engine 210 to call M heterogeneous APIs respectively and the cache addresses of the program instructions required for multiple processing engines to call M heterogeneous APIs. Taking processing engine 1 as an example, the heterogeneous API call information includes the time required for processing engine 1 to call M heterogeneous APIs respectively and the cache addresses of the program instructions required for the processing engine to call M heterogeneous APIs. The time required for processing engine 1 to call any heterogeneous API includes the time required to call the heterogeneous API with different parameter scales. The required times are T111, T122,..., T1M respectively. S。The cache addresses of the program instructions required for the processing engine 1 to call a heterogeneous API include the cache addresses of the program instructions required for the processing engine 1 to call this heterogeneous API with different parameter scales. The cache addresses are respectively cache address 11, cache address 12,..., cache address 13.

[0154] In the above description, an example is given where the heterogeneous API call information includes the cache addresses of the program instructions required for each processing engine to call each heterogeneous API. In practical applications, the heterogeneous API call information may also only include the cache addresses of the program instructions required for some processing engines to call one or more heterogeneous APIs. That is, the heterogeneous API call information may only include the cache addresses of the program instructions required for some processing engines to call multiple heterogeneous APIs, or may include the cache addresses of the program instructions required for some processing engines to call some heterogeneous APIs. In addition, the information in the heterogeneous API call information (such as the time required for each processing engine 210 to call different heterogeneous APIs, the cache addresses of the program instructions required for each processing engine 210 to call different heterogeneous APIs, etc.) can be updated in real time.

[0155] When the heterogeneous API call information includes the cache addresses of the program instructions required for each processing engine to call multiple heterogeneous APIs, after the host CPU determines the target processing engine that needs to call the target heterogeneous API, it determines whether there is a cache address of the program instructions required for the target processing engine to call the target heterogeneous API in the heterogeneous API call information, that is, determines whether there is a cache address of the program instructions required for the target processing engine to call the target heterogeneous API with the target parameter scale. If it exists, the program instructions required for the target processing engine to call the target heterogeneous API with the target parameter scale are obtained according to this cache address. If it does not exist, the intermediate representation of the target heterogeneous API is compiled into the program instructions required for the target processing engine to call the target heterogeneous API, and the program instructions required for the target processing engine to call the target heterogeneous API can also be cached, and the cache address of the program instructions required for the target processing engine to call the target heterogeneous API is stored in the heterogeneous API call information.

[0156] Based on the same inventive concept as the method embodiment, an embodiment of the present application further provides an API call device for executing the method executed by the host CPU in the above method embodiment. The related features can be seen in the above method embodiment and will not be elaborated here. As Figure 5 shown, the heterogeneous API call device 500 includes a determination unit 501, a selection unit 502. Optionally, it may further include an instruction determination unit 503 and a sending unit 504;

[0157] The determination unit 501 is used to determine the target API to be called.

[0158] A selection unit 502, configured to select a first processing engine for invoking a target API based on API call information, where the API call information is used to indicate the efficiency of the first processing engine and the second processing engine in invoking the target heterogeneous API respectively.

[0159] The above API call apparatus 500 can be used to execute Figure 2 the method executed by the host CPU shown in the figure. Among them, the determination unit 501 can execute step 201 in the embodiment shown in Figure 2 the figure; the selection unit 502 can execute step 202 in the embodiment shown in Figure 2 the figure; the instruction determination unit 503 can execute the method for determining the program instructions required for the target processing engine to invoke the target heterogeneous API in step 203 in the embodiment shown in Figure 2 the figure, and the sending unit 504 can execute the method for sending the program instructions required for the target processing engine to invoke the target heterogeneous API to the target processing engine in step 203 in the embodiment shown in Figure 2 the figure.

[0160] It should be noted that the division of units in the embodiments of this application is illustrative, merely a logical function division. In actual implementation, there may be other division methods. Each functional unit in the embodiments of this application can be integrated in one processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above integrated units can be implemented in the form of hardware or in the form of software functional units.

[0161] If the above integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to execute all or part of the steps of the methods described in the embodiments of this application. The foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), magnetic disks, or optical discs that can store program codes.

[0162] In a simple embodiment, those skilled in the art can think that the API call apparatus 500 in the above embodiments can all adopt Figure 6 the form shown in the figure.

[0163] As Figure 6 shown, the computing device 600 includes at least one processor 610 and a memory 620. Optionally, a communication interface 630 may also be included.

[0164] The memory 620 may be a volatile memory, such as a random access memory; the memory may also be a non-volatile memory, such as a read-only memory, a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD), or the memory 620 is any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory 620 may be a combination of the above memories.

[0165] In the embodiments of the present application, the specific connection medium between the above-mentioned processor 610 and the memory 620 is not limited. The processor 610 may be a processing engine in the heterogeneous system 200, such as a CPU.

[0166] In the computing device as Figure 6 shown, a communication interface 630 is further included. When the processor 610 communicates with other devices, such as a compiler 100 or other processing engines 210, data transmission can be performed through the communication interface 630.

[0167] When the API call device 500 adopts the Figure 6 form shown, Figure 6 the processor 610 in it can call the computer-executable instructions stored in the memory 620, so that the device 600 can execute the methods executed by the host CPU in any of the above method embodiments; for example, the device 600 can execute the Figure 2 methods executed by the host CPU in steps 201 to 203 in the method embodiment shown.

[0168] Specifically, Figure 5 the functions / implementation processes of the determination unit 501, the selection unit 502, the instruction determination unit 503, and the sending unit 504 in it can all be implemented by Figure 6 the processor 610 in it calling the computer-executable instructions stored in the memory 620. Or, Figure 5 the functions / implementation processes of the determination unit 501, the selection unit 502, and the instruction determination unit 503 in it can be implemented by Figure 6 the processor 610 in it calling the computer-executable instructions stored in the memory 620, Figure 6 the function / implementation process of the sending unit 504 in it can be implemented by Figure 6 the communication interface 630 in it.

[0169] When the API calling device 500 adopts Figure 6 the form shown, Figure 6 the processor 610 in Figure 2 can execute the method executed by the host CPU in any of the above method embodiments by calling the computer-executable instructions stored in the memory 620; for example, the computing device 600 can execute

[0170] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0171] The present application is described with reference to the flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each flow and / or block in the flowchart and / or block diagram can be implemented by computer program instructions, and the combination of the flows and / or blocks in the flowchart and / or block diagram can also be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing devices generate a device for implementing the functions specified in one or more flows in the flowchart and / or one or more blocks in the block diagram.

[0172] These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory generate a manufactured product including an instruction device, and the instruction device implements the functions specified in one or more flows in the flowchart and / or one or more blocks in the block diagram.

[0173] These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more flows in the flowchart and / or one or more blocks in the block diagram.

[0174] Obviously, those skilled in the art can make various modifications and variations to the embodiments of the present application without departing from the scope of the embodiments of the present application. Thus, if these modifications and variations of the embodiments of the present application fall within the scope of the claims of the present application and their equivalent technologies, the present application also intends to include these modifications and variations.

Claims

1. A heterogeneous application program interface (API) calling method, characterized in that: The method is applied to a heterogeneous system, the heterogeneous system including a first processing engine and a second processing engine, and the method includes: Determine the target API that needs to be called; Selecting the first processing engine to call the target API based on API call information, wherein the API call information is used to indicate efficiency of the first processing engine and the second processing engine in calling the target API respectively; Obtaining, according to a cache address of the program instructions required by the first processing engine to call the target API and a target parameter size of the target API, the program instructions required by the first processing engine to call the target API; The program instructions are sent to the first processing engine.

2. The method according to claim 1, wherein The selecting the first processing engine to call the target API based on the API call information includes: Obtaining a signature of the target API, where the signature of the target API is used to indicate a target parameter scale of the target API; The first processing engine is selected based on the API call information and the target parameter scale of the target API, wherein the API call information indicates efficiency of the first processing engine and the second processing engine in calling the target API with candidate parameter scales, the candidate parameter scales including the target parameter scale.

3. The method according to claim 2, wherein The obtaining of the signature of the target API includes: Determining the identity of the target API; The signature of the target API is determined from a pre-configured API signature set according to the identifier of the target API.

4. The method according to any one of claims 1 to 3, wherein The method further comprises: Obtaining, from a pre-configured API function library of the first processing engine, program instructions required for the first processing engine to call the target API, the API function library of the first processing engine including program instructions required for the first processing engine to call one or more APIs, the one or more APIs including the target API; Sending to the first processing engine program instructions required for the first processing engine to call the target API.

5. The method according to any one of claims 1 to 3, wherein The method further comprises: Obtaining a pre-stored intermediate representation of the target API; Compiling the intermediate representation of the target API into program instructions required by the first processing engine to call the target API; Sending to the first processing engine program instructions required for the first processing engine to call the target API.

6. The method according to claim 5, wherein The API call information is further used to indicate a storage address of an intermediate representation of the target API. The obtaining of the pre-stored intermediate representation of the target API includes: The intermediate representation of the target API is obtained according to the storage address of the intermediate representation of the target API.

7. The method according to any one of claims 1 to 3 and 6, characterized in that: The API call information is stored in a table format.

8. The method according to any one of claims 1 to 3, wherein: The API call information is further used to indicate cache addresses of program instructions required by the first processing engine and the second processing engine to respectively call the target API. The method further includes: The program instructions required by the first processing engine to call the target API are obtained according to the cache address of the program instructions required by the first processing engine to call the target API in the API call information.

9. An API calling device, characterized in that: The device is used to select a processing engine for calling a target API from a heterogeneous system, the heterogeneous system including a first processing engine and a second processing engine, and the device includes: A determination unit, used to determine the target API to be called; a selection unit, configured to select the first processing engine for calling the target API based on API call information, wherein the API call information is used to indicate efficiency of the first processing engine and the second processing engine in calling the target API respectively; an instruction determining unit, configured to obtain, based on a cache address of the program instruction required by the first processing engine to call the target API and a target parameter size of the target API, the program instruction required by the first processing engine to call the target API; A sending unit is used to send the program instruction to the first processing engine.

10. The device according to claim 9, wherein When the selection unit selects the first processing engine to call the target API based on the API call information, the selection unit is specifically configured to: Obtaining a signature of the target API, where the signature of the target API is used to indicate a target parameter scale of the target API; The first processing engine is selected based on the API call information and the target parameter scale of the target API, wherein the API call information indicates efficiency of the first processing engine and the second processing engine in calling the target API with candidate parameter scales, the candidate parameter scales including the target parameter scale.

11. The device according to claim 10, wherein When obtaining the signature of the target API, the selection unit is specifically configured to: Determining the identity of the target API; The signature of the target API is determined from a pre-configured API signature set according to the identifier of the target API, wherein the target API signature includes the identifier of the target API.

12. The device according to any one of claims 9 to 11, characterized in that The device further comprises an instruction determining unit and a sending unit: The instruction determination unit is configured to obtain, from a pre-configured API function library of the first processing engine, program instructions required for the first processing engine to call the target API, the API function library of the first processing engine including program instructions required for the first processing engine to call an API, and the API including the target API; The sending unit is configured to send, to the first processing engine, program instructions required for the first processing engine to call the target API.

13. The device according to any one of claims 9 to 11, characterized in that The device further comprises an instruction determining unit and a sending unit: The instruction determination unit is configured to obtain a pre-stored intermediate representation of the target API; and compile the intermediate representation of the target API into program instructions required by the first processing engine to call the target API; The sending unit is configured to send, to the first processing engine, program instructions required for the first processing engine to call the target API.

14. The device according to claim 13, wherein The API call information is further used to indicate the storage address of the intermediate representation of the target API. When the instruction determination unit obtains the pre-stored intermediate representation of the target API, it is specifically used to: The intermediate representation of the target API is obtained according to the storage address of the intermediate representation of the target API.

15. The device according to any one of claims 9 to 11 and 14, characterized in that: The API call information is stored in a table format.

16. The device according to any one of claims 9 to 11, characterized in that: The API call information indicates cache addresses of program instructions required for the first processing engine and the second processing engine to respectively call the target API, and the instruction determination unit is further configured to: The program instructions required by the first processing engine to call the target API are obtained according to the cache address of the program instructions required by the first processing engine to call the target API in the API call information.

17. A computing device, characterized in that: The computing device includes a memory and a processor, wherein the memory is used to store computer instructions; the processor calls the computer instructions stored in the memory to execute any one of the methods described in claims 1 to 8.

Citation Information

Patent Citations

  • Methods and apparatus for scheduling data stream tasks

    CN105900064B

  • API calling method and device

    CN118642826A