---
title: CopyKvBlocks
description: "| 产品 | 是否支持 |"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/others/llmdatadistdev/llmcrv1_42_14.html
sourcePath: /source/zh/canncommercial/900/others/llmdatadistdev/llmcrv1_42_14.html
indexId: 98b2880976f24d95e6dc6d7429e1d3bbef662510045604b61e8e62bfab4c66ad70
---
# CopyKvBlocks

#### 产品支持情况

| 产品 | 是否支持 |
| --- | --- |
| 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 异构组件。


#### 函数功能

PA场景下，通过block列表的方式拷贝KV Cache。支持D2D，D2H，H2D的拷贝。

- D2D场景主要是针对当多个回答需要共用相同block，block没填满时，新增的token需要拷贝到新的block上继续迭代。
- H2D和D2H的拷贝主要用于对应block_index上Cache内存的换入换出。


#### 函数原型

```
Status CopyKvBlocks(const Cache &src_cache,
                    const Cache &dst_cache,
                    const std::vector<uint64_t> &src_blocks,
                    const std::vector<std::vector<uint64_t>> &dst_blocks_list)
```


#### 参数说明

| 参数名称 | 输入/输出 | 取值说明 |
| --- | --- | --- |
| src\_cache | 输入 | 源Cache。 |
| dst\_cache | 输入 | 目的Cache。 |
| src\_blocks | 输入 | 源Cache的block index列表。 |
| dst\_blocks\_list | 输入 | 目标Cache的block index列表的列表，一组src\_blocks可以拷贝到多组dst\_blocks。 |


#### 调用示例

```
Status ret = llm_datadist.CopyKvCache(src_cache, dst_cache, {1,2}, {{1,2},{3,4}})
```


#### 返回值

- LLM_SUCCESS：成功
- LLM_PARAM_INVALID：参数错误
- 其他：失败


#### 约束说明

该接口调用之前，需要先调用Initialize接口完成初始化。不支持Host->Host的拷贝。
