Electronic Component Flow Management Method, Device, Medium and Computer Program Product

By creating flow management instances to obtain target flow from shared flow pools, the problem of low flow management efficiency in artificial intelligence model training and inference programs is solved, and the utilization rate of electronic components and program performance is improved.

CN119045917BActive Publication Date: 2025-05-27LANGCHAO ELECTRONIC INFORMATION IND CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411523899.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-30
Publication Date
2025-05-27
Estimated Expiration
2044-10-30

AI Technical Summary

Technical Problem

In AI model training and inference programs, how to efficiently manage large amounts of flows, thereby improving program performance and improving the usage of electronic components.

Method used

By receiving the flow request, determine the number and flow type of the electronic component, and create a flow management instance for the current thread, obtain the target flow from the pre-established shared flow pool, fill in the flow list, and return to the current thread.

Benefits of technology

It realizes convenient and efficient management of electronic component flows from different manufacturers and different models, avoids the performance losses caused by the creation of large amounts of streams, and improves the utilization rate and program performance of electronic components.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119045917B_ABST
    Figure CN119045917B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of computer technology, and discloses a method, device, medium and computer program product for managing electronic component streams. The method includes: receiving a stream application request; determining the number and stream type of the electronic component corresponding to the stream application request, and creating a stream management instance for the current thread; the stream management instance is used to manage the corresponding stream list; according to the determined number and stream type of the electronic component, using the stream management instance to obtain the corresponding target stream from a pre-established shared stream pool and fill it into the corresponding position in the stream list; different electronic component streams are stored in the shared stream pool; returning the target stream in the stream list to the current thread. In this way, it can conveniently and efficiently manage the streams of electronic components, has good compatibility, can be applied to electronic components of different manufacturers and different models, avoids performance losses caused by the creation of a large number of streams, thereby improving the utilization rate of electronic components and enhancing the performance of the program.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technologies, and in particular, to a method, device, medium, and computer program product for managing electronic component streams. Background Art

[0002] With the rise of Artificial Intelligence (AI) technologies, solutions using central processing units, graphics processing units, AI chips, etc. for artificial intelligence model training and inference have been widely applied in various industries. To improve the performance of artificial intelligence model training and inference, the concept of streams has been incorporated into the design of AI chips or boards. A stream represents an operation queue, and different streams are created to execute different tasks to achieve parallelism between tasks, thereby improving the performance of the program. However, how to efficiently manage streams has become an important issue.

[0003] In related technical solutions, artificial intelligence training or inference programs are usually divided into different modules according to functions, such as a dataset loading module, a training module, an inference module, etc., and different streams are created for each module. Each module uses its own stream to complete its tasks. However, when there are many modules in the program, the number of created streams will be excessive, and the creation of streams will take time, thus affecting the performance of the program; in addition, if many modules are responsible for short-term tasks, that is, they end after executing for a very short time, then creating a separate stream for it will instead cause a loss in program performance. Summary of the Invention

[0004] The purpose of the present invention is to provide a method, device, medium, and computer program product for managing electronic component streams, which can conveniently and efficiently manage the streams of electronic components of different manufacturers and models, improve the utilization rate of electronic components, and enhance the performance of the program.

[0005] To solve the above technical problems, the present invention provides a method for managing electronic component streams, the method including:

[0006] Receiving a stream application request;

[0007] Determining the number and stream type of the electronic component corresponding to the stream application request, and creating a stream management instance for the current thread; the stream management instance is used to manage the corresponding stream list;

[0008] According to the determined number and stream type of the electronic component, using the stream management instance to obtain the corresponding target stream from a pre-established shared stream pool and fill it into the corresponding position of the stream list; different electronic component streams are stored in the shared stream pool;

[0009] Returning the target stream in the stream list to the current thread.

[0010] In a first aspect, in the above-mentioned electronic component flow management method provided by the present invention, before receiving a flow application request, it further includes:

[0011] Invoking the runtime functions of each electronic component to sequentially establish at least two flows on each electronic component; wherein, the type of the first flow established on each electronic component is the default flow, and the types of the other flows except the first flow are the current flows;

[0012] Numbering each electronic component, and forming the flows on the numbered electronic components into the shared flow pool.

[0013] In another aspect, in the above-mentioned electronic component flow management method provided by the present invention, according to the determined number and flow type of the electronic component, using the flow management instance to obtain the corresponding target flow from the pre-established shared flow pool and fill it into the corresponding position in the flow list, including:

[0014] Using the flow management instance to determine whether there is a target flow in the flow list corresponding to the determined number and flow type of the electronic component;

[0015] If it exists, directly return the target flow existing in the flow list to the current thread;

[0016] If it does not exist, use the flow management instance to obtain the target flow corresponding to the determined number and flow type of the electronic component from the pre-established shared flow pool and fill it into the corresponding position in the flow list.

[0017] In another aspect, in the above-mentioned electronic component flow management method provided by the present invention, the flow management instance includes a function for obtaining the default flow, a function for obtaining the current flow, a function for creating a new flow, and a function for setting a flow as the current flow.

[0018] In another aspect, in the above-mentioned electronic component flow management method provided by the present invention, the flow list includes a default flow list and a current flow list;

