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

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

Contributors (1)