• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020 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_FRONTEND_PARALLEL_OPS_INFO_UNFORM_CANDIDATE_SAMPLER_INFO_H_
18 #define MINDSPORE_CCSRC_FRONTEND_PARALLEL_OPS_INFO_UNFORM_CANDIDATE_SAMPLER_INFO_H_
19 
20 #include <string>
21 #include <memory>
22 #include <vector>
23 
24 #include "ir/value.h"
25 #include "frontend/parallel/auto_parallel/operator_costmodel.h"
26 #include "frontend/parallel/ops_info/operator_info.h"
27 #include "frontend/parallel/strategy.h"
28 
29 namespace mindspore {
30 namespace parallel {
31 constexpr size_t UNIFORM_CANDIDATE_SAMPLER_INPUTS_SIZE = 2;
32 class UniformCandidateSamplerInfo : public OperatorInfo {
33  public:
UniformCandidateSamplerInfo(const std::string & operator_name,const Shapes & inputs_shape,const Shapes & outputs_shape,const PrimitiveAttrs & attrs)34   UniformCandidateSamplerInfo(const std::string &operator_name, const Shapes &inputs_shape, const Shapes &outputs_shape,
35                               const PrimitiveAttrs &attrs)
36       : OperatorInfo(operator_name, inputs_shape, outputs_shape, attrs,
37                      std::make_shared<UniformCandidateSamplerCost>()),
38         num_sampled_(0),
39         num_true_(0),
40         unique_(false),
41         range_max_(0),
42         seed_(0),
43         remove_accidental_hits_(false) {}
44   ~UniformCandidateSamplerInfo() override = default;
45 
46   Status Init(const StrategyPtr &strategy) override;
47   Status InitForCostModel(const StrategyPtr &strategy) override;
48   std::vector<StrategyPtr> GenerateOpStrategies(int64_t) override;
49   std::shared_ptr<Strategys> GenerateBatchStrategies() override;
50   Status SetCostUnderStrategy(const StrategyPtr &) override;
51   Status InferAsLossDivisor() override;
52   ReplaceGraphPtr replace_graph(const CNodePtr &cnode) override;
53 
54  protected:
55   Status GetAttrs() override;
56   Status CheckStrategy(const StrategyPtr &strategy) override;
InferForwardCommunication()57   Status InferForwardCommunication() override { return SUCCESS; }
58   Status InferDevMatrixShape() override;
59   Status InferTensorMap() override;
60   Status ComputeReplaceGraph(const CNodePtr &cnode);
61 
62  private:
63   Status GetUniformSamplerAttrBool(const std::string &argsy, bool *value);
64   Status GetUniformSamplerAttrInt64(const std::string &args, int64_t *value);
65   int64_t num_sampled_;
66   int64_t num_true_;
67   bool unique_;
68   int64_t range_max_;
69   int64_t seed_;
70   bool remove_accidental_hits_;
71 };
72 }  // namespace parallel
73 }  // namespace mindspore
74 
75 #endif  // MINDSPORE_CCSRC_FRONTEND_PARALLEL_OPS_INFO_UNFORM_CANDIDATE_SAMPLER_INFO_H_
76