[0019] The default flow list is the first array; each element in the first array is a flow, and the subscript of the first array corresponds one-to-one with the number of the electronic component; each element in the first array is assigned the same flow of the corresponding electronic component during initialization;

[0020] The current flow list is the second array; each element in the second array is a flow, and the subscript of the second array corresponds one-to-one with the number of the electronic component; each element in the second array is assigned at least twice.

[0021] On the other hand, in the above-mentioned electronic component flow management method provided by the present invention, it further includes:

[0022] When the get default flow function in the flow management instance is called for the first time, obtain the default flow from the shared flow pool and fill it into the corresponding position in the default flow list;

[0023] When the get current flow function in the flow management instance is called for the first time, obtain the default flow from the shared flow pool and fill it into the corresponding position in the current flow list.

[0024] On the other hand, in the above-mentioned electronic component flow management method provided by the present invention, after the target flow in the flow list is returned to the current thread, it further includes:

[0025] If the returned target flow is not the flow required by the current thread, call the create flow function in the flow management instance to create a new flow in the flow list;

[0026] Call the set current flow function in the flow management instance to set the created new flow as the current flow;

[0027] Return the set current flow to the current thread.

[0028] On the other hand, in the above-mentioned electronic component flow management method provided by the present invention, calling the create flow function in the flow management instance to create a new flow in the flow list includes:

[0029] Call the create flow function in the flow management instance to control the flow list to obtain the corresponding flow from the shared flow pool in a polling manner, and at the same time use the flow obtained by the flow list as the new flow created in the flow list;

[0030] Correspondingly, calling the set current flow function in the flow management instance to set the created new flow as the current flow includes:

[0031] Call the set current flow function in the flow management instance to fill the created new flow into the corresponding position in the current flow list.

[0032] On the other hand, in the above-mentioned electronic component flow management method provided by the present invention, it further includes:

[0033] When multiple threads select the default flow for calculation, perform serial calculation in the order of adding to the functions of the flow;

[0034] Wherein, after the function calculation added to the default flow by each thread is completed, a new function is added to the flow.

[0035] On the other hand, in the above-mentioned electronic component flow management method provided by the present invention, it further includes:

[0036] When multiple threads select the current stream for calculation, the corresponding current stream is obtained by polling and allocation from the shared stream pool;

[0037] Among them, if the number of threads is more than the number of streams in the shared stream pool, parallel calculation is performed using the obtained current stream.

[0038] On the other hand, in the above-mentioned electronic component stream management method provided by the present invention, it further includes:

[0039] When the current thread exits, the stream management instance is destroyed, and at the same time, the stream list managed by the stream management instance is destroyed.

[0040] On the other hand, in the above-mentioned electronic component stream management method provided by the present invention, it further includes:

[0041] When there is a stream to be destroyed in the shared stream pool, the runtime function of the electronic component corresponding to the stream to be destroyed is called to destroy the stream to be destroyed.

[0042] In order to solve the above technical problems, the present invention also provides an electronic component stream management device, and the device includes:

[0043] A memory for storing a computer program;

[0044] A processor for implementing the steps of the above-mentioned electronic component stream management method when executing the computer program.

[0045] In order to solve the above technical problems, the present invention also provides a non-volatile storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the above-mentioned electronic component stream management method are implemented.

[0046] In order to solve the above technical problems, the present invention also provides a computer program product, including a computer program / instructions, and when the computer program / instructions are executed by a processor, the steps of the above-mentioned electronic component stream management method are implemented.

[0047] As can be seen from the above technical solutions, an electronic component stream management method provided by the present invention includes: receiving a stream application request; determining the number and stream type of the electronic component corresponding to the stream application request, and creating a stream management instance for the current thread; the stream management instance is used to manage the corresponding stream list; according to the determined number and stream type of the electronic component, the corresponding target stream is obtained from the pre-established shared stream pool by using the stream management instance and filled into the corresponding position of the stream list; different electronic component streams are stored in the shared stream pool; and the target stream in the stream list is returned to the current thread.

[0048] The beneficial effects of the present invention are as follows. For the above-mentioned electronic component flow management method provided by the present invention, after receiving a flow application request, it determines the number and flow type of the electronic component corresponding to the flow application request, and creates a flow management instance for the current thread. This flow management instance can obtain the target flow of the electronic component from the shared flow pool according to the determined number and flow type of the electronic component and return it. In this way, it can conveniently and efficiently manage the flow of electronic components, has good compatibility, can be applied to electronic components of different manufacturers and different models, supports different threads to use different flows, and obtains the corresponding flow from the shared flow pool through the flow management instance, avoiding the performance loss caused by the creation of a large number of flows, thereby improving the utilization rate of electronic components and enhancing the performance of the program.

[0049] In addition, the present invention also provides a corresponding electronic component flow management device, non-volatile storage medium, and computer program product for the electronic component flow management method, which have the same or corresponding technical features as the above-mentioned electronic component flow management method, and the effects are the same. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] To more clearly illustrate the embodiments of the present invention, the following will briefly introduce the drawings required for use in the embodiments. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.

[0051] Figure 1 It is a flowchart of the electronic component flow management method provided by the embodiment of the present invention;

[0052] Figure 2 It is a schematic structural diagram corresponding to the electronic component flow management method provided by the embodiment of the present invention;

