A general-purpose graphics processor virtualization method and system
By adding GPU front-end and back-end drivers in virtual machines and physical machines, and utilizing shared memory zero-copy and time-sharing scheduling technologies, the problems of low efficiency and reliance on hardware virtualization in existing GPU virtualization solutions are solved, and efficient and universal GPU virtualization functions are realized.
Patent Information
- Application Number
- CN202311148059.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-06
- Publication Date
- 2025-12-12
- Estimated Expiration
- 2043-09-06
AI Technical Summary
Existing GPU virtualization solutions suffer from low command forwarding efficiency and reliance on specific hardware virtualization modules.
By adding a GPU front-end driver in the virtual machine and a GPU back-end driver in the physical machine, graphics commands are forwarded in a zero-copy manner using shared memory, and GPU time-sharing scheduling technology is adopted to avoid relying on hardware virtualization support.
It achieves efficient GPU virtualization without requiring modifications to existing applications, is highly adaptable and versatile, improves virtualization efficiency, and ensures fair use of multiple virtual machines.
Smart Images

Figure CN117290052B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application belongs to the technical field of virtualization, and more particularly relates to a general-purpose graphics processor virtualization method and system. BACKGROUND
[0002] Virtualization technology in the field of computers generally refers to a resource management scheme in which physical machine resources are split and reused for virtual machines. By abstracting and simulating various physical resources (CPU, graphics processor, disk space, memory, etc.) of a computer, the resources are split or combined into one or more computer configuration environments (mainly virtual machines), so as to break the non-cutting barrier between physical structures and achieve the purpose of efficient and convenient sharing of computer hardware resources by multiple users (mainly multiple virtual machines).
[0003] At present, cloud computing applications and environments represented by virtualization technology are developing rapidly, and heterogeneous computing systems represented by CPU+GPU (graphics processing units) have become the key to the development of virtualization technology. CPU virtualization is currently relatively mature. GPU virtualization methods, however, have started relatively late, and the actual GPU virtualization schemes mainly include application layer forwarding or GPU slicing supported by hardware virtualization modules, which have problems such as low forwarding command efficiency and dependence on specific hardware virtualization modules. SUMMARY
[0004] In view of the defects of the prior art, the purpose of the present application is to provide a general-purpose graphics processor virtualization method and system, which aims to solve the problems of low forwarding command efficiency and dependence on specific hardware virtualization modules in existing GPU virtualization schemes.
[0005] To achieve the above-mentioned purpose, in a first aspect, the present application provides a general-purpose graphics processor virtualization method, which is applied to a physical machine, the physical machine comprising a plurality of virtual machines, a GPU backend driver, a graphics framework provided with a GPU driver, and a GPU; each virtual machine comprising a graphics application and a GPU frontend driver.
[0006] The method comprises the following steps:
[0007] Step S101: The graphics application of any virtual machine receives a graphics command sent by a CPU.
[0008] Step S102: The GPU frontend driver of the any virtual machine captures the graphics command of the graphics application and writes the graphics command into a ring queue of a shared memory; the shared memory is applied for by the GPU frontend driver in an initialization process.
[0009] In step S103, the GPU back-end driver reads the graphics commands in the ring queue of the shared memory in a zero-copy manner, and calls the graphics framework to operate the GPU driver to make the GPU execute the graphics commands.
[0010] In an optional example, the GPU front-end driver writes the graphics commands into the ring queue of the shared memory in step S102, specifically including:
[0011] The GPU front-end driver writes the graphics commands into the space corresponding to the front-end flag bit in the ring queue, and after the writing succeeds, the front-end flag bit after being incremented is taken as the updated front-end flag bit.
[0012] Correspondingly, the GPU back-end driver reads the graphics commands in the ring queue of the shared memory in a zero-copy manner in step S103, specifically including:
[0013] The GPU back-end driver reads the graphics commands from the space corresponding to the back-end flag bit in the ring queue, and after the reading succeeds, the back-end flag bit after being incremented is taken as the updated back-end flag bit; the initial value of the back-end flag bit is the same as that of the front-end flag bit.
[0014] In an optional example, the ring queue specifically stores the pointers of the graphics commands.
[0015] In an optional example, the GPU front-end driver of any virtual machine includes a scheduling controller, and the GPU back-end driver includes a scheduling monitor.
[0016] The method further includes:
[0017] The scheduling monitor calculates the frame period required by the graphics commands based on the graphics frame rate.
[0018] The scheduling monitor sends the frame period to the scheduling controller.
[0019] The scheduling controller controls the time when the graphics commands are written into the ring queue based on the frame period, to realize the allocation of the time when the GPU is used by any virtual machine.
[0020] In a second aspect, the application provides a general-purpose graphics processor virtualization system, including a CPU and a physical machine, the physical machine including a plurality of virtual machines, a GPU back-end driver, a graphics framework provided with a GPU driver, and a GPU; each virtual machine including a graphics application and a GPU front-end driver.
[0021] The graphics application of any virtual machine is configured to receive the graphics commands sent by the CPU.
[0022] The GPU front-end driver of any virtual machine is configured to capture graphics commands of a graphics application and write the graphics commands into a ring queue of a shared memory;
[0023] The GPU back-end driver is configured to read the graphics commands in the ring queue of the shared memory in a zero-copy manner and invoke a graphics framework to operate a GPU driver so that the GPU executes the graphics commands.
[0024] In an optional example, the GPU front-end driver of any virtual machine is specifically configured to write the graphics commands into a space corresponding to the front-end flag bit in the ring queue and, after the writing succeeds, take the front-end flag bit after being incremented as an updated front-end flag bit.
[0025] Correspondingly, the GPU back-end driver is specifically configured to read the graphics commands from a space corresponding to the back-end flag bit in the ring queue and, after the reading succeeds, take the back-end flag bit after being incremented as an updated back-end flag bit; the initial value of the back-end flag bit is the same as that of the front-end flag bit.
[0026] In an optional example, the ring queue specifically stores a pointer of the graphics command.
[0027] In an optional example, the GPU front-end driver of any virtual machine includes a scheduling controller and the GPU back-end driver includes a scheduling monitor.
[0028] The scheduling monitor is configured to calculate a frame period required by the graphics commands based on a graphics frame rate.
[0029] The scheduling monitor is configured to send the frame period to the scheduling controller.
[0030] The scheduling controller is configured to control a time at which the graphics commands are written into the ring queue based on the frame period so as to allocate a time at which the GPU is used by any virtual machine.
[0031] In a third aspect, the present application provides an electronic device, including: at least one memory configured to store a program; and at least one processor configured to execute the program stored in the memory, and when the program stored in the memory is executed, the processor is configured to execute the method described in the first aspect or any possible implementation manner of the first aspect.
[0032] In a fourth aspect, the present application provides a computer-readable storage medium, and the computer-readable storage medium stores a computer program, and when the computer program is run on a processor, the processor is caused to execute the method described in the first aspect or any possible implementation manner of the first aspect.
[0033] In summary, the technical solutions conceived by this invention have the following beneficial effects compared with the prior art:
[0034] This invention provides a general-purpose graphics processor virtualization method and system. It adds a GPU front-end driver to the virtual machine and a GPU back-end driver to the physical machine. The GPU front-end driver captures graphics commands from the graphics application in the virtual machine and writes them to shared memory. The GPU back-end driver directly reads the commands from the shared memory in a zero-copy manner and then calls the graphics framework to operate the GPU driver, ultimately enabling the execution of graphics commands on the GPU. This achieves GPU virtualization functionality without relying on hardware virtualization support, requires no modification to existing applications, has strong adaptability and versatility, and employs a zero-copy command forwarding method at the driver layer, resulting in higher virtualization efficiency compared to ordinary command forwarding methods. Attached Figure Description
[0035] Figure 1 This is a flowchart of a general graphics processor virtualization method provided in an embodiment of the present invention;
[0036] Figure 2 This is a general framework diagram of the general graphics processor virtualization method provided in the embodiments of the present invention;
[0037] Figure 3 This is a schematic diagram of a ring-shaped shared memory for zero-copy provided in an embodiment of the present invention;
[0038] Figure 4 This is a schematic diagram of the working principle of the GPU scheduler provided in an embodiment of the present invention;
[0039] Figure 5 This is an architecture diagram of a general graphics processor virtualization system provided in an embodiment of the present invention. Detailed Implementation
[0040] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0041] GPU virtualization methods are mainly divided into four categories: device emulation, device passthrough, application-layer forwarding, and GPU slicing schemes supported by hardware virtualization. Each of these four methods has its own advantages and disadvantages, as follows:
[0042] 1. Device emulation currently mainly relies on CPU emulation of GPU interface semantics. Its advantage is that the design principle is simple, but the performance loss is too great, the virtualization efficiency is too low, and the GPU specifications of different manufacturers are very different, resulting in poor universality.
[0043] 2, device pass-through technology, mainly by providing a physical GPU directly to a virtual machine for exclusive use, the advantage is high efficiency, good performance; but multiple virtual machine scene can not use GPU at the same time, even the physical machine can not control the exclusive GPU, can not monitor the resources.
[0044] 3, application layer forwarding technology, by capturing GPU programming interface in the application interface layer, then transmitted to the physical machine or remote execution, realize GPU virtualization. The advantage is that different GPUs are suitable for strong, but the efficiency of command forwarding is low, and the performance is poor.
[0045] 4, hardware virtualization supported GPU slicing technology uses hardware SR-IOV and other technologies to realize physical GPU virtualization, with low virtual loss and high efficiency close to device pass-through scheme; but the scheme depends on the hardware virtualization support provided by the manufacturer, and in the case of hardware support, virtualization cannot be realized.
[0046] In summary, the present application is based on this background, a general-purpose graphics processor virtualization method is proposed, which aims to realize domestic general-purpose GPU virtualization without relying on GPU hardware virtualization support, design zero-copy forwarding graphics command mechanism, design GPU time-sharing sharing scheduling technology to realize multiple virtual machines to use GPU fairly, and provide a general-purpose GPU virtualization solution for realizing domestic cloud environment.
[0047] The general-purpose graphics processor virtualization method provided by the application is applied to a physical machine, the physical machine includes a plurality of virtual machines, a GPU backend driver, a graphics framework provided with a GPU driver and a GPU; each virtual machine includes a graphics application and a GPU front-end driver;
[0048] Figure 1 The general-purpose graphics processor virtualization method provided by the application is applied to a physical machine, the physical machine includes a plurality of virtual machines, a GPU backend driver, a graphics framework provided with a GPU driver and a GPU; each virtual machine includes a graphics application and a GPU front-end driver; Figure 1 As shown in the flowchart of the general-purpose graphics processor virtualization method provided by the embodiment of the application,
[0049] Step S101, the graphics application of any virtual machine receives the graphics command sent by the CPU;
[0050] Step S102, the GPU front-end driver of the virtual machine captures the graphics command of the graphics application, and writes the graphics command into the ring queue of the shared memory; the shared memory is applied by the GPU front-end driver during initialization process;
[0051] Step S103, the GPU backend driver reads the graphics command in the ring queue of the shared memory in the form of zero-copy, and calls the graphics framework to operate the GPU driver, so that the GPU executes the graphics command.
[0052] It should be noted that the GPU driver in step S103 is the original manufacturer GPU driver. The GPU backend driver can call the general standard graphics framework of the operating system to execute graphics commands without modifying the manufacturer GPU driver, so as to achieve the GPU virtualization purpose. The application does not require hardware virtualization support, and only requires the corresponding GPU driver to support the general standard graphics framework of the operating system on the basis of the general GPU, without modifying the original GPU driver, without requiring the GPU to have a hardware virtualization module, and achieving the GPU virtualization function by adding the GPU front and back drivers, i.e. the GPU front-end driver and the GPU backend driver.
[0053] The GPU front-end driver is located in the virtual machine kernel and is mainly used for capturing the graphics commands of the graphics application in the virtual machine; then the graphics commands are written into a ring-shaped shared memory which can be accessed by the virtual machine and the physical machine. The GPU backend driver (located in the physical machine kernel) directly reads the commands from the shared memory in the form of zero-copy, and then directly operates the physical kernel driver to execute the graphics commands, thereby avoiding the loss of memory copying and reducing the number of virtual machine exits caused by peripheral operations, and improving the GPU virtualization efficiency.
[0054] The method provided by the embodiment of the application adds the GPU front-end driver in the virtual machine and adds the GPU backend driver in the physical machine. The GPU front-end driver captures the graphics commands of the graphics application in the virtual machine and writes the graphics commands into the shared memory. The GPU backend driver directly reads the commands from the shared memory in the form of zero-copy, and then calls the graphics framework to operate the GPU driver, so as to finally execute the graphics commands on the GPU. Therefore, the GPU virtualization function is realized without relying on hardware virtualization support, without modifying the existing application program, with strong adaptability, with universality, and with the virtualization mode adopting the zero-copy forwarding command in the driver layer, so that the virtualization efficiency is high compared with the ordinary command forwarding mode.
[0055] Based on the above embodiment, the GPU front-end driver writes the graphics commands into the ring-shaped queue of the shared memory in step S102, and specifically includes:
[0056] The GPU front-end driver writes the graphics commands into the space corresponding to the front-end flag in the ring-shaped queue, and after the writing is successful, the front-end flag after being added by one is taken as the updated front-end flag.
[0057] Correspondingly, the GPU backend driver reads the graphics commands in the ring-shaped queue of the shared memory in the form of zero-copy in step S103, and specifically includes:
[0058] The GPU backend driver reads the graphics commands from the space corresponding to the back-end flag in the ring-shaped queue, and after the reading is successful, the back-end flag after being added by one is taken as the updated back-end flag. The initial value of the back-end flag is the same as that of the front-end flag.
[0059] It can be understood that the shared memory adopts a first-in first-out ring queue, and according to front-end and back-end flag bits, the front-end and back-end drive read and write the ring shared memory; the front-end flag bit FrontFlag and the back-end flag bit BackFlag are used for the front-end and back-end drive to maintain the ring shared memory, and the front-end and back-end flag bits are both incremented from 0, and the value is reset to 0 after the front-end and back-end flag bits are added to n, and n is the length of the ring queue. FrontFlag can only be operated by the GPU front-end drive, and BackFlag can only be operated by the GPU back-end drive, so as to avoid misoperation caused by simultaneous operation.
[0060] It should be noted that due to the randomness of user commands, there is a case that FrontFlag has been added 1 multiple times (multiple graphics operation commands are captured) in the front-end drive, but the back-end drive is not responsive or stuck in executing the previous command, and the number of times that BackFlag is added 1 is less than the number of times captured by the front end (that is, FrontFlag> BackFlag), but as long as the difference between the two does not exceed the length of the ring queue (that is, FrontFlag-BackFlag<n), the program will not be affected. Therefore, according to the actual running situation of the program, increasing the length n of the ring queue can ensure the normal running of the program and avoid the loss of commands.
[0061] The existing construction method of the ring queue is usually based on the general virtio method, and the front-end and back-end construct ring queues respectively, the front-end only writes the front-end queue (reads the back-end queue), and the back-end only writes the back-end queue (reads the front-end queue), so as to realize lock-free, but two queues need to be constructed, and the two queues will occupy a large amount of cache when the CPU runs. In the present application, only one queue containing front-end and back-end data is designed, and lock-free access is realized by setting the flag bits of the front-end and back-end, and the construction method is different, which reduces the occupied cache space and improves the cache hit rate.
[0062] Based on any of the above embodiments, the ring queue specifically stores the pointer of the graphics command.
[0063] The method provided by the embodiment of the present application mainly stores the pointer of the virtual machine data in the ring queue of the shared memory, and does not directly store data, which is beneficial to save space.
[0064] Based on any of the above embodiments, considering that the currently adopted GPU virtualization scheme is mainly the application layer forwarding or hardware virtualization supported GPU slicing scheme, there is a problem of interference when multiple virtual machines are used simultaneously.
[0065] To this end, the GPU front-end drive of the virtual machine in the embodiment of the present application includes a scheduling controller, and the GPU back-end drive includes a scheduling monitor.
[0066] The method further includes:
[0067] The scheduling monitor calculates a frame period required by the graphics command based on the graphics frame rate;
[0068] The scheduling monitor sends the frame period to the scheduling controller;
[0069] The scheduling controller controls the time of writing the graphics command into the ring queue based on the frame period, so as to realize the time allocation of the GPU used by the virtual machine.
[0070] Here, the graphics frame rate is specifically set according to the actual application scene, for example, can be the standard frame rate of graphics such as movies, animations, etc.
[0071] The scheduling controller uses the obtained frame period T as a target parameter, adopts the idea of negative feedback, changes the time of writing the graphics command into the ring queue, and thus dynamically allocates the time of using the GPU by the virtual machine. For example, the time of rendering one frame, i.e. the frame period, is fixed at 50 ms, and the CPU controls the time of sending the graphics command to the GPU backend through the scheduling controller, i.e. the time of writing the graphics command into the ring queue. After sending, the GPU must render one frame within the remaining time, otherwise the frame rate requirement cannot be met.
[0072] It should be noted that the design idea of the existing fair scheduling is usually realized by controlling the frame rate, while in the present application, the fair scheduling is realized by controlling the allocated GPU running time, which is more direct in logic, has fewer link links in implementation, can reduce the development and deployment cost, and is more efficient.
[0073] The method provided by the embodiment of the present application designs the GPU time-sharing sharing scheduling technology, can control the length of time of using the GPU by each virtual machine in the multi-virtual machine scene, avoid the case that a single virtual machine excessively occupies the GPU, and guarantee the fairness of sharing the GPU by multiple virtual machines.
[0074] Based on any of the above embodiments, step S103 further includes:
[0075] After the GPU executes the graphics command, the obtained return value is returned to the GPU driver in the graphics framework, and the graphics framework returns the return value to the GPU backend driver;
[0076] The GPU backend driver writes the return value into the ring queue;
[0077] The GPU front-end driver reads the return value in the ring queue in a zero-copy manner, and finally returns the return value to the graphics application.
[0078] Here, the graphics framework can be a DRM framework.
[0079] Based on any of the above embodiments, the application proposes a zero-copy and scheduling technology for general-purpose graphics processor virtualization, aiming to design a zero-copy forwarding graphics command mechanism to realize domestic general-purpose GPU virtualization without relying on GPU hardware virtualization support, and design a time-sharing shared scheduling technology to realize fair sharing of the function of the physical machine GPU by multiple virtual machines, thereby providing a general-purpose GPU virtualization solution for realizing domestic cloud environment. The implementation details of the shared ring queue, the read-write mode of the front-end and back-end, and the implementation mode of the fair scheduling GPU are all newly designed.
[0080] As shown in the accompanying Figure 2 The overall framework diagram of the general-purpose graphics processor virtualization method provided by the embodiment of the application is shown in the accompanying Figure 2 The GPU foreground driver (i.e., the GPU front-end driver), the GPU background driver (i.e., the GPU back-end driver), and the GPU scheduler (divided into a scheduling controller and a scheduling monitor) are the main components of the application, and the rest is the virtualization environment, which is composed of virtual machines and physical machine systems.
[0081] As shown in the accompanying Figure 2 The scheme shown includes a GPU foreground driver and a background driver, which are used to realize GPU virtualization. The GPU foreground driver is located in the virtual machine kernel and is mainly used to capture the graphics commands of the graphics application in the virtual machine through OpenGPL and other graphics libraries, and then write the graphics commands into a ring-shaped shared memory that can be accessed by both the virtual machine and the physical machine. The GPU background driver (located in the physical machine kernel) reads the commands from the shared memory in the form of zero-copy and directly operates the physical kernel graphics DRM driver to execute the graphics commands, thereby avoiding the loss caused by memory copying.
[0082] Figure 3 The ring-shaped shared memory principle diagram for zero-copy provided by the embodiment of the application is shown in the accompanying Figure 3 When the foreground driver captures the graphics commands, it will first fill the corresponding data pointer into the space pointed by the foreground flag FrontFlag (recording the end position of the commands sent by the foreground driver) in the shared memory. After successful writing, the foreground flag FrontFlag is incremented by 1, representing the increase of the end position of the commands sent by the foreground driver. Then, the background driver reads the data from the space pointed by the background flag BackFlag (recording the end position of the commands read by the background driver) in the shared memory for executing graphics operations. After successful reading, the background flag BackFlag is incremented by 1, representing the increase of the end position of the commands read by the background driver. In this way, the zero-copy forwarding of the graphics commands between the GPU foreground driver and the background driver is realized, avoiding the loss caused by copying data and reducing the number of virtual machine exits caused by peripheral operations, thereby improving the efficiency of GPU virtualization.
[0083] Meanwhile, as shown in the accompanying Figure 2The shown GPU scheduler (divided into a scheduling controller and a scheduling monitor) is mainly used to realize the demand of sharing the GPU fairly in the foreground and background driving in the multi-virtual machine scene. The working principle of the GPU scheduler provided by the embodiment of the application is as shown in Figure 4 As shown, the scheduling monitor is mainly responsible for real-time calculation of the physical GPU resource allocation resource to obtain the frame period T required by the graphics command, and the calculation formula is as follows:
[0084] T = 1 / fps
[0085] Wherein fps is the graphics standard frame rate (user-defined number of pictures rendered per second), then the scheduling monitor sends the calculated frame period T to the scheduling controller in the virtual machine, and the controller uses the obtained frame period T as a target parameter, adopts the idea of negative feedback, and according to the following formula,
[0086] t gpu = T-t cpu
[0087] Changes the time t of sending commands controlled by the CPU cpu , so as to dynamically allocate the time t of using the GPU of the virtual machine gpu , avoid the case that a single virtual machine occupies too much GPU, and ensure the fairness of sharing the GPU by multiple virtual machines.
[0088] The specific implementation method is as follows in combination with the drawings:
[0089] 1. A GPU foreground driver needs to be added in the virtual machine kernel, such as Figure 2 The driver includes normal device registration, discovery and graphics operation interface; the foreground driver will replace the ordinary GPU driver in the virtual machine, so as to capture the graphics command of the virtual machine application. However, the foreground driver will not process itself, but will write the received command into the ring shared memory in the form of zero copy; the foreground driver is also responsible for initializing the ring shared memory required by zero copy, calculating the time t of sending commands cpu controlled by the CPU;
[0090] 2. As Figure 3As shown, a shared memory will be applied in the GPU foreground driver initialization process, based on the shared mechanism (provided by the operating system) physical machine and virtual machine access to the memory in the form of a ring queue; the memory will not directly store data, but store data pointers, using the characteristics of the pointer, only to apply a smaller memory can access a large amount of memory space. For the maintenance of the shared memory, mainly using two flags: foreground flag FrontFlag and background flag BackFlag. FrontFlag is used to record the end position of the foreground driver sending commands in the ring queue, when the foreground driver captures the graphics command, need to write according to the FrontFlag value in the ring shared memory, write successfully need to do FrontFlag plus 1 operation (after adding n value to 0). BackFlag records the end position of the background driver has read the command, each time the background driver operation need to read the command from the ring shared memory according to the BackFlag value; successful also need to do BackFlag plus 1 operation (after adding n value to 0). Foreground and background driver read and write ring shared memory position depends on the foreground and background flag: FrontFlag, BackFlag.
[0091] 3. The physical machine kernel needs to increase the GPU background driver, such as Figure 2 , used to read the graphics command from the above shared memory in the form of zero copy, and then call the physical machine graphics driver function in the physical machine kernel to operate the actual manufacturer GPU driver, so as to execute the user graphics command. No modification is needed for the original manufacturer driver, and it can run.
[0092] Based on any of the above embodiments, the application provides a general graphics processor virtualization system. Figure 5 is the architecture diagram of the general graphics processor virtualization system provided by the embodiment of the application, as shown in Figure 5 , the system includes CPU 510 and physical machine 520, the physical machine 520 includes a plurality of virtual machines 521, GPU backend driver 524, graphics framework 525 provided with GPU driver 526 and GPU 527; each virtual machine 521 includes graphics application 522 and GPU front-end driver 523;
[0093] The graphics application 522 of any virtual machine 521 is used to receive the graphics command sent by the CPU 510;
[0094] The GPU front-end driver 523 of any virtual machine 521 is used to capture the graphics command of the graphics application 522, and write the graphics command into the ring queue of the shared memory; the shared memory is applied by the GPU front-end driver 523 in the initialization process;
[0095] The GPU backend driver 524 is configured to read graphics commands in the ring queue of the shared memory in a zero-copy manner, and to call the graphics framework 525 to operate the GPU driver 526, so as to make the GPU 527 execute the graphics commands.
[0096] It can be understood that the detailed function implementation of each module can refer to the description in the foregoing method embodiments, and will not be described herein.
[0097] In addition, the embodiment of the present application provides another general-purpose graphics processor virtualization device, which comprises a memory and a processor.
[0098] The memory is configured to store a computer program.
[0099] The processor is configured to implement the method in the foregoing embodiments when executing the computer program.
[0100] In addition, the present application also provides a computer readable storage medium, and the storage medium stores a computer program, and when the computer program is executed by a processor, the method in the foregoing embodiments is implemented.
[0101] Based on the method in the foregoing embodiments, the embodiment of the present application provides a computer program product, and when the computer program product is run on a processor, the processor executes the method in the foregoing embodiments.
[0102] Those skilled in the art can easily understand that the above description is only the preferred embodiment of the present application, and is not used to limit the present application, and any modification, equivalent replacement and improvement made within the spirit and principle of the present application should be included in the protection scope of the present application.
Claims
1. A method of general-purpose graphics processor virtualization, the method comprising: The method is applied to a physical machine, the physical machine comprising a plurality of virtual machines, a GPU backend driver, a graphics framework provided with a GPU driver and a GPU; each virtual machine comprising a graphics application and a GPU frontend driver; The method comprises the following steps: In step S101, the graphics application of any virtual machine receives graphics commands sent by a CPU; In step S102, the GPU frontend driver of the any virtual machine captures the graphics commands of the graphics application and writes the graphics commands into a ring queue of a shared memory; the shared memory is applied for by the GPU frontend driver in an initialization process; and the ring queue specifically stores pointers of the graphics commands; In step S103, the GPU backend driver reads the graphics commands in the ring queue of the shared memory in a zero-copy manner and calls the graphics framework to operate the GPU driver so that the GPU executes the graphics commands; In step S102, the GPU frontend driver writes the graphics commands into a space corresponding to a front-end flag bit of the ring queue and, after successful writing, takes the front-end flag bit after addition by one as an updated front-end flag bit; Correspondingly, in step S103, the GPU backend driver reads the graphics commands from a space corresponding to a rear-end flag bit of the ring queue in a zero-copy manner and, after successful reading, takes the rear-end flag bit after addition by one as an updated rear-end flag bit; the rear-end flag bit has the same initial value as the front-end flag bit; The GPU frontend driver of the any virtual machine comprises a scheduling controller, and the GPU backend driver comprises a scheduling monitor; The method further comprises that the scheduling monitor calculates a frame period required by the graphics commands based on a graphics frame rate, the scheduling monitor sends the frame period to the scheduling controller, and the scheduling controller controls a time for writing the graphics commands into the ring queue based on the frame period to realize allocation of a time for using the GPU by the any virtual machine.
2. A general-purpose graphics processor virtualization system, comprising: The method is applied to a physical machine, the physical machine comprising a plurality of virtual machines, a GPU backend driver, a graphics framework provided with a GPU driver and a GPU; each virtual machine comprising a graphics application and a GPU frontend driver; The graphics application of any virtual machine is configured to receive graphics commands sent by a CPU; The GPU frontend driver of the any virtual machine is configured to capture the graphics commands of the graphics application and write the graphics commands into a ring queue of a shared memory; The shared memory is applied for by the GPU frontend driver in an initialization process; and the ring queue specifically stores pointers of the graphics commands; and the GPU backend driver is configured to read the graphics commands in the ring queue of the shared memory in a zero-copy manner and call a graphics framework to operate a GPU driver so that a GPU executes the graphics commands; The GPU frontend driver of the any virtual machine is specifically configured to write the graphics commands into a space corresponding to a front-end flag bit of the ring queue and, after successful writing, take the front-end flag bit after addition by one as an updated front-end flag bit; Correspondingly, the GPU backend driver is specifically configured to read the graphics command from the space corresponding to the backend flag bit in the ring queue, and after the reading is successful, the incremented backend flag bit is taken as the updated backend flag bit; the initial value of the backend flag bit is the same as that of the front-end flag bit; The GPU front-end driver of any virtual machine comprises a scheduling controller, and the GPU backend driver comprises a scheduling monitor; The scheduling monitor is configured to calculate the frame period required by the graphics command based on the graphics frame rate; The scheduling monitor is configured to send the frame period to the scheduling controller, and the scheduling controller is configured to control the time of writing the graphics command into the ring queue based on the frame period, so as to realize the time of allocating the GPU for use by any virtual machine.
3. An electronic device, comprising: Comprise: At least one memory for storing a program; At least one processor for executing the program stored in the memory, and when the program stored in the memory is executed, the processor is configured to execute the method of claim 1.
4. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a computer program, and when the computer program runs on the processor, the processor executes the method of claim 1. The computer readable storage medium stores a computer program, and when the computer program runs on the processor, the processor executes the method of claim 1.
Citation Information
Patent Citations
Para-virtualization-based general calculation method and system
CN106708602A
Method and device for sharing special processing resources, equipment and storage medium
CN110413377A