Function execution method and device and computing equipment

By identifying the operating mode of the computing device and dynamically adjusting the concurrency of the functions, the concurrent execution efficiency and security problems on the equipment with rich and tight computing resources are solved, and more efficient and safe function execution is achieved.

CN119201291APending Publication Date: 2024-12-27HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310750386.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-06-25
Publication Date
2024-12-27

AI Technical Summary

Technical Problem

The prior art is difficult to effectively manage the concurrent execution of functions on devices with abundant computing resources and tight computing resources, resulting in efficiency and security issues, especially when concurrent execution consumes a lot of resources, which may reduce data processing efficiency and increase the probability of errors.

Method used

By identifying the operating mode of computing devices, dynamically adjusting the concurrency of functions, using cache utilization and thread management to optimize function execution, including allocating additional threads at high loads and recycling threads at low loads, ensuring resource utilization and efficiency balance.

Benefits of technology

It improves the adaptability and efficiency of function execution, reduces resource consumption and error probability, and adapts to the needs of different computing environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119201291A_ABST
    Figure CN119201291A_ABST
Patent Text Reader

Abstract

The invention discloses a function execution method and device and computing equipment. The method comprises the steps that before a program runs, the running mode of the program on the computing device is recognized as a first mode; in the first mode, when the first function is executed by a first thread of the computing device, the cache utilization rate of the first function is obtained; when the cache utilization rate of the first function is greater than a first threshold value, allocating a second thread of the computing device to the first function; instructing the first thread and the second thread to execute the first function at the same time; wherein the first thread processes a part of data in a cache of the first function by executing the first function, and the second thread processes the other part of data in the cache of the first function by executing the first function. The method can improve the adaptability of concurrent execution of functions in the program.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a function execution method, device and computing equipment. Background Art

[0002] The concurrent execution of functions in a computer program can process multiple processing requests at the same time, which can improve data processing efficiency. However, the concurrent execution of functions consumes a lot of computing resources. For computing devices with limited computing resources, the concurrent execution of functions may reduce data processing efficiency and the probability of data processing errors may also be high.

[0003] Programs may run on computing devices with different computing resources. How to improve the concurrency of functions on computing devices with rich computing resources and reduce the concurrency of function execution on computing devices with limited computing resources is a problem that the industry is concerned about. Summary of the invention

[0004] The present application provides a function execution method, apparatus and computing device, which can improve the adaptability of concurrent execution of functions in a program.

[0005] In a first aspect, a function execution method is provided, which is applied to a computing device running a program, wherein the program includes a first function; the method includes: before running the program, identifying that the running mode of the program on the computing device is a first mode; in the first mode, when the first function is executed by a first thread of the computing device, obtaining the cache utilization of the first function; when the cache utilization of the first function is greater than a first threshold, allocating a second thread of the computing device to the first function; instructing the first thread and the second thread to execute the first function simultaneously; wherein the first thread processes a portion of data in the cache of the first function by executing the first function, and the second thread processes another portion of data in the cache of the first function by executing the first function.

[0006] In this method, before the program is run, the running mode of the program on the current computing device can be identified, and the functions in the program are executed according to the running mode, thereby improving the adaptability of concurrent execution of functions in the program.

[0007] The first mode is a balanced mode of efficiency and resource conservation, and the cache utilization of the function reflects the load of the function. When the program is identified as running in the first mode on the current computing device, a new thread can be allocated to the function when the function load is heavy. The new thread and the original thread execute the function at the same time, which improves the concurrency of the function, thereby enabling the data to be processed by the function to be processed in a timely manner, thereby improving the execution efficiency.

[0008] In one possible implementation, the output of a first function is the input of a second function in a program; when the cache utilization of the first function is greater than a first threshold, allocating a second thread of a computing device to the first function includes: when the cache utilization of the first function is greater than the first threshold, predicting the cache utilization of the second function when the first thread and the second thread execute the first function simultaneously; when the prediction result is not greater than the second threshold, allocating the second thread to the first function.

[0009] That is to say, when increasing the concurrency of the first function, consider the load of the second function after the concurrency of the first function is increased. If the load of the second function becomes too heavy, the concurrency of the first function will not be increased to avoid the second function becoming the efficiency bottleneck of the entire program in processing data, thereby avoiding the situation where the efficiency of program data processing cannot be improved when the resource input is increased.

[0010] In one possible implementation, when the cache utilization of the first function is greater than a first threshold, allocating a second thread of the computing device to the first function includes: when the cache utilization of the first function is greater than the first threshold, obtaining the total number of execution threads of the program; when the total number is less than an upper limit on the number of threads, allocating the second thread of the computing device to the first function.

[0011] In this implementation, when allocating a new thread to the first function, the total number of execution threads of the program is taken into consideration to avoid the situation where, after allocating a new thread to the first function, the number of execution threads of the program exceeds the total number, thereby increasing the thread scheduling burden and causing the overall execution rate of the program to decrease.

[0012] In a possible implementation, the first thread is a plurality of threads, and the method further includes: when the cache utilization of the first function is not greater than a third threshold, reclaiming some threads in the first thread, and the third threshold is less than the first threshold.

[0013] In this implementation, in the first mode, when the load of the first function is light, some threads executing the first function may be recycled to save resources without affecting the efficiency of the first function in processing data.

[0014] In one possible implementation, the method further includes: before running the program, identifying that the running mode of the program on the computing device is a second mode; in the second mode, whenever a processing request for the program is received, creating a third thread for the processing request, and instructing the third thread to process the data requested by the processing request by executing a function in the program.

[0015] The second mode is a resource-saving mode, in which one or more fixed threads are used to execute functions in the program to save resources, so that on a computing device with limited resources, the execution of the program will not occupy too many resources of the computing device.

[0016] In one possible implementation, the method further includes: before running the program, identifying that the running mode of the program on the computing device is a third mode; in the third mode, instructing the fourth thread to process the data requested to be processed by all processing requests for the program by executing functions in the program.

[0017] The third mode is the efficiency priority mode. Whenever a data processing request is received, a thread dedicated to processing the data processing request is allocated, thereby improving the efficiency of data processing.

[0018] In one possible implementation, the source code of the program includes a graph structure, the first function is a first node in the graph structure, the second function is a second node in the graph structure, and the graph structure includes a connecting edge from the first node toward the second node, and the connecting edge indicates that the output of the first function is the input of the second function.

[0019] In this implementation, the function execution method provided by the present application can be used to execute a data flow program.

[0020] In a possible implementation, the first node is associated with a usage list, and the usage list is used to declare shared variables of the first function; the method also includes: before compiling the source code, when it is detected that at least one shared variable of the first function is not included in the usage list, reporting an error.

[0021] In this implementation, the shared variables of the function are included in the use list, indicating that the programmer noticed the shared variables when writing the code. If the shared variables are not included in the use list, the programmer may not have noticed the shared variables when writing the code. By detecting whether the shared variables of the function are included in the use list and performing security detection, it can help programmers avoid potential data competition and improve the security of program execution.

[0022] In a possible implementation, the method further includes: compiling the first node and the connecting edge into an executable version of the first function; the executable version of the first function includes the code of the first function and the data dependency relationship between the first function and the second function.

