AddInputTd
功 能 说 明
为 算 子 增 加 输 入Tensor的 描 述
函 数 原 型
Text
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)
参 数 说 明
值 依 赖 场 景 下 该 输 入tensor需 要 设 置 的 数 据 指 针。 bfloat16与float16的 数 据 依 赖 场 景,请 传 入float格 式 的 数 据,接 口 内 部 自 行 转 换 成bfloat16或float16。 | ||
返 回 值 说 明
当 前ContextBuilder的 对 象。
约 束 说 明
输 入 的index需 要 基 于 算 子IR定 义,按 照IrInstanceNum声 明 顺 序 来 排 布;
调 用AddInputTd前 需 要 调 用NodeIoNum与IrInstanceNum接 口
调 用 示 例
Text
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) // 声 明 算 子 有5个 输 入,1个 输 出
.IrInstanceNum({1, 1, 2, 1, 1}) // 声 明index 2的 算 子tensor有 两 个dynamic实 例
.SetOpNameType("tmpName", "tmpType")
.AddInputTd(0, ge::DT_FLOAT16, ge::FORMAT_ND, ge::FORMAT_ND, x_shape, reinterpret_cast<void *>(x_const_value.data())) // 内 部 会 将 该 指 针 指 向 的 数 据 转 为float16类 型
.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") // index2 的 第 一 个dynamic tensor,值 依 赖 场 景 传 入 数 据 路 径
.AddInputTd(3, ge::DT_INT64, ge::FORMAT_ND, ge::FORMAT_ND, expert_tokens_shape, "./expert_tokens_data.bin") // index2 的 第 二 个dynamic tensor, 值 依 赖 场 景 传 入 数 据 路 径
.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())) // 内 部 会 将 该 指 针 指 向 的 数 据 转 为Bf16类 型