[0053] Figure 3 It is a schematic diagram of the functions provided by the flow management instance in the embodiment of the present invention;

[0054] Figure 4 It is a schematic structural diagram of the flow list provided by the embodiment of the present invention;

[0055] Figure 5 It is a schematic diagram of the polling mechanism of the shared flow pool provided by the embodiment of the present invention;

[0056] Figure 6 It is a schematic structural diagram of the runtime module provided by the embodiment of the present invention;

[0057] Figure 7 It is a schematic diagram of multiple threads performing serial calculations using the default flow provided by the embodiment of the present invention;

[0058] Figure 8Schematic diagram of multiple threads provided by an embodiment of the present invention for parallel computing using the current stream;

[0059] Figure 9 Schematic diagram of the structure of an electronic component stream management device provided by an embodiment of the present invention;

[0060] Figure 10 Schematic diagram of the structure of an electronic component stream management device provided by an embodiment of the present invention. Detailed implementation manners

[0061] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the protection scope of the present invention.

[0062] The core of the present invention is to provide an electronic component stream management method, device, medium and computer program product to solve the technical problem of how to efficiently manage streams.

[0063] In order to enable those skilled in the art to better understand the solution of the present invention, the present invention will be further described in detail below in conjunction with the accompanying drawings and specific implementation manners. Figure 1 Flowchart of the electronic component stream management method provided by an embodiment of the present invention, as Figure 1 shown, the method includes:

[0064] S101. Receive a stream application request.

[0065] It should be noted that a stream represents the operation queue of a processor. Operations in the same stream will be executed in the order of addition to the stream, and different streams can be executed in parallel. The present invention can analogize a stream to the concept of "thread" in central processing unit (CPU) programming: tasks in the same "thread" are executed serially, and different "threads" can be executed in parallel.

[0066] The execution subject of the electronic component stream management method provided by the present invention can be a stream manager. The stream manager refers to a device that manages streams. A user can send a stream application request carrying the number of an electronic component and the stream type to the stream manager. That is, the stream application request can include the number of an electronic component and the stream type, such as the device number and stream type of an AI chip. Among them, the stream type can include a default stream and a current stream.

[0067] S102. Determine the number and stream type of the electronic component corresponding to the stream application request, and create a stream management instance for the current thread; the stream management instance is used to manage the corresponding stream list.

[0068] In implementation, after the flow manager receives a flow application request, in response to the flow application request, it can determine the number and flow type of the electronic component corresponding to the flow application request, and create a flow management instance for the current thread. The present invention can create a flow management instance for each user thread, and this flow management instance can be responsible for the flow application and release of the corresponding thread. Each flow management instance can manage a flow list. When multiple threads are running, corresponding flow management instances can be created for multiple threads, and each flow management instance corresponds to a flow list.

[0069] It should be noted that the above flow manager can be implemented in a programming language, such as the C++ programming language; when the flow manager is implemented in the C++ programming language, the above flow management instance can be an object of the thread_local type in C++ (it is a variable declarator introduced for thread safety, indicating that the life cycle of the object belongs to the thread storage period). The significance of the thread_local object is that when different threads make flow applications, the program will create its own flow management instance for each thread. This method is simple and effective and will not affect the performance of each thread.

[0070] Figure 2 It is a schematic architecture diagram corresponding to the electronic component flow management method provided by the embodiment of the present invention. As Figure 2 shown, the flow manager in the present invention is mainly responsible for specific flow application and release operations; the flow manager can internally include N user threads, N flow manager instances, N flow lists, a shared flow pool, and a runtime module; N is a positive integer. User thread 1 corresponds to flow management instance 1, and flow management instance 1 manages flow list 1; user thread 2 corresponds to flow management instance 2, and flow management instance 2 manages flow list 2; similarly, user thread N corresponds to flow management instance N, and flow management instance N manages flow list N.

[0071] S103. According to the determined number and flow type of the electronic component, use the flow management instance to obtain the corresponding target flow from the pre-established shared flow pool, and fill it into the corresponding position of the flow list; different electronic component flows are saved in the shared flow pool.

[0072] In implementation, the electronic component can include a chip (such as an AI chip), a board card, etc. The present invention can, according to the determined number of the electronic component, use the flow management instance to obtain the information of the target electronic component with the same number as that from the shared flow pool, and according to the determined flow type, use the flow management instance to obtain the target flow of the target electronic component from the shared flow pool. When the flow type is the default flow, the corresponding default flow can be obtained from the pre-established shared flow pool by using the flow management instance; when the flow type is the current flow, the corresponding current flow can be obtained from the pre-established shared flow pool by using the flow management instance.

[0073] S104. Return the target stream in the stream list to the current thread.

[0074] In the above-mentioned electronic component stream management method provided by the embodiments of the present invention, after receiving a stream application request, the number and stream type of the electronic component corresponding to the stream application request are determined, and a stream management instance is created for the current thread. The stream management instance can obtain the target stream of the electronic component from the shared stream pool according to the determined number and stream type of the electronic component and return it. In this way, the streams of the electronic component can be managed conveniently and efficiently, with good compatibility, and can be applied to electronic components of different manufacturers and different models, supporting different threads to use different streams. And by obtaining the corresponding stream from the shared stream pool through the stream management instance, the performance loss caused by the creation of a large number of streams is avoided, thereby improving the utilization rate of the electronic component and enhancing the performance of the program.