[0023] In this implementation, the operations to be performed and the data dependencies are compiled into the executable version of the function, so that the function can be executed correctly.

[0024] In a second aspect, a function execution device is provided, which is configured on a computing device running a program, and the program includes a first function; the device includes: an identification unit, which is used to identify that the running mode of the program on the computing device is a first mode before running the program; an acquisition unit, which is used to acquire the cache utilization of the first function when the first function is executed by the first thread of the computing device in the first mode; an allocation unit, which is used to allocate the second thread of the computing device to the first function when the cache utilization of the first function is greater than a first threshold; an indication unit, which is used to indicate the first thread and the second thread to execute the first function simultaneously; wherein the first thread processes a part of the data in the cache of the first function by executing the first function, and the second thread processes another part of the data in the cache of the first function by executing the first function.

[0025] In one possible implementation, the output of the first function is the input of the second function in the program; the allocation unit is used to: when the cache utilization of the first function is greater than a first threshold, predict the cache utilization of the second function when the first thread and the second thread execute the first function simultaneously; when the prediction result is not greater than the second threshold, allocate the second thread to the first function.

[0026] In one possible implementation, the allocation unit is used to: when the cache utilization of the first function is greater than a first threshold, obtain the total number of execution threads of the program; when the total number is less than an upper limit on the number of threads, allocate a second thread of the computing device to the first function.

[0027] In a possible implementation, the first thread is a plurality of threads, and the device further includes: a recycling unit, configured to recycle some threads in the first thread when the cache utilization of the first function is not greater than a third threshold, and the third threshold is less than the first threshold.

[0028] In one possible implementation, the identification unit is further used to identify that the running mode of the program on the computing device is the second mode before running the program; the allocation unit is further used to create a third thread for the processing request whenever a processing request for the program is received in the second mode; the instruction unit is further used to instruct the third thread to process the data requested to be processed by executing a function in the program.

[0029] In one possible implementation, the identification unit is further used to identify that the running mode of the program on the computing device is the third mode before running the program; the instruction unit is further used to instruct the fourth thread to process the data requested to be processed by all processing requests for the program by executing functions in the program in the third mode.

[0030] In one possible implementation, the source code of the program includes a graph structure, the first function is a first node in the graph structure, the second function is a second node in the graph structure, and the graph structure includes a connecting edge from the first node toward the second node, and the connecting edge indicates that the output of the first function is the input of the second function.

[0031] In a possible implementation, the first node is associated with a usage list, which is used to declare shared variables of the first function; the device also includes: a checking unit, which is used to report an error when it is checked before compiling the source code that at least one shared variable of the first function is not included in the usage list.

[0032] In a possible implementation, the device also includes: a compilation unit, used to compile the first node and the connecting edge into an executable version of the first function; the executable version of the first function includes the code of the first function, and the data dependency relationship between the first function and the second function.

[0033] According to a third aspect, a computing device is provided, comprising a processor and a memory; wherein the memory stores computer instructions, and the processor is used to execute the computer instructions to implement the method provided in the first aspect.

[0034] According to a fourth aspect, a computer-readable storage medium is provided, characterized in that it includes computer program instructions. When the computer program instructions are executed by a computing device, the computing device executes the method provided in the first aspect.

[0035] In a fifth aspect, a computer program product is provided, comprising a program for implementing the method provided in the first aspect.

[0036] The beneficial effects of the second to fifth aspects can be referred to the above introduction to the beneficial effects of the first aspect, and will not be repeated here.

[0037] Based on the implementations provided in the above aspects, this application can also be further combined to provide more implementations. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 A schematic diagram of code writing, compiling and executing provided in an embodiment of the present application;

[0039] Figure 2A A schematic diagram for explaining semantic rules provided in an embodiment of the present application;

[0040] Figure 2B A schematic diagram for explaining semantic rules provided in an embodiment of the present application;

[0041] Figure 2C A schematic diagram for explaining semantic rules provided in an embodiment of the present application;

[0042] Figure 2D A schematic diagram for explaining semantic rules provided in an embodiment of the present application;

[0043] Figure 2E A schematic diagram for explaining semantic rules provided in an embodiment of the present application;

[0044] Figure 3 A schematic diagram of a security check rule provided in an embodiment of the present application;

[0045] Figure 4 A code conversion flow chart provided for an embodiment of the present application;

[0046] Figure 5 A code conversion flow chart provided for an embodiment of the present application;

[0047] Figure 6 A flowchart of a code execution method provided in an embodiment of the present application;

[0048] Figure 7 A schematic diagram of a code execution method provided in an embodiment of the present application;

[0049] Figure 8 A flowchart of code writing, compiling and executing provided in an embodiment of the present application;

[0050] Fig. 9 A schematic diagram of code writing, compiling and executing provided in an embodiment of the present application;

[0051] Fig.10 A flowchart of a code execution method provided in an embodiment of the present application;

[0052] Fig.11 A schematic diagram of a code execution device provided in an embodiment of the present application;

[0053] Fig.12 A schematic diagram of the structure of a computing device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0054] The technical solutions in the embodiments of the present application will be described below in conjunction with the accompanying drawings, wherein "multiple" refers to two or more.

[0055] A computer program may be referred to as a program, and includes multiple functions. The multiple functions share different functions in the program. By executing the functions, the functions of the program can be realized. Usually, a function is executed by a thread. A thread can process an input of a function by executing the function. Multiple threads can simultaneously execute a function and process multiple inputs of the function, wherein each thread executes the function and processes one input of the function. The simultaneous execution of a function by multiple threads can be referred to as concurrent execution of the function.

[0056] In a solution A, in order to implement concurrent execution of functions in a computing device, a programmer writes code in a program to instruct the functions in the program to execute concurrently. Specifically, the programmer inserts a concurrency control function in the program. When the computing device is running the program, when the concurrency control function is executed, additional threads can be allocated to other executing functions so that other executing functions can be executed concurrently.

[0057] This solution requires programmers to write code in the program and understand the source code of the program, which places high demands on programmers. In addition, writing code in the program is an intrusive modification of the program, which may damage the program, causing the program to fail to run or make it difficult to implement the intended functions.

[0058] In addition, embodiments of the present application also relate to data flow programming. In current data flow programming, a data flow framework (responsive framework (reactiveX, Rx)) implemented in the language is generally provided as a tripartite library for different languages. However, the current data flow framework uses the language native syntax to write data flow programs, making the data flow relationship unclear. And existing work has weak support for concurrent execution, and developers are often required to achieve concurrent execution by writing code (i.e., Solution A). Moreover, the function execution security in programs written using the current data flow framework is not guaranteed. Specifically, a function has shared variables, and when a function is executed by multiple threads, the modification of the shared variables by the multiple threads may be a conflict. However, the current data flow framework lacks reminders for shared variables, which causes programmers to be unaware of shared variables when writing programs, and thus no relevant constraints are made on the shared variables of the function, resulting in a lack of guarantee for the function execution security.

[0059] In addition, the current data flow framework is a third-party library, which makes the written data flow program poorly readable and misleading in data dependency. Take the program shown below as an example.

[0060] "s1 = x.map(...)

[0061] s2 = y.map(...)

[0062] s3 = z.map(...)

[0063] s1.zip(s2)

