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 3.6 kB

5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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_INTERNAL_INCLUDE_MS_TENSOR_H_
  17. #define MINDSPORE_LITE_INTERNAL_INCLUDE_MS_TENSOR_H_
  18. #include "internal/include/lite_utils.h"
  19. enum TypeId : int {
  20. kTypeUnknown = 0,
  21. kMetaTypeBegin = kTypeUnknown,
  22. kMetaTypeType, // Type
  23. kMetaTypeAnything,
  24. kMetaTypeObject,
  25. kMetaTypeTypeType, // TypeType
  26. kMetaTypeProblem,
  27. kMetaTypeExternal,
  28. kMetaTypeNone,
  29. kMetaTypeNull,
  30. kMetaTypeEllipsis,
  31. kMetaTypeEnd,
  32. //
  33. // Object types
  34. //
  35. kObjectTypeBegin = kMetaTypeEnd,
  36. kObjectTypeNumber,
  37. kObjectTypeString,
  38. kObjectTypeList,
  39. kObjectTypeTuple,
  40. kObjectTypeSlice,
  41. kObjectTypeKeyword,
  42. kObjectTypeTensorType,
  43. kObjectTypeRowTensorType,
  44. kObjectTypeSparseTensorType,
  45. kObjectTypeUndeterminedType,
  46. kObjectTypeClass,
  47. kObjectTypeDictionary,
  48. kObjectTypeFunction,
  49. kObjectTypeJTagged,
  50. kObjectTypeSymbolicKeyType,
  51. kObjectTypeEnvType,
  52. kObjectTypeRefKey,
  53. kObjectTypeRef,
  54. kObjectTypeEnd,
  55. //
  56. // Number Types
  57. //
  58. kNumberTypeBegin = kObjectTypeEnd,
  59. kNumberTypeBool,
  60. kNumberTypeInt,
  61. kNumberTypeInt8,
  62. kNumberTypeInt16,
  63. kNumberTypeInt32,
  64. kNumberTypeInt64,
  65. kNumberTypeUInt,
  66. kNumberTypeUInt8,
  67. kNumberTypeUInt16,
  68. kNumberTypeUInt32,
  69. kNumberTypeUInt64,
  70. kNumberTypeFloat,
  71. kNumberTypeFloat16,
  72. kNumberTypeFloat32,
  73. kNumberTypeFloat64,
  74. kNumberTypeEnd
  75. };
  76. enum Format {
  77. Format_NCHW = 0,
  78. Format_NHWC = 1,
  79. Format_NHWC4 = 2,
  80. Format_HWKC = 3,
  81. Format_HWCK = 4,
  82. Format_KCHW = 5,
  83. Format_CKHW = 6,
  84. Format_KHWC = 7,
  85. Format_CHWK = 8,
  86. Format_HW = 9,
  87. Format_HW4 = 10,
  88. Format_NC = 11,
  89. Format_NC4 = 12,
  90. Format_NC4HW4 = 100,
  91. Format_NUM_OF_FORMAT = 101,
  92. Format_MIN = Format_NCHW,
  93. Format_MAX = Format_NUM_OF_FORMAT
  94. };
  95. typedef struct MSTensor {
  96. enum Category {
  97. CONST, // weight tensor
  98. VAR // activation tensor
  99. };
  100. void *data_ = NULL;
  101. void *device_data_ = NULL;
  102. TypeId data_type_;
  103. Format format_ = Format_NHWC;
  104. Category category_ = VAR;
  105. ShapeVector shape_;
  106. size_t refCount = 0;
  107. int32_t Batch() const;
  108. int32_t Channel() const;
  109. int32_t Height() const;
  110. int32_t Width() const;
  111. /// \brief Get size of the dimension of the MindSpore Lite MSTensor index by the parameter index.
  112. ///
  113. /// \param[in] index Define index of dimension returned.
  114. ///
  115. /// \return Size of dimension of the MindSpore Lite MSTensor.
  116. int DimensionSize(size_t index) const;
  117. /// \brief Get number of element in MSTensor.
  118. ///
  119. /// \return Number of element in MSTensor.
  120. int ElementsNum() const;
  121. int ElementsC4Num() const;
  122. /// \brief Get byte size of data in MSTensor.
  123. ///
  124. /// \return Byte size of data in MSTensor.
  125. size_t Size() const;
  126. static void *operator new(size_t sz);
  127. static void *operator new[](size_t sz);
  128. static void operator delete(void *ptr, size_t sz);
  129. static void operator delete[](void *ptr, size_t sz);
  130. } MSTensor;
  131. MSTensor *CreateTensor(TypeId data_type, const ShapeVector &shape);
  132. void DestroyTensor(MSTensor *ptr);
  133. #endif // MINDSPORE_LITE_INCLUDE_MS_TENSOR_H_