Method, device and equipment for identifying and accessing accelerator card device
By initializing the tree structure in the driver and establishing the BDF and device file mapping relationship of the accelerator card device, the problem of cumbersome device access in the multi-accelerator card environment is solved, convenient identification and access of the accelerator card device is achieved, and operation efficiency is improved.
Patent Information
- Application Number
- CN202410531925.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-29
- Publication Date
- 2025-04-01
- Estimated Expiration
- 2044-04-29
AI Technical Summary
In the case where the accelerator card device BDF is uncertain, especially when multiple accelerator cards are used simultaneously, the application access to the accelerator card device is complicated and inefficient.
The driver initializes the tree structure in memory, obtains the functional identification BDF of the accelerator card device, mounts it to the tree structure, and creates a device file corresponding to the accelerator card device in the system device directory, establishes a mapping relationship between the BDF and the device file, and the application can identify and access the accelerator card device through the device file according to the mapping relationship.
It realizes convenient identification and access of accelerator card devices, and users do not need to pay attention to the specific device identification BDF, which improves operation efficiency and convenience of equipment management.
Smart Images

Figure CN118426847B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method, device and equipment for identifying and accessing an accelerator card device. Background Art
[0002] The brain-like computing accelerator card is a self-developed high-performance computing accelerator card. The brain-like computing accelerator card (hereinafter referred to as "accelerator card" or "accelerator card device") communicates and transmits data with the computer through the high-speed serial computer expansion bus standard (Peripheral Component Interconnect Express, PCIE) bus.
[0003] The accelerator card is installed in the PCIE slot on the computer, such as Figure 1 As shown in the figure. During the application process, the driver of the PCIE device is loaded on the operating system to realize the use of the accelerator card. The accelerator card device and the corresponding software constitute the brain-like computing application system, the structure of which is as follows: Figure 2 shown.
[0004] When using multiple accelerator cards, different accelerator cards are generally distinguished by device identification / BDF (Bus, Device, Function). On a computer, different PCIE slots have different corresponding device BDFs, but the BDF value is not fixed. The device BDF will be different for different computers and different slots. Even the device BDF corresponding to the same slot of the same computer will change due to the use of the device. Therefore, the difficulty in identifying the accelerator card will lead to inconvenience and inefficiency in the use of the accelerator card.
[0005] In order to solve this problem, the device BDF can be directly specified when the application reads and writes the accelerator card to access the accelerator card. The device driver can dynamically detect the PCIE device and accelerator card, and the accelerator card device BDF list can be stored in the memory during program design. The application obtains the device BDF through system calls and uses it.
[0006] However, due to the uncertainty and variability of the accelerator card device BDF, directly using the device BDF will cause inconvenience or even failure to the accelerator card application. In addition, for the software and components of the application layer, as well as cluster applications, only the number and identification of available accelerator card devices in the computer system and network nodes are concerned, and the specific value of the device BDF is not concerned. Summary of the invention
[0007] The present invention provides an accelerator card device identification and access method, device and equipment, which solves the problem that when the BDF of the accelerator card device is uncertain, especially when multiple accelerator cards are used simultaneously, the application program accessing the accelerator card device is cumbersome and inefficient.
[0008] A method for identifying and accessing an accelerator card device, comprising:
[0009] The driver initializes the tree structure in memory;
[0010] Obtaining a function identifier BDF of the accelerator card device, mounting it to the tree structure, creating a device file corresponding to the accelerator card device under the system device directory, and establishing a mapping relationship between the BDF and the device file;
[0011] The application identifies and accesses the accelerator card device through the device file according to the mapping relationship.
[0012] In one embodiment of the present invention, the tree structure is a radix tree data structure.
[0013] In an embodiment of the present invention, the step of obtaining a function identification BDF of an accelerator card device, mounting it to the tree structure, creating a device file corresponding to the accelerator card device under a system device directory, and establishing a mapping relationship between the BDF and the device file specifically includes: when the system detects an accelerator card device, obtaining the function identification BDF of the accelerator card device; in a probe function of a driver, mounting the BDF to the tree structure, and creating a device file corresponding to the accelerator card device under a system device directory; mapping the BDF and the device file one by one to determine a mapping relationship between the device file and the BDF; and saving the mapping relationship between the device file and the BDF into a structure array.
[0014] In one embodiment of the present invention, the application identifies and accesses the accelerator card device through the device file according to the mapping relationship, specifically including: when the application uses the accelerator card device, the accelerator card device is accessed by opening the device file corresponding to the accelerator card device in the system device directory; when the device file is opened, the open function of the driver program obtains the name of the device file accessed by the application, and determines the mapping relationship between the accessed device file and the BDF; determines the corresponding BDF according to the mapping relationship, identifies the corresponding accelerator card device according to the BDF, and implements reading and writing of the accelerator card device through the read / write function.
[0015] In one embodiment of the present invention, when removing an accelerator card device with an established mapping relationship, the method further includes: the driver removes the BDF corresponding to the accelerator card device from the tree structure, and deletes the device file corresponding to the accelerator card device under the system device directory, thereby deleting the established mapping relationship.
[0016] In one embodiment of the present invention, when multiple accelerator card devices are accessed in parallel, the characteristics of each accelerator card device are obtained, and a task queue is allocated to each accelerator card device according to the different characteristics of the accelerator card; each task applying for the accelerator card is evaluated, and the task is added to the corresponding task queue according to the evaluation result; or when multiple accelerator card devices are accessed in parallel, the concurrency control mechanism is initialized according to a preset concurrency control strategy.
[0017] An identification and access device for an acceleration card device, comprising:
[0018] Initialization module, used to initialize the tree structure in memory through the driver;
[0019] A device file creation module, used for obtaining a function identifier BDF of an accelerator card device, mounting it to the tree structure, creating a device file corresponding to the accelerator card device under a system device directory, and establishing a mapping relationship between the BDF and the device file;
[0020] The identification and access module is used for the application to identify and access the accelerator card device through the device file according to the mapping relationship.
[0021] In one embodiment of the present invention, the device also includes an acceleration card removal module, which is used for, when removing an acceleration card device with an established mapping relationship, the driver removes the BDF corresponding to the acceleration card device from the tree structure, and deletes the device file corresponding to the acceleration card device under the system device directory, thereby deleting the established mapping relationship.
[0022] An identification and access device for an acceleration card device, comprising:
[0023] at least one processor; and,
[0024] A memory connected to the at least one processor via a bus; wherein,
[0025] The memory stores instructions executable by the at least one processor, and the instructions are executed to implement the method described in any one of the above embodiments.
[0026] A non-volatile storage medium stores computer executable instructions, wherein the computer executable instructions are executed by a processor to implement the method described in any one of the above embodiments.
[0027] The present invention provides an identification and access method, apparatus and device for an accelerator card device, which at least includes the following beneficial effects: by associating a device identifier BDF with a device file, a mapping relationship between the two is established, and the BDF can be obtained from a radix tree, thereby realizing file expression of specific parameters of the device; users can access multiple brain-like computing accelerator cards only through the device file without paying attention to the specific device identifier, making the devices easier to distinguish while providing users with a convenient usage environment. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0029] Figure 1 A schematic diagram of the structure of a computer, a PCIE slot and an accelerator card provided in an embodiment of the present invention;
[0030] Figure 2 The software and hardware hierarchical structure of the computer system and accelerator card provided in the embodiment of the present invention;
[0031] Figure 3 A schematic diagram of the steps of a method for identifying and accessing an accelerator card device provided by an embodiment of the present invention;
[0032] Figure 4 A schematic diagram of a device mapping process provided by an embodiment of the present invention;
[0033] Figure 5 A schematic diagram of an accelerator card access process provided by an embodiment of the present invention;
[0034] Figure 6 A schematic diagram of an identification and access device for an accelerator card device provided by an embodiment of the present invention;
[0035] Figure 7 A schematic diagram of an identification and access device for an accelerator card device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0036] In order to make the purpose, technical scheme and advantages of the present invention clearer, the present invention will be described clearly and completely in conjunction with the specific embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0037] It should be noted that it is explicitly and implicitly understood by those of ordinary skill in the art that the embodiments described in the present invention can be combined with other embodiments without conflict. Unless otherwise defined, the technical terms or scientific terms involved in the present invention should be the usual meanings understood by people with ordinary skills in the technical field to which the present invention belongs. The words "one", "a", "a", "the" and the like involved in the present invention do not indicate a quantitative limitation and may represent the singular or plural. The terms "including", "comprising", "having" and any of their variations involved in the present invention are intended to cover non-exclusive inclusions; the terms "first", "second", "third", etc. involved in the present invention are merely to distinguish similar objects and do not represent a specific ordering of objects.
[0038] Some concepts involved in this application are explained below.
[0039] Radix tree, or compressed prefix tree, is a more space-saving Trie (prefix tree). For each node of the radix tree, if the node is a certain subtree, it is merged with the parent node. Radix tree can be used to build associative arrays.
[0040] PCIE, which refers to PCI Express, is a computer bus standard. In PCIE, each device connected to the motherboard has a unique address, called BDF.
[0041] BDF is the abbreviation of Bus, Device, Function, where Bus refers to the PCIE bus number (there may be multiple PCIE buses in a system), Device refers to the number of a device connected to the bus, and Function refers to the numbers of different functions on the same device.
[0042] PCIE BDF is an identifier used to uniquely identify PCIE devices. BDF stands for bus number, device number, and function number. These three numbers combined together can identify a specific PCIE device.
[0043] Mounting refers to connecting files and directories on a storage device (such as a hard disk, CD-ROM, or shared resource) to the operating system's file system so that they can be accessed and used. In Linux or Unix-like systems, this usually involves connecting a device or partition to a directory. In this way, users can operate files and directories on the storage device by accessing this directory. The mounting operation usually requires understanding whether the operating system's file system format supports the device or file system to be mounted.
[0044] System device directory / dev. In Linux system, the / dev directory is used to store device files. Each file points to a system device. User applications can use these device files to operate the corresponding real hardware devices.
[0045] The present invention proposes an identification and access method, device and equipment for an accelerator card device, which solves the problem of using multiple brain-like accelerator cards in a Linux environment. The method is implemented by a driver and an application program. The computer on which the accelerator card device is installed is a personal computer (PC), or a workstation (Workstation), or a server (Server); it has at least two PCIE slots and can install at least two accelerator card devices. In this method, the accelerator card device identifier BDF is associated with the accelerator card device file, and the BDF can be obtained from the radix tree, realizing the file expression of the specific parameters of the device; the user only needs to access multiple brain-like accelerator cards through the device file under the system device directory without paying attention to the specific device identifier, so that the user can use it conveniently and access the accelerator card accurately and efficiently.
[0046] The specific instructions are given below.
[0047] Figure 3 A schematic diagram of the steps of a method for identifying and accessing an accelerator card device provided by an embodiment of the present invention, Figure 3 The identification and access method of the accelerator card device shown can be executed by the identification and access device of the accelerator card device, and the identification and access device of the accelerator card device can be set in a computer, for example, the computer can be a personal computer, or a workstation, or a server, and the server can be a physical server including an independent host, a virtual server carried by a host cluster, a cloud server, etc., which is not limited in the embodiment of the present invention. The identification and access method of the accelerator card device may include the following steps:
[0048] S310: Initialize the tree structure in the memory through the driver.
[0049] In one embodiment of the present invention, the tree structure is a radix tree data structure.
[0050] Specifically, in the initialization phase, the driver initializes the radix tree dev_tree in the memory by calling the init function to store and manage the function identifier BDF of the accelerator card device, and creates a device file chip under the system device directory / dev.
[0051] By defining a radix tree data structure, the specific accelerator card device can be quickly located in the subsequent steps, thereby improving the access speed; and the tree structure can easily add and delete nodes, which also provides flexibility for the subsequent increase and decrease of accelerator card devices.
[0052] S320: Obtain the function identifier BDF of the accelerator card device, mount it to the tree structure, create a device file corresponding to the accelerator card device in the system device directory, and establish a mapping relationship between the BDF and the device file.
[0053] Specifically, there are three mounting methods for the accelerator card device: 1. Static loading method: when the computer system is turned off, insert or remove the accelerator card, then turn on the computer and load / load the driver; 2. Dynamic mounting method: when the computer system is running and the driver is loaded, hot-plug / unplug the accelerator card; 3. A combination of the above two methods.
[0054] When a new accelerator card is inserted into the PCIE slot, the system detects the new accelerator card device, and the driver obtains the function identifier BDF of the accelerator card device and mounts it into a tree structure, such as a radix tree data structure. At the same time, the driver also creates a device file corresponding to the accelerator card device in the system device directory. In this way, each accelerator card device has a unique device file associated with it.
[0055] In addition to BDF, you can also consider adding other device attributes, such as device ID, vendor ID, subsystem ID, etc., to perform more accurate accelerator card device identification; or introduce device feature codes or serial numbers to further distinguish different accelerator cards of the same type.
[0056] In one embodiment of the present invention, a function identifier BDF of an accelerator card device is obtained, mounted to a tree structure, and a device file corresponding to the accelerator card device is created under a system device directory, and a mapping relationship between the BDF and the device file is established, specifically including: when the system detects an accelerator card device, the function identifier BDF of the accelerator card device is obtained; in a probe function of a driver, the BDF is mounted to a tree structure, and a device file corresponding to the accelerator card device is created under a system device directory; the BDF and the device file are mapped one by one to determine a mapping relationship between the device file and the BDF; and the mapping relationship between the device file and the BDF is saved in a structure array.
[0057] Specifically, Figure 4As shown in the figure, if the operating system detects the existence of the brain-like computing accelerator card device, it can obtain one or more device function identifiers BDF of the accelerator card from the system by calling the probe function in the driver, which are recorded as BDF-1, BDF-2, BDF-3, ..., and so on. At this time, the BDF of the accelerator card is mounted to the radix tree dev_tree, and the device files chip1, chip2, chip3, ..., and so on corresponding to the accelerator card are created in the system device directory / dev.
[0058] By binding the BDF of the brain-like accelerator card device to the device file, a one-to-one correspondence is established between the BDF and the device file, for example: chip1 corresponds to BDF-1, chip2 corresponds to BDF-2, chip3 corresponds to BDF-3, and so on; and the mapping relationship is saved in a structure array. In this way, when the BDF of the accelerator card device is uncertain and multiple accelerator cards are used at the same time, the accelerator card BDF can be quickly distinguished and determined, so as to quickly locate the corresponding accelerator card device.
[0059] By establishing a mapping relationship between BDF and device files, each accelerator card device has a unique identifier for easy management and access. Users can read and write accelerator card devices by simply accessing the device file without having to worry about the underlying hardware details. For users, the specific identification of the device is transparent, and they only need to know the name of the device file to access it.
[0060] Whenever a new accelerator card is inserted, a corresponding device file is created in the system device directory and associated with the BDF through a mapping relationship. However, as the number of accelerator cards increases, the naming and management of device files may become complicated, increasing the possibility of errors.
[0061] In one embodiment of the present invention, in order to avoid the above problems, a clear naming rule is formulated for the accelerator card device file, such as using the naming method of "accelerator card type_serial number" to facilitate rapid identification and management. An existing device manager tool can also be developed or adopted to centrally manage the accelerator card device files and provide a visual interface for viewing, modifying and deleting device files.
[0062] S330: The application identifies and accesses the accelerator card device through the device file according to the mapping relationship.
[0063] In one embodiment of the present invention, an accelerator card device is identified and accessed according to a mapping relationship, specifically including: when an application uses the accelerator card device, the accelerator card device is accessed by opening a device file corresponding to the accelerator card device in a system device directory; when the device file is opened, the open function of the driver program obtains the name of the device file accessed by the application program, and determines a mapping relationship between the accessed device file and the BDF; the corresponding BDF is determined according to the mapping relationship, the corresponding accelerator card device is identified according to the BDF, and the reading and writing of the accelerator card device are realized through the read / write function.
[0064] Specifically, Figure 5 As shown in the figure, the application only needs to access the accelerator card device file chip1 under the system device directory / dev to read and write the accelerator card corresponding to BDF-1; access the device file chip2 to read and write the accelerator card corresponding to BDF-2; and so on. This method allows the application to access the accelerator card device conveniently and accurately.
[0065] Through the above method, the application does not need to write complex hardware access code, but only needs to use standard file operation functions to access the accelerator card device. Since the access method is based on the file system, this method has good portability on different operating systems and platforms.
[0066] In one embodiment of the present invention, in order to ensure the security of access to the accelerator card device, the driver may also implement error handling and permission checking in the open function to ensure that only authorized applications can access the accelerator card device.
[0067] Specifically, in Linux systems, each file and directory has permission bits associated with it, which determine which users or user groups can read, write, or execute operations on it. These permissions also apply to device files.
[0068] System administrators can use the chmod command or similar mechanisms to set device file permissions so that only applications from a specific user or user group can access the accelerator card device.
[0069] In addition to permission checks, you can also set the ownership of device files. With the chown command, system administrators can assign ownership of device files to specific users or user groups. In this way, only the user or application in the user group that owns the device can open the device file.
[0070] To further ensure the access security of the accelerator card device, error handling needs to be performed in the open function of the driver. When errors such as device does not exist or the device is busy occur, the driver should return an appropriate error code, such as EACCES (access denied). In this way, the application can handle the error code accordingly and record the error information through the log system, such as displaying an error message to the user or trying other operations.
[0071] In this way, based on the above access control mechanism, the security and stability of the system are enhanced.
[0072] To avoid problems where exceptions are difficult to track and troubleshoot when error handling is performed in the driver, a debug printing mechanism is set up to add detailed debug print statements to key parts of the driver (such as device detection, file creation, etc.) to output key information and error codes for administrators to view and analyze.
[0073] In one embodiment of the present invention, when removing an accelerator card device with an established mapping relationship, the driver removes the BDF corresponding to the accelerator card device from the tree structure, deletes the device file corresponding to the accelerator card device in the system device directory, and deletes the established mapping relationship.
[0074] Specifically, in order to save system resources, for an accelerator card device that has been removed from the hardware level, or when the accelerator card driver is uninstalled / unloaded, an operation of removing the accelerator card at the software level is performed, and the corresponding device file is deleted.
[0075] The process of handling the hot-plug event of the accelerator card when the computer is powered on includes:
[0076] 1. When a new accelerator card is inserted into the PCIE slot, that is, when the system detects the new accelerator card device and obtains the function identifier BDF of the accelerator card device, the probe function of the driver program will mount the BDF to the tree structure, create a new device file corresponding to the accelerator card device in the system device directory, and map the BDF and the device file one by one to determine the mapping relationship between the device file and the BDF.
[0077] 2. When the original accelerator card is unplugged from the PCIE slot, the driver will find and remove the original BDF from the tree structure, and delete the device file corresponding to the accelerator card device in the system device directory. The mapping relationship between the device file and the BDF will be cancelled immediately.
[0078] For example, the driver modifies the radix tree dev_tree, removes the function identifier BDF corresponding to the accelerator card device, such as BDF-1 and BDF-2; deletes the device files corresponding to the accelerator card device in the system device directory / dev, such as chip1 corresponding to BDF-1 and chip2 corresponding to BDF-2; in the structure array that stores the mapping relationship, the mapping relationship and nodes between chip1 and BDF-1, and between chip2 and BDF-2 are removed immediately. That is, the accelerator cards corresponding to BDF-1 and BDF-2 are no longer accessible.
[0079] In one embodiment of the present invention, a detection and processing mechanism, a verification mechanism and a file management mechanism for hot plugging events are added to the driver.
[0080] Specifically, during the hot-swapping process of the accelerator card, a series of problems may occur, which mainly involve system stability, data security, and the complexity of device management.
[0081] 1. When the accelerator card is hot-plugged, the driver may fail to respond or handle this situation in a timely manner, resulting in inconsistency between the driver status and the actual hardware status, causing system crashes, freezes, or improper resource release, affecting the normal operation of other devices. To address this issue that affects system stability, update the driver, add a detection and processing mechanism for hot-plug events, and implement a state synchronization mechanism in the driver to ensure that the driver status is consistent with the hardware status. By designing a resource pre-allocation and recycling mechanism, ensure that resources can be correctly released when the accelerator card is removed. Monitor resource usage and clean up resources that are not released normally.
[0082] 2. Hot-plugging may cause data transmission interruption, data loss or corruption, affecting data consistency and integrity. To address this, a verification mechanism can be added during the data transmission process to ensure data integrity. Once data transmission interruption or data corruption is found, the transmission should be suspended immediately and the problem should be repaired. Implement a hot-plug processing mechanism. When the accelerator card is removed, suspend the data transmission and processing tasks related to the accelerator card to avoid data loss and corruption. Design a data synchronization mechanism to ensure data consistency between multiple accelerator cards. At the same time, regularly back up key data so that it can be quickly restored when problems occur.
[0083] 3. Hot plugging may cause confusion between device files and hardware, increasing the difficulty of device management. To ensure the normal operation of the system, the status of the accelerator card in the system should be monitored and managed in real time. When a new accelerator card is added to the system, the device manager should be able to automatically detect and update the device file list; when the accelerator card is removed or fails, the device manager should be able to update the status accordingly and notify the system. Automatic identification and configuration of the accelerator card can be achieved by writing device identification and configuration scripts or tools. When a new accelerator card is inserted, the system can automatically detect and configure the device, reducing the complexity of device management.
[0084] In one embodiment of the present invention, the currently running operating system and kernel version are identified, and the corresponding code blocks are searched according to the identified target operating system and kernel version to generate a driver binary file specific to the target system.
[0085] Specifically, for different versions of operating systems and kernels, the interfaces and functions used by the driver are different, which makes the driver incompatible or unable to work properly on some systems. Therefore, support for different operating systems or kernel versions is added to the driver, and conditional compilation and runtime checks are used to ensure that the driver can work correctly on different systems.
[0086] To ensure the compatibility of the driver, the currently running operating system and kernel version are identified through predefined macros, system calls or specific APIs. According to different operating systems and kernel versions, a series of conditional compilation macros are defined. For example, for the Linux kernel, different macros can be defined according to LINUX_VERSION_CODE. Before compiling the driver, set appropriate compilation flags or define macros according to the target system or kernel version. Use preprocessing instructions such as #ifdef, #ifndef, #if to include or exclude specific code blocks. In this way, certain codes will be included or excluded according to the conditions during compilation, and a driver binary file specific to the target system will be generated.
[0087] For example, the following macros have been used in the version.h file in the Linux system resource directory to define the operating system version and calculation method:
[0088] #define LINUX_VERSION_CODE 2266002
[0089] #define KERNEL_VERSION(a,b,c)(((a)<<16)+((b)<<8)+(c)) In the driver, include the version.h file using the following preprocessor directive:
[0090] #include<linux / version.h>
[0091] In the following statements, use the following structures and methods to control the flow of the program:
[0092] #if LINUX_VERSION_CODE <KERNEL_VERSION(5,0,0)
[0093] statement1;
[0094] #else
[0095] statement2;
[0096] #endif
[0097] Among them, statement1 and statement2 are program statements, which can be variable declarations or executable statements, including functions, operation expressions, etc. In this example, statement1 is executed only when the current condition satisfies LINUX_VERSION_CODE>KERNEL_VERSION(5,0,0); otherwise, when the condition is not met, statement2 is executed. When compiling the program, the conditional compilation process can be implemented according to the actual situation of the current operating system and kernel through the definition of LINUX_VERSION_CODE in the version.h file and the corresponding conditional judgment, branch, and execution statements in the driver, so that the program is applicable to different versions of operating systems and kernels.
[0098] In addition to conditional compilation, you can also perform dynamic checks when the driver is running, use system calls or APIs to obtain information about the current system, and decide which part of the code to execute based on this information. If an unsupported system or kernel version is found, you can execute an error handler, such as logging error information, returning an error code, or taking other appropriate recovery measures.
[0099] To keep the code clear and maintainable, you can also create an abstract interface layer. This layer is responsible for handling differences related to the operating system and kernel version, while providing a unified interface to the upper layer code. In this way, most of the driver code can remain independent of the operating system and kernel version, and only the abstract interface layer needs to handle these differences.
[0100] In one embodiment of the present invention, when multiple accelerator card devices are accessed in parallel, the characteristics of each accelerator card device are obtained, and a task queue is allocated to each accelerator card device according to the different characteristics of the accelerator card; each task applying for the accelerator card is evaluated, and the task is added to the corresponding task queue according to the evaluation result; or when multiple accelerator card devices are accessed in parallel, the concurrency control mechanism is initialized according to a preset concurrency control strategy.
[0101] Specifically, when multiple accelerator card devices are accessed in parallel, multiple processes or threads may try to access the same accelerator card at the same time, resulting in resource contention and performance bottlenecks. To this end, by obtaining the characteristics of each accelerator card device (such as computing power, memory size, etc.), a task queue is assigned to each accelerator card, which is initially empty. Each task that applies for an accelerator card is evaluated, including its computing power, data dependency, and other related characteristics; based on the task evaluation results, the task is added to the task queue of the corresponding accelerator card based on load balancing to ensure the load balancing of the system. If there is data dependency between tasks (that is, the output of one task is used as the input of another task), these tasks need to be assigned to the same or associated accelerator cards to reduce data transmission delays.
[0102] You can also implement a concurrency control mechanism in the driver to ensure that multiple applications access the accelerator card device in an orderly manner to avoid resource competition. You can take the following steps:
[0103] 1. Determine the concurrency control strategy: Select a suitable concurrency control strategy, such as mutex, semaphore, spinlock, or read-write lock, and select the appropriate mechanism according to specific needs and scenarios.
[0104] 2. Initialize the concurrency control mechanism: When the driver is initialized, create and initialize the selected concurrency control mechanism. For example, if a mutex lock is used, it is necessary to create the lock when the driver is loaded and ensure that it is destroyed when the driver is unloaded.
[0105] 3. Locking and unlocking of device access: In the driver, lock each key part that may cause resource competition (such as reading and writing of device registers, data transmission, etc.). When an application accesses the accelerator card device, it needs to obtain the lock first. If the lock is already held by other applications, the application needs to wait. After the access is completed, the application needs to release the lock so that other waiting applications can obtain access.
[0106] 4. Optimize the granularity of locks: The finer the lock granularity, the better the concurrency performance is generally, but it also increases complexity and overhead. Therefore, it is necessary to weigh the relationship between lock granularity and performance. You can consider using multiple locks to protect different resources or device functions to reduce lock contention.
[0107] 5. Timeout and error handling: Implement a timeout mechanism to prevent an application from occupying resources for a long time and causing other applications to be unable to access. Provide appropriate error handling mechanisms when locking fails or times out.
[0108] 6. Debugging and monitoring: Implement debugging and printing mechanisms to track and debug concurrency issues. For example, monitor lock usage, lock holding time, wait time, etc. to identify performance bottlenecks.
[0109] In one embodiment of the present invention, the execution of the access program is monitored by a performance analysis tool, the working status of the accelerator card is collected according to the execution status, the accelerator card access performance analysis is performed according to the working status, and the corresponding tuning strategy is executed according to the analysis results.
[0110] Specifically, suppose there is a deep learning training task that uses multiple accelerator cards for parallel computing. The initial task allocation strategy is to simply divide the dataset into parts equal to the number of accelerator cards and assign them to each accelerator card for processing.
[0111] After running the initial version of the access program, use performance analysis tools to monitor the execution of the access program. Through these tools, key indicators such as the working status of the accelerator card and resource utilization are collected in real time for performance analysis. The following problems may be found:
[0112] 1. Load imbalance: The utilization of some accelerator cards is significantly higher than that of other accelerator cards, and the task distribution is uneven.
[0113] 2. High data transmission overhead: The amount of data transmitted between accelerator cards is large, and there is unnecessary repeated transmission.
[0114] 3. High synchronization delay: After each iteration, all accelerator cards need to be synchronized, resulting in significant delays.
[0115] To address this, you can adopt the following tuning strategies:
[0116] Adjust task allocation: To solve the problem of unbalanced load, use more complex strategies to dynamically allocate tasks to ensure that each accelerator card has a similar workload. For example, the amount of data allocated to each accelerator card can be dynamically adjusted based on its real-time load. Consider the priority, dependency, and estimated execution time of tasks to optimize the task scheduling order.
[0117] Optimize data transmission: In order to reduce the amount of data transmission between accelerator cards, the concept of data locality is introduced. Data is assigned to the accelerator card closest to it for processing as much as possible to reduce data transmission across accelerator cards.
[0118] Improve synchronization mechanism: To reduce synchronization latency, perform global synchronization only when necessary, and use local synchronization or asynchronous operations in other cases.
[0119] By using performance analysis tools to identify performance bottlenecks in parallel programs and performing corresponding optimizations based on the analysis results, these optimization strategies not only improve program execution efficiency, but also increase the utilization of accelerator card resources.
[0120] The characteristics of the present invention are: first, unlike the general method, the present method can use multiple accelerator cards at the same time and identify and distinguish them; second, the general method only creates one device file and accesses the corresponding device according to different BDFs. When the present method uses multiple accelerator cards, the application can open multiple corresponding device files under the directory / dev; and there is no need to pay attention to the device identifier BDF of the accelerator card, which provides a convenient way of use for developers of application programs and even cluster applications.
[0121] The above is a method for identifying and accessing an accelerator card device provided by an embodiment of the present invention. Based on the same inventive idea, an embodiment of the present invention also provides a corresponding device for identifying and accessing an accelerator card device, such as Figure 6 As shown, including:
[0122] Initialization module 610, used to initialize the tree structure in the memory;
[0123] The device file creation module 620 is used to obtain the function identifier BDF of the accelerator card device, mount it to the tree structure, and create a device file corresponding to the accelerator card device;
[0124] A mapping relationship establishing module 630, used to establish a mapping relationship between BDF and device files;
[0125] The identification and access module 640 is used to identify and access the acceleration card device according to the mapping relationship.
[0126] The accelerator card removal module 650 is used to, when removing an accelerator card device with an established mapping relationship, cause the driver to remove the BDF corresponding to the accelerator card device from the tree structure, delete the device file corresponding to the accelerator card device in the system device directory, and delete the established mapping relationship.
[0127] In one embodiment of the present invention, the device file creation module 620 is specifically used to: when the system detects an accelerator card device, obtain the function identifier BDF of the accelerator card device; in the probe function of the driver, mount the BDF to the tree structure, and create a device file corresponding to the accelerator card device under the system device directory.
[0128] In one embodiment of the present invention, the identification and access module 640 is specifically used for: when an application uses an accelerator card device, the accelerator card device is accessed by opening the device file corresponding to the accelerator card device in the system device directory; when the device file is opened, the open function of the driver obtains the name of the device file accessed by the application, and determines the mapping relationship between the accessed device file and the BDF; determines the corresponding BDF according to the mapping relationship, identifies the corresponding accelerator card device according to the BDF, and implements reading and writing of the accelerator card device through the read / write function.
[0129] The embodiment of the present invention also provides a corresponding identification and access device for an acceleration card device, such as Figure 7 As shown, including:
[0130] At least one processor 702 (processor), a communication interface 704 (Communications Interface), a memory 706 (memory) and a communication bus 708; wherein the processor 702, the communication interface 704, and the memory 706 communicate with each other via the communication bus 708; the processor 702 can call the logic instructions stored in the memory 706 to enable at least one processor 702 to execute the steps of the above-mentioned embodiments.
[0131] Based on the same idea, some embodiments of the present invention also provide a medium corresponding to the above method.
[0132] Some embodiments of the present invention provide a storage medium storing computer executable instructions, and the computer executable instructions are executed by a processor to implement the steps of the above embodiments.
[0133] On the other hand, an embodiment of the present application also provides a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the steps of a method for identifying and accessing an accelerator card device provided in the above embodiments.
[0134] Each embodiment of the present invention is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device, medium and program product embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0135] The devices, media, and program products provided in the embodiments of the present invention correspond one-to-one to the methods. Therefore, the devices, media, and program products also have similar beneficial technical effects as the corresponding methods. Since the beneficial technical effects of the methods have been described in detail above, the beneficial technical effects of the devices, media, and program products will not be repeated here.
[0136] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or method including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or method. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or method including the elements.
[0137] The above are only embodiments of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail above with general descriptions and specific embodiments, it is obvious to those skilled in the art that some modifications or improvements can be made on the basis of the present invention. Therefore, these modifications or improvements made on the basis of not departing from the spirit of the present invention all belong to the scope of protection claimed in the present invention.
Claims
1. A method for identifying and accessing an accelerator card device, characterized in that: The accelerator card device is used for computing, including: Initialize a tree structure in memory through a driver, wherein the tree structure is a radix tree data structure; The function identification BDF of the accelerator card device is obtained, mounted to the tree structure, and a device file corresponding to the accelerator card device is created in the system device directory, and a mapping relationship between the BDF and the device file is established, including: when the system detects the accelerator card device, the function identification BDF of the accelerator card device is obtained; in the probe function of the driver, the BDF is mounted to the tree structure, and a device file corresponding to the accelerator card device is created in the system device directory; the BDF and the device file are mapped one by one to determine the mapping relationship between the device file and the BDF; the mapping relationship between the device file and the BDF is saved in a structure array; The application identifies and accesses the accelerator card device through the device file according to the mapping relationship, including: when the application uses the accelerator card device, the accelerator card device is accessed by opening the device file corresponding to the accelerator card device in the system device directory; when the device file is opened, the open function of the driver obtains the name of the device file accessed by the application, and determines the mapping relationship between the accessed device file and the BDF; determines the corresponding BDF according to the mapping relationship, identifies the corresponding accelerator card device according to the BDF, and realizes reading and writing of the accelerator card device through the read / write function; When removing the accelerator card device with established mapping relationship, the method further includes: the driver removes the BDF corresponding to the accelerator card device from the tree structure, and deletes the device file corresponding to the accelerator card device in the system device directory to delete the established mapping relationship; When multiple accelerator card devices are accessed in parallel, the method further includes: obtaining the characteristics of each accelerator card device, and allocating a task queue to each accelerator card device according to the different characteristics of the accelerator card; evaluating each task applying for the accelerator card, and adding the task to the corresponding task queue according to the evaluation result; or when multiple accelerator card devices are accessed in parallel, initializing the concurrency control mechanism according to a preset concurrency control strategy; Add hot-plug event detection and processing mechanisms, verification mechanisms, and file management mechanisms to the driver; Identify the currently running operating system and kernel version, find the corresponding code block according to the identified target operating system and kernel version, and generate a driver binary file specific to the target system; The execution of the access program is monitored by a performance analysis tool, the working status of the accelerator card is collected according to the execution status, the access performance of the accelerator card is analyzed according to the working status, and the corresponding tuning strategy is executed according to the analysis result.
2. An identification and access device for an accelerator card device, characterized in that: The accelerator card device is used for computing, including: An initialization module, used for initializing a tree structure in a memory, wherein the tree structure is a radix tree data structure; The device file creation module is used to obtain the function identification BDF of the accelerator card device, mount it to the tree structure, create a device file corresponding to the accelerator card device, and establish a mapping relationship between the BDF and the device file, including: when the system detects the accelerator card device, obtain the function identification BDF of the accelerator card device; in the probe function of the driver, mount the BDF to the tree structure, and create a device file corresponding to the accelerator card device under the system device directory; map the BDF and the device file one by one to determine the mapping relationship between the device file and the BDF; save the mapping relationship between the device file and the BDF into a structure array; An identification and access module, used for identifying and accessing the accelerator card device according to the mapping relationship, including: when the application uses the accelerator card device, the accelerator card device is accessed by opening the device file corresponding to the accelerator card device in the system device directory; when the device file is opened, the open function of the driver obtains the name of the device file accessed by the application, and determines the mapping relationship between the accessed device file and the BDF; determines the corresponding BDF according to the mapping relationship, identifies the corresponding accelerator card device according to the BDF, and realizes reading and writing of the accelerator card device through the read / write function; The accelerator card removal module is used for, when removing the accelerator card device with established mapping relationship, the driver removes the BDF corresponding to the accelerator card device from the tree structure, deletes the device file corresponding to the accelerator card device in the system device directory, and deletes the established mapping relationship; The accelerator card device identification and access device is also used to: when multiple accelerator card devices are accessed in parallel, obtain the characteristics of each accelerator card device, and allocate a task queue to each accelerator card device according to the different characteristics of the accelerator card; evaluate each task applying for the accelerator card, and add the task to the corresponding task queue according to the evaluation result; or when multiple accelerator card devices are accessed in parallel, initialize the concurrency control mechanism according to a preset concurrency control strategy; The identification and access device of the acceleration card device is also used to: add a detection and processing mechanism, a verification mechanism and a file management mechanism for hot plugging events in the driver; The recognition and access device of the accelerator card device is also used to: identify the currently running operating system and kernel version, search for corresponding code blocks according to the identified target operating system and kernel version, and generate a driver binary file specific to the target system; The identification and access device of the accelerator card device is also used to: monitor the execution of the access program through a performance analysis tool, collect the working status of the accelerator card according to the execution status, perform accelerator card access performance analysis according to the working status, and execute corresponding tuning strategies according to the analysis results.
3. An identification and access device for an accelerator card device, characterized in that: include: at least one processor; and a memory connected to the at least one processor via a bus; wherein, The memory stores instructions executable by the at least one processor, and the instructions are executed to implement the method according to claim 1.
4. A non-volatile storage medium storing computer executable instructions, characterized in that: The computer executable instructions are executed by a processor to implement the method according to claim 1.
Citation Information
Patent Citations
Storage system and mapping method
US20190213147A1