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.5 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 <functional>
  19. #include <memory>
  20. #include <string>
  21. #include <utility>
  22. #include <vector>
  23. #include "ir/dtype/type_id.h"
  24. #ifndef MS_API
  25. #ifdef _WIN32
  26. #define MS_API __declspec(dllexport)
  27. #else
  28. #define MS_API __attribute__((visibility("default")))
  29. #endif
  30. #endif
  31. namespace mindspore {
  32. namespace tensor {
  33. /// \brief MSTensor defined tensor in MindSpore Lite.
  34. class MS_API MSTensor {
  35. public:
  36. /// \brief Constructor of MindSpore Lite MSTensor.
  37. ///
  38. /// \return Instance of MindSpore Lite MSTensor.
  39. MSTensor() = default;
  40. /// \brief Destructor of MindSpore Lite Model.
  41. virtual ~MSTensor() = default;
  42. /// \brief Get data type of the MindSpore Lite MSTensor.
  43. ///
  44. /// \note TypeId is defined in mindspore/mindspore/include/api/type_id.h. Only number types in TypeId enum are
  45. /// suitable for MSTensor.
  46. ///
  47. /// \return MindSpore Lite TypeId of the MindSpore Lite MSTensor.
  48. virtual TypeId data_type() const = 0;
  49. /// \brief Get shape of the MindSpore Lite MSTensor.
  50. ///
  51. /// \return A vector of int as the shape of the MindSpore Lite MSTensor.
  52. virtual std::vector<int> shape() const = 0;
  53. /// \brief Get size of the dimension of the MindSpore Lite MSTensor index by the parameter index.
  54. ///
  55. /// \param[in] index Define index of dimension returned.
  56. ///
  57. /// \return Size of dimension of the MindSpore Lite MSTensor.
  58. virtual int DimensionSize(size_t index) const = 0;
  59. /// \brief Get number of element in MSTensor.
  60. ///
  61. /// \return Number of element in MSTensor.
  62. virtual int ElementsNum() const = 0;
  63. /// \brief Get byte size of data in MSTensor.
  64. ///
  65. /// \return Byte size of data in MSTensor.
  66. virtual size_t Size() const = 0;
  67. /// \brief Get the pointer of data in MSTensor.
  68. ///
  69. /// \note The data pointer can be used to both write and read data in MSTensor.
  70. ///
  71. /// \return the pointer points to data in MSTensor.
  72. virtual void *MutableData() = 0;
  73. /// \brief Get the name of MSTensor.
  74. ///
  75. /// \return the name of MSTensor.
  76. virtual std::string tensor_name() const = 0;
  77. /// \brief Set the name of MSTensor.
  78. virtual void set_tensor_name(const std::string name) = 0;
  79. /// \brief Set the data of MSTensor.
  80. virtual void set_data(void *data) = 0;
  81. };
  82. } // namespace tensor
  83. /// \brief CallBackParam defined input arguments for callBack function.
  84. struct CallBackParam {
  85. std::string node_name; /**< node name argument */
  86. std::string node_type; /**< node type argument */
  87. };
  88. /// \brief KernelCallBack defined the function pointer for callBack.
  89. using KernelCallBack = std::function<bool(std::vector<tensor::MSTensor *> inputs,
  90. std::vector<tensor::MSTensor *> outputs, const CallBackParam &opInfo)>;
  91. } // namespace mindspore
  92. #endif // MINDSPORE_LITE_INCLUDE_MS_TENSOR_H_