[0064] .zip(s3)

[0065] .map(...)

[0066] .map(...)"

[0067] In this program, variables s2 and s3 appear as method call parameters of variable s1. In fact, s1 does not depend on s2, and the data flows represented by the two variables are completely independent. Variables s2 and s3 appear as method call parameters of variable s1, which can easily lead to the misconception that s1 depends on s2 and s3.

[0068] In view of the above situation, an embodiment of the present application provides an embedded domain specific language (eDSL) and a function execution scheme. Among them, the eDSL can be used by programmers to write data flow programs and can be used to construct data flow graphs. The function execution scheme can decouple the writing of programs (such as the writing of data flow programs or the communication of data flow graphs) and the execution mode of programs. In short, there is no need to write code in the program to achieve changes in the program operation mode (such as concurrent execution or cancellation of concurrent execution of functions). In other words, there is no need to make intrusive modifications to the program to achieve changes in the program operation mode.

[0069] Next, the eDSL and function execution solution provided in the embodiments of the present application are described in detail.

[0070] First, some technical terms that may be involved in the embodiments of the present application are introduced.

[0071] Dataflow programming: Dataflow programming is a programming paradigm that abstractly models a program as a directed graph. The nodes in the graph represent functions, and the edges between nodes describe the flow of data between functions. Functions are used to perform operations, i.e., data calculations and other processing.

[0072] Data flow program: A program written using data flow programming, where nodes in a directed graph represent functions, and the edges between nodes describe the flow of data between functions.

[0073] Responsive programming: Responsive programming belongs to the category of data flow programming. It usually uses a declarative programming paradigm to write data flow transmission and data transformation.

[0074] Data flow graph: The logical structure of a data flow program can be reflected through a graph structure. The nodes in the graph are functions that process data, and the edges in the graph are the flow relationships of data between functions.

[0075] Program concurrency: Program concurrency means that different parts of a program can be executed in a non-serial manner. Usually, the concurrently executed codes form a partial order relationship rather than a strict sequential relationship.

[0076] Host language: A new customized domain-related programming language is designed in an existing programming language. The original language is called the host language, and the new customized language is called eDSL. The eDSL provided in the embodiment of the present application can be used to write data flow programs, and the eDSL can be called data flow eDSL.

[0077] Code annotation: usually a syntax provided by the compiler. Developers use annotations to mark meta-information in the code. After receiving the meta-information, the compiler can perform specific compilation processes on the code, such as specific semantic checks or code transformations.

[0078] Code transformation: During the program compilation process, the original code structure is changed, and then the new code structure is obtained and continued to be used for compilation.

[0079] See also Figure 1 In some embodiments, the eDSL 100 may be designed using a language related to data flow programming and used to write data flow programs. That is, the data flow eDSL 100 is a domain-specific language for data flow programming based on a host language. The host language may be Java, C, or Cangjie. R○ Coding language, etc.

[0080] eDSL 100 has a preset syntax. The syntax is used to enhance the convenience of writing data flow graphs. Among them, the eDSL 100 syntax is mainly used to define data flow operations and construct data flow direction relationships.

[0081] The syntax of eDSL 100 defines function tags. When performing data flow programming, programmers can add function tags to a function in the host language to identify the function as a node in the data flow program, thereby converting the function in the host language into a data flow operation. When compiling, the compiler can treat the code with the function tag as a function. In an example, the syntax of eDSL 100 can be shown in Table 1.

[0082] Table 1

[0083]

[0084]

[0085] “@FlowOp” is a possible implementation form of the function tag. “op” stands for operation. Operations are performed by functions, so “op” can also stand for functions. “stream” stands for data stream. In addition, data stream can be referred to as stream(s).

[0086] Using function tags to mark host language functions has the following advantages.

[0087] a1. Programmers can fully use the expressive power of the host language to write data processing logic;

[0088] a2. Function notation is easy to use. By adding only a few annotations, data flow operations can be obtained. The writing operation is (almost) equivalent to writing functions directly in the host language.

[0089] a3. The existing code is highly reusable and can be used in data flow programming without invasive modification.

[0090] In some embodiments, a function tag is followed by a usage list. The usage list is used to declare the shared variables used by the function carrying the function tag. Exemplarily, the usage list is used to declare the shared variables used by the function in a display declaration manner. Specifically, the programmer is required to add the shared variables used by the function to the declaration list to indicate that the programmer has noticed the shared variables when writing the program, so that the shared variables are set or preset accordingly to avoid security issues in program execution. Among them, shared variables refer to variables that are not specific to a function, and the modification of shared variables by a function may affect the execution of other functions. Therefore, in order to ensure the safe execution of the program, the programmer is required to set or constrain the shared variables of the function accordingly when writing the program (for example, implement correct thread synchronization measures for shared variables).

[0091] Among them, the usage list is used for the compiler to check the shared variables when compiling the source code, to prevent the programmer from misusing the undeclared shared variables, thereby assisting the programmer to reduce concurrent programming errors.

[0092] eDSL 100 provides two operators for constructing data flow relations, namely "inflow" and "combine". "Inflow" is used to construct edge relations in a data flow graph, and "combine" is used to construct a subgraph of a data flow.

[0093] In some embodiments, the symbol for "inflow" is "|>", which is used to represent "the connection between a stream and an operation". For example, "s|>op" means that the data in stream s will continuously flow into the operation op. The inflow symbol can not only be used to represent the connection between a single stream and an operation, but also to merge multiple streams at the same time. The syntax allows multiple streams to be combined together through brackets and flow into an operation uniformly, such as "(s1,...,sn)|>op".

[0094] In some embodiments, the symbol "~>" of "combination" is used to indicate "two operations are combined to obtain a new operation", and the data processing logic of the new operation is a sequential combination of the two operations. For example, "op1~>op2" obtains a new operation op3. op3 can receive the flow s|>op3 through the inflow symbol, and the processing of data by op3 is equivalent to the processing of op1 and op2 in sequence. Through the symbol of "combination", eDSL 100 provides the ability to construct a data flow subgraph. The programmer can first construct a partial graph structure in the data flow graph, and then connect the flow to the subgraph.

[0095] In the semantic part, eDSL 100 needs to introduce a basic type "stream" (i.e. "stream" or "s"), which is represented by the symbol ρ. Stream abstracts "continuous data". When a stream is connected to an operation, it means that the data in the stream will be continuously received and processed by the operation. Considering that data has different types, such as numeric type and string type, the stream is designed as a "generic" type, denoted by ρ. T The semantic rules of the flow are shown in Table 2.

[0096] Table 2

[0097]

[0098] In Table 2, the symbol a:b indicates that a has type b; (T)→U indicates a function type, the function parameter type is T, and the return value type is U; (T1,…,T n )→U is also a function type, but it accepts multiple parameters. Represents a type checking context.

[0099] The description of each semantic rule in Table 2 is shown in Table 3.

[0100] Table 3

[0101]

[0102] There are two different cases for the connection in each semantic rule. One case is: in the form of "s|>op", the return value type of op is empty (denoted as ⊥), indicating that the operation will not generate a new flow. When the data flow is connected to this type of operation, it indicates that the construction of the data flow graph is completed. At this time, a complete data flow graph is obtained, and its type is denoted as DF. This special type of operation is called "end point operation". For example Figure 2B , Figure 2D The end point operation is shown. Another case is: Figure 2A , Figure 2C In the case shown, the operation will generate a new data stream.

