1 /** 2 * Copyright 2021-2022 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_CONCAT_OFFSET_CPU_KERNEL_H_ 18 #define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_CONCAT_OFFSET_CPU_KERNEL_H_ 19 20 #include <map> 21 #include <vector> 22 #include <memory> 23 #include <utility> 24 #include "plugin/device/cpu/kernel/cpu_kernel.h" 25 #include "plugin/factory/ms_factory.h" 26 27 namespace mindspore { 28 namespace kernel { 29 class ConcatOffsetCpuKernelMod : public NativeCpuKernelMod { 30 public: 31 ConcatOffsetCpuKernelMod() = default; 32 ~ConcatOffsetCpuKernelMod() override = default; 33 34 bool Init(const std::vector<KernelTensor *> &inputs, const std::vector<KernelTensor *> &outputs) override; 35 36 int Resize(const std::vector<KernelTensor *> &inputs, const std::vector<KernelTensor *> &outputs) override; 37 Launch(const std::vector<KernelTensor * > & inputs,const std::vector<KernelTensor * > & workspace,const std::vector<KernelTensor * > & outputs)38 bool Launch(const std::vector<KernelTensor *> &inputs, const std::vector<KernelTensor *> &workspace, 39 const std::vector<KernelTensor *> &outputs) override { 40 return kernel_func_(this, inputs, outputs); 41 } 42 43 std::vector<KernelAttr> GetOpSupport() override; 44 45 private: 46 template <typename T> 47 bool LaunchKernel(const std::vector<kernel::KernelTensor *> &, const std::vector<kernel::KernelTensor *> &outputs); 48 using ConcatOffsetFunc = std::function<bool(ConcatOffsetCpuKernelMod *, const std::vector<kernel::KernelTensor *> &, 49 const std::vector<kernel::KernelTensor *> &)>; 50 static std::vector<std::pair<KernelAttr, ConcatOffsetFunc>> func_list_; 51 ConcatOffsetFunc kernel_func_; 52 int64_t axis_{0}; 53 std::vector<ShapeVector> input_shapes_; 54 ShapeVector output_shape_; 55 }; 56 } // namespace kernel 57 } // namespace mindspore 58 59 #endif // MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_CONCAT_OFFSET_CPU_KERNEL_H_ 60