### Install and Load Open GPU Kernel Modules Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/README.md Installs the compiled modules to the system and then loads them using modprobe. This ensures the GPU drivers are active. ```bash # Install modules sudo make modules_install # Load modules sudo modprobe nvidia sudo modprobe nvidia-modeset sudo modprobe nvidia-drm sudo modprobe nvidia-uvm ``` -------------------------------- ### Install Kernel Modules Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/README.md After building, use this command to install the kernel modules. It's recommended to uninstall existing modules first. Requires root privileges. ```makefile make modules_install -j$(nproc) ``` -------------------------------- ### Parallel Compilation Examples Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/configuration.md Demonstrates different ways to configure parallel jobs for compilation, from a fixed number to using all available cores. ```bash make modules -j4 ``` ```bash make modules -j$(nproc) ``` ```bash make modules -j1 ``` -------------------------------- ### Install Cross-Compiler Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/configuration.md If the compiler is not found, install the appropriate cross-compiler package. For aarch64, use 'apt-get install gcc-aarch64-linux-gnu'. You can also specify the full path to the compiler. ```bash # Error: aarch64-linux-gnu-gcc: command not found # Solution: Install cross-compiler sudo apt-get install gcc-aarch64-linux-gnu # Or specify full path make modules CC=/opt/custom/gcc ``` -------------------------------- ### Install Build Dependencies on Arch Linux Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/configuration.md Installs the base development group and kernel headers for Arch Linux. ```bash sudo pacman -S base-devel linux-headers ``` -------------------------------- ### Install Build Dependencies on Red Hat/Fedora/CentOS Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/configuration.md Installs required development tools and kernel headers for Red Hat-based systems. ```bash sudo yum groupinstall "Development Tools" sudo yum install kernel-devel ``` -------------------------------- ### Share Memory Between GPU Address Spaces Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/unified-virtual-memory.md This example demonstrates how to allocate memory in one GPU's address space and then duplicate that allocation into another GPU's address space, enabling both GPUs to access the same memory region. Ensure proper setup of virtual address spaces for each GPU. ```c // GPU1 allocates memory in its address space vnGpuOpsMemoryAllocFb(gpu1_va_space, size, &gpu1_addr, NULL); // UVM duplicates allocation into GPU2's address space vnGpuOpsDupAllocation(gpu1_va_space, gpu1_addr, gpu2_va_space, alignment, &gpu2_addr); // Now both GPUs can access the same memory ``` -------------------------------- ### Check Kernel Version Mismatch Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/configuration.md Verify that the installed kernel headers match the running kernel version. Use 'uname -r' to get the current kernel version and check the corresponding build directory. ```bash # Error: kernel version mismatch # Ensure kernel headers match running kernel uname -r ls -l /lib/modules/$(uname -r)/build ``` -------------------------------- ### Install Kernel Headers Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/configuration.md If kernel headers are missing, install them using the package manager. For Debian/Ubuntu systems, use 'apt-get install linux-headers-$(uname -r)'. ```bash # Error: kernel/build directory not found # Solution: Install kernel headers sudo apt-get install linux-headers-$(uname -r) # Or specify path make modules KDIR=/path/to/kernel/build ``` -------------------------------- ### Basic GPU Session Workflow Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/gpu-operations.md Demonstrates the fundamental steps for creating and managing a GPU session, including getting GPU information, creating a device, and setting up an address space. Ensure to clean up resources in reverse order of creation. ```c // Create a session gpuSessionHandle session = NULL; status = nvGpuOpsCreateSession(&session); if (status != NV_OK) return error; // Get GPU info nv_gpu_info_t gpu_info = {0}; status = nvGpuOpsGetGpuInfo(&gpu_uuid, NULL, &gpu_info); // Create device for GPU gpuDeviceHandle device = NULL; status = nvGpuOpsDeviceCreate(session, &gpu_info, &gpu_uuid, &device, FALSE); // Create address space gpuAddressSpaceHandle va_space = NULL; status = nvGpuOpsAddressSpaceCreate(device, 0x0, UINT64_MAX, FALSE, &va_space, NULL); // ... perform GPU operations ... // Cleanup vGpuOpsAddressSpaceDestroy(va_space); vGpuOpsDeviceDestroy(device); vGpuOpsDestroySession(session); ``` -------------------------------- ### Example: Allocating Contiguous Physical Pages Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/memory-management.md Demonstrates how to allocate contiguous physical GPU memory pages using `nvGpuOpsPmaAllocPages`. Ensure the `physical_pages` buffer is large enough to hold the returned addresses. ```c gpuPmaAllocationOptions pma_opts = { .flags = UVM_PMA_ALLOCATE_CONTIGUOUS, .minimumSpeed = 0, }; NvU64 *physical_pages = malloc(page_count * sizeof(NvU64)); NV_STATUS status = nvGpuOpsPmaAllocPages(pma, page_count, 4096, // 4K pages &pma_opts, physical_pages); if (status == NV_OK) { // physical_pages[0..page_count-1] are valid physical addresses } ``` -------------------------------- ### Configure Build Verbosity Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/configuration.md Example of how to set NV_VERBOSE to 1 for detailed build output. ```bash make modules NV_VERBOSE=1 ``` -------------------------------- ### Kernel Build System Targets Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/kernel-interface.md Basic Makefile targets for compiling and installing NVIDIA kernel modules. Use 'make modules' to compile and 'make modules_install' to install. ```makefile # From top-level Makefile nv_kernel_o = src/nvidia/$(OUTPUTDIR)/nv-kernel.o nv_modeset_kernel_o = src/nvidia-modeset/$(OUTPUTDIR)/nv-modeset-kernel.o # Build targets make modules # Compile all kernel modules make modules_install # Install modules to system ``` -------------------------------- ### Install Compiled Kernel Modules Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/configuration.md Installs the compiled kernel modules into the target kernel's module directory. This makes the modules available for loading. ```bash sudo make modules_install ``` -------------------------------- ### Get Attached GPUs Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/gpu-operations.md Returns a list of all GPUs currently attached and initialized. ```APIDOC ## Get Attached GPUs ### Description Returns list of all GPUs currently attached and initialized. ### Signature ```c NV_STATUS nvGpuOpsGetAttachedGpus(NvU8 *guidList, unsigned *numGpus); ``` ### Parameters | Parameter | Type | Direction | Description | |-----------|------|-----------|-------------| | guidList | NvU8 * | Output | Array of GPU UUIDs | | numGpus | unsigned * | In/Out | On entry: array size; on exit: count found | ``` -------------------------------- ### Extract and Install Firmware with Symlinks Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/nouveau/extract-firmware-nouveau.txt This command extracts firmware to `/lib/firmware`, creates necessary symlinks for all supported GPU variants, and downloads the driver package if needed. The -s option is crucial for Nouveau as it expects different directories for each GPU variant. ```bash sudo nouveau/extract-firmware-nouveau.py -o /lib/firmware -s -d ``` -------------------------------- ### Cross-Compilation Toolchain Setup Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/configuration.md Configure the complete toolchain for cross-compiling kernel modules to a different architecture. Ensure the specified toolchain components are available in your PATH or specified with their full paths. ```bash make modules -j$(nproc) \ TARGET_ARCH=aarch64 \ CC=aarch64-linux-gnu-gcc \ LD=aarch4-linux-gnu-ld \ AR=aarch64-linux-gnu-ar \ CXX=aarch64-linux-gnu-g++ \ OBJCOPY=aarch64-linux-gnu-objcopy ``` -------------------------------- ### Install Build Dependencies on Ubuntu/Debian Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/README.md Installs the necessary packages for building kernel modules on Ubuntu or Debian-based systems. This includes the compiler toolchain and kernel headers. ```bash # Ubuntu/Debian sudo apt-get install build-essential linux-headers-$(uname -r) ``` -------------------------------- ### Verify NVIDIA Module Installation Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/configuration.md Checks if NVIDIA modules are loaded and inspects module information and kernel logs. ```bash # Check loaded modules lsmod | grep nvidia # Check module information modinfo /path/to/nvidia.ko # View kernel logs dmesg | grep nvidia ``` -------------------------------- ### Install Build Dependencies on Fedora/RHEL Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/README.md Installs the required packages for building kernel modules on Fedora or RHEL-based systems. This includes the development tools group and kernel development files. ```bash # Fedora/RHEL sudo yum groupinstall "Development Tools" sudo yum install kernel-devel ``` -------------------------------- ### Cross-Compile NVIDIA Kernel Modules to ARM64 Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/configuration.md This script installs the necessary cross-compiler, sets environment variables for the target architecture, and builds the kernel modules. It concludes by verifying the compiled module's architecture. ```bash #!/bin/bash # Install ARM64 cross-compiler sudo apt-get install gcc-aarch64-linux-gnu # Set up environment export CROSS_COMPILE=aarch64-linux-gnu- export ARCH=arm64 # Build for ARM64 target cd open-gpu-kernel-modules make modules -j$(nproc) \ TARGET_ARCH=aarch64 \ CC=${CROSS_COMPILE}gcc \ LD=${CROSS_COMPILE}ld \ AR=${CROSS_COMPILE}ar \ CXX=${CROSS_COMPILE}g++ \ OBJCOPY=${CROSS_COMPILE}objcopy # Verify compilation file kernel-open/nvidia/nvidia.ko # Output: ELF 64-bit LSB relocatable, ARM aarch64, version 1, ... ``` -------------------------------- ### Get GPU Client Info Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/gpu-operations.md Maps a Linux process ID to RM handles for GPU access control. ```APIDOC ## Get GPU Client Info ### Description Maps a Linux process ID to RM handles for GPU access control. ### Signature ```c NV_STATUS nvGpuOpsGetClientInfoFromPid(unsigned pid, const NvU8 *gpuUuid, NvHandle *hClient, NvHandle *hDevice, NvHandle *hSubDevice); ``` ``` -------------------------------- ### Create Device Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/gpu-operations.md Creates a new GPU device handle for a specific GPU. The GUID uniquely identifies the physical GPU. ```APIDOC ## Create Device ### Description Creates a new GPU device handle for a specific GPU. The GUID uniquely identifies the physical GPU. ### Function Signature ```c NV_STATUS nvGpuOpsDeviceCreate(struct gpuSession *session, const gpuInfo *pGpuInfo, const NvProcessorUuid *gpuGuid, struct gpuDevice **device, NvBool bCreateSmcPartition) ``` ### Parameters #### Input Parameters - **session** (struct gpuSession *) - Session handle - **pGpuInfo** (const gpuInfo *) - GPU hardware information - **gpuGuid** (const NvProcessorUuid *) - GPU UUID for identification - **bCreateSmcPartition** (NvBool) - Create SMC (Streaming Multiprocessor Cluster) partition #### Output Parameters - **device** (struct gpuDevice **) - Pointer to device handle storage ### Returns - `NV_OK` on success ### Error Conditions - GPU not found or not initialized - Insufficient resources - UUID mismatch or invalid GPU info - SMC partition creation failed ``` -------------------------------- ### Build All Kernel Modules Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/configuration.md Compiles all kernel modules without installing them. The output includes the core GPU driver, display driver, DRM subsystem driver, and UVM driver. ```bash make modules ``` -------------------------------- ### Cross-Compile Kernel Modules for ARM Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/kernel-interface.md Example command for cross-compiling kernel modules for ARM architecture (aarch64). Specify target architecture and cross-compilation toolchain components. ```bash # Cross-compile for ARM make modules TARGET_ARCH=aarch64 \ CC=aarch64-linux-gnu-gcc \ LD=aarch64-linux-gnu-ld \ AR=aarch64-linux-gnu-ar \ CXX=aarch64-linux-gnu-g++ \ OBJCOPY=aarch64-linux-gnu-objcopy ``` -------------------------------- ### Get P2P Capabilities Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/gpu-operations.md Queries whether direct GPU-to-GPU data transfer is possible and at what performance characteristics. Returns NV_OK on success. ```APIDOC ## Get P2P Capabilities ### Description Queries whether direct GPU-to-GPU data transfer is possible and at what performance characteristics. Output includes whether P2P is supported, PCIe bandwidth between GPUs, whether PCIe bridging is used, and access atomicity constraints. ### Signature ```c NV_STATUS nvGpuOpsGetP2PCaps(gpuDeviceHandle device1, gpuDeviceHandle device2, getP2PCapsParams *p2pCaps) ``` ### Parameters #### Input Parameters - **device1** (gpuDeviceHandle) - The first GPU device. - **device2** (gpuDeviceHandle) - The second GPU device. #### Output Parameters - **p2pCaps** (getP2PCapsParams *) - P2P capability information. ``` -------------------------------- ### Cross-Compile for aarch64 on x86_64 Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/README.md Example of cross-compiling kernel modules for aarch64 architecture on an x86_64 host. Specify target architecture and cross-compilation toolchain components. ```makefile make modules -j$(nproc) \ TARGET_ARCH=aarch64 \ CC=aarch64-linux-gnu-gcc \ LD=aarch64-linux-gnu-ld \ AR=aarch64-linux-gnu-ar \ CXX=aarch64-linux-gnu-g++ \ OBJCOPY=aarch64-linux-gnu-objcopy ``` -------------------------------- ### Show Build Time Statistics Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/configuration.md Use the 'time' command with 'make modules' to measure the total build duration. ```bash # Show build time time make modules ``` -------------------------------- ### Load NVIDIA Module with Parameters Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/configuration.md Demonstrates how to load the NVIDIA module with custom parameters. Common parameters include `NVreg_EnableMSI`, `NVreg_RegistryDwords`, and `NVreg_RmLogonRC`. ```bash # Load nvidia module with parameters sudo modprobe nvidia [parameter=value ...] ``` -------------------------------- ### Phase 1: OS-Agnostic Compilation Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/configuration.md Execute these make commands to build OS-agnostic object files for the NVIDIA driver and modeset components. ```makefile make -C src/nvidia # Builds nv-kernel.o make -C src/nvidia-modeset # Builds nv-modeset-kernel.o ``` -------------------------------- ### GPU Memory Allocation and Mapping Workflow Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/gpu-operations.md Illustrates the process of allocating memory on the GPU, mapping it to the CPU for initialization, and then freeing it. This workflow is essential for preparing GPU memory before use. ```c // Allocate GPU VRAM NvU64 gpu_offset; gpuAllocInfo alloc_info; status = nvGpuOpsMemoryAllocFb(va_space, ALLOC_SIZE, &gpu_offset, &alloc_info); // Map to CPU for initialization void *cpu_ptr; status = nvGpuOpsMemoryCpuMap(va_space, gpu_offset, ALLOC_SIZE, &cpu_ptr, &page_size); // Use CPU pointer to initialize memset(cpu_ptr, 0, ALLOC_SIZE); // Unmap from CPU vGpuOpsMemoryCpuUnMap(va_space, cpu_ptr); // Free GPU memory vGpuOpsMemoryFree(va_space, gpu_offset); ``` -------------------------------- ### Display Help Message for Firmware Extraction Script Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/nouveau/extract-firmware-nouveau.txt Use the -h or --help flag to display the usage instructions and available options for the firmware extraction script. ```bash nouveau/extract-firmware-nouveau.py -h ``` -------------------------------- ### Install Driver Without Kernel Modules Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/README.md This command installs the NVIDIA GPU driver without building kernel modules, allowing you to use the pre-built open modules. ```shell sh ./NVIDIA-Linux-[...].run --no-kernel-modules ``` -------------------------------- ### Output Directory Structure Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/configuration.md Illustrates the directory structure for source files, OS-agnostic build outputs, and final kernel modules. ```tree . ├── src/ │ ├── nvidia/ │ │ └── build/ # OS-agnostic build output │ │ └── nv-kernel.o │ ├── nvidia-modeset/ │ │ └── build/ │ │ └── nv-modeset-kernel.o │ └── common/ # Common utilities ├── kernel-open/ │ ├── nvidia/ │ │ ├── nv-kernel.o_binary -> ../../src/nvidia/build/nv-kernel.o │ │ ├── nvidia.ko # Final module │ │ └── *.o # Kernel interface layer object files │ ├── nvidia-modeset/ │ │ ├── nv-modeset-kernel.o_binary │ │ └── nvidia-modeset.ko │ ├── nvidia-drm/ │ │ └── nvidia-drm.ko │ └── nvidia-uvm/ │ └── nvidia-uvm.ko ``` -------------------------------- ### Basic Build of Open GPU Kernel Modules Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/README.md Builds the kernel modules using make. Ensure you are in the 'open-gpu-kernel-modules' directory. The '-j$(nproc)' flag utilizes all available CPU cores for faster compilation. ```bash cd open-gpu-kernel-modules make modules -j$(nproc) sudo make modules_install ``` -------------------------------- ### Get NVLink Info Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/gpu-operations.md Retrieves NVLink interconnect information for GPU-to-GPU communication. ```APIDOC ## Get NVLink Info ### Description Retrieves NVLink interconnect information for GPU-to-GPU communication over dedicated links (not PCIe). ### Signature ```c NV_STATUS nvGpuOpsGetNvlinkInfo(struct gpuDevice *device, gpuNvlinkInfo *nvlinkInfo); ``` ``` -------------------------------- ### Show Build Progress Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/configuration.md Pipe the output of 'make modules' to 'grep' to filter and display compilation and linking steps. ```bash # Show build progress make modules | grep -E "CC|LD|AR" ``` -------------------------------- ### Get ECC Info Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/gpu-operations.md Queries GPU ECC capabilities and current error counts. ```APIDOC ## Get ECC Info ### Description Queries GPU ECC capabilities and current error counts. ### Signature ```c NV_STATUS nvGpuOpsGetEccInfo(struct gpuDevice *device, gpuEccInfo *eccInfo); ``` ``` -------------------------------- ### Basic UVM Workflow Steps Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/unified-virtual-memory.md This comment block lists the sequential steps involved in a basic UVM workflow, from opening the device to tracking memory access bits. ```c // 1. User application opens /dev/nvidia-uvm // 2. UVM creates GPU session via nvGpuOpsCreateSession() // 3. UVM creates address space via nvGpuOpsAddressSpaceCreate() // 4. Application creates GPU channels via nvGpuOpsChannelAllocate() // 5. Memory accessed by GPU triggers page faults // 6. UVM migrates memory as needed for optimal performance // 7. Access bits tracked via nvGpuOpsAccessBitsDump() ``` -------------------------------- ### Get GPU IDs Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/gpu-operations.md Maps a GPU UUID to NVIDIA device and subdevice IDs. ```APIDOC ## Get GPU IDs ### Description Maps a GPU UUID to NVIDIA device and subdevice IDs. ### Signature ```c NV_STATUS nvGpuOpsGetGpuIds(const NvU8 *pUuid, unsigned uuidLength, NvU32 *pDeviceId, NvU32 *pSubdeviceId); ``` ``` -------------------------------- ### Phase 2: Kernel Interface Layer Build Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/configuration.md Run this make command to build the final kernel modules using the object files generated in Phase 1 and kbuild. ```makefile make -C kernel-open modules # Builds modules using .o files from Phase 1 ``` -------------------------------- ### Build with GCC (Default) Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/configuration.md Command to build kernel modules using GCC, which is the default compiler. ```bash make modules CC=gcc ``` -------------------------------- ### Pre-allocate and Map Memory for GPU Access Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/memory-management.md Demonstrates how to pre-allocate and map memory before GPU access using `nvGpuOpsMemoryAllocFb`. This function allocates memory and returns a GPU offset, preparing it for GPU utilization. ```c // Pre-allocate and map memory before GPU access void *prep_memory() { NvU64 gpu_offset; NV_STATUS status = nvGpuOpsMemoryAllocFb(va_space, work_size, &gpu_offset, NULL); // Memory is now allocated and ready for GPU use return (void *)gpu_offset; } ``` -------------------------------- ### UVM Architecture Detection and Initialization Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/unified-virtual-memory.md This code comment outlines the process of detecting the GPU architecture and initializing specific features based on the detected generation. ```c // Architecture detection and initialization // Determines GPU generation and enables specific features ``` -------------------------------- ### GPU Information Structure Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/kernel-interface.md Provides detailed information about a GPU, including its ID, PCI address, and NUMA setup requirements. ```c typedef struct { NvU32 gpu_id; // NVIDIA GPU ID struct { NvU32 domain; // PCI domain number NvU8 bus; // PCI bus number NvU8 slot; // PCI slot number NvU8 function; // PCI function number } pci_info; NvBool needs_numa_setup; // Whether NUMA setup is required NvBool is_soc_disp; // System-on-Chip display GPU void *os_device_ptr; // OS-specific device pointer (Linux struct device) } nv_gpu_info_t; #define NV_MAX_GPUS 32 // Maximum number of supported GPUs ``` -------------------------------- ### Build with Clang Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/configuration.md Command to build kernel modules using Clang and LLD linker. ```bash make modules CC=clang LD=lld ``` -------------------------------- ### Configuration Types Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/types.md Lists types related to GPU configuration and system parameters. ```text nv_ioctl_numa_info_t nv_ioctl_sys_params_t nv_gpu_info_t ``` -------------------------------- ### Get Frame Buffer Info Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/gpu-operations.md Retrieves GPU frame buffer (VRAM) information including total memory, type, and configuration. ```APIDOC ## Get Frame Buffer Info ### Description Retrieves GPU frame buffer (VRAM) information: - Total available memory - Memory type (GDDR6, HBM, etc.) - Memory configuration and layout ### Signature ```c NV_STATUS nvGpuOpsGetFbInfo(struct gpuDevice *device, gpuFbInfo *fbInfo); ``` ``` -------------------------------- ### Build with Debug Symbols and Logging Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/configuration.md Compile the modules with debug symbols and enable NV_DEBUG_PRINTS. This is useful for debugging. ```bash make modules DEBUG=1 ``` -------------------------------- ### Session Management Type Hierarchy Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/types.md Illustrates the hierarchical relationship between different session management handles, starting from a general gpuSessionHandle down to gpuChannelHandle. ```text gpuSessionHandle ├── gpuDeviceHandle ├── gpuAddressSpaceHandle └── gpuTsgHandle └── gpuChannelHandle ``` -------------------------------- ### Get GPU Info Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/gpu-operations.md Retrieves detailed GPU hardware information including architecture, capabilities, memory configuration, compute capabilities, and ECC support. ```APIDOC ## Get GPU Info ### Description Retrieves detailed GPU hardware information including: - GPU architecture and capabilities - Memory configuration - Compute capabilities - ECC support ### Signature ```c NV_STATUS nvGpuOpsGetGpuInfo(const NvProcessorUuid *gpuUuid, const gpuClientInfo *pGpuClientInfo, gpuInfo *pGpuInfo); ``` ``` -------------------------------- ### Get GMMU Format Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/unified-virtual-memory.md Retrieves the GMMU (GPU Memory Management Unit) format descriptor for an address space, which describes the page table structure. ```c NV_STATUS nvGpuOpsGetGmmuFmt(struct gpuAddressSpace *vaSpace, void **pFmt); ``` -------------------------------- ### Manually Load NVIDIA Kernel Modules Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/configuration.md Loads NVIDIA kernel modules in the required order using `insmod`. Ensure `nvidia.ko` is loaded first. ```bash # Manual loading (in order) sudo insmod /lib/modules/$(uname -r)/kernel/drivers/gpu/drm/nvidia/nvidia.ko sudo insmod /lib/modules/$(uname -r)/kernel/drivers/gpu/drm/nvidia-modeset/nvidia-modeset.ko sudo insmod /lib/modules/$(uname -r)/kernel/drivers/gpu/drm/nvidia-drm/nvidia-drm.ko sudo insmod /lib/modules/$(uname -r)/kernel/drivers/gpu/drm/nvidia-uvm/nvidia-uvm.ko ``` -------------------------------- ### Get ECC Info Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/gpu-operations.md Queries the GPU's Error Correction Code (ECC) capabilities and current error counts. Requires a pointer to a gpuDevice structure. ```c NV_STATUS nvGpuOpsGetEccInfo(struct gpuDevice *device, gpuEccInfo *eccInfo); ``` -------------------------------- ### Get GPU Info Function Signature Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/gpu-operations.md Use this function to retrieve detailed hardware information about a specific GPU, including its architecture, memory, and compute capabilities. ```c NV_STATUS nvGpuOpsGetGpuInfo(const NvProcessorUuid *gpuUuid, const gpuClientInfo *pGpuClientInfo, gpuInfo *pGpuInfo); ``` -------------------------------- ### Handle Invalid Device for Address Space Creation Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/errors.md This code demonstrates how to handle errors when attempting to create an address space with an invalid device handle. Always ensure a valid device handle is provided. ```c // Scenario: Creating address space on invalid device vnGpuOpsAddressSpaceCreate(NULL, 0, UINT64_MAX, FALSE, &va_space, NULL); // Returns: NV_ERR_INVALID_DEVICE (0x0001) // Cause: NULL device handle // Recovery: Create device first ``` -------------------------------- ### Query GPU Interrupt Status Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/errors.md This example shows how to query the status of GPU interrupts using an ioctl call. Check the `intr_query.status` field for errors after the call. ```c nv_ioctl_query_device_intr_t intr_query = {0}; ioctl(gpu_fd, _IOC(_IOC_READ | _IOC_WRITE, 'F', 213, sizeof(nv_ioctl_query_device_intr_t)), &intr_query); if (intr_query.status != NV_OK) { printf("Failed to query interrupts: 0x%08x\n", intr_query.status); } ``` -------------------------------- ### Enable Verbose Build Output Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/configuration.md Control the level of detail in build output. Set to '1' to see complete command lines, or '0' for summary lines. ```makefile NV_VERBOSE=0|1 ``` -------------------------------- ### Get Attached GPUs Function Signature Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/gpu-operations.md Retrieves a list of all GPUs currently attached and initialized within the system. The function populates a buffer with GPU UUIDs and returns the count. ```c NV_STATUS nvGpuOpsGetAttachedGpus(NvU8 *guidList, unsigned *numGpus); ``` -------------------------------- ### nvGpuOpsSetPageDirectory Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/unified-virtual-memory.md Establishes an external page directory for ATS support, allowing the GPU to use the same page tables as the CPU for shared virtual memory. ```APIDOC ## nvGpuOpsSetPageDirectory ### Description Establishes an external page directory for ATS support, allowing the GPU to use the same page tables as the CPU for shared virtual memory. ### Function Signature ```c NV_STATUS nvGpuOpsSetPageDirectory(struct gpuAddressSpace *vaSpace, NvU64 physAddress, unsigned numEntries, NvBool bVidMemAperture, NvU32 pasid, NvU64 *dmaAddress); ``` ### Parameters #### Path Parameters - **vaSpace** (struct gpuAddressSpace *) - Target address space - **physAddress** (NvU64) - Physical address of page directory - **numEntries** (unsigned) - Number of page table entries - **bVidMemAperture** (NvBool) - Whether directory is in VRAM - **pasid** (NvU32) - Process Address Space ID for ATS (if supported) - **dmaAddress** (NvU64 *) - Output: GPU-accessible address for directory ``` -------------------------------- ### Get GPU IDs Function Signature Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/gpu-operations.md Maps a GPU's unique identifier (UUID) to its corresponding NVIDIA device and subdevice IDs. This is useful for identifying specific hardware components. ```c NV_STATUS nvGpuOpsGetGpuIds(const NvU8 *pUuid, unsigned uuidLength, NvU32 *pDeviceId, NvU32 *pSubdeviceId); ``` -------------------------------- ### Get Frame Buffer Info Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/gpu-operations.md Retrieves information about the GPU's frame buffer (VRAM), including total available memory, memory type, and configuration. Requires a pointer to a gpuDevice structure. ```c NV_STATUS nvGpuOpsGetFbInfo(struct gpuDevice *device, gpuFbInfo *fbInfo); ``` -------------------------------- ### Load NVIDIA Module with Parameters Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/README.md This bash command loads the NVIDIA kernel module with specific parameters, such as enabling MSI interrupts. Ensure you have root privileges. ```bash sudo modprobe nvidia NVreg_EnableMSI=1 ``` -------------------------------- ### Build-Time Environment Variables Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/configuration.md Set these variables before building to control the build process. KBUILD_VERBOSE enables detailed build output. ```bash KBUILD_VERBOSE=1 # Verbose kbuild output ``` ```bash KCPPFLAGS # Additional C preprocessor flags ``` ```bash KCFLAGS # Additional compiler flags ``` ```bash LDFLAGS # Linker flags ``` -------------------------------- ### Set Page Directory - C Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/gpu-operations.md Sets up an external page directory for the GPU address space, essential for GPU shared virtual memory with the CPU. Ensure the physical address and number of entries are correct. ```c NV_STATUS nvGpuOpsSetPageDirectory( struct gpuAddressSpace *vaSpace, NvU64 physAddress, unsigned numEntries, NvBool bVidMemAperture, NvU32 pasid, NvU64 *dmaAddress ); ``` -------------------------------- ### Get GPU Client Info Function Signature Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/gpu-operations.md Maps a Linux process ID (PID) to RM handles, which are necessary for GPU access control. This function is used to establish a connection between a process and a GPU. ```c NV_STATUS nvGpuOpsGetClientInfoFromPid(unsigned pid, const NvU8 *gpuUuid, NvHandle *hClient, NvHandle *hDevice, NvHandle *hSubDevice); ``` -------------------------------- ### Get GMMU Format - C Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/gpu-operations.md Retrieves the GMMU (GPU Memory Management Unit) format for the address space, which describes the page table structure. The returned format is opaque and intended for internal use. ```c NV_STATUS nvGpuOpsGetGmmuFmt( struct gpuAddressSpace *vaSpace, void **pFmt ); ``` -------------------------------- ### GPU Information Structure Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/types.md Contains GPU identity and configuration information, including its PCI details, NUMA setup requirements, and SoC display status. It also includes a pointer for OS-specific device structures. ```c typedef struct { NvU32 gpu_id; // NVIDIA GPU ID struct { NvU32 domain; // PCI domain NvU8 bus; // PCI bus NvU8 slot; // PCI slot NvU8 function; // PCI function } pci_info; NvBool needs_numa_setup; // NUMA setup required NvBool is_soc_disp; // SoC display GPU void *os_device_ptr; // OS-specific device struct } nv_gpu_info_t; #define NV_MAX_GPUS 32 ``` -------------------------------- ### Parallel Compilation with All Cores Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/configuration.md Utilize all available CPU cores for parallel compilation to significantly speed up the build process. This is highly recommended. ```bash make modules -j$(nproc) ``` -------------------------------- ### System Parameters Structure Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/types.md Returns system-level parameters used by the GPU driver, such as memory block size. ```c typedef struct nv_ioctl_sys_params { NvU64 memblock_size; // System memory block size } nv_ioctl_sys_params_t; ``` -------------------------------- ### Build with Verbose Output Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/README.md Enable verbose output during the build process by setting NV_VERBOSE to '1'. This prints each command executed. ```makefile make modules -j$(nproc) NV_VERBOSE=1 ``` -------------------------------- ### Troubleshoot IOCTL Failures Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/README.md Commands to help debug IOCTL failures. Enable debugging during module compilation and verify GPU presence and access. ```bash # Enable debugging make modules DEBUG=1 ``` ```bash # Check for GPU presence lspci | grep NVIDIA ``` ```bash # Test GPU access cat /proc/driver/nvidia/gpus/*/information ``` -------------------------------- ### Troubleshoot Module Load Failures Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/README.md Use these commands to diagnose issues when the NVIDIA kernel module fails to load. Check system logs, kernel version, and module dependencies. ```bash # Check dmesg for errors dmesg | tail -50 ``` ```bash # Verify kernel version compatibility uname -r ``` ```bash # Check module dependencies modinfo nvidia.ko | grep depends ``` -------------------------------- ### Hypervisor Type Enumeration Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/types.md Enumerates the different types of hypervisors that can be detected. Use this to identify the underlying virtualization platform. ```c typedef enum { OS_HYPERVISOR_XEN = 0, OS_HYPERVISOR_VMWARE, OS_HYPERVISOR_HYPERV, OS_HYPERVISOR_KVM, OS_HYPERVISOR_UNKNOWN } HYPERVISOR_TYPE; ``` -------------------------------- ### Unified Virtual Memory (UVM) Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/COMPLETION_REPORT.txt Explains the UVM architecture, GPU memory information, page fault handling, page table management, and support for P2P memory access, NVLink, and debugging. ```APIDOC ## Unified Virtual Memory (UVM) API ### Description This section describes the Unified Virtual Memory (UVM) architecture, providing insights into GPU memory information, page fault handling, and page table management. It covers support for P2P memory access, NVLink integration, and debugging utilities. ### UVM Architecture Overview of the UVM system and its components. ### GPU Memory Information APIs to retrieve information about the GPU's memory layout and usage. ### Page Fault Handling Mechanisms for handling page faults within the UVM system. ### Page Table Management Details on how page tables are managed for UVM. ### Architecture Support Information on supported GPU architectures and their UVM features. ### P2P Memory Access How UVM facilitates peer-to-peer memory access between GPUs. ### NVLink Integration Details on how UVM leverages NVLink for high-speed interconnect. ### ECC and Debugging Error Correction Code (ECC) handling and debugging tools for UVM. ``` -------------------------------- ### API Version Check Structure Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/types.md Queries API version compatibility with the driver. Supports different command types (STRICT, RELAXED, QUERY) and provides a version string. ```c #define NV_RM_API_VERSION_STRING_LENGTH 64 typedef struct nv_ioctl_rm_api_version { NvU32 cmd; // Command (STRICT, RELAXED, QUERY) NvU32 reply; // Response (UNRECOGNIZED or RECOGNIZED) char versionString[NV_RM_API_VERSION_STRING_LENGTH]; } nv_ioctl_rm_api_version_t; ``` -------------------------------- ### nvGpuOpsOwnPageFaultIntr Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/gpu-operations.md Allows user-space GPU drivers to claim ownership of page fault exceptions for custom handling. ```APIDOC ## nvGpuOpsOwnPageFaultIntr ### Description Allows user-space GPU drivers to claim ownership of page fault exceptions for custom handling. ### Function Signature ```c NV_STATUS nvGpuOpsOwnPageFaultIntr(struct gpuDevice *device, NvBool bOwnInterrupts); ``` ### Parameters #### Input Parameters - **device** (struct gpuDevice *) - GPU device - **bOwnInterrupts** (NvBool) - TRUE to take ownership of page fault interrupts ``` -------------------------------- ### Build Kernel Modules with Verbose Output Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/kernel-interface.md Command to build kernel modules with verbose output enabled. Use 'NV_VERBOSE=1' for detailed build logs. ```bash # Build with verbose output make modules NV_VERBOSE=1 ``` -------------------------------- ### nvGpuOpsDupMemory Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/api-reference/gpu-operations.md Creates a new handle to existing memory, allowing access by another client. ```APIDOC ## nvGpuOpsDupMemory ### Description Creates a new handle to existing memory, allowing access by another client. ### Signature ```c NV_STATUS nvGpuOpsDupMemory(struct gpuDevice *device, NvHandle hClient, NvHandle hPhysMemory, NvHandle *hDupMemory, gpuMemoryInfo *pGpuMemoryInfo); ``` ### Parameters #### Input Parameters - **device** (struct gpuDevice *) - GPU device - **hClient** (NvHandle) - Client handle owning original memory - **hPhysMemory** (NvHandle) - Handle to original memory allocation #### Output Parameters - **hDupMemory** (NvHandle *) - New handle for duplicated access - **pGpuMemoryInfo** (gpuMemoryInfo *) - Memory information ``` -------------------------------- ### Required Kernel Configuration Options Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/README.md Specifies essential kernel configuration options needed for building and running the NVIDIA open GPU kernel modules. CONFIG_IOMMU_SUPPORT is optional but recommended for IOMMU functionality. ```text CONFIG_MODULES=y CONFIG_IOMMU_SUPPORT=y (optional, for IOMMUs) ``` -------------------------------- ### Custom Output Directory Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/configuration.md Specify a custom directory for build artifacts using the 'O' argument with the 'make modules' target. ```bash make modules O=/custom/output/path ``` -------------------------------- ### Load NVIDIA Kernel Modules with Modprobe Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/configuration.md Loads NVIDIA kernel modules using `modprobe`, which automatically handles dependencies. This is the recommended method. ```bash # Or via modprobe (automatic dependency resolution) sudo modprobe nvidia sudo modprobe nvidia-modeset sudo modprobe nvidia-drm sudo modprobe nvidia-uvm ``` -------------------------------- ### Generate WHENCE File for linux-firmware Repository Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/nouveau/extract-firmware-nouveau.txt The -w option generates a WHENCE file, which is useful for updating the linux-firmware git repository, specifically for Mode #2. ```bash nouveau/extract-firmware-nouveau.py -w ``` -------------------------------- ### Load NVIDIA Kernel Module Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/README.md Requires root privileges to load the NVIDIA kernel module. Use this command to enable GPU driver functionality. ```bash sudo modprobe nvidia ``` -------------------------------- ### Utilities Functions Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/INDEX.md Utility functions for calculating PCIe bandwidth and detecting hypervisor type. ```APIDOC ## Utilities Functions ### Description Utility functions for calculating PCIe bandwidth and detecting hypervisor type. ### Functions - **calculatePCIELinkRateMBps**: Calculate PCIe bandwidth. - **nv_get_hypervisor_type**: Detect hypervisor type. ``` -------------------------------- ### Query GPU Capabilities Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/README.md C functions to retrieve various GPU capabilities and information. Ensure the 'device' pointer is valid before calling these functions. ```c // Get general capabilities nvGpuOpsQueryCaps(device, &caps); ``` ```c // Get copy engine capabilities nvGpuOpsQueryCesCaps(device, &ce_caps); ``` ```c // Get frame buffer info nvGpuOpsGetFbInfo(device, &fb_info); ``` -------------------------------- ### Build Configuration Source: https://github.com/nvidia/open-gpu-kernel-modules/blob/main/_autodocs/COMPLETION_REPORT.txt Details on build configurations, including target architecture, debug mode, and compiler selection. ```APIDOC ## Build Configuration ### Description Details on build configurations, including target architecture, debug mode, and compiler selection. ### Options - TARGET_ARCH (x86_64, aarch64) - DEBUG mode - Verbosity settings - Compiler selection - Kernel configuration - Cross-compilation setup - Module installation - Build troubleshooting ```