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 #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_SPARSETODENSE_H_ 17 #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_SPARSETODENSE_H_ 18 19 #include <vector> 20 #include "src/inner_kernel.h" 21 22 #include "include/context.h" 23 #include "nnacl/fp32/sparse_to_dense_fp32.h" 24 #include "src/runtime/kernel/arm/base/layout_transform.h" 25 26 using mindspore::lite::InnerContext; 27 28 namespace mindspore::kernel { 29 class SparseToDenseCPUKernel : public InnerKernel { 30 public: SparseToDenseCPUKernel(OpParameter * parameter,const std::vector<lite::Tensor * > & inputs,const std::vector<lite::Tensor * > & outputs,const lite::InnerContext * ctx)31 SparseToDenseCPUKernel(OpParameter *parameter, const std::vector<lite::Tensor *> &inputs, 32 const std::vector<lite::Tensor *> &outputs, const lite::InnerContext *ctx) 33 : InnerKernel(parameter, inputs, outputs, ctx), ctx_(ctx), thread_count_(ctx->thread_num_) { 34 s2d_param = (reinterpret_cast<SparseToDenseParameter *>(op_parameter_)); 35 s2d_param->thread_num_ = thread_count_; 36 } 37 ~SparseToDenseCPUKernel() = default; 38 39 int Init() override; 40 int ReSize() override; 41 int Run() override; 42 int DoExcute(int task_id); 43 int GenerateIndices(); 44 int IndicesValidCheck() const; 45 46 protected: 47 const InnerContext *ctx_; 48 int thread_count_; 49 SparseToDenseParameter *s2d_param; 50 51 private: 52 int **sparse_indices_vect = nullptr; 53 float *sparse_values = nullptr; 54 float default_value = 0; 55 bool isScalar = false; 56 int index_num = 0; 57 int index_dim = 0; 58 float *output_data = nullptr; 59 int output_shape[4] = {0}; 60 int output_num = 0; 61 int64_t count_unit_ = 0; 62 }; 63 } // namespace mindspore::kernel 64 #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_SPARSETODENSE_H_ 65