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_GET_MODEL_KERNEL_H_ 18 #define MINDSPORE_CCSRC_FL_SERVER_KERNEL_GET_MODEL_KERNEL_H_ 19 20 #include <map> 21 #include <memory> 22 #include <string> 23 #include <vector> 24 #include "fl/server/common.h" 25 #include "fl/server/executor.h" 26 #include "fl/server/kernel/round/round_kernel.h" 27 #include "fl/server/kernel/round/round_kernel_factory.h" 28 29 namespace mindspore { 30 namespace fl { 31 namespace server { 32 namespace kernel { 33 constexpr uint32_t kPrintGetModelForEveryRetryTime = 50; 34 class GetModelKernel : public RoundKernel { 35 public: GetModelKernel()36 GetModelKernel() : executor_(nullptr), iteration_time_window_(0), retry_count_(0) {} 37 ~GetModelKernel() override = default; 38 39 void InitKernel(size_t) override; 40 bool Launch(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> &workspace, 41 const std::vector<AddressPtr> &outputs); 42 bool Reset() override; 43 44 private: 45 void GetModel(const schema::RequestGetModel *get_model_req, const std::shared_ptr<FBBuilder> &fbb); 46 void BuildGetModelRsp(const std::shared_ptr<FBBuilder> &fbb, const schema::ResponseCode retcode, 47 const std::string &reason, const size_t iter, 48 const std::map<std::string, AddressPtr> &feature_maps, const std::string ×tamp); 49 50 // The executor is for getting model for getModel request. 51 Executor *executor_; 52 53 // The time window of one iteration. 54 size_t iteration_time_window_; 55 56 // The count of retrying because the iteration is not finished. 57 std::atomic<uint64_t> retry_count_; 58 }; 59 } // namespace kernel 60 } // namespace server 61 } // namespace fl 62 } // namespace mindspore 63 #endif // MINDSPORE_CCSRC_FL_SERVER_KERNEL_UPDATE_MODEL_KERNEL_H_ 64