[0075] Further, in specific implementation, in the above-mentioned electronic component stream management method provided by the embodiments of the present invention, before performing step S101 to receive a stream application request, it may further include: First, call the runtime functions of each electronic component to establish at least two streams on each electronic component in turn; where the type of the first stream established on each electronic component is the default stream, and the types of the other streams except the first stream are the current streams; then, number each electronic component, and form the streams on the numbered electronic components into a shared stream pool.

[0076] In implementation, the runtime module of the stream manager can call the runtime functions of each electronic component (such as the stream creation function) to create multiple streams on each electronic component in a set order and save them to the shared stream pool. For example, call the runtime function of the AI chip to create corresponding multiple streams on the AI chip and save them to the shared stream pool. It should be noted that the shared stream pool will create M streams (M is a configurable constant, M≥2) for each electronic component during initialization, and the first stream is the default stream. The default stream is predefined and is the stream used without special specification.

[0077] Further, in specific implementation, in the above-mentioned electronic component stream management method provided by the embodiments of the present invention, step S102 uses the stream management instance to obtain the corresponding target stream from the pre-established shared stream pool according to the determined number and stream type of the electronic component, and fill it into the corresponding position in the stream list. Specifically, it may include: Use the stream management instance to determine whether there is a target stream in the stream list corresponding to the determined number and stream type of the electronic component; if it exists, directly return the existing target stream in the stream list to the current thread; if it does not exist, use the stream management instance to obtain the target stream corresponding to the determined number and stream type of the electronic component from the pre-established shared stream pool, and fill it into the corresponding position in the stream list.

[0078] In implementation, in a stream application, a stream management instance may first determine whether there is a target stream in the stream list that corresponds to the number and stream type of a determined electronic component. If the stream exists, it directly returns; if not, then the stream management instance may apply for a corresponding stream from the shared stream pool, fill it into the corresponding position in the stream list, and finally return to the corresponding user thread.

[0079] It should be noted that the shared stream pool is a stream pool shared by all threads. Only when there is no corresponding stream of the electronic component in the stream list will it be allocated from the shared stream pool. All streams of electronic components are maintained in the shared stream pool.

[0080] Further, in specific implementation, in the above-mentioned electronic component stream management method provided by the embodiments of the present invention, the stream management instance may include a function for obtaining a default stream, a function for obtaining the current stream, a function for creating a new stream, and a function for setting a stream as the current stream.

[0081] Figure 3 It is a schematic diagram of the functions provided for the stream management instance provided by the embodiments of the present invention. In implementation, as Figure 3 shown, the stream management instance may provide four functions for user threads to call, namely: a function for obtaining a default stream, a function for obtaining the current stream, a function for creating a stream, and a function for setting the current stream. The function for obtaining a default stream can be used to obtain a default stream; the function for obtaining the current stream can be used to obtain the current stream; the function for creating a stream can be used to create a new stream; the function for setting the current stream can be used to set a stream as the current stream.

[0082] Further, in specific implementation, in the above-mentioned electronic component stream management method provided by the embodiments of the present invention, the stream list may include a default stream list and a current stream list; the default stream list is a first array; each element in the first array is a stream, and the subscript of the first array corresponds one-to-one with the number of the electronic component; each element in the first array is assigned the same stream of the corresponding electronic component during initialization; the current stream list is a second array; each element in the second array is a stream, and the subscript of the second array corresponds one-to-one with the number of the electronic component; each element in the second array is assigned at least twice.

[0083] In implementation, the stream list module includes a default stream list and a current stream list. The default stream list may be an array, and each element in the array is a stream, and the subscript of the array corresponds one-to-one with the number of the electronic component. For example, the first element of the array is the default stream of the AI chip numbered 1. It should be noted that each element of the default stream list is assigned the same stream of the corresponding electronic component during initialization, that is, the first stream created by the stream manager on this electronic component. Once each element of the default stream list is assigned, it cannot be changed anymore.

[0084] The current stream list can also be an array, where each element in the array is a stream, and the subscript of the array corresponds one-to-one with the number of the electronic component. For example, the first element of the array is the current stream of the AI chip numbered 1. The initial value of the current stream is the same as the default stream, but different from the default stream list, each element of the current stream list can be assigned multiple times.

[0085] Further, in specific implementation, in the above-mentioned electronic component stream management method provided by the embodiments of the present invention, it may further include: when the get default stream function in the stream management instance is called for the first time, obtaining the default stream from the shared stream pool using the stream list and filling it into the corresponding position of the default stream list; when the get current stream function in the stream management instance is called for the first time, obtaining the default stream from the shared stream pool using the stream list and filling it into the corresponding position of the current stream list.

[0086] In implementation, when the user thread calls the get default stream function of the stream management instance for the first time for a certain electronic component, the stream list can obtain the default stream from the shared stream pool and fill it into the corresponding position of the default stream list. When the user thread calls the get current stream function of the stream management instance for the first time for a certain electronic component, the stream list can obtain the default stream from the shared stream pool and fill it into the corresponding position of the current stream list.

