• 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_CCSRC_BACKEND_KERNEL_COMPILER_CPU_MAP_CACHE_IDX_CPU_KERNEL_H_
18 #define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_MAP_CACHE_IDX_CPU_KERNEL_H_
19 
20 #include <math.h>
21 #include <vector>
22 #include <memory>
23 #include <unordered_map>
24 #include "backend/kernel_compiler/cpu/cpu_kernel.h"
25 #include "backend/kernel_compiler/cpu/cpu_kernel_factory.h"
26 
27 namespace mindspore {
28 namespace kernel {
29 class MapCacheIdxCPUKernel : public CPUKernel {
30  public:
31   MapCacheIdxCPUKernel() = default;
32   ~MapCacheIdxCPUKernel() override = default;
33 
34   void InitKernel(const CNodePtr &kernel_node) override;
35 
36   bool Launch(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> &workspace,
37               const std::vector<AddressPtr> &outputs) override;
38 
39  private:
40   template <typename T>
41   void LaunchKernel(const std::vector<AddressPtr> &inputs, const std::vector<kernel::AddressPtr> &outputs);
42 
43   size_t batch_size_{1};
44   size_t hashmap_length_{1};
45   TypeId dtype_{kTypeUnknown};
46   CNodeWeakPtr node_wpt_;
47 };
48 
49 MS_REG_CPU_KERNEL(MapCacheIdx,
50                   KernelAttr()
51                     .AddInputAttr(kNumberTypeInt32)
52                     .AddInputAttr(kNumberTypeInt32)
53                     .AddInputAttr(kNumberTypeInt32)
54                     .AddInputAttr(kNumberTypeInt32)
55                     .AddInputAttr(kNumberTypeInt32)
56                     .AddOutputAttr(kNumberTypeInt32)
57                     .AddOutputAttr(kNumberTypeInt32)
58                     .AddOutputAttr(kNumberTypeInt32)
59                     .AddOutputAttr(kNumberTypeInt32),
60                   MapCacheIdxCPUKernel);
61 
62 MS_REG_CPU_KERNEL(MapCacheIdx,
63                   KernelAttr()
64                     .AddInputAttr(kNumberTypeInt64)
65                     .AddInputAttr(kNumberTypeInt64)
66                     .AddInputAttr(kNumberTypeInt64)
67                     .AddInputAttr(kNumberTypeInt64)
68                     .AddInputAttr(kNumberTypeInt64)
69                     .AddOutputAttr(kNumberTypeInt64)
70                     .AddOutputAttr(kNumberTypeInt64)
71                     .AddOutputAttr(kNumberTypeInt64)
72                     .AddOutputAttr(kNumberTypeInt64),
73                   MapCacheIdxCPUKernel);
74 
75 MS_REG_CPU_KERNEL(MapCacheIdx,
76                   KernelAttr()
77                     .AddInputAttr(kNumberTypeInt64)
78                     .AddInputAttr(kNumberTypeInt64)
79                     .AddInputAttr(kNumberTypeInt32)
80                     .AddInputAttr(kNumberTypeInt32)
81                     .AddInputAttr(kNumberTypeInt32)
82                     .AddOutputAttr(kNumberTypeInt64)
83                     .AddOutputAttr(kNumberTypeInt64)
84                     .AddOutputAttr(kNumberTypeInt64)
85                     .AddOutputAttr(kNumberTypeInt64),
86                   MapCacheIdxCPUKernel);
87 
88 MS_REG_CPU_KERNEL(MapCacheIdx,
89                   KernelAttr()
90                     .AddInputAttr(kNumberTypeInt32)
91                     .AddInputAttr(kNumberTypeInt32)
92                     .AddInputAttr(kNumberTypeInt64)
93                     .AddInputAttr(kNumberTypeInt64)
94                     .AddInputAttr(kNumberTypeInt64)
95                     .AddOutputAttr(kNumberTypeInt32)
96                     .AddOutputAttr(kNumberTypeInt32)
97                     .AddOutputAttr(kNumberTypeInt32)
98                     .AddOutputAttr(kNumberTypeInt32),
99                   MapCacheIdxCPUKernel);
100 }  // namespace kernel
101 }  // namespace mindspore
102 
103 #endif  // MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SEARCH_CACHE_IDX_CPU_KERNEL_H_
104