Task processing method and device, storage medium and electronic equipment
By introducing task processing modules and resource management modules into the OpenCL application framework, tasks are directly executed in context instances, solving the problem of increasing communication overhead for cross-device transit operations, and achieving efficient task processing and performance improvement.
Patent Information
- Application Number
- CN202411734059.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-03-07
- Estimated Expiration
- 2044-11-29
AI Technical Summary
In the OpenCL application framework, when cross-device computing tasks are executed, the sharing of context instances cannot be achieved, resulting in the need to perform complex cross-device transit operations, which increases communication overhead and reduces the performance of computing tasks.
By introducing a task processing module and a resource management module into the task processing device, the task processing module receives memory instances passed in by the external OpenCL library, determines the corresponding context instances based on the memory instance, and uses the resource management module to find or create a kernel function instance in the hash table, and directly executes tasks in the context instance to avoid unnecessary data redirection.
By directly executing tasks in context instances, data redirection operations are reduced and task processing efficiency is improved. At the same time, the existing kernel function instances are used to avoid duplicate compilation, further improving performance.
Smart Images

Figure CN119576565A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a task processing method and device, a storage medium, and an electronic device. Background Art
[0002] With the rapid development of computer technology, cross-platform parallel programming has become a key means to improve computing performance. TM (Open Computing Language) is an open, royalty-free standard that is widely used for parallel programming of various accelerators in supercomputers, cloud servers, personal computers, mobile devices, and embedded platforms. OpenCL allows users to write programs that conform to its standards and run them on processor devices that implement the OpenCL standard, thereby making full use of hardware acceleration capabilities.
[0003] In the OpenCL architecture, an OpenCL kernel is a function that can run on devices supported by OpenCL and is managed by cl_kernel in the OpenCL Runtime. These kernels can be stored in the same OpenCL Program (program instance management module) and managed as a whole using cl_program. OpenCLProgram is usually released with the application in source code form and compiled into binary code executable by the OpenCL Runtime at runtime. This compilation mechanism ensures that the program can run flexibly on different processor devices, but the processing efficiency is low.
[0004] In addition, in some OpenCL application frameworks (such as TensorFlow), context instances (cl_context) cannot be shared, which results in the need to perform complex cross-device transfer operations when executing computing tasks between multiple plug-ins. This communication overhead greatly reduces the performance of the entire computing task. Summary of the invention
[0005] The present disclosure proposes a task processing technical solution.
[0006] According to one aspect of the present disclosure, there is provided a task processing device, comprising:
[0007] A task processing module receives a memory instance transmitted by an external OpenCL library, and determines a context instance corresponding to the memory instance according to the memory instance, wherein the OpenCL library is any OpenCL library implemented based on the open computing language OpenCL;
[0008] The resource management module returns the kernel function instance to the task processing module if a kernel function instance for processing the memory instance already exists in the context instance, the kernel function instance being created when the target task was previously executed, and the target task is the same as the task type corresponding to the memory instance;
[0009] The task processing module processes the task corresponding to the memory instance based on the kernel function instance, obtains a processing result, and returns the processing result to the client through the memory instance.
[0010] In a possible implementation, the task processing module sends a resource application request to the resource management module, wherein the resource application request includes the context instance;
[0011] The resource management module, in response to the resource application request, searches for the context instance in the child nodes of the root node of the hash table, where the root node is implemented based on a singleton class.
[0012] In one possible implementation, the resource management module, when the context instance is found, searches for the program instance required to execute the task in the child nodes of the context instance; when the program instance is found, searches for the kernel function instance required to execute the task in the child nodes of the program instance; when the kernel function instance is found, returns the kernel function instance to the task processing module.
[0013] In one possible implementation, the resource management module, if the context instance is not found, adds the context instance as a child node of the root node to the hash table; and generates a kernel function instance required to execute the task in the context instance, and returns the kernel function instance to the task processing module.
[0014] In one possible implementation, the resource management module creates a program instance based on the program source code of the kernel function required to execute the task, and compiles the program source code based on the program instance; adds the created program instance to the child node of the context instance in the hash table; creates a kernel function instance for managing the compiled program source code, and adds the created kernel function instance to the child node of the corresponding program instance in the hash table.
[0015] In a possible implementation manner, the device further includes:
[0016] A memory instance creation module, in response to a memory instance creation request from a client, sends a resource application request to the resource management module;
[0017] The resource management module, in response to the resource application request sent by the memory instance creation module, creates a target context instance and returns it to the memory instance creation module; adds the target context instance as a child node of the root node to the hash table;
[0018] The memory instance creation module creates a target memory instance in the target context instance and returns the target memory instance to the client. The target memory instance includes a first address for storing input data and a second address for storing output data.
[0019] In a possible implementation, the task processing module receives the target memory instance transmitted by the client, determines the target context instance corresponding to the target memory instance according to the target memory instance; sends a resource application request to the resource management module, wherein the resource application request includes the target context instance;
[0020] The resource management module, in response to a resource application request, searches for the target context instance in the child nodes of the root node of the hash table; if the target context instance is not found, adds the target context instance as a child node of the root node to the hash table; and generates a target kernel function instance required to execute the task in the target context instance, and returns the target kernel function instance to the task processing module.
[0021] In one possible implementation, the resource management module simultaneously receives data requests from multiple threads; when multiple data requests are for requesting to read data in the hash table, multiple data requests are allowed to read the contents of the hash table simultaneously; when multiple data requests include a request to modify data in the hash table, only one thread is allowed to perform the data modification operation.
[0022] In a possible implementation manner, the device further includes:
[0023] An input / output interface, wherein the input and output of the input / output interface are memory instances;
[0024] The task processing module interacts with the outside based on the input and output interface, and the task processing module is obtained by encapsulating the open source component.
[0025] According to one aspect of the present disclosure, a task processing method is provided, which is applied to a task processing device, the device comprising a task processing module and a resource management module, the method comprising:
[0026] The task processing module receives a memory instance passed in by an external OpenCL library, and determines a context instance corresponding to the memory instance according to the memory instance, wherein the OpenCL library is any OpenCL library implemented based on the open computing language OpenCL;
[0027] The resource management module returns the kernel function instance to the task processing module if a kernel function instance for processing the memory instance already exists in the context instance, wherein the kernel function instance is created when the target task is previously executed, and the target task is the same as the task type corresponding to the memory instance;
[0028] The task processing module processes the task corresponding to the memory instance based on the kernel function instance, obtains a processing result, and returns the processing result to the client through the memory instance.
[0029] According to one aspect of the present disclosure, an electronic device is provided, comprising: a processor; and a memory for storing instructions executable by the processor; wherein the processor is configured to call the instructions stored in the memory to implement the above-mentioned apparatus.
[0030] According to one aspect of the present disclosure, a computer-readable storage medium is provided, on which computer program instructions are stored, and the computer program instructions implement the above-mentioned apparatus when executed by a processor.
[0031] In the disclosed embodiment, the task processing module receives the memory instance passed in by the external OpenCL library, and determines the context instance corresponding to the memory instance according to the memory instance; the resource management module returns the kernel function instance to the task processing module when there is a kernel function instance for processing the memory instance in the context instance, and the kernel function instance is created when the target task is previously executed, and the target task is the same as the task type corresponding to the memory instance; the task processing module processes the task corresponding to the memory instance based on the kernel function instance, obtains the processing result, and returns the processing result to the client through the memory instance. Thus, by directly obtaining the context instance of the memory instance passed in by the external OpenCL library, and running the kernel function instance in the context instance for task processing, there is no need to transfer data through the memory, which reduces the data overhead caused by unnecessary data transfer operations and improves the task processing efficiency; in addition, by using the kernel function instance created when executing the task of the same task type before for task processing, there is no need to repeatedly compile the source code, which improves the task processing efficiency.
[0032] It should be understood that the above general description and the following detailed description are exemplary and explanatory only and do not limit the present disclosure. Other features and aspects of the present disclosure will become clear from the following detailed description of exemplary embodiments with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present disclosure and are used to illustrate the technical solutions of the present disclosure together with the specification.
[0034] Figure 1 A block diagram of a task processing device according to an embodiment of the present disclosure is shown.
[0035] Figure 2 A schematic diagram of the structure of a task processing device according to an embodiment of the present disclosure is shown.
[0036] Figure 3 An interaction diagram of various modules when generating a kernel function instance according to an embodiment of the present disclosure is shown.
[0037] Figure 4 An interaction diagram of various modules when calling a generated kernel function instance according to an embodiment of the present disclosure is shown.
[0038] Figure 5 An interaction diagram of various modules when a memory instance is created according to an embodiment of the present disclosure is shown.
[0039] Figure 6 A flowchart of a task processing method according to an embodiment of the present disclosure is shown.
[0040] Figure 7 A block diagram of an electronic device 1900 according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0041] Various exemplary embodiments, features and aspects of the present disclosure will be described in detail below with reference to the accompanying drawings. The same reference numerals in the accompanying drawings represent elements with the same or similar functions. Although various aspects of the embodiments are shown in the accompanying drawings, the drawings are not necessarily drawn to scale unless otherwise specified.
[0042] The word “exemplary” is used exclusively herein to mean “serving as an example, example, or illustration.” Any embodiment described herein as “exemplary” is not necessarily to be construed as preferred or advantageous over other embodiments.
[0043] The term "and / or" herein is only a description of the association relationship of the associated objects, indicating that there may be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the term "at least one" herein represents any combination of at least two of any one or more of a plurality of. For example, including at least one of A, B, and C can represent including any one or more elements selected from the set consisting of A, B, and C.
[0044] In addition, in order to better illustrate the present disclosure, numerous specific details are given in the following specific embodiments. It should be understood by those skilled in the art that the present disclosure can also be implemented without certain specific details. In some examples, methods, means, components and circuits well known to those skilled in the art are not described in detail in order to highlight the subject matter of the present disclosure.
[0045] Figure 1 A block diagram of a task processing device according to an embodiment of the present disclosure is shown as follows: Figure 1 As shown, the device 10 comprises:
[0046] The task processing module 11 receives a memory instance transmitted by an external OpenCL library, and determines a context instance corresponding to the memory instance according to the memory instance, wherein the OpenCL library is any OpenCL library implemented based on the open computing language OpenCL;
[0047] The resource management module 12, when a kernel function instance for processing the memory instance already exists in the context instance, returns the kernel function instance to the task processing module, the kernel function instance being created when the target task is previously executed, and the target task is the same as the task type corresponding to the memory instance;
[0048] The task processing module 11 processes the task corresponding to the memory instance based on the kernel function instance, obtains a processing result, and returns the processing result to the client through the memory instance.
[0049] A kernel instance (cl_kernel) is an object instance representing a kernel function (kernel). The object instance may contain a reference or identifier of a kernel function executed on an OpenCL device, which is used to manage the execution of the kernel. When a kernel instance is created using the OpenCL API (for example, through the clCreateKernel function), a variable of type cl_kernel is obtained, which represents the kernel executed on the OpenCL device. The variable can be used to set kernel parameters and to add the kernel to the command queue for kernel execution.
[0050] The compiled kernel is located in the program, which is a container that contains multiple compiled kernel functions and other related data. The program is managed by a program instance (cl_program), which contains a reference or identifier of a specific program and is used to reference or manage a specific program in the OpenCL runtime environment.
[0051] The memory instance (cl_mem) is used to manage the storage space on a device (such as a GPU). The memory instance includes a first address src for storing input data and a second address dst for storing output data.
[0052] A context instance (cl_context) is an instance object representing an OpenCL context (context). The instance object may contain a reference or identifier for indicating the context. The context is an abstract container. All computations and computation-related data transfer tasks are performed in the same context. cl_context is used to reference and operate the context in a program. When an OpenCL context is created, an instance object of the cl_context type is obtained at the same time, which is the context instance. This object can be used to perform various operations related to the context.
[0053] In the related art, during the task processing, different OpenCL libraries in the OpenCL application framework often cannot effectively reuse cl_context and cl_kernel instances, resulting in unnecessary data transfer and repeated compilation, which in turn affects the efficiency of task processing.
[0054] An external OpenCL library can be a library or framework that encapsulates OpenCL functions. From the perspective of data flow, the input and output of different OpenCL libraries are interdependent and connected in series to jointly complete a computing task. In the disclosed embodiment, the kernel function instance currently executing the task is created based on the context instance corresponding to the input memory instance, so that multiple OpenCL libraries can be integrated into the same context to execute tasks.
[0055] For the memory instance received from the outside, the context instance can be obtained by calling the OpenCL API. For example, for the memory instance, the context instance corresponding to the memory instance can be obtained by calling the clGetMemObjectInfo function. Furthermore, the clGetContextInfo function can be called for the memory instance to obtain the number of devices and device index corresponding to the context, and the clGetDeviceInfo function can be called for the index of each device to obtain detailed information related to the device. Based on this information, the storage space and OpenCL kernel required for subsequent use are initialized to ensure that the parameters passed in when calling the kernel function instance to perform the task match the context and device corresponding to the memory instance.
[0056] In addition, if multiple memory instances are received in one call, it is possible to determine whether the contexts of the various memory instances are consistent. If not, an error is returned to avoid passing wrong parameters to the device to run and causing the entire program to crash.
[0057] When executing a task, the resource management module will create a kernel function instance in the context instance. The kernel function instance is used to control the execution of the kernel function. The specific process of creating a kernel function instance can refer to the possible implementation methods provided by the present disclosure, which will not be described here. When executing a task, the same kernel function will be used for tasks of the same task type. The same task type here can be the same processing flow when the task is executed. For example, the kernel function instance used to normalize an image has the same processing flow when normalizing different images. The kernel function instance can be executed multiple times to normalize different images. The image to be normalized will be stored in the input address in the memory instance. By receiving different memory instances, different images can be normalized.
[0058] Then, after obtaining the memory instance, you can check whether there is already a kernel function instance in the context that can be used to process the newly passed in memory instance, so as to reuse the kernel function instance. If there is already a kernel function instance for processing the memory instance in the context instance, it means that when executing the target task of the same task type as that corresponding to the memory instance, a kernel function instance that can process the memory instance has been created, and the kernel function instance can be returned to the task processing module.
[0059] After the task processing module obtains the kernel function instance, it will execute the kernel function in the context obtained, which provides the necessary environment and resources for the execution of the kernel function. The kernel function will process the data stored in the address of the memory instance, which is often located in the storage medium inside the device, such as the GPU's video memory.
[0060] After the kernel function completes data processing, the processing result will be stored back in the output address dst of the memory instance. The task processing module will return the result to the client through the memory instance. The client can be an external system or component.
[0061] In the embodiments of the present disclosure, by directly obtaining the context instance of the memory instance passed in by the external OpenCL library, and running the kernel function instance in the context instance to perform task processing, there is no need to transfer data through the memory, thereby reducing the data overhead caused by unnecessary data transfer operations and improving the task processing efficiency. In addition, by utilizing the kernel function instance created when executing the same type of task before to perform task processing, there is no need to repeatedly compile the source code, thereby improving the task processing efficiency.
[0062] In one possible implementation, the task processing module sends a resource application request to the resource management module, wherein the resource application request includes the context instance; the resource management module, in response to the resource application request, searches for the context instance in the child nodes of the root node of the hash table, wherein the root node is implemented based on a singleton class.
[0063] The task processing module is responsible for processing various tasks. In the process of processing tasks, processing resources are needed. In order to obtain processing resources, the task processing module will send a resource application request to the resource management module to apply for the resources required for processing tasks. The resource application request will contain information about the context instance.
[0064] The resource management module is mainly responsible for managing and maintaining context instances and kernel function instances. When the task processing module requests a kernel function instance, the resource management module will first check whether the context instance exists. If the context instance exists, it will check whether there is a kernel function instance corresponding to the requested memory instance in the current context instance. If it exists, it will be returned to the task processing module; if it does not exist, a new kernel function instance will be created according to the request and stored in the corresponding context instance for subsequent reuse.
[0065] In addition, the resource management module can also monitor and manage the life cycle of context instances. When a context instance is no longer needed, the resource management module will be responsible for releasing the resources it occupies to ensure the stable operation of the system.
[0066] In order to find the corresponding resources quickly and efficiently, the resource management module manages the resources uniformly through a hash table. After receiving the resource application request sent by the task processing module, the resource management module will search for the corresponding resources in the hash table.
[0067] The root node of the hash table is implemented based on a singleton class, which means that in the entire device, the hash table has only one instance of the root node to ensure the uniqueness and stability of the hash table and avoid resource conflicts and confusion.
[0068] Different context instances are stored in the child nodes of the root node. Since the context instance includes a reference or identifier for indicating the context, such as a pointer for indicating the context in the system, the pointer of the context instance can be stored in the child nodes of the root node.
[0069] The resource management module will search the child nodes of the root node one by one according to the pointer of the context instance until it finds a node that matches the context instance in the request. After finding the matching node, the resource management module can obtain the corresponding resource information and allocate the required resources to the task processing module based on this information.
[0070] In the disclosed embodiment, the task processing module sends a resource application request to the resource management module, and the resource application request includes the context instance; the resource management module, in response to the resource application request, searches for the context instance in the child nodes of the root node of the hash table, and the root node is implemented based on the singleton class. Thus, by sending the resource application request through the task processing module, the resource management module searches for the context instance using the hash table implemented based on the singleton class, thereby realizing rapid location and allocation of resources, and improving resource utilization and overall performance of the device.
[0071] By managing resources with a hash table built based on the singleton class as the root node, unified management of resources is achieved, which makes it easy to track and manage all created OpenCL resources and ensure their consistency and correctness throughout the application. And because resources are managed in a unified way, unnecessary resource initialization can be avoided. When a resource needs to be used, the framework will first check whether it already exists. If it does, it will be reused directly, thus reducing the initialization overhead. By reducing the number of resource initializations and avoiding repeated creation of the same resource, system performance can be significantly improved.
[0072] In addition, using a singleton class as the root node to build a hash table to manage resources can simplify the programming model, making it easier for developers to understand and operate OpenCL resources. The task processing module developed by the developer only needs to access and operate the entire resource tree through the singleton class without having to worry about the specific implementation details, which can easily realize the encapsulation of the application.
[0073] In one possible implementation, the resource management module, when the context instance is found, searches for the program instance required to execute the task in the child nodes of the context instance; when the program instance is found, searches for the kernel function instance required to execute the task in the child nodes of the program instance; when the kernel function instance is found, returns the kernel function instance to the task processing module.
[0074] The hash table implements a tree structure in which the child nodes of the root node implemented based on the singleton class contain the managed context instances, and the nodes of the context instances contain the program instances created in the context; similarly, the child nodes of the program instance nodes contain the kernel function instances of the compiled kernel functions in the program.
[0075] The resource management module searches the hash table for items that match the context instance provided by the task processing module. In the tree structure of the hash table, each node stores a pointer or reference to the instance. For the node of the context instance, it stores the pointer or reference in the context instance, so the context instance is searched by traversing the pointers or references in these nodes.
[0076] When a context instance is found, the resource management module will further search for the program instance required to execute the task in the child nodes of the node. The program instance node also stores pointers or references to the program, and the program instance related to the task is searched by traversing the pointers or references in these child nodes.
[0077] After finding the program instance, the resource management module will continue to search for the kernel function instance required to execute the task in the child nodes of the program instance. The kernel function instance node stores the pointer or reference in the kernel function instance, and searches for the kernel function used to execute the task by traversing the pointers or references in these child nodes.
[0078] Finally, when the resource management module successfully finds the required kernel function instance, it returns the kernel function instance to the task processing module. After the task processing module obtains the kernel function instance, it can call the instance to run the kernel function to execute the corresponding task.
[0079] In the disclosed embodiment, through the hash table design of this tree structure, the resource management module can efficiently manage and find various resource instances. The instance pointer or reference stored in each node makes resource management more direct and fast, improves the accuracy and reliability of resource access, and realizes effective management and efficient utilization of resources.
[0080] In one possible implementation, the resource management module, if the context instance is not found, adds the context instance as a child node of the root node to the hash table; and generates a kernel function instance required to execute the task in the context instance, and returns the kernel function instance to the task processing module.
[0081] If the resource management module fails to find the requested context instance in the hash table, since context instances can be shared, the new context instance can be added to the hash table as a child node of the root node to ensure that when a processing task requiring the same context is received in the future, the context instance can be found quickly to avoid repeated creation and addition of contexts.
[0082] After adding the context instance to the hash table, the resource management module generates the kernel function instance required to execute the task in the newly added context instance. This kernel function instance is created according to the specific requirements of the task and can meet the requirements of the task processing module to execute a specific task. The specific process of creating a kernel function instance can be found in the possible implementation methods provided in the present disclosure, which will not be described here.
[0083] After generating the kernel function instance, the resource management module will return it to the task processing module. After obtaining the kernel function instance, the task processing module can use the kernel function instance to execute the corresponding task.
[0084] In the embodiment of the present disclosure, the resource management module, if the context instance is not found, adds the context instance as a child node of the root node to the hash table; and generates a kernel function instance required to execute the task in the context instance, and returns the kernel function instance to the task processing module to ensure the smooth execution of the task. When a processing task requiring the same context is received in the future, the context instance can be found quickly, avoiding repeated creation and addition of context, thereby improving the processing efficiency of the task.
[0085] In one possible implementation, the resource management module creates a program instance based on the program source code of the kernel function required to execute the task, and compiles the program source code based on the program instance; adds the created program instance to the child node of the context instance in the hash table; creates a kernel function instance for managing the compiled program source code, and adds the created kernel function instance to the child node of the corresponding program instance in the hash table.
[0086] In the case where the context instance is not found, after the context instance is added to the hash table, the task processing module will request to create a kernel function instance, that is, initialize the kernel function.
[0087] The task processing module may send a request to the resource management module to obtain a kernel function instance. If the kernel function instance does not exist, the resource management module will create a kernel function instance based on the program source code corresponding to the kernel function instance.
[0088] The resource management module will create a program instance based on the provided program source code. The program instance is an abstract representation of the program source code, which contains the program source code's meta information and the necessary execution environment. By creating a program instance, the resource management module can better manage and control the compilation and execution process of the program source code.
[0089] After creating a program instance, the resource management module will compile the program source code and convert it into machine language code (such as binary code) through compilation, so that the program can be executed on the target device. The resource management module will use the appropriate compiler and compilation parameters to compile the program source code to generate executable machine code.
[0090] After the compilation is completed, the resource management module will add the created program instance to the corresponding position in the hash table. Specifically, the resource management module will add the program instance to the child node of the context instance and associate the program instance with the context instance so that the corresponding program instance can be quickly found and accessed when needed.
[0091] Then, the resource management module will create a kernel function instance for managing the compiled program source code. A kernel function instance is an object instance representing a kernel function (kernel), which can uniquely identify a kernel function (program) in a program instance.
[0092] The resource management module will add the created kernel function instance to the child node of the corresponding program instance in the hash table. Therefore, when the task processing module needs to execute a task, it can find the corresponding context instance through the hash table, and then find the associated program instance and kernel function instance. The task processing module can directly call the kernel function instance to execute the task without having to compile and create the program source code again.
[0093] In an embodiment of the present disclosure, the device also includes: a memory instance creation module, which sends a resource application request to the resource management module in response to a memory instance creation request from a client; the resource management module, which creates a target context instance and returns it to the memory instance creation module in response to the resource application request sent by the memory instance creation module; adds the target context instance as a child node of the root node to the hash table; the memory instance creation module creates a target memory instance in the target context instance and returns the target memory instance to the client, wherein the target memory instance includes a first address for storing input data and a second address for storing output data.
[0094] The task processing device provided by the present disclosure may also create a context instance and a memory instance. For example, when multiple devices jointly complete a computing task, the task processing device may be the first device in the pipeline, so no other devices will pass in the memory instance. In this case, when a task processing request is received, the memory instance and the context instance will be created.
[0095] After receiving the memory instance creation request, the memory instance creation module will send a resource application request to the resource management module. After receiving the resource application request, the resource management module will first create a target context instance, which is a set of resources and environments required to perform a specific task or operation. It contains the necessary information required to perform the task.
[0096] After creating the target context instance, the resource management module will return it to the memory instance creation module. At the same time, in order to achieve efficient management and fast search of context instances, the resource management module will also add the target context instance as a child node of the root node to the hash table, so that the resource management module can easily manage and search for context instances later.
[0097] After obtaining the target context instance, the memory instance creation module will further create a target memory instance in the context instance to facilitate the client to input data and receive output data. The memory instance contains a first address for storing input data and a second address for storing output data. Through these two addresses, the client can easily input data and read processed data from the memory instance.
[0098] The memory instance creation module returns the created target memory instance to the client. After obtaining the memory instance, the client can use the address in it to store and read data.
[0099] For example, when normalizing an image, the client will load the image file into the CPU's memory (main memory), and then the task processing device will allocate a GPU's video memory and create a memory instance. The memory instance is then sent to the client so that the client can copy the image data in the CPU's main memory to the created GPU video memory.
[0100] In the disclosed embodiment, the memory instance creation module, in response to the client's memory instance creation request, sends a resource application request to the resource management module; the resource management module, in response to the resource application request sent by the memory instance creation module, creates a target context instance and returns it to the memory instance creation module; the target context instance is added to the hash table as a child node of the root node; the memory instance creation module creates a target memory instance in the target context instance, and returns the target memory instance to the client, wherein the target memory instance includes a first address for storing input data and a second address for storing output data. Thus, the memory instance creation module and the resource management module work together to achieve efficient creation and management of memory instances.
[0101] In one possible implementation, the task processing module receives the target memory instance transmitted by the client, determines the target context instance corresponding to the target memory instance based on the target memory instance; sends a resource application request to the resource management module, wherein the resource application request includes the target context instance; the resource management module searches for the target context instance in the child nodes of the root node of the hash table in response to the resource application request; if the target context instance is not found, adds the target context instance to the hash table as a child node of the root node; and generates a target kernel function instance required to execute the task in the target context instance, and returns the target kernel function instance to the task processing module.
[0102] After creating the context instance and memory instance, you also need to create a kernel function instance for executing the task. The specific process is as follows.
[0103] The task processing module receives the target memory instance passed in by the client. The target memory instance is created according to the client's memory instance creation request. After receiving the target memory instance, the task processing module determines the target context instance of the target memory instance, and then sends a resource application request to the resource management module. The request contains the information of the target context instance so that the resource management module can perform corresponding resource search and allocation based on the information.
[0104] The resource management module responds to the resource application request and searches for the target context instance in the child nodes of the root node of the hash table. After finding the target context instance, the resource management module generates the target kernel function instance required to perform the specific task in the context instance. The process of creating the target kernel function instance is similar to the process of creating the kernel function instance in the previous text. First, a program instance is created, then the kernel function source code is compiled, and then the kernel function instance is created. The specific process can be found in the description of generating the kernel function instance provided in the present disclosure, which will not be repeated here.
[0105] The resource management module returns the generated target kernel function instance to the task processing module. After obtaining the kernel function instance, the task processing module can execute the corresponding task.
[0106] In the disclosed embodiment, after the target memory instance is created and returned to the client, the task processing module can determine the corresponding target context instance based on the target memory instance passed in by the client, and request the resource management module to generate the required target kernel function instance. This is not only suitable for task processing between OpenGL libraries, but also can adapt to the needs of the client to directly request processing tasks, and has high adaptability.
[0107] In one possible implementation, the resource management module receives data requests from multiple threads simultaneously; when the multiple data requests are for requesting to read data in the hash table, the multiple data requests are allowed to read the contents of the hash table simultaneously; when there is a data request for modifying the data in the hash table among the multiple data requests, only one thread is allowed to perform the data modification operation.
[0108] In this implementation, the resource management module can receive data requests from task processing modules and / or clients in multiple threads, and these requests include requests to read data in a hash table or requests to modify data in a hash table.
[0109] In the case where multiple data requests are all for reading data in the hash table, that is, all multiple data requests are read requests, the resource management module allows multiple threads to read the contents of the hash table at the same time. Since the read operation does not modify the state of the hash table, multiple threads can read at the same time without interfering with each other. This concurrent reading mechanism improves the efficiency and response speed of task processing.
[0110] However, when there is a request for modifying data in the hash table among the multiple data requests, that is, there is at least one modification request (there may also be other modification requests or other read requests among the multiple data requests), since the modification operation will change the state of the hash table, if multiple threads perform modifications at the same time, data inconsistency or conflict may result. Therefore, the resource management module only allows one thread to perform the data modification operation.
[0111] Exemplarily, in order to implement this thread-safe hash table operation, a template class can be implemented, in which a semaphore is added to the class member of the template class, and access to the hash table is controlled by the semaphore. When a thread wants to modify the hash table, the thread will try to obtain an exclusive lock. If no other thread holds an exclusive lock at this time, the thread can successfully obtain the lock and perform the modification operation. During the modification, other threads cannot obtain the exclusive lock, so they cannot perform the modification operation. If other threads already hold the exclusive lock at this time, the current thread will be blocked until the exclusive lock is released. When multiple threads want to read the hash table at the same time, they can obtain a shared lock, and multiple threads can hold a shared lock at the same time, so they can read the contents of the hash table at the same time. However, if a thread holds an exclusive lock at this time, other threads cannot obtain a shared lock or read the hash table.
[0112] In this way, thread-safe access to the hash table is achieved. It allows multiple threads to read the hash table at the same time, but ensures that only one thread can perform the modification operation. Data conflicts and inconsistencies are avoided, ensuring the stability and correctness of the device.
[0113] In the disclosed embodiment, the resource management module can process data requests of multiple threads simultaneously and implement thread-safe access to the hash table, thereby improving the efficiency and response speed of data processing and ensuring the consistency and correctness of data.
[0114] In a possible implementation, the device also includes: an input-output interface, the input and output of the input-output interface are memory instances; the task processing module, which interacts with the outside based on the input-output interface, and the task processing module is obtained by encapsulating the open source component.
[0115] The device provided in the embodiment of the present disclosure is provided with an input / output interface, which is mainly responsible for the interaction between the device and the outside. The input and output of the input / output interface are both memory instances, so as to facilitate efficient data transmission and exchange with external systems or components.
[0116] The task processing module interacts with the outside based on the input and output interface. In the embodiment of the present disclosure, the task processing module is obtained by encapsulating the open source component. That is to say, the device can be implemented by encapsulating and integrating the open source component and embedding its function into the task processing module. This encapsulation method enables the device to more conveniently utilize the functions of the open source component, and also customize and optimize the functions as needed.
[0117] Taking the function of using OpenCL to generate pseudo-random numbers in the TensorFlow plug-in as an example, the device provided by the present disclosure can be encapsulated using the open source component clRNG. clRNG is an open source component for generating random numbers, which can use the parallel computing capabilities of OpenCL to generate high-quality pseudo-random number sequences. By encapsulating clRNG into the task processing module and exposing the function interface for generating random numbers, which uses memory instances as input and output, external systems or components can interact with the device provided by the present disclosure in the form of memory instances.
[0118] When an external system or component sends a request through the input and output interface, the task processing module can call the encapsulated clRNG function, generate the corresponding pseudo-random number sequence, and return it to the outside through the input and output interface.
[0119] In this way, not only the adaptation process of the TensorFlow plug-in is simplified, but also the processing performance is improved. By encapsulating and integrating open source components, the dependence on external systems or components is reduced, and its own flexibility and scalability are improved.
[0120] In the disclosed embodiment, the device further includes: an input / output interface, the input and output of the input / output interface are memory instances; the task processing module interacts with the outside based on the input / output interface, and the task processing module is obtained by encapsulating the open source component. Thus, by interacting with the outside through the input / output interface and encapsulating the task processing module using the open source component, the functions of the open source component can be directly utilized to realize the reuse of the kernel function instance and the context instance, and various open source OpenCL function libraries can be easily accessed, reducing the time required for adaptation development.
[0121] An application scenario of an embodiment of the present disclosure is described below. Figure 2 The structural diagram of a task processing device according to an embodiment of the present disclosure is shown. In this application scenario, the task processing module is specifically implemented as a normalization module, and the normalization module performs normalization processing on the image. The resource management module includes a resource application module, a context instance management module, a program instance management module, a kernel function instance management module, and a memory instance creation module. The functions implemented by each module are as follows.
[0122] Figure 3 The interaction diagram of each module when generating a kernel function instance according to an embodiment of the present disclosure is shown as follows: Figure 3As shown, the external system / component passes in a memory instance, which includes a storage address src for storing input data. The normalization module receives the memory instance and obtains the context instance of the memory instance, and then sends a resource application request to the resource application module. The resource application module does not find the context instance in the hash table, so it instructs the context instance management module to initialize the context instance and add the context instance to the child node of the root node of the hash table; the normalization module requests the context instance management module to obtain the kernel function instance, and the context instance management module instructs the program instance management module to create a program instance in the context instance, and uses the program instance to compile the program source code to obtain a compiled program, which includes a kernel function; the program instance management module instructs the kernel function instance management module to create a kernel function instance, and the kernel function instance points to the compiled kernel function.
[0123] The normalization module runs the kernel function through the kernel function instance, normalizes the data in the storage address src, stores the processing result of the kernel function in the storage address dst, and returns dst to the external system / component through the memory instance.
[0124] Figure 4 The interaction diagram of each module when calling the generated kernel function instance according to the embodiment of the present disclosure is shown as follows: Figure 4 As shown, the external system / component passes in a memory instance, which includes a storage address src for storing input data. The normalization module receives the memory instance and obtains the context instance of the memory instance, and then sends a resource application request to the resource application module. The resource application module finds the context instance in the hash table, and the context instance management module searches for the program instance in the child nodes of the context instance. When the program instance is found, the kernel function instance management module searches for the kernel function instance in the child nodes of the program instance, and finally finds the kernel function instance that has been created when the normalization task was previously executed.
[0125] The normalization module runs the kernel function through the kernel function instance, normalizes the data in the storage address src, stores the processing result of the kernel function in the storage address dst, and returns dst to the external system / component through the memory instance.
[0126] Figure 5 The interaction diagram of each module when creating a memory instance according to an embodiment of the present disclosure is shown as follows: Figure 5As shown, the client sends a memory instance creation request to the memory instance creation module. After receiving the memory instance creation request, the memory instance creation module sends a resource application request to the resource application module. After receiving the resource application request, the resource application module instructs the context instance management module to create a context instance. After creating the target context instance, the context management module returns it to the memory instance creation module. At the same time, the resource management module also adds the context instance as a child node of the root node to the hash table.
[0127] After obtaining the target context instance, the memory instance creation module will further create a memory instance in the context instance, and then return the memory instance containing the input address src to the client. The client will request the memory instance creation module to create the output address dst in the context instance, and the memory instance creation module will return the memory instance containing the output address to the client.
[0128] The client passes the generated memory instance to the normalization module. The normalization module receives the memory instance and obtains the context instance of the memory instance, and then sends a resource application request to the resource application module. The resource application module does not find the context instance in the hash table, so it instructs the context instance management module to initialize the context instance and add the context instance to the child node of the root node of the hash table; the normalization module requests the context instance management module to obtain the kernel function instance. The context instance management module instructs the program instance management module to create a program instance in the context instance, and uses the program instance to compile the program source code to obtain the compiled program, which includes the kernel function; the program instance management module instructs the kernel function instance management module to create a kernel function instance, which points to the compiled kernel function.
[0129] The normalization module runs the kernel function through the kernel function instance, normalizes the data in the storage address src, stores the processing result of the kernel function in the storage address dst, and returns dst to the external system / component through the memory instance.
[0130] In a possible implementation, the task processing device can be implemented based on an electronic device such as a terminal device or a server, and the terminal device can be a user equipment (UE), a mobile device, a user terminal, a terminal, a cellular phone, a cordless phone, a personal digital assistant (PDA), a handheld device, a computing device, a vehicle-mounted device, a wearable device, etc. The device can be implemented by a processor calling a computer-readable instruction stored in a memory. Alternatively, the device can be implemented by a server.
[0131] In addition, the present disclosure also provides a task processing method, an electronic device, a computer-readable storage medium, and a program, all of which can be used to implement any task processing device provided by the present disclosure. The corresponding technical solutions and descriptions can be found in the corresponding records in the method part and will not be repeated here.
[0132] Figure 6 A flowchart of a task processing method according to an embodiment of the present disclosure is shown. The task processing method is applied to a task processing device, and the device includes a task processing module and a resource management module. Figure 6 As shown, the method includes:
[0133] In step S21, the task processing module receives a memory instance transmitted by an external OpenCL library, and determines a context instance corresponding to the memory instance according to the memory instance, wherein the OpenCL library is any OpenCL library implemented based on the open computing language OpenCL;
[0134] In step S22, if a kernel function instance for processing the memory instance already exists in the context instance, the resource management module returns the kernel function instance to the task processing module, where the kernel function instance is created when the target task is previously executed, and the target task is the same as the task type corresponding to the memory instance;
[0135] In step S23, the task processing module processes the task corresponding to the memory instance based on the kernel function instance, obtains a processing result, and returns the processing result to the client through the memory instance.
[0136] In a possible implementation, the method further includes:
[0137] The task processing module sends a resource application request to the resource management module, wherein the resource application request includes the context instance;
[0138] The resource management module, in response to the resource application request, searches for the context instance in the child nodes of the root node of the hash table, where the root node is implemented based on a singleton class.
[0139] In a possible implementation, when a kernel function instance for processing the memory instance already exists in the context instance, the resource management module returns the kernel function instance to the task processing module, including:
[0140] When the context instance is found, the resource management module searches for the program instance required to execute the task in the child nodes of the context instance; when the program instance is found, the resource management module searches for the kernel function instance required to execute the task in the child nodes of the program instance; when the kernel function instance is found, the kernel function instance is returned to the task processing module.
[0141] In a possible implementation, the method further includes:
[0142] The resource management module, when the context instance is not found, adds the context instance as a child node of the root node to the hash table; generates a kernel function instance required to execute the task in the context instance, and returns the kernel function instance to the task processing module.
[0143] In a possible implementation, the resource management module, when the context instance is not found, adds the context instance as a child node of the root node to the hash table; and generates a kernel function instance required to execute the task in the context instance, including:
[0144] The resource management module creates a program instance based on the program source code of the kernel function required to execute the task, and compiles the program source code based on the program instance; adds the created program instance to the child node of the context instance in the hash table; creates a kernel function instance for managing the compiled program source code, and adds the created kernel function instance to the child node of the corresponding program instance in the hash table.
[0145] In a possible implementation, the method further includes:
[0146] A memory instance creation module, in response to a memory instance creation request from a client, sends a resource application request to the resource management module;
[0147] The resource management module, in response to the resource application request sent by the memory instance creation module, creates a target context instance and returns it to the memory instance creation module; adds the target context instance as a child node of the root node to the hash table;
[0148] The memory instance creation module creates a target memory instance in the target context instance and returns the target memory instance to the client. The target memory instance includes a first address for storing input data and a second address for storing output data.
[0149] In a possible implementation, the method further includes:
[0150] The task processing module receives the target memory instance transmitted by the client, determines the target context instance corresponding to the target memory instance according to the target memory instance; sends a resource application request to the resource management module, wherein the resource application request includes the target context instance;
[0151] The resource management module, in response to a resource application request, searches for the target context instance in the child nodes of the root node of the hash table; if the target context instance is not found, adds the target context instance as a child node of the root node to the hash table; and generates a target kernel function instance required to execute the task in the target context instance, and returns the target kernel function instance to the task processing module.
[0152] In a possible implementation, the method further includes: the resource management module simultaneously receives data requests from multiple threads; when multiple data requests are for requesting to read data in the hash table, multiple data requests are allowed to read the contents of the hash table simultaneously; when multiple data requests include a request to modify data in the hash table, only one thread is allowed to perform the data modification operation.
[0153] In a possible implementation, the method further includes:
[0154] The task processing module interacts with the outside based on the input and output interface. The task processing module is obtained by encapsulating open source components. The input and output of the input and output interface are memory instances.
[0155] In some embodiments, the functions or modules included in the method provided by the embodiments of the present disclosure can be used to implement the device described in the above method embodiments. The specific implementation can refer to the description of the above device embodiments, and for the sake of brevity, it will not be repeated here.
[0156] The embodiment of the present disclosure also provides a computer-readable storage medium, on which computer program instructions are stored, and when the computer program instructions are executed by a processor, the above-mentioned device is implemented. The computer-readable storage medium can be a volatile or non-volatile computer-readable storage medium.
[0157] The embodiment of the present disclosure also proposes an electronic device, comprising: a processor; a memory for storing instructions executable by the processor; wherein the processor is configured to call the instructions stored in the memory to implement the above-mentioned device.
[0158] The embodiments of the present disclosure also provide a computer program product, including a computer-readable code, or a non-volatile computer-readable storage medium carrying the computer-readable code. When the computer-readable code runs in a processor of an electronic device, the processor in the electronic device implements the functions of the above-mentioned device.
[0159] The electronic device may be provided as a terminal, a server, or a device in other forms.
[0160] Figure 7 1 is a block diagram of an electronic device 1900 according to an embodiment of the present disclosure. For example, the electronic device 1900 may be provided as a server or a terminal device. Figure 7 , the electronic device 1900 includes a processing component 1922, which further includes one or more processors, and a memory resource represented by a memory 1932 for storing instructions executable by the processing component 1922, such as an application. The application stored in the memory 1932 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 1922 is configured to execute instructions to perform the above method.
[0161] The electronic device 1900 may also include a power supply component 1926 configured to perform power management of the electronic device 1900, a wired or wireless network interface 1950 configured to connect the electronic device 1900 to a network, and an input / output (I / O) interface 1958. The electronic device 1900 may operate based on an operating system stored in the memory 1932, such as a Microsoft Server operating system (Windows Server 2003). TM ), a graphical user interface operating system launched by Apple (Mac OSX TM ), a multi-user, multi-process computer operating system (Unix TM ), a free and open source Unix-like operating system (Linux TM ), an open source Unix-like operating system (FreeBSD TM ) or similar.
[0162] In an exemplary embodiment, a non-volatile computer-readable storage medium is also provided, such as a memory 1932 including computer program instructions, which can be executed by the processing component 1922 of the electronic device 1900 to perform the above method.
[0163] The present disclosure may be a system, a method and / or a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for causing a processor to implement various aspects of the present disclosure.
[0164] Computer readable storage medium can be a tangible device that can hold and store instructions used by an instruction execution device. Computer readable storage medium can be, for example, (but not limited to) an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination thereof. More specific examples (non-exhaustive list) of computer readable storage medium include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, for example, a punch card or a convex structure in a groove on which instructions are stored, and any suitable combination thereof. The computer readable storage medium used here is not interpreted as a transient signal itself, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagated by a waveguide or other transmission medium (for example, a light pulse by an optical fiber cable), or an electrical signal transmitted by a wire.
[0165] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.
[0166] The computer program instructions for performing the operation of the present disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. Computer-readable program instructions may be executed completely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or completely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), may be customized by utilizing the state information of the computer-readable program instructions, and the electronic circuit may execute the computer-readable program instructions, thereby realizing various aspects of the present disclosure.
[0167] Various aspects of the present disclosure are described herein with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer-readable program instructions.
[0168] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0169] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0170] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to multiple embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of the module, program segment or instruction includes one or more executable instructions for realizing the specified logical function. In some alternative implementations, the function marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or action, or can be implemented with a combination of special hardware and computer instructions.
[0171] The computer program product may be implemented in hardware, software or a combination thereof. In one optional embodiment, the computer program product is embodied as a computer storage medium, and in another optional embodiment, the computer program product is embodied as a software product, such as a software development kit (SDK) and the like.
[0172] The above description of various embodiments tends to emphasize the differences between the various embodiments. The same or similar aspects can be referenced to each other, and for the sake of brevity, they will not be repeated herein.
[0173] Those skilled in the art will appreciate that, in the above method of specific implementation, the order in which the steps are written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of the steps should be determined by their functions and possible internal logic.
[0174] If the technical solution of this application involves personal information, the product using the technical solution of this application has clearly informed the personal information processing rules and obtained the individual's voluntary consent before processing the personal information. If the technical solution of this application involves sensitive personal information, the product using the technical solution of this application has obtained the individual's separate consent before processing the sensitive personal information, and at the same time meets the "explicit consent" requirement. For example, on personal information collection devices such as cameras, clear and prominent signs are set to inform that the personal information collection scope has been entered and personal information will be collected. If the individual voluntarily enters the collection scope, it is deemed that he or she agrees to the collection of his or her personal information; or on the device that processes personal information, the personal information processing rules are notified by obvious signs / information, and the individual's authorization is obtained through pop-up information or by asking the individual to upload his or her personal information; among them, the personal information processing rules may include information such as the personal information processor, the purpose of personal information processing, the processing method, and the type of personal information processed.
[0175] The embodiments of the present disclosure have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. A task processing device, characterized in that: include: A task processing module receives a memory instance transmitted by an external OpenCL library, and determines a context instance corresponding to the memory instance according to the memory instance, wherein the OpenCL library is any OpenCL library implemented based on the open computing language OpenCL; The resource management module returns the kernel function instance to the task processing module if a kernel function instance for processing the memory instance already exists in the context instance, the kernel function instance being created when the target task was previously executed, and the target task is the same as the task type corresponding to the memory instance; The task processing module processes the task corresponding to the memory instance based on the kernel function instance, obtains a processing result, and returns the processing result to the client through the memory instance.
2. The device according to claim 1, characterized in that: The task processing module sends a resource application request to the resource management module, wherein the resource application request includes the context instance; The resource management module, in response to the resource application request, searches for the context instance in the child nodes of the root node of the hash table, where the root node is implemented based on a singleton class.
3. The device according to claim 2, characterized in that: When the context instance is found, the resource management module searches for the program instance required to execute the task in the child nodes of the context instance; when the program instance is found, the resource management module searches for the kernel function instance required to execute the task in the child nodes of the program instance; when the kernel function instance is found, the kernel function instance is returned to the task processing module.
4. The device according to claim 2, characterized in that: The resource management module, when the context instance is not found, adds the context instance as a child node of the root node to the hash table; generates a kernel function instance required to execute the task in the context instance, and returns the kernel function instance to the task processing module.
5. The device according to claim 4, characterized in that: The resource management module creates a program instance based on the program source code of the kernel function required to execute the task, and compiles the program source code based on the program instance; and adds the created program instance to the child node of the context instance in the hash table; A kernel function instance for managing the compiled program source code is created, and the created kernel function instance is added to a child node of a corresponding program instance in a hash table.
6. The device according to claim 1, characterized in that The device also includes: A memory instance creation module, in response to a memory instance creation request from a client, sends a resource application request to the resource management module; The resource management module, in response to the resource application request sent by the memory instance creation module, creates a target context instance and returns it to the memory instance creation module; adds the target context instance as a child node of the root node to the hash table; The memory instance creation module creates a target memory instance in the target context instance and returns the target memory instance to the client. The target memory instance includes a first address for storing input data and a second address for storing output data.
7. The device according to claim 6, characterized in that: The task processing module receives the target memory instance transmitted by the client, and determines the target context instance corresponding to the target memory instance according to the target memory instance; Sending a resource application request to the resource management module, wherein the resource application request includes the target context instance; The resource management module, in response to the resource application request, searches for the target context instance in the child nodes of the root node of the hash table; If the target context instance is not found, adding the target context instance as a child node of the root node to the hash table; And generate a target kernel function instance required to execute the task in the target context instance, and return the target kernel function instance to the task processing module.
8. The device according to claim 2, characterized in that The resource management module receives data requests from multiple threads simultaneously; when the multiple data requests are for requesting to read data in the hash table, the multiple data requests are allowed to read the content in the hash table simultaneously; In the case that there is a plurality of data requests for modifying data in the hash table, only one thread is allowed to perform the data modification operation.
9. The device according to claim 1, characterized in that The device also includes: An input / output interface, wherein the input and output of the input / output interface are memory instances; The task processing module interacts with the outside based on the input and output interface, and the task processing module is obtained by encapsulating the open source component.
10. A task processing method, characterized in that: Applied to a task processing device, the device includes a task processing module and a resource management module, and the method includes: The task processing module receives a memory instance passed in by an external OpenCL library, and determines a context instance corresponding to the memory instance according to the memory instance, wherein the OpenCL library is any OpenCL library implemented based on the open computing language OpenCL; The resource management module returns the kernel function instance to the task processing module if a kernel function instance for processing the memory instance already exists in the context instance, wherein the kernel function instance is created when the target task is previously executed, and the target task is the same as the task type corresponding to the memory instance; The task processing module processes the task corresponding to the memory instance based on the kernel function instance, obtains a processing result, and returns the processing result to the client through the memory instance.
11. An electronic device, characterized in that: include: processor; a memory for storing processor-executable instructions; The processor is configured to call the instructions stored in the memory to implement the device described in any one of claims 1 to 9.
12. A computer-readable storage medium having computer program instructions stored thereon, characterized in that: When the computer program instructions are executed by a processor, the apparatus according to any one of claims 1 to 9 is implemented.
Citation Information
Patent Citations
Method, apparatus, and computer program product for allocating processing resources to applications
CN109697121A
Data locality enhancement for graphics processing units
CN112819678A
Implementation method and device of OpenCL DNN library, electronic equipment and storage medium
CN115268858A
OpenCL TensorFlow implementation method and device, electronic equipment and storage medium
CN115268859A
Host machine, virtualization instance introspection method and storage medium
CN116991543A