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

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