• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2019 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MINDSPORE_CCSRC_TRANSFORM_GRAPH_IR_OP_ADAPTER_UTIL_H_
18 #define MINDSPORE_CCSRC_TRANSFORM_GRAPH_IR_OP_ADAPTER_UTIL_H_
19 
20 #include <string>
21 #include <vector>
22 
23 #include "transform/graph_ir/op_adapter_base.h"
24 
25 namespace mindspore {
26 namespace transform {
27 template <typename P, typename Q>
ConvertAnyUtil(const ValuePtr & value,const AnyTraits<P> &,const AnyTraits<Q> &)28 static Q ConvertAnyUtil(const ValuePtr &value, const AnyTraits<P> &, const AnyTraits<Q> &) {
29   return static_cast<Q>(GetValue<P>(value));
30 }
31 
32 GeTensor ConvertAnyUtil(const ValuePtr &value, const AnyTraits<mindspore::tensor::Tensor> &traits);
33 
34 std::vector<int64_t> ConvertAnyUtil(const ValuePtr &value, const std::string &name,
35                                     const AnyTraits<std::vector<int64_t>>);
36 
37 std::string ConvertAnyUtil(const ValuePtr &value, const AnyTraits<std::vector<int64_t>>, const AnyTraits<std::string>);
38 
39 std::vector<float> ConvertAnyUtil(const ValuePtr &value, const AnyTraits<std::vector<float>>, const AnyTraits<float>);
40 
41 std::vector<int64_t> ConvertAnyUtil(const ValuePtr &value, const std::string &format,
42                                     const AnyTraits<std::vector<int64_t>>, const AnyTraits<int64_t>);
43 
44 GeDataType ConvertAnyUtil(const ValuePtr &value, const AnyTraits<GEType>);
45 
46 template <typename P, typename Q>
ConvertAnyUtil(const ValuePtr & value,AnyTraits<P>,const AnyTraits<std::vector<Q>>)47 std::vector<Q> ConvertAnyUtil(const ValuePtr &value, AnyTraits<P>, const AnyTraits<std::vector<Q>>) {
48   MS_EXCEPTION_IF_NULL(value);
49   if (!value->isa<ValueTuple>() && !value->isa<ValueList>()) {
50     MS_LOG(EXCEPTION) << "error convert Value to vector for value: " << value->ToString()
51                       << ", type: " << value->type_name() << ", value should be a tuple or list";
52   }
53   auto vec = value->isa<ValueTuple>() ? value->cast<ValueTuplePtr>()->value() : value->cast<ValueListPtr>()->value();
54   std::vector<Q> data;
55   for (auto &it : vec) {
56     data.push_back(ConvertAnyUtil(it, AnyTraits<P>(), AnyTraits<Q>()));
57   }
58   return data;
59 }
60 
61 GeTensor ConvertAnyUtil(const ValuePtr &value, const AnyTraits<AnyValue>);
62 
63 bool IsCustomPrim(const PrimitivePtr &prim);
64 bool IsCustomCNode(const AnfNodePtr &node);
65 std::string GetOpIOFormat(const AnfNodePtr &node);
66 }  // namespace transform
67 }  // namespace mindspore
68 #endif  // MINDSPORE_CCSRC_TRANSFORM_GRAPH_IR_OP_ADAPTER_UTIL_H_
69