cuda.bindings._v2.driver.mem_host_register_v2#
- cuda.bindings._v2.driver.mem_host_register_v2(p, size_t bytesize, unsigned int flags)#
Registers an existing host memory range for use by CUDA.
Page-locks the memory range specified by
pandbytesizeand maps it for the device(s) as specified byflags. This memory range also is added to the same tracking mechanism ascuMemHostAllocto automatically accelerate calls to functions such ascuMemcpyHtoD(). Since the memory can be accessed directly by the device, it can be read or written with much higher bandwidth than pageable memory that has not been registered. Page-locking excessive amounts of memory may degrade system performance, since it reduces the amount of memory available to the system for paging. As a result, this function is best used sparingly to register staging areas for data exchange between host and device. On systems whereCU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS_USES_HOST_PAGE_TABLESis true,cuMemHostRegisterwill not page-lock the memory range specified byptrbut only populate unpopulated pages. Theflagsparameter enables different options to be specified that affect the allocation, as follows.CU_MEMHOSTREGISTER_PORTABLE: The memory returned by this call will be considered as pinned memory by all CUDA contexts, not just the one that performed the allocation.CU_MEMHOSTREGISTER_DEVICEMAP: Maps the allocation into the CUDA address space. The device pointer to the memory may be obtained by callingcuMemHostGetDevicePointer().CU_MEMHOSTREGISTER_IOMEMORY: The pointer is treated as pointing to some I/O memory space, e.g. the PCI Express resource of a 3rd party device.CU_MEMHOSTREGISTER_READ_ONLY: The pointer is treated as pointing to memory that is considered read-only by the device. On platforms withoutCU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS_USES_HOST_PAGE_TABLES, this flag is required in order to register memory mapped to the CPU as read-only. Support for the use of this flag can be queried from the device attributeCU_DEVICE_ATTRIBUTE_READ_ONLY_HOST_REGISTER_SUPPORTED. Using this flag with a current context associated with a device that does not have this attribute set will causecuMemHostRegisterto error with CUDA_ERROR_NOT_SUPPORTED.
All of these flags are orthogonal to one another: a developer may page-lock memory that is portable or mapped with no restrictions. The
CU_MEMHOSTREGISTER_DEVICEMAPflag may be specified on CUDA contexts for devices that do not support mapped pinned memory. The failure is deferred tocuMemHostGetDevicePointer()because the memory may be mapped into other CUDA contexts via theCU_MEMHOSTREGISTER_PORTABLEflag. For devices that have a non-zero value for the device attributeCU_DEVICE_ATTRIBUTE_CAN_USE_HOST_POINTER_FOR_REGISTERED_MEM, the memory can also be accessed from the device using the host pointerp. The device pointer returned bycuMemHostGetDevicePointer()may or may not match the original host pointerptrand depends on the devices visible to the application. If all devices visible to the application have a non-zero value for the device attribute, the device pointer returned bycuMemHostGetDevicePointer()will match the original pointerptr. If any device visible to the application has a zero value for the device attribute, the device pointer returned bycuMemHostGetDevicePointer()will not match the original host pointerptr, but it will be suitable for use on all devices provided Unified Virtual Addressing is enabled. In such systems, it is valid to access the memory using either pointer on devices that have a non-zero value for the device attribute. Note however that such devices should access the memory using only of the two pointers and not both. The memory page-locked by this function must be unregistered withmem_host_unregister().- Parameters:
p (bytes) – Host pointer to memory to page-lock.
bytesize (size_t) – Size in bytes of the address range to page- lock.
flags (unsigned int) – flags for allocation request.
See also
cuMemHostRegister_v2