• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2022 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_PIPELINE_PYNATIVE_FORWARD_DO_CAST_H_
18 #define MINDSPORE_CCSRC_PIPELINE_PYNATIVE_FORWARD_DO_CAST_H_
19 
20 #include <vector>
21 #include <string>
22 #include <memory>
23 #include <utility>
24 #include <map>
25 #include "pipeline/pynative/forward/cast_base.h"
26 
27 namespace mindspore {
28 namespace pynative {
29 class CastOperation : public CastBaseOperation {
30  public:
31   CastOperation() = default;
32   ~CastOperation() = default;
33   void DoCast(const FrontendOpRunInfoPtr &op_run_info);
34   void ClearRes();
35   ValuePtr DoNormalCast(const FrontendOpRunInfoPtr &cast_run_info, const ValuePtr &v, const TypeId &type_id) const;
36 
37  private:
38   bool IsValueTypeInvalid(const ValuePtr &v) const;
39   void SetTensorMixPrecisionCast(const FrontendOpRunInfoPtr &op_run_info) const;
40   ValuePtr DoParamMixPrecisionCastTuple(const FrontendOpRunInfoPtr &op_run_info, bool *is_cast,
41                                         const ValueSequencePtr &value_seq, const std::string &op_name,
42                                         size_t index) const;
43   ValuePtr DoParamMixPrecisionCast(const FrontendOpRunInfoPtr &op_run_info, bool *is_cast, const ValuePtr &v,
44                                    const std::string &op_name, size_t index) const;
45   ValuePtr DoAutoCast(const FrontendOpRunInfoPtr &op_run_info, const ValuePtr &v,
46                       const std::pair<TypeId, bool> &dst_type, const std::string &op_name, size_t index) const;
47   void DoSignatureCast(const FrontendOpRunInfoPtr &op_run_info,
48                        const std::map<SignatureEnumDType, std::pair<TypeId, bool>> &dst_type,
49                        const std::vector<SignatureEnumDType> &dtypes) const;
50   void SetImplicitCast(const FrontendOpRunInfoPtr &op_run_info);
51 };
52 using CastOperationPtr = std::shared_ptr<CastOperation>;
53 }  // namespace pynative
54 }  // namespace mindspore
55 
56 #endif  // MINDSPORE_CCSRC_PIPELINE_PYNATIVE_FORWARD_DO_CAST_H_
57