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

#### 产品支持情况

| 产品 | 是否支持 |
| --- | --- |
| 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。


#### 函数原型

```
Status AllocateCache(const CacheDesc &cache_desc, Cache &cache)
```


#### 参数说明

| 参数名称 | 输入/输出 | 取值说明 |
| --- | --- | --- |
| cache\_desc | 输入 | Cache的描述。 |
| cache | 输出 | 分配出的Cache，当该接口返回LLM\_SUCCESS时有效。 |


#### 调用示例

```
CacheDesc kv_desc{};
kv_desc.num_tensors = 80;
kv_desc.data_type = DT_FLOAT16;
kv_desc.shape = {1, 256};
Cache cache;
Status ret = llm_datadist.AllocateCache(kv_desc, cache);
```


#### 返回值

- LLM_SUCCESS：成功
- LLM_PARAM_INVALID：参数错误
- LLM_DEVICE_OUT_OF_MEMORY: Device内存不足
- 其他：失败


#### 约束说明

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

仅支持参数“cache_desc”中的placement为CachePlacement::kDevice时，该接口生效。Cache的描述请参考CacheDesc。
