---
title: aclrtMapMem
description: "| 产品 | 是否支持 |"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/API/runtimeapi/aclcppdevg_03_0116.html
sourcePath: /source/zh/canncommercial/900/API/runtimeapi/aclcppdevg_03_0116.html
indexId: 409dcd1e27fe637bc50adf454c7bf2ff209a2983a7d6201085c67ebefb2c0d8768
---
# aclrtMapMem

#### 产品支持情况

| 产品 | 是否支持 |
| --- | --- |
| Atlas 350 加速卡 | √ |
| Atlas A3 训练系列产品 / Atlas A3 推理系列产品 | √ |
| Atlas A2 训练系列产品 / Atlas A2 推理系列产品 | √ |
| Atlas 200I/500 A2 推理产品 | √ |
| Atlas 推理系列产品 | √ |
| Atlas 训练系列产品 | √ |


#### 功能说明

将虚拟内存映射到物理内存。

本接口需与以下其它接口配合使用，以便申请地址连续的虚拟内存、最大化利用物理内存：1. 申请虚拟内存（  aclrtReserveMemAddress
接口）；
2. 申请物理内存（  aclrtMallocPhysical
接口）；
3. 将虚拟内存映射到物理内存（  aclrtMapMem
接口）；
4. 执行任务（调用具体的任务接口）；
5. 取消虚拟内存与物理内存的映射（  aclrtUnmapMem
接口）；
6. 释放物理内存（  aclrtFreePhysical
接口）；
7. 释放虚拟内存（  aclrtReleaseMemAddress
接口）。


#### 函数原型

```
aclError aclrtMapMem(void *virPtr, size_t size, size_t offset, aclrtDrvMemHandle handle, uint64_t flags)
```


#### 参数说明

| 参数名 | 输入/输出 | 说明 |
| --- | --- | --- |
| virPtr | 输入 | 待映射的虚拟内存地址指针。 这个地址不一定是起始地址，用户也可以根据起始地址自行偏移后，再映射。 |
| size | 输入 | 待映射的内存大小，单位Byte。 此处的size必须与aclrtMallocPhysical接口的size参数值相同，size必须与aclrtMemGetAllocationGranularity接口获取的ACL\_RT\_MEM\_ALLOC\_GRANULARITY\_MINIMUM对齐。 |
| offset | 输入 | 物理内存偏移值，当前只能设置为0。 |
| handle | 输入 | 物理内存信息handle。类型定义请参见aclrtDrvMemHandle。 通过aclrtReserveMemAddress接口预留出来的一整段虚拟地址，由用户自行管理、划分时，不能同时与两个Device上申请的物理地址绑定。 通过aclrtReserveMemAddress接口预留出来的一整段虚拟地址，由用户自行管理、划分时，不能同时与aclrtMallocPhysical、aclrtMemImportFromShareableHandle接口输出的handle绑定。 |
| flags | 输入 | 预留，当前只能设置为0。 |


#### 返回值说明

返回0表示成功，返回其他值表示失败，请参见aclError。


#### 约束说明

对于 Atlas 200I/500 A2 推理产品 ，Ascend RC形态下，不支持调用本接口。


#### 接口调用示例

接口调用示例，参见虚拟内存管理(https://www.hiascend.comdocument/detail/zh/canncommercial/900/programug/acldevg/runtime_doc_dev_0007.html)。
