Method and device for allocating video memory resources, computer equipment and storage medium
By dynamically adjusting the allocation of video memory resources, the problem of AIU resource congestion between tasks is solved, and the system stability and execution speed of computer equipment are improved.
Patent Information
- Application Number
- CN202410813380.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-21
- Publication Date
- 2024-09-27
AI Technical Summary
When running multiple tasks on a computer device, the tasks occupy AIU resources, causing the execution speed to slow down.
By obtaining the video memory allocation instructions of the target container, parsing the task type and container process identification information, determining the corresponding accelerator card, and dynamically adjusting the video memory resource allocation based on real-time video memory information and preset video memory quotas to avoid resource overload and ensure system stability and computing speed.
It achieves resource isolation between different tasks, avoids accelerator card overload and crashes, improves overall system stability and computing speed, and ensures that critical tasks have sufficient resources to run.
Smart Images

Figure CN118708345A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method, device, computer equipment and storage medium for allocating video memory resources. Background Art
[0002] With the rapid development of artificial intelligence technology, the computing power required by computer equipment is increasing. Therefore, various accelerator cards or computing units (Artificial Intelligence Unit, AIU) have become the key hardware for current deep learning model training.
[0003] When running multiple tasks on a computer device, in order to increase the running speed, multiple tasks can be run simultaneously in a high-concurrency manner. In this case, multiple tasks will occupy each other's AIU resources, slowing down the execution speed of the tasks. Summary of the invention
[0004] In view of this, the present invention provides a method, apparatus, computer device, storage medium and program product for allocating video memory resources to solve the problem that multiple tasks occupy each other's AIU resources and slow down the execution speed of tasks.
[0005] In a first aspect, the present invention provides a method for allocating video memory resources, the method being applied to a target device, the target device being connected to at least one accelerator card, the target device being installed with at least one container, the method comprising:
[0006] Obtaining a video memory allocation instruction of a target container, parsing the video memory allocation instruction, and obtaining a task type and at least one container process identification information, wherein the target container is any one of the at least one containers;
[0007] Determining, according to the task type, first accelerator card identification information corresponding to the task type;
[0008] Determining, according to the first accelerator card identification information, a first accelerator card corresponding to the first accelerator card identification information, wherein the first accelerator card is one accelerator card of the at least one accelerator card;
[0009] According to each of the at least one container process identification information, acquiring, from the first accelerator card, real-time video memory information of a process corresponding to each of the container process identification information;
[0010] Determine whether to allocate the video memory resources of the first accelerator card according to the real-time video memory information of the process corresponding to each of the container process identification information and the preset video memory quota corresponding to the target container.
[0011] The method for allocating video memory resources provided by the present invention has the following advantages:
[0012] Run different applications on different containers. Since the containers are isolated from each other, the training tasks run in the containers without affecting each other. The resource leakage or crash of one training task will not affect other training tasks, which improves the overall system stability. In addition, each container can use the corresponding accelerator card. At the same time, the maximum available video memory resources of each container are limited by the preset video memory quota. In this way, before performing the video memory resource allocation operation, the real-time video memory information of each process of the target container can be obtained first. According to the real-time video memory information of each process of the target container and the preset video memory quota, it is determined whether to perform the video memory resource allocation operation. This can avoid different applications grabbing the resources of different accelerator cards, and different applications grabbing the video memory resources of the same accelerator card, causing the accelerator card to overload and crash and slow down the calculation speed. That is, the calculation speed can be improved.
[0013] In an optional implementation, the real-time video memory information includes the size of video memory occupied by the process;
[0014] The determining whether to allocate the video memory resources of the first accelerator card according to the real-time video memory information of the process corresponding to each of the container process identification information and the preset video memory quota corresponding to the target container includes:
[0015] Determine the size of the video memory occupied by the target container according to the size of the video memory occupied by the process corresponding to each of the container process identification information;
[0016] Determine the remaining video memory size of the target container according to the video memory size occupied by the target container and the preset video memory quota corresponding to the target container;
[0017] Determine whether the video memory size occupied by the target container is less than or equal to a preset video memory quota corresponding to the target container, and whether the remaining video memory size of the target container is greater than or equal to a preset allocated video memory size;
[0018] When it is determined that the video memory size occupied by the target container is less than or equal to the preset video memory quota corresponding to the target container, and the remaining video memory size of the target container is greater than or equal to the preset allocated video memory size, video memory resources on the first accelerator card that are equal to the preset allocated video memory size are allocated to the target process corresponding to the video memory allocation instruction according to the preset allocated video memory size.
[0019] Specifically, the actual video memory usage of each container process is monitored in real time, and the video memory resource allocation is dynamically adjusted. By setting a preset video memory quota, a resource usage boundary is set for container use to ensure that even under high load conditions, the target device's system will not be unstable due to excessive resource occupation by individual tasks.
[0020] In an optional implementation, when it is determined that the video memory size occupied by the target container is greater than a preset video memory quota corresponding to the target container, and / or the remaining video memory size of the target container is less than a preset allocated video memory size, the method further includes:
[0021] Kills the target process.
[0022] Specifically, by terminating the overloaded process in a timely manner and preventing the target container from over-consuming video memory resources and causing exhaustion of the entire accelerator card resources, the overall stable operation of the system and the normal operation of other important processes can be protected.
[0023] In an optional embodiment, the method further includes:
[0024] Obtain a video memory allocation level of the target container, wherein the video memory allocation level is used to determine whether to allocate video memory resources of the first accelerator card based on real-time video memory information of a process corresponding to each process identification information of the container and a preset video memory quota corresponding to the target container.
[0025] Specifically, by dividing the video memory allocation levels, limited video memory resources can be more reasonably allocated to higher priority tasks or processes, ensuring the stability and performance of key services, while avoiding the waste of resources on low priority or non-critical tasks, thereby improving the overall system resource utilization efficiency.
[0026] In an optional implementation, when the video memory allocation level of the target container is the first level, the preset video memory quota corresponding to the target container is equal to the video memory resource size of the first accelerator card;
[0027] Alternatively, when the graphics memory allocation level of the target container is the second level, the preset graphics memory quota corresponding to the target container is smaller than the graphics memory resource size of the first acceleration card, and the first level is higher than the second level.
[0028] Specifically, because the first-level tasks can use the same amount of video memory resources as the first accelerator card, it ensures that critical or high-priority tasks have sufficient resources to support their operation, so that resources are tilted toward important tasks, optimizing the overall task execution efficiency and quality.
[0029] In an optional embodiment, the method further includes:
[0030] Get the video memory information acquisition instruction;
[0031] Parsing the video memory information acquisition instruction to obtain second accelerator card identification information;
[0032] Determining, according to the second accelerator card identification information, a second accelerator card corresponding to the second accelerator card identification information, wherein the second accelerator card is one of the at least one accelerator card;
[0033] Obtain the number of processes running on the second accelerator card;
[0034] Determining whether the number of processes running on the second accelerator card is greater than a preset number of processes;
[0035] When it is determined that the number of processes running on the second acceleration card is greater than the preset number of processes, target alarm information is generated and fed back to the client.
[0036] Specifically, when it is detected that the number of processes on the second accelerator card exceeds a preset threshold, an alarm message is immediately generated and fed back to the client. This preventive maintenance measure allows administrators to quickly intervene, investigate and resolve potential resource contention issues, and avoid service interruptions or performance degradation caused by resource exhaustion.
[0037] In an optional implementation, when it is determined that the number of processes running on the second acceleration card is less than or equal to the preset number of processes, the method further includes:
[0038] Acquire identification information corresponding to a preset process of the second accelerator card and identification information corresponding to a real-time process running on the second accelerator card, wherein the preset process includes at least one and the number of the real-time process is at least one;
[0039] Determine, according to the identification information corresponding to the target real-time process and the identification information corresponding to the preset process, whether the target real-time process is a preset process in at least one of the preset processes, wherein the target real-time process is any real-time process in at least one of the real-time processes;
[0040] When it is determined that the target real-time process is one of at least one of the preset processes according to the identification information corresponding to the target real-time process and the identification information corresponding to the preset process, the target real-time process is determined to be a normal process;
[0041] or,
[0042] When it is determined that the target real-time process is not one of the preset processes according to the identification information corresponding to the target real-time process and the identification information corresponding to the preset process, the target real-time process is determined to be an abnormal process, and the target real-time process is killed;
[0043] When at least one normal process is determined, determining the size of the video memory occupied by the second accelerator card according to the size of the video memory occupied by each normal process;
[0044] According to the size of the video memory occupied by the second accelerator card, video memory information corresponding to the second accelerator card is generated and fed back to the client.
[0045] Specifically, by identifying and distinguishing normal processes from abnormal processes, and taking termination actions on non-preset abnormal processes, unauthorized or malicious processes can be effectively prevented from occupying accelerator card resources, enhancing security and compliance. This is especially important in shared or cloud environments to ensure that resources are used by legitimate and predetermined applications.
[0046] In a second aspect, the present invention provides a device for allocating video memory resources, the device is applied to a target device, the target device is connected to at least one accelerator card, the target device is installed with at least one container, and the method includes:
[0047] an acquisition module, configured to acquire a video memory allocation instruction of a target container, parse the video memory allocation instruction, and obtain a task type and at least one container process identification information, wherein the target container is any one of the at least one containers;
[0048] a determination module, configured to determine, according to the task type, first accelerator card identification information corresponding to the task type; and determine, according to the first accelerator card identification information, a first accelerator card corresponding to the first accelerator card identification information, wherein the first accelerator card is one accelerator card of at least one accelerator card;
[0049] The acquisition module is further configured to acquire, from the first accelerator card, real-time video memory information of a process corresponding to each of the container process identification information according to each of the container process identification information in the at least one container process identification information;
[0050] The determination module is further used to determine whether to allocate the video memory resources of the first accelerator card according to the real-time video memory information of the process corresponding to each of the container process identification information and the preset video memory quota corresponding to the target container.
[0051] In a third aspect, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the method for allocating video memory resources of the first aspect or any corresponding embodiment thereof by executing the computer instructions.
[0052] In a fourth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the method for allocating video memory resources according to the first aspect or any corresponding embodiment thereof.
[0053] In a fifth aspect, the present invention provides a computer program product, including computer instructions, where the computer instructions are used to enable a computer to execute the method for allocating video memory resources according to the first aspect or any corresponding embodiment thereof. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the related technologies, the drawings required for use in the specific embodiments or the related technical descriptions will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0055] Figure 1 is a schematic diagram of the architecture of a graphics memory resource management software system according to an embodiment of the present invention;
[0056] Figure 2 is a functional schematic diagram of a hijacking library module according to an embodiment of the present invention;
[0057] Figure 3 is a flow chart of a method for allocating video memory resources according to an embodiment of the present invention;
[0058] Figure 4 is a flowchart of another method for allocating video memory resources according to an embodiment of the present invention;
[0059] Figure 5 is a flow chart of a method for obtaining video memory information according to an embodiment of the present invention;
[0060] Figure 6 is a structural block diagram of a device for allocating video memory resources according to an embodiment of the present invention;
[0061] Figure 7 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0062] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0063] The embodiment of the present invention provides a video memory resource management software system, such as Figure 1 As shown, the video memory resource management software system may include at least one POD and a host process module (also referred to as host_proc_ctled). Among them, a POD may be encapsulated with a container, each container running a training task, and a corresponding training framework (for example, TensorFlow, Pytorch, etc.). The container may include a hijacking library module (also referred to as libcn_aiu_partition.so), and the hijacking library module includes a forwarding submodule (also referred to as a communicator) for receiving and parsing various instructions issued by the container. The host process module includes a listening module and a parsing module, and the listening module is used to listen to the instructions issued by the forwarding submodule, and when the instructions issued by the forwarding submodule are listened to as the specified message type, the instructions are forwarded to the parsing module. The parsing module is used to parse the instructions and perform related operations according to the parsing results, such as the operation of obtaining video memory information in this solution. After starting the training task in the container, the training task will be run using the training framework, and the training framework will issue various instructions according to the training task to execute the training process. When these instructions are sent to the system bottom layer of the target device, they will be intercepted by the hijacking library module.
[0064] The video memory resource management software system can be configured on a target device, which can be a server. The target device can be connected to at least one accelerator card (AIU).
[0065] The following describes the configuration process of the video memory resource management software system.
[0066] The host process module can run on the host as a daemon process, and is provided with a mechanism for automatic startup upon startup or restart. However, if the daemon process is actively killed, the daemon process will not automatically restart. The daemon process can shield SIGINT, SIGPIPE, and SIGHUP signals to ensure the stable operation of the host process module. In addition, the host process module can be provided with an error reporting mechanism. During the execution of related operations, if it is determined that the corresponding / var / log / host_proc directory does not exist, the log is not output. If it is determined that the corresponding / var / log / host_proc directory exists, a directory named vaiu can be created under the directory, and a log file can be generated based on the information of related operations at the current time.
[0067] The monitoring submodule may be a User Datagram Protocol (UDP) monitoring submodule. The configuration process of the monitoring submodule may be as follows:
[0068] First, the target device obtains the target configuration file and parses the target configuration file to obtain the port information. In addition, the target device can create a target socket (which can be a UDP socket). Then, according to the port information, determine the target port corresponding to the port information. Bind the target socket to the target port. Among them, the port information can be a port number. In this solution, the port number can be 22586.
[0069] After the above configuration, the instructions sent by the container can be listened to through the target port. In this solution, the UDP listening submodule will only perform subsequent processing when it listens to instructions with message type 10.
[0070] For example, the code implementation of the UDP listening submodule can be as follows:
[0071] using namespace std;
[0072] int main(){
[0073] int port;
[0074] FILE*fp;
[0075] char buffer[MAX_BUFFER_SIZE];
[0076] intmessage_type;
[0077] intsockfd;
[0078] struct sockaddr_inserv_addr;
[0079] charsend_buf[MAX_BUFFER_SIZE];
[0080] charrecv_buf[MAX_BUFFER_SIZE];
[0081] / / Read the port number from the target configuration file
[0082] fp = fopen(CONF_FILE,"r");
[0083] fscanf(fp,"%d",&port);
[0084] fclose(fp);
[0085] / / Create a UDP socket and bind to the target port
[0086] sockfd=socket(AF_INET,SOCK_DGRAM,0);
[0087] memset(&serv_addr,0,sizeof(serv_addr));
[0088] serv_addr.sin_family=AF_INET;
[0089] serv_addr.sin_addr.s_addr=htonl(INADDR_ANY);
[0090] serv_addr.sin_port=htons(port);
[0091] bind(sockfd,(structsockaddr*)&serv_addr,sizeof(serv_addr));
[0092] / / The UDP listening submodule starts listening to the target port and waits for instructions from the container
[0093] while(true){
[0094] / / Receive the message and parse the message type
[0095] memset(recv_buf,0,MAX_BUFFER_SIZE);
[0096] socklen_taddrlen=sizeof(serv_addr);
[0097] recvfrom(sockfd,recv_buf,MAX_BUFFER_SIZE,0,(structsockaddr*)&serv_addr,&addrlen);
[0098] message_type=atoi(recv_buf);
[0099] / / Only process messages of type 10, ignore other types
[0100] if(message_type==MESSAGE_TYPE_10){
[0101] / / Logic for processing messages of type 10...
[0102] }else{
[0103] / / Ignore other types of messages...
[0104] }
[0105] }
[0106] return 0;
[0107] }
[0108] The parsing submodule may be a host pid parsing submodule. The configuration process of the parsing submodule may be as follows:
[0109] First, the target device obtains the number of accelerator cards connected to the target device; according to the number of accelerator cards, a number of message processing threads equal to the number of accelerator cards is created; a message processing thread is bound to an accelerator card, wherein the message processing thread is used to obtain corresponding video memory information from the accelerator card to which it is bound.
[0110] After the above configuration, the parsing submodule can perform parsing operations on related instructions.
[0111] For example, the code implementation of the Host pid parsing submodule can be as follows:
[0112] / / Assume the following classes and methods:
[0113] class AIU{
[0114] public:
[0115] int id;
[0116] / / Other properties and methods
[0117] };
[0118] class MessageHandler {
[0119] public:
[0120] voidhandleMessage(intaiuId);
[0121] / / Other properties and methods...
[0122] };
[0123] / / Global variable and function declaration
[0124] std::vector <aiu>before;
[0125] std::vector <std::thread>threads;
[0126] std::mutexmtx;
[0127] std::condition_variable cv;
[0128] / / Create corresponding message processing threads according to the number of accelerator cards connected to the target device void createMessageHandlerThreads(intnumAIUs){
[0129] for(int i = 0; i <numAIUs;i++){
[0130] threads.push_back(std::thread([i]{
[0131] while(true){
[0132] std::unique_lock <std::mutex>lock(mtx);
[0133] cv.wait(lock,[]{return!aius.empty();});
[0134] intaiuId = aius.back().id;
[0135] aius.pop_back();
[0136] lock.unlock();
[0137] cv2.notify_all();
[0138] MessageHandler().handleMessage(aiuId);
[0139] }
[0140] }));
[0141] }
[0142] }
[0143] / / Each message processing thread only processes the message of the corresponding accelerator card void handleMessage(intaiuId){
[0144] / / Logic for processing messages corresponding to the accelerator card
[0145] }
[0146] / / Message processing thread processing rules
[0147] int main(){
[0148] intnumAIUs = getNumAIUs();
[0149] createMessageHandlerThreads(numAIUs);
[0150] for(int i = 0; i <numAIUs;i++){
[0151] aius.push_back({i});
[0152] cv2.notify_all();
[0153] }
[0154] for(auto&thread:threads){
[0155] thread.join();
[0156] }
[0157] return 0;
[0158] }
[0159] When running a training task, the loading of the hijacking library module can be automatically triggered. Figure 2 As shown, the hijacking library module can hijack the original cn and cndev functions at compile time, and replace the original cn and cndev functions with the redefined cn and cndev functions. At runtime, it can hijack the original dlsym instruction and replace the original dlsym instruction with the redefined dlsym instruction. In this way, the real-time video memory information and process identification information can be obtained through the replaced cndev function later.
[0160] When training deep learning models, the required computing power is very large. Accelerator cards can provide efficient parallel computing capabilities and support complex neural network computing tasks. Therefore, an accelerator card can be configured on the target device to improve the computing power of the target device. When the target device executes training tasks, the graphics memory resources of the accelerator card can be allocated to each training task.
[0161] An embodiment of the present invention provides a method for allocating video memory resources. Before issuing a training task, it is determined whether to allocate video memory resources based on the video memory resources occupied by the training task, so as to avoid the problem that some training tasks excessively occupy the video memory resources of other training tasks, thereby slowing down the calculation speed of all training tasks.
[0162] According to an embodiment of the present invention, a method embodiment for allocating video memory resources is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0163] In this embodiment, a method for allocating video memory resources is provided, which can be executed by the above-mentioned target device. Figure 3 is a flowchart of a method for allocating video memory resources according to an embodiment of the present invention. Figure 3 As shown, the process includes the following steps:
[0164] Step S301, obtaining a video memory allocation instruction of a target container, parsing the video memory allocation instruction, and obtaining a task type and at least one container process identification information.
[0165] The target container is any one of the at least one container.
[0166] Specifically, the user can run the training task through the target container and issue various instructions. The hijacking library module inside the target container can hijack the instructions issued by the target container and send them to the listening submodule of the host process module through the forwarding submodule. At this time, the listening submodule can listen to the target port receiving the instruction, and the listening submodule can parse the instruction to obtain the type of the message. When the type of the message is a preset type, the instruction can be further sent to the parsing submodule.
[0167] The above instructions can be cnInvokeKernel, cnModuleLoadFatBinary, cnQueueSync, cnMemcpyHtoDAsync, cnModuleGetKernel, cnMemcpyDtoHAsync, cnMalloc, cnInit, cnSharedContextAcquire, cnCreateQueueWithPriority, cnModuleGet One of Symbol, cnDeviceGetAttribute, cnGetCtxMaxParallelUnionTasks, cnGetCtxConfigParam_pt, cnModuleGetLoadingMode, cnDeviceGetUuid, cndevGetUUID, cndevGetCardNameStringByDevId, cndevGetProcessInfo.
[0168] When the target container issues a data computing instruction, it is necessary to allocate the video memory resources of the accelerator card to the training task corresponding to the data computing instruction. The target container will generate a video memory allocation instruction, and the hijacking library module can hijack the video memory allocation instruction and forward the video memory allocation instruction to the parsing submodule in the above manner. The parsing submodule can parse the video memory allocation instruction to obtain the task type and at least one container process identification information.
[0169] Generally, a training task can be run on a container, and a training task generally starts a process. However, since the application developers corresponding to the training tasks are different, it is possible that a training task starts multiple processes. Therefore, when issuing a video memory allocation instruction, all container process identification information corresponding to the target container can be used as part of the video memory allocation instruction.
[0170] Step S302: Determine first accelerator card identification information corresponding to the task type according to the task type.
[0171] The first accelerator card identification information may be a universally unique identifier (Universally Unique Identifier, UUID).
[0172] Specifically, since the video memory resources of the accelerator card are limited, it is possible to pre-set which containers each accelerator card can run, that is, the correspondence between the task type and the accelerator card identification information can be created in advance. After parsing the task type, the first accelerator card identification information corresponding to the parsed task type can be determined based on the parsed task type and the pre-created correspondence between the task type and the accelerator card identification information.
[0173] In some optional implementations, the memory allocation instruction may include identification information of the container. Accordingly, the target device may pre-store a correspondence between the identification information of the container and the identification information of the accelerator card. In step S302, the target device may determine the first accelerator card identification information corresponding to the identification information of the container based on the identification information of the container in the memory allocation instruction and the correspondence between the identification information of the container and the identification information of the accelerator card.
[0174] Step S303: determining, according to the first accelerator card identification information, a first accelerator card corresponding to the first accelerator card identification information.
[0175] The first acceleration card is an acceleration card among at least one acceleration card connected to the target device.
[0176] Specifically, in order to limit the video memory resources occupied by each container, the target device may determine the first acceleration card corresponding to the first acceleration card identification information according to the first acceleration card identification information, and only allocate the video memory resources on the first acceleration card to the target container.
[0177] Step S304: According to each container process identification information in the at least one container process identification information, real-time video memory information of a process corresponding to each container process identification information is obtained from the first accelerator card.
[0178] Specifically, since the above-mentioned video memory allocation instruction is issued by the target container, the target container is a virtual device, and therefore, the process identification information in the video memory allocation instruction is the container process identification information, that is, the container process identification information named inside the container. However, the container process identification information actually corresponds to the actual process information of a physical machine (that is, the host process identification information, Host_pid), and each process running on the accelerator card is managed through the host process identification information. Therefore, the parsing submodule may need to perform the following operations first:
[0179] According to each container process identification information, the host process identification information corresponding to each container process identification information is determined. According to each host process identification information, the real-time video memory information corresponding to each host process identification information is obtained from the target accelerator card; the real-time video memory information corresponding to each host process identification information is determined as the real-time video memory information of the process corresponding to each container process identification information.
[0180] In this way, the parsing submodule can obtain the real-time video memory information of the process corresponding to each container process identification information, and feed back the obtained real-time video memory information of the process corresponding to each container process identification information to the target container.
[0181] In some optional implementations, the real-time video memory information can be obtained through the cndev command, and in the process of feeding back the real-time video memory information to the target container, it is fed back through the cnmon command. The cnmon command will feed back the host process identification information and the corresponding real-time video memory information together, and the host process identification information is invalid inside the container. In addition, the object directly operated by the user is the container, not the host hardware itself. If the host process identification information is fed back to the user, it may cause security problems. Therefore, before feeding back the real-time video memory information to the target container, the hijacking library module may first replace the host process identification information with the original container process identification information. For example, the implementation code for the above-mentioned execution of feedback of real-time video memory information may be as follows:
[0182] / / Define the hijacking function prototype
[0183] voidinterceptCnmonOutput(conststd::string&oldCommand,std::string&newCommand,int&hostPid,intcontainerPid);
[0184] intmainproc(){
[0185] / / Get cnmon command and parameters
[0186] std::stringcnmonCommand="cnmon";
[0187] std::vector <std::string>cnmonArgs;
[0188] / / Get cnmon commands and parameters from environment variables, command line parameters, etc., and add them to cnmonArgs...
[0189] / / Get the host process identification information and container process identification information
[0190] inthostPid = getpid(); / / Get the current process ID as the host process ID
[0191] int containerPid = getContainerPid(); / / Get the container process ID from some method, such as through the docker or containerd API
[0192] / / Hijack the cnmon command and parameters, and replace the host process identification information with the process identification information
[0193] interceptCnmonOutput(cnmonCommand,cnmonArgs,hostPid,containerPid);
[0194] / / Execute the hijacked cnmon command
[0195] std::string command = buildCommand(cnmonArgs); / / Build the command after hijacking
[0196] int result = std::system(command.c_str()); / / Execute the hijacked command
[0197] if (result!=0) {
[0198] std::cout<<"Failed to execute"< <command<<std::endl;
[0199] return 1;
[0200] }
[0201] return 0;
[0202] }
[0203] In some optional methods, a monitoring mechanism may be provided during the above-mentioned process of obtaining the host process identification information. If the time for obtaining the host process identification information reaches a preset time threshold (for example, 90s), the hijacking library module may be exited.
[0204] Step S305 : Determine whether to allocate the video memory resources of the first accelerator card according to the real-time video memory information of the process corresponding to each container process identification information and the preset video memory quota corresponding to the target container.
[0205] The real-time video memory information may include the size of the video memory occupied by the process.
[0206] Specifically, the target container can determine the occupied video memory size of the target container according to the video memory size occupied by the process corresponding to each container process identification information. Further, the remaining video memory size of the target container can be determined according to the occupied video memory size of the target container and the preset video memory quota. Further, it can be determined whether the remaining video memory size of the target container is greater than or equal to the preset remaining video memory threshold. If so, the video memory resource of the first accelerator card can be allocated. If not, the target process can be killed.
[0207] For example, the above step S305 can be implemented by the following code:
[0208] / / Define the video memory control class
[0209] classPODMemCtrl{
[0210] public:
[0211] / / Constructor
[0212] PODMemCtrl(intpodId){
[0213] m_podId = podId;
[0214] }
[0215] / / Calculate the memory size occupied by the container and the remaining memory size
[0216] boolgetTotalAndRemainingMem(unsigned int&totalMem,unsignedint&remainingMem){
[0217] totalMem = 0;
[0218] remainingMem = 0;
[0219] std::vector <int>aiuIds;
[0220] getAIUIds(aiuIds);
[0221] for(int aiuId:aiuIds){
[0222] unsignedintdeviceTotalMem=0;
[0223] unsignedintdeviceRemainingMem=0;
[0224] if(!getDeviceMemInfo(aiuId,deviceTotalMem,deviceRemainingMem))
[0225] totalMem + = deviceTotalMem;
[0226] remainingMem+=deviceRemainingMem;
[0227] }
[0228] / / Check if the remaining video memory size meets the requirements
[0229] if(remainingMem>=MIN_REMAINING_MEM){
[0230] return true; / / The remaining video memory size meets the requirements and returns a success message
[0231] }else{
[0232] return false; / / The remaining video memory size does not meet the requirements, and returns a failure message
[0233] }
[0234] }
[0235] private:
[0236] / / POD ID
[0237] intm_podId;
[0238] };
[0239] The method for allocating video memory resources provided in this embodiment runs different applications on different containers. Since the containers are isolated from each other, the training tasks run in the containers without affecting each other. The resource leakage or crash of one training task will not affect other training tasks, thereby improving the overall system stability. In addition, each container can use the corresponding accelerator card. At the same time, the maximum usable video memory resources of each container are limited by the preset video memory quota. In this way, before performing the video memory resource allocation operation, the real-time video memory information of each process of the target container can be obtained first. According to the real-time video memory information of each process of the target container and the preset video memory quota, it is determined whether to perform the video memory resource allocation operation. This can avoid different applications from grabbing the resources of different accelerator cards, and different applications from grabbing the video memory resources of the same accelerator card, resulting in the problem of overload and crash of the accelerator card and slowing down the computing speed. That is, the computing speed can be improved.
[0240] In this embodiment, a method for allocating video memory resources is provided, which can be executed by the above-mentioned target device. Figure 4 is a flowchart of a method for allocating video memory resources according to an embodiment of the present invention. Figure 4 As shown, the process includes the following steps:
[0241] Step S401, obtaining a video memory allocation instruction of a target container, parsing the video memory allocation instruction, and obtaining a task type and at least one container process identification information.
[0242] The target container is any one of the at least one container.
[0243] Step S402: Determine, according to the task type, first accelerator card identification information corresponding to the task type.
[0244] Step S403: determining, according to the first accelerator card identification information, a first accelerator card corresponding to the first accelerator card identification information.
[0245] The first acceleration card is an acceleration card among the at least one acceleration card.
[0246] Step S404: According to each container process identification information in the at least one container process identification information, real-time video memory information of a process corresponding to each container process identification information is obtained from the first accelerator card.
[0247] The specific processing from step S401 to step S404 is similar to the specific processing from step S301 to step S304, and will not be repeated here.
[0248] Step S405 : determining whether to allocate the video memory resources of the first accelerator card according to the real-time video memory information of the process corresponding to each container process identification information and the preset video memory quota corresponding to the target container.
[0249] The real-time video memory information includes the size of the video memory occupied by the process.
[0250] Specifically, the above step S405 includes:
[0251] Step S4051, determining the video memory size occupied by the target container according to the video memory size occupied by the process corresponding to each container process identification information.
[0252] Step S4052: Determine the remaining video memory size of the target container according to the video memory size occupied by the target container and the preset video memory quota corresponding to the target container.
[0253] Step S4053, determining whether the video memory size occupied by the target container is less than or equal to the preset video memory quota corresponding to the target container, and whether the remaining video memory size of the target container is greater than or equal to the preset allocated video memory size.
[0254] Step S4054: when it is determined that the video memory size occupied by the target container is less than or equal to the preset video memory quota corresponding to the target container, and the remaining video memory size of the target container is greater than or equal to the preset allocated video memory size, based on the preset allocated video memory size, video memory resources on the first accelerator card that are equal to the preset allocated video memory size are allocated to the target process corresponding to the video memory allocation instruction.
[0255] Step S4055: when it is determined that the video memory size occupied by the target container is greater than the preset video memory quota corresponding to the target container, and / or the remaining video memory size of the target container is less than the preset allocated video memory size, the target process is killed.
[0256] Specifically, the target container may sum the video memory sizes occupied by the processes corresponding to all container process identification information in the at least one container process identification information to obtain the video memory size occupied by the target container. The target container may subtract the video memory size occupied by the target container from the preset video memory quota corresponding to the target container to obtain the remaining video memory size of the target container.
[0257] When the size of the video memory occupied by the target container exceeds the preset video memory quota of the target container, it means that the application running on the target container is occupying the video memory resources occupied by other applications. This behavior will affect the computing speed. Therefore, when allocating resources, it is necessary to ensure that the size of the video memory occupied by the target container does not exceed the preset video memory quota before and after the allocation.
[0258] When the video memory size occupied by the target container exceeds the preset video memory quota of the target container, the target process is killed to release the video memory resources occupied by the target process as soon as possible.
[0259] In some optional implementations, in order to improve the flexibility of video memory resource allocation, the present solution may also provide a function for setting a video memory allocation level. Accordingly, the target device may also perform the following operations:
[0260] Get the target container's video memory allocation level.
[0261] Among them, the video memory allocation level is used to determine whether to allocate the video memory resources of the first accelerator card based on the real-time video memory information of the process corresponding to each container process identification information and the preset video memory quota corresponding to the target container. When the video memory allocation level of the target container is the first level, the preset video memory quota corresponding to the target container is equal to the video memory resource size of the first accelerator card. Alternatively, when the video memory allocation level of the target container is the second level, the preset video memory quota corresponding to the target container is less than the video memory resource size of the first accelerator card, and the first level is higher than the second level. For example, the video memory of the first accelerator card is 32GB. When the video memory allocation level of the target container is set to the first level, the maximum video memory resource that can be allocated to the target container can be 32GB.
[0262] Specifically, when the video memory allocation level of the target container is the first level, as long as there are remaining video memory resources, the remaining video memory resources can be allocated to the target process. When the video memory allocation level of the target container is the first level, the process can be performed according to steps S4051 to S4055.
[0263] The method for allocating video memory resources provided in this embodiment runs different applications on different containers. Since the containers are isolated from each other, the training tasks run in the containers without affecting each other. The resource leakage or crash of one training task will not affect other training tasks, thereby improving the overall system stability. In addition, each container can use the corresponding accelerator card. At the same time, the maximum usable video memory resources of each container are limited by the preset video memory quota. In this way, before performing the video memory resource allocation operation, the real-time video memory information of each process of the target container can be obtained first. According to the real-time video memory information of each process of the target container and the preset video memory quota, it is determined whether to perform the video memory resource allocation operation. This can avoid different applications from grabbing the resources of different accelerator cards, and different applications from grabbing the video memory resources of the same accelerator card, resulting in the problem of overload and crash of the accelerator card and slowing down the computing speed. That is, the computing speed can be improved.
[0264] In this embodiment, a method for obtaining video memory information is provided, which can be executed by the above-mentioned target device. Figure 5 is a flow chart of a method for obtaining video memory information according to an embodiment of the present invention. Figure 5 As shown, the process includes the following steps:
[0265] Step S501, obtaining a video memory information obtaining instruction.
[0266] Specifically, when the user needs to query the video memory information of a certain accelerator card, the user can send a video memory information acquisition instruction to the target device through the client. Alternatively, the target device can periodically query the video memory information of the accelerator card and generate a video memory information acquisition instruction at each periodic triggering moment.
[0267] After obtaining the video memory information acquisition instruction, the target device will call the target function and initialize the value of the occupied video memory parameter in the target function to 0.
[0268] Step S502: parse the video memory information acquisition instruction to obtain the second accelerator card identification information.
[0269] Step S503: determining, according to the second accelerator card identification information, a second accelerator card corresponding to the second accelerator card identification information.
[0270] The second acceleration card is any one of the at least one acceleration card.
[0271] Step S504: Obtain the number of processes running on the second accelerator card.
[0272] Specifically, the target device may parse the video memory information acquisition instruction to obtain the second acceleration card identification information, determine the corresponding second acceleration card according to the second acceleration card identification information, and obtain the number of running processes on the second acceleration card.
[0273] Step S505: determine whether the number of processes running on the second accelerator card is greater than a preset number of processes.
[0274] Step S506: When it is determined that the number of processes running on the second acceleration card is greater than the preset number of processes, target alarm information is generated and fed back to the client.
[0275] Specifically, in order to avoid resource preemption and taking into account the different specifications of different accelerator cards, the number of executable processes and a preset process array can be set in advance for each accelerator card. The preset process array can include identification information corresponding to one or more preset processes.
[0276] The length of the preset process array corresponding to each accelerator card (that is, the preset number of processes mentioned above) can be fixed. When it is determined that the number of processes running on the second accelerator card is greater than the preset number of processes, it means that other processes that do not belong to the second accelerator card may have occupied resources. At this time, a target alarm message can be generated and fed back to the client, so that the user can find out the specific reason.
[0277] Step S507: when it is determined that the number of processes running on the second accelerator card is less than or equal to the preset number of processes, obtain identification information corresponding to the preset process of the second accelerator card and identification information corresponding to the real-time process running on the second accelerator card.
[0278] Among them, the preset process can include at least one, and the number of real-time processes can be at least one.
[0279] Specifically, when it is determined that the number of processes running on the second accelerator card is less than or equal to the preset number of processes, although these processes include some processes that do not belong to the second accelerator card, since the number of processes of the second accelerator card has not exceeded the preset number of processes at this time, further processing can be performed. The target device can obtain a preset process array corresponding to the second accelerator card according to the identification information of the second accelerator card, and obtain a real-time process array from the second accelerator card, wherein the real-time process array includes the identification information corresponding to the real-time process running on the second accelerator card.
[0280] Step S508: determining whether the target real-time process is a preset process among at least one preset process according to the identification information corresponding to the target real-time process and the identification information corresponding to the preset process.
[0281] The target real-time process is any real-time process among the at least one real-time process.
[0282] Step S509: when it is determined that the target real-time process is one of the at least one preset process according to the identification information corresponding to the target real-time process and the identification information corresponding to the preset process, the target real-time process is determined to be a normal process.
[0283] Step S510, when it is determined that the target real-time process is not one of the at least one preset process according to the identification information corresponding to the target real-time process and the identification information corresponding to the preset process, the target real-time process is determined to be an abnormal process and the target real-time process is killed.
[0284] Step S511, when at least one normal process is determined, the occupied video memory size of the second acceleration card is determined according to the video memory size occupied by each normal process.
[0285] Specifically, the target device can compare the two sets of process identification information obtained.
[0286] Step S512: Generate video memory information corresponding to the second accelerator card according to the size of the video memory occupied by the second accelerator card, and feed it back to the client.
[0287] Specifically, the target device can traverse the identification information corresponding to each real-time process in the real-time process array, and each time the identification information corresponding to a real-time process is traversed, it can be determined whether the identification information corresponding to the traversed real-time process is the identification information corresponding to a preset process in the preset process array. If yes, it can be determined that the real-time process is a normal process. At this time, the value of the occupied video memory parameter can be updated according to the video memory size occupied by the real-time process. If not, it can be determined that the real-time process is an abnormal process, that is, the real-time process belongs to the process that occupies the video memory resources. At this time, the real-time process can be killed to release the video memory resources it occupies. In this way, after traversing the identification information corresponding to each real-time process in the real-time process array, the occupied video memory size of the second accelerator card can be obtained. The target device can generate video memory information corresponding to the second accelerator card according to the occupied video memory size of the second accelerator card, and feedback it to the client. Alternatively, the video memory information corresponding to the second accelerator card can be generated according to the occupied video memory size and the total video memory size of the second accelerator card, and feedback it to the client.
[0288] It should be noted that the identification information corresponding to the preset process and the identification information corresponding to the real-time process can both be host process identification information or container process identification information.
[0289] The above execution process can be implemented by the following code:
[0290] size_tget_cndev_process_mem_usage(){
[0291] size_ttotal_mem = 0;
[0292] cndevice_tdev;
[0293] get_real_device_info(dev);
[0294] unsignedintnum=MAX_PROC_COUNT; / / MAX_PROC_COUNT=256
[0295] cndevProcessInfo_t pi[MAX_PROC_COUNT];
[0296] memset(pi,0,sizeof(cndevProcessInfo_t)*MAX_PROC_COUNT);
[0297] cndevReturn_tcndev_ret=cnDeviceGetComputeRunningProcesses(dev,&num,pi);
[0298] CHECK_CNDEV_RETURN(cndev_ret,
[0299] "cnDeviceGetComputeRunningProcesses");
[0300] if(num>MAX_PROC_COUNT){
[0301] WARN_PRT("cndev compute running processes num exceed buffer len,\
[0302] [num=%d,buff_len=%d]\n",num,MAX_PROC_COUNT);
[0303] num=MAX_PROC_COUNT;
[0304] }
[0305] if(0==num){
[0306] returntotal_mem;
[0307] }
[0308] std::unordered_set <int>pids;
[0309] get_share_mem_host_pids(pids);
[0310] for(int i = 0; i <num;i++){
[0311] if(pids.find(pi[i].pid)!=pids.end()){
[0312] total_mem+=pi[i].usedGpuMemory;
[0313] }
[0314] }
[0315] return total_mem;
[0316] }
[0317] The method for obtaining video memory information provided in this embodiment, first, realizes the refined management of video memory resources by setting a preset number of processes for each accelerator card. This method takes into account the specification differences of different accelerator cards, allows customized resource management strategies for different accelerator cards, and enhances the flexibility and adaptability of the system. Second, in the process of determining whether a process is normal, by comparing identification information, it is possible not only to identify which processes are legally occupying video memory, but also to track abnormal processes. Third, killing operations are taken for non-preset abnormal processes, which effectively prevents illegal occupation of resources, protects the resource requirements of preset processes, and ensures the smooth execution of key tasks.
[0318] In some optional implementations, a monitoring operation may be performed on each accelerator card, and the configuration process of real-time monitoring may be as follows:
[0319] Step 1: Obtain the serial number of the third accelerator card in the target device.
[0320] Step 2: Determine the device index of the third accelerator card according to the serial number of the third accelerator card in the target device.
[0321] Step three: determine the UUID corresponding to the third accelerator card according to the device index of the third accelerator card.
[0322] Step 4: Format the UUID corresponding to the third accelerator card to obtain a target character string.
[0323] Step 5: Obtain a device handle corresponding to the third accelerator card according to the target character string.
[0324] Step six: perform monitoring configuration on the third accelerator card according to the device handle corresponding to the third accelerator card.
[0325] Specifically, first, according to the serial number of the third accelerator card in the target device and cnCtxGetDevice(&cn_idx), the device index of the third accelerator card is obtained. Then, according to the device index of the third accelerator card and calling cnDeviceGetUuid(&uuid,cn_idx), the UUID corresponding to the third accelerator card is obtained. Further, the snprintf function is used to format the byte data of the UUID into a string uuid_str (that is, the target string). Finally, the device handle corresponding to the UUID can be obtained according to the target string and cnDeviceGetHandleByUUID(uuid_str,&dev), and stored in the passed in reference parameter dev. Among them, the device handle is used to interact with the cnDev library.
[0326] intget_device_info(cnDevice_t&dev){
[0327] CNdevicecn_idx;
[0328] CNresult ret=cnCtxGetDevice(&cn_idx);
[0329] CHECK_CN_RETURN(ret,,"cnCtxGetDevice");
[0330] CNuuiduuid;
[0331] ret=cnDeviceGetUuid(&uuid,cn_idx);
[0332] CHECK_CN_RETURN(ret,,"cnDeviceGetUuid");
[0333] charuuid_str
[64] ;
[0334] snprintf(uuid_str,64,"AIU-%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
[0335] (unsigned char)uuid.bytes[0],(unsigned char)uuid.bytes[1],
[0336] (unsigned char)uuid.bytes[2],(unsigned char)uuid.bytes[3],
[0337] (unsigned char)uuid.bytes[4],(unsigned char)uuid.bytes[5],
[0338] (unsigned char)uuid.bytes[6],(unsigned char)uuid.bytes[7],
[0339] (unsigned char)uuid.bytes[8],(unsigned char)uuid.bytes[9],
[0340] (unsigned char)uuid.bytes
[10] ,(unsigned char)uuid.bytes
[11] ,
[0341] (unsigned char)uuid.bytes
[12] ,(unsigned char)uuid.bytes
[13] ,
[0342] (unsigned char)uuid.bytes
[14] ,(unsigned char)uuid.bytes
[15] );
[0343] cnDevReturn_tcndev_ret=cnDeviceGetHandleByUUID(uuid_str,&dev);
[0344] CHECK_NVML_RETURN(cndev_ret,"cnDeviceGetHandleByUUID");
[0345] return 0;
[0346] }
[0347] In this way, after the monitoring configuration of the accelerator card is performed, the monitoring of the accelerator card can be implemented so as to timely understand the real-time video memory information or working status of the accelerator card, etc.
[0348] Since the applications corresponding to the training tasks running in different containers are developed by different manufacturers, there may be more resource-grabbing mechanisms for some applications. Therefore, this solution obtains the real-time video memory information of the corresponding container after hijacking the video memory allocation instruction to determine whether to allocate video memory resources, monitor the accelerator card, obtain the real-time video memory information of the accelerator card, and perform related operations based on the real-time video memory information of the accelerator card, etc., and kills the process that grabs resources in real time, which can avoid most of the resource-grabbing operations and ensure that each container can execute tasks within the resource range of the preset video memory quota. Further, it can improve the task execution speed and maintain system stability.
[0349] In this embodiment, a device for allocating video memory resources is also provided, and the device is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made are not repeated here. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0350] This embodiment provides a device for allocating video memory resources, such as Figure 6 As shown, including:
[0351] The acquisition module 601 is used to acquire a video memory allocation instruction of a target container, parse the video memory allocation instruction, and obtain a task type and at least one container process identification information, wherein the target container is any one of the at least one container;
[0352] The determination module 602 is used to determine, according to the task type, first accelerator card identification information corresponding to the task type; and determine, according to the first accelerator card identification information, a first accelerator card corresponding to the first accelerator card identification information, wherein the first accelerator card is one of the at least one accelerator card;
[0353] The acquisition module 601 is further configured to acquire, from the first accelerator card, real-time video memory information of a process corresponding to each container process identification information according to each container process identification information in the at least one container process identification information;
[0354] The determination module 602 is further used to determine whether to allocate the video memory resources of the first accelerator card according to the real-time video memory information of the process corresponding to each container process identification information and the preset video memory quota corresponding to the target container.
[0355] In some optional implementations, the real-time video memory information includes the size of the video memory occupied by the process;
[0356] The determination module 602 is specifically configured to:
[0357] Determine the video memory size occupied by the target container according to the video memory size occupied by the process corresponding to each container process identification information;
[0358] Determine the remaining video memory size of the target container according to the video memory size occupied by the target container and the preset video memory quota corresponding to the target container;
[0359] Determine whether the video memory size occupied by the target container is less than or equal to the preset video memory quota corresponding to the target container, and whether the remaining video memory size of the target container is greater than or equal to the preset allocated video memory size;
[0360] When it is determined that the video memory size occupied by the target container is less than or equal to the preset video memory quota corresponding to the target container, and the remaining video memory size of the target container is greater than or equal to the preset allocated video memory size, based on the preset allocated video memory size, video memory resources on the first accelerator card that are equal to the preset allocated video memory size are allocated to the target process corresponding to the video memory allocation instruction.
[0361] In some optional implementations, the determination module 602 is specifically configured to:
[0362] When it is determined that the video memory size occupied by the target container is greater than the preset video memory quota corresponding to the target container, and / or the remaining video memory size of the target container is less than the preset allocated video memory size, the target process is killed.
[0363] In some optional implementations, the acquisition module 601 is further used to:
[0364] The video memory allocation level of the target container is obtained, wherein the video memory allocation level is used to determine whether to allocate the video memory resources of the first accelerator card based on the real-time video memory information of the process corresponding to each container process identification information and the preset video memory quota corresponding to the target container.
[0365] In some optional implementations, when the video memory allocation level of the target container is the first level, the preset video memory quota corresponding to the target container is equal to the video memory resource size of the first accelerator card;
[0366] Alternatively, when the graphics memory allocation level of the target container is the second level, the preset graphics memory quota corresponding to the target container is smaller than the graphics memory resource size of the first acceleration card, and the first level is higher than the second level.
[0367] In some optional implementations, the acquisition module 601 is further used to:
[0368] Get the video memory information acquisition instruction;
[0369] Parsing the video memory information acquisition instruction to obtain the second accelerator card identification information;
[0370] Determining, according to the second accelerator card identification information, a second accelerator card corresponding to the second accelerator card identification information, wherein the second accelerator card is one accelerator card of the at least one accelerator card;
[0371] Get the number of processes running on the second accelerator card;
[0372] Determine whether the number of processes running on the second accelerator card is greater than a preset number of processes;
[0373] When it is determined that the number of processes running on the second acceleration card is greater than the preset number of processes, target alarm information is generated and fed back to the client.
[0374] In some optional implementations, the acquisition module 601 is further used to:
[0375] When it is determined that the number of processes running on the second accelerator card is less than or equal to the preset number of processes, obtaining identification information corresponding to the preset process of the second accelerator card and identification information corresponding to the real-time process running on the second accelerator card, wherein the preset process includes at least one and the number of the real-time process is at least one;
[0376] Determine whether the target real-time process is a preset process in at least one preset process according to the identification information corresponding to the target real-time process and the identification information corresponding to the preset process, wherein the target real-time process is any real-time process in the at least one real-time process;
[0377] When it is determined that the target real-time process is one of the at least one preset process according to the identification information corresponding to the target real-time process and the identification information corresponding to the preset process, the target real-time process is determined to be a normal process;
[0378] or,
[0379] When it is determined that the target real-time process is not one of the at least one preset process according to the identification information corresponding to the target real-time process and the identification information corresponding to the preset process, the target real-time process is determined to be an abnormal process, and the target real-time process is killed;
[0380] When at least one normal process is determined, determining the size of the video memory occupied by the second accelerator card according to the size of the video memory occupied by each normal process;
[0381] According to the size of the video memory occupied by the second acceleration card, video memory information corresponding to the second acceleration card is generated and fed back to the client.
[0382] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.
[0383] The device for allocating video memory resources in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.
[0384] The embodiment of the present invention also provides a computer device having the above Figure 6 A device configured with video memory resources is shown.
[0385] See also Figure 7 , Figure 7 is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, such as Figure 7 As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 7 A processor 10 is taken as an example.
[0386] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.
[0387] The memory 20 stores instructions executable by at least one processor 10, so that the at least one processor 10 executes the method shown in the above embodiment.
[0388] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0389] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.
[0390] The computer device further comprises a communication interface 30 for the computer device to communicate with other devices or a communication network.
[0391] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.
[0392] A part of the present invention may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. Those skilled in the art should understand that the existence of the computer program instruction in a computer-readable medium includes, but is not limited to, a source file, an executable file, an installation package file, etc., and accordingly, the way in which the computer program instruction is executed by the computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium may be any available computer-readable storage medium or communication medium accessible to the computer.
[0393] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.< / int> < / int> < / std::string> < / std::mutex> < / std::thread> < / aiu>
Claims
1. A method for allocating video memory resources, characterized in that: The method is applied to a target device, the target device is connected to at least one accelerator card, and the target device is installed with at least one container, and the method includes: Obtaining a video memory allocation instruction of a target container, parsing the video memory allocation instruction, and obtaining a task type and at least one container process identification information, wherein the target container is any one of the at least one containers; Determining, according to the task type, first accelerator card identification information corresponding to the task type; Determining, according to the first accelerator card identification information, a first accelerator card corresponding to the first accelerator card identification information, wherein the first accelerator card is one accelerator card of the at least one accelerator card; According to each of the at least one container process identification information, acquiring, from the first accelerator card, real-time video memory information of a process corresponding to each of the container process identification information; Determine whether to allocate the video memory resources of the first accelerator card according to the real-time video memory information of the process corresponding to each of the container process identification information and the preset video memory quota corresponding to the target container.
2. The method according to claim 1, characterized in that: The real-time video memory information includes the video memory size occupied by the process; The determining whether to allocate the video memory resources of the first accelerator card according to the real-time video memory information of the process corresponding to each of the container process identification information and the preset video memory quota corresponding to the target container includes: Determine the size of the video memory occupied by the target container according to the size of the video memory occupied by the process corresponding to each of the container process identification information; Determine the remaining video memory size of the target container according to the video memory size occupied by the target container and the preset video memory quota corresponding to the target container; Determine whether the video memory size occupied by the target container is less than or equal to a preset video memory quota corresponding to the target container, and whether the remaining video memory size of the target container is greater than or equal to a preset allocated video memory size; When it is determined that the video memory size occupied by the target container is less than or equal to the preset video memory quota corresponding to the target container, and the remaining video memory size of the target container is greater than or equal to the preset allocated video memory size, video memory resources on the first accelerator card that are equal to the preset allocated video memory size are allocated to the target process corresponding to the video memory allocation instruction according to the preset allocated video memory size.
3. The method according to claim 2, characterized in that When it is determined that the video memory size occupied by the target container is greater than the preset video memory quota corresponding to the target container, and / or the remaining video memory size of the target container is less than the preset allocated video memory size, the method further includes: Kills the target process.
4. The method according to claim 1, characterized in that: The method further comprises: Obtain a video memory allocation level of the target container, wherein the video memory allocation level is used to determine whether to allocate video memory resources of the first accelerator card based on real-time video memory information of a process corresponding to each process identification information of the container and a preset video memory quota corresponding to the target container.
5. The method according to claim 4, characterized in that When the video memory allocation level of the target container is the first level, the preset video memory quota corresponding to the target container is equal to the video memory resource size of the first accelerator card; Alternatively, when the graphics memory allocation level of the target container is the second level, the preset graphics memory quota corresponding to the target container is smaller than the graphics memory resource size of the first acceleration card, and the first level is higher than the second level.
6. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: Get the video memory information acquisition instruction; Parsing the video memory information acquisition instruction to obtain second accelerator card identification information; Determining, according to the second accelerator card identification information, a second accelerator card corresponding to the second accelerator card identification information, wherein the second accelerator card is one of the at least one accelerator card; Obtain the number of processes running on the second accelerator card; Determining whether the number of processes running on the second accelerator card is greater than a preset number of processes; When it is determined that the number of processes running on the second acceleration card is greater than the preset number of processes, target alarm information is generated and fed back to the client.
7. The method according to claim 6, characterized in that When it is determined that the number of processes running on the second accelerator card is less than or equal to the preset number of processes, the method further includes: Acquire identification information corresponding to a preset process of the second accelerator card and identification information corresponding to a real-time process running on the second accelerator card, wherein the preset process includes at least one and the number of the real-time process is at least one; Determine, according to the identification information corresponding to the target real-time process and the identification information corresponding to the preset process, whether the target real-time process is a preset process in at least one of the preset processes, wherein the target real-time process is any real-time process in at least one of the real-time processes; When it is determined that the target real-time process is one of at least one of the preset processes according to the identification information corresponding to the target real-time process and the identification information corresponding to the preset process, the target real-time process is determined to be a normal process; or, When it is determined that the target real-time process is not one of the preset processes according to the identification information corresponding to the target real-time process and the identification information corresponding to the preset process, the target real-time process is determined to be an abnormal process, and the target real-time process is killed; When at least one normal process is determined, determining the size of the video memory occupied by the second accelerator card according to the size of the video memory occupied by each normal process; According to the size of the video memory occupied by the second accelerator card, video memory information corresponding to the second accelerator card is generated and fed back to the client.
8. A device for allocating video memory resources, characterized in that: The device is applied to a target device, the target device is connected to at least one accelerator card, the target device is installed with at least one container, and the device includes: an acquisition module, configured to acquire a video memory allocation instruction of a target container, parse the video memory allocation instruction, and obtain a task type and at least one container process identification information, wherein the target container is any one of the at least one containers; a determination module, configured to determine, according to the task type, first accelerator card identification information corresponding to the task type; and determine, according to the first accelerator card identification information, a first accelerator card corresponding to the first accelerator card identification information, wherein the first accelerator card is one of the at least one accelerator card; The acquisition module is further configured to acquire, from the first accelerator card, real-time video memory information of a process corresponding to each of the container process identification information according to each of the container process identification information in the at least one container process identification information; The determination module is further used to determine whether to allocate the video memory resources of the first accelerator card according to the real-time video memory information of the process corresponding to each of the container process identification information and the preset video memory quota corresponding to the target container.
9. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the method for allocating video memory resources according to any one of claims 1 to 7 by executing the computer instructions.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the method for allocating video memory resources according to any one of claims 1 to 7.
Citation Information
Cited By
Accelerator card resource monitoring method and device, storage medium and program product
CN119273530A
