SVM【免费下载链接】driver本项目是CANN提供的驱动模块实现基础驱动和资源管理及调度等功能使能昇腾芯片。项目地址: https://gitcode.com/cann/driverOverviewSVM (Shared Virtual Memory) is a memory management module in the Ascend AI processor platform, used to efficiently manage device-side memory. Its main functions include memory initialization, allocation, release, copy, query, and sharing, and it provides HAL interfaces to upper-layer modules (such as Runtime).SVM InitializationSVM interface:halMemAgentOpenThe APP process calls the upper-layer business initialization interfaceaclrtSetDeviceduring initialization, which includes the SVM module initialization process. This process mainly includes: initializing the SVM module management structure, and completing the interaction between Host-side and Device-side SVM modules.Memory Allocation/Release/SetSVM interfaces:halMemAlloc/halMemFree/drvMemsetD8Allocate and map (throughmmap) a virtual address range from the reserved virtual address range, while entering kernel mode to request physical pages and establish corresponding page table entries. When releasing, unmap page tables, release physical pages, and return virtual addresses to the reserved range. Memory set sets the specified size of device memory to a given value.Additionally, the driver provides VMM interfaces, allowing developers to separately allocate virtual addresses and physical addresses, and dynamically establish mapping relationships between them as needed.VMM Virtual Address Allocation/ReleaseSVM interface: halMemAddressReserve/halMemAddressFreeAllocate and map (through mmap) a virtual address range from the reserved address range. At this point, physical pages have not been actually allocated. When releasing, only the virtual address is reclaimed.VMM Physical Address Allocation/ReleaseSVM interface: halMemCreate/halMemReleaseAllocate physical memory with specified attributes and size on the device side, and return an opaque generic memory allocation handle as the reference identifier for subsequent memory mapping. When releasing, the physical memory corresponding to this handle is released.VMM Map/Unmap Virtual Address to Physical AddressSVM interface: halMemMap/halMemUnmapEstablish or remove mapping relationships between the passed virtual address and physical address.Memory QueryMemory query supports memory attribute query and memory information query for specified addresses.Memory Attribute QuerySVM interface: drvMemGetAttributeGet memory attributes, physical page granularity, and other attributes for the passed virtual address.Memory Information QuerySVM interface: halMemGetInfoQuery physical memory information on the device side.Memory CopySVM interface:halMemcpySupport memory data transfer between host and device, or between different devices. For example, when performing H2D (Host-to-Device) transfer, data is synchronously copied from host memory to device memory. This synchronous copy operation is blocking—the caller waits until all data copying is complete before returning and continuing to execute subsequent code.Memory SharingMemory sharing supports memory sharing between different devices, as well as memory sharing between Host and Device.Inter-Device Memory SharingSVM interfaces: halShmemCreateHandle/halShmemDestroyHandlehalShmemOpenHandleByDevId/halShmemCloseHandleProcess 1 creates a handle pointing to shared device memory. Process 2 parses this handle and maps it as a device memory address within its own process, enabling shared access to the same physical memory on the device side. Destroying handles and unmapping perform corresponding reverse operations.Host and Device Memory SharingSVM interface: halHostRegister/halHostUnregisterRegister the peer (Host-side or Device-side) memory to the local side (Device-side or Host-side), enabling the local side to directly access or modify data in the peer memory.SVM Usage Process in BusinessBusiness Usage Process for Allocation and Copy FeaturesApplication ScenarioBefore operator execution, its Host-side process needs to first initialize the SVM module, then call the halMemAlloc interface to separately allocate Host memory and Device memory, and obtain corresponding memory addresses. Then, transfer the data to be calculated from the Host side to the Device side through the memory copy interface.Business Calling SVM Interface ProcessCallhalMemAllocinterface to allocate Host memory and obtain Host memory address.CallhalMemAllocinterface to allocate Device memory and obtain Device memory address.CallhalMemcpyinterface to synchronously copy data from Host memory to Device memory, completing data transfer.Business Usage Process for Memory Sharing FeatureApplication ScenarioThe business module starts two application processes on the Host side: host_app process 0 and host_app process 1, corresponding to devices dev0 and dev1 respectively.During operator execution, dev0 writes completed calculation results to its local device memory. If subsequent calculations need to be executed by dev1, dev1 can directly access dev0s calculation results through the above shared memory mechanism, without Host forwarding or explicit data copying, significantly improving operator pipeline execution efficiency.Business Calling SVM Interface Processhost_app process 0 callshalMemAllocto allocate device memory on dev0, and creates a shared handle for this memory throughhalShmemCreateHandleinterface, then passes this handle to host_app process 1.host_app process 1 calls the driver interfacehalShmemOpenHandleByDevIdto open this shared handle. The driver returns a pointer pointing to shared memory, completing the mapping of dev0 memory.Business Usage Process for VMM FeatureApplication ScenarioBased on VMM feature, the business module can allocate required virtual addresses and physical addresses at once, and dynamically establish mapping relationships based on actual needs, reusing the same physical memory, effectively reducing memory fragmentation caused by frequent physical memory splitting.Business Calling SVM Interface ProcessCallhalMemAddressReserveto allocate virtual address.CallhalMemCreateto allocate physical address.CallhalMemMapto establish mapping from virtual address to physical address.【免费下载链接】driver本项目是CANN提供的驱动模块实现基础驱动和资源管理及调度等功能使能昇腾芯片。项目地址: https://gitcode.com/cann/driver创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
CANN/driver SVM共享虚拟内存模块
发布时间:2026/6/6 5:11:05
SVM【免费下载链接】driver本项目是CANN提供的驱动模块实现基础驱动和资源管理及调度等功能使能昇腾芯片。项目地址: https://gitcode.com/cann/driverOverviewSVM (Shared Virtual Memory) is a memory management module in the Ascend AI processor platform, used to efficiently manage device-side memory. Its main functions include memory initialization, allocation, release, copy, query, and sharing, and it provides HAL interfaces to upper-layer modules (such as Runtime).SVM InitializationSVM interface:halMemAgentOpenThe APP process calls the upper-layer business initialization interfaceaclrtSetDeviceduring initialization, which includes the SVM module initialization process. This process mainly includes: initializing the SVM module management structure, and completing the interaction between Host-side and Device-side SVM modules.Memory Allocation/Release/SetSVM interfaces:halMemAlloc/halMemFree/drvMemsetD8Allocate and map (throughmmap) a virtual address range from the reserved virtual address range, while entering kernel mode to request physical pages and establish corresponding page table entries. When releasing, unmap page tables, release physical pages, and return virtual addresses to the reserved range. Memory set sets the specified size of device memory to a given value.Additionally, the driver provides VMM interfaces, allowing developers to separately allocate virtual addresses and physical addresses, and dynamically establish mapping relationships between them as needed.VMM Virtual Address Allocation/ReleaseSVM interface: halMemAddressReserve/halMemAddressFreeAllocate and map (through mmap) a virtual address range from the reserved address range. At this point, physical pages have not been actually allocated. When releasing, only the virtual address is reclaimed.VMM Physical Address Allocation/ReleaseSVM interface: halMemCreate/halMemReleaseAllocate physical memory with specified attributes and size on the device side, and return an opaque generic memory allocation handle as the reference identifier for subsequent memory mapping. When releasing, the physical memory corresponding to this handle is released.VMM Map/Unmap Virtual Address to Physical AddressSVM interface: halMemMap/halMemUnmapEstablish or remove mapping relationships between the passed virtual address and physical address.Memory QueryMemory query supports memory attribute query and memory information query for specified addresses.Memory Attribute QuerySVM interface: drvMemGetAttributeGet memory attributes, physical page granularity, and other attributes for the passed virtual address.Memory Information QuerySVM interface: halMemGetInfoQuery physical memory information on the device side.Memory CopySVM interface:halMemcpySupport memory data transfer between host and device, or between different devices. For example, when performing H2D (Host-to-Device) transfer, data is synchronously copied from host memory to device memory. This synchronous copy operation is blocking—the caller waits until all data copying is complete before returning and continuing to execute subsequent code.Memory SharingMemory sharing supports memory sharing between different devices, as well as memory sharing between Host and Device.Inter-Device Memory SharingSVM interfaces: halShmemCreateHandle/halShmemDestroyHandlehalShmemOpenHandleByDevId/halShmemCloseHandleProcess 1 creates a handle pointing to shared device memory. Process 2 parses this handle and maps it as a device memory address within its own process, enabling shared access to the same physical memory on the device side. Destroying handles and unmapping perform corresponding reverse operations.Host and Device Memory SharingSVM interface: halHostRegister/halHostUnregisterRegister the peer (Host-side or Device-side) memory to the local side (Device-side or Host-side), enabling the local side to directly access or modify data in the peer memory.SVM Usage Process in BusinessBusiness Usage Process for Allocation and Copy FeaturesApplication ScenarioBefore operator execution, its Host-side process needs to first initialize the SVM module, then call the halMemAlloc interface to separately allocate Host memory and Device memory, and obtain corresponding memory addresses. Then, transfer the data to be calculated from the Host side to the Device side through the memory copy interface.Business Calling SVM Interface ProcessCallhalMemAllocinterface to allocate Host memory and obtain Host memory address.CallhalMemAllocinterface to allocate Device memory and obtain Device memory address.CallhalMemcpyinterface to synchronously copy data from Host memory to Device memory, completing data transfer.Business Usage Process for Memory Sharing FeatureApplication ScenarioThe business module starts two application processes on the Host side: host_app process 0 and host_app process 1, corresponding to devices dev0 and dev1 respectively.During operator execution, dev0 writes completed calculation results to its local device memory. If subsequent calculations need to be executed by dev1, dev1 can directly access dev0s calculation results through the above shared memory mechanism, without Host forwarding or explicit data copying, significantly improving operator pipeline execution efficiency.Business Calling SVM Interface Processhost_app process 0 callshalMemAllocto allocate device memory on dev0, and creates a shared handle for this memory throughhalShmemCreateHandleinterface, then passes this handle to host_app process 1.host_app process 1 calls the driver interfacehalShmemOpenHandleByDevIdto open this shared handle. The driver returns a pointer pointing to shared memory, completing the mapping of dev0 memory.Business Usage Process for VMM FeatureApplication ScenarioBased on VMM feature, the business module can allocate required virtual addresses and physical addresses at once, and dynamically establish mapping relationships based on actual needs, reusing the same physical memory, effectively reducing memory fragmentation caused by frequent physical memory splitting.Business Calling SVM Interface ProcessCallhalMemAddressReserveto allocate virtual address.CallhalMemCreateto allocate physical address.CallhalMemMapto establish mapping from virtual address to physical address.【免费下载链接】driver本项目是CANN提供的驱动模块实现基础驱动和资源管理及调度等功能使能昇腾芯片。项目地址: https://gitcode.com/cann/driver创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考