A task processing method and device, a storage medium and an electronic device

By managing kernel function instances and context instances within the OpenCL application framework and utilizing hash tables to achieve resource reuse, the communication overhead and repetitive compilation issues of cross-device computing tasks in the OpenCL application framework are resolved, thereby improving task processing efficiency and system performance.

CN119576565BActive Publication Date: 2026-06-23MOORE THREADS TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
MOORE THREADS TECH CO LTD
Filing Date
2024-11-29
Publication Date
2026-06-23

AI Technical Summary

Technical Problem

In the OpenCL application framework, cross-device computing tasks suffer from high communication overhead, leading to reduced computing performance. Furthermore, different OpenCL libraries cannot effectively reuse cl_context and cl_kernel instances, resulting in unnecessary data transfers and repeated compilations.

Method used

The task processing module receives memory instances from the external OpenCL library, determines the corresponding context instance, and performs task processing within existing kernel function instances. It utilizes a hash table to manage resources, thereby enabling the reuse of kernel function instances and improving compilation efficiency.

Benefits of technology

It reduces unnecessary data transfer operations, improves task processing efficiency, avoids repeated compilation, and enhances system performance and resource utilization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119576565B_ABST
    Figure CN119576565B_ABST
Patent Text Reader

Abstract

The present disclosure relates to a task processing method and device, a storage medium and an electronic device. The device comprises: a task processing module, receiving a memory instance transmitted by an external OpenCL library, determining a context instance corresponding to the memory instance according to the memory instance; a resource management module, in the case where a kernel function instance for processing the memory instance already exists in the context instance, returning the kernel function instance to the task processing module, the kernel function instance being created when a target task is executed previously, the target task being of the same type as a task type corresponding to the memory instance; the task processing module, processing a task corresponding to the memory instance based on the kernel function instance, obtaining a processing result, and returning the processing result to a client through the memory instance. The embodiments of the present disclosure can improve the task processing efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of computer technology, and in particular to a task processing method and apparatus, storage medium and electronic device. Background Technology

[0002] With the rapid development of computer technology, cross-platform parallel programming has become a key means to improve computing performance. OpenCL TM OpenCL (Open Computing Language) is an open, royalty-free standard 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 standard and run on processor devices that implement the OpenCL standard, thus fully utilizing hardware acceleration capabilities.

[0003] In the OpenCL architecture, OpenCL kernels are functions that can run on OpenCL-supported devices and are managed by the `cl_kernel` function within the OpenCL Runtime. These kernels can be stored within the same OpenCL Program (program instance management module) and managed as a whole using `cl_program`. OpenCL Programs are typically distributed with the application as source code and are compiled into device-specific executable binaries at runtime using the OpenCL Runtime. This compilation mechanism ensures the program can run flexibly on different processor devices, but it results in lower processing efficiency.

[0004] Furthermore, in some OpenCL application frameworks (such as TensorFlow), the context instance (cl_context) cannot be shared. This leads to the need for complex cross-device relay operations when performing computation tasks between multiple plugins, and this communication overhead greatly reduces the performance of the entire computation task. Summary of the Invention

[0005] This disclosure proposes a task processing technology solution.

[0006] According to one aspect of this disclosure, a task processing apparatus is provided, comprising:

[0007] The task processing module receives a memory instance from an external OpenCL library, determines the context instance corresponding to the memory instance based on the memory instance, and the OpenCL library is any OpenCL library implemented based on the open computing language OpenCL;

[0008] 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. The kernel function instance was created when the target task was executed previously, and the target task has the same task type as the memory instance.

[0009] 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.

[0010] In one possible implementation, the task processing module sends a resource request to the resource management module, the resource request including the context instance;

[0011] In response to the resource request, the resource management module 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, upon finding the context instance, searches for a program instance required to execute the task in the child nodes of the context instance; if the program instance is found, it searches for a kernel function instance required to execute the task in the child nodes of the program instance; and if the kernel function instance is found, it 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 one possible implementation, the device further includes:

[0016] The memory instance creation module, in response to the client's memory instance creation request, sends a resource request to the resource management module;

[0017] In response to a resource request sent by the memory instance creation module, the resource management module creates a target context instance and returns it to the memory instance creation module; and 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 one possible implementation, the task processing module receives the target memory instance from the client, determines the target context instance corresponding to the target memory instance based on the target memory instance, and sends a resource request to the resource management module, wherein the resource request includes the target context instance.

[0020] In response to a resource request, the resource management module 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, it 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 receives data requests from multiple threads simultaneously; if the multiple data requests are for reading data from the hash table, multiple data requests are allowed to read the contents of the hash table simultaneously; if among the multiple data requests there is a request to modify data in the hash table, then only one thread is allowed to perform the data modification operation.

[0022] In one possible implementation, the device further includes:

[0023] 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 world based on the input / output interface, and the task processing module is obtained by encapsulating open source components.

[0025] According to one aspect of this disclosure, a task processing method is provided, applied to a task processing apparatus, the apparatus including a task processing module and a resource management module, the method comprising:

[0026] The task processing module receives a memory instance from an external OpenCL library, and determines the context instance corresponding to the memory instance based on the memory instance. The OpenCL library is any OpenCL library implemented based on the open computing language OpenCL.

