---
title: AllocHostTensor
description: "申请一个host侧tensor，提供多个重载函数，可以指定不同的输入属性，如不同的数据类型。"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/API/aolapi/atlasascendc_api_07_1121.html
sourcePath: /source/zh/canncommercial/900/API/aolapi/atlasascendc_api_07_1121.html
indexId: f29ea5fc5fdbef6d6c6d45a7a54104f8a0e44fd55c601b3cf9ed863dc45dedfc70
---
# AllocHostTensor

#### 功能说明

申请一个host侧tensor，提供多个重载函数，可以指定不同的输入属性，如不同的数据类型。


#### 函数原型

- 根据不同的输入信息组合，申请一个host侧tensor

```
aclTensor *AllocHostTensor(const op::Shape &shape, op::DataType datatype, op::Format format = op::Format::FORMAT_ND)
```

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


- 申请一个host侧tensor，将指定数据类型的内存作为该tensor内容

```
aclTensor *AllocHostTensor(const int64_t *value, uint64_t size, op::DataType dataType)
```

```
aclTensor *AllocHostTensor(const uint64_t *value, uint64_t size, op::DataType dataType)
```

```
aclTensor *AllocHostTensor(const bool *value, uint64_t size, op::DataType dataType)
```

```
aclTensor *AllocHostTensor(const char *value, uint64_t size, op::DataType dataType)
```

```
aclTensor *AllocHostTensor(const int32_t *value, uint64_t size, op::DataType dataType)
```

```
aclTensor *AllocHostTensor(const uint32_t *value, uint64_t size, op::DataType dataType)
```

```
aclTensor *AllocHostTensor(const int16_t *value, uint64_t size, op::DataType dataType)
```

```
aclTensor *AllocHostTensor(const uint16_t *value, uint64_t size, op::DataType dataType)
```

```
aclTensor *AllocHostTensor(const int8_t *value, uint64_t size, op::DataType dataType)
```

```
aclTensor *AllocHostTensor(const uint8_t *value, uint64_t size, op::DataType dataType)
```

```
aclTensor *AllocHostTensor(const double *value, uint64_t size, op::DataType dataType)
```

```
aclTensor *AllocHostTensor(const float *value, uint64_t size, op::DataType dataType)
```

```
aclTensor *AllocHostTensor(const fp16_t *value, uint64_t size, op::DataType dataType)
```

```
aclTensor *AllocHostTensor(const bfloat16 *value, uint64_t size, op::DataType dataType)
```


#### 参数说明

- 根据不同的输入信息组合，申请一个host侧tensor。| 参数 | 输入/输出 | 说明 |
| --- | --- | --- |
| 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。 |


- 申请一个host侧tensor，将指定数据类型的内存作为该tensor内容。| 参数 | 输入/输出 | 说明 |
| --- | --- | --- |
| value | 输入 | 指向不同数据类型的源数据。 |
| size | 输入 | 源数据的元素个数。 |
| dataType | 输入 | 将源数据转为dataType指定的数据类型后，写入tensor。 |


#### 返回值说明

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


#### 约束说明

入参指针不能为空。


#### 调用示例

```
// 申请一个host侧tensor，并将myArray中的数据拷贝到tensor中
void Func(aclOpExecutor *executor) {
    int64_t myArray[10];
    aclTensor *tensor = executor->AllocHostTensor(myArray, 10, DT_INT64);
}
```
