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 17 #ifndef MINDSPORE_SINGLE_TBE_JSON_CREATOR_H 18 #define MINDSPORE_SINGLE_TBE_JSON_CREATOR_H 19 #include <vector> 20 #include "backend/kernel_compiler/tbe/tbe_json/tbe_json_creator.h" 21 namespace mindspore::kernel { 22 23 class SingleTbeJsonCreator : public TbeJsonCreator { 24 public: 25 SingleTbeJsonCreator() = default; 26 virtual ~SingleTbeJsonCreator() = default; 27 bool GenJson(const AnfNodePtr &anf_node, nlohmann::json *kernel_json) override; 28 29 protected: 30 bool GenOpListJson(const AnfNodePtr &anf_node, std::vector<nlohmann::json> *op_list_json); 31 void GenDataJson(const AnfNodePtr &anf_node, const nlohmann::json &compute_json, 32 std::vector<nlohmann::json> *op_list_json); 33 bool GenInputsJson(const AnfNodePtr &anf_node, nlohmann::json *compute_json) override; 34 virtual void GenInputDescJson(const AnfNodePtr &anf_node, size_t real_input_index, nlohmann::json *input_desc); 35 bool AssignInputsJson(const AnfNodePtr &anf_node, const std::vector<nlohmann::json> &inputs_desc, 36 const std::vector<size_t> &inputs_tensor_num, const std::vector<OpIOInfoPtr> &inputs_ptr, 37 std::vector<nlohmann::json> *inputs_json); 38 void GenOutputDescJson(const AnfNodePtr &anf_node, size_t node_out_idx, nlohmann::json *output_desc); 39 bool GenOutputsJson(const AnfNodePtr &anf_node, nlohmann::json *compute_json) override; 40 bool AssignOutputsJson(const AnfNodePtr &anf_node, const std::vector<nlohmann::json> &outputs_desc, 41 const std::vector<size_t> &outputs_tensor_num, const std::vector<OpIOInfoPtr> &outputs_ptr, 42 std::vector<nlohmann::json> *outputs_json); 43 void GenOtherJson(const AnfNodePtr &anf_node, nlohmann::json *compute_json) override; 44 }; 45 class CheckTbeJsonCreator : public SingleTbeJsonCreator { 46 public: 47 CheckTbeJsonCreator() = default; 48 ~CheckTbeJsonCreator() override = default; 49 50 protected: 51 void GenDescJson(const AnfNodePtr &anf_node, size_t node_out_idx, size_t desc_output_idx, 52 nlohmann::json *output_desc) override; 53 void GenInputDescJson(const AnfNodePtr &anf_node, size_t real_input_index, nlohmann::json *input_desc) override; 54 }; 55 class SelectTbeJsonCreator : public SingleTbeJsonCreator { 56 public: 57 SelectTbeJsonCreator() = default; 58 ~SelectTbeJsonCreator() override = default; 59 60 protected: 61 bool AttrsJsonPostProcessing(const AnfNodePtr &anf_node, const OpInfoPtr &op_info_ptr, 62 nlohmann::json *attrs_json) override; 63 void GenDescJson(const AnfNodePtr &anf_node, size_t node_out_idx, size_t desc_output_idx, 64 nlohmann::json *output_desc) override; 65 void GenInputDescJson(const AnfNodePtr &anf_node, size_t real_input_index, nlohmann::json *input_desc) override; 66 }; 67 class BuildTbeJsonCreator : public SingleTbeJsonCreator { 68 public: 69 BuildTbeJsonCreator() = default; 70 ~BuildTbeJsonCreator() override = default; 71 }; 72 } // namespace mindspore::kernel 73 #endif // MINDSPORE_SINGLE_TBE_JSON_CREATOR_H 74