Resource allocation method and apparatus, and electronic device and storage medium
By dynamically determining GPU usage time based on virtual machine task information and historical records, the problem of low utilization of shared GPU resources across multiple virtual machines is solved, achieving more efficient resource allocation and system performance optimization.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- SPREADTRUM COMMUNICATION (SHANGHAI) CO LTD
- Filing Date
- 2026-01-07
- Publication Date
- 2026-07-16
AI Technical Summary
In scenarios where multiple virtual machines share GPU resources, existing technologies result in consistent access times for each virtual machine when accessing the GPU, leading to low GPU resource utilization.
Based on the target virtual machine's task information and historical resource allocation records, determine the target virtual machine's required GPU usage time and send a resource allocation request to the resource allocation device to allocate GPU resources to the target virtual machine for the corresponding duration when the GPU is idle.
It improves GPU resource utilization by dynamically adjusting the duration of GPU usage by virtual machines, optimizing resource allocation, and enhancing system performance.
Smart Images

Figure CN2026071029_16072026_PF_FP_ABST
Abstract
Description
Resource allocation methods, devices, electronic equipment and storage media
[0001] This disclosure claims priority to Chinese Patent Application No. 202510042247.8, filed on January 9, 2025, entitled “Resource Allocation Method, Apparatus, Electronic Device and Storage Medium”, the entire contents of which are incorporated herein by reference. Technical Field
[0002] This disclosure relates to the field of computer technology, and in particular to a resource allocation method, apparatus, electronic device, and storage medium. Background Technology
[0003] Virtual machines can utilize the resources of a Graphics Processing Unit (GPU) to meet the operational requirements of different tasks. In some scenarios, multiple virtual machines can share a single GPU resource. Therefore, it is necessary to allocate GPU resources to multiple virtual machines.
[0004] In related technologies, for at least one virtual machine sharing the same GPU resource, the access duration for each virtual machine accessing the GPU is consistent. For any given virtual machine, when accessing the GPU, it sends an access request to the GPU hardware resource scheduling module. Upon receiving the access request, the GPU hardware resource scheduling module allocates GPU resources to the virtual machine within the access duration when the GPU is idle. Summary of the Invention
[0005] This disclosure provides a resource allocation method, apparatus, electronic device, and storage medium.
[0006] Firstly, this disclosure provides a resource allocation method, the method comprising:
[0007] Determine the target task to be processed by the target virtual machine, which shares the GPU resources with at least one other virtual machine;
[0008] Based on the target task, determine the target time that the target virtual machine requires to occupy the GPU;
[0009] Based on the target occupancy duration, a resource allocation request is sent to the resource allocation device corresponding to the GPU. The resource allocation request is used to request the allocation of GPU resources corresponding to the target occupancy duration for the target virtual machine.
[0010] In one possible implementation, the target virtual machine's required GPU usage time is determined based on the target task, including:
[0011] Obtain the task information of the target task, including the task size and the type of the target task;
[0012] Obtain multiple historical resource allocation records for the target virtual machine. The historical resource allocation records include historical task size, historical task type, historical GPU usage duration, and historical allocation time.
[0013] Determine the target duration based on task information and / or multiple historical resource allocation records.
[0014] In one possible implementation, determining the target duration based on task information includes:
[0015] The first duration of time is determined based on the task size and the first correspondence relationship. The first correspondence relationship includes multiple task size ranges and the duration of time corresponding to each task size range.
[0016] The target weight coefficient is determined based on the target task type and the second correspondence. The second correspondence includes multiple task types and the weight coefficient corresponding to each task type.
[0017] The target duration is determined by multiplying the first duration of occupation by the target weight coefficient.
[0018] In one possible implementation, the target occupancy duration is determined based on multiple historical resource allocation records, including:
[0019] Determine the execution time of the target task;
[0020] Determine the first time difference between the execution time and the start time of the current cycle;
[0021] For any historical resource allocation record, determine the second time difference between the historical allocation time in the historical resource allocation record and the start time of the corresponding period;
[0022] Based on the first time difference and the second time difference corresponding to each historical resource allocation record, at least one first allocation record is determined among multiple historical resource allocation records, and the difference between the second time difference and the first time difference corresponding to the first allocation record is less than or equal to a preset threshold.
[0023] The target usage duration is determined based on the historical GPU usage duration in at least one first allocation record.
[0024] In one possible implementation, the target duration is determined based on task information and multiple historical resource allocation records, including:
[0025] Determine the first feature vector corresponding to the task information;
[0026] For any historical resource allocation record, generate a second feature vector corresponding to the historical resource allocation record based on the historical task size and historical task type in the historical resource allocation record;
[0027] Based on the first feature vector and the second feature vector, at least one second allocation record is determined from multiple historical resource allocation records;
[0028] The target occupancy time is determined based on the historical GPU occupancy time in at least one second allocation record.
[0029] In one possible implementation, a resource allocation request is sent to the resource allocation device corresponding to the GPU based on the target occupancy duration, including:
[0030] Based on the target occupancy duration, a resource allocation request is generated, which includes the target occupancy duration.
[0031] Determine the target transmission method, which may be cross-domain communication or shared memory.
[0032] The resource allocation request is sent to the resource requesting device via the target transmission method.
[0033] In one possible implementation, the method further includes:
[0034] Receive the resource allocation response sent by the resource request device. The resource allocation response includes the target time period, and the duration of the target time period is the target occupancy duration.
[0035] During the target time period, the GPU is invoked to execute the target task.
[0036] Secondly, this disclosure provides a resource allocation device, comprising:
[0037] The determination module is used to determine the target task to be processed by the target virtual machine, which shares the resources of the graphics processing unit (GPU) with at least one other virtual machine.
[0038] The processing module is used to determine the target time that the target virtual machine needs to occupy the GPU, based on the target task.
[0039] The sending module is used to send a resource allocation request to the resource calling device corresponding to the GPU based on the target occupancy time. The resource allocation request is used to request the allocation of GPU resources corresponding to the target occupancy time for the target virtual machine.
[0040] In one possible implementation, the processing module can be used for:
[0041] Obtain the task information of the target task, including the task size and the type of the target task;
[0042] Obtain multiple historical resource allocation records for the target virtual machine. The historical resource allocation records include historical task size, historical task type, historical GPU usage duration, and historical allocation time.
[0043] Determine the target duration based on task information and / or multiple historical resource allocation records.
[0044] In one possible implementation, the processing module can be used for:
[0045] The first duration of time is determined based on the task size and the first correspondence relationship. The first correspondence relationship includes multiple task size ranges and the duration of time corresponding to each task size range.
[0046] The target weight coefficient is determined based on the target task type and the second correspondence. The second correspondence includes multiple task types and the weight coefficient corresponding to each task type.
[0047] The target duration is determined by multiplying the first duration of occupation by the target weight coefficient.
[0048] In one possible implementation, the processing module can be used for:
[0049] Determine the execution time of the target task;
[0050] Determine the first time difference between the execution time and the start time of the current cycle;
[0051] For any historical resource allocation record, determine the second time difference between the historical allocation time in the historical resource allocation record and the start time of the corresponding period;
[0052] Based on the first time difference and the second time difference corresponding to each historical resource allocation record, at least one first allocation record is determined among multiple historical resource allocation records, and the difference between the second time difference and the first time difference corresponding to the first allocation record is less than or equal to a preset threshold.
[0053] The target usage duration is determined based on the historical GPU usage duration in at least one first allocation record.
[0054] In one possible implementation, the processing module can be used for:
[0055] Determine the first feature vector corresponding to the task information;
[0056] For any historical resource allocation record, generate a second feature vector corresponding to the historical resource allocation record based on the historical task size and historical task type in the historical resource allocation record;
[0057] Based on the first feature vector and the second feature vector, at least one second allocation record is determined from multiple historical resource allocation records;
[0058] The target occupancy time is determined based on the historical GPU occupancy time in at least one second allocation record.
[0059] In one possible implementation, the sending module can be used to:
[0060] Based on the target occupancy duration, a resource allocation request is generated, which includes the target occupancy duration.
[0061] Determine the target transmission method, which may be cross-domain communication or shared memory.
[0062] The resource allocation request is sent to the resource requesting device via the target transmission method.
[0063] In one possible implementation, the device further includes:
[0064] Receive the resource allocation response sent by the resource request device. The resource allocation response includes the target time period, and the duration of the target time period is the target occupancy duration.
[0065] During the target time period, the GPU is invoked to execute the target task.
[0066] Thirdly, this disclosure provides an electronic device, including:
[0067] At least one processor; and
[0068] A memory that is communicatively connected to at least one processor; wherein,
[0069] The memory stores instructions that can be executed by at least one processor to cause the at least one processor to perform the resource allocation method involved in the first aspect and any possible implementation.
[0070] Fourthly, this disclosure provides a non-transitory computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions for causing a computer to perform the resource allocation method involved in the first aspect and any possible implementation.
[0071] Fifthly, this disclosure provides a computer program product, including a computer program that, when executed by a processor, implements the resource allocation method involved in the first aspect and any possible implementation.
[0072] In a sixth aspect, this disclosure provides a chip including at least one processor, the processor being configured to execute program instructions to perform the resource allocation method involved in the first aspect and any possible implementation. Attached Figure Description
[0073] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.
[0074] Figure 1 is a schematic diagram of application scenarios provided by some embodiments of this disclosure;
[0075] Figure 2 is a flowchart illustrating a resource allocation method provided in some embodiments of this disclosure;
[0076] Figure 3 is a schematic flowchart illustrating a process for determining the duration of a target occupancy according to some embodiments of this disclosure;
[0077] Figure 4 is a signaling diagram of a resource allocation method provided in some embodiments of this disclosure;
[0078] Figure 5 is a schematic diagram of the structure of a resource allocation device provided in some embodiments of this disclosure;
[0079] Figure 6 is a schematic diagram of the structure of an electronic device provided in some embodiments of this disclosure.
[0080] The accompanying drawings have illustrated specific embodiments of this disclosure, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concepts of this disclosure to those skilled in the art through reference to particular embodiments. Detailed Implementation
[0081] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.
[0082] The collection, storage, use, processing, transmission, provision, and disclosure of financial data or user data and other information involved in the technical solutions disclosed herein comply with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0083] It should be noted that in some embodiments of this disclosure, certain software, components, models and other existing solutions in the industry may be mentioned. These should be considered as exemplary and are intended only to illustrate the feasibility of implementing the technical solutions of this disclosure. However, they do not mean that the applicant has used or necessarily used such solutions.
[0084] To facilitate understanding, the following description, in conjunction with Figure 1, briefly explains the application scenarios to which some embodiments of this disclosure are applicable.
[0085] Figure 1 is a schematic diagram of application scenarios provided by some embodiments of this disclosure. Please refer to Figure 1, which includes a virtual machine 11, a resource access device 12, and a GPU 13.
[0086] In practical applications, virtual machine 11 can communicate with resource allocation device 12 through the hypervisor. For example, virtual machine 11 sends a resource allocation request to resource allocation device 12 through the hypervisor, and resource allocation device 12 sends a resource allocation response to virtual machine 11 through the hypervisor. Furthermore, resource allocation device 12 is responsible for allocating GPU 13 resources to virtual machine 11. For instance, after receiving a resource allocation request from virtual machine 11, resource allocation device 12 allocates GPU 13 resources to virtual machine 11 when GPU 13 is idle.
[0087] It should be noted that Figure 1 is only an example to illustrate one application scenario and is not a limitation on the application scenario.
[0088] In related technologies, virtual machines can share GPU resources in various ways, including shared access based on Graphics Application Programming Interface (API) forwarding, passthrough, hardware virtualization, and paravirtualization. The shared access method based on graphics API forwarding includes a graphics API server partition and a graphics API client partition. The graphics API server partition contains GPU hardware and graphics driver software, while the graphics API client partition contains graphics API forwarding software and graphics application software. When the graphics application software in the graphics API client partition needs to execute a graphics task, it calls the graphics API. After the graphics API forwarding software detects the call, it sends the graphics API to the graphics API server partition according to the agreed protocol. Upon receiving the graphics API, the graphics driver software parses and executes the graphics task, and returns the execution result to the graphics API client partition. However, in the above method, because of the need for forwarding graphics tasks between the graphics API client and the graphics API server, the large amount of data during forwarding can lead to high latency in task processing.
[0089] Hardware virtualization integrates a graphics virtualization manager onto the GPU, allowing administrators to configure multiple virtual GPUs. This configuration achieves hardware-level resource isolation between different GPU partitions. It's important to note that the operating principles of these virtual GPUs on the processor core are the same as those of a standalone GPU. However, this method requires a platform that supports GPU hardware virtualization.
[0090] The passthrough method involves setting up an external interconnect interface on the GPU device that can connect to virtual machines. In this case, the virtual machine can connect to the GPU device and access GPU resources through the external interconnect interface. However, in the above method, each GPU device can only be accessed by one virtual machine, which cannot enable multiple virtual machines to share the same GPU resources.
[0091] Paravirtualization modifies the guest operating system's graphics driver, enabling the virtual machine to interact directly with the hypervisor. The hypervisor then sends resource allocation requests to the resource allocation device, which allocates GPU resources to the virtual machine within a preset access duration when the GPU is idle. However, because the size and type of tasks performed by the virtual machine vary, the duration for which GPU resources are required also differs. Therefore, allocating GPU resources to the virtual machine within the preset access duration results in low GPU resource utilization.
[0092] Based on this, some embodiments of this disclosure provide a resource allocation method, apparatus, electronic device, and storage medium that determines the target time the target virtual machine needs to occupy the GPU based on the target task of the target virtual machine, and then sends a resource allocation request to a resource allocation device. When the GPU is idle, the resource allocation device allocates GPU resources corresponding to the target time to the target virtual machine, thereby improving the resource utilization of the GPU.
[0093] The technical solutions of this disclosure and how they solve the aforementioned technical problems will be described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of this disclosure will now be described with reference to the accompanying drawings.
[0094] Figure 2 is a flowchart illustrating a resource allocation method according to some embodiments of this disclosure. Referring to Figure 2, the method may include the following steps:
[0095] S21. Determine the target task to be processed by the target virtual machine. The target virtual machine shares GPU resources with at least one other virtual machine.
[0096] The execution entity of some embodiments of this disclosure can be a target virtual machine or a resource allocation device set in the target virtual machine. The resource allocation device can be implemented by software or by a combination of software and hardware.
[0097] The target virtual machine can be one of multiple virtual machines sharing GPU resources, and the duration of its GPU resource usage needs to be determined. The target task can be the task that the target virtual machine needs to process at the current moment.
[0098] For example, suppose the virtual machines sharing GPU resources are virtual machine 1, virtual machine 2, and virtual machine 3. Virtual machine 1 currently needs to process task A, virtual machine 2 needs to process task B, and virtual machine 3 needs to process task C. If the target virtual machine is virtual machine 1, then the target task to be processed by the target virtual machine is determined to be task A.
[0099] S22. Based on the target task, determine the target time that the target virtual machine needs to occupy the GPU.
[0100] The target duration is the amount of GPU resources required by the target virtual machine to process the target task. Target duration can be measured in microseconds, nanoseconds, milliseconds, etc.
[0101] The time a target virtual machine (VM) needs to utilize GPU resources varies depending on the size of the target task and its usage scenario. In other words, the time required to utilize GPU resources differs depending on the target task. Generally, the larger the target task, the longer the time the VM needs to utilize GPU resources; conversely, the more demanding the usage scenario, the longer the time required. Ultimately, the required time to utilize GPU resources can be determined by considering various factors, including the size of the target task and its usage scenario.
[0102] For example, for Task A and Task B, suppose Task A is used in an in-vehicle device, the task type is video rendering, and the task size is 30MB; Task B is used in a wearable device, the task type is page switching, and the task size is 2MB. When the target task is Task A, the target virtual machine's required GPU time is determined to be 20 nanoseconds; when the target task is Task B, the target virtual machine's required GPU time is determined to be 10 microseconds.
[0103] S23. Based on the target occupancy duration, send a resource allocation request to the resource access device corresponding to the GPU. The resource allocation request is used to request the allocation of GPU resources corresponding to the target occupancy duration for the target virtual machine.
[0104] The resource allocation device corresponding to the GPU is used to invoke and allocate GPU resources. Upon receiving a resource allocation request from a virtual machine, the resource allocation device allocates GPU resources corresponding to the target duration of GPU usage to the target virtual machine. For example, for virtual machines 1 and 2, virtual machine 1 requires a target duration of M on the GPU, and virtual machine 2 requires a target duration of N on the GPU. When the resource allocation device receives a resource allocation request from virtual machine 1, it allocates GPU resources corresponding to the target duration M for virtual machine 1; when it receives a resource allocation request from virtual machine 2, it allocates GPU resources corresponding to the target duration N for virtual machine 2.
[0105] The resource allocation method provided in some embodiments of this disclosure first determines the target task to be processed by the target virtual machine, and then determines the target time required by the target virtual machine to occupy the GPU based on the target task. Next, a resource allocation request is sent to the resource allocation device corresponding to the GPU, requesting the resource allocation device to allocate GPU resources corresponding to the target time to the target virtual machine. Through this method, the target virtual machine determines the target time required by the GPU to process the target task, and then requests the resource allocation device to allocate GPU resources corresponding to the target time, thereby improving the resource utilization of the GPU.
[0106] Based on the embodiment shown in Figure 2, the process of determining the target virtual machine's required GPU usage time according to the target task will be described in detail below with reference to Figure 3.
[0107] Figure 3 is a flowchart illustrating a method for determining the target duration according to some embodiments of this disclosure. Referring to Figure 3, the method may include the following steps:
[0108] S31. Obtain the task information of the target task, which includes the task size and the type of the target task.
[0109] Task information represents relevant information about the target task. Task size can be the size of the target task itself; for example, if the target task size is 3MB, then the target task size is 3MB. Target task type represents the use case and task category of the target task. For example, if task A is used in wearable devices and its task category is page rendering, and task B is used in in-vehicle devices and its task category is video rendering, then when the target task is task A, the target task type is a page rendering task for wearable devices; when the target task is task B, the target task type is a video rendering task for in-vehicle devices.
[0110] S32. Obtain multiple historical resource allocation records of the target virtual machine. The historical resource allocation records include historical task size, historical task type, historical GPU usage time, and historical allocation time.
[0111] Multiple historical resource allocation records are used to represent multiple historical tasks for the target virtual machine, including task information for each historical task, as well as the duration and timing of GPU resource allocation for each historical task.
[0112] For any one of the multiple historical tasks of the target virtual machine, the size of the historical task is the size of the historical task, the historical task type is used to indicate the use case and task category of the historical task, the historical GPU usage time is used to indicate the duration of GPU resource usage by the target virtual machine when executing the historical task, and the historical allocation time is used to indicate the moment when the resource calling device allocates GPU resources to the target virtual machine when executing the historical task.
[0113] For example, suppose the target virtual machine has multiple historical tasks, namely Task A, Task B, and Task C. Task A has a historical task size of 10MB, a historical task type of video rendering for in-vehicle devices, a historical GPU usage time of 10 microseconds, and a historical allocation time of time X. Task B has a historical task size of 2MB, a historical task type of page rendering for wearable devices, a historical GPU usage time of 3 microseconds, and a historical allocation time of time Y. Task C has a historical task size of 5MB, a historical task type of page rendering for mobile devices, a historical GPU usage time of 7 microseconds, and a historical allocation time of time Z.
[0114] The target virtual machine's multiple historical resource allocation records can be seen in Table 1:
[0115] Table 1
[0116] S33. Determine the target duration based on task information and / or multiple historical resource allocation records.
[0117] The method for determining the target duration based on task information is as follows: Determine the first duration based on the task size and the first correspondence, which includes multiple task size ranges and the duration corresponding to each task size range; determine the target weight coefficient based on the target task type and the second correspondence, which includes multiple task types and the weight coefficient corresponding to each task type; and determine the target duration by multiplying the first duration and the target weight coefficient.
[0118] The task size range can be a preset range, such as 0-5MB, 5-10MB, 10-15MB, etc. The first correspondence is used to represent the duration of the target task located in different task size ranges. The first duration is determined based on the target task size and the first correspondence, and is used to represent the duration of the target task corresponding to its size. The second correspondence is used to represent the weight coefficients corresponding to different task types.
[0119] First, based on the size of the target task, the task size range corresponding to the target task can be determined from multiple task size ranges in the first correspondence relationship. Then, the first occupied time corresponding to the target task can be determined. The first occupied time is the occupied time corresponding to the task size range of the target task in the first correspondence relationship.
[0120] Then, based on the target task type of the target task, among the multiple task types in the second correspondence, the task type that is the same as the target task type is determined, and then the target weight coefficient corresponding to the target task type is determined. The target weight coefficient is the weight coefficient corresponding to the task type that is the same as the target task type in the second correspondence.
[0121] Finally, the first duration of the target task is multiplied by the target weight coefficient to obtain the target duration of the target task.
[0122] For example, assuming the target task size is 15MB and the target task type is a video rendering task for in-vehicle devices, the first correspondence includes task size ranges of 0-10MB, 10-20MB, and 20-30MB. The task size range of 0-10MB corresponds to a duration of 10 microseconds, the task size range of 10-20MB corresponds to a duration of 20 microseconds, and the task size range of 20-30MB corresponds to a duration of 30 microseconds. The second correspondence includes multiple task types: video rendering task for in-vehicle devices, page rendering task for in-vehicle devices, and page rendering task for wearable devices. The weight coefficient for video rendering task for in-vehicle devices is 50%, for page rendering task for in-vehicle devices is 30%, and for page rendering task for wearable devices is 20%.
[0123] Based on the target task's size, within the multiple task size ranges in the first correspondence, the target task's corresponding task size range is determined to be 10-20MB. Therefore, the first occupancy time for the target task is determined to be 20 microseconds, corresponding to the 10-20MB range in the first correspondence. Next, based on the target task's type, within the multiple task types in the second correspondence, a task type identical to the target task type is determined: a video rendering task for in-vehicle devices. Therefore, the target weight coefficient is determined to be 50% for a video rendering task for in-vehicle devices in the second correspondence. Finally, the first occupancy time of 20 microseconds is multiplied by the target weight coefficient of 50%, resulting in a target occupancy time of 10 microseconds.
[0124] The above method describes a method for determining the target duration based on task information. In addition, the target duration can also be determined based on multiple historical resource allocation records, as follows: Determine the execution time of the target task; determine the first time difference between the execution time and the start time of the current period; for any historical resource allocation record, determine the second time difference between the historical allocation time in the historical resource allocation record and the start time of the corresponding period; based on the first time difference and the second time difference corresponding to each historical resource allocation record, determine at least one first allocation record among the multiple historical resource allocation records, where the difference between the second time difference and the first time difference corresponding to the first allocation record is less than or equal to a preset threshold; determine the target duration based on the historical GPU duration in at least one first allocation record.
[0125] The execution time of the target task is the start time when the target virtual machine begins processing the target task. Assuming a day is a cycle, the current cycle can be the day the target virtual machine processes the target task, and the start time of the current cycle can be the start time of that day. The first time difference is the time difference between the execution time of the target task and the start time of the current cycle; this first time difference represents the relative position of the target task within the current cycle.
[0126] Assuming a period of one day, for any historical resource allocation record, the corresponding period can be defined as the day on which the target virtual machine processes the historical task corresponding to that historical resource allocation record. The start time of the corresponding period can be defined as the start time of the day on which the target virtual machine processes that historical task. The second time difference can be defined as the time difference between the historical allocation time and the start time of the corresponding period. The second time difference is used to represent the relative position of the historical task within the corresponding period.
[0127] At least one first allocation record can be a historical resource allocation record in which the difference between the first time difference and the second time difference is less than or equal to a preset threshold among multiple historical resource allocation records, that is, the time characteristics of the historical task corresponding to at least one first allocation record are similar to the time characteristics of the target task.
[0128] The target occupancy time can be determined by calculating the average, median, maximum or minimum value of the historical GPU occupancy time in at least one first allocation record, and using it as the target occupancy time.
[0129] In summary, methods for determining target occupancy duration based on task information or multiple historical resource allocation records have been introduced. Furthermore, in one possible implementation, the target occupancy duration can be determined based on the task information of the target task and multiple historical resource allocation records. This method can be as follows: determine a first feature vector corresponding to the task information; for any historical resource allocation record, generate a second feature vector corresponding to the historical resource allocation record based on the historical task size and type in the historical resource allocation record; determine at least one second allocation record among the multiple historical resource allocation records based on the first and second feature vectors; and determine the target occupancy duration based on the historical GPU occupancy duration in the at least one second allocation record.
[0130] The first feature vector includes the target task size and target task type. The target task type can be represented in numerical form. For example, assuming a task for an in-vehicle device is represented as 1, a task for a wearable device as 2, a task for a mobile device as 3, a video rendering task as 0, and a page rendering task as 1, then when the target task type is a video rendering task for an in-vehicle device, the target task type can be represented as 1-0; when the target task type is a page rendering task for a wearable device, the target task type can be represented as 2-1; and when the target task type is a page rendering task for a mobile device, the target task type can be represented as 3-1.
[0131] For example, assuming the target task size is 20MB and the target task type is a video rendering task for in-vehicle devices, the first feature vector can be [20, 1-0], where 20 represents the target task size of 20MB, 1-0 represents the target task type, and 1 in 1-0 represents the target task's usage scenario as an in-vehicle device, and 0 represents the target task's task category as a video rendering task.
[0132] For any historical resource allocation record, the corresponding second feature vector includes the historical task size and historical task type. The representation of the historical task size and historical task type in the second feature vector is consistent with the representation of the task size and target task type in the first feature vector. It should be noted that the position of the historical task size in the second feature vector is consistent with the position of the task size in the first feature vector; the position of the historical task type in the second feature vector is consistent with the position of the target task type in the first feature vector. For example, assuming the first feature vector is [20, 1-0], where 20 represents the target task size of 20MB, 1-0 represents the target task type, the historical task size is 10MB, and the historical task type is represented as 2-1, then the second feature vector can be represented as [10, 2-1]. The second allocation record is the historical resource allocation record among multiple historical resource allocation records whose second feature vector matches the first feature vector.
[0133] First, based on the task information of the target task, a first feature vector corresponding to the target task is determined. Then, for multiple historical resource allocation records of the target virtual machine, a second feature vector is determined for each historical resource allocation record based on its historical task size and type. The first feature vector is matched with the second feature vector, and the historical resource allocation record corresponding to the second feature vector that matches the first feature vector is determined as the second allocation record, thus obtaining at least one second allocation record. The average, median, maximum, or minimum historical GPU usage time, and other relevant parameters of the at least one second allocation record are calculated and determined as the target usage time.
[0134] For example, assuming the target task information is: task size is 2MB, target task type is page rendering task for wearable devices, the first feature vector corresponding to the target task is determined to be [2, 2-1], where 2 represents the task size, 2-1 represents the target task type, and in 2-1, 2 indicates the usage scenario is for wearable devices, and 1 indicates the task category is page rendering task. Multiple historical resource allocation records of the target virtual machine can be shown in Table 2:
[0135] Table 2
[0136] Based on the historical task size and type corresponding to each historical resource allocation record from multiple historical resource allocation records, the second feature vector corresponding to the historical resource allocation record of task A is determined to be [10, 1-0], where 10 represents the historical task size of task A, 1-0 represents the historical task type of task A, and in 1-0, 1 indicates the usage scenario is for vehicle-mounted equipment, and 0 indicates the task category is video rendering task; the second feature vector corresponding to the historical resource allocation record of task B is [2, 2-1], where 2 represents the historical task size of task B, 2-1 represents the historical task type of task B, and in 2-1, 2 indicates the usage scenario is for vehicle-mounted equipment. For wearable devices, 1 indicates that the task category is page drawing task; the second feature vector corresponding to the historical resource allocation record of task C is [5, 3-1], where 5 represents the historical task size of task C, 3-1 represents the historical task type of task C, and 3 in 3-1 indicates that the usage scenario is for mobile devices, and 1 indicates that the task category is page drawing task; the second feature vector corresponding to the historical resource allocation record of task D is [2, 2-1], where 2 represents the historical task size of task B, 2-1 represents the historical task type of task B, and 2 in 2-1 indicates that the usage scenario is for wearable devices, and 1 indicates that the task category is page drawing task.
[0137] The first feature vector is matched with the second feature vectors corresponding to the historical resource allocation records of tasks A, B, C, and D, respectively. The second feature vectors that match the first feature vector are the second feature vectors corresponding to the historical allocation records of tasks B and D. Therefore, the second allocation record is determined to be the historical allocation record of tasks B and D. The average historical GPU usage time in the second allocation record is calculated to be (3+5) / 2 = 4 microseconds. Therefore, the target usage time is determined to be 4 microseconds.
[0138] In the embodiment shown in Figure 3, the target duration can be determined based on the target task's size, target task type, a first correspondence, and a second correspondence; or, based on the first time difference between the target task's execution time and the current start time, and the second time difference between the historical allocation time of each historical resource allocation record and the start time of the corresponding period in multiple historical resource allocation records, a first allocation record with similar time characteristics to the target task can be determined, and the target duration can be determined based on the historical GPU duration in the first allocation record; or, based on the target task's size and target task type, at least one second allocation record matching the target task's size and target task type can be determined from multiple historical resource allocation records, and the target duration can be determined based on the historical GPU duration in the second allocation record. Through these methods, the target duration can be determined using different approaches based on the target task's task information and / or multiple historical resource allocation records, improving the accuracy of determining the target virtual machine's required GPU duration and thus improving GPU resource utilization.
[0139] The above embodiments introduced resource allocation methods and methods for determining target occupancy durations provided by some embodiments of this disclosure. The resource allocation process will be further explained below with reference to Figure 4 through specific embodiments.
[0140] Figure 4 is a signaling diagram of a resource allocation method provided in some embodiments of this disclosure. Referring to Figure 4, the method may include the following steps:
[0141] S41. Determine the target task to be processed in the target virtual machine.
[0142] For a detailed description of this step, please refer to S21 in the embodiment shown in Figure 2, which will not be repeated here.
[0143] S42. Based on the target task, determine the target time that the target virtual machine needs to occupy the GPU.
[0144] For a detailed description of this step, please refer to the embodiment shown in Figure 3, which will not be repeated here.
[0145] It should be noted that, in addition to the method described in the embodiment shown in Figure 3, other methods can be used to determine the target virtual machine's required GPU time. This disclosure does not limit the method for determining the target time.
[0146] S43. Generate a resource allocation request based on the target occupancy duration. The resource allocation request includes the target occupancy duration.
[0147] A resource allocation request is used to request the allocation of GPU resources corresponding to the target virtual machine's usage duration.
[0148] For example, assuming the target duration is 7 microseconds, a resource allocation request is generated based on the target duration. This resource allocation request includes 7 microseconds and is used to request the allocation of GPU resources corresponding to 7 microseconds to the target virtual machine.
[0149] S44. Determine the target transmission method, which is either cross-domain communication or shared memory.
[0150] When determining the target transmission method, it is usually necessary to select an appropriate transmission method based on factors such as the specific application scenario, data transmission requirements, and performance requirements. Cross-domain communication is typically used for data transmission between different thresholds or different processes. This method is suitable for scenarios that require communication between different security thresholds, network nodes, or processes. Shared memory is suitable for communication between different processes on the same machine. This method allows multiple processes to access a unified block of memory, thereby achieving fast data exchange.
[0151] S45. Send a resource allocation request to the resource calling device via the target transmission method.
[0152] The target virtual machine sends a resource allocation request to the resource calling device in the following way: according to the target transmission method, the virtual machine hypervisor sends a resource allocation request to the resource calling device.
[0153] For example, assuming the target transmission method is cross-domain communication, the target virtual machine sends a resource allocation request to the resource calling device through the virtual machine hypervisor according to the cross-domain communication method.
[0154] S46. Receive the resource allocation response sent by the resource calling device. The resource allocation response includes the target time period, and the duration of the target time period is the target occupancy duration.
[0155] The resource allocation response is the information provided in response to the resource allocation request, indicating that the target virtual machine can access GPU resources within the target time period. The start time of the target time period is the moment when the resource requesting device sends the resource allocation response, and the end time of the target time period is the duration between the start time and the end time, which is the target usage time.
[0156] After receiving a resource allocation request from the target virtual machine, the resource allocation device monitors the status of the GPU. If the GPU is idle, it sends a resource allocation response to the target virtual machine, indicating that the target virtual machine can access GPU resources from the start time of the target time period for the target duration.
[0157] S47. During the target time period, invoke the GPU to execute the target task.
[0158] After receiving the resource allocation response, the target virtual machine accesses GPU resources and uses them to execute the target task within the target time period.
[0159] For example, suppose the target time period starts at time X and lasts for 5 microseconds. After receiving the resource allocation response, the target virtual machine accesses GPU resources within the target time period and uses those resources to execute the target task.
[0160] In the embodiment shown in Figure 4, the target task to be processed in the target virtual machine is first determined, and the target time period required by the target virtual machine to access the GPU is determined based on the target task. Then, a resource allocation request is generated based on the target time period, and the target transmission method is determined based on factors such as the specific application scenario and data transmission requirements. Then, based on the target transmission method, the resource allocation request is sent to the resource invocation device through the hypervisor. Finally, the resource allocation response sent by the resource invocation device is received, and the GPU resources are accessed and the target task is executed within the target time period. In the above method, the target time period is determined based on the target task, and when the GPU is idle, the GPU resources are accessed within the target time period with the target time period as the duration, and the target task is executed using the GPU resources, thereby improving the resource utilization of the GPU.
[0161] Figure 5 is a schematic diagram of the structure of a resource allocation device provided in some embodiments of this disclosure. As shown in Figure 5, the resource allocation device 50 includes a determining module 51, a processing module 52, and a sending module 53, wherein...
[0162] The determination module 51 is used to determine the target task to be processed by the target virtual machine, which shares the resources of the image processor GPU with at least one other virtual machine.
[0163] Processing module 52 is used to determine the target time that the target virtual machine needs to occupy the GPU based on the target task;
[0164] The sending module 53 is used to send a resource allocation request to the resource calling device corresponding to the GPU according to the target occupancy time. The resource allocation request is used to request the allocation of GPU resources corresponding to the target occupancy time for the target virtual machine.
[0165] In one possible implementation, the processing module 52 can be used for:
[0166] Obtain the task information of the target task, including the task size and the type of the target task;
[0167] Obtain multiple historical resource allocation records for the target virtual machine. The historical resource allocation records include historical task size, historical task type, historical GPU usage duration, and historical allocation time.
[0168] Determine the target duration based on task information and / or multiple historical resource allocation records.
[0169] In one possible implementation, the processing module 52 can be used for:
[0170] The first duration of time is determined based on the task size and the first correspondence relationship. The first correspondence relationship includes multiple task size ranges and the duration of time corresponding to each task size range.
[0171] The target weight coefficient is determined based on the target task type and the second correspondence. The second correspondence includes multiple task types and the weight coefficient corresponding to each task type.
[0172] The target duration is determined by multiplying the first duration of occupation by the target weight coefficient.
[0173] In one possible implementation, the processing module 52 can be used for:
[0174] Determine the execution time of the target task;
[0175] Determine the first time difference between the execution time and the start time of the current cycle;
[0176] For any historical resource allocation record, determine the second time difference between the historical allocation time in the historical resource allocation record and the start time of the corresponding period;
[0177] Based on the first time difference and the second time difference corresponding to each historical resource allocation record, at least one first allocation record is determined among multiple historical resource allocation records, and the difference between the second time difference and the first time difference corresponding to the first allocation record is less than or equal to a preset threshold.
[0178] The target usage duration is determined based on the historical GPU usage duration in at least one first allocation record.
[0179] In one possible implementation, the processing module 52 can be used for:
[0180] Determine the first feature vector corresponding to the task information;
[0181] For any historical resource allocation record, generate a second feature vector corresponding to the historical resource allocation record based on the historical task size and historical task type in the historical resource allocation record;
[0182] Based on the first feature vector and the second feature vector, at least one second allocation record is determined from multiple historical resource allocation records;
[0183] The target occupancy time is determined based on the historical GPU occupancy time in at least one second allocation record.
[0184] In one possible implementation, the sending module 53 can be used for:
[0185] Based on the target occupancy duration, a resource allocation request is generated, which includes the target occupancy duration.
[0186] Determine the target transmission method, which may be cross-domain communication or shared memory.
[0187] The resource allocation request is sent to the resource requesting device via the target transmission method.
[0188] In one possible implementation, the device further includes:
[0189] Receive the resource allocation response sent by the resource request device. The resource allocation response includes the target time period, and the duration of the target time period is the target occupancy duration.
[0190] During the target time period, the GPU is invoked to execute the target task.
[0191] The resource allocation apparatus provided in some embodiments of this disclosure can execute the technical solutions of the resource allocation methods in the above method embodiments, and will not be described in detail here.
[0192] Figure 6 is a schematic diagram of the structure of an electronic device provided in some embodiments of this disclosure. The electronic device 60 includes:
[0193] At least one processor 62; and
[0194] Memory 61 is communicatively connected to at least one processor 62; wherein,
[0195] The memory 61 stores instructions that can be executed by at least one processor 62, which in turn executes the resource allocation method described in the above method embodiments.
[0196] Optionally, the processor mentioned above can be a central processing unit (CPU), or it can be a GPU, other general-purpose processors, digital signal processors (DSPs), or application-specific integrated circuits (ASICs), etc. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in some embodiments of this disclosure can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules in the processor.
[0197] All embodiments of this disclosure can be executed individually or in combination with other embodiments, and are all considered to be within the scope of protection claimed by this disclosure.
[0198] The electronic device 60 provided in some embodiments of this disclosure can execute the resource allocation method involved in the above method embodiments, which will not be repeated here.
[0199] Some embodiments of this disclosure provide a non-transitory computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions for causing a computer to perform the resource allocation method involved in the above method embodiments.
[0200] Some embodiments of this disclosure provide a computer program product, including a computer program that, when executed by an electronic device, implements the resource allocation method involved in the above-described method embodiments.
[0201] Some embodiments of this disclosure provide a chip, the chip including at least one processor, the processor being configured to run program instructions to perform the resource allocation method in the above method embodiments.
[0202] Some embodiments of this disclosure provide a chip module on which a computer program is stored. When the computer program is executed by the chip module, it implements the resource allocation method in the above method embodiments.
[0203] All or part of the steps in the above-described method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a readable memory. When the program is executed, it performs the steps of the above-described method embodiments; and the aforementioned memory (storage medium) includes: read-only memory (ROM), RAM, flash memory, hard disk, solid-state drive, magnetic tape, floppy disk, optical disk, and any combination thereof.
[0204] Some embodiments of this disclosure are described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to some embodiments of this disclosure. It will 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 program instructions. These computer program instructions can be provided to a processing unit of a general-purpose computer, special-purpose computer, embedded processor, or other programmable terminal device to produce a machine, such that the instructions, which execute via the processing unit of the computer or other programmable terminal device, create means for implementing the functions specified in one or more flowchart illustrations and / or one or more block diagrams.
[0205] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable terminal device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means that implement the functions specified in one or more flowcharts and / or one or more block diagrams.
[0206] These computer program instructions may also be loaded onto a computer or other programmable terminal equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, such that the instructions, which execute on the computer or other programmable equipment, provide steps for implementing the functions specified in one or more flowcharts and / or one or more block diagrams.
[0207] Obviously, those skilled in the art can make various modifications and variations to some embodiments of this disclosure without departing from the spirit and scope of this disclosure. Therefore, if such modifications and variations to some embodiments of this disclosure fall within the scope of the claims of this disclosure and their equivalents, this disclosure also intends to include such modifications and variations.
[0208] Those skilled in the art will understand that all or part of the steps of the above-described method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments; and the aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.
[0209] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this disclosure, and are not intended to limit them. Although this disclosure has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this disclosure.
Claims
1. A resource allocation method, characterized in that, include: The target task to be processed by the target virtual machine is determined, wherein the target virtual machine shares the resources of the graphics processing unit (GPU) with at least one other virtual machine; Based on the target task, determine the target time that the target virtual machine requires to occupy the GPU; Based on the target occupancy duration, a resource allocation request is sent to the resource allocation device corresponding to the GPU. The resource allocation request is used to request the allocation of GPU resources corresponding to the target occupancy duration for the target virtual machine.
2. The method according to claim 1, characterized in that, Based on the target task, determine the target time that the target virtual machine requires to occupy the GPU, including: Obtain the task information of the target task, the task information including the task size and the target task type; Obtain multiple historical resource allocation records of the target virtual machine, wherein the historical resource allocation records include historical task size, historical task type, historical GPU usage duration, and historical allocation time; The target occupancy duration is determined based on the task information and / or the multiple historical resource allocation records.
3. The method according to claim 2, characterized in that, Based on the task information, the duration of the target's occupation is determined, including: The first duration of occupation is determined based on the task size and the first correspondence relationship, wherein the first correspondence relationship includes multiple task size ranges and the duration of occupation corresponding to each task size range; Based on the target task type and the second correspondence, the target weight coefficient is determined. The second correspondence includes multiple task types and the weight coefficient corresponding to each task type. The product of the first occupied time and the target weight coefficient is determined as the target occupied time.
4. The method according to claim 2, characterized in that, Based on the multiple historical resource allocation records, the target occupancy duration is determined, including: Determine the execution time of the target task; Determine the first time difference between the execution time and the start time of the current cycle; For any historical resource allocation record, determine the second time difference between the historical allocation time in the historical resource allocation record and the start time of the corresponding period; Based on the first time difference and the second time difference corresponding to each historical resource allocation record, at least one first allocation record is determined among the plurality of historical resource allocation records, wherein the difference between the second time difference corresponding to the first allocation record and the first time difference is less than or equal to a preset threshold. The target occupancy time is determined based on the historical GPU occupancy time in at least one first allocation record.
5. The method according to claim 2, characterized in that, Based on the task information and the multiple historical resource allocation records, the target occupancy duration is determined, including: Determine the first feature vector corresponding to the task information; For any historical resource allocation record, a second feature vector corresponding to the historical resource allocation record is generated based on the historical task size and historical task type in the historical resource allocation record; Based on the first feature vector and the second feature vector, at least one second allocation record is determined from the plurality of historical resource allocation records; The target occupancy time is determined based on the historical GPU occupancy time in the at least one second allocation record.
6. The method according to any one of claims 1-5, characterized in that, Based on the target occupancy duration, a resource allocation request is sent to the resource allocation device corresponding to the GPU, including: The resource allocation request is generated based on the target occupancy duration, and the resource allocation request includes the target occupancy duration. Determine the target transmission method, which is either cross-domain communication or shared memory. The resource allocation request is sent to the resource calling device via the target transmission method.
7. The method according to any one of claims 1-6, characterized in that, The method further includes: Receive a resource allocation response sent by the resource calling device, wherein the resource allocation response includes a target time period, and the duration of the target time period is the target occupancy duration; During the target time period, the GPU is invoked to execute the target task.
8. A resource allocation device, characterized in that, include: A determination module is used to determine the target task to be processed by the target virtual machine, wherein the target virtual machine shares the resources of the image processor GPU with at least one other virtual machine; The processing module is configured to determine the target time that the target virtual machine requires to occupy the GPU based on the target task; The sending module is used to send a resource allocation request to the resource calling device corresponding to the GPU based on the target occupancy time. The resource allocation request is used to request the allocation of GPU resources corresponding to the target occupancy time for the target virtual machine.
9. An electronic device, characterized in that, include: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to cause the at least one processor to perform the resource allocation method according to any one of claims 1 to 7.
10. A non-transitory computer-readable storage medium, characterized in that, in, The computer-readable storage medium stores computer-executable instructions for causing a computer to perform the resource allocation method according to any one of claims 1 to 7.
11. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the resource allocation method according to any one of claims 1 to 7.
12. A chip comprising at least one processor for executing program instructions to perform the resource allocation method of any one of claims 1 to 7.