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.

ms_tensor.h 4.3 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. #ifndef MINDSPORE_LITE_INCLUDE_MS_TENSOR_H_
  17. #define MINDSPORE_LITE_INCLUDE_MS_TENSOR_H_
  18. #include <vector>
  19. #include "include/lite_utils.h"
  20. #include "ir/dtype/type_id.h"
  21. namespace mindspore {
  22. enum Format : int64_t;
  23. namespace tensor {
  24. /// \brief MSTensor defined tensor in MindSpore Lite.
  25. class MS_API MSTensor {
  26. public:
  27. /// \brief Constructor of MindSpore Lite MSTensor.
  28. ///
  29. /// \return Instance of MindSpore Lite MSTensor.
  30. MSTensor() = default;
  31. /// \brief Destructor of MindSpore Lite Model.
  32. virtual ~MSTensor() = default;
  33. /// \brief Create a MSTensor.
  34. ///
  35. /// \return Pointer to an instance of MindSpore Lite MSTensor.
  36. static MSTensor *CreateTensor(const String &name, TypeId type, const Vector<int> &shape, const void *data,
  37. size_t data_len);
  38. /// \brief Set memory allocator for current MSTensor.
  39. ///
  40. /// \param[in] allocator Define memory allocator, which is shown in allocator.h.
  41. virtual void set_allocator(AllocatorPtr allocator) = 0;
  42. /// \brief Get memory allocator of current MSTensor.
  43. ///
  44. /// \return Pointer of memory allocator class.
  45. virtual AllocatorPtr allocator() const = 0;
  46. /// \brief Get data type of the MindSpore Lite MSTensor.
  47. ///
  48. /// \note TypeId is defined in mindspore/mindspore/include/api/type_id.h. Only number types in TypeId enum are
  49. /// suitable for MSTensor.
  50. ///
  51. /// \return MindSpore Lite TypeId of the MindSpore Lite MSTensor.
  52. virtual TypeId data_type() const = 0;
  53. /// \brief Set data type of current MSTensor.
  54. ///
  55. /// \param[in] data_type Define data type, which is shown in type_id.h.
  56. virtual void set_data_type(TypeId data_type) = 0;
  57. /// \brief Set format of current MSTensor.
  58. ///
  59. /// \param[in] format Define format of data, which is shown in format.h
  60. virtual void set_format(mindspore::Format format) = 0;
  61. /// \brief Get format of current MSTensor.
  62. ///
  63. /// \return format, which is shown in format.h
  64. virtual mindspore::Format format() const = 0;
  65. /// \brief Get shape of the MindSpore Lite MSTensor.
  66. ///
  67. /// \return A vector of int as the shape of the MindSpore Lite MSTensor.
  68. virtual Vector<int> shape() const = 0;
  69. /// \brief Set the shape of MSTensor.
  70. virtual void set_shape(const Vector<int> &shape) = 0;
  71. /// \brief Get number of element in MSTensor.
  72. ///
  73. /// \return Number of element in MSTensor.
  74. virtual int ElementsNum() const = 0;
  75. /// \brief Get byte size of data in MSTensor.
  76. ///
  77. /// \return Byte size of data in MSTensor.
  78. virtual size_t Size() const = 0;
  79. /// \brief Get the name of MSTensor.
  80. ///
  81. /// \return the name of MSTensor.
  82. virtual String tensor_name() const = 0;
  83. /// \brief Set the name of MSTensor.
  84. virtual void set_tensor_name(const String &name) = 0;
  85. /// \brief Get the pointer of data in MSTensor.
  86. ///
  87. /// \note The data pointer can be used to both write and read data in MSTensor. The memory buffer will be
  88. /// automatically allocated.
  89. ///
  90. /// \return the pointer points to data in MSTensor.
  91. virtual void *MutableData() = 0;
  92. /// \brief Get the pointer of data in MSTensor.
  93. ///
  94. /// \note The data pointer can be used to both write and read data in MSTensor. No memory buffer will be
  95. /// allocated.
  96. ///
  97. /// \return the pointer points to data in MSTensor.
  98. virtual void *data() = 0;
  99. /// \brief Set the data of MSTensor.
  100. virtual void set_data(void *data) = 0;
  101. virtual Vector<lite::LiteQuantParam> quant_params() const = 0;
  102. virtual void set_quant_params(Vector<lite::LiteQuantParam>) = 0;
  103. };
  104. } // namespace tensor
  105. } // namespace mindspore
  106. #endif // MINDSPORE_LITE_INCLUDE_MS_TENSOR_H_