[0087] Further, in specific implementation, in the above-mentioned electronic component stream management method provided by the embodiments of the present invention, after returning the target stream in the stream list to the current thread, it may further include: if the returned target stream is not the stream required by the current thread, calling the create stream function in the stream management instance to create a new stream in the stream list; calling the set current stream function in the stream management instance to set the created new stream as the current stream; returning the set current stream to the current thread.

[0088] In implementation, when the user thread wants to use other streams of the corresponding electronic component, it can create a new stream by calling the create stream function, and then call the set current stream function to set the newly created stream as the current stream.

[0089] Figure 4 It is a schematic structural diagram of the stream list provided by the embodiments of the present invention. In implementation, as Figure 4 shown, the default streams of stream list 1 and stream list 2 can be the same, but the current streams of stream list 1 and stream list 2 can be different. An identifier like stream 1.2 indicates that this stream is on electronic component 1 and is the second stream on this electronic component 1.

[0090] Further, in specific implementation, in the above-mentioned electronic component flow management method provided by the embodiments of the present invention, calling the create flow function in the flow management instance to create a new flow in the flow list may specifically include: calling the create flow function in the flow management instance to control the flow list to obtain the corresponding flow from the shared flow pool in a polling manner, and at the same time using the flow obtained by the flow list as the new flow created in the flow list.

[0091] Correspondingly, calling the set current flow function in the flow management instance to set the created new flow as the current flow may specifically include: calling the set current flow function in the flow management instance to fill the created new flow into the corresponding position in the current flow list.

[0092] In implementation, when the user thread calls the create flow function for a certain electronic component, the flow list can obtain a flow from the shared flow pool in a polling manner. When the user thread calls the set current flow function for a certain electronic component, the flow passed into the function will be filled into the corresponding position in the current flow list.

[0093] Figure 5 It is a schematic diagram of the polling mechanism of the shared flow pool provided by the embodiments of the present invention. As Figure 5 shown, the shared flow pool is shared by all user threads. Assume that flow list 1 obtains the second flow of electronic component 2 from the shared flow pool. If flow list 2 then obtains a flow from the shared flow pool immediately, the flow it obtains should be the third flow of electronic component 2.

[0094] Suppose at a certain moment, a flow list obtains the Mth flow (i.e., the last flow of the electronic component) from the shared flow pool. Then when another flow list comes to obtain a flow later, it will obtain the second flow because the first flow is the default flow and it does not participate in polling. The shared flow pool distributes flows in such a cyclic manner.

[0095] Further, in specific implementation, in the above-mentioned electronic component flow management method provided by the embodiments of the present invention, it may further include: when the current thread exits, destroying the flow management instance and at the same time destroying the flow list managed by the flow management instance.

[0096] In implementation, when the user thread exits, the flow management instance will also be destroyed along with the user thread, and at the same time the flow list will also be destroyed along with the user thread, which can avoid performance losses caused by the destruction of a large number of flows.

[0097] Further, in specific implementation, in the above-mentioned electronic component flow management method provided by the embodiments of the present invention, it may further include: when there is a flow to be destroyed in the shared flow pool, calling the runtime function of the electronic component corresponding to the flow to be destroyed to destroy the flow to be destroyed.

[0098] In implementation, functions for creating and destroying streams of electronic components from different manufacturers can vary. Specifications of these functions can be defined by the manufacturers of each electronic component. The present invention defines a runtime module for each type of device. At the code level, the runtime of each electronic component can be placed in an independent file. Figure 6 It is a schematic structural diagram of the runtime module provided by an embodiment of the present invention. In implementation, as Figure 6 shown, when chip A runs, a stream can be created on chip A through the stream creation function, and the stream to be destroyed can be destroyed through the stream destruction function; similarly, when chip B runs, a stream can be created on chip B through the stream creation function, and the stream to be destroyed can be destroyed through the stream destruction function.

[0099] Furthermore, in specific implementation, in the above-mentioned electronic component stream management method provided by an embodiment of the present invention, it may further include: when multiple threads select the default stream for calculation, serial calculation is performed in the order of functions added to the stream; wherein, after the calculation of the function that each thread has added to the default stream is completed, a new function is added to the stream.

[0100] In implementation, a user can choose to use the default stream of the electronic component for calculation. Since the default stream is the first stream created and will not change, if multiple user threads select the default stream for calculation, then these calculations will be serially calculated in the order of addition to the stream. Figure 7 It is a schematic diagram of multiple threads using the default stream for serial calculation provided by an embodiment of the present invention. As Figure 7 shown, user thread 1 adds function 1.1 to the default stream, and the default stream performs the calculation of function 1.1. After the calculation is completed, user thread 2 adds function 2.1 to the default stream, and the default stream performs the calculation of function 2.1. After the calculation is completed, user thread 3 adds function 3.1 to the default stream, and the default stream performs the calculation of function 3.1, and so on. Each user thread has to wait until the calculation of the function that has been added to the default stream is completed before adding a new function to the stream.

[0101] Furthermore, in specific implementation, in the above-mentioned electronic component stream management method provided by an embodiment of the present invention, it may further include: when multiple threads select the current stream for calculation, the corresponding current stream is obtained by polling from the shared stream pool; wherein, if the number of threads is more than the number of streams in the shared stream pool, parallel calculation is performed using the obtained current stream.

