1 /** 2 * Copyright 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_PLUGIN_DEVICE_CPU_KERNEL_SET_SIZE_CPU_KERNEL_H_ 18 #define MINDSPORE_CCSRC_PLUGIN_DEVICE_CPU_KERNEL_SET_SIZE_CPU_KERNEL_H_ 19 20 #include <memory> 21 #include <unordered_map> 22 #include <vector> 23 #include <utility> 24 #include <map> 25 26 #include "plugin/device/cpu/kernel/cpu_kernel.h" 27 #include "plugin/factory/ms_factory.h" 28 29 namespace mindspore { 30 namespace kernel { 31 class SetSizeCpuKernelMod : public NativeCpuKernelMod, public MatchKernelHelper<SetSizeCpuKernelMod> { 32 public: 33 SetSizeCpuKernelMod() = default; 34 ~SetSizeCpuKernelMod() override = default; 35 Launch(const std::vector<KernelTensor * > & inputs,const std::vector<KernelTensor * > & workspace,const std::vector<KernelTensor * > & outputs)36 bool Launch(const std::vector<KernelTensor *> &inputs, const std::vector<KernelTensor *> &workspace, 37 const std::vector<KernelTensor *> &outputs) override { 38 MS_EXCEPTION_IF_NULL(kernel_func_); 39 return kernel_func_(this, inputs, workspace, outputs); 40 } 41 42 bool Init(const std::vector<KernelTensor *> &inputs, const std::vector<KernelTensor *> &outputs) override; 43 44 int Resize(const std::vector<KernelTensor *> &inputs, const std::vector<KernelTensor *> &outputs) override; 45 46 const std::vector<std::pair<KernelAttr, KernelRunFunc>> &GetFuncList() const override; 47 48 protected: GetOpSupport()49 std::vector<KernelAttr> GetOpSupport() override { return OpSupport(); } 50 51 template <typename T> 52 bool LaunchKernel(const std::vector<KernelTensor *> &inputs, const std::vector<KernelTensor *> &workspace, 53 const std::vector<KernelTensor *> &outputs); 54 55 private: 56 bool IndicesValid(int64_t n, const std::vector<kernel::KernelTensor *> &inputs) const; 57 58 ShapeVector output_shape_; 59 ShapeVector shape_; 60 bool validate_indices_{true}; 61 int64_t dims_{0}; 62 TypeId val_dtype_{kTypeUnknown}; 63 size_t values_size_{0}; 64 }; 65 } // namespace kernel 66 } // namespace mindspore 67 #endif // MINDSPORE_CCSRC_PLUGIN_DEVICE_CPU_KERNEL_SET_SIZE_CPU_KERNEL_H_ 68