• 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 #ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_AICPU_AICPU_KERNEL_MOD_H_
17 #define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_AICPU_AICPU_KERNEL_MOD_H_
18 #include <vector>
19 #include <memory>
20 #include <string>
21 #include "backend/kernel_compiler/ascend_kernel_mod.h"
22 #include "backend/kernel_compiler/aicpu/aicpu_util.h"
23 namespace mindspore {
24 namespace kernel {
25 class AicpuOpKernelMod : public AscendKernelMod {
26  public:
27   AicpuOpKernelMod();
28   ~AicpuOpKernelMod() override;
29   bool Launch(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> &workspace,
30               const std::vector<AddressPtr> &outputs, void *stream_ptr) override;
31 
32   std::vector<TaskInfoPtr> GenTask(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> &workspace,
33                                    const std::vector<AddressPtr> &outputs, uint32_t stream_id) override;
34   device::DynamicKernelPtr GenDynamicKernel(const CNodePtr &cnode_ptr, void *stream_ptr) override;
35 
36   void SetInputList(const std::vector<int64_t> &inputList);
37   void SetOutputList(const std::vector<int64_t> &outputList);
38   void SetAnfNode(const AnfNodePtr &anf_node);
39   void SetNodeDef(const std::string &nodeDef);
40   void SetExtInfo(const std::string &ext_info);
41   void SetNodeName(const std::string &node_name);
42 
43   /**
44    *  @brief Build AICPU Engine kernel structure, and allocate device memory for offline task generate
45    *  @return SUCCESS
46    *  @return FAIL
47    *
48    */
49   void CreateCpuKernelInfo(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> &outputs);
50 
51   void SetInputSizeList(const std::vector<size_t> &size_list);
52   void SetOutputSizeList(const std::vector<size_t> &size_list);
53   void SetWorkspaceSizeList(const std::vector<size_t> &size_list);
54   const std::vector<size_t> &GetInputSizeList() const override;
55   const std::vector<size_t> &GetOutputSizeList() const override;
56   const std::vector<size_t> &GetWorkspaceSizeList() const override;
57 
58  private:
59   std::string args_;
60   std::string node_def_str_;
61   std::string node_name_;
62   std::string node_so_;
63   std::string ext_info_;
64   std::vector<int64_t> inputList_;
65   std::vector<int64_t> outputList_;
66   AnfNodePtr anf_node_;
67 
68   std::vector<size_t> input_size_list_;
69   std::vector<size_t> output_size_list_;
70   std::vector<size_t> workspace_size_list_;
71 };
72 
73 using AicpuOpKernelModPtr = std::shared_ptr<AicpuOpKernelMod>;
74 using AicputOpKernelModPtrList = std::vector<AicpuOpKernelModPtr>;
75 }  // namespace kernel
76 }  // namespace mindspore
77 
78 #endif  // MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_AICPU_AICPU_KERNEL_MOD_H_
79