[0103] Through the eDSL 100 provided by the embodiment of the present application, programmers can conveniently write programs with a data flow structure based on the expression capabilities of the host language, thereby improving programming efficiency.

[0104] Before running a program written using the eDSL 100 provided by the embodiment of the present application, a security check may be performed on the functions in the program, as follows.

[0105] The embodiment of the present application defines a security rule for function execution. The security rule restricts the function that executes the operation to access only the declared shared variables, so as to effectively remind the programmer to set or constrain the shared variables of the function accordingly when writing the program (for example, to implement correct thread synchronization measures for the shared variables).

[0106] The shared variables of a function can be declared through the use list described above. That is, when a shared variable appears in the use list, it means that the shared variable has been declared.

[0107] Table 4 shows a safety check rule.

[0108] Table 4

[0109]

[0110] Specifically, when using the function tag (such as @FlowOp) described above to define a function that performs an operation, the programmer can explicitly write all shared variables accessed inside the function by following the use list of the function tag. Among them, the set composed of shared variables in the use list is denoted as Θ. The auxiliary function shared(op) is used to analyze the shared variables used inside the function. Among them, the auxiliary function shared(op) is used to statically analyze the shared variables used inside the function, which is imprecise, that is, it is impossible to accurately analyze each shared variable in all cases). Therefore, when implementing, a conservative analysis method can be adopted (that is, false positives caused by analysis are allowed). The security check rule needs to check whether the shared variables used inside the analyzed function exist in the use list, that is, the set Θ. If at least one of the shared variables used inside the analyzed function does not exist in the use list, an error is reported. Otherwise, if all the shared variables used inside the analyzed function exist in the use list, the security check passes.

[0111] In an example, Figure 3 As shown, the usage list corresponding to the function "plus1(v:Int64):Int64" can be set to include shared variables safeV+=1 and shared variable return v+1. The source code of the function is analyzed for shared variables (for example, the auxiliary function shared(op) is used to analyze the shared variables used inside the function), and it is found that the shared variables used inside the function include shared variables safeV+=1, shared variables unsafeV+=1, and shared variables return v+1. Among them, the shared variable unsafeV+=1 does not exist in the usage list corresponding to the function, which means that the function has not passed the security check, and an error may be reported.

[0112] For example, Figure 1 As shown, security checks on functions in a program can be performed by the compiler.

[0113] Security check rules can help programmers avoid potential data contention and improve the security of program execution.

[0114] If all functions in the program have passed the security check, the program can be converted into a program containing the syntax of the eDSL 100, that is, converted into a program containing only the syntax provided by the host language. In addition, in the following description, for the convenience of description, the program containing the syntax of the eDSL 100 is called the original program, and accordingly, the function in the program containing the syntax of the eDSL 100 is called the original function; the program converted from the original program and not containing the syntax of the eDSL 100 is called the target program, and accordingly, the function in the target program is called the target function. The target program is the executable version of the original program, that is, the version that can be compiled by the compiler. Accordingly, the target function is the executable version of the original function.

[0115] The specific process of converting the original program into the target program can be as follows Figure 4 shown.

[0116] The functions marked by function tags in the program containing the syntax of eDSL 100 represent the actual processing logic of the data. The functions lack the structure of the data flow relationship, that is, where the data flow is received from and to which function the data flow generated by the function flows. To this end, in step 401, the original function is renamed, and in step 402, a target function with the same name as the original function is defined. Specifically, two types need to be introduced in the host language. One type is the stream type, and the other type is the operator type. Among them, the stream type is a generic, that is, the ρ type in the semantic rules of eDSL 100. The operator type is a packaging type used to carry the processing logic of the original function. For the type (T1,…,T n )→U, the target function type is defined as In the function body of the target function, the operation is first constructed by instantiating the operation type. The operation needs to provide a connection function that can connect the input stream and the operation and return a new stream.

[0117] In step 402, the parameters and return value types of the original function are encapsulated using the stream type.

[0118] In step 403, the code of the target function may be converted. Step 403 includes steps 4031 and 4032. In step 4031, an object of the operation type of the target function is constructed, and the original function is used as the processing logic for processing the object of the operation type. In step 4032, an input stream of the object of the operation type is received, and an output stream of the object of the operation type is output.

[0119] More specifically, the inflow symbol "|>" is converted to a function call in the host language. It is combined with the conversion of function tags to correctly translate the semantics of "s|>op".

[0120] The combination symbol “~>” constructs the target function, and the internal processing of the target function is the two primitive operations combined. For example, “op1~>op2”, the code conversion will define the target function op3=λs1,…,s n .op2(op1(s1,…,s n )). The target function op3 receives the same data stream as the target function op1. The target function op3 first connects the input stream with the target function op1 to generate a new input stream, and then connects the new input stream with op2 to obtain a new input stream.

[0121] Figure 5 Shown A schematic diagram of code conversion using a coding language as an example. Figure 5 The left part of the figure is a program containing the syntax of eDSL 100, and the right part is a converted program based on Specifically, the original function plus1 of the operation is renamed plus1Impl, the parameter types and return values ​​of the new method plus1 are promoted to stream types, and the op in the function body is an instance object of the operation type of the target function, which receives the input stream (as a parameter) and returns a new stream.

[0122] Back to Figure 1 After security rule checking and code conversion are performed on the program containing the syntax of the eDSL 100, compilation can be performed to compile the program based on the high-level language into a program based on the machine language. The program based on the machine language can be called an executable program, which is a program executable by a computer.

[0123] After the executable program is compiled, the program can be run. Exemplarily, the compiler can send the compiled executable program to the data flow runtime, and the data flow runtime manages the running of the executable program.

[0124] The program can be run according to the function execution method provided in the embodiment of the present application. The function execution method can be implemented by any device, equipment, platform or cluster with data computing capability. Next, take the computing device 100 executing the function execution method as an example, and combine it with Figure 6 , the execution process of the function execution method is introduced.

[0125] In step 601, the computing device 100 may obtain a program to be executed. For example, the computing device 100 may load the program to obtain the program.

[0126] What is obtained in step 601 is the executable program of the program. Specifically, the compiler can compile the source code of the program to obtain the executable program of the program.

[0127] In some embodiments, the source code of the program may be a data flow program, that is, the source code of the program includes a graph structure. The functions in the program are nodes in the graph structure. The connecting edge between two nodes in the graph structure represents the data dependency relationship between the functions corresponding to the two nodes. Specifically, the program may be set to include function C1 and function C2, and there is a connecting edge between the node corresponding to function C1 and the node corresponding to function C1, and the direction of the connecting edge is from the node corresponding to function C1 toward the node corresponding to function C2. This indicates that the output of function C1 is the input of function C2, that is, the processing result of function C1 is the processing object of function C1 or the data to be processed.

[0128] In an example of this embodiment, the source code of the program can be obtained by a programmer by programming according to the eDSL 100. The nodes in the graph structure included in the source code are associated with a usage list, that is, the function tag of the node is followed by the usage list. The usage list is used to declare the shared variables of the function corresponding to the node. Before the compiler compiles the source code of the program, it can be checked based on the security rules to check whether the shared variables of the function corresponding to the node are all included in the usage list. If not all are included in the usage list, that is, if at least one shared variable is not included in the usage list, an error is reported.