[0027] If the resource management module already has a kernel function instance in the context instance for processing the memory instance, it returns the kernel function instance to the task processing module. The kernel function instance was created when the target task was executed previously, and the target task is of the same type as the task 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 the processing result, and returns the processing result to the client through the memory instance.

[0029] According to one aspect of this disclosure, an electronic device is provided, comprising: a processor; a memory for storing processor-executable instructions; wherein the processor is configured to invoke the instructions stored in the memory to implement the above-described apparatus.

[0030] According to one aspect of this disclosure, a computer-readable storage medium is provided that stores computer program instructions thereon, which, when executed by a processor, implement the above-described apparatus.

[0031] In this embodiment, the task processing module receives a memory instance from an external OpenCL library and determines a context instance corresponding to the memory instance. 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. This kernel function instance was created during the execution of a target task, and the target task has the same type as the task 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. Therefore, by directly obtaining the context instance of the memory instance from the external OpenCL library and running the kernel function instance within that context instance for task processing, data transfer through memory is eliminated, reducing unnecessary data transfer overhead and improving task processing efficiency. Furthermore, by utilizing a kernel function instance created during the execution of a task of the same type, repeated compilation of the source code is avoided, further improving task processing efficiency.

[0032] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Other features and aspects of this disclosure will become clear from the following detailed description of exemplary embodiments with reference to the accompanying drawings. Attached Figure Description

[0033] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this disclosure and, together with the specification, serve to illustrate the technical solutions of this disclosure.

[0034] Figure 1 A block diagram of a task processing apparatus according to an embodiment of the present disclosure is shown.

[0035] Figure 2 A schematic diagram of the structure of a task processing apparatus according to an embodiment of the present disclosure is shown.

[0036] Figure 3 The diagram illustrates the interaction between the modules when generating kernel function instances according to an embodiment of this disclosure.

[0037] Figure 4 This diagram illustrates the interaction between modules when a generated kernel function instance is invoked according to an embodiment of this disclosure.

[0038] Figure 5 This diagram illustrates the interaction between the modules during the creation of a memory instance according to an embodiment of the present disclosure.

[0039] Figure 6 A flowchart illustrating 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 Implementation

[0041] Various exemplary embodiments, features, and aspects of this disclosure will now be described in detail with reference to the accompanying drawings. The same reference numerals in the drawings denote elements that have the same or similar functions. Although various aspects of the embodiments are shown in the drawings, they are not necessarily drawn to scale unless specifically indicated otherwise.

[0042] The term “exemplary” as used herein means “serving as an example, embodiment, or illustration.” Any embodiment illustrated herein as “exemplary” is not necessarily to be construed as superior to or better than other embodiments.

[0043] In this document, the term "and / or" is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent three cases: A alone, A and B simultaneously, and B alone. Furthermore, the term "at least one" in this document means any combination of at least two of any one or more elements. For example, including at least one of A, B, and C can mean including any one or more elements selected from the set consisting of A, B, and C.

[0044] Furthermore, to better illustrate this disclosure, numerous specific details are set forth in the following detailed description. Those skilled in the art will understand that this disclosure can be practiced without certain specific details. In some instances, methods, means, components, and circuits well known to those skilled in the art have not been described in detail in order to highlight the main points of this disclosure.

[0045] Figure 1 A block diagram of a task processing apparatus according to an embodiment of the present disclosure is shown, such as Figure 1 As shown, the device 10 includes:

[0046] The task processing module 11 receives a memory instance from an external OpenCL library, and determines the context instance corresponding to the memory instance based on the memory instance. The OpenCL library is any OpenCL library implemented based on the open computing language OpenCL.

[0047] If a kernel function instance for processing the memory instance already exists in the context instance, the resource management module 12 returns the kernel function instance to the task processing module. The kernel function instance was created when the target task was executed previously, and the target task has the same task type as the memory instance.

[0048] The task processing module 11 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.

[0049] A kernel instance (cl_kernel) is an object instance representing a kernel function. This object instance can contain references or identifiers to the kernel function that executes on the OpenCL device, used to manage kernel execution. When a kernel instance is created using the OpenCL API (e.g., via the clCreateKernel function), a variable of type cl_kernel is obtained. This variable represents the kernel executing on the OpenCL device. This variable can be used to set kernel parameters and to add the kernel to the command queue for execution.

[0050] The compiled kernel resides within a program, which is a container that contains multiple compiled kernel functions and other related data. Programs are managed by program instances (cl_program), which contain references or identifiers to specific programs, used to reference or manage a particular program within the OpenCL runtime environment.

[0051] A memory instance (cl_mem) is used to manage storage space on a device (such as a GPU). A memory instance contains 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. This instance object can contain references or identifiers used to indicate the context. The context is an abstract container where all computations and computation-related data transfers occur within the same context. cl_context is used to reference and manipulate the context in the program. When an OpenCL context is created, an instance object of type cl_context is also obtained; this is the context instance, which can be used to perform various context-related operations.

[0053] In related technologies, during task processing, different OpenCL libraries within the OpenCL application framework often cannot effectively reuse cl_context and cl_kernel instances, leading to unnecessary data transfers and repeated compilations, which in turn affects the efficiency of task processing.

