• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021 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 #ifndef MINDSPORE_FUSION_TBE_JSON_CREATOR_H
17 #define MINDSPORE_FUSION_TBE_JSON_CREATOR_H
18 #include <map>
19 #include <vector>
20 #include "backend/kernel_compiler/tbe/tbe_json/tbe_json_creator.h"
21 namespace mindspore::kernel {
22 
23 using ANodeFusionDataTypeMap = std::map<const AnfNodePtr, tbe::FusionDataType>;
24 class FusionBuildTbeJsonCreator : public TbeJsonCreator {
25  public:
FusionBuildTbeJsonCreator()26   FusionBuildTbeJsonCreator() : optional_index_(0) {}
27   ~FusionBuildTbeJsonCreator() override = default;
28   bool GenJson(const FusionScopeInfo &fusion_scope_info, nlohmann::json *fusion_json) override;
29 
30  protected:
31   bool GenOpListJson(const FusionScopeInfo &fusion_scope_info, std::vector<nlohmann::json> *fusion_json);
32   bool GenInputsJson(const AnfNodePtr &anf_node, nlohmann::json *compute_json) override;
33   bool GenOutputsJson(const AnfNodePtr &anf_node, nlohmann::json *compute_json) override;
34   std::vector<size_t> GetDescOutputIndex(const std::vector<int64_t> &output_used_nums);
35   void GenReusedOutputDesc(const AnfNodePtr &anf_node, size_t index, size_t output_index, nlohmann::json *output_desc,
36                            size_t out_size);
37   void GenDataJson(const std::vector<AnfNodePtr> &compute_nodes, const std::vector<nlohmann::json> &compute_json,
38                    std::vector<nlohmann::json> *op_list_json, const ANodeFusionDataTypeMap &spec_data_input);
39   bool AttrsJsonPostProcessing(const AnfNodePtr &anf_node, const OpInfoPtr &op_info_ptr,
40                                nlohmann::json *attrs_json) override;
41   void GenOtherJson(const AnfNodePtr &anf_node, nlohmann::json *compute_json) override;
42 
43  private:
44   AnfNodePtr GetInputCNode(const AnfNodePtr &node, const nlohmann::json &input_desc);
45   bool CheckDynamicInput(const CNodePtr &cnode);
46   bool CheckInput(const FusionScopeInfo &fusion_scope_info);
47   size_t optional_index_;
48 };
49 }  // namespace mindspore::kernel
50 #endif  // MINDSPORE_FUSION_TBE_JSON_CREATOR_H
51