[0129] Before the compiler compiles the source code of the program, the source code may be converted to convert the source code containing the syntax of eDSL 100 into the source code not containing the syntax of eDSL 100. The original function of the function corresponding to the node may be converted into the target function according to the node in the graph structure included in the source code and the connecting edge of the node, and the executable version of the function corresponding to the node may be obtained after being compiled by the compiler. Taking function C1 as an example, function C1 may include the code for implementing the data processing logic of function C1 in function C1 and the information for indicating the data dependency relationship between function C1 and function C2.

[0130] Continue reading Figure 6 After acquiring the program to be run and before running the program, the computing device 100 may execute step 602 to identify the running mode of the program to be run on the computing device 100 .

[0131] Among them, there are three operation modes of the program: operation model B1, operation mode B2 and operation mode B3. Among them, operation mode B1 is a resource-saving mode. Under operation mode B1, the computing device 100 only allocates one thread for the operation of the program, and the thread is responsible for executing the operations of all functions in the program. Operation mode B2 is efficiency-first. Under operation mode B1, whenever a data processing request of the program is received, a thread is allocated to the program, and the thread is specifically used to process the data processing request, and does not process other data processing requests. Operation mode B3 is a balanced type. Under operation mode B3, when the program starts running, at least one thread is first allocated to the program. During the program running, the cache utilization of the function in the program can be obtained. When the cache utilization of the function is high, a new thread can be allocated to the function to provide the concurrency of the function execution, so as to process the data waiting to be processed in the function as soon as possible. Among them, the concurrency of function execution is positively correlated with the number of threads executing the function.

[0132] In the embodiment of the present application, a data processing request may be referred to as a processing request.

[0133] In some embodiments, the computing device 100 may identify the running mode of the program to be run on the computing device 100 based on preset configuration information. Exemplarily, when the operation and maintenance personnel or the user loads the program to the computing device 100, they may configure the computing device 100 to obtain the configuration information. The configuration information indicates the running mode of the program on the computing device 100. For example, if the configuration information indicates running mode B1, the computing device 100 may identify the running mode of the program to be run on the computing device 100 as running mode B1 based on the preset configuration information. For another example, if the configuration information indicates running mode B2, the computing device 100 may identify the running mode of the program to be run on the computing device 100 as running mode B2 based on the preset configuration information. For another example, if the configuration information indicates running mode B3, the computing device 100 may identify the running mode of the program to be run on the computing device 100 as running mode B3 based on the preset configuration information.

[0134] In some embodiments, after the computing device 100 loads the program and is about to run the program, it obtains the current load of the computing device 100 (e.g., the utilization rate of the central processing unit (CPU)) and identifies the running mode of the program on the computing device 100. When the current load of the computing device 100 is greater than the first load threshold, it can be confirmed that the running mode of the program on the computing device 100 is running mode B1. When the current load of the computing device 100 is less than the second load threshold, it can be confirmed that the running mode of the program on the computing device 100 is running mode B2. When the current load of the computing device 100 is greater than or equal to the second load threshold and less than or equal to the first load threshold, it can be confirmed that the running mode of the program on the computing device 100 is running mode B3.

[0135] In some embodiments, the computing device 100 may identify the running mode of the program on the computing device 100 based on the amount of computing resources of the computing device 100 (e.g., the number of CPU cores). When the computing resources of the computing device 100 are greater than the first resource threshold, it can be confirmed that the running mode of the program on the computing device 100 is running mode B2. When the load of the computing device 100 is less than the second resource threshold, it can be confirmed that the running mode of the program on the computing device 100 is running mode B1. When the load of the computing device 100 is greater than or equal to the second resource threshold and less than or equal to the first resource threshold, it can be confirmed that the running mode of the program on the computing device 100 is running mode B3.

[0136] After the running mode of the program on the computing device 100 is identified, the running of the program can be controlled according to the identified running mode. The details are as follows.

[0137] In some embodiments, the operation mode identified in step 602 can be set as operation mode B1, and the computing device 100 can execute step 603, assign thread D1 to the program, and instruct the thread to execute all functions in the program. During the entire operation of the program, the computing device 100 no longer assigns other threads other than thread D1 to the program. That is, during the operation of the program, the functions in the program are only executed by thread D1. Among them, thread D1 can be a thread. In operation mode B1, only one thread processes data processing requests for the program, and when there are multiple data processing requests, the multiple data processing requests are processed serially. In other words, under operation mode B1, the computing device 100 instructs a thread to process the data requested for processing by all processing requests for the program by executing the functions in the program. Under this operation mode, the program consumes fewer computing resources per unit time.

[0138] In some embodiments, the operation model identified in step 602 can be set as operation mode B2, and the computing device 100 can execute step 604, and whenever a processing request is received, a thread D2 is created for the processing request, and the created thread D2 is instructed to process the data requested to be processed by the processing request by running the program. In step 604, a separate thread is created and assigned for each processing request, and the thread is only used to process the data requested to be processed by the processing request. That is, for the processing request, the thread executes the function in the program to process the data requested to be processed by the processing request. That is, under operation mode B2, whenever a processing request for a program is received, a new thread is created for the processing request, and the created thread is instructed to execute the function in the program to process the data requested to be processed by the processing request.

[0139] In some embodiments, the operation model identified in step 602 may be set to operation mode B3, and the computing device 100 may execute step 605 to obtain the cache utilization of function C1 when function C1 in the program is executed by thread D3.

[0140] In operation mode B3, at least one function may be allocated to each function in the program. The thread allocated to the function is used to indicate the function. For example, the thread allocated to function C1 in the program is thread D3, and thread D3 is used to execute function C1. Thread D3 may be one thread or multiple threads.

[0141] During the execution of each function by the thread assigned to the function, the cache utilization of the function can be obtained. The cache utilization of a function can also be called the load of the function, which refers to the ratio of the available cache of the function to the total cache of the function. It can be understood that, taking function C1 as an example, the data that needs to be processed by function C1 is temporarily stored in the cache of function C1, and function C1 obtains the data to be processed from its cache and processes it. If the generation rate of data that needs to be processed by function C1 is greater than the rate at which function C1 processes data, the data in the cache of function C1 continues to increase, so that the cache utilization of function C1 continues to increase. Therefore, the load of function C1 can be reflected by the cache utilization of function C1.

[0142] Continue reading Figure 6 , the computing device 100 may execute step 606 , and when the cache utilization of the function C1 is greater than the threshold Y1 , allocate thread D4 to the function C1 .

[0143] The threshold value Y1 may be referred to as a load threshold value (load_threshold). The threshold value Y1 may be a preset value. In one example, the threshold value Y1 may be 75%. In another example, the threshold value Y1 may be 70%. And so on, which are not listed here one by one.

[0144] Thread D4 may be one or more threads.

