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.

tensor_utils.h 4.3 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * Copyright 2019-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 INC_GRAPH_UTILS_TENSOR_UTILS_H_
  17. #define INC_GRAPH_UTILS_TENSOR_UTILS_H_
  18. #include <vector>
  19. #include "graph/def_types.h"
  20. #include "graph/ge_error_codes.h"
  21. #include "graph/ge_tensor.h"
  22. namespace ge {
  23. class TensorUtils {
  24. public:
  25. static ge::graphStatus GetSize(const GeTensorDesc &tensorDesc, int64_t &size);
  26. static void SetSize(GeTensorDesc &tensorDesc, int64_t size);
  27. static uint32_t GetWeightSize(const ConstGeTensorPtr &tensorPtr);
  28. static uint32_t GetWeightSize(const GeTensor &tensor);
  29. static uint32_t GetWeightSize(const GeTensorDesc &tensorDesc);
  30. static uint8_t *GetWeightAddr(const ConstGeTensorPtr &tensorPtr, uint8_t *base);
  31. static uint8_t *GetWeightAddr(const GeTensor &tensor, uint8_t *base);
  32. static void SetWeightSize(GeTensorDesc &tensorDesc, uint32_t size);
  33. static ge::graphStatus GetReuseInput(const GeTensorDesc &tensorDesc, bool &flag);
  34. static void SetReuseInput(GeTensorDesc &tensorDesc, bool flag);
  35. static ge::graphStatus GetOutputTensor(const GeTensorDesc &tensorDesc, bool &flag);
  36. static void SetOutputTensor(GeTensorDesc &tensorDesc, bool flag);
  37. static graphStatus GetDeviceType(const GeTensorDesc &tensorDesc, DeviceType &type);
  38. static void SetDeviceType(GeTensorDesc &tensorDesc, DeviceType type);
  39. static ge::graphStatus GetInputTensor(const GeTensorDesc &tensorDesc, bool &flag);
  40. static void SetInputTensor(GeTensorDesc &tensorDesc, bool flag);
  41. static ge::graphStatus GetRealDimCnt(const GeTensorDesc &tensorDesc, uint32_t &cnt);
  42. static void SetRealDimCnt(GeTensorDesc &tensorDesc, uint32_t cnt);
  43. static ge::graphStatus GetReuseInputIndex(const GeTensorDesc &tensorDesc, uint32_t &idx);
  44. static void SetReuseInputIndex(GeTensorDesc &tensorDesc, uint32_t idx);
  45. static ge::graphStatus GetDataOffset(const GeTensorDesc &tensorDesc, int64_t &offset);
  46. static void SetDataOffset(GeTensorDesc &tensorDesc, int64_t offset);
  47. static ge::graphStatus GetCmpsSize(const GeTensorDesc &tensorDesc, uint32_t &cmp_size);
  48. static void SetCmpsSize(GeTensorDesc &tensorDesc, uint32_t cmp_size);
  49. static ge::graphStatus GetCmpsTab(const GeTensorDesc &tensorDesc, vector<uint8_t> &vec);
  50. static void SetCmpsTab(GeTensorDesc &tensorDesc, const uint8_t *data, size_t size);
  51. static ge::graphStatus GetCmpsTabOffset(const GeTensorDesc &tensorDesc, int64_t &tab_offset);
  52. static void SetCmpsTabOffset(GeTensorDesc &tensorDesc, int64_t tab_offset);
  53. static ge::graphStatus GetCmpsInfo(const GeTensorDesc &tensorDesc, CompressInfo &info);
  54. static void SetCmpsInfo(GeTensorDesc &tensorDesc, const CompressInfo &info);
  55. static bool HasAlloffsetQuantizeInfo(const GeTensorDesc &tensorDesc);
  56. static ge::graphStatus GetAlloffsetQuantizeInfo(const GeTensorDesc &tensorDesc, AllOffsetQuantizeInfo &info);
  57. static void SetAlloffsetQuantizeInfo(GeTensorDesc &tensorDesc, const AllOffsetQuantizeInfo &info);
  58. static ge::graphStatus GetRC(const GeTensorDesc &tensorDesc, uint32_t &rc);
  59. static void SetRC(GeTensorDesc &tensorDesc, uint32_t rc);
  60. ///
  61. /// calculate tensor mem size.
  62. /// @param shape tensor shape
  63. /// @param format tensor format
  64. /// @param data_type tensor data type
  65. /// @param mem_size -1 means unknown shape,other means mem size
  66. /// @return GRAPH_SUCCESS:success, other:failed
  67. ///
  68. static ge::graphStatus CalcTensorMemSize(const GeShape &shape, Format format, DataType data_type, int64_t &mem_size);
  69. static ge::graphStatus GetTensorMemorySizeInBytes(const GeTensorDesc &desc_temp, int64_t &size_temp);
  70. static ge::graphStatus GetTensorSizeInBytes(const GeTensorDesc &desc_temp, int64_t &size_temp);
  71. };
  72. } // namespace ge
  73. #endif // INC_GRAPH_UTILS_TENSOR_UTILS_H_

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