• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020-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_BACKEND_KERNEL_COMPILER_CPU_SPARSE_APPLY_LAZY_ADAM_CPU_KERNEL_H_
18 #define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SPARSE_APPLY_LAZY_ADAM_CPU_KERNEL_H_
19 
20 #include <vector>
21 #include "backend/kernel_compiler/cpu/sparse_optimizer_cpu_kernel.h"
22 
23 namespace mindspore {
24 namespace kernel {
25 class SparseApplyLazyAdamCPUKernel : public SparseOptimizerCPUKernel {
26  public:
27   SparseApplyLazyAdamCPUKernel() = default;
28   ~SparseApplyLazyAdamCPUKernel() override = default;
29 
30   void InitKernel(const CNodePtr &kernel_node) override;
31   bool Launch(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> &workspace,
32               const std::vector<AddressPtr> &outputs) override;
33 
34  protected:
35   void InitInputOutputSize(const CNodePtr &kernel_node) override;
36   bool use_nesterov_{false};
37 
38  private:
39   template <typename T>
40   void InitWorkspaceSize();
41 
42   template <typename T>
43   void LaunchKernel(const std::vector<kernel::AddressPtr> &inputs,
44                     const std::vector<kernel::AddressPtr> &workspace) const;
45 };
46 
47 MS_REG_CPU_KERNEL(FusedSparseLazyAdam,
48                   KernelAttr()
49                     .AddInputAttr(kNumberTypeFloat32)
50                     .AddInputAttr(kNumberTypeFloat32)
51                     .AddInputAttr(kNumberTypeFloat32)
52                     .AddInputAttr(kNumberTypeFloat32)
53                     .AddInputAttr(kNumberTypeFloat32)
54                     .AddInputAttr(kNumberTypeFloat32)
55                     .AddInputAttr(kNumberTypeFloat32)
56                     .AddInputAttr(kNumberTypeFloat32)
57                     .AddInputAttr(kNumberTypeFloat32)
58                     .AddInputAttr(kNumberTypeFloat32)
59                     .AddInputAttr(kNumberTypeInt32)
60                     .AddOutputAttr(kNumberTypeFloat32)
61                     .AddOutputAttr(kNumberTypeFloat32)
62                     .AddOutputAttr(kNumberTypeFloat32),
63                   SparseApplyLazyAdamCPUKernel);
64 
65 MS_REG_CPU_KERNEL(FusedSparseLazyAdam,
66                   KernelAttr()
67                     .AddInputAttr(kNumberTypeFloat32)
68                     .AddInputAttr(kNumberTypeFloat32)
69                     .AddInputAttr(kNumberTypeFloat32)
70                     .AddInputAttr(kNumberTypeFloat32)
71                     .AddInputAttr(kNumberTypeFloat32)
72                     .AddInputAttr(kNumberTypeFloat32)
73                     .AddInputAttr(kNumberTypeFloat32)
74                     .AddInputAttr(kNumberTypeFloat32)
75                     .AddInputAttr(kNumberTypeFloat32)
76                     .AddInputAttr(kNumberTypeFloat32)
77                     .AddInputAttr(kNumberTypeInt64)
78                     .AddOutputAttr(kNumberTypeFloat32)
79                     .AddOutputAttr(kNumberTypeFloat32)
80                     .AddOutputAttr(kNumberTypeFloat32),
81                   SparseApplyLazyAdamCPUKernel);
82 }  // namespace kernel
83 }  // namespace mindspore
84 
85 #endif  // MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SPARSE_APPLY_LAZY_ADAM_CPU_KERNEL_H_
86