[0145] In some embodiments, the program can be set to also include function C2, and the output of function C1 is the input of function C2. That is to say, the processing result of the data processed by function C1 is the data to be processed by function C2. When thread D4 is assigned to function C1, the cache utilization of function C2 is predicted when thread D4 and thread D3 execute function C2 at the same time. It is not difficult to understand that the output of function C1 is the input of function C2. The more threads that execute function C1, that is, the higher the concurrency of function C1, the faster the output rate of function C1, which may lead to an increase in the cache utilization of function C2, and thus may cause the processing rate of function C2 to become the efficiency bottleneck of the entire program in processing data. In other words, without considering the cache utilization of function C2, rashly increasing the concurrency of function C1 may not necessarily improve the data processing efficiency of the entire program.

[0146] The number of threads executing function C1 is the value of the concurrency of function C1.

[0147] To this end, in step 606, when thread D3 and thread D4 are predicted to execute function C1 simultaneously, the cache utilization of function C2 is predicted to obtain a prediction result. When the prediction result is not greater than threshold Y2, or in other words, when the cache utilization of function C2 indicated by the prediction result is not greater than threshold Y2, thread D4 is allocated to function C1. When the prediction result is greater than threshold Y2, no new thread is allocated to function C1.

[0148] In some embodiments, the data processing rate of thread D3 executing function C1 and the data processing rate of thread D2 executing function C1 can be calculated to obtain rate V1. Then, the rate V1 is compared with the data processing rate V2 of function C2.

[0149] If the rate V1 is less than or equal to the rate V2 at which the function C2 processes data, it can be confirmed that the prediction result is not greater than the threshold Y2.

[0150] If the rate V1 is greater than the rate V1 at which function C2 processes data, it is determined whether the cache utilization of function C2 reaches the threshold value Y2 within the preset time length T1. If the cache utilization of function C2 does not reach the threshold value Y2 within the preset time length T1, it can be confirmed that the prediction result is not greater than the threshold value Y2.

[0151] If the cache utilization of the function C2 reaches the threshold value Y2 within the preset time length T1, it can be confirmed that the prediction result is greater than the threshold value Y2.

[0152] In one example, the rate V1 minus the rate V at which function C2 processes data can be calculated to obtain a rate difference. The current cache utilization of function C2 is subtracted from the threshold Y2 to obtain a cache utilization difference. The cache utilization difference is divided by the rate difference to obtain time T2. If time T2 is greater than time T1, it is confirmed that the cache utilization of function C2 does not reach threshold Y2 within time T1. If time T2 is not greater than time T1, it is confirmed that the cache utilization of function C2 reaches threshold Y2 within time T1.

[0153] The threshold value Y2 may be referred to as a downstream load threshold value (next_load_threshold). The threshold value Y2 may be a preset value. In one example, the threshold value Y2 may be 75%. In another example, the threshold value Y2 may be 70%. And so on, which are not listed here one by one.

[0154] In some embodiments, the number of threads used to run the program is limited and can be increased indefinitely. The number of threads and performance benefits are not simply proportional. Too many threads will cause the performance of the underlying thread scheduling module to deteriorate, thereby reducing the data efficiency of the program. Therefore, the program has a preset upper limit on the number of threads (global_concurrency). In one example, the upper limit on the number of threads is twice the number of computing cores of the CPU of the computing device 100.

[0155] In step 606, before allocating thread D4 to function C1, first obtain the total number of currently executed threads of the program. The execution thread of a program refers to the thread used to execute program-related code (such as a function). And determine whether the total number of currently executed threads of the program is less than the upper limit of the number of threads of the program. If the total number of currently executed threads of the program is less than the upper limit of the number of threads of the program, then in step 606, thread D4 is allocated to function C1. If the total number of currently executed threads of the program is not less than the upper limit of the number of threads of the program, then in step 606, thread D4 is not allocated to function C1.

[0156] Continue reading Figure 6 After assigning thread D4 to function C1, computing device 100 may execute step 607 to instruct thread D3 and thread D4 to execute function C1 simultaneously. Thread D3 processes a portion of data in the cache of function C1 by executing function C1, and thread D4 processes another portion of data in the cache of function C1 by executing function C1. In other words, different data in the data to be processed in the cache of function C1 are processed by thread D3 and thread D4 respectively, thereby speeding up the processing rate of data in the cache of function C1 and reducing the cache utilization of function C1.

[0157] In some embodiments, if there are multiple threads executing function C1, for example, thread D3 is multiple threads, when the cache utilization of function C1 is relatively low, that is, when the load of function C1 is relatively light, some of the multiple threads can be recycled to release the computing resources occupied by these threads.

[0158] Specifically, when the execution thread of function C1 is thread D3, and thread D3 is a plurality of threads, computing device 100 may obtain cache utilization of function C1. If the cache utilization of function C1 is not greater than threshold value Y3, some threads among the plurality of threads are recycled. For example, one thread among the plurality of threads is recycled. For another example, the plurality of threads is set to N threads, and N-1 threads may be recycled.

[0159] The threshold value Y3 may be referred to as a minimum load threshold value (min_load_threshold). The threshold value Y3 may be a preset value. In one example, the threshold value Y3 may be 50%. In another example, the threshold value Y2 may be 40%. And so on, which are not listed here one by one.

[0160] In an illustrative example, the thread allocation method in the operation mode B3 can be implemented by the code shown below.

[0161]

[0162] For an illustrative example, see Figure 7 , the concurrency of function C1 can be set to 3, that is, there are 3 execution threads for executing function C1. When the threshold Y1 is 70%, the computing device 100 detects that the cache utilization of function C1 is 80%, which is greater than the threshold Y1. At this time, a thread application request and the identifier of function C1 can be sent to the concurrency management module in the computing device 100. The concurrency management module can respond to the thread application request and allocate a new thread to function C1. The allocated new thread and the original execution thread of function C1 execute function C1 at the same time to provide the concurrency of function C1.

[0163] See also Figure 7 , the concurrency of function C2 can be set to 2, that is, there are 2 execution threads for executing function C2. When the threshold Y3 is 50%, the computing device 100 detects that the cache utilization of function C2 is 30%, which is less than the threshold Y3. At this time, a thread recovery request and the identifier of function C2 can be sent to the concurrency management module in the computing device 100. The concurrency management module can respond to the thread recovery request for one of the execution threads of function C2 to release the computing resources occupied by the thread.

[0164] The function execution method provided in the embodiment of the present application can determine the operating mode of the program before the program is run, so as to run the program according to the operating mode of the program, such as adjusting the concurrency of the function in the program. This method can select the operating mode of the program on a computing device without intrusive modification of the program code. In other words, different computing devices can run the same program code using different operating modes. Among them, the same program code means that the program code is the same and the functions contained are the same. If one program has one more function than another program, such as a function for adjusting the concurrency, the codes of the two programs are different.

[0165] Furthermore, in the function execution method provided in the embodiment of the present application, the concurrency of the function can be adjusted automatically according to the load of the function, thereby improving the processing efficiency of the function while taking into account resource utilization.

[0166] In summary, the embodiments of the present application provide a program writing and execution solution, which is as follows.

[0167] Source code for programs written based on eDSL 100. Figure 8 When the source code needs to be executed, the source code can be input into the compiler, wherein the compiler is composed of a host language compiler and an eDSL compiler.

[0168] The host language compiler performs host language parsing to obtain a parsing result.