[0102] In implementation, the user can choose to perform calculations using the current stream of the electronic component. The current stream is designed for parallel calculations. When multiple user threads obtain the current stream from the shared stream pool, the shared stream pool allocates the streams in a polling manner. It should be noted that when multiple user threads obtain the current stream from the shared stream pool, if the number of user threads is more than the number of streams in the shared stream pool, different user threads may get the same stream. When the current streams of multiple user threads are different, they can perform parallel calculations.

[0103] It should be pointed out that the present invention can pre-create multiple streams for each electronic component. After that, each time the stream creation function is called, in fact, only one stream is taken out from the shared stream pool, which further avoids the performance loss caused by the creation and destruction of a large number of streams. The present invention can conveniently and efficiently manage the streams of electronic components of different manufacturers and different models, and is very easy to be extended to other types of electronic components, only by implementing the runtime of the corresponding electronic components. Different user threads can use the same stream as the current stream. User threads can use the default stream for serial calculations or use the current stream for parallel calculations.

[0104] In the above embodiments, the method for managing the electronic component stream is described in detail. The present invention also provides corresponding embodiments of an electronic component stream management device and an electronic component stream management device. It should be noted that the present invention describes the embodiments of the device part from two perspectives, one is from the perspective of functional modules, and the other is from the perspective of hardware.

[0105] Figure 9 It is a schematic structural diagram of the electronic component stream management device provided by the embodiment of the present invention. This embodiment is based on the perspective of functional modules. As Figure 9 shown, the device includes:

[0106] A request receiving module 10, configured to receive a stream application request;

[0107] An instance creation module 11, configured to determine the number and stream type of the electronic component corresponding to the stream application request, and create a stream management instance for the current thread; the stream management instance is used to manage the corresponding stream list;

[0108] A target stream obtaining module 12, configured to obtain the corresponding target stream from the pre-established shared stream pool by using the stream management instance according to the determined number and stream type of the electronic component, and fill it into the corresponding position of the stream list; different electronic component streams are stored in the shared stream pool; the target stream in the stream list is returned to the current thread.

[0109] In the above-mentioned electronic component flow management device provided by the embodiments of the present invention, through the interaction of the above four modules, a flow application request can be received, the numbers and flow types of the electronic components corresponding to the flow application request can be determined, and a flow management instance can be created for the current thread. According to the determined numbers and flow types of the electronic components, the flow management instance can obtain the target flow of the electronic components from the shared flow pool and return it, which can conveniently and efficiently manage the flow of the electronic components, has good compatibility, can be applied to electronic components of different manufacturers and different models, supports different threads to adopt different flows, and obtains the corresponding flow from the flow list through the flow management instance, avoiding the performance loss caused by the creation of a large number of flows, thereby improving the utilization rate of the electronic components and enhancing the performance of the program.

[0110] Since the embodiments of the device part correspond to the embodiments of the method part, please refer to the description of the embodiments of the method part for the embodiments of the device part, which will not be elaborated here for the time being. And it has the same beneficial effects as the above-mentioned electronic component flow management method.

[0111] Furthermore, in specific implementation, in the above-mentioned electronic component flow management device provided by the embodiments of the present invention, it may further include:

[0112] A shared flow pool establishment module, which is used to call the runtime functions of each electronic component to sequentially establish at least two flows on each electronic component; number each electronic component, and form the flows on the numbered electronic components into a shared flow pool.

[0113] In implementation, when the shared flow pool is initialized, M flows can be created for each electronic component through the flow creation function, where the first flow is the default flow, and the other flows except the first flow are the current flows.

[0114] Furthermore, in specific implementation, in the above-mentioned electronic component flow management device provided by the embodiments of the present invention, the target flow acquisition module 12 can specifically be used to use the flow management instance to determine whether there is a target flow in the flow list corresponding to the determined numbers and flow types of the electronic components; if it exists, directly return the target flow existing in the flow list to the current thread; if it does not exist, use the flow management instance to obtain the target flow corresponding to the determined numbers and flow types of the electronic components from the pre-established shared flow pool and fill it into the corresponding position in the flow list.

[0115] In implementation, the target flow acquisition module 12 can use the flow management instance to determine whether there is a target flow in the corresponding flow list that corresponds to the determined electronic component number and flow type; if the flow exists, it is directly returned; if not, the flow management instance can apply for the corresponding flow from the shared flow pool, fill it into the corresponding position in the flow list, and finally return it to the corresponding user thread. The shared flow pool here is a flow pool shared by all threads, and allocation from the shared flow pool only occurs when there is no flow corresponding to the electronic component in the flow list. All electronic component flows are maintained in the shared flow pool.

[0116] In specific implementation, the above-mentioned flow management instance may include a function for obtaining the default flow to obtain the default flow, a function for obtaining the current flow to obtain the current flow, a function for creating a new flow to create a new flow, and a function for setting a flow as the current flow to set a flow as the current flow.

[0117] In specific implementation, the above-mentioned flow list includes a default flow list and a current flow list; the default flow list is a first array; each element in the first array is a flow, and the subscript of the first array corresponds one-to-one with the electronic component number; each element in the first array is assigned the same flow of the corresponding electronic component during initialization; the current flow list is a second array; each element in the second array is a flow, and the subscript of the second array corresponds one-to-one with the electronic component number; each element in the second array is assigned at least twice.