[0054] External OpenCL libraries can be libraries or frameworks that encapsulate OpenCL functionality. From a data flow perspective, the inputs and outputs of different OpenCL libraries are interdependent and linked together to complete a computational task. In this embodiment, the kernel function instance of the currently executing task is created based on the context instance corresponding to the input memory instance, thus integrating multiple OpenCL libraries into the same context for task execution.

[0055] For externally received memory instances, the context instance can be obtained by calling the OpenCL API. For example, for a memory instance, the context instance corresponding to that memory instance can be obtained by calling the `clGetMemObjectInfo` function. Furthermore, the `clGetContextInfo` function can be called for a memory instance to obtain information such as the number of devices and device indices corresponding to that context. For each device index, the `clGetDeviceInfo` function can be called to obtain detailed device information. Based on this information, the storage space and OpenCL kernel used subsequently are initialized to ensure that the parameters passed when calling kernel function instances to execute tasks match the context and devices corresponding to the memory instance.

[0056] In addition, if a single call receives multiple memory instances, it can be determined whether the contexts of each memory instance are consistent. If they are inconsistent, an error is returned to avoid passing incorrect parameters to the device and causing the entire program to crash.

[0057] When executing a task, the resource management module creates a kernel function instance in the context instance. This kernel function instance controls the execution of the kernel function. The specific process of creating a kernel function instance can be found in the possible implementations provided in this disclosure, and will not be elaborated here. During task execution, the same kernel function is used for tasks of the same type. "Same task type" here can refer to the same processing flow during task execution. For example, a kernel function instance used for image normalization executes the same processing flow when normalizing different images. This kernel function instance can be executed multiple times to normalize different images. The input address in the memory instance stores the image to be normalized. By receiving different memory instances, different images can be normalized.

[0058] Once the memory instance is obtained, it can be checked within the context to see if a kernel function instance already exists that can handle the newly passed memory instance, allowing for its reuse. If a kernel function instance already exists in the context instance, it indicates that a kernel function instance capable of handling the memory instance was created when the target task of the same type as the memory instance was previously executed, and the kernel function instance can then be returned to the task processing module.

[0059] After obtaining a kernel function instance, the task processing module executes the kernel function within the acquired context, which provides the necessary environment and resources for its execution. The kernel function processes the data stored at the address of the memory instance; this data is often located in the device's internal storage media, such as the GPU's video memory.

[0060] After the kernel function completes the 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 this embodiment, by directly obtaining the context instance of the memory instance passed from 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 memory, which reduces the data overhead caused by unnecessary data transfer operations and improves task processing efficiency. In addition, by using the kernel function instance created when executing the same type of task before for task processing, there is no need to repeatedly compile the source code, which improves task processing efficiency.

[0062] In one possible implementation, the task processing module sends a resource request to the resource management module, the resource request containing the context instance; the resource management module, in response to the resource request, searches for the context instance in the child nodes of the root node of the hash table, the root node being implemented based on a singleton class.

[0063] The task processing module is responsible for handling various tasks. During task processing, it requires processing resources. To obtain these resources, the task processing module sends a resource request to the resource management module. This resource request includes information about the context instance.

[0064] The resource management module is primarily 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 first checks if the context instance already exists. If it does, it checks if the current context instance contains a kernel function instance corresponding to the requested memory instance. If it exists, it returns it to the task processing module; otherwise, it creates a new kernel function instance based on the request and stores it in the corresponding context instance for later reuse.

[0065] In addition, the resource management module can monitor and manage the lifecycle of context instances. When a context instance is no longer needed, the resource management module will release the resources it occupies to ensure the stable operation of the system.

[0066] To quickly and efficiently locate the corresponding resources, the resource management module uses a hash table to manage resources uniformly. After receiving a resource request from the task processing module, the resource management module will look up the corresponding resource in the hash table.

[0067] The root node of the hash table is implemented based on a singleton class, meaning that there is only one instance of the root node in the entire device, to ensure the uniqueness and stability of the hash table and avoid resource conflicts and chaos.

[0068] The child nodes of the root node store different context instances. Since the context instance contains a reference or identifier used to indicate the context, such as a pointer used to indicate the context in the system, the child nodes of the root node can store pointers to the context instances.

[0069] The resource management module searches through the child nodes of the root node one by one, based on the pointer to 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 necessary resources to the task processing module based on this information.

[0070] In this embodiment, the task processing module sends a resource request to the resource management module, the resource request including the context instance; the resource management module, in response to the resource 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. Thus, by having the task processing module send a resource request and the resource management module use a hash table implemented based on a singleton class to search for the context instance, rapid resource location and allocation are achieved, improving resource utilization and the overall performance of the device.

[0071] By managing resources through a hash table built around a singleton class as the root node, unified resource management is achieved. This facilitates the tracking and management of all created OpenCL resources, ensuring their consistency and correctness throughout the application. Furthermore, unified resource management avoids unnecessary resource initialization. When a resource is needed, the framework first checks if it already exists; if so, it reuses it directly, reducing initialization overhead. By reducing the number of resource initializations and avoiding the duplication of identical resources, system performance can be significantly improved.