[0169] The eDSL compiler performs a security rule check on the parsing result. After passing the security rule check, the eDSL compiler performs code conversion to obtain a conversion result. The security rule check and code conversion are specifically implemented as described above and will not be described in detail here.

[0170] The host language compiler performs a host language compilation process on the conversion result to obtain an executable program in the host language. The computing device can run the executable program. The data flow runtime can manage the running of the executable program.

[0171] In an example, Fig. 9 As shown, in the data flow framework of the Cangjie programming language, the eDSL design, security rule checking, code transformation, function execution and other method steps described above realize the basic data flow adaptive concurrent execution capability. In this example, the code macro capability supported by Cangjie and the inflow (|>) and combination (~>) symbols natively supported by the language implement the data flow eDSL language, and complete the inspection and conversion of the data flow code through macros. The data flow runtime supports the three operating modes mentioned above and the adaptive thread allocation algorithm, and finally completes the data flow framework with adaptive concurrent execution in the Cangjie language.

[0172] Fig. 9 The solution shown can implement the data flow framework based on existing programming languages ​​(such as Cangjie programming language) with a workload of 3 man-years. The implementation cost of this solution is low and the workload is small.

[0173] Existing solutions either implement the data flow framework directly in the host language or design a dedicated data flow programming language. The former lacks the readability of the data flow graph when writing data flow programs, and the latter lacks ease of programming. Fig. 9 The solution shown embeds the data flow domain language in a general programming language, which takes into account the ease of writing general logic and improves the readability of data flow programming.

[0174] In addition, existing solutions do not adequately support concurrent execution of data streams, or do not provide this function, or require programmers to write specific concurrent control codes themselves, resulting in a poor user experience of the concurrent execution data stream framework. Fig. 9 The scheme shown provides different designs for concurrent execution, decoupling graph construction from execution, and providing different execution modes and adaptive concurrent execution modes to alleviate existing pain points, and improving the security of concurrent execution through compiler checking rules.

[0175] In summary, compared with the existing solutions, Fig. 9 The scheme shown has the advantages shown in Table 5.

[0176] Table 5

[0177]

[0178] Specifically, the design using eDSL can fully reuse the expressive power of the host language, while simplifying the data flow programming syntax, making data flow programming simple and flexible. The syntax of eDSL is designed for the most critical data dependencies in the data flow graph, allowing programmers to experience the "what you write is what you get" data flow graph structure, making the data dependency relationship between functions highly understandable. The decoupling of data flow graphs and execution modes allows the same program to be easily ported to different application scenarios for execution. The adaptive concurrency management method can improve performance while taking into account programming ease of use, avoiding programmers from manually writing concurrent logic. Improve code reliability through compile-time data flow rule security checks. These advantages give the Cangjie data flow framework a good experience.

[0179] In summary, the embodiment of the present application provides a method for executing a function. The method is applied to a computing device running a program, wherein the program includes a first function. Fig.10 As shown, the method includes the following steps.

[0180] Step 1001, before running the program, identifying that the running mode of the program on the computing device is the first mode. For details, refer to the introduction of step 601 and step 602 above.

[0181] Step 1002: In the first mode, when the first function is executed by the first thread of the computing device, the cache utilization rate of the first function is obtained. For details, please refer to the introduction of step 605 above.

[0182] Step 1003: when the cache utilization rate of the first function is greater than a first threshold, a second thread of the computing device is allocated to the first function. For details, please refer to the above description of step 606.

[0183] Step 1004, instructing the first thread and the second thread to execute the first function simultaneously; wherein the first thread processes a portion of data in the cache of the first function by executing the first function, and the second thread processes another portion of data in the cache of the first function by executing the first function. For details, please refer to the above description of step 606.

[0184] In some embodiments, the output of the first function is the input of the second function in the program; when the cache utilization of the first function is greater than a first threshold, allocating the second thread of the computing device to the first function includes: when the cache utilization of the first function is greater than the first threshold, predicting the cache utilization of the second function when the first thread and the second thread execute the first function simultaneously; when the prediction result is not greater than the second threshold, allocating the second thread to the first function.

[0185] In some embodiments, when the cache utilization of the first function is greater than a first threshold, allocating the second thread of the computing device to the first function includes: when the cache utilization of the first function is greater than the first threshold, obtaining the total number of execution threads of the program; when the total number is less than an upper limit on the number of threads, allocating the second thread of the computing device to the first function.

[0186] In some embodiments, the first thread is a plurality of threads, and the method further includes: when the cache utilization of the first function is not greater than a third threshold, reclaiming some of the first threads, and the third threshold is less than the first threshold.

[0187] In some embodiments, the method further includes: before running the program, identifying that the running mode of the program on the computing device is a second mode; in the second mode, whenever a processing request for the program is received, creating a third thread for the processing request, and instructing the third thread to process the data requested by the processing request by executing a function in the program. For details, please refer to the above introduction to step 604.

[0188] In some embodiments, the method further includes: before running the program, identifying that the running mode of the program on the computing device is a third mode; in the third mode, instructing the fourth thread to process the data requested to be processed by all processing requests for the program by executing functions in the program. For details, please refer to the above introduction to step 603.

[0189] In some embodiments, the source code of the program includes a graph structure, the first function is a first node in the graph structure, the second function is a second node in the graph structure, and the graph structure includes a connecting edge from the first node toward the second node, and the connecting edge indicates that the output of the first function is the input of the second function.

[0190] In some embodiments, the first node is associated with a usage list, and the usage list is used to declare shared variables of the first function; the method also includes: before compiling the source code, when it is detected that at least one shared variable of the first function is not included in the usage list, reporting an error.

[0191] In some embodiments, the method further includes: compiling the first node and the connecting edge into an executable version of the first function; the executable version of the first function includes the code of the first function and the data dependency between the first function and the second function.

[0192] The function execution method provided in the embodiment of the present application can determine the running mode of the program before the program is run, so as to run the program according to the running mode of the program, for example, to adjust the concurrency of the function in the program. The method can select the running mode of the program on a certain computing device without intrusive modification of the program code. In other words, different computing devices can run the same program code in different running modes.

[0193] The present application also provides a function execution device. The device can be configured on a computing device running a program, wherein the program includes a first function. The device includes a function for implementing Fig.10 The functional unit of the method shown. Fig.11 , the execution device may include the following functional units.

[0194] An identification unit 1110, used for identifying that the running mode of the program on the computing device is a first mode before running the program;

[0195] An acquiring unit 1120, configured to acquire a cache utilization rate of the first function when the first function is executed by a first thread of the computing device in the first mode;

[0196] An allocating unit 1130, configured to allocate a second thread of the computing device to the first function when the cache utilization rate of the first function is greater than a first threshold;

[0197] The indication unit 1140 is used to instruct the first thread and the second thread to execute the first function simultaneously; wherein, the first thread processes a part of the data in the cache of the first function by executing the first function, and the second thread processes another part of the data in the cache of the first function by executing the first function.

[0198] The above mainly introduces the device provided by the embodiment of the present application from the perspective of the method flow. It is understandable that, in order to realize the above functions, each terminal includes a hardware structure and / or software module corresponding to each function. It should be easily appreciated by those skilled in the art that, in combination with the units and algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present application.

