• 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_MINDSPORE_CCSRC_RUNTIME_DEVICE_ASCEND_EXECUTOR_EXECUTOR_H_
18 #define MINDSPORE_MINDSPORE_CCSRC_RUNTIME_DEVICE_ASCEND_EXECUTOR_EXECUTOR_H_
19 
20 #include <memory>
21 #include <string>
22 #include <vector>
23 #include <map>
24 #include "ir/anf.h"
25 #include "ir/tensor.h"
26 #include "abstract/primitive_infer_map.h"
27 
28 namespace mindspore {
29 namespace device {
30 class DynamicKernel {
31  public:
DynamicKernel(void * stream,const CNodePtr & cnode_ptr)32   DynamicKernel(void *stream, const CNodePtr &cnode_ptr)
33       : stream_(stream),
34         cnode_ptr_(cnode_ptr),
35         is_dynamic_shape_(false),
36         is_input_dynamic_shape_(false),
37         is_output_dynamic_shape_(false) {}
38   virtual ~DynamicKernel() = default;
39   virtual void InferShape();
40   virtual void UpdateArgs() = 0;
41   virtual void Execute() = 0;
42   virtual void PostExecute() = 0;
is_dynamic_shape()43   [[nodiscard]] bool is_dynamic_shape() const { return is_dynamic_shape_; }
have_depends()44   [[nodiscard]] bool have_depends() const { return !depend_list_.empty(); }
45   virtual void Initialize();
46   [[nodiscard]] int GetKernelType() const;
47 
48  protected:
49   void RebuildDependTensor();
50   void InferShapeRecursive();
51   static void InferShapeForNopNode(AnfNodePtr *input_node);
52 
53   void *stream_;
54   const CNodeWeakPtr cnode_ptr_;
55   bool is_dynamic_shape_;
56   bool is_input_dynamic_shape_;
57   bool is_output_dynamic_shape_;
58   std::vector<uint32_t> depend_list_;
59   std::map<uint32_t, tensor::TensorPtr> depend_tensor_map_;
60 };
61 using DynamicKernelPtr = std::shared_ptr<DynamicKernel>;
62 }  // namespace device
63 }  // namespace mindspore
64 #endif  // MINDSPORE_MINDSPORE_CCSRC_RUNTIME_DEVICE_ASCEND_EXECUTOR_EXECUTOR_H_
65