[0072] Furthermore, using a hash table built with a singleton class as the root node to manage resources simplifies the programming model, making it easier for developers to understand and manipulate OpenCL resources. The task processing modules developed by developers only need to access and manipulate the entire resource tree through the singleton class, without having to worry about the specific implementation details, which can easily achieve application encapsulation.

[0073] In one possible implementation, the resource management module, upon finding the context instance, searches for a program instance required to execute the task in the child nodes of the context instance; if the program instance is found, it searches for a kernel function instance required to execute the task in the child nodes of the program instance; and if the kernel function instance is found, it 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, which is based on a singleton class, contain the managed context instance, and the nodes of the context instance contain the program instances created in that context; similarly, the child nodes of the program instance node contain the kernel function instances of the kernel functions that have been compiled in the program.

[0075] The resource management module searches the hash table for an item that matches 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 an instance. For a node representing a context instance, it stores a pointer or reference to that context instance; therefore, the context instance is searched by traversing these pointers or references.

[0076] If 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 that node. The program instance node also stores pointers or references to programs. By traversing the pointers or references in these child nodes, the program instance related to the task can be found.

[0077] After locating a program instance, the resource management module continues to search for kernel function instances required to execute the task within the program instance's child nodes. Kernel function instance nodes store pointers or references to kernel function instances; by traversing these pointers or references in the child nodes, the kernel function used to execute the task is located.

[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 obtaining the kernel function instance, the task processing module can call the instance to run the kernel function and execute the corresponding task.

[0079] In this embodiment of the disclosure, the resource management module can efficiently manage and search for various resource instances through this tree-structured hash table design. The instance pointers or references stored in each node make resource management more direct and faster, improve the accuracy and reliability of resource access, and achieve 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 does not find the requested context instance in the hash table, since context instances can be shared, this new context instance can be added to the hash table as a child node of the root node. This ensures that when a processing task requiring the same context is received in the future, the context instance can be found quickly, avoiding the 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 within the newly added context instance. This kernel function instance is created based on 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 the kernel function instance can be found in the possible implementations provided in this disclosure, and will not be elaborated here.

[0083] After generating a kernel function instance, the resource management module returns it to the task processing module. Once the task processing module obtains the kernel function instance, it can use it to execute the corresponding task.

[0084] In this embodiment of the disclosure, if the context instance is not found, the resource management module 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, and when a processing task requiring the same context is received in the future, the context instance can be found quickly, avoiding the repeated creation and addition of context, and 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] If the context instance is not found, after adding the context instance to the hash table, the task processing module will request the creation of a kernel function instance, that is, initialize the kernel function.

[0087] The task processing module can 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 the kernel function instance based on the program source code corresponding to the kernel function instance.

[0088] The resource management module creates program instances based on the provided source code. A program instance is an abstract representation of the source code, containing its metadata and the necessary execution environment. By creating program instances, the resource management module can better manage and control the compilation and execution process of the source code.

[0089] After creating a program instance, the resource management module compiles the program source code, converting it into machine language code (e.g., binary code), enabling the program to execute on the target device. The resource management module uses an appropriate compiler and compilation parameters to compile the program source code, generating executable machine code.

[0090] After compilation, the resource management module adds the created program instance to the corresponding position in the hash table. Specifically, the resource management module adds the program instance to the child nodes of the context instance, associating 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 creates kernel function instances to manage the compiled program source code. A kernel function instance is an object instance that represents a kernel function and can uniquely identify a specific kernel function (program) within a program instance.

[0092] The resource management module adds the created kernel function instance to the child nodes 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 needing to recompile and create the program source code.

[0093] In this embodiment of the disclosure, the apparatus further includes: a memory instance creation module, which, in response to a memory instance creation request from a client, sends a resource request to the resource management module; the resource management module, in response to the resource 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 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 apparatus provided in this disclosure can also create context instances and memory instances. For example, when multiple devices work together to complete a computational task, the task processing apparatus may be the first device in the pipeline, and therefore, no other devices will pass in a memory instance. In this case, when a task processing request is received, both the memory instance and the context instance are created.

[0095] Upon receiving a memory instance creation request, the memory instance creation module sends a resource request to the resource management module. Upon receiving the resource request, the resource management module first creates a target context instance. The target context instance is a collection of resources and environment elements required to perform a specific task or operation; it contains the necessary information for task execution.

[0096] After creating the target context instance, the resource management module returns it to the memory instance creation module. Simultaneously, to achieve efficient management and fast lookup of the context instance, the resource management module adds the target context instance as a child node of the root node to the hash table, enabling convenient subsequent management and lookup of the context instance.

[0097] After obtaining the target context instance, the memory instance creation module further creates a target memory instance within that context instance to facilitate client input and output data reception. 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 its address to perform data storage and retrieval operations.

[0099] For example, when performing normalization on an image, the client loads the image file into the CPU's main memory. Then, the task processing unit allocates a GPU memory and creates a memory instance. It then sends this memory instance to the client so that the client can copy the image data from the CPU's main memory to the created GPU memory.

[0100] In this embodiment, the memory instance creation module, in response to a client's memory instance creation request, sends a resource request to the resource management module. The resource management module, in response to the resource request, creates a target context instance and returns it to the memory instance creation module. The target context instance is added as a child node of the root node to the hash table. The memory instance creation module creates a target memory instance within 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. 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 from the client, determines the target context instance corresponding to the target memory instance, sends a resource request to the resource management module, the resource request containing the target context instance, and, in response to the resource 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, it is added to the hash table as a child node of the root node. The module also 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, it is also necessary to create the kernel function instance used to execute the task. The specific process is as follows.

