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

5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 <utility>
  19. #include <vector>
  20. #include <memory>
  21. #include "ir/dtype/type_id.h"
  22. namespace mindspore {
  23. #define MS_API __attribute__((visibility("default")))
  24. namespace tensor {
  25. /// \brief MSTensor defined tensor in MindSpore Lite.
  26. class MS_API MSTensor {
  27. public:
  28. /// \brief Constructor of MindSpore Lite MSTensor.
  29. ///
  30. /// \return Instance of MindSpore Lite MSTensor.
  31. MSTensor() = default;
  32. /// \brief Destructor of MindSpore Lite Model.
  33. virtual ~MSTensor() = default;
  34. /// \brief Get data type of the MindSpore Lite MSTensor.
  35. ///
  36. /// \note TypeId is defined in mindspore/mindspore/core/ir/dtype/type_id.h. Only number types in TypeId enum are
  37. /// suitable for MSTensor.
  38. ///
  39. /// \return MindSpore Lite TypeId of the MindSpore Lite MSTensor.
  40. virtual TypeId data_type() const = 0;
  41. /// \brief Get shape of the MindSpore Lite MSTensor.
  42. ///
  43. /// \return A vector of int as the shape of the MindSpore Lite MSTensor.
  44. virtual std::vector<int> shape() const = 0;
  45. /// \brief Get size of the dimension of the MindSpore Lite MSTensor index by the parameter index.
  46. ///
  47. /// \param[in] index Define index of dimension returned.
  48. ///
  49. /// \return Size of dimension of the MindSpore Lite MSTensor.
  50. virtual int DimensionSize(size_t index) const = 0;
  51. /// \brief Get number of element in MSTensor.
  52. ///
  53. /// \return Number of element in MSTensor.
  54. virtual int ElementsNum() const = 0;
  55. /// \brief Get byte size of data in MSTensor.
  56. ///
  57. /// \return Byte size of data in MSTensor.
  58. virtual size_t Size() const = 0;
  59. /// \brief Get the pointer of data in MSTensor.
  60. ///
  61. /// \note The data pointer can be used to both write and read data in MSTensor.
  62. ///
  63. /// \return the pointer points to data in MSTensor.
  64. virtual void *MutableData() = 0;
  65. };
  66. } // namespace tensor
  67. } // namespace mindspore
  68. #endif // MINDSPORE_LITE_INCLUDE_MS_TENSOR_H_