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.h 3.5 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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_EXTERNAL_GRAPH_TENSOR_H_
  17. #define INC_EXTERNAL_GRAPH_TENSOR_H_
  18. #include <atomic>
  19. #include <memory>
  20. #include <string>
  21. #include <vector>
  22. #include "./ge_error_codes.h"
  23. #include "./types.h"
  24. namespace ge {
  25. class ShapeImpl;
  26. class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Shape {
  27. public:
  28. Shape();
  29. ~Shape() = default;
  30. explicit Shape(const std::vector<int64_t> &dims);
  31. size_t GetDimNum() const;
  32. // If the idx is invalid, return 0
  33. int64_t GetDim(size_t idx) const;
  34. graphStatus SetDim(size_t idx, int64_t value);
  35. std::vector<int64_t> GetDims() const;
  36. int64_t GetShapeSize() const;
  37. private:
  38. std::shared_ptr<ShapeImpl> impl_;
  39. };
  40. class TensorDescImpl;
  41. class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY TensorDesc {
  42. public:
  43. TensorDesc();
  44. ~TensorDesc() = default;
  45. explicit TensorDesc(Shape shape, Format format = FORMAT_ND, DataType dt = DT_FLOAT);
  46. // Copy
  47. TensorDesc(const TensorDesc &desc);
  48. // Move
  49. TensorDesc(TensorDesc &&desc);
  50. // Copy
  51. TensorDesc &operator=(const TensorDesc &desc);
  52. // Move
  53. TensorDesc &operator=(TensorDesc &&desc);
  54. void Update(const Shape &shape, Format format = FORMAT_ND, DataType dt = DT_FLOAT);
  55. Shape GetShape() const;
  56. void SetShape(const Shape &shape);
  57. Format GetFormat() const;
  58. void SetFormat(Format format);
  59. Shape GetOriginShape() const;
  60. void SetOriginShape(const Shape &originShape);
  61. Format GetOriginFormat() const;
  62. void SetOriginFormat(Format originFormat);
  63. DataType GetDataType() const;
  64. void SetDataType(DataType dt);
  65. std::string GetName() const;
  66. void SetName(const std::string &name);
  67. // Attr acess
  68. void SetSize(int64_t size);
  69. int64_t GetSize() const;
  70. int64_t GetRealDimCnt() const;
  71. void SetRealDimCnt(const int64_t realDimCnt);
  72. private:
  73. std::shared_ptr<TensorDescImpl> impl;
  74. };
  75. class TensorImpl;
  76. class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Tensor {
  77. public:
  78. Tensor();
  79. ~Tensor() = default;
  80. explicit Tensor(const TensorDesc &tensorDesc);
  81. Tensor(const TensorDesc &tensorDesc, const std::vector<uint8_t> &data);
  82. Tensor(const TensorDesc &tensorDesc, const uint8_t *data, size_t size);
  83. Tensor(TensorDesc &&tensorDesc, std::vector<uint8_t> &&data);
  84. TensorDesc GetTensorDesc() const;
  85. graphStatus SetTensorDesc(const TensorDesc &tensorDesc);
  86. const uint8_t *GetData() const;
  87. uint8_t *GetData();
  88. size_t GetSize() const;
  89. graphStatus SetData(std::vector<uint8_t> &&data);
  90. graphStatus SetData(const std::vector<uint8_t> &data);
  91. graphStatus SetData(const uint8_t *data, size_t size);
  92. graphStatus SetData(const std::string &data);
  93. graphStatus SetData(const std::vector<std::string> &data);
  94. graphStatus IsValid();
  95. Tensor Clone() const;
  96. private:
  97. std::shared_ptr<TensorImpl> impl;
  98. friend class TensorAdapter;
  99. };
  100. } // namespace ge
  101. #endif // INC_EXTERNAL_GRAPH_TENSOR_H_

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