[0103] The task processing module receives the target memory instance from the client, which is created based on 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 request to the resource management module. This request contains information about the target context instance, enabling the resource management module to perform the corresponding resource search and allocation based on this information.

[0104] In response to a resource request, the resource management module searches for the target context instance in the child nodes of the root node of the hash table. Once the target context instance is found, the resource management module generates the target kernel function instance required to perform the specific task within that context instance. The creation process of the target kernel function instance is similar to the kernel function instance creation process described earlier: first, a program instance is created; then, the kernel function source code is compiled; and finally, the kernel function instance is created. For details, please refer to the description of kernel function instance generation provided in this disclosure; it will not be repeated here.

[0105] The resource management module returns the generated target kernel function instance to the task processing module. Once the task processing module receives the kernel function instance, it can execute the corresponding task.

[0106] In this embodiment of the disclosure, after creating a target memory instance and returning it 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 applicable to task processing between OpenGL libraries, but also adaptable to the client's need to directly request task processing, and has high adaptability.

[0107] In one possible implementation, the resource management module receives data requests from multiple threads simultaneously; if the multiple data requests are for reading data from the hash table, multiple data requests are allowed to read the contents of the hash table simultaneously; if among the multiple data requests there is a request to modify data in the hash table, then 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. These requests include requests to read data from the hash table or requests to modify data in the hash table.

[0109] When multiple data requests are all reads from the hash table, the resource management module allows multiple threads to read the hash table concurrently. Since read operations do not modify the hash table's state, multiple threads can read simultaneously without interfering with each other. This concurrent reading mechanism improves task processing efficiency and response speed.

