• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/).
3  *
4  * Copyright 2019 Huawei Technologies Co., Ltd
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef MINDSPORE_CCSRC_PIPELINE_JIT_PARSE_DATA_CONVERTER_H_
20 #define MINDSPORE_CCSRC_PIPELINE_JIT_PARSE_DATA_CONVERTER_H_
21 
22 #include <deque>
23 #include <memory>
24 #include <vector>
25 #include <string>
26 #include <unordered_map>
27 #include "pipeline/jit/parse/parse_base.h"
28 #include "pipeline/jit/parse/python_adapter.h"
29 #include "utils/log_adapter.h"
30 
31 namespace mindspore {
32 namespace parse {
33 // data convert for parse
34 namespace data_converter {
35 void CacheObjectValue(const std::string &obj_key, const ValuePtr &data);
36 bool GetObjectValue(const std::string &obj_key, ValuePtr *const data);
37 
38 void SetObjGraphValue(const std::string &obj_key, const FuncGraphPtr &data);
39 
40 const std::unordered_map<std::string, std::vector<FuncGraphPtr>> &GetObjGraphs();
41 
42 std::vector<std::string> GetObjKey(const py::object &obj);
43 ResolveTypeDef GetObjType(const py::object &obj);
44 ClassInstanceTypeDef GetClassInstanceType(const py::object &obj);
45 
46 bool IsCellInstance(const py::object &obj);
47 py::object CreatePythonObject(const py::object &type, const py::tuple &args_kwargs);
48 py::object CallPythonScript(const py::object &script, const py::tuple &args_kwargs);
49 void MakeProperNameToFuncGraph(const FuncGraphPtr &func_graph, std::string name);
50 ValuePtr PyDataToValue(const py::object &obj);
51 void ClearObjectCache();
52 }  // namespace data_converter
53 
54 ClassPtr ParseDataClass(const py::object &cls_obj);
55 FuncGraphPtr ConvertToBpropCut(const py::object &obj);
56 
57 void CleanDataClassToClassMap();
58 
59 }  // namespace parse
60 }  // namespace mindspore
61 
62 #endif  // MINDSPORE_CCSRC_PIPELINE_JIT_PARSE_DATA_CONVERTER_H_
63