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_CCSRC_FL_SERVER_KERNEL_PARAMS_INFO_H_ 18 #define MINDSPORE_CCSRC_FL_SERVER_KERNEL_PARAMS_INFO_H_ 19 20 #include <utility> 21 #include <string> 22 #include <vector> 23 #include "ir/dtype/type_id.h" 24 25 namespace mindspore { 26 namespace fl { 27 namespace server { 28 namespace kernel { 29 // ParamsInfo is used for server computation kernel's register, e.g, ApplyMomentumKernel, FedAvgKernel, etc. 30 // Register of a server kernel needs every inputs/workspace/outputs parameters' name and type. 31 // For example: 32 // ParamsInfo() 33 // .AddInputNameType("input1_name", kNumberTypeFloat32) 34 // .AddInputNameType("input2_name", kNumberTypeUInt64) 35 // .AddWorkspaceNameType("workspace1_name", kNumberTypeFloat32) 36 // .AddOutputNameType("output1_name", kNumberTypeUInt64) 37 // This invocation describes a server kernel with parameters below: 38 // An input with name "input1_name" and type float32. 39 // An input with name "input1_name" and type uint_64. 40 // A workspace with name "workspace1_name" and type float32. 41 // An output with name "output1_name" and type float32. 42 class ParamsInfo { 43 public: 44 ParamsInfo() = default; 45 ~ParamsInfo() = default; 46 47 ParamsInfo &AddInputNameType(const std::string &name, TypeId type); 48 ParamsInfo &AddWorkspaceNameType(const std::string &name, TypeId type); 49 ParamsInfo &AddOutputNameType(const std::string &name, TypeId type); 50 size_t inputs_num() const; 51 size_t outputs_num() const; 52 const std::pair<std::string, TypeId> &inputs_name_type(size_t index) const; 53 const std::pair<std::string, TypeId> &outputs_name_type(size_t index) const; 54 const std::vector<std::string> &inputs_names() const; 55 const std::vector<std::string> &workspace_names() const; 56 const std::vector<std::string> &outputs_names() const; 57 58 private: 59 std::vector<std::pair<std::string, TypeId>> inputs_name_type_; 60 std::vector<std::pair<std::string, TypeId>> workspaces_name_type_; 61 std::vector<std::pair<std::string, TypeId>> outputs_name_type_; 62 std::vector<std::string> inputs_names_; 63 std::vector<std::string> workspace_names_; 64 std::vector<std::string> outputs_names_; 65 }; 66 } // namespace kernel 67 } // namespace server 68 } // namespace fl 69 } // namespace mindspore 70 #endif // MINDSPORE_CCSRC_FL_SERVER_KERNEL_PARAMS_INFO_H_ 71