• 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_EMBEDDING_LOOK_UP_CPU_KERNEL_H_
18 #define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_EMBEDDING_LOOK_UP_CPU_KERNEL_H_
19 
20 #include <vector>
21 #include <memory>
22 #include "backend/kernel_compiler/cpu/cpu_kernel.h"
23 #include "backend/kernel_compiler/cpu/cpu_kernel_factory.h"
24 
25 namespace mindspore {
26 namespace kernel {
27 class EmbeddingLookUpCPUKernel : public CPUKernel {
28  public:
EmbeddingLookUpCPUKernel()29   EmbeddingLookUpCPUKernel() {}
~EmbeddingLookUpCPUKernel()30   ~EmbeddingLookUpCPUKernel() override {}
31 
32   void InitKernel(const CNodePtr &kernel_node) override;
33 
34   bool Launch(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> &workspace,
35               const std::vector<AddressPtr> &outputs) override;
36 
37  protected:
38   template <typename T>
39   void LaunchKernel(const std::vector<kernel::AddressPtr> &inputs, const std::vector<kernel::AddressPtr> &outputs);
40 
41   int64_t offset_{0};
42   size_t indices_lens_{1};
43   size_t first_dim_size_{1};
44   size_t outer_dim_size_{1};
45   TypeId indices_data_type_{kNumberTypeInt32};
46   CNodeWeakPtr node_wpt_;
47 };
48 
49 MS_REG_CPU_KERNEL(
50   EmbeddingLookup,
51   KernelAttr().AddInputAttr(kNumberTypeFloat32).AddInputAttr(kNumberTypeInt32).AddOutputAttr(kNumberTypeFloat32),
52   EmbeddingLookUpCPUKernel);
53 
54 MS_REG_CPU_KERNEL(
55   EmbeddingLookup,
56   KernelAttr().AddInputAttr(kNumberTypeInt32).AddInputAttr(kNumberTypeInt32).AddOutputAttr(kNumberTypeInt32),
57   EmbeddingLookUpCPUKernel);
58 
59 MS_REG_CPU_KERNEL(
60   EmbeddingLookup,
61   KernelAttr().AddInputAttr(kNumberTypeFloat32).AddInputAttr(kNumberTypeInt64).AddOutputAttr(kNumberTypeFloat32),
62   EmbeddingLookUpCPUKernel);
63 }  // namespace kernel
64 }  // namespace mindspore
65 
66 #endif  // MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_EMBEDDING_LOOK_UP_CPU_KERNEL_H_
67