---
title: AllocTensor
description: "申请一个device侧tensor，提供多个重载函数，可以指定不同的属性。"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/API/aolapi/atlasascendc_api_07_1120.html
sourcePath: /source/zh/canncommercial/900/API/aolapi/atlasascendc_api_07_1120.html
indexId: 37033229fb5be24a7764c52c1b736150e07dd549cf065b0ca9216083fef6bcfa70
---
# AllocTensor

#### 功能说明

申请一个device侧tensor，提供多个重载函数，可以指定不同的属性。


#### 函数原型

```
aclTensor *AllocTensor(const Shape &shape, DataType dataType, Format format = FORMAT_ND)
```

```
aclTensor *AllocTensor(const Shape &storageShape, const Shape &originShape, DataType dataType, Format storageFormat, Format originFormat)
```

```
aclTensor *AllocTensor(DataType dataType, Format storageFormat, Format originFormat)
```


#### 参数说明

| 参数 | 输入/输出 | 说明 |
| --- | --- | --- |
| shape | 输入 | 将aclTensor的StorageShape和OriginShape都设置为指定的shape。 |
| dataType | 输入 | 指定aclTensor的数据类型。 |
| format | 输入 | 将aclTensor的StorageFormat和OriginFormat都设置为指定的format。 |
| storageShape | 输入 | 将aclTensor的StorageShape设置为指定shape。 |
| originShape | 输入 | 将aclTensor的OriginShape设置为指定shape。 |
| storageFormat | 输入 | 将aclTensor的StorageFormat设置为指定format。 |
| originFormat | 输入 | 将aclTensor的OriginFormat设置为指定format。 |


#### 返回值说明

返回申请得到的aclTensor，申请失败则返回nullptr。


#### 约束说明

入参指针不能为空。


#### 调用示例

```
// 申请一个int64类型，shape为[1, 2, 3, 4, 5]的ND tensor
void Func(aclOpExecutor *executor) {
    gert::Shape newShape;
    for (int64_t i = 1; i <= 5; i++) {
        newShape.AppendDim(i);
    }
    aclTensor *tensor = executor->AllocTensor(newShape, DT_INT64, ge::FORMAT_ND);
}
```