[0199] See also Fig.12 , the embodiment of the present application provides a computing device 1200. The computing device 1200 may include a processor 1210 and a memory 1220. The memory 1220 stores instructions, which can be executed by the processor 1210. When the instructions are executed by the processor 1210, the computing device 1200 may execute Figure 6 The method shown or Fig.10 The method shown.

[0200] It is understood that the processor in the embodiments of the present application may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. The general-purpose processor may be a microprocessor or any conventional processor.

[0201] The method steps in the embodiments of the present application can be implemented by hardware or by a processor executing software instructions. The software instructions can be composed of corresponding software modules, and the software modules can be stored in random access memory (RAM), flash memory, read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), registers, hard disks, mobile hard disks, CD-ROMs, or any other form of storage medium known in the art. An exemplary storage medium is coupled to the processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an ASIC.

[0202] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted through the computer-readable storage medium. The computer instructions may be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid state disk (SSD)), etc.

[0203] It should be understood that the various numerical numbers involved in the embodiments of the present application are only used for the convenience of description and are not used to limit the scope of the embodiments of the present application.

Claims

1. A function execution method, characterized in that: The method is applied to a computing device running a program, wherein the program includes a first function; the method includes: Before running the program, identifying that the running mode of the program on the computing device is a first mode; In the first mode, when the first function is executed by a first thread of the computing device, obtaining a cache utilization rate of the first function; When the cache utilization rate of the first function is greater than a first threshold, allocating a second thread of the computing device to the first function; Instruct the first thread and the second thread to execute the first function simultaneously; wherein, the first thread processes a portion of data in the cache of the first function by executing the first function, and the second thread processes another portion of data in the cache of the first function by executing the first function.

2. The method according to claim 1, characterized in that: The output of the first function is the input of a second function in the program; when the cache utilization rate of the first function is greater than a first threshold, allocating the second thread of the computing device to the first function comprises: When the cache utilization of the first function is greater than a first threshold, predicting the cache utilization of the second function when the first thread and the second thread execute the first function simultaneously; When the prediction result is not greater than a second threshold, the second thread is allocated to the first function.

3. The method according to claim 1, characterized in that When the cache utilization rate of the first function is greater than a first threshold, allocating a second thread of the computing device to the first function comprises: When the cache utilization rate of the first function is greater than a first threshold, obtaining the total number of execution threads of the program; When the total number is less than an upper limit on the number of threads, a second thread of the computing device is allocated to the first function.

4. The method according to any one of claims 1 to 3, characterized in that The first thread is a plurality of threads, and the method further includes: When the cache utilization of the first function is not greater than a third threshold, some threads in the first thread are recycled, and the third threshold is less than the first threshold.

5. The method according to any one of claims 1 to 4, characterized in that The method further comprises: Before running the program, identifying that the running mode of the program on the computing device is a second mode; In the second mode, whenever a processing request for the program is received, a third thread is created for the processing request, and the third thread is instructed to process the data requested to be processed by executing a function in the program.

6. The method according to any one of claims 1 to 4, characterized in that The method further comprises: Before running the program, identifying that the running mode of the program on the computing device is a third mode; In the third mode, the fourth thread is instructed to process data requested to be processed by all processing requests for the program by executing functions in the program.

7. The method according to any one of claims 1 to 6, characterized in that: The source code of the program includes a graph structure, the first function is a first node in the graph structure, the second function is a second node in the graph structure, and the graph structure includes a connecting edge from the first node to the second node, and the connecting edge indicates that the output of the first function is the input of the second function.

8. The method according to claim 7, characterized in that The first node is associated with a usage list, and the usage list is used to declare shared variables of the first function; the method further includes: Before compiling the source code, when it is detected that at least one shared variable of the first function is not included in the usage list, an error is reported.

9. The method according to claim 7 or 8, characterized in that: The method further comprises: Compiling the first node and the connecting edge into an executable version of the first function; The executable version of the first function includes the code of the first function and the data dependency relationship between the first function and the second function.

10. A function execution device, characterized in that: The device is configured to be mounted on a computing device running a program, wherein the program includes a first function; and the device includes: an identification unit, used for identifying that the running mode of the program on the computing device is a first mode before running the program; an acquiring unit, configured to acquire, in the first mode, a cache utilization rate of the first function when the first function is executed by the first thread of the computing device; an allocating unit, configured to allocate a second thread of the computing device to the first function when the cache utilization rate of the first function is greater than a first threshold; An indication unit is used to instruct the first thread and the second thread to execute the first function simultaneously; wherein, the first thread processes a part of the data in the cache of the first function by executing the first function, and the second thread processes another part of the data in the cache of the first function by executing the first function.

11. The device according to claim 10, characterized in that The output of the first function is the input of the second function in the program; the allocation unit is used for: When the cache utilization of the first function is greater than a first threshold, predicting the cache utilization of the second function when the first thread and the second thread execute the first function simultaneously; When the prediction result is not greater than a second threshold, the second thread is allocated to the first function.

12. The device according to claim 10, characterized in that The allocation unit is used to: When the cache utilization rate of the first function is greater than a first threshold, obtaining the total number of execution threads of the program; When the total number is less than an upper limit on the number of threads, a second thread of the computing device is allocated to the first function.

13. The device according to any one of claims 10 to 12, characterized in that The first thread is a plurality of threads, and the device further comprises: A recycling unit is used to recycle part of the first threads when the cache utilization rate of the first function is not greater than a third threshold, and the third threshold is less than the first threshold.

14. The device according to any one of claims 10 to 13, characterized in that The identification unit is also used to identify that the running mode of the program on the computing device is the second mode before running the program; The allocation unit is further configured to, in the second mode, create a third thread for a processing request whenever a processing request for the program is received; The instructing unit is further used to instruct the third thread to process the data requested to be processed by the processing request by executing a function in the program.

15. The device according to any one of claims 10 to 13, characterized in that The identification unit is also used to identify that the running mode of the program on the computing device is a third mode before running the program; The instructing unit is further configured to instruct the fourth thread to process data requested to be processed by all processing requests for the program by executing a function in the program in the third mode.

16. The device according to any one of claims 10 to 15, characterized in that: The source code of the program includes a graph structure, the first function is a first node in the graph structure, the second function is a second node in the graph structure, and the graph structure includes a connecting edge from the first node to the second node, and the connecting edge indicates that the output of the first function is the input of the second function.

17. The device according to claim 16, characterized in that The first node is associated with a usage list, and the usage list is used to declare shared variables of the first function; the apparatus further comprises: The checking unit is used to report an error when it is checked that at least one shared variable of the first function is not included in the use list before compiling the source code.

18. The device according to claim 16 or 17, characterized in that The device also includes: A compiling unit, used for compiling the first node and the connecting edge into an executable version of the first function; The executable version of the first function includes the code of the first function and the data dependency relationship between the first function and the second function.

19. A computing device, characterized in that The system comprises a processor and a memory; wherein the memory stores computer instructions, and the processor is used to execute the computer instructions to implement the method according to any one of claims 1 to 9.

20. A computer-readable storage medium, characterized in that: The method comprises computer program instructions, and when the computer program instructions are executed by a computing device, the computing device performs the method according to any one of claims 1 to 9.