ConvertToTensor
Function Usage
Converts different types of host data into a host aclTtensor object.
Prototype
aclTensor *ConvertToTensor(const aclIntArray *value, DataType dataType)
aclTensor *ConvertToTensor(const aclBoolArray *value, DataType dataType)
aclTensor *ConvertToTensor(const aclFloatArray *value, DataType dataType)
aclTensor *ConvertToTensor(const aclFp16Array *value, DataType dataType)
aclTensor *ConvertToTensor(const aclBf16Array *value, DataType dataType)
aclTensor *ConvertToTensor(const aclScalar *value, DataType dataType)
template<typename T>
aclTensor *ConvertToTensor(const T *value, uint64_t size, DataType dataType)
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
value |
Input |
Source data on the host. |
size |
Input |
Number of elements in the source data. |
dataType |
Input |
Destination data type of the source data, which is written to the aclTensor. |
Returns
Converted tensor on the host.
Constraints
The input parameter pointer must not be null.
Example
1 2 3 4 5 6 7 | // Convert an aclScalar and an int64_t to tensors on the host. void Func(aclOpExecutor *executor) { int64_t val = 5; aclScalar *scalar = executor->AllocScalar(val); aclTensor *tensor = executor->ConvertToTensor(scalar, DT_INT64); tensor = executor->ConvertToTensor(&val, 1, DT_INT64); } |