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_FTRL_CPU_KERNEL_H_ 18 #define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SPARSE_APPLY_FTRL_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 SparseApplyFtrlCPUKernel : public SparseOptimizerCPUKernel { 26 public: 27 SparseApplyFtrlCPUKernel() = default; 28 ~SparseApplyFtrlCPUKernel() 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 float lr_{0.0}; 36 float l1_{0.0}; 37 float l2_{0.0}; 38 float lr_power_{0.0}; 39 40 private: 41 void InitInputOutputSize(const CNodePtr &kernel_node) override; 42 43 template <typename T> 44 void InitWorkspaceSize(); 45 46 template <typename T> 47 void LaunchKernel(const std::vector<kernel::AddressPtr> &inputs, 48 const std::vector<kernel::AddressPtr> &workspace) const; 49 }; 50 51 MS_REG_CPU_KERNEL(FusedSparseFtrl, 52 KernelAttr() 53 .AddInputAttr(kNumberTypeFloat32) 54 .AddInputAttr(kNumberTypeFloat32) 55 .AddInputAttr(kNumberTypeFloat32) 56 .AddInputAttr(kNumberTypeFloat32) 57 .AddInputAttr(kNumberTypeInt32) 58 .AddOutputAttr(kNumberTypeFloat32) 59 .AddOutputAttr(kNumberTypeFloat32) 60 .AddOutputAttr(kNumberTypeFloat32), 61 SparseApplyFtrlCPUKernel); 62 63 MS_REG_CPU_KERNEL(FusedSparseFtrl, 64 KernelAttr() 65 .AddInputAttr(kNumberTypeFloat32) 66 .AddInputAttr(kNumberTypeFloat32) 67 .AddInputAttr(kNumberTypeFloat32) 68 .AddInputAttr(kNumberTypeFloat32) 69 .AddInputAttr(kNumberTypeInt64) 70 .AddOutputAttr(kNumberTypeFloat32) 71 .AddOutputAttr(kNumberTypeFloat32) 72 .AddOutputAttr(kNumberTypeFloat32), 73 SparseApplyFtrlCPUKernel); 74 } // namespace kernel 75 } // namespace mindspore 76 77 #endif // MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SPARSE_APPLY_FTRL_CPU_KERNEL_H_ 78