昇腾社区首页
中文
注册

register_cache

产品支持情况

产品

是否支持

Atlas A3 训练系列产品/Atlas A3 推理系列产品

Atlas 800I A2 推理产品/A200I A2 Box 异构组件

Atlas A2 训练系列产品

x

Atlas 200I/500 A2 推理产品

x

Atlas 推理系列产品

x

Atlas 训练系列产品

x

函数功能

非PagedAttention场景下,调用此接口注册一个自行申请的内存。

函数原型

1
register_cache(cache_desc: CacheDesc, addrs: List[int], cache_keys: Union[Tuple[CacheKey], List[CacheKey]] = (), remote_accessible: Optional[bool] = None) -> Cache:

参数说明

参数名称

数据类型

取值说明

cache_desc

CacheDesc

Cache的描述信息。

addrs

List[int]

Cache的地址。register_cache中的地址个数与register_blocks_cache的地址个数之和不超过240。

cache_keys

Union[Tuple[CacheKey], List[CacheKey]]

Cache的索引。

remote_accessible

Optional[bool]

指定当前注册内存是否能用来做网络传输,对于device内存,默认值是True,对于host内存,默认值是False。

调用示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
from llm_datadist import *
import torch
...
cache_mgr = llm_datadist.cache_manager
data_addrs = []
for i in range(80):
    tensor = torch.ones(4, 1024 * 1024, dtype=torch.float32).npu()
    tensor_addr = tensor.data_ptr()
    data_addrs.append(tensor_addr)
cache_desc = CacheDesc(80, [4, 1024 * 1024], DataType.DT_FLOAT, Placement.DEVICE)
cache = cache_mgr.register_cache(cache_desc, data_addrs)
print('register cache suc:', cache.cache_id, flush=True)

返回值

正常情况下返回注册的cache。

传入数据类型错误,src和dst不匹配情况下会抛出TypeError或ValueError异常。

传入参数为None,会抛出AttributeError异常。

约束说明

device内存需要先注册再进行建链,host内存不约束顺序。

注册内存地址需自行保证不重复。

D2D HCCS数据传输时,首地址需要按照2MB对齐,否则可能导致link失败,HCCS不支持host内存。

RDMA数据传输时,申请host内存必须通过aclrtMallocHost接口,否则可能导致link失败。