You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

cpu_kernel.cc 1.9 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * Copyright 2019 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. #include "kernel/cpu/cpu_kernel.h"
  17. namespace mindspore {
  18. namespace kernel {
  19. void CPUKernel::InitInputOutputSize(const CNodePtr &kernel_node) {
  20. MS_EXCEPTION_IF_NULL(kernel_node);
  21. size_t input_num = AnfAlgo::GetInputTensorNum(kernel_node);
  22. size_t type_size = sizeof(float);
  23. for (size_t input_index = 0; input_index < input_num; ++input_index) {
  24. std::vector<size_t> shape = AnfAlgo::GetInputDeviceShape(kernel_node, input_index);
  25. size_t tensor_size =
  26. shape.empty() ? type_size : std::accumulate(shape.begin(), shape.end(), type_size, std::multiplies<size_t>());
  27. input_size_list_.emplace_back(tensor_size);
  28. }
  29. size_t output_num = AnfAlgo::GetOutputTensorNum(kernel_node);
  30. for (size_t output_index = 0; output_index < output_num; ++output_index) {
  31. std::vector<size_t> shape = AnfAlgo::GetOutputDeviceShape(kernel_node, output_index);
  32. size_t tensor_size =
  33. shape.empty() ? type_size : std::accumulate(shape.begin(), shape.end(), type_size, std::multiplies<size_t>());
  34. output_size_list_.emplace_back(tensor_size);
  35. }
  36. }
  37. void CPUKernel::Init(const CNodePtr &kernel_node) {
  38. InitInputOutputSize(kernel_node);
  39. InitKernel(kernel_node);
  40. }
  41. } // namespace kernel
  42. } // namespace mindspore