AddInputTd
Function Usage
Adds input tensor descriptions for an operator.
Prototype
ContextBuilder &AddInputTd(int32_t index, ge::DataType dtype, ge::Format originFormat,
ge::Format storageFormat, gert::StorageShape storageShape);
ContextBuilder &AddInputTd(int32_t index, ge::DataType dtype, ge::Format originFormat,
ge::Format storageFormat, gert::StorageShape storageShape, void* constValues);
ContextBuilder &AddInputTd(int32_t index, ge::DataType dtype, ge::Format originFormat,
ge::Format storageFormat, gert::StorageShape storageShape, const std::string &filePath);
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
index |
Input |
Operator input index, starting from 0. |
dtype |
Input |
Data type of the operator input tensor. |
originFormat |
Input |
Original format of the operator input tensor. |
storageFormat |
Input |
Runtime format of the operator input tensor. |
storageShape |
Input |
Shape of the operator input tensor. |
constValues |
Input |
Data pointer to be set for the input tensor in the value dependency scenario. In the data dependency scenario involving bfloat16 and float16, pass data in float format, which will be internally cast to bfloat16 or float16 by the API. |
filePath |
Input |
Path of the .bin data file of the input tensor in the value dependency scenario. |
Returns
Object of the current ContextBuilder
Constraints
The input indexes must be arranged in the declared sequence in IrInstanceNum based on the operator IR definition.
Call the NodeIoNum and IrInstanceNum APIs before calling AddInputTd.
Example
gert::StorageShape x_shape = {{1024, 5120}, {1024, 5120}};
gert::StorageShape expert_tokens_shape = {{16}, {16}};
gert::StorageShape weight1_shape = {{16, 5120, 0}, {16, 5120, 0}};
gert::StorageShape bias1_shape = {{16, 0}, {16, 0}};
std::vector<float> x_const_value (1024 * 5120, 2.f);
std::vector<float> bias_value (16 * 5120, 3.f);
context_ascendc::ContextBuilder builder
(void)builder.NodeIoNum(5, 1) // Declare that the operator has five inputs and one output.
.IrInstanceNum({1, 1, 2, 1, 1}) // Declare that the operator tensor whose index is 2 has two dynamic instances.
.SetOpNameType("tmpName", "tmpType")
.AddInputTd(0, ge::DT_FLOAT16, ge::FORMAT_ND, ge::FORMAT_ND, x_shape, reinterpret_cast<void *>(x_const_value.data())) // The API internally casts the data to which the pointer points to the float16 type.
.AddInputTd(1, ge::DT_FLOAT16, ge::FORMAT_ND, ge::FORMAT_ND, weight1_shape)
.AddInputTd(2, ge::DT_INT64, ge::FORMAT_ND, ge::FORMAT_ND, expert_tokens_shape, "./expert_tokens_data.bin") // First dynamic tensor of index 2. Pass the data path in the value dependency scenario.
.AddInputTd(3, ge::DT_INT64, ge::FORMAT_ND, ge::FORMAT_ND, expert_tokens_shape, "./expert_tokens_data.bin") // Second dynamic tensor of index 2. Pass the data path in the value dependency scenario.
.AddInputTd(4, ge::DT_FLOAT16, ge::FORMAT_ND, ge::FORMAT_ND, bias1_shape)
.AddInputTd(5, ge::DT_BF16, ge::FORMAT_ND, ge::FORMAT_ND, bias2_shape, reinterpret_cast<void*>(bias_value.data())) // The API internally casts the data to which the pointer points to the Bf16 type.