transform/graph_builder.cc

71 lines
2.8 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "include/transform/graph_ir/graph_builder.h"
#include <sstream>
#include "ops/math_ops.h"
namespace mindspore {
namespace transform {
// 该函数用于构建 MDDatasetMindSpore Dataset的图形Graph
DfGraphPtr BuildMDDatasetGraph(const DatasetGraphParam &param) {
MS_LOG(INFO) << "BuildMDDatasetGraph."; // 记录日志,表示正在构建 MDDataset 图形
// InitData
// 创建一个操作符 "InitData",使用参数 "init_data_tmp" 作为操作符的名称,并设置属性 "channel_name" 为
// param.queue_name() 的值
auto d = ge::op::InitData("init_data_tmp").set_attr_channel_name(param.queue_name());
// set graph inputs & outputs
// 设置图形的输入和输出
std::vector<ge::Operator> inputs{d}; // 将 "InitData" 操作符设置为图形的输入
std::vector<ge::Operator> outputs{d}; // 将 "InitData" 操作符设置为图形的输出
// 创建一个名为 "dataset" 的 MDDataset 图形,并使用 "dataset_graph" 指针指向该图形
DfGraphPtr dataset_graph = std::make_shared<DfGraph>("dataset");
// 将输入和输出设置到 MDDataset 图形中
(void)dataset_graph->SetInputs(inputs);
(void)dataset_graph->SetOutputs(outputs);
return dataset_graph; // 返回构建好的 MDDataset 图形的指针
}
// 该函数用于构建数据集的图形Graph
Status BuildDatasetGraph(const DatasetGraphParam &param, const std::string &phase) {
Status ret; // 存储函数执行结果的状态对象
std::string graph_name = phase; // 以给定的 'phase' 参数作为图形的名称
MS_LOG(INFO) << "BuildDatasetGraph begin. phase is " << phase; // 记录日志,表示开始构建数据集图形
MS_LOG(INFO) << "param is " << param.ToString() << "."; // 记录日志,打印参数 'param' 的详细信息
// 调用 BuildMDDatasetGraph 函数构建 MDDataset 图形,并将构建好的图形指针存储在 'dataset_graph' 变量中
DfGraphPtr dataset_graph = BuildMDDatasetGraph(param);
// 将构建好的 MDDataset 图形添加到图形管理器中,并使用 'graph_name' 作为图形的名称
ret = DfGraphManager::GetInstance().AddGraph(graph_name, dataset_graph);
// 根据 AddGraph 函数的执行结果,进行相应的日志记录
if (ret != Status::SUCCESS) { // 如果添加图形失败,记录错误日志
MS_LOG(ERROR) << "BuildDatasetGraph failed.";
} else { // 如果添加图形成功,记录结束日志
MS_LOG(INFO) << "BuildDatasetGraph end.";
}
return ret; // 返回函数执行结果的状态对象
}
} // namespace transform
} // namespace mindspore