---
title: PullKvCache
description: "| 产品 | 是否支持 |"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/API/hixlug/llmcrv2_42_12.html
sourcePath: /source/zh/canncommercial/900/API/hixlug/llmcrv2_42_12.html
indexId: 905cee90d539c6c4bbed6b1c6dc9c634949eec44b5ca20e1d2ef61c9afe6acc659
---
# PullKvCache

#### 产品支持情况

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


说明：针对 Atlas A2 训练系列产品 / Atlas A2 推理系列产品 ，仅支持Atlas 800I A2 推理服务器、A200I A2 Box 异构组件。


#### 函数功能

从远端节点拉取Cache到本地Cache。


#### 函数原型

```
Status PullKvCache(const CacheIndex &src_cache_index,
                   const Cache &dst_cache,
                   uint32_t batch_index = 0U,
                   int64_t size = -1,
                   const KvCacheExtParam &ext_param = {})
```


#### 参数说明

| 参数名称 | 输入/输出 | 取值说明 |
| --- | --- | --- |
| src\_cache\_index | 输入 | 远端源Cache的索引。 |
| dst\_cache | 输入 | 本地目的Cache。仅需指定调用RegisterKvCache返回的cache\_id。 |
| batch\_index | 输入 | 本地目的batch的下标。 |
| size | 输入 | 设置为>0的整数，表示需要拉取的大小，单位字节。 或设置为\-1，表示完整拉取。 默认为\-1。 |
| ext\_param | 输入 | 当前支持ext\_param中src\_layer\_range的second与first的差值和dst\_layer\_range的second与first的差值一致。src\_layer\_range和dst\_layer\_range的first和second默认值都是\-1，表示全部的层。取值范围都是[0, 最大可用层索引]，且first小于等于second。 最大可用层索引值的计算公式如下。 (CacheDesc::num\_tensors / KvCacheExtParam::tensor\_num\_per\_layer) \- 1 当前支持tensor\_num\_per\_layer取值范围是[1, 当前cache的tensor总数]，默认值为2。当src\_layer\_range或dst\_layer\_range取值为非默认值时， tensor\_num\_per\_layer可以保持默认值，也可以输入其他值，输入其他值时，tensor\_num\_per\_layer的取值还需要被当前cache的tensor总数整除。 |


#### 调用示例

单击Gitee(https://gitee.com/ascend/samples/tags)，根据“标签名”下载配套版本的sample包，从“cplusplus/level1_single_api/11_llm_data_dist”目录中获取样例。


#### 返回值

- LLM_SUCCESS：成功
- LLM_PARAM_INVALID：参数错误
- LLM_NOT_YET_LINK：与远端cluster没有建链
- LLM_TIMEOUT：拉取超时
- LLM_KV_CACHE_NOT_EXIST：本地或远端KV Cache不存在
- 其他：失败


#### 约束说明

该接口调用之前，需要先调用LinkLlmClusters接口完成初始化。
