Resource management method and device of thread, equipment, storage medium and program product
By dynamically managing resources in the streaming multiprocessor of the graphics processing chip and allocating and releasing them according to the resource requirements of the instructions, the problem of low resource utilization in traditional technologies is solved and more efficient resource utilization is achieved.
Patent Information
- Application Number
- CN202411147605.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-20
- Publication Date
- 2024-12-13
Smart Images

Figure CN119127480A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to, but is not limited to, the field of computer technology, and in particular to a thread resource management method, apparatus, device, storage medium, and program product. Background Art
[0002] In a traditional graphics processing unit (GPU), services need to be executed in a stream multiprocessor (SM) in the form of threads. During the execution of threads in the SM, they rely on resources for operations such as reading, writing, storage, and indexing. Therefore, resources need to be allocated to threads.
[0003] Generally, the entire thread processing process includes multiple stages such as instruction fetching, decoding, and instruction execution. In the related art, resources are applied for any thread before it starts processing (i.e., the instruction fetching stage), and the resources corresponding to the thread are released after the thread is processed. This makes the resources always in a locked state during the entire processing process of the thread, and the thread does not always use the resources during the entire processing process, so there is a problem of low resource utilization. Summary of the invention
[0004] In view of this, the embodiments of the present disclosure at least provide a thread resource management method, apparatus, device, storage medium and program product.
[0005] The technical solution of the embodiment of the present disclosure is implemented as follows:
[0006] On the one hand, an embodiment of the present disclosure provides a thread resource management method, which includes: when executing a first instruction of a first thread corresponding to a graphics processing service in a streaming multiprocessor of a graphics processing chip, determining whether the first instruction requires the use of resources; if the first instruction requires the use of resources, allocating first resources to the first thread; and based on the first resources, executing the first instruction and / or instructions executed after the first instruction.
[0007] In some embodiments, when executing a first instruction of a first thread corresponding to a graphics processing service in a streaming multiprocessor of a graphics processing chip, determining whether the first instruction requires the use of resources includes: when executing the first instruction in the streaming multiprocessor, adding an allocation mark to a field of the first instruction based on a dependency relationship between instructions in the first thread; the allocation mark indicates whether the first instruction requires the use of resources; and the dependency relationship indicates a timing relationship between instructions in the first thread and resource usage of each instruction.
[0008] In some embodiments, when a first instruction requires the use of resources, a first resource is allocated to a first thread, including: when the first instruction is the first instruction in the first thread that requires the use of resources, based on the allocation tag, setting the execution state of the first thread to a first identifier, and generating a resource application request for the first thread; the first identifier indicates that the corresponding thread is in an inactivated state; and based on the resource information in the resource application request of the first thread, allocating the first resource to the first thread.
[0009] In some embodiments, allocating a first resource to the first thread based on resource information in the resource application request of the first thread includes: determining whether a resource application request of a second thread other than the first thread is currently being processed; determining whether idle resources in the graphics processing chip are greater than or equal to the first resource; and allocating the first resource to the first thread based on the resource information in the resource application request of the first thread when there is currently no resource application request of the second thread and the idle resources are greater than or equal to the first resource.
[0010] In some embodiments, the thread resource management method also includes: pausing processing of the resource application request of the first thread when the resource application request of the second thread is currently being processed, or when the free resources are less than the first resources, or when the resource application request of the second thread is currently being processed and the free resources are less than the first resources.
[0011] In some embodiments, the thread resource management method also includes: when the free resources are less than the first resources, detecting a resource release request of any thread; when the resource release request is detected, determining whether the sum of the resources released by the resource release request and the free resources is greater than or equal to the first resources; when there is currently no resource allocation request from the second thread and the sum of the resources released by the resource release request and the free resources is greater than or equal to the first resources, reprocessing the resource application request of the first thread.
[0012] In some embodiments, based on the first resource, executing the first instruction and / or the instructions executed after the first instruction includes: after the first thread obtains the first resource, updating the execution state of the first thread from the first identifier to the second identifier; the first identifier indicates that the corresponding thread is in an inactive state, and the second identifier indicates that the corresponding thread is in an active state; based on the first resource and the dependency relationship between the instructions in the first thread, executing the first instruction and / or the instructions executed after the first instruction; the dependency relationship indicates the timing relationship between the instructions in the first thread and the resource usage of each instruction.
[0013] In some embodiments, based on the dependency between the first resource and the instructions in the first thread, executing the first instruction and / or the instructions executed after the first instruction includes: executing the first instruction based on the first resource; determining whether the first instruction is the last instruction in the first thread that uses the resource based on the dependency; if the first instruction is not the last instruction in the first thread that uses the resource, executing the next instruction executed after the first instruction based on the first resource, and determining whether the next instruction is the last instruction in the first thread that uses the resource based on the dependency, until all instructions executed after the first instruction are executed.
[0014] In some embodiments, the thread resource management method further includes: releasing the first resource corresponding to the first thread when the first instruction is the last instruction in the first thread that uses the resource; and executing all instructions in the first thread that are executed after the first instruction.
[0015] In some embodiments, when the first instruction is the last instruction in the first thread that uses a resource, releasing the first resource corresponding to the first thread includes: when the first instruction is the last instruction in the first thread that uses a resource, adding a release mark to a field of the first instruction; when it is detected that the execution of the first instruction is complete, generating a resource release request for the first thread; and releasing the first resource based on the resource information in the resource release request of the first thread.
[0016] In some embodiments, when executing a first instruction of a first thread corresponding to a graphics processing service in a streaming multiprocessor of a graphics processing chip, before determining whether the first instruction requires the use of resources, the thread resource management method also includes: when processing a graphics processing service in a streaming multiprocessor, organizing multiple threads according to the service type included in the graphics processing service and / or the execution codes of multiple threads corresponding to the graphics processing service to obtain multiple thread groups; when any thread in any thread group meets an execution condition, taking any thread as the first thread and executing instructions in an instruction sequence in the first thread; the execution condition at least includes that the data dependencies and optimization dependencies required by the corresponding thread before execution have been released.
[0017] On the other hand, an embodiment of the present disclosure provides a thread resource management device, which includes: a thread execution module, which is used to determine whether a first instruction of a first thread corresponding to a graphics processing service needs to use resources when executing the first instruction in a streaming multiprocessor of a graphics processing chip; a resource management module, which is used to allocate a first resource to the first thread if the first instruction needs to use resources; and the thread execution module, which is also used to execute the first instruction and / or instructions executed after the first instruction based on the first resource.
[0018] In some embodiments, the thread resource management device also includes: a thread component module, which is used to organize multiple threads according to the business types included in the graphics processing business and the execution codes of multiple threads corresponding to the graphics processing business to obtain multiple thread groups; a resource application detection module, which is used to detect the resource application request of the thread; and a resource release detection module, which is used to detect the resource release request of the thread.
[0019] On the other hand, an embodiment of the present disclosure provides a computer device, including a memory and a processor, wherein the memory stores a computer program executable on the processor, and when the processor executes the program, some or all of the steps in the above method are implemented.
[0020] On the other hand, an embodiment of the present disclosure provides a computer-readable storage medium having a computer program stored thereon, which implements part or all of the steps in the above method when executed by a processor.
[0021] On the other hand, an embodiment of the present disclosure provides a computer program, including computer-readable codes. When the computer-readable codes are executed in a computer device, a processor in the computer device executes some or all of the steps for implementing the above method.
[0022] On the other hand, an embodiment of the present disclosure provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and when the computer program is read and executed by a computer, some or all of the steps in the above method are implemented.
[0023] In the disclosed embodiment, when executing the first instruction of the first thread corresponding to the graphics processing service in the streaming multiprocessor of the graphics processing chip, it is determined whether the first instruction needs to use resources; thus, when executing any instruction (first instruction) of the first thread, the resource usage requirement of the thread can be determined. In the case where the first instruction needs to use resources, the first resource is allocated to the first thread; thus, when the first instruction of the first thread has a resource usage requirement, the first resource is allocated to the first thread. Based on the first resource, the first instruction and / or the instructions executed after the first instruction are executed; thus, the first instruction and the instructions executed after the first instruction can be executed based on the applied first resource. In this way, in the instruction execution phase of the thread, resources are allocated according to the resource usage requirement. Compared with the related art in which resources are locked all the time during the entire processing process of the thread, the resource locking time of a single thread can be made only during the execution phase of the thread, so that the resource locking time of a single thread can be made as short as possible, thereby improving resource utilization.
[0024] It should be understood that the above general description and the following detailed description are merely exemplary and explanatory, and are not intended to limit the technical solutions of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] 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.
[0026] Figure 1 A schematic diagram of the implementation process of a thread resource management method provided in an embodiment of the present disclosure Figure 1 ;
[0027] Figure 2 A schematic diagram of the implementation process of a thread resource management method provided in an embodiment of the present disclosure Figure 2 ;
[0028] Figure 3 A schematic diagram of modules involved in a thread resource management method provided by an embodiment of the present disclosure;
[0029] Figure 4 A schematic diagram of an application of a thread resource management method provided by an embodiment of the present disclosure;
[0030] Figure 5 A schematic diagram of the composition structure of a thread resource management device provided by an embodiment of the present disclosure;
[0031] Figure 6 A hardware entity schematic diagram of a computer device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0032] In order to make the purpose, technical solutions and advantages of the present disclosure clearer, the technical solutions of the present disclosure are further elaborated in detail below in conjunction with the drawings and embodiments. The described embodiments should not be regarded as limiting the present disclosure. All other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present disclosure.
[0033] In the following description, reference is made to “some embodiments”, which describe a subset of all possible embodiments, but it will be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0034] The terms "first / second / third" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It is understandable that "first / second / third" can be interchanged with a specific order or sequence where permitted so that the embodiments of the present disclosure described herein can be implemented in an order other than that illustrated or described herein.
[0035] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which the present disclosure belongs. The terms used herein are only for the purpose of describing the present disclosure and are not intended to limit the present disclosure.
[0036] The present disclosure provides a thread resource management method, which can be executed by a graphics processing chip of a computer device. The computer device may refer to a server, a laptop, a tablet computer, a desktop computer, a smart TV, a set-top box, a mobile device (such as a mobile phone, a portable video player, a personal digital assistant, a dedicated messaging device, a portable gaming device), and other devices with data processing capabilities. Figure 1 As shown, the method includes the following steps 101 to 103:
[0037] Step 101: When executing a first instruction of a first thread corresponding to a graphics processing service in a streaming multiprocessor of a graphics processing chip, determine whether the first instruction needs to use resources.
[0038] Graphics processing chips are used to provide hardware support for graphics-related services. For example, graphics processing chips can be used to enhance graphics and / or video rendering, etc. In a feasible implementation, the graphics processing chip can be a GPU. Graphics processing services refer to services related to graphics; for example, graphics processing services include rendering services at the graphics front end and processing services at the graphics back end.
[0039] Each graphics processing service includes at least one thread; for example, if the graphics processing service is to perform a convolution operation on an image, then the convolution operation on each pixel in the image can be regarded as a thread, and thus, there will be as many threads as there are pixels in the image.
[0040] Each thread includes an instruction sequence consisting of at least one instruction. The instruction sequence can be expressed as: {instruction_N, instruction_N+1, instruction_N+2, ...}. The first thread refers to any thread in the graphics processing service. The first instruction refers to any instruction in the first thread. The first resource refers to the resource allocated to the first thread, and the resource may include but is not limited to: thread number, resource size, on-chip private storage, off-chip private storage, etc.
[0041] The streaming multiprocessor is a core component in the GPU architecture, responsible for executing parallel computing tasks. In a feasible implementation, the streaming multiprocessor can be an SM. The SM contains multiple registers, shared memory, cache and other resources, which are shared by threads. Each SM is composed of multiple streaming processors (SP), which are used to convert the data transmitted from the GPU into digital signals that can be recognized by the display. In the GPU architecture, the number and configuration of SMs vary depending on the different GPU models and architectures. For example, some architectures may have more computing resources on each SM, while other architectures may provide more shared memory or registers.
[0042] In a feasible implementation, when the first thread has gone through the stages of instruction fetching, decoding, etc. and is in the execution stage, when executing the first instruction (any instruction) in the first thread, it is first determined whether the first instruction needs to use resources. If the first instruction needs to use resources, step 102 is executed; if the first instruction does not need to use resources, it is directly executed, and then the next instruction is used as the first instruction, and step 101 and subsequent steps are re-executed.
[0043] In a feasible implementation, an allocation identifier may be pre-marked on the field of each instruction of the first thread, and the allocation identifier indicates that the corresponding thread needs to apply for resources; thus, when executing the first instruction (any instruction) in the first thread, it may be determined whether the first instruction needs to use resources based on the allocation identifier on the field of the first instruction. For ease of distinction, the allocation identifier may be marked only on the field of instructions that need to use resources, and not on the field of instructions that do not need to use resources. Exemplarily, the allocation identifier may be a binary character, a string, etc.; for example, 1 (allocation identifier) may be marked on the field of instructions that need to use resources.
[0044] In another feasible implementation, at least one instruction that requires the use of resources can be stored in advance in the form of a table to obtain an instruction table. When executing any instruction in the first thread (first instruction), the instruction can be matched with the instruction table. If the match is successful, it is determined that the instruction requires the use of resources; if the match fails, it is determined that the instruction does not need to use resources.
[0045] Step 102: When the first instruction needs to use resources, allocate first resources to the first thread.
[0046] In a feasible implementation, the first resource may be allocated to the first thread based on the resource information required by the first instruction. The resource information may include the thread number to which the first instruction belongs, the resource size required by the first instruction, etc.; wherein the resource size may include the cache size required by the first instruction, the on-chip storage size required by the first instruction, the on-chip private storage required by the first instruction, the computing resource bandwidth required by the first instruction, the video memory resource size required by the first instruction, etc.
[0047] Step 103: Execute the first instruction and / or instructions executed after the first instruction based on the first resource.
[0048] In a feasible implementation, when the first resource is applied for the first thread, the first instruction in the first thread can be executed based on the first resource. When the instructions executed after the first instruction also need to use resources, the instructions executed after the first instruction continue to be executed based on the applied first resource.
[0049] In the disclosed embodiment, when executing the first instruction of the first thread corresponding to the graphics processing service in the streaming multiprocessor of the graphics processing chip, it is determined whether the first instruction needs to use resources; thus, when executing any instruction (first instruction) of the first thread, the resource usage requirement of the thread can be determined. In the case where the first instruction needs to use resources, the first resource is allocated to the first thread; thus, when the first instruction of the first thread has a resource usage requirement, the first resource is allocated to the first thread. Based on the first resource, the first instruction and / or the instructions executed after the first instruction are executed; thus, the first instruction and the instructions executed after the first instruction can be executed based on the applied first resource. In this way, in the instruction execution phase of the thread, resources are allocated according to the resource usage requirement. Compared with the related art in which resources are locked all the time during the entire processing process of the thread, the resource locking time of a single thread can be made only during the execution phase of the thread, so that the resource locking time of a single thread can be made as short as possible, thereby improving resource utilization.
[0050] The present disclosure provides a thread resource management method, which can be executed by a graphics processing chip of a computer device. Figure 2 As shown, the method includes the following steps 201 to 207:
[0051] Step 201: When processing the graphics processing service in the streaming multiprocessor, the multiple threads are organized according to the service types included in the graphics processing service and / or the execution codes of the multiple threads corresponding to the graphics processing service to obtain multiple thread groups.
[0052] like Figure 3As shown, the thread resource management method provided by the embodiment of the present disclosure involves a thread component module, a thread execution module, a resource application detection module, a resource management module, and a resource release detection module. Among them, the thread component module is used to assemble the thread executed on the GPU; the thread execution module is used to process the thread, and the thread execution module supports multi-threaded processing; the resource application detection module is used to detect the resource application request of the thread; the resource management module is used to allocate resources to the thread; and the resource release detection module is used to detect the resource release request of the thread.
[0053] In a feasible implementation, the types of services included in the graphics processing service may include graphics front-end and graphics back-end. Further, the graphics front-end and graphics back-end may be subdivided; illustratively, they may be subdivided according to specific operations of graphics processing; for example, the graphics back-end may be subdivided into convolution type services and rendering type services according to specific operations of graphics processing.
[0054] In a feasible implementation, multiple threads corresponding to the graphics processing service may be organized by a thread component module to obtain multiple thread groups. It should be noted that organizing multiple threads corresponding to the graphics processing service may reduce subsequent instruction fetching pressure.
[0055] Specifically, the multiple threads corresponding to the graphics processing business can be organized according to the business types included in the graphics processing business, and the threads with the same business type can be divided into the same group to obtain multiple thread groups; or, the multiple threads can be organized according to the execution codes of the multiple threads corresponding to the graphics processing business, and the threads with the same execution codes can be divided into the same group to obtain multiple thread groups; or, the multiple threads can be organized according to the business types included in the graphics processing business and the execution codes of the multiple threads corresponding to the graphics processing business, and the threads with the same business type and the same execution code can be divided into the same group to obtain multiple thread groups.
[0056] In a feasible implementation, multiple threads corresponding to the graphics processing business can also be organized according to a preset number threshold to obtain multiple thread groups. The preset number threshold can be set according to the business type; illustratively, the preset number threshold can be 32; that is, every 32 threads are divided into a group to obtain multiple thread groups.
[0057] Step 202: When any thread in any thread group meets the execution condition, use the any thread as the first thread and execute instructions in the instruction sequence in the first thread.
[0058] The execution condition at least includes that the data dependency and optimization dependency required by the corresponding thread before execution have been released.
[0059] Execution conditions refer to the conditions that need to be prepared before a thread is executed. Data dependency refers to the data that a thread needs to prepare before it is executed; optimization dependency refers to the timing optimization and execution optimization that need to be clarified before a thread is executed.
[0060] If any thread in any thread group meets the execution condition, it means that the thread has released data dependency and optimization dependency, that is, the thread has been initialized successfully, and subsequent steps such as instruction fetching, decoding, and instruction execution can be performed.
[0061] In a feasible implementation, when any thread in any thread group meets the execution condition, any thread is used as the first thread, and the instructions in the instruction sequence in the first thread are executed through the thread execution module.
[0062] Step 203: When executing the first instruction in the streaming multiprocessor, based on the dependency relationship between instructions in the first thread, add an allocation tag to a field of the first instruction.
[0063] The allocation tag indicates whether the first instruction needs to use resources; the dependency relationship indicates the timing relationship between instructions in the first thread and the resource usage of each instruction.
[0064] In a feasible implementation, a compiler may add a 1-bit allocation tag to the field (field) of the instruction that needs to use resources based on the dependency relationship between instructions in the first thread. In this way, when the first instruction is executed, it may be determined whether the first instruction needs to use resources based on the allocation tag on the field of the first instruction.
[0065] Step 204: When the first instruction is the first instruction in the first thread that needs to use resources, the execution state of the first thread is set to a first flag based on the allocation tag, and a resource application request for the first thread is generated.
[0066] The first flag indicates that the corresponding thread is in an inactive state.
[0067] The first flag indicates that the corresponding thread is in an inactive state, that is, the first flag indicates that the corresponding thread is currently in a suspended state and waiting for resources. Exemplarily, the first flag may be descheduled (suspended) or notactive (inactive).
[0068] In a feasible implementation, when executing the first instruction, the first thread can be set as the first identifier through the thread execution module, and a resource application request for the first thread is generated and sent to the resource application detection module.
[0069] Step 205: Allocate the first resource to the first thread based on the resource information in the resource application request of the first thread.
[0070] In some embodiments, the specific implementation method of step 205 may be: determining whether a resource application request of a second thread other than the first thread is currently being processed; determining whether the idle resources in the graphics processing chip are greater than or equal to the first resources; in a case where there is currently no resource application request of the second thread and the idle resources are greater than or equal to the first resources, allocating the first resource to the first thread based on the resource information in the resource application request of the first thread.
[0071] The second thread refers to the other thread currently being processed except the first thread. The resource application request of the second thread except the first thread is currently being processed, which means that the resource application request of the other thread is currently being processed. Since processing the resource application requests of multiple threads at the same time may cause the problem of repeated resource allocation and thread execution exception, only one thread's resource application request can be processed at the same time to improve the effectiveness of resource allocation.
[0072] Whether the idle resources in the graphics processing chip are greater than or equal to the first resources refers to whether the current idle resources meet the resource requirements of the first thread. If the idle resources in the graphics processing chip are greater than or equal to the first resources, it means that the idle resources on the graphics processing chip can meet the resource requirements of the first thread; if the idle resources on the graphics processing chip are less than the first resources, it means that the idle resources on the graphics processing chip are less and cannot meet the resource requirements of the first thread at this time.
[0073] There is no resource application request of the second thread at present, and the sum of the resources released by the resource release request and the idle resources is greater than or equal to the first resources, indicating that the current idle resources meet the resource requirements of the first thread. At this time, the resource application request of the first thread can be reprocessed.
[0074] In a feasible implementation, when no resource application requests from other threads are currently being processed and there are sufficient idle resources on the graphics processor, the required first resource can be allocated to the first thread based on the resource type and resource size of the resource information in the resource application request of the first thread.
[0075] Exemplarily, if the first thread requires video memory resources and / or computing power resources, the video memory resource size and / or computing power resource size may be carried in the resource application request, thereby allocating the first resource matching the video memory resource size and / or computing power resource size to the first thread.
[0076] Furthermore, in a feasible implementation, a segment allocation strategy, a page allocation strategy, or a segment-page mixed allocation strategy can be adopted to allocate the required first resource to the first thread based on the resource type and resource size of the resource information in the resource application request of the first thread.
[0077] In some embodiments, when the resource application request of the second thread is currently being processed, or when the free resources are less than the first resources, or when the resource application request of the second thread is currently being processed and the free resources are less than the first resources, processing of the resource application request of the first thread is suspended.
[0078] In a feasible implementation, if the following three situations exist: first, the resource application request of a second thread other than the first thread is currently being processed; second, the idle resources on the graphics processor are less than the first resources; third, the resource application request of a second thread other than the first thread is currently being processed and the idle resources on the graphics processor are less than the first resources, then the processing of the resource application request of the first thread needs to be suspended, and the resource application request of the first thread is reprocessed when the resource application request of other threads is not currently being processed and there are sufficient idle resources.
[0079] In some embodiments, if the idle resources on the graphics processor are insufficient, the following steps may be performed: when the idle resources are less than the first resources, detecting a resource release request of any thread; when the resource release request is detected, determining whether the sum of the resources released by the resource release request and the idle resources is greater than or equal to the first resources; and when there is currently no resource allocation request from the second thread and the sum of the resources released by the resource release request and the idle resources is greater than or equal to the first resources, reprocessing the resource application request of the first thread.
[0080] In a feasible implementation, a resource release detection module can be used to detect a resource release request of any thread; after detecting the resource release request of any thread, a resource management module can be used to determine whether the sum of the resources released by the resource release request and the idle resources is greater than or equal to the first resource.
[0081] Step 206: After the first thread obtains the first resource, update the execution state of the first thread from the first identifier to the second identifier.
[0082] The first mark indicates that the corresponding thread is in an inactive state, and the second mark indicates that the corresponding thread is in an active state.
[0083] The second flag indicates that the corresponding thread is in an activated state, that is, the second flag indicates that the corresponding thread is currently in an activated state. Exemplarily, the second flag may be scheduled (execution) or active (activation).
[0084] In a feasible implementation, after receiving the feedback information indicating that the resource application is successful and sent by the resource management module, the thread execution module may update the execution state of the first thread to the second identifier.
[0085] Step 207: Execute the first instruction and / or instructions executed after the first instruction based on the dependency relationship between the first resource and the instructions in the first thread.
[0086] The dependency relationship represents the timing relationship between instructions in the first thread and the resource usage of each instruction.
[0087] Here, the above step 207 corresponds to the above step 103, and the specific implementation of the above step 103 may be referred to during implementation.
[0088] In some embodiments, the specific implementation method of step 207 may be: executing the first instruction based on the first resource; based on the dependency, determining whether the first instruction is the last instruction in the first thread that uses the resource; if the first instruction is not the last instruction in the first thread that uses the resource, executing the next instruction executed after the first instruction based on the first resource, and determining whether the next instruction is the last instruction in the first thread that uses the resource based on the dependency, until all instructions executed after the first instruction are executed; if the first instruction is the last instruction in the first thread that uses the resource, releasing the first resource corresponding to the first thread; and executing all instructions in the first thread that are executed after the first instruction.
[0089] There are dependencies between instructions of the same thread, and which instructions need to use resources can be known based on the dependencies.
[0090] The first instruction is not the last instruction in the first thread that uses the resource, which means that instructions after the first instruction still need to use the first resource. At this time, the first resource is continued to be used to process instructions after the first instruction.
[0091] The first instruction is the last instruction in the first thread that uses resources, which means that all instructions after the first instruction do not need to use resources. Therefore, the resources can be released after the first instruction is executed. Compared with the related art that resources must be released after all instructions of the first thread are executed, the resource locking time is shorter, which further improves the resource utilization rate.
[0092] In a feasible implementation, when the first instruction is not the last instruction that uses the resource in the first thread, the next instruction executed after the first instruction is executed based on the first resource, and whether the next instruction is the last instruction that uses the resource in the first thread is determined based on the dependency relationship; if the next instruction is the last instruction that uses the resource in the first thread, the resources are released; if the next instruction is not the last instruction that uses the resource in the first thread, instructions after the next instruction are processed based on the first resource until all instructions executed after the first instruction are executed.
[0093] In some embodiments, the specific implementation method of "releasing the first resource corresponding to the first thread when the first instruction is the last instruction in the first thread that uses the resource" may be: when the first instruction is the last instruction in the first thread that uses the resource, adding a release mark to the field of the first instruction; when it is detected that the execution of the first instruction is completed, generating a resource release request for the first thread; and releasing the first resource based on the resource information in the resource release request of the first thread.
[0094] The release mark indicates that the corresponding thread needs to release resources.
[0095] In a feasible implementation, a 1-bit release mark can be marked on the field of the first instruction; in this way, after detecting that the first instruction has been executed, the thread execution module sends a resource release request for the first thread to the resource release detection module, and the resource release request carries resource information such as the thread number, resource base address, and resource size.
[0096] For example, there is an instruction sequence {instruction_M, instruction_M+1, instruction_M+2, ...; among them, instruction_M+1} in the thread, among which, instruction_M and instruction_M+1 need to use resources. When executing instruction_M, resources are requested; instruction_M and instruction_M+1 are executed based on the requested resources. After executing instruction_M+1, since instruction_M+1 is the last instruction of the thread that uses resources, the compiler marks a 1-bit release mark on the instruction field of instruction_M+1. After the thread execution module detects that instruction_M+1 has been executed, it sends a resource release request to the resource release detection module, and carries the necessary resource information of the thread, and continues to execute instruction_M+2.
[0097] In the embodiment of the present disclosure, when executing the first instruction of the first thread corresponding to the graphics processing service in the streaming multiprocessor of the graphics processing chip, it is determined whether the first instruction needs to use resources; thus, when executing any instruction (first instruction) of the first thread, the resource usage requirement of the thread can be determined. In the case where the first instruction needs to use resources, the first resource is allocated to the first thread; thus, when the first instruction of the first thread has a resource usage requirement, the first resource is allocated to the first thread. Based on the first resource, the first instruction and / or the instructions executed after the first instruction are executed; thus, the first instruction and the instructions executed after the first instruction can be executed based on the applied first resource. In this way, in the instruction execution phase of the thread, resources are allocated according to the resource usage requirement. Compared with the related art in which resources are locked all the time during the entire processing process of the thread, the resource locking time of a single thread can be made only during the execution phase of the thread, so that the resource locking time of a single thread can be made as short as possible, thereby improving resource utilization. Without increasing hardware overhead, resource utilization can be improved by simply changing the resource application and release time, and implementation is more flexible.
[0098] The following describes the application of the thread resource management method provided by the embodiment of the present disclosure in a practical scenario.
[0099] In the actual GPU scenario, Figure 3 The thread assembly module shown is specifically used to: assemble threads that can be executed on the GPU according to certain specification indicators (preset quantity threshold); although the thread assembly module is assembled in a serial order, multiple threads can be processed simultaneously during processing, and there will be a certain time interval t between the front and rear threads due to the bandwidth of the upstream data transmission and the lack of downstream back pressure.
[0100] In the actual GPU scenario, Figure 3 The thread execution module shown is specifically used to support multi-thread processing, including steps such as instruction fetching, decoding, and instruction execution. When the thread execution is completed, the thread is terminated. Specifically, there are two functional descriptions of the following processes:
[0101] 1) There is an instruction sequence {instruction_N, instruction_N+1, instruction_N+2, ...} in the thread. Among them, instruction_N+1 needs to use a certain resource, so the compiler marks a 1-bit allocation mark on the relevant field (field) of the instruction code of instruction_N+1. When the thread processor (thread execution module) executes instruction_N+1, it changes the thread to the descheduled (not active) state by default, and sends the resource application request to the resource application detection module at the same time; waits for a while, and when it receives the feedback information from the resource management module indicating that the resource application is successful, it changes the thread state to the scheduled (active) state; and restarts the execution of instruction_N+1.
[0102] 2) There is an instruction sequence {instruction_M, instruction_M+1, instruction_M+2, ...} in the thread. Instruction_M+1 is the last instruction of the thread that uses resources. The compiler marks a 1-bit release mark on the relevant field of the instruction code of instruction_M+1. The thread execution module executes instruction_M+1 normally, detects whether instruction_M+1 has been executed, and sends a resource release request to the resource release detection module after completion, and carries the necessary resource information of the thread (such as thread number, resource base address, resource size, etc.); and continues to execute instruction_M+2.
[0103] In the actual GPU scenario, Figure 3 The resource application detection module shown is specifically used to detect the resource application request issued by the thread execution module and forward the resource application request to the resource management module. Regardless of the management method adopted (segment allocation strategy or page allocation strategy), it is difficult for the resource management module to complete the resource allocation operation within one clock cycle. In the multi-threaded operation scenario, the need for cache application can ensure the correctness of the function; therefore, this module adopts a serial processing structure, that is, the resource application request is sent to the resource management module in the order of receiving the resource application request from the thread execution module.
[0104] In the actual GPU scenario, Figure 3 The resource release detection module shown is specifically used to detect the resource release request issued by the thread execution module and forward the resource release request to the resource management module. In a multi-threaded operation scenario, since the resource releases of different threads have little impact on each other, the resource release requests of multiple threads can be processed simultaneously. Alternatively, to ensure the correctness of the function, this module adopts a serial processing structure, that is, the resource release request is sent to the resource management module in the order in which the resource release request of the thread execution module is received.
[0105] In the actual GPU scenario, Figure 3 The resource management module shown is specifically used to: manage resources according to resource application requests and resource release requests, and return an application success message after the application is completed, and return a release success message after the release is completed. The application and release of resources can be performed independently in parallel. If a resource application request cannot be responded to due to resource limitations, the resource application request is suspended, and when a resource release request releases part of the resource space, the previously suspended resource application request is retried; specifically, a resource application request can be selected from the suspended resource application requests according to the sending time of the resource application request for retry.
[0106] like Figure 4 As shown, the assumed scenario is as follows: there are several threads executing the same code segment, and no resources are used in the 10% time at the beginning and the end. If a thread wants to use 25% of the resources; the interval t for each resource to be issued (t is much smaller than the entire processing time T of the thread); then the time for thread 1, thread 2, thread 3, and thread 4 to apply for resources is 0.1T, 0.1T+t, 0.1T+2t, and 0.1T+3t respectively; the time for releasing resources is 0.9T, 0.9T+t, 0.9T+2t, and 0.9T+3t respectively; then, thread 5, thread 6, thread 7, and thread 8 can apply for resources at 0.9T, 0.9T+t, 0.9T+2t, and 0.9T+3t.
[0107] Compared with the related art method of applying for resources before the thread starts processing and releasing the resources after the thread ends, the time each thread locks the resource is 0.8T, and the resource utilization efficiency can be improved by 25%.
[0108] Assume there are X threads, and other parameters are as above. Figure 4As mentioned above, the total time required for the thread resource management method provided by the present disclosure is: (X / 4)*0.8T+(0.1T)+(0.1T+3t); and the total time required for the method of the related art is: (X / 4)*0.8T+(3t); the total task volume is divided by the total working time to calculate the resource utilization efficiency, then the ratio of the resource utilization efficiency a of the thread resource management method provided by the present disclosure to the resource utilization efficiency b of the method of the related art can be expressed as:
[0109]
[0110] It is known that t is much smaller than T. When X is infinite, the value of the above formula is invalid and approaches 1.25; therefore, the resource utilization rate of the thread resource management method provided by the present disclosure is increased by 25% compared with the resource utilization rate of the related art.
[0111] Based on the above embodiments, the embodiment of the present disclosure provides a thread resource management device, which includes the units included, and the modules included in each unit, which can be implemented by a processor in a computer device; of course, it can also be implemented by a specific logic circuit; in the implementation process, the device is used as a general processing device to perform basic controls including but not limited to data handling, starting and / or stopping the computing device. According to different implementation methods, the processing device can be one or more types of processors in a central processing unit (CPU), a graphics processor or other general and / or special processors, these processors include but are not limited to a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc., and their number can be determined according to actual needs. As mentioned above, only with respect to the computing device disclosed in the present disclosure, it can be regarded as having a single-core structure or a homogeneous multi-core structure. However, when the computing device and the processing device are integrated and considered together, the two are regarded as forming a heterogeneous multi-core structure.
[0112] Figure 5 A schematic diagram of the composition structure of a thread resource management device provided by an embodiment of the present disclosure, such as Figure 5 As shown, the thread resource management device 500 includes: a thread execution module 510 and a resource management module 520, wherein:
[0113] The thread execution module 510 is used to determine whether a first instruction of a first thread corresponding to a graphics processing service needs to use resources when executing the first instruction in the streaming multiprocessor of the graphics processing chip;
[0114] A resource management module 520, configured to allocate a first resource to the first thread when the first instruction needs to use a resource;
[0115] The thread execution module 510 is further configured to execute the first instruction and / or instructions executed after the first instruction based on the first resource.
[0116] In some embodiments, the thread resource management device further includes:
[0117] A thread component module (not shown in the figure), used to organize the multiple threads according to the service types included in the graphics processing service and the execution codes of the multiple threads corresponding to the graphics processing service to obtain multiple thread groups;
[0118] A resource application detection module (not shown in the figure), used to detect resource application requests of threads;
[0119] The resource release detection module (not shown in the figure) is used to detect the resource release request of the thread.
[0120] The description of the above device embodiment is similar to the description of the above method embodiment, and has similar beneficial effects as the method embodiment. In some embodiments, the functions or modules included in the device provided in the embodiments of the present disclosure can be used to execute the method described in the above method embodiment. For technical details not disclosed in the device embodiment of the present disclosure, please refer to the description of the method embodiment of the present disclosure for understanding.
[0121] It should be noted that, in the embodiments of the present disclosure, if the resource management method of the above-mentioned thread is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the embodiment of the present disclosure is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in each embodiment of the present disclosure. The aforementioned storage medium includes: various media that can store program codes, such as a U disk, a mobile hard disk, a read-only memory (ROM), a disk or an optical disk. In this way, the embodiments of the present disclosure are not limited to any specific hardware, software or firmware, or any combination of hardware, software, and firmware.
[0122] An embodiment of the present disclosure provides a computer device, including a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the processor executes the program, some or all of the steps in the above method are implemented.
[0123] The embodiment of the present disclosure provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, some or all of the steps in the above method are implemented. The computer-readable storage medium can be transient or non-transient.
[0124] An embodiment of the present disclosure provides a computer program, including a computer-readable code. When the computer-readable code is executed in a computer device, a processor in the computer device executes some or all of the steps for implementing the above method.
[0125] The present disclosure provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and when the computer program is read and executed by a computer, some or all of the steps in the above method are implemented. The computer program product can be implemented specifically by hardware, software or a combination thereof. In some embodiments, the computer program product is specifically embodied as a computer storage medium, and in other embodiments, the computer program product is specifically embodied as a software product, such as a software development kit (SDK), etc.
[0126] It should be noted here that the description of the various embodiments above tends to emphasize the differences between the various embodiments, and the same or similar aspects can be referenced to each other. The description of the above device, storage medium, computer program and computer program product embodiments is similar to the description of the above method embodiment, and has similar beneficial effects as the method embodiment. For technical details not disclosed in the embodiments of the device, storage medium, computer program and computer program product disclosed in the present invention, please refer to the description of the method embodiment disclosed in the present invention for understanding.
[0127] It should be noted that Figure 6 is a schematic diagram of a hardware entity of a computer device in an embodiment of the present disclosure, such as Figure 6 As shown, the hardware entity of the computer device 600 includes: a processor 601, a communication interface 602 and a memory 603, wherein:
[0128] Processor 601 generally controls the overall operation of computer device 600 .
[0129] The communication interface 602 enables the computer device to communicate with other terminals or servers through a network.
[0130] The memory 603 is configured to store instructions and applications executable by the processor 601, and can also cache data to be processed or processed by the processor 601 and each module in the computer device 600 (for example, image data, audio data, voice communication data, and video communication data), which can be implemented by flash memory (FLASH) or random access memory (Random Access Memory, RAM). Data transmission can be performed between the processor 601, the communication interface 602, and the memory 603 through the bus 604.
[0131] It should be understood that "one embodiment" or "an embodiment" mentioned throughout the specification means that specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present disclosure. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. It should be understood that in the various embodiments of the present disclosure, the size of the serial numbers of the above-mentioned steps / processes does not mean the order of execution. The execution order of each step / process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present disclosure. The serial numbers of the embodiments of the present disclosure are for description only and do not represent the advantages and disadvantages of the embodiments.
[0132] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0133] In the several embodiments provided in the present disclosure, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored, or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0134] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units; they may be located in one place or distributed on multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0135] In addition, all functional units in the embodiments of the present disclosure may be integrated into one processing unit, or each unit may be separately configured as a unit, or two or more units may be integrated into one unit; the above-mentioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0136] A person skilled in the art can understand that all or part of the steps of implementing the above method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above method embodiment; and the aforementioned storage medium includes: mobile storage devices, read-only memories (ROM), magnetic disks or optical disks, etc., various media that can store program codes.
[0137] Alternatively, if the above-mentioned integrated unit of the present disclosure is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present disclosure can essentially or in other words, the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in each embodiment of the present disclosure. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROMs, magnetic disks, or optical disks.
[0138] The above description is only an implementation mode of the present disclosure, but the protection scope of the present disclosure is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present disclosure, which should be included in the protection scope of the present disclosure.
Claims
1. A thread resource management method, characterized in that: The thread resource management method includes: When executing a first instruction of a first thread corresponding to a graphics processing service in a streaming multiprocessor of a graphics processing chip, determining whether the first instruction needs to use resources; When the first instruction needs to use resources, allocating first resources to the first thread; The first instruction and / or instructions executed after the first instruction are executed based on the first resource.
2. The thread resource management method according to claim 1, characterized in that: When executing a first instruction of a first thread corresponding to a graphics processing service in a streaming multiprocessor of a graphics processing chip, determining whether the first instruction needs to use resources includes: When the first instruction is executed in the streaming multiprocessor, an allocation tag is added to the field of the first instruction based on the dependency relationship between the instructions in the first thread; the allocation tag indicates whether the first instruction needs to use resources; the dependency relationship indicates the timing relationship between the instructions in the first thread and the resource usage of each instruction.
3. The thread resource management method according to claim 2, characterized in that: The allocating a first resource to the first thread when the first instruction needs to use a resource includes: In the case where the first instruction is the first instruction in the first thread that needs to use resources, the execution state of the first thread is set to a first identifier based on the allocation tag, and a resource application request for the first thread is generated; the first identifier indicates that the corresponding thread is in an inactive state; Based on the resource information in the resource application request of the first thread, the first resource is allocated to the first thread.
4. The thread resource management method according to claim 3, characterized in that: The allocating the first resource to the first thread based on the resource information in the resource application request of the first thread includes: Determining whether a resource application request of a second thread other than the first thread is currently being processed; Determine whether the idle resources in the graphics processing chip are greater than or equal to the first resources; When there is no resource application request of the second thread at present and the idle resources are greater than or equal to the first resources, the first resource is allocated to the first thread based on resource information in the resource application request of the first thread.
5. The thread resource management method according to claim 4, characterized in that: The thread resource management method also includes: When the resource application request of the second thread is currently being processed, or when the free resources are smaller than the first resources, or when the resource application request of the second thread is currently being processed and the free resources are smaller than the first resources, the processing of the resource application request of the first thread is suspended.
6. The thread resource management method according to claim 5, characterized in that: The thread resource management method also includes: In a case where the idle resources are less than the first resources, detecting a resource release request of any thread; In the case where the resource release request is detected, determining whether the sum of the resources released by the resource release request and the idle resources is greater than or equal to the first resource; If there is no resource allocation request of the second thread currently, and the sum of the resources released by the resource release request and the idle resources is greater than or equal to the first resources, the resource application request of the first thread is reprocessed.
7. The thread resource management method according to any one of claims 1 to 6, characterized in that: The executing the first instruction and / or an instruction executed after the first instruction based on the first resource includes: After the first thread acquires the first resource, updating the execution state of the first thread from a first identifier to a second identifier; the first identifier indicates that the corresponding thread is in an inactive state, and the second identifier indicates that the corresponding thread is in an active state; Based on the dependency between the first resource and the instructions in the first thread, the first instruction and / or instructions executed after the first instruction are executed; the dependency represents the timing relationship between the instructions in the first thread and the resource usage of each instruction.
8. The thread resource management method according to claim 7, characterized in that: The executing the first instruction and / or an instruction executed after the first instruction based on the dependency relationship between the first resource and the instructions in the first thread includes: executing the first instruction based on the first resource; Based on the dependency relationship, determining whether the first instruction is the last instruction in the first thread that uses resources; When the first instruction is not the last instruction in the first thread that uses the resource, a next instruction executed after the first instruction is executed based on the first resource, and based on the dependency, it is determined whether the next instruction is the last instruction in the first thread that uses the resource, until all instructions executed after the first instruction are executed.
9. The thread resource management method according to claim 8, characterized in that: The thread resource management method also includes: When the first instruction is the last instruction in the first thread that uses a resource, releasing a first resource corresponding to the first thread; All instructions in the first thread that are executed after the first instruction are executed.
10. The thread resource management method according to claim 9, characterized in that: When the first instruction is the last instruction in the first thread that uses a resource, releasing the first resource corresponding to the first thread includes: When the first instruction is the last instruction in the first thread that uses a resource, adding a release mark to a field of the first instruction; When it is detected that the first instruction has been executed, generating a resource release request for the first thread; Based on the resource information in the resource release request of the first thread, the first resource is released.
11. The thread resource management method according to any one of claims 1 to 6, or 8 to 10, characterized in that: When executing a first instruction of a first thread corresponding to a graphics processing service in a streaming multiprocessor of a graphics processing chip, before determining whether the first instruction needs to use resources, the thread resource management method further includes: When processing the graphics processing service in the streaming multiprocessor, the multiple threads are organized according to the service type included in the graphics processing service and / or the execution codes of the multiple threads corresponding to the graphics processing service to obtain multiple thread groups; When any thread in any thread group meets the execution condition, the any thread is used as the first thread, and the instructions in the instruction sequence in the first thread are executed; the execution condition at least includes the data dependency and optimization dependency required by the corresponding thread before execution.
12. A thread resource management device, characterized in that: The thread resource management device comprises: A thread execution module, configured to determine whether a first instruction of a first thread corresponding to a graphics processing service needs to use resources when executing the first instruction in a streaming multiprocessor of a graphics processing chip; a resource management module, configured to allocate a first resource to the first thread when the first instruction needs to use a resource; The thread execution module is further configured to execute the first instruction and / or instructions executed after the first instruction based on the first resource.
13. The thread resource management method according to claim 12, characterized in that: The thread resource management device also includes: A thread component module, configured to organize the multiple threads according to the service types included in the graphics processing service and the execution codes of the multiple threads corresponding to the graphics processing service, so as to obtain multiple thread groups; Resource application detection module, used to detect resource application requests of threads; The resource release detection module is used to detect the resource release request of the thread.
14. A computer device comprising a memory and a processor, wherein the memory stores a computer program executable on the processor, wherein: When the processor executes the program, the steps of the method according to any one of claims 1 to 11 are implemented.
15. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 11 are implemented.
16. A computer program product, comprising a non-transitory computer-readable storage medium storing a computer program, wherein when the computer program is read and executed by a computer, the steps of the method according to any one of claims 1 to 11 are implemented.
Citation Information
Cited By
Resource application method of thread, processor, computer equipment and chip
CN119806830A
