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.

squeeze_kernel.cc 2.9 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #include "host_kernels/squeeze_kernel.h"
  17. #include "framework/common/ge_inner_error_codes.h"
  18. #include "framework/common/op/ge_op_utils.h"
  19. #include "framework/common/types.h"
  20. #include "framework/common/debug/ge_log.h"
  21. #include "host_kernels/kernel_utils.h"
  22. #include "inc/kernel_factory.h"
  23. namespace {
  24. constexpr uint32_t kInputDescIndex = 0;
  25. constexpr uint32_t kOutputDescIndex = 0;
  26. constexpr size_t kSqueezeInputSize = 1;
  27. constexpr size_t kSqueezeOutputSize = 1;
  28. }
  29. namespace ge {
  30. Status SqueezeKernel::Compute(const NodePtr &node_ptr) {
  31. if (node_ptr == nullptr) {
  32. GELOGE(PARAM_INVALID, "parameter is nullptr");
  33. return PARAM_INVALID;
  34. }
  35. if (!KernelUtils::CheckFormatSupported(node_ptr)) {
  36. GELOGW("CheckFormatSupported failed");
  37. return NOT_CHANGED;
  38. }
  39. return SUCCESS;
  40. }
  41. Status SqueezeKernel::Compute(const ge::OpDescPtr op_desc, const std::vector<ge::ConstGeTensorPtr> &input,
  42. std::vector<ge::GeTensorPtr> &v_output) {
  43. if (op_desc == nullptr) {
  44. GELOGE(PARAM_INVALID, "SqueezeKernel op_desc is null.");
  45. return PARAM_INVALID;
  46. }
  47. GELOGD("SqueezeKernel in: node[%s]", op_desc->GetName().c_str());
  48. bool size_check = ((op_desc->GetInputsSize() != kSqueezeInputSize) ||
  49. (op_desc->GetOutputsSize() != kSqueezeOutputSize) || (input.size() != kSqueezeInputSize));
  50. if (size_check) {
  51. GELOGW("Size check fail, node[%s] inputs size:%zu, outputs size:%zu", op_desc->GetName().c_str(),
  52. op_desc->GetInputsSize(), op_desc->GetOutputsSize());
  53. return NOT_CHANGED;
  54. }
  55. auto tensor_desc = op_desc->GetOutputDesc(kOutputDescIndex);
  56. GeTensorPtr output_ptr = MakeShared<ge::GeTensor>(tensor_desc);
  57. if (output_ptr == nullptr) {
  58. GELOGE(PARAM_INVALID, "node [%s] make shared failed.", op_desc->GetName().c_str());
  59. return PARAM_INVALID;
  60. }
  61. auto ge_tensor = input.at(kInputDescIndex);
  62. if (ge_tensor == nullptr) {
  63. GELOGE(PARAM_INVALID, "node [%s] get input failed.", op_desc->GetName().c_str());
  64. return PARAM_INVALID;
  65. }
  66. if (output_ptr->SetData(ge_tensor->GetData()) != GRAPH_SUCCESS) {
  67. GELOGW("Compute: SetData failed");
  68. }
  69. v_output.emplace_back(output_ptr);
  70. GELOGI("SqueezeKernel success: node[%s]", op_desc->GetName().c_str());
  71. return SUCCESS;
  72. }
  73. REGISTER_KERNEL(SQUEEZE, SqueezeKernel);
  74. } // namespace ge

图引擎模块(GE)是MindSpore的一个子模块,其代码由C++实现,位于前端模块ME和底层硬件之间,起到承接作用。图引擎模块以ME下发的图作为输入,然后进行一系列的深度图优化操作,最后输出一张可以在底层硬件上高效运行的图。GE针对昇腾AI处理器的硬件结构特点,做了特定的优化工作,以此来充分发挥出昇腾AI处理器的强大算力。在进行模型训练/推理时,GE会被自动调用而用户并不感知。GE主要由GE API和GE Core两部分组成,详细的架构图如下所示