transform/op_adapter_map.cc

44 lines
2.0 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-2021 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/op_adapter_map.h"
#include <memory>
#include "graph/operator.h"
#include "transform/graph_ir/op_adapter_desc.h"
namespace mindspore {
namespace transform {
namespace {
// 定义一个 HashMap 来存储字符串到 OpAdapterDescPtr 的映射关系。
// 键是 std::string 类型,值是 OpAdapterDesc 的 shared_ptr。
mindspore::HashMap<std::string, OpAdapterDescPtr> adpt_map_ = {
{kNameCustomOp, std::make_shared<OpAdapterDesc>(std::make_shared<OpAdapter<Operator>>())}};
// 使用初始化列表将一个元素插入到 HashMap 中。
// 键是 "kNameCustomOp",值是一个使用 OpAdapter<Operator> 作为模板参数构造的 OpAdapterDesc 的 shared_ptr。
} // namespace
// 特例化模板,为 ge::Operator 类型的 OpAdapter 创建一个定制的输入映射。
// 使用 mindspore::HashMap<int, std::string> 作为值的 HashMap然后使用 std::string 作为键的 HashMap。
template <>
mindspore::HashMap<std::string, mindspore::HashMap<int, std::string>> OpAdapter<ge::Operator>::cus_input_map_{};
// 特例化模板,为 ge::Operator 类型的 OpAdapter 创建一个定制的输出映射。
// 使用 mindspore::HashMap<int, std::string> 作为值的 HashMap然后使用 std::string 作为键的 HashMap。
template <>
mindspore::HashMap<std::string, mindspore::HashMap<int, std::string>> OpAdapter<ge::Operator>::cus_output_map_{};
// OpAdapterMap 类的成员函数,用于返回 OpAdapterMap 的 adpt_map_ 成员引用。
mindspore::HashMap<std::string, OpAdapterDescPtr> &OpAdapterMap::get() { return adpt_map_; }
} // namespace transform
} // namespace mindspore