[0110] However, when multiple data requests include requests to modify data in the hash table (i.e., at least one modification request exists (other modification requests or read requests may also exist among the multiple data requests), the modification operation changes the state of the hash table. If multiple threads perform modifications simultaneously, it may lead to data inconsistency or conflicts. Therefore, the resource management module only allows one thread to perform data modification operations.

[0111] For example, to implement thread-safe hash table operations, a template class can be implemented with a semaphore added to its class members to control access to the hash table. When a thread wants to modify the hash table, it attempts to acquire an exclusive lock. If no other thread holds the exclusive lock at that time, the thread can successfully acquire the lock and perform the modification operation. During the modification, other threads cannot acquire the exclusive lock and therefore cannot perform modification operations. If another thread already holds the exclusive lock, the current thread will be blocked until the exclusive lock is released. When multiple threads want to read the hash table simultaneously, they can acquire a shared lock. Multiple threads can hold the shared lock simultaneously, so they can read the contents of the hash table concurrently. However, if a thread holds the exclusive lock at that time, other threads cannot acquire the shared lock and cannot read the hash table.

[0112] This method achieves thread-safe access to the hash table. It allows multiple threads to read the hash table simultaneously, but ensures that only one thread can execute modification operations. This avoids data collisions and inconsistencies, guaranteeing the stability and correctness of the device.

[0113] In this embodiment of the disclosure, the resource management module can process data requests from multiple threads simultaneously and achieves thread-safe access to the hash table, thereby improving the efficiency and response speed of data processing while ensuring data consistency and correctness.

[0114] In one possible implementation, the device further includes: an input / output interface, wherein the input and output of the input / output interface are memory instances; and a task processing module, which interacts with the outside world based on the input / output interface, wherein the task processing module is obtained by encapsulating open-source components.

[0115] The device provided in this embodiment includes an input / output interface, the main function of which is to facilitate interaction between the device and external systems. Both the input and output of the input / output interface are memory instances to enable efficient data transmission and exchange with external systems or components.

[0116] The task processing module interacts with the outside world based on input / output interfaces. In this embodiment, the task processing module is obtained by encapsulating open-source components. That is, the device can implement its functionality by encapsulating and integrating open-source components and embedding their functions into the task processing module. This encapsulation method allows the device to more easily utilize the functionality of open-source components, while also enabling customization and optimization of the functionality as needed.

[0117] Taking the function of generating pseudo-random numbers using OpenCL in a TensorFlow plugin as an example, the device provided in this disclosure can be encapsulated using the open-source component clRNG. clRNG is an open-source component for generating random numbers that can leverage OpenCL's parallel computing capabilities to generate high-quality pseudo-random number sequences. By encapsulating clRNG into a task processing module and exposing a function interface for generating random numbers, which takes a memory instance as input and output, external systems or components can interact with the device provided in this disclosure through a memory instance.

[0118] When an external system or component sends a request through the input / output interface, the task processing module can call the encapsulated clRNG function to generate the corresponding pseudo-random number sequence and return it to the outside through the input / output interface.

[0119] This approach not only simplifies the adaptation process for TensorFlow plugins but also improves processing performance. By encapsulating and integrating open-source components, it reduces dependence on external systems or components, thereby enhancing its flexibility and scalability.

[0120] In this embodiment, the device further includes: an input / output interface, wherein the input and output of the input / output interface are memory instances; and a task processing module, which interacts with the outside world based on the input / output interface, and is obtained by encapsulating open-source components. Therefore, by interacting with the outside world through the input / output interface and encapsulating the task processing module using open-source components, the functionality of the open-source components can be directly utilized, enabling the reuse of kernel function instances and context instances. This facilitates access to various open-source OpenCL function libraries and reduces the time required for adaptation and development.

[0121] The following describes an application scenario of an embodiment of this disclosure. Figure 2 The diagram illustrates the structure of a task processing apparatus according to an embodiment of the present disclosure. In this application scenario, the task processing module is specifically implemented as a normalization module, which performs normalization processing on the image. The resource management module includes a resource allocation module, a context instance management module, a program instance management module, a kernel function instance management module, and a memory instance creation module. The specific functions implemented by each module are as follows.

[0122] Figure 3 This diagram illustrates the interaction between the modules during the generation of kernel function instances according to embodiments of the present disclosure, such as... Figure 3As shown, an external system / component passes in a memory instance, which contains the storage address `src` used to store input data. The normalization module receives this memory instance, obtains its context instance, and then sends a resource request to the resource request module. Since the resource request module cannot find the context instance in the hash table, it instructs the context instance management module to initialize the context instance and add it to the child node of the hash table root node. The normalization module then requests a kernel function instance from the context instance management module. The context instance management module instructs the program instance management module to create a program instance within this context instance and uses this program instance to compile the program source code, resulting in a compiled program containing kernel functions. The program instance management module then instructs the kernel function instance management module to create a kernel function instance, which points to the compiled kernel function.

[0123] The normalization module runs the kernel function through this 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 This diagram illustrates the interaction between modules when a generated kernel function instance is invoked according to an embodiment of this disclosure, such as... Figure 4 As shown, an external system / component passes in a memory instance, which contains the storage address src used to store input data. The normalization module receives the memory instance and obtains its context instance. Then, it sends a resource request to the resource request module. The resource request module finds the context instance in the hash table. The context instance management module searches for the program instance in the child nodes of the context instance. If 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. Finally, it finds the kernel function instance that was created when the normalization task was performed.

[0125] The normalization module runs the kernel function through this 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 This diagram illustrates the interaction between modules during the creation of a memory instance according to an embodiment of the present disclosure, such as... Figure 5As shown, the client sends a memory instance creation request to the memory instance creation module. Upon receiving the memory instance creation request, the memory instance creation module sends a resource request to the resource request module. After receiving the resource request, the resource request module instructs the context instance management module to create a context instance. After the target context instance is created, 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 that 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 an output address dst in that 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, obtains its context instance, and then sends a resource request to the resource request module. Since the resource request module cannot find the context instance in the hash table, it instructs the context instance management module to initialize the context instance and add it to the child node of the hash table root node. The normalization module then requests a kernel function instance from the context instance management module. The context instance management module instructs the program instance management module to create a program instance within the context instance and uses this program instance to compile the program source code, resulting in a compiled program containing kernel functions. Finally, 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 this 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 one possible implementation, the task processing device can be based on electronic devices such as terminal devices or servers. The terminal device can be user equipment (UE), mobile device, user terminal, terminal, cellular phone, cordless phone, personal digital assistant (PDA), handheld device, computing device, in-vehicle device, wearable device, etc. The device can be implemented by a processor calling computer-readable instructions stored in memory. Alternatively, the device can be implemented via a server.

[0131] In addition, this 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 of the task processing devices provided in this disclosure. The corresponding technical solutions and descriptions can be found in the relevant descriptions in the method section, and will not be repeated here.

[0132] Figure 6 A flowchart illustrating a task processing method according to an embodiment of the present disclosure is shown. The task processing method is applied to a task processing apparatus, which includes a task processing module and a resource management module, such as... Figure 6 As shown, the method includes:

[0133] In step S21, the task processing module receives a memory instance from an external OpenCL library, and determines the context instance corresponding to the memory instance based on the memory instance. The OpenCL library is any OpenCL library implemented based on the open computing language OpenCL.

[0134] In step S22, if the resource management module already has a kernel function instance in the context instance for processing the memory instance, it returns the kernel function instance to the task processing module. The kernel function instance was created when the target task was executed previously, and the target task is of the same type as the task 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 the processing result, and returns the processing result to the client through the memory instance.

[0136] In one possible implementation, the method further includes:

[0137] The task processing module sends a resource request to the resource management module, and the resource request includes the context instance;

[0138] In response to the resource request, the resource management module 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 one possible implementation, 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, including:

[0140] If 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; if the program instance is found, it searches for the kernel function instance required to execute the task in the child nodes of the program instance; if the kernel function instance is found, it returns the kernel function instance to the task processing module.

[0141] In one possible implementation, the method further includes:

[0142] If the resource management module does not find the context instance, it 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.

[0143] 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, including:

[0144] The resource management module creates a program instance based on the source code of the kernel function required to execute the task, and compiles the 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 source code, and adds the created kernel function instance to the child node of the corresponding program instance in the hash table.

[0145] In one possible implementation, the method further includes:

[0146] The memory instance creation module, in response to the client's memory instance creation request, sends a resource request to the resource management module;

[0147] In response to a resource request sent by the memory instance creation module, the resource management module creates a target context instance and returns it to the memory instance creation module; and 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 one possible implementation, the method further includes:

[0150] The task processing module receives the target memory instance from the client, determines the target context instance corresponding to the target memory instance based on the target memory instance, and sends a resource request to the resource management module, wherein the resource request includes the target context instance.

[0151] In response to a resource request, the resource management module 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, it 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 one possible implementation, the method further includes: the resource management module simultaneously receiving data requests from multiple threads; when multiple data requests are for requesting to read data from the hash table, allowing multiple data requests to read the contents of the hash table simultaneously; and when multiple data requests include requests to modify data in the hash table, allowing only one thread to perform the data modification operation.

[0153] In one possible implementation, the method further includes:

[0154] The task processing module interacts with the outside world based on the input / output interface. The task processing module is obtained by encapsulating open-source components, and the input and output of the input / output interface are memory instances.

[0155] In some embodiments, the functions or modules of the methods provided in this disclosure can be used to implement the apparatus described in the above method embodiments. The specific implementation can be referred to the description of the above apparatus embodiments, which will not be repeated here for the sake of brevity.

[0156] This disclosure also proposes a computer-readable storage medium storing computer program instructions thereon, which, when executed by a processor, implement the aforementioned apparatus. The computer-readable storage medium may be volatile or non-volatile.

[0157] This disclosure also proposes an electronic device, including: a processor; and a memory for storing processor-executable instructions; wherein the processor is configured to invoke the instructions stored in the memory to implement the above-described apparatus.

[0158] This disclosure also provides a computer program product, including computer-readable code, or a non-volatile computer-readable storage medium carrying computer-readable code, wherein when the computer-readable code is executed in a processor of an electronic device, the processor in the electronic device performs the functions of the above-described device.

[0159] Electronic devices can be provided as terminals, servers, or other forms of devices.

[0160] Figure 7 A block diagram of an electronic device 1900 according to an embodiment of the present disclosure is shown. For example, the electronic device 1900 may be provided as a server or a terminal device. (Refer to...) Figure 7 The electronic device 1900 includes a processing component 1922, which further includes one or more processors, and memory resources represented by memory 1932 for storing instructions, such as application programs, that can be executed by the processing component 1922. The application programs stored in memory 1932 may include one or more modules, each corresponding to a set of instructions. Furthermore, the processing component 1922 is configured to execute instructions to perform the methods described above.

[0161] Electronic device 1900 may also include a power supply component 1926 configured to perform power management of electronic device 1900, a wired or wireless network interface 1950 configured to connect electronic device 1900 to a network, and an input / output (I / O) interface 1958. Electronic device 1900 can operate on an operating system stored in memory 1932, such as Microsoft Server operating system (Windows Server). TM Apple's graphical user interface-based operating system (Mac OSX) TM ), a multi-user, multi-process computer operating system (Unix) TM Linux is a free and open-source Unix-like operating system. TM ), the 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 that can be executed by a processing component 1922 of an electronic device 1900 to perform the above-described method.

[0163] This disclosure can be a system, method, and / or computer program product. A computer program product may include a computer-readable storage medium having computer-readable program instructions loaded thereon for causing a processor to implement various aspects of this disclosure.

[0164] Computer-readable storage media can be tangible devices capable of holding and storing instructions for use by an instruction execution device. Computer-readable storage media can be, for example, (but not limited to) electrical storage devices, magnetic storage devices, optical storage devices, electromagnetic storage devices, semiconductor storage devices, or any suitable combination of the foregoing. More specific examples (a non-exhaustive list) of computer-readable storage media include: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), static random access memory (SRAM), portable compact disc read-only memory (CD-ROM), digital multifunction disc (DVD), memory sticks, floppy disks, mechanical encoding devices, such as punch cards or recessed protrusions storing instructions thereon, and any suitable combination of the foregoing. The computer-readable storage media used herein are not to be construed as transient signals themselves, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through waveguides or other transmission media (e.g., light pulses through fiber optic cables), or electrical signals transmitted through wires.