[0118] Furthermore, in specific implementation, in the above-mentioned electronic component flow management device provided by the embodiments of the present invention, it may further include:

[0119] The first-time flow acquisition module can specifically be used to, when the function for obtaining the default flow in the flow management instance is called for the first time, obtain the default flow from the shared flow pool using the flow list and fill it into the corresponding position in the default flow list; when the function for obtaining the current flow in the flow management instance is called for the first time, obtain the default flow from the shared flow pool using the flow list and fill it into the corresponding position in the current flow list.

[0120] Furthermore, in specific implementation, in the above-mentioned electronic component flow management device provided by the embodiments of the present invention, it may further include:

[0121] The new flow acquisition module can specifically be used to, if the returned target flow is not the flow required by the current thread, call the function for creating a new flow in the flow management instance to create a new flow in the flow list; call the function for setting the current flow in the flow management instance to set the created new flow as the current flow; and return the set current flow to the current thread.

[0122] Among them, the create stream function in the stream management instance can be called to control the stream list to obtain the corresponding stream from the shared stream pool in a polling manner, and at the same time, the stream obtained by the stream list is used as the new stream created in the stream list. In addition, the set current stream function in the stream management instance is called to fill the created new stream into the corresponding position of the current stream list.

[0123] Further, in specific implementation, in the above-mentioned electronic component stream management device provided by the embodiments of the present invention, it may further include:

[0124] A first calculation module, configured to perform serial calculation in the order of adding functions to the stream when multiple threads select the default stream for calculation; wherein, each thread waits until the function calculation added to the default stream is completed, and then adds a new function to the stream.

[0125] Further, in specific implementation, in the above-mentioned electronic component stream management device provided by the embodiments of the present invention, it may further include:

[0126] A second calculation module, configured to allocate and obtain the corresponding current stream from the shared stream pool in a polling manner when multiple threads select the current stream for calculation; wherein, if the number of threads is more than the number of streams in the shared stream pool, parallel calculation is performed using the allocated current stream.

[0127] Further, in specific implementation, in the above-mentioned electronic component stream management device provided by the embodiments of the present invention, it may further include:

[0128] A first destruction module, configured to destroy the stream management instance and simultaneously destroy the stream list managed by the stream management instance when the current thread exits;

[0129] A second destruction module, configured to call the runtime function of the electronic component corresponding to the stream to be destroyed to destroy the stream to be destroyed when there is a stream to be destroyed in the shared stream pool.

[0130] Figure 10 It is a schematic structural diagram of the electronic component stream management device provided by the embodiments of the present invention. This embodiment is based on a hardware perspective, as Figure 10 shown, the electronic component stream management device includes:

[0131] A memory 20, configured to store a computer program;

[0132] A processor 21, configured to implement the steps of the electronic component stream management method as mentioned in the above embodiments when executing the computer program.

[0133] Among them, the processor 21 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 21 may be implemented in at least one hardware form of a Digital Signal Processor (DSP), a Field-Programmable Gate Array (FPGA), or a Programmable Logic Array (PLA). The processor 21 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the wake state, also known as the CPU; the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 21 may be integrated with a Graphics Processing Unit (GPU), and the GPU is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 21 may also include an Artificial Intelligence (AI) processor, and the AI processor is used to process computational operations related to machine learning.

[0134] The memory 20 may include one or more non-volatile storage media, and the non-volatile storage media may be non-transitory. The memory 20 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices and flash storage devices. In this embodiment, the memory 20 is at least used to store the following computer program 201. After the computer program is loaded and executed by the processor 21, it can implement the relevant steps of the electronic component flow management method disclosed in any of the foregoing embodiments. In addition, the resources stored in the memory 20 may also include an operating system 202 and data 203, etc., and the storage method may be temporary storage or permanent storage. Among them, the operating system 202 may include Windows, Unix, Linux, etc. The data 203 may include, but is not limited to, the data involved in the above-mentioned electronic component flow management method.

[0135] In some embodiments, the electronic component flow management device may further include a display screen 22, an input / output interface 23, a communication interface 24, a power supply 25, and a communication bus 26. Those skilled in the art can understand that Figure 10 the structure shown in does not constitute a limitation on the electronic component flow management device, and it may include more or fewer components than shown in the figure. The electronic component flow management device provided by the embodiments of the present invention includes a memory and a processor. When the processor executes the program stored in the memory, it can implement the following method: the electronic component flow management method, and the effect is the same.

[0136] Finally, the present invention also provides an embodiment corresponding to a non-volatile storage medium. A computer program is stored on the non-volatile storage medium, and when the computer program is executed by a processor, the steps recorded in the above method embodiment are implemented.

[0137] It can be understood that if the method in the above embodiments 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 the present invention, 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 executes all or part of the steps of the methods described in the various embodiments of the present invention. The foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical discs that can store program codes. The non-volatile storage medium provided by the present invention can implement the above-mentioned electronic component flow management method, and the effect is the same.

[0138] Finally, the present invention also provides an embodiment corresponding to a computer program product. The computer program product includes computer programs / instructions, and when the computer programs / instructions are executed by a processor, the steps recorded in the above embodiment of the electronic component flow management method are implemented. The computer program product provided by the present invention can implement the above-mentioned electronic component flow management method, and the effect is the same.

