- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在看 Page-Locked Host Memory
在 Cuda
Programming Guide
并想知道在使用函数 cudaHostAlloc
创建时分配的固定内存在哪里?它在内核地址空间中吗?还是分配在进程地址空间中?
最佳答案
CUDA(以及其他具有 DMA 功能的外部硬件,如 PCI-express 卡)的“页面锁定主机内存”分配在主机的物理内存中。分配被标记为不可交换(不可分页)和不可移动(锁定、固定)。这类似于 mlock
syscall的 Action “将调用进程的部分或全部虚拟地址空间锁定到 RAM 中,防止该内存被分页到交换区。”
这个分配可以被内核虚拟地址空间访问(因为内核拥有物理内存的完整 View )并且这个分配也被添加到用户进程虚拟地址空间以允许进程访问它。
当您执行普通 malloc 时,实际的物理内存分配可能(并将)推迟到对页面的第一次(写)访问。使用锁定/锁定内存,所有物理页面都在锁定或锁定调用中分配(如 mmap 中的 MAP_POPULATE :“为映射填充(预错)页表”),并且页面的物理地址不会改变(不交换,不移动,没有压缩...)。
CUDA 文档:
http://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__MEMORY.html#group__CUDART__MEMORY_1gb65da58f444e7230d3322b6126bb4902
__host__ cudaError_t cudaHostAlloc ( void** pHost, size_t size, unsigned int flags )
Allocates page-locked memory on the host. ...
Allocates size bytes of host memory that is page-locked and accessible to the device. The driver tracks the virtual memory ranges allocated with this function and automatically accelerates calls to functions such as
cudaMemcpy()
. Since the memory can be accessed directly by the device, it can be read or written with much higher bandwidth than pageable memory obtained with functions such asmalloc()
. Allocating excessive amounts of pinned 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 allocate staging areas for data exchange between host and device....
Memory allocated by this function must be freed with
cudaFreeHost()
.
Pinned memory is memory allocated using the cudaMallocHost function, which prevents the memory from being swapped out and provides improved transfer speeds. Non-pinned memory is memory allocated using the malloc function. As described in Memory Management Overhead and Memory Transfer Overhead, pinned memory is much more expensive to allocate and deallocate but provides higher transfer throughput for large memory transfers.
If you want truly asynchronous behavior (e.g. overlap of copy and compute) then the memory must be pinned. If it is not pinned, there won't be any runtime errors, but the copy will not be asynchronous - it will be performed like an ordinary cudaMemcpy.
The usable size may vary by system and OS. Pinning 4GB of memory on a 64GB system on Linux should not have a significant effect on CPU performance, after the pinning operation is complete. Attempting to pin 60GB on the other hand might cause significant system responsiveness issues.
关于cuda - 使用 cudaHostAlloc 分配的固定内存在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49480334/
我在看 Page-Locked Host Memory在 Cuda Programming Guide并想知道在使用函数 cudaHostAlloc 创建时分配的固定内存在哪里?它在内核地址空间中吗?
我试图找出在将数据传输到设备之前将数据复制到固定内存是否有意义,因为我对输入数据的分配没有影响(它是一个库)。 std::vector idata(WORK_SIZE); int *idata_ali
我多次启动内核,直到找到解决方案。解决方案将被至少一个 block 找到。 因此,当一个 block 找到解决方案时,它应该通知 cpu 找到了解决方案,以便 cpu 打印该 block 提供的解决方
在 CUDA 文档中,特别是在有关 cudaSetDevice 的设备管理部分的 CUDA Runtime API 中,它是这样写的 Any host memory allocated from th
我是 CUDA 的新手,我想使用 cudaHostAlloc。我能够将我的问题隔离到以下代码。使用 malloc 进行主机分配工作,使用 cudaHostAlloc 导致段错误,可能是因为分配的区域无
我想通过 cudaHostGetDevicePointer 在映射内存上使用零拷贝.我可以用thrust::host_vector或者我必须使用 cudaHostAlloc(...,cudaHostA
在 CUDA 中,我想知道 cudaMallocHost() 之间的区别和 cudaHostAlloc() . 它们在 API 引用中的各自摘要说: cudaMallocHost():“在主机上分配页
我正在执行一个简单的测试,比较主机(CPU 正在执行访问)使用 malloc() 分配的数据和使用 cudaHostAlloc() 分配的数据的访问延迟。我注意到在 Jetson Tk1 上访问使用
我刚接触 Nvidia 的这些 API,有些表达对我来说不太清楚。我想知道是否有人可以帮助我以简单的方式了解何时以及如何使用这些 CUDA 命令。更准确地说: 研究如何通过并行执行内核(例如使用 CU
我是一名优秀的程序员,十分优秀!