ev-stdexec-pmr-pinned-resource-001¶
| 字段 | 值 |
|---|---|
| 项目 | NVIDIA/stdexec |
| 固定 commit | 6d7ad689f4d4 |
| 路径 | include/nvexec/detail/memory.cuh |
| 行段 | L146-L160 |
| 特性 | 多态内存资源(std::pmr) |
| 许可证 | Apache-2.0 |
| 代码来源 | 项目源码 |
| 级别 | manual |
| 审核 | zyuhao7 @ 2026-10-26 |
| 测试代码 | 否 |
| 发现方式 | manual |
用法¶
实现 std::pmr::memory_resource 子类,用 cudaMallocHost 提供固定页内存
为什么典型¶
自定义资源只需覆盖 do_allocate/do_deallocate/do_is_equal,容器即可通过 pmr 分配器透明使用它。
摘录¶
struct pinned_resource : public std::pmr::memory_resource
{
pinned_resource() noexcept = default;
auto do_allocate(std::size_t const bytes, std::size_t const /* alignment */) -> void* override
{
void* ret;
if (cudaError_t status = STDEXEC_LOG_CUDA_API(cudaMallocHost(&ret, bytes));
status != cudaSuccess)
{
throw std::bad_alloc();
}
return ret;
备注¶
生产路径;pinned_resource 适配 CUDA 的页锁定主机内存。