[0139] It should also be noted that in this specification, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprises", "comprising" or any other variation thereof is intended to cover a non-exclusive inclusion, such that a process, method, article or device comprising a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the phrase "comprising a..." does not exclude the presence of additional identical elements in the process, method, article or device comprising the element.

[0140] The above has introduced in detail the electronic component flow management method, device, medium and computer program product provided by the present invention. The various embodiments in the specification are described in a progressive manner. Each embodiment focuses on the differences from other embodiments. For the same or similar parts among the various embodiments, reference can be made to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple. For the relevant parts, reference can be made to the description in the method part. It should be noted that for those of ordinary skill in the art in the technical field of the present invention, without departing from the principle of the present invention, several improvements and modifications can be made to the present invention, and these improvements and modifications also fall within the protection scope of the present invention.

Claims

1. A method for managing electronic component flow, characterized in that: include: Calling the runtime function of each electronic component to sequentially establish at least two streams on each electronic component; wherein the type of the first stream established on each electronic component is a default stream, and the types of other streams except the first stream are current streams; Number each electronic component, and organize the flows on each numbered electronic component into a shared flow pool; Receive a flow application request; Determine the number and flow type of the electronic component corresponding to the flow application request, and create a flow management instance for the current thread; the flow management instance is used to manage the corresponding flow list; According to the determined number and flow type of the electronic component, the flow management instance is used to obtain the corresponding target flow from the shared flow pool and fill it into the corresponding position of the flow list; the shared flow pool stores flows of different electronic components; Return the target stream in the stream list to the current thread; When multiple threads select the default stream for calculation, they perform serial calculations in the order in which the corresponding functions are added to the stream; each thread adds a new function to the stream after the calculation of the function already added to the default stream is completed; When multiple threads select the current stream for calculation, the corresponding current stream is allocated from the shared stream pool in a polling manner; if the number of threads is greater than the number of streams in the shared stream pool, the allocated current stream is used for parallel calculation.

2. The electronic component flow management method according to claim 1, characterized in that: According to the determined number and flow type of the electronic component, the flow management instance is used to obtain the corresponding target flow from the shared flow pool and fill it into the corresponding position of the flow list, including: Using the flow management instance, determining whether there is a target flow corresponding to the number and flow type of the determined electronic component in the flow list; If so, the target stream in the stream list is directly returned to the current thread; If it does not exist, the target flow corresponding to the determined number and flow type of the electronic component is obtained from the shared flow pool using the flow management instance, and is filled into the corresponding position of the flow list.

3. The electronic component flow management method according to claim 2, characterized in that: The stream management instance includes a get default stream function for obtaining a default stream, a get current stream function for obtaining a current stream, a create stream function for creating a new stream, and a set current stream function; the set current stream function is used to set a stream as the current stream.

4. The electronic component flow management method according to claim 3, characterized in that: The stream list includes a default stream list and a current stream list; The default flow list is a first array; each element in the first array is a flow, and the subscripts of the first array correspond to the numbers of the electronic components one by one; each element in the first array is assigned the same flow of the corresponding electronic component during initialization; The current flow list is a second array; each element in the second array is a flow, and the subscript of the second array corresponds to the number of the electronic component one by one; each element in the second array is assigned a value at least twice.

5. The electronic component flow management method according to claim 4, characterized in that: Also includes: When the default stream acquisition function in the stream management instance is called for the first time, the default stream is acquired from the shared stream pool and filled into the corresponding position of the default stream list; When the get current stream function in the stream management instance is called for the first time, a default stream is obtained from the shared stream pool and filled into the corresponding position of the current stream list.

6. The electronic component flow management method according to claim 4, characterized in that: After returning the target stream in the stream list to the current thread, the method further includes: If the returned target stream is not the stream required by the current thread, then calling the create stream function in the stream management instance to create a new stream in the stream list; Calling the set current stream function in the stream management instance to set the created new stream as the current stream; Return the set current stream to the current thread.

7. The electronic component flow management method according to claim 6, characterized in that: Calling the create stream function in the stream management instance to create a new stream in the stream list includes: Calling a create stream function in the stream management instance to control the stream list to obtain corresponding streams from the shared stream pool in a polling manner, and using the streams obtained by the stream list as new streams created in the stream list; Correspondingly, calling the set current stream function in the stream management instance to set the created new stream as the current stream includes: The set current stream function in the stream management instance is called to fill the created new stream into the corresponding position of the current stream list.

8. The electronic component flow management method according to claim 1, characterized in that: Also includes: When the current thread exits, the stream management instance is destroyed, and the stream list managed by the stream management instance is destroyed at the same time.

9. The electronic component flow management method according to claim 1, characterized in that: Also includes: When there is a flow to be destroyed in the shared flow pool, a runtime function of an electronic component corresponding to the flow to be destroyed is called to destroy the flow to be destroyed.

10. An electronic component flow management device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the electronic component flow management method as claimed in any one of claims 1 to 9 when executing the computer program.

11. A non-volatile storage medium, characterized in that: The non-volatile storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the electronic component flow management method according to any one of claims 1 to 9 are implemented.

12. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the electronic component flow management method according to any one of claims 1 to 9 are implemented.

Citation Information

Patent Citations

  • Cloud resource creation method, system and device and readable storage medium

    CN110532076A