[0165] The computer-readable program instructions described herein can be downloaded from computer-readable storage media to various computing / processing devices, or downloaded via a network, such as the Internet, local area network, wide area network, and / or wireless network, to an external computer or external storage device. The network may include copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers, and / or edge servers. A network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards them to the computer-readable storage media in the respective computing / processing device.

[0166] Computer program instructions used to perform the operations of this disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, status 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 the "C" language or similar programming languages. The computer-readable program instructions may execute entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving 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., via the Internet using an Internet service provider). In some embodiments, electronic circuitry, such as programmable logic circuitry, field-programmable gate arrays (FPGAs), or programmable logic arrays (PLAs), is personalized by utilizing the status information of the computer-readable program instructions to implement various aspects of this disclosure.

[0167] Various aspects of this disclosure are described herein with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this disclosure. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, 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 apparatus to produce a machine such that, when executed by the processor of the computer or other programmable data processing apparatus, they create means for implementing the functions / actions specified in one or more blocks of the flowchart and / or block diagram. These computer-readable program instructions can also be stored in a computer-readable storage medium that causes a computer, programmable data processing apparatus, and / or other device to operate in a particular manner; thus, the computer-readable medium storing the instructions comprises an article of manufacture that includes instructions for implementing aspects of the functions / actions specified in one or more blocks of 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 to cause a series of operational steps to be 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 perform the functions / actions specified in one or more boxes of a flowchart and / or block diagram.

[0170] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of an instruction containing one or more executable instructions for implementing a specified logical function. In some alternative implementations, the functions marked in the blocks may occur in a different order than those shown in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

[0171] The computer program product can be implemented specifically through hardware, software, or a combination thereof. In one alternative embodiment, the computer program product is specifically embodied in a computer storage medium; in another alternative embodiment, the computer program product is specifically embodied in a software product, such as a software development kit (SDK), etc.

[0172] The description of the various embodiments above tends to emphasize the differences between the various embodiments. The similarities or similarities between them can be referred to, and for the sake of brevity, they will not be repeated here.

[0173] Those skilled in the art will understand that, in the above-described method of the specific implementation, the order in which each step is written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of each step should be determined by its function and possible internal logic.

[0174] If the technical solution of this application involves personal information, the product using this technical solution has clearly informed the user of the personal information processing rules and obtained the user's voluntary consent before processing the personal information. If the technical solution of this application involves sensitive personal information, the product using this technical solution has obtained the user's separate consent before processing the sensitive personal information, and also meets the requirement of "express consent". For example, at personal information collection devices such as cameras, clear and prominent signs are set up to inform users that they have entered the scope of personal information collection and that personal information will be collected. If an individual voluntarily enters the collection scope, it is deemed that they have agreed to the collection of their personal information; or on the personal information processing device, with clear signs / information informing users of the personal information processing rules, authorization is obtained from the individual through pop-up information or by asking the individual to upload their personal information; wherein, 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 types of personal information processed.

[0175] The various embodiments of this disclosure have been described above. These descriptions are exemplary and not exhaustive, nor are they limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is chosen to best explain the principles, practical application, or improvement of the technology in the market, or to enable others skilled in the art to understand the embodiments disclosed herein.

Claims

1. A task processing device, characterized in that, include: The task processing module receives a memory instance from an external OpenCL library, determines the context instance corresponding to the memory instance based on the memory instance, and the OpenCL library is any OpenCL library implemented based on the open computing language OpenCL; 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. The kernel function instance was created when the target task was executed previously, and the target task has the same task type as 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.

2. The apparatus according to claim 1, characterized in that: The task processing module sends a resource request to the resource management module, and the resource request includes the context instance; In response to the resource request, the resource management module 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 apparatus according to claim 2, characterized in that: If 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; if the program instance is found, it searches for the kernel function instance required to execute the task in the child nodes of the program instance; if the kernel function instance is found, it returns the kernel function instance to the task processing module.

4. The apparatus according to claim 2, characterized in that: If the resource management module does not find the context instance, it 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.

5. The apparatus according to claim 4, characterized in that: The resource management module creates program instances based on the source code of the kernel functions required to execute the task, and compiles the source code based on the program instances; it also adds the created program instances to the child nodes of the context instances in the hash table. Create a kernel function instance to manage the compiled program source code, and add the created kernel function instance to the child node of the corresponding program instance in the hash table.

6. The apparatus according to claim 1, characterized in that, The device further includes: The memory instance creation module, in response to the client's memory instance creation request, sends a resource request to the resource management module; In response to a resource request sent by the memory instance creation module, the resource management module creates a target context instance and returns it to the memory instance creation module; and 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 apparatus according to claim 6, characterized in that: The task processing module receives the target memory instance from the client and determines the target context instance corresponding to the target memory instance based on the target memory instance. Send a resource request to the resource management module, wherein the resource request includes the target context instance; In response to a resource request, the resource management module 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, the target context instance is added to the hash table as a child node of the root node; Then, a target kernel function instance required to execute the task is generated in the target context instance, and the target kernel function instance is returned to the task processing module.

8. The apparatus according to claim 2, characterized in that, The resource management module receives data requests from multiple threads simultaneously; when multiple data requests are for reading data from the hash table, multiple data requests are allowed to read the contents of the hash table simultaneously. If multiple data requests involve modifying data in the hash table, only one thread is allowed to perform the data modification operation.

9. The apparatus according to claim 1, characterized in that, The device further includes: Input / output interface, wherein the input and output of the input / output interface are memory instances; The task processing module interacts with the outside world based on the input / output interface, and the task processing module is obtained by encapsulating open source components.

10. A task processing method, characterized in that, Applied to a task processing device, the device including a task processing module and a resource management module, the method includes: The task processing module receives a memory instance from an external OpenCL library, and determines the context instance corresponding to the memory instance based on the memory instance. The OpenCL library is any OpenCL library implemented based on the open computing language OpenCL. If the resource management module already has a kernel function instance in the context instance for processing the memory instance, it returns the kernel function instance to the task processing module. The kernel function instance was created when the target task was executed previously, and the target task is of the same type as the task 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.

11. An electronic device, characterized in that, include: processor; Memory used to store processor-executable instructions; The processor is configured to invoke instructions stored in the memory to implement the method of claim 10.

12. A computer-readable storage medium having computer program instructions stored thereon, characterized in that, When the computer program instructions are executed by the processor, they implement the method of claim 10.