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_c.h 4.8 kB

4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /**
  2. * Copyright 2021 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_INCLUDE_C_API_TENSOE_C_H
  17. #define MINDSPORE_INCLUDE_C_API_TENSOE_C_H
  18. #include <stddef.h>
  19. #include "include/c_api/types_c.h"
  20. #include "include/c_api/data_type_c.h"
  21. #include "include/c_api/format_c.h"
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. typedef void *MSTensorHandle;
  26. /// \brief Create a tensor object.
  27. ///
  28. /// \param[in] name The name of the tensor.
  29. /// \param[in] type The data type of the tensor.
  30. /// \param[in] shape The shape of the tensor.
  31. /// \param[in] shape_num The num of the shape.
  32. /// \param[in] data The data pointer that points to allocated memory.
  33. /// \param[in] data_len The length of the memory, in bytes.
  34. ///
  35. /// \return Tensor object handle.
  36. MS_API MSTensorHandle MSTensorCreate(const char *name, MSDataType type, const int64_t *shape, size_t shape_num,
  37. const void *data, size_t data_len);
  38. /// \brief Destroy the tensor object.
  39. ///
  40. /// \param[in] tensor Tensor object handle address.
  41. MS_API void MSTensorDestroy(MSTensorHandle *tensor);
  42. /// \brief Obtain a deep copy of the tensor.
  43. ///
  44. /// \param[in] tensor Tensor object handle.
  45. ///
  46. /// \return Tensor object handle.
  47. MS_API MSTensorHandle MSTensorClone(MSTensorHandle tensor);
  48. /// \brief Set the name for the tensor.
  49. ///
  50. /// \param[in] tensor Tensor object handle.
  51. /// \param[in] name The name of the tensor.
  52. MS_API void MSTensorSetName(MSTensorHandle tensor, const char *name);
  53. /// \brief Obtain the name of the tensor.
  54. ///
  55. /// \param[in] tensor Tensor object handle.
  56. ///
  57. /// \return The name of the tensor.
  58. MS_API const char *MSTensorGetName(const MSTensorHandle tensor);
  59. /// \brief Set the data type for the tensor.
  60. ///
  61. /// \param[in] tensor Tensor object handle.
  62. /// \param[in] type The data type of the tensor.
  63. MS_API void MSTensorSetDataType(MSTensorHandle tensor, MSDataType type);
  64. /// \brief Obtain the data type of the tensor.
  65. ///
  66. /// \param[in] tensor Tensor object handle.
  67. ///
  68. /// \return The date type of the tensor.
  69. MS_API MSDataType MSTensorGetDataType(const MSTensorHandle tensor);
  70. /// \brief Set the shape for the tensor.
  71. ///
  72. /// \param[in] tensor Tensor object handle.
  73. /// \param[in] shape The shape array.
  74. /// \param[in] shape_num Dimension of shape.
  75. MS_API void MSTensorSetShape(MSTensorHandle tensor, const int64_t *shape, size_t shape_num);
  76. /// \brief Obtain the shape of the tensor.
  77. ///
  78. /// \param[in] tensor Tensor object handle.
  79. /// \param[out] shape_num Dimension of shape.
  80. ///
  81. /// \return The shape array of the tensor.
  82. MS_API const int64_t *MSTensorGetShape(const MSTensorHandle tensor, size_t *shape_num);
  83. /// \brief Set the format for the tensor.
  84. ///
  85. /// \param[in] tensor Tensor object handle.
  86. /// \param[in] format The format of the tensor.
  87. MS_API void MSTensorSetFormat(MSTensorHandle tensor, MSFormat format);
  88. /// \brief Obtain the format of the tensor.
  89. ///
  90. /// \param[in] tensor Tensor object handle.
  91. ///
  92. /// \return The format of the tensor.
  93. MS_API MSFormat MSTensorGetFormat(const MSTensorHandle tensor);
  94. /// \brief Obtain the data for the tensor.
  95. ///
  96. /// \param[in] tensor Tensor object handle.
  97. /// \param[in] data A pointer to the data of the tensor.
  98. MS_API void MSTensorSetData(MSTensorHandle tensor, void *data);
  99. /// \brief Obtain the data pointer of the tensor.
  100. ///
  101. /// \param[in] tensor Tensor object handle.
  102. ///
  103. /// \return The data pointer of the tensor.
  104. MS_API const void *MSTensorGetData(const MSTensorHandle tensor);
  105. /// \brief Obtain the mutable data pointer of the tensor. If the internal data is empty, it will allocate memory.
  106. ///
  107. /// \param[in] tensor Tensor object handle.
  108. ///
  109. /// \return The data pointer of the tensor.
  110. MS_API void *MSTensorGetMutableData(const MSTensorHandle tensor);
  111. /// \brief Obtain the element number of the tensor.
  112. ///
  113. /// \param[in] tensor Tensor object handle.
  114. ///
  115. /// \return The element number of the tensor.
  116. MS_API int64_t MSTensorGetElementNum(const MSTensorHandle tensor);
  117. /// \brief Obtain the data size fo the tensor.
  118. ///
  119. /// \param[in] tensor Tensor object handle.
  120. ///
  121. /// \return The data size of the tensor.
  122. MS_API size_t MSTensorGetDataSize(const MSTensorHandle tensor);
  123. #ifdef __cplusplus
  124. }
  125. #endif
  126. #endif // MINDSPORE_INCLUDE_